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

global $EM_Location;
$attributes = em_get_attributes(true);
//get Lattributes
$has_deprecated = false;
?>
<div id="location-attributes">
	<?php 
if (!empty($attributes['names']) && count($attributes['names']) > 0) {
    ?>
		<table class="form-table">
			<thead>
				<tr valign="top">
					<td><strong>Attribute Name</strong></td>
					<td><strong>Value</strong></td>
				</tr>
			</thead> 
			<tbody id="mtm_body">
				<?php 
    $count = 1;
    foreach ($attributes['names'] as $name) {
        ?>
					<tr valign="top" id="em_attribute_<?php 
        echo $count;
        ?>
">
						<td scope="row"><?php 
        echo $name;
        ?>
</td>
Пример #3
0
 /**
  * Retrieve event, location and recurring information via POST
  * @return boolean
  */
 function get_post()
 {
     //Build Event Array
     do_action('em_event_get_post_pre', $this);
     $this->name = !empty($_POST['event_name']) ? stripslashes($_POST['event_name']) : '';
     $this->slug = !empty($_POST['event_slug']) ? $_POST['event_slug'] : '';
     $this->start_date = !empty($_POST['event_start_date']) ? $_POST['event_start_date'] : '';
     $this->end_date = !empty($_POST['event_end_date']) ? $_POST['event_end_date'] : $this->start_date;
     $this->rsvp = !empty($_POST['event_rsvp']) ? 1 : 0;
     //$this->spaces = ( !empty($_POST['event_spaces']) && is_numeric($_POST['event_spaces']) ) ? $_POST['event_spaces']:0;
     $this->notes = !empty($_POST['content']) ? stripslashes($_POST['content']) : '';
     //WP TinyMCE field
     //Sort out time
     //TODO make time handling less painful
     $match = array();
     if (!empty($_POST['event_start_time']) && preg_match('/^([01]\\d|2[0-3]):([0-5]\\d)(AM|PM)?$/', $_POST['event_start_time'], $match)) {
         if ($match[3] == 'PM' && $match[1] != 12) {
             $match[1] = 12 + $match[1];
         } elseif ($match[3] == 'AM' && $match[1] == 12) {
             $match[1] = '00';
         }
         $this->start_time = $match[1] . ":" . $match[2] . ":00";
     } else {
         $this->start_time = "00:00:00";
     }
     if (!empty($_POST['event_end_time']) && preg_match('/^([01]\\d|2[0-3]):([0-5]\\d)(AM|PM)?$/', $_POST['event_end_time'], $match)) {
         if ($match[3] == 'PM' && $match[1] != 12) {
             $match[1] = 12 + $match[1];
         } elseif ($match[3] == 'AM' && $match[1] == 12) {
             $match[1] = '00';
         }
         $this->end_time = $match[1] . ":" . $match[2] . ":00";
     } else {
         $this->end_time = $this->start_time;
     }
     //Start/End times should be available as timestamp
     $this->start = strtotime($this->start_date . " " . $this->start_time);
     $this->end = strtotime($this->end_date . " " . $this->end_time);
     //owner
     if (!empty($_REQUEST['event_owner']) && is_numeric($_REQUEST['event_owner'])) {
         $this->owner = current_user_can('edit_others_events') ? $_REQUEST['event_owner'] : get_current_user_id();
     }
     //categories
     if (!empty($_POST['event_categories']) && is_array($_POST['event_categories'])) {
         $this->categories = new EM_Categories($_POST['event_categories']);
     }
     //Attributes
     $event_attributes = array();
     $post = $_POST;
     $event_available_attributes = em_get_attributes();
     if (!empty($_POST['em_attributes']) && is_array($_POST['em_attributes'])) {
         foreach ($_POST['em_attributes'] as $att_key => $att_value) {
             if ((in_array($att_key, $event_available_attributes['names']) || array_key_exists($att_key, $this->attributes)) && trim($att_value) != '') {
                 $att_vals = count($event_available_attributes['values'][$att_key]);
                 if ($att_vals == 0 || $att_vals > 0 && in_array($att_value, $event_available_attributes['values'][$att_key])) {
                     $event_attributes[$att_key] = $att_value;
                 } elseif ($att_vals > 0) {
                     $event_attributes[$att_key] = $event_available_attributes['values'][$att_key][0];
                 }
             }
         }
     }
     $this->attributes = $event_attributes;
     //Recurrence data
     $this->recurrence_id = !empty($_POST['recurrence_id']) && is_numeric($_POST['recurrence_id']) ? $_POST['recurrence_id'] : 0;
     if (!empty($_POST['repeated_event'])) {
         $this->recurrence = 1;
         $this->freq = !empty($_POST['recurrence_freq']) && in_array($_POST['recurrence_freq'], array('daily', 'weekly', 'monthly')) ? $_POST['recurrence_freq'] : 'daily';
         if (!empty($_POST['recurrence_bydays']) && $this->freq == 'weekly' && self::array_is_numeric($_POST['recurrence_bydays'])) {
             $this->byday = implode(",", $_POST['recurrence_bydays']);
         } elseif (!empty($_POST['recurrence_byday']) && $this->freq == 'monthly') {
             $this->byday = $_POST['recurrence_byday'];
         }
         $this->interval = !empty($_POST['recurrence_interval']) ? $_POST['recurrence_interval'] : 1;
         $this->byweekno = !empty($_POST['recurrence_byweekno']) ? $_POST['recurrence_byweekno'] : '';
     }
     //Add location information, or just link to previous location, this is a requirement...
     if (!empty($_POST['location_id']) && is_numeric($_POST['location_id'])) {
         $this->location_id = $_POST['location_id'];
         $this->location = new EM_Location($_POST['location_id']);
     } else {
         $this->location = new EM_Location();
         $this->location->get_post();
     }
     if (!$this->get_bookings()->get_tickets()->get_post()) {
         $EM_Tickets = $this->get_bookings()->get_tickets();
         array_merge($this->errors, $this->get_bookings()->get_tickets()->errors);
     }
     return apply_filters('em_event_get_post', $this->validate(), $this);
 }
Пример #4
0
 /**
  * Retrieve event post meta information via POST, which should be always be called when saving the event custom post via WP.
  * @param boolean $validate whether or not to run validation, default is true
  * @return mixed
  */
 function get_post_meta($validate = true)
 {
     //We are getting the values via POST or GET
     do_action('em_location_get_post_meta_pre', $this);
     $this->location_address = !empty($_POST['location_address']) ? wp_kses(stripslashes($_POST['location_address']), array()) : '';
     $this->location_town = !empty($_POST['location_town']) ? wp_kses(stripslashes($_POST['location_town']), array()) : '';
     $this->location_state = !empty($_POST['location_state']) ? wp_kses(stripslashes($_POST['location_state']), array()) : '';
     $this->location_postcode = !empty($_POST['location_postcode']) ? wp_kses(stripslashes($_POST['location_postcode']), array()) : '';
     $this->location_region = !empty($_POST['location_region']) ? wp_kses(stripslashes($_POST['location_region']), array()) : '';
     $this->location_country = !empty($_POST['location_country']) ? wp_kses(stripslashes($_POST['location_country']), array()) : '';
     $this->location_latitude = !empty($_POST['location_latitude']) && is_numeric($_POST['location_latitude']) ? $_POST['location_latitude'] : '';
     $this->location_longitude = !empty($_POST['location_longitude']) && is_numeric($_POST['location_longitude']) ? $_POST['location_longitude'] : '';
     //Sort out event attributes - note that custom post meta now also gets inserted here automatically (and is overwritten by these attributes)
     if (get_option('dbem_location_attributes_enabled')) {
         global $allowedtags;
         if (!is_array($this->location_attributes)) {
             $this->location_attributes = array();
         }
         $location_available_attributes = em_get_attributes(true);
         //lattributes only
         if (!empty($_POST['em_attributes']) && is_array($_POST['em_attributes'])) {
             foreach ($_POST['em_attributes'] as $att_key => $att_value) {
                 if (in_array($att_key, $location_available_attributes['names']) || array_key_exists($att_key, $this->location_attributes)) {
                     $att_vals = count($location_available_attributes['values'][$att_key]);
                     if ($att_vals == 0 || $att_vals > 0 && in_array($att_value, $location_available_attributes['values'][$att_key])) {
                         $this->location_attributes[$att_key] = stripslashes($att_value);
                     } elseif ($att_vals > 0) {
                         $this->location_attributes[$att_key] = stripslashes(wp_kses($location_available_attributes['values'][$att_key][0], $allowedtags));
                     }
                 }
             }
         }
     }
     $result = $validate ? $this->validate_meta() : true;
     //post returns null
     $this->compat_keys();
     return apply_filters('em_location_get_post_meta', $result, $this);
 }
<?php

/*
 * This file is called by templates/forms/event-editor.php to display attribute fields on your event form on your website.
* You can override this file by copying it to /wp-content/themes/yourtheme/plugins/events-manager/forms/event/ and editing it there.
*/
global $EM_Event;
/* @var $EM_Event EM_Event */
$attributes = em_get_attributes();
$has_depreciated = false;
if (count($attributes['names']) > 0) {
    ?>
	<?php 
    foreach ($attributes['names'] as $name) {
        ?>
	<div class="event-attributes">
		<label for="em_attributes[<?php 
        echo $name;
        ?>
]"><?php 
        echo $name;
        ?>
</label>
		<?php 
        if (count($attributes['values'][$name]) > 1) {
            ?>
		<select name="em_attributes[<?php 
            echo $name;
            ?>
]">
			<?php 
Пример #6
0
/**
 * Generates Event Admin page, for adding and updating a single (or recurring) event.
 * @param $title
 * @return null
 */
function em_admin_event_page()
{
    global $EM_Event, $current_user, $EM_Notices, $localised_date_formats;
    //$EM_Event->get_bookings()->get_tickets()->get_ticket_bookings(); print_r($EM_Event);die();
    //check that user can access this page
    if (is_object($EM_Event) && !$EM_Event->can_manage('edit_events', 'edit_others_events')) {
        ?>
		<div class="wrap"><h2><?php 
        _e('Unauthorized Access', 'dbem');
        ?>
</h2><p><?php 
        echo sprintf(__('You do not have the rights to manage this %s.', 'dbem'), __('Event', 'dbem'));
        ?>
</p></div>
		<?php 
        return false;
    } elseif (!is_object($EM_Event)) {
        $EM_Event = new EM_Event();
    }
    if (is_object($EM_Event) && $EM_Event->id > 0) {
        if ($EM_Event->is_recurring()) {
            $title = __("Reschedule", 'dbem') . " '{$EM_Event->name}'";
        } else {
            $title = __("Edit Event", 'dbem') . " '" . $EM_Event->name . "'";
        }
    } else {
        $EM_Event = is_object($EM_Event) && get_class($EM_Event) == 'EM_Event' ? $EM_Event : new EM_Event();
        $title = __("Insert New Event", 'dbem');
        //Give a default location & category
        $default_cat = get_option('dbem_default_category');
        $default_loc = get_option('dbem_default_location');
        if (is_numeric($default_cat) && $default_cat > 0) {
            $EM_Category = new EM_Category($default_cat);
            $EM_Event->get_categories()->categories[] = $EM_Category;
        }
        if (is_numeric($default_loc) && $default_loc > 0 && (empty($EM_Event->location->id) && empty($EM_Event->location->name) && empty($EM_Event->location->address) && empty($EM_Event->location->town))) {
            $EM_Event->location_id = $default_loc;
            $EM_Event->location = new EM_Location($default_loc);
        }
    }
    $use_select_for_locations = get_option('dbem_use_select_for_locations');
    // change prefix according to event/recurrence
    $pref = "event_";
    $locale_code = substr(get_locale(), 0, 2);
    $localised_date_format = $localised_date_formats[$locale_code];
    //FIXME time useage is very flimsy imho
    $hours_locale_regexp = "H:i";
    // Setting 12 hours format for those countries using it
    if (preg_match("/en|sk|zh|us|uk/", $locale_code)) {
        $hours_locale_regexp = "h:iA";
    }
    $days_names = array(1 => __('Mon'), 2 => __('Tue'), 3 => __('Wed'), 4 => __('Thu'), 5 => __('Fri'), 6 => __('Sat'), 0 => __('Sun'));
    $required = "<i>*</i>";
    ?>
	<?php 
    echo $EM_Notices;
    ?>

	<form id="event-form" method="post" action=""  enctype='multipart/form-data'>
		<div class="wrap">
			<div id="icon-events" class="icon32"><br /></div>
			<h2><?php 
    echo $title;
    ?>
</h2>
			<?php 
    if (count($EM_Event->warnings) > 0) {
        ?>
				<?php 
        foreach ($EM_Event->warnings as $warning) {
            ?>
				<p class="warning"><?php 
            echo $warning;
            ?>
</p>
				<?php 
        }
        ?>
			<?php 
    }
    ?>
             
			<div id="poststuff" class="metabox-holder has-right-sidebar">
				<!-- SIDEBAR -->
				<div id="side-info-column" class='inner-sidebar'>
					<div id='side-sortables'>
						<?php 
    do_action('em_admin_event_form_side_header');
    ?>
       
						<?php 
    if (get_option('dbem_recurrence_enabled') && ($EM_Event->is_recurrence() || $EM_Event->is_recurring() || $EM_Event->id == '')) {
        ?>
							<!-- START recurrence postbox -->
							<div class="postbox ">
								<div class="handlediv" title="Fare clic per cambiare."><br />
								</div>
								<h3 class='hndle'><span>
									<?php 
        _e("Recurrence", 'dbem');
        ?>
									</span></h3>
									<div class="inside">
									<?php 
        //TODO add js warning if rescheduling, since all bookings are deleted
        ?>
									<?php 
        if (!$EM_Event->id || $EM_Event->is_recurring()) {
            ?>
										<p>
											<input id="event-recurrence" type="checkbox" name="repeated_event" value="1" <?php 
            echo $EM_Event->is_recurring() ? 'checked="checked"' : '';
            ?>
 />
											<?php 
            _e('Repeated event', 'dbem');
            ?>
										</p>
										<div id="event_recurrence_pattern">
											<p>
												Frequency:
												<select id="recurrence-frequency" name="recurrence_freq">
													<?php 
            $freq_options = array("daily" => __('Daily', 'dbem'), "weekly" => __('Weekly', 'dbem'), "monthly" => __('Monthly', 'dbem'));
            em_option_items($freq_options, $EM_Event->freq);
            ?>
												</select>
											</p>
											<p>
												<?php 
            _e('Every', 'dbem');
            ?>
												<input id="recurrence-interval" name='recurrence_interval' size='2' value='<?php 
            echo $EM_Event->interval;
            ?>
' />
												<span class='interval-desc' id="interval-daily-singular">
												<?php 
            _e('day', 'dbem');
            ?>
												</span> <span class='interval-desc' id="interval-daily-plural">
												<?php 
            _e('days', 'dbem');
            ?>
												</span> <span class='interval-desc' id="interval-weekly-singular">
												<?php 
            _e('week', 'dbem');
            ?>
												</span> <span class='interval-desc' id="interval-weekly-plural">
												<?php 
            _e('weeks', 'dbem');
            ?>
												</span> <span class='interval-desc' id="interval-monthly-singular">
												<?php 
            _e('month', 'dbem');
            ?>
												</span> <span class='interval-desc' id="interval-monthly-plural">
												<?php 
            _e('months', 'dbem');
            ?>
												</span> 
											</p>
											<p class="alternate-selector" id="weekly-selector">
												<?php 
            $saved_bydays = $EM_Event->is_recurring() ? explode(",", $EM_Event->byday) : array();
            em_checkbox_items('recurrence_bydays[]', $days_names, $saved_bydays);
            ?>
											</p>
											<p class="alternate-selector" id="monthly-selector">
												<?php 
            _e('Every', 'dbem');
            ?>
												<select id="monthly-modifier" name="recurrence_byweekno">
													<?php 
            $weekno_options = array("1" => __('first', 'dbem'), '2' => __('second', 'dbem'), '3' => __('third', 'dbem'), '4' => __('fourth', 'dbem'), '-1' => __('last', 'dbem'));
            em_option_items($weekno_options, $EM_Event->byweekno);
            ?>
												</select>
												<select id="recurrence-weekday" name="recurrence_byday">
													<?php 
            em_option_items($days_names, $EM_Event->byday);
            ?>
												</select>
												&nbsp;
											</p>
										</div>
										<p id="recurrence-tip">
											<?php 
            _e('Check if your event happens more than once according to a regular pattern', 'dbem');
            ?>
										</p>
									<?php 
        } elseif ($EM_Event->is_recurrence()) {
            ?>
											<p>
												<?php 
            echo $EM_Event->get_recurrence_description();
            ?>
												<br />
												<a href="<?php 
            bloginfo('wpurl');
            ?>
/wp-admin/admin.php?page=events-manager-event&amp;event_id=<?php 
            echo $EM_Event->recurrence_id;
            ?>
">
												<?php 
            _e('Reschedule', 'dbem');
            ?>
												</a>
												<input type="hidden" name="recurrence_id" value="<?php 
            echo $EM_Event->recurrence_id;
            ?>
" />
											</p>
									<?php 
        } else {
            ?>
										<p><?php 
            _e('This is\'t a recurrent event', 'dbem');
            ?>
</p>
									<?php 
        }
        ?>
								</div>
							</div> 
							<!-- END recurrence postbox -->   
						<?php 
    }
    ?>
   
						   
						<?php 
    if (current_user_can('edit_others_events')) {
        ?>
						<div class="postbox ">
							<div class="handlediv" title="Fare clic per cambiare."><br />
							</div>
							<h3 class='hndle'><span><?php 
        _e('Event Owner/Contact Person', 'dbem');
        ?>
</span></h3>
							<div class="inside">
								<?php 
        wp_dropdown_users(array('name' => 'event_owner', 'show_option_none' => __("Select...", 'dbem'), 'selected' => $EM_Event->owner));
        ?>
							</div>
						</div>
						<?php 
    } else {
        ?>
						<input type="hidden" name="event_owner" value="<?php 
        get_current_user_id();
        ?>
" />
						<?php 
    }
    ?>
 
						   
						<?php 
    if (empty($EM_Event->id)) {
        ?>
							<?php 
        $user_groups = array();
        if (function_exists('groups_get_user_groups')) {
            $group_data = groups_get_user_groups(get_current_user_id());
            foreach ($group_data['groups'] as $group_id) {
                if (groups_is_user_admin(get_current_user_id(), $group_id)) {
                    $user_groups[] = groups_get_group(array('group_id' => $group_id));
                }
            }
        }
        ?>
							<?php 
        if (count($user_groups) > 0) {
            ?>
							<!-- START RSVP -->
							<div class="postbox " id='group-data'>
								<div class="handlediv" title="Fare clic per cambiare."><br />
								</div>
								<h3 class='hndle'><span><?php 
            _e('Group Ownership', 'dbem');
            ?>
</span></h3>
								<div class="inside">
									<p>
										<select name="group_id">
											<option value="<?php 
            echo $BP_Group->id;
            ?>
">Not a Group Event</option>
										<?php 
            foreach ($user_groups as $BP_Group) {
                ?>
											<option value="<?php 
                echo $BP_Group->id;
                ?>
"><?php 
                echo $BP_Group->name;
                ?>
</option>
											<?php 
            }
            ?>
										</select>
										<br />
										<em><?php 
            _e('Select a group you admin to attach this event to it. Note that all other admins of that group can modify the booking, and you will not be able to unattach the event without deleting it.', 'dbem');
            ?>
</em>
									</p>
								</div>
							</div>
							<?php 
        }
        ?>
						<?php 
    }
    ?>
						
						<?php 
    if (get_option('dbem_rsvp_enabled')) {
        ?>
							<!-- START RSVP -->
							<div class="postbox " id='rsvp-data'>
								<div class="handlediv" title="Fare clic per cambiare."><br />
								</div>
								<h3 class='hndle'><span><?php 
        _e('Bookings Stats', 'dbem');
        ?>
</span></h3>
								<div class="inside">
									<div>
										<!-- START RSVP Stats -->
										<?php 
        $available_spaces = $EM_Event->get_bookings()->get_available_spaces();
        $booked_spaces = $EM_Event->get_bookings()->get_booked_spaces();
        if (count($EM_Event->get_bookings()->bookings) > 0) {
            ?>
													<div class='wrap'>
														<p><strong><?php 
            echo __('Available Spaces', 'dbem') . ': ' . $EM_Event->get_bookings()->get_available_spaces();
            ?>
</strong></p>
														<p><strong><?php 
            echo __('Confirmed Spaces', 'dbem') . ': ' . $EM_Event->get_bookings()->get_booked_spaces();
            ?>
</strong></p>
														<p><strong><?php 
            echo __('Pending Spaces', 'dbem') . ': ' . $EM_Event->get_bookings()->get_pending_spaces();
            ?>
</strong></p>
												 	</div>
													 		
											 	    <br class='clear'/>
											 	    
											 	 	<div id='major-publishing-actions'>  
														<div id='publishing-action'> 
															<a id='printable' href='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&event_id=" . $EM_Event->id;
            ?>
'><?php 
            _e('manage bookings', 'dbem');
            ?>
</a><br />
															<a target='_blank' href='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=bookings_report&event_id=" . $EM_Event->id;
            ?>
'><?php 
            _e('printable view', 'dbem');
            ?>
</a>
															<a href='<?php 
            echo get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&action=export_csv&event_id=" . $EM_Event->id;
            ?>
'><?php 
            _e('export csv', 'dbem');
            ?>
</a>
															<br class='clear'/>             
												        </div>
														<br class='clear'/>    
													</div>
													<?php 
        } else {
            ?>
													<p><em><?php 
            _e('No responses yet!');
            ?>
</em></p>
													<?php 
        }
        ?>
										<!-- END RSVP Stats -->
									</div>
								</div>
							</div>
							<!-- END RSVP -->
						<?php 
    }
    ?>
  
						<?php 
    if (get_option('dbem_categories_enabled')) {
        ?>
							<!-- START Categories -->
							<div class="postbox ">
								<div class="handlediv" title="Fare clic per cambiare."><br />
								</div>
								<h3 class='hndle'><span>
									<?php 
        _e('Category', 'dbem');
        ?>
									</span></h3>
								<div class="inside">
									<?php 
        $categories = EM_Categories::get(array('orderby' => 'category_name'));
        ?>
									<?php 
        if (count($categories) > 0) {
            ?>
										<p>
											<?php 
            foreach ($categories as $EM_Category) {
                ?>
											<label><input type="checkbox" name="event_categories[]" value="<?php 
                echo $EM_Category->id;
                ?>
" <?php 
                if ($EM_Event->get_categories()->has($EM_Category->id)) {
                    echo 'checked="checked"';
                }
                ?>
 /> <?php 
                echo $EM_Category->name;
                ?>
</label><br />			
											<?php 
            }
            ?>
										</p>
									<?php 
        } else {
            ?>
										<p><?php 
            sprintf(__('No categories available, <a href="%s">create one here first</a>', 'dbem'), get_bloginfo('wpurl') . '/wp-admin/admin.php?page=events-manager-categories');
            ?>
</p>
									<?php 
        }
        ?>
								</div>
							</div> 
							<!-- END Categories -->
						<?php 
    }
    ?>
						<?php 
    do_action('em_admin_event_form_side_footer');
    ?>
					</div>
				</div>
				<!-- END OF SIDEBAR -->
				<div id="post-body">
					<div id="post-body-content">
						<?php 
    do_action('em_admin_event_form_header');
    ?>
						<div id="event_name" class="stuffbox">
							<h3>
								<?php 
    _e('Name', 'dbem');
    ?>
							</h3>
							<div class="inside">
								<input type="text" name="event_name" id="event-name" value="<?php 
    echo htmlspecialchars($EM_Event->name, ENT_QUOTES);
    ?>
" /><?php 
    echo $required;
    ?>
								<br />
								<?php 
    _e('The event name. Example: Birthday party', 'dbem');
    ?>
								<?php 
    $slug_link = __('View Slug', 'dbem');
    ?>
								<a href="#" id="event-slug-trigger"><?php 
    echo $slug_link;
    ?>
</a>
								<script type="text/javascript">
									jQuery(document).ready(function($){
										$('#event-slug-trigger').click(function(){
											if( $(this).text() == '<?php 
    echo $slug_link;
    ?>
'){
												$('.event-slug').show(); 
												 $(this).text('<?php 
    _e('Hide Slug', 'dbem');
    ?>
');
											}else{ 
												$('.event-slug').hide(); 
												 $(this).text('<?php 
    echo $slug_link;
    ?>
'); 
											}
										});
									});
								</script>
								<p class='event-slug' style="display:none">
									<?php 
    _e('Event Slug', 'dbem');
    ?>
: <input type="text" name="event_slug" id="event-slug" value="<?php 
    echo $EM_Event->slug;
    ?>
" />
									<br />
									<?php 
    _e('The event slug. If the event slug already exists, a random number will be appended to the end.', 'dbem');
    ?>
								</p>
							</div>
						</div>
						<div id="event_start_date" class="stuffbox">
							<h3 id='event-date-title'><?php 
    _e('Event date', 'dbem');
    ?>
</h3>
							<h3 id='recurrence-dates-title'><?php 
    _e('Recurrence dates', 'dbem');
    ?>
</h3>
							<div class="inside">
								<input id="em-date-start-loc" type="text" />
								<input id="em-date-start" type="hidden" name="event_start_date" value="<?php 
    echo $EM_Event->start_date;
    ?>
" />
								<input id="em-date-end-loc" type="text" />
								<input id="em-date-end" type="hidden" name="event_end_date" value="<?php 
    echo $EM_Event->end_date;
    ?>
" />
								<br />
								<span id='event-date-explanation'>
								<?php 
    _e('The event date.', 'dbem');
    /* Marcus Begin Edit */
    echo " ";
    _e('When not reoccurring, this event spans between the beginning and end date.', 'dbem');
    /* Marcus End Edit */
    ?>
								</span>
								<span id='recurrence-dates-explanation'>
									<?php 
    _e('The recurrence beginning and end date.', 'dbem');
    ?>
								</span>
							</div>
						</div>
						<div id="event_end_day" class="stuffbox">
							<h3>
								<?php 
    _e('Event time', 'dbem');
    ?>
							</h3>
							<div class="inside">
								<input id="start-time" type="text" size="8" maxlength="8" name="event_start_time" value="<?php 
    echo date($hours_locale_regexp, strtotime($EM_Event->start_time));
    ?>
" />
								-
								<input id="end-time" type="text" size="8" maxlength="8" name="event_end_time" value="<?php 
    echo date($hours_locale_regexp, strtotime($EM_Event->end_time));
    ?>
" />
								<br />
								<?php 
    _e('The time of the event beginning and end', 'dbem');
    ?>
. 
							</div>
						</div>
						<div id="location_coordinates" class="stuffbox" style='display: none;'>
							<h3>
								<?php 
    _e('Coordinates', 'dbem');
    ?>
							</h3>
							<div class="inside">
								<input id='location-latitude' name='location_latitude' type='text' value='<?php 
    echo $EM_Event->get_location()->latitude;
    ?>
' size='15' />
								-
								<input id='location-longitude' name='location_longitude' type='text' value='<?php 
    echo $EM_Event->get_location()->longitude;
    ?>
' size='15' />
							</div>
						</div>
						<div id="location_info" class="stuffbox">
							<h3>
								<?php 
    _e('Location', 'dbem');
    ?>
							</h3>
							<div class="inside">
								<table id="dbem-location-data">     
									<tr>
										<td style="padding-right:20px; width:100%;">
											<table>
												<?php 
    if ($use_select_for_locations) {
        ?>
 
												<tr>
													<th><?php 
        _e('Location:', 'dbem');
        ?>
</th>
													<td> 
														<select name="location_id" id='location-select-id' size="1">  
															<?php 
        $locations = EM_Locations::get();
        foreach ($locations as $location) {
            $selected = "";
            if ($EM_Event->get_location()->id == $location->id) {
                $selected = "selected='selected' ";
            }
            ?>
          
														    	<option value="<?php 
            echo $location->id;
            ?>
" title="<?php 
            echo "{$location->latitude},{$location->longitude}";
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo $location->name;
            ?>
</option>
														    	<?php 
        }
        ?>
														</select>
														<p><?php 
        _e('The name of the location where the event takes place. You can use the name of a venue, a square, etc', 'dbem');
        ?>
</p>
													</td>
												</tr>
												<?php 
    } else {
        ?>
												<tr>
													<th><?php 
        _e('Name:');
        ?>
</th>
													<td>
														<input id='location-id' name='location_id' type='hidden' value='<?php 
        echo $EM_Event->get_location()->id;
        ?>
' size='15' />
														<input id="location-name" type="text" name="location_name" value="<?php 
        echo htmlspecialchars($EM_Event->location->name, ENT_QUOTES);
        ?>
" /><?php 
        echo $required;
        ?>
													
					                            		<p><em><?php 
        _e('Create a location or start typing to search a previously created location.', 'dbem');
        ?>
</em></p>
					                            	</td>
										 		</tr>
												<tr>
													<th><?php 
        _e('Address:');
        ?>
&nbsp;</th>
													<td>
														<input id="location-address" type="text" name="location_address" value="<?php 
        echo htmlspecialchars($EM_Event->location->address, ENT_QUOTES);
        ?>
" /><?php 
        echo $required;
        ?>
													</td>
												</tr>
												<tr>
													<th><?php 
        _e('City/Town:');
        ?>
&nbsp;</th>
													<td>
														<input id="location-town" type="text" name="location_town" value="<?php 
        echo htmlspecialchars($EM_Event->location->town, ENT_QUOTES);
        ?>
" /><?php 
        echo $required;
        ?>
														<input id="location-town-wpnonce" type="hidden" value="<?php 
        echo wp_create_nonce('search_town');
        ?>
" />
													</td>
												</tr>
												<tr>
													<th><?php 
        _e('State/County:');
        ?>
&nbsp;</th>
													<td>
														<input id="location-state" type="text" name="location_state" value="<?php 
        echo htmlspecialchars($EM_Event->location->state, ENT_QUOTES);
        ?>
" />
														<input id="location-state-wpnonce" type="hidden" value="<?php 
        echo wp_create_nonce('search_states');
        ?>
" />
													</td>
												</tr>
												<tr>
													<th><?php 
        _e('Postcode:');
        ?>
&nbsp;</th>
													<td>
														<input id="location-postcode" type="text" name="location_postcode" value="<?php 
        echo htmlspecialchars($EM_Event->location->postcode, ENT_QUOTES);
        ?>
" />
													</td>
												</tr>
												<tr>
													<th><?php 
        _e('Region:');
        ?>
&nbsp;</th>
													<td>
														<input id="location-region" type="text" name="location_region" value="<?php 
        echo htmlspecialchars($EM_Event->location->region, ENT_QUOTES);
        ?>
" />
														<input id="location-region-wpnonce" type="hidden" value="<?php 
        echo wp_create_nonce('search_regions');
        ?>
" />
													</td>
												</tr>
												<tr>
													<th><?php 
        _e('Country:');
        ?>
&nbsp;</th>
													<td>
														<select id="location-country" name="location_country">
															<option value="0" <?php 
        echo $EM_Event->location->country == '' && $EM_Event->location->id == '' && get_option('dbem_location_default_country') == '' ? 'selected="selected"' : '';
        ?>
><?php 
        _e('none selected', 'dbem');
        ?>
</option>
															<?php 
        foreach (em_get_countries() as $country_key => $country_name) {
            ?>
															<option value="<?php 
            echo $country_key;
            ?>
" <?php 
            echo $EM_Event->location->country == $country_key || $EM_Event->location->country == '' && $EM_Event->location->id == '' && get_option('dbem_location_default_country') == $country_key ? 'selected="selected"' : '';
            ?>
><?php 
            echo $country_name;
            ?>
</option>
															<?php 
        }
        ?>
														</select><?php 
        echo $required;
        ?>
														<!-- <p><em><?php 
        _e('Filling this in first will allow you to quickly find previously filled states and regions for the country.', 'dbem');
        ?>
</em></p> -->
													</td>
												</tr>
												<?php 
    }
    ?>
											</table>
										</td>
										<?php 
    if (get_option('dbem_gmap_is_active')) {
        ?>
										<td width="400">
											<div id='em-map-404' style='width: 400px; vertical-align:middle; text-align: center;'>
												<p><em><?php 
        _e('Location not found', 'dbem');
        ?>
</em></p>
											</div>
											<div id='em-map' style='width: 400px; height: 300px; display: none;'></div>
										</td>
										<?php 
    }
    ?>
									</tr>
							</table>
						</div>
					</div>
					<div id="event_notes" class="stuffbox">
						<h3>
							<?php 
    _e('Details', 'dbem');
    ?>
						</h3>
						<div class="inside">
							<div id="<?php 
    echo user_can_richedit() ? 'postdivrich' : 'postdiv';
    ?>
" class="postarea">
								<?php 
    the_editor($EM_Event->notes);
    ?>
							</div>
							<br />
							<?php 
    _e('Details about the event', 'dbem');
    ?>
						</div>
					</div>
									
					<div id="event-image" class="stuffbox">
						<h3>
							<?php 
    _e('Event image', 'dbem');
    ?>
						</h3>
						<div class="inside" style="padding:10px;">
								<?php 
    if ($EM_Event->get_image_url() != '') {
        ?>
 
									<img src='<?php 
        echo $EM_Event->image_url;
        ?>
' alt='<?php 
        echo $EM_Event->name;
        ?>
'/>
								<?php 
    } else {
        ?>
 
									<?php 
        _e('No image uploaded for this event yet', 'dbem');
        ?>
								<?php 
    }
    ?>
								<br /><br />
								<label for='event_image'><?php 
    _e('Upload/change picture', 'dbem');
    ?>
</label> <input id='event-image' name='event_image' id='event_image' type='file' size='40' />
						</div>
					</div>
					
					<?php 
    if (get_option('dbem_rsvp_enabled')) {
        ?>
					<div id="event-bookings" class="stuffbox">
						<h3><span><?php 
        _e('Bookings/Registration', 'dbem');
        ?>
</span></h3>
						<div class="inside">
							<div class="wrap">
								<div id="event-rsvp-box">
									<input id="event-rsvp" name='event_rsvp' value='1' type='checkbox' <?php 
        echo $EM_Event->rsvp ? 'checked="checked"' : '';
        ?>
 />
									&nbsp;&nbsp;
									<?php 
        _e('Enable registration for this event', 'dbem');
        ?>
								</div>
								<div id="event-tickets" style="<?php 
        echo $EM_Event->rsvp ? '' : 'display:none;';
        ?>
">
									<?php 
        //get tickets here and if there are none, create a blank ticket
        $EM_Tickets = $EM_Event->get_bookings()->get_tickets();
        if (count($EM_Tickets->tickets) == 0) {
            $EM_Tickets->tickets[] = new EM_Ticket();
            $delete_temp_ticket = true;
        }
        if (get_option('dbem_bookings_tickets_single')) {
            $EM_Ticket = $EM_Tickets->get_first();
            include em_locate_template('forms/ticket-form.php');
        } else {
            ?>
		
										<p><strong><?php 
            _e('Tickets', 'dbem');
            ?>
</strong></p>
										<p><em><?php 
            _e('You have single or multiple tickets, where certain tickets become availalble under certain conditions, e.g. early bookings, group discounts, maximum bookings per ticket, etc.', 'dbem');
            ?>
</em></p>					
										<table class="form-table">
											<thead>
												<tr valign="top">
													<th class="ticket-status">&nbsp;</th>
													<th><?php 
            _e('Ticket Name', 'dbem');
            ?>
</th>
													<th><?php 
            _e('Price', 'dbem');
            ?>
</th>
													<th><?php 
            _e('Min/Max', 'dbem');
            ?>
</th>
													<th><?php 
            _e('Start/End', 'dbem');
            ?>
</th>
													<th><?php 
            _e('Avail. Spaces', 'dbem');
            ?>
</th>
													<th><?php 
            _e('Booked Spaces', 'dbem');
            ?>
</th>
													<th>&nbsp;</th>
												</tr>
											</thead>    
											<tfoot>
												<tr valign="top">
													<td colspan="6">
														<a href="#" id="em-tickets-add" rel="#em-tickets-form"><?php 
            _e('Add new ticket', 'dbem');
            ?>
</a>
													</td>
												</tr>
											</tfoot>
											<tbody id="em-tickets-body">
												<?php 
            $count = 1;
            foreach ($EM_Tickets->tickets as $EM_Ticket) {
                ?>
														<tr valign="top" id="em-tickets-row-<?php 
                echo $count;
                ?>
" class="em-tickets-row">
															<td class="ticket-status"><span class="<?php 
                echo $EM_Ticket->is_available() ? 'ticket_on' : 'ticket_off';
                ?>
"></span></td>													
															<td class="ticket-name"><span class="ticket_name"><?php 
                echo $EM_Ticket->name;
                ?>
</span><br /><span class="ticket_description"></span></td>
															<td class="ticket-price">
																<span class="ticket_price"><?php 
                echo $EM_Ticket->price ? $EM_Ticket->price : __('Free', 'dbem');
                ?>
</span>
															</td>
															<td class="ticket-limit">
																<span class="ticket_min">
																	<?php 
                echo !empty($EM_Ticket->min) ? $EM_Ticket->min : '-';
                ?>
																</span> / 
																<span class="ticket_max"><?php 
                echo !empty($EM_Ticket->max) ? $EM_Ticket->max : '-';
                ?>
</span>
															</td>
															<td class="ticket-time">
																<span class="ticket_start"><?php 
                echo !empty($EM_Ticket->start) ? date($localised_date_format, $EM_Ticket->start_timestamp) : '';
                ?>
</span> -
																<span class="ticket_end"><?php 
                echo !empty($EM_Ticket->end) ? date($localised_date_format, $EM_Ticket->end_timestamp) : '';
                ?>
</span>
															</td>
															<td class="ticket-qty">
																<span class="ticket_available_spaces"><?php 
                echo $EM_Ticket->get_available_spaces();
                ?>
</span>/
																<span class="ticket_spaces">
																	<?php 
                if ($EM_Ticket->get_spaces()) {
                    echo $EM_Ticket->get_spaces();
                    echo $EM_Ticket->spaces_limit ? '' : '*';
                } else {
                    echo '-';
                }
                ?>
																</span>
															</td>
															<td class="ticket-booked-spaces">
																<span class="ticket_booked_spaces"><?php 
                echo $EM_Ticket->get_booked_spaces();
                ?>
</span>
															</td>
															<td class="ticket-actions">
																<a href="#" class="ticket-actions-edit"><?php 
                _e('Edit', 'dbem');
                ?>
</a> 
																<?php 
                if (count($EM_Ticket->get_bookings()->bookings) == 0) {
                    ?>
																| <a href="<?php 
                    bloginfo('wpurl');
                    ?>
/wp-load.php" class="ticket-actions-delete"><?php 
                    _e('Delete', 'dbem');
                    ?>
</a>
																<?php 
                } else {
                    ?>
																| <a href="<?php 
                    bloginfo('wpurl');
                    ?>
/wp-admin/admin.php?page=events-manager-bookings&ticket_id=<?php 
                    echo $EM_Ticket->id;
                    ?>
"><?php 
                    _e('View Bookings', 'dbem');
                    ?>
</a>
																<?php 
                }
                ?>
																<input type="hidden" class="ticket_id" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_id]" value="<?php 
                echo $EM_Ticket->id;
                ?>
" />
																<input type="hidden" class="ticket_name" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_name]" value="<?php 
                echo $EM_Ticket->name;
                ?>
" />
																<input type="hidden" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_description]" value="<?php 
                echo $EM_Ticket->description;
                ?>
" />
																<input type="hidden" class="ticket_price" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_price]" value="<?php 
                echo $EM_Ticket->price;
                ?>
" />
																<input type="hidden" class="ticket_spaces" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_spaces]" value="<?php 
                echo $EM_Ticket->spaces;
                ?>
" />
																<input type="hidden" class="ticket_start" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_start]" value="<?php 
                echo !empty($EM_Ticket->start) ? date("Y-m-d H:i", $EM_Ticket->start_timestamp) : '';
                ?>
" />
																<input type="hidden" class="ticket_end" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_end]" value="<?php 
                echo !empty($EM_Ticket->end) ? date("Y-m-d H:i", $EM_Ticket->end_timestamp) : '';
                ?>
" />
																<input type="hidden" class="ticket_min" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_min]" value="<?php 
                echo $EM_Ticket->min;
                ?>
" />
																<input type="hidden" class="ticket_max" name="em_tickets[<?php 
                echo $count;
                ?>
][ticket_max]" value="<?php 
                echo $EM_Ticket->max;
                ?>
" />
															</td>
														</tr>
														<?php 
                $count++;
            }
            if (!empty($delete_temp_ticket)) {
                array_pop($EM_Tickets->tickets);
            }
            ?>
											</tbody>
										</table>
										<?php 
        }
        ?>
								</div>
							</div>
						</div>
					</div>
					<?php 
    }
    ?>
					
					<?php 
    if (get_option('dbem_attributes_enabled')) {
        ?>
						<div id="event-attributes" class="stuffbox">
							<h3>
								<?php 
        _e('Attributes', 'dbem');
        ?>
							</h3>
							<div class="inside">
								<?php 
        $attributes = em_get_attributes();
        $has_depreciated = false;
        ?>
								<div class="wrap">
									<?php 
        if (!empty($attributes['names']) && count($attributes['names']) > 0) {
            ?>
										<table class="form-table">
											<thead>
												<tr valign="top">
													<td><strong>Attribute Name</strong></td>
													<td><strong>Value</strong></td>
												</tr>
											</thead> 
											<tbody id="mtm_body">
												<?php 
            $count = 1;
            foreach ($attributes['names'] as $name) {
                ?>
													<tr valign="top" id="em_attribute_<?php 
                echo $count;
                ?>
">
														<td scope="row"><?php 
                echo $name;
                ?>
</td>
														<td>
															<?php 
                if (count($attributes['values'][$name]) > 0) {
                    ?>
															<select name="em_attributes[<?php 
                    echo $name;
                    ?>
]">
																<option><?php 
                    echo __('No Value', 'dbem');
                    ?>
</option>
																<?php 
                    foreach ($attributes['values'][$name] as $attribute_val) {
                        ?>
																	<?php 
                        if (array_key_exists($name, $EM_Event->attributes) && $EM_Event->attributes[$name] == $attribute_val) {
                            ?>
																		<option selected="selected"><?php 
                            echo $attribute_val;
                            ?>
</option>
																	<?php 
                        } else {
                            ?>
																		<option><?php 
                            echo $attribute_val;
                            ?>
</option>
																	<?php 
                        }
                        ?>
																<?php 
                    }
                    ?>
															</select>
															<?php 
                } else {
                    ?>
															<input type="text" name="em_attributes[<?php 
                    echo $name;
                    ?>
]" value="<?php 
                    echo array_key_exists($name, $EM_Event->attributes) ? htmlspecialchars($EM_Event->attributes[$name], ENT_QUOTES) : '';
                    ?>
" />
															<?php 
                }
                ?>
														</td>
													</tr>
													<?php 
                $count++;
            }
            if ($count == 1) {
                ?>
													<tr><td colspan="2"><?php 
                echo sprintf(__("You don't have any custom attributes defined in any of your Events Manager template settings. Please add them the <a href='%s'>settings page</a>", 'dbem'), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-options");
                ?>
</td></tr>
													<?php 
            }
            ?>
											</tbody>
										</table>
										<?php 
            if (count(array_diff(array_keys($EM_Event->attributes), $attributes['names'])) > 0) {
                ?>
										<p><strong><?php 
                _e('Depreciated Attributes');
                ?>
</strong></p>
										<p><em><?php 
                _e("If you see any attributes under here, that means they're not used in Events Manager anymore. To add them, you need to add the custom attribute again to a formatting option in the settings page. To remove any of these depreciated attributes, give it a blank value and save.");
                ?>
</em></p>
										<table class="form-table">
											<thead>
												<tr valign="top">
													<td><strong>Attribute Name</strong></td>
													<td><strong>Value</strong></td>
												</tr>
											</thead> 
											<tbody id="mtm_body">
												<?php 
                if (is_array($EM_Event->attributes) and count($EM_Event->attributes) > 0) {
                    foreach ($EM_Event->attributes as $name => $value) {
                        if (!in_array($name, $attributes['names'])) {
                            ?>
															<tr valign="top" id="em_attribute_<?php 
                            echo $count;
                            ?>
">
																<td scope="row"><?php 
                            echo $name;
                            ?>
</td>
																<td>
																	<input type="text" name="em_attributes[<?php 
                            echo $name;
                            ?>
]" value="<?php 
                            echo htmlspecialchars($value, ENT_QUOTES);
                            ?>
" />
																</td>
															</tr>
															<?php 
                            $count++;
                        }
                    }
                }
                ?>
											</tbody>
										</table>
										<?php 
            }
            ?>
									<?php 
        } else {
            ?>
										<p>
										<?php 
            _e('In order to use attributes, you must define some in your templates, otherwise they\'ll never show. Go to Events > Settings to add attribute placeholders.', 'dbem');
            ?>
										</p> 
										<script>
											jQuery(document).ready(function($){ $('#event_attributes').addClass('closed'); });
										</script>
									<?php 
        }
        ?>
								</div>
							</div>
						</div>
						<?php 
    }
    ?>
						<?php 
    do_action('em_admin_event_form_footer');
    ?>
					</div>
					<p class="submit">
						<input type="submit" name="events_update" value="<?php 
    _e('Submit Event', 'dbem');
    ?>
 &raquo;" />
					</p>
					<input type="hidden" name="p" value="<?php 
    echo !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : '';
    ?>
" /><a>
					<input type="hidden" name="scope" value="<?php 
    echo !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : '';
    ?>
" /></a>
					<input type="hidden" name="event_id" value="<?php 
    echo $EM_Event->id;
    ?>
" />
					<input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('wpnonce_event_save');
    ?>
" />
					<input type="hidden" name="action" value="event_save" />
				</div>
			</div>
		</div>
	</form>
	<?php 
    em_locate_template('forms/tickets-form.php', true);
    //put here as it can't be in the add event form
    ?>
	<script type="text/javascript">
		jQuery(document).ready( function($) {
			<?php 
    if ($EM_Event->is_recurring()) {
        ?>
			//Recurrence Warnings
			$('#event_form').submit( function(event){
				confirmation = confirm('<?php 
        _e('Are you sure you want to reschedule this recurring event? If you do this, you will lose all booking information and the old recurring events will be deleted.', 'dbem');
        ?>
');
				if( confirmation == false ){
					event.preventDefault();
				}
			});
			<?php 
    }
    ?>
			<?php 
    if (get_option('dbem_rsvp_enabled')) {
        ?>
			//RSVP Warning
			$('#event-rsvp').click( function(event){
				if( !this.checked ){
					confirmation = confirm('<?php 
        _e('Are you sure you want to disable bookings? If you do this and save, you will lose all previous bookings. If you wish to prevent further bookings, reduce the number of spaces available to the amount of bookings you currently have', 'dbem');
        ?>
');
					if( confirmation == false ){
						event.preventDefault();
					}else{
						$('#event-tickets').hide();
						$("div#rsvp-data").hide();
					}
				}else{
					$('#event-tickets').fadeIn();
					$("div#rsvp-data").fadeIn();
				}
			});
			  
			if($('input#event-rsvp').attr("checked")) {
				$("div#rsvp-data").fadeIn();
			} else {
				$("div#rsvp-data").hide();
			}
			<?php 
    }
    ?>
		});		
	</script>
<?php 
}
Пример #7
0
 /**
  * Retrieve event post meta information via POST, which should be always be called when saving the event custom post via WP.
  * @param boolean $validate whether or not to run validation, default is true
  * @return boolean
  */
 function get_post_meta($validate = true)
 {
     //Grab POST data
     $this->event_start_date = !empty($_POST['event_start_date']) ? $_POST['event_start_date'] : '';
     $this->event_end_date = !empty($_POST['event_end_date']) ? $_POST['event_end_date'] : $this->event_start_date;
     //check if this is recurring or not
     if (!empty($_POST['recurring'])) {
         $this->recurrence = 1;
         $this->post_type = 'event-recurring';
     }
     //Get Location info
     if (!get_option('dbem_locations_enabled') || !empty($_POST['no_location']) && !get_option('dbem_require_location', true) || empty($_POST['location_id']) && !get_option('dbem_require_location', true) && get_option('dbem_use_select_for_locations')) {
         $this->location_id = 0;
     } elseif (!empty($_POST['location_id']) && is_numeric($_POST['location_id'])) {
         $this->location_id = $_POST['location_id'];
     } else {
         //we're adding a new location, so create an empty location and populate
         $this->location_id = null;
         $this->get_location()->get_post(false);
         $this->get_location()->post_content = '';
         //reset post content, as it'll grab the event description otherwise
     }
     //Sort out time
     $this->event_all_day = !empty($_POST['event_all_day']) ? 1 : 0;
     if (!$this->event_all_day) {
         $match = array();
         foreach (array('event_start_time', 'event_end_time', 'event_rsvp_time') as $timeName) {
             if (!empty($_POST[$timeName]) && preg_match('/^([01]\\d|2[0-3]):([0-5]\\d) ?(AM|PM)?$/', $_POST[$timeName], $match)) {
                 if (!empty($match[3]) && $match[3] == 'PM' && $match[1] != 12) {
                     $match[1] = 12 + $match[1];
                 } elseif (!empty($match[3]) && $match[3] == 'AM' && $match[1] == 12) {
                     $match[1] = '00';
                 }
                 $this->{$timeName} = $match[1] . ":" . $match[2] . ":00";
             } else {
                 $this->{$timeName} = $timeName == 'event_start_time' ? "00:00:00" : $this->event_start_time;
             }
         }
     } else {
         $this->event_start_time = $this->event_end_time = '00:00:00';
     }
     //Start/End times should be available as timestamp
     $this->start = strtotime($this->event_start_date . " " . $this->event_start_time);
     $this->end = strtotime($this->event_end_date . " " . $this->event_end_time);
     //Bookings
     if (!empty($_POST['event_rsvp']) && $_POST['event_rsvp']) {
         $this->get_bookings()->get_tickets()->get_post();
         $this->event_rsvp = 1;
         //RSVP cuttoff TIME is set up above where start/end times are as well
         $this->event_rsvp_date = isset($_POST['event_rsvp_date']) ? $_POST['event_rsvp_date'] : $this->event_start_date;
         if (empty($this->event_rsvp_date)) {
             $this->event_rsvp_time = '00:00:00';
         }
         $this->event_spaces = isset($_POST['event_spaces']) ? absint($_POST['event_spaces']) : 0;
     } else {
         $this->event_rsvp = 0;
         $this->event_rsvp_time = '00:00:00';
     }
     //Sort out event attributes - note that custom post meta now also gets inserted here automatically (and is overwritten by these attributes)
     if (get_option('dbem_attributes_enabled')) {
         global $allowedtags;
         if (!is_array($this->event_attributes)) {
             $this->event_attributes = array();
         }
         $event_available_attributes = em_get_attributes();
         if (!empty($_POST['em_attributes']) && is_array($_POST['em_attributes'])) {
             foreach ($_POST['em_attributes'] as $att_key => $att_value) {
                 if (in_array($att_key, $event_available_attributes['names']) || array_key_exists($att_key, $this->event_attributes)) {
                     if (!empty($att_value)) {
                         $att_vals = count($event_available_attributes['values'][$att_key]);
                         if ($att_vals == 0 || $att_vals > 0 && in_array($att_value, $event_available_attributes['values'][$att_key])) {
                             $this->event_attributes[$att_key] = stripslashes($att_value);
                         } elseif ($att_vals > 0) {
                             $this->event_attributes[$att_key] = stripslashes(wp_kses($event_available_attributes['values'][$att_key][0], $allowedtags));
                         }
                     } else {
                         $this->event_attributes[$att_key] = '';
                     }
                 }
             }
         }
     }
     //Set Blog ID
     if (is_multisite()) {
         $this->blog_id = get_current_blog_id();
     }
     //group id
     $this->group_id = !empty($_POST['group_id']) && is_numeric($_POST['group_id']) ? $_POST['group_id'] : 0;
     //Recurrence data
     if ($this->is_recurring()) {
         $this->recurrence = 1;
         //just in case
         $this->recurrence_freq = !empty($_POST['recurrence_freq']) && in_array($_POST['recurrence_freq'], array('daily', 'weekly', 'monthly', 'yearly')) ? $_POST['recurrence_freq'] : 'daily';
         if (!empty($_POST['recurrence_bydays']) && $this->recurrence_freq == 'weekly' && self::array_is_numeric($_POST['recurrence_bydays'])) {
             $this->recurrence_byday = implode(",", $_POST['recurrence_bydays']);
         } elseif (!empty($_POST['recurrence_byday']) && $this->recurrence_freq == 'monthly') {
             $this->recurrence_byday = $_POST['recurrence_byday'];
         }
         $this->recurrence_interval = !empty($_POST['recurrence_interval']) && is_numeric($_POST['recurrence_interval']) ? $_POST['recurrence_interval'] : 1;
         $this->recurrence_byweekno = !empty($_POST['recurrence_byweekno']) ? $_POST['recurrence_byweekno'] : '';
         $this->recurrence_days = !empty($_POST['recurrence_days']) && is_numeric($_POST['recurrence_days']) ? (int) $_POST['recurrence_days'] : 0;
     }
     //categories in MS GLobal
     if (EM_MS_GLOBAL && !is_main_site()) {
         $this->get_categories()->get_post();
         //it'll know what to do
     }
     //validate (optional) and return result
     $result = $validate ? $this->validate_meta() : true;
     $this->compat_keys();
     //compatability
     return apply_filters('em_event_get_post', $result, $this);
 }
Пример #8
0
    /**
     * Will output a event in the format passed in $format by replacing placeholders within the format.
     * @param string $format
     * @param string $target
     * @return string
     */
    function output($format, $target = "html")
    {
        $event_string = $format;
        //Time place holder that doesn't show if empty.
        //TODO add filter here too
        preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results);
        foreach ($results[0] as $result) {
            if (substr($result, 0, 3) == "#@_") {
                $date = 'end_date';
                $offset = 4;
            } else {
                $date = 'start_date';
                $offset = 3;
            }
            if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) {
                $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target));
            } else {
                $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target));
            }
            $event_string = str_replace($result, $replace, $event_string);
        }
        //This is for the custom attributes
        preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $format, $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 < get_option('dbem_conditional_recursions', 1); $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') {
                        //is it an all day event
                        $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0;
                    } elseif ($condition == 'fully_booked') {
                        //is it an all day event
                        $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0;
                    } 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
                        $show_condition = $this->start <= current_time('timestamp');
                    } elseif ($condition == 'is_future') {
                        //if event is upcoming
                        $show_condition = $this->start > current_time('timestamp');
                    } 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]+)({([a-zA-Z0-9_,]+)})?/", $format, $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 {
                            $matches = explode('<!--more', $this->post_content);
                            $replace = $matches[0];
                        }
                    }
                    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_src = $this->image_url;
                                if (is_multisite()) {
                                    //get the direct url as timthumb doesn't support redirect urls
                                    global $blog_id;
                                    $imageParts = explode('/blogs.dir/', $image_src);
                                    if (isset($imageParts[1])) {
                                        $image_src = network_site_url('/wp-content/blogs.dir/' . $imageParts[1]);
                                    }
                                }
                                if ($this->array_is_numeric($image_size) && count($image_size) > 1) {
                                    $replace = "<img src='" . esc_url(em_get_thumbnail_url($image_src, $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->event_name) . "' width='{$image_size[0]}' height='{$image_size[1]}'/>";
                                } else {
                                    $replace = "<img src='" . esc_url($image_src) . "' 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_seperator') . 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_seperator') . 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')) {
                        ob_start();
                        $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this));
                        if (!defined('EM_BOOKING_JS_LOADED')) {
                            //this kicks off the Javascript required by booking forms. This is fired once for all booking forms on a page load and appears at the bottom of the page
                            //your theme must call the wp_footer() function for this to work (as required by many other plugins too)
                            function em_booking_js_footer()
                            {
                                ?>
		
								<script type="text/javascript">
									jQuery(document).ready( function($){	
										<?php 
                                //we call the segmented JS files and include them here
                                include WP_PLUGIN_DIR . '/events-manager/includes/js/bookingsform.js';
                                do_action('em_gateway_js');
                                ?>
							
									});
								</script>
								<?php 
                            }
                            add_action('wp_footer', 'em_booking_js_footer');
                            add_action('admin_footer', 'em_booking_js_footer');
                            define('EM_BOOKING_JS_LOADED', true);
                        }
                        $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 '#_EVENTPRICERANGE':
                    //get the range of prices
                    $min = false;
                    $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();
                            }
                            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;
                    //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 '#_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
                    if ($this->event_all_day && $this->event_start_date == $this->event_end_date) {
                        $dateStart = date('Ymd', $this->start - 60 * 60 * get_option('gmt_offset'));
                        $dateEnd = date('Ymd', $this->start + 60 * 60 * 24 - 60 * 60 * get_option('gmt_offset'));
                    } else {
                        $dateStart = date('Ymd\\THis\\Z', $this->start - 60 * 60 * get_option('gmt_offset'));
                        $dateEnd = date('Ymd\\THis\\Z', $this->end - 60 * 60 * get_option('gmt_offset'));
                    }
                    //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 {
                $desc_replace[$full_result] = $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);
            }
        }
        return apply_filters('em_event_output', $event_string, $this, $format, $target);
    }
Пример #9
0
 /**
  * Retrieve event post meta information via POST, which should be always be called when saving the event custom post via WP.
  * @param boolean $validate whether or not to run validation, default is true
  * @return mixed
  */
 function get_post_meta($validate = true)
 {
     //We are getting the values via POST or GET
     do_action('em_location_get_post_meta_pre', $this);
     $this->location_address = !empty($_POST['location_address']) ? wp_kses(wp_unslash($_POST['location_address']), array()) : '';
     $this->location_town = !empty($_POST['location_town']) ? wp_kses(wp_unslash($_POST['location_town']), array()) : '';
     $this->location_state = !empty($_POST['location_state']) ? wp_kses(wp_unslash($_POST['location_state']), array()) : '';
     $this->location_postcode = !empty($_POST['location_postcode']) ? wp_kses(wp_unslash($_POST['location_postcode']), array()) : '';
     $this->location_region = !empty($_POST['location_region']) ? wp_kses(wp_unslash($_POST['location_region']), array()) : '';
     $this->location_country = !empty($_POST['location_country']) ? wp_kses(wp_unslash($_POST['location_country']), array()) : '';
     $this->location_latitude = !empty($_POST['location_latitude']) && is_numeric($_POST['location_latitude']) ? $_POST['location_latitude'] : '';
     $this->location_longitude = !empty($_POST['location_longitude']) && is_numeric($_POST['location_longitude']) ? $_POST['location_longitude'] : '';
     //Sort out event attributes - note that custom post meta now also gets inserted here automatically (and is overwritten by these attributes)
     if (get_option('dbem_location_attributes_enabled')) {
         global $allowedtags;
         if (!is_array($this->location_attributes)) {
             $this->location_attributes = array();
         }
         $location_available_attributes = em_get_attributes(true);
         //lattributes only
         if (!empty($_POST['em_attributes']) && is_array($_POST['em_attributes'])) {
             foreach ($_POST['em_attributes'] as $att_key => $att_value) {
                 if (in_array($att_key, $location_available_attributes['names']) || array_key_exists($att_key, $this->location_attributes)) {
                     $att_vals = count($location_available_attributes['values'][$att_key]);
                     if ($att_vals == 0 || $att_vals > 0 && in_array($att_value, $location_available_attributes['values'][$att_key])) {
                         $this->location_attributes[$att_key] = wp_unslash($att_value);
                     } elseif ($att_vals > 0) {
                         $this->location_attributes[$att_key] = wp_unslash(wp_kses($location_available_attributes['values'][$att_key][0], $allowedtags));
                     }
                 }
             }
         }
     }
     //the line below should be deleted one day and we move validation out of this function, when that happens check otherfunctions like EM_ML_IO::get_post_meta function which force validation again
     $result = $validate ? $this->validate_meta() : true;
     //post returns null
     $this->compat_keys();
     return apply_filters('em_location_get_post_meta', $result, $this, $validate);
     //if making a hook, assume that eventually $validate won't be passed on
 }