public static function override_bookings($EM_Bookings, $EM_Event) { if (!EM_ML::is_original($EM_Event)) { $event = EM_ML::get_original_event($EM_Event); if (!empty($EM_Bookings->translated)) { //we've already done this before, so we just need to make sure the event id isn't being reset to the translated event id $EM_Bookings->event_id = $event->event_id; } else { //bookings hasn't been 'translated' yet, so we get the original event, get the EM_Bookings object and replace the current event with it. $EM_Bookings = new EM_Bookings($event); $EM_Bookings->event_id = $event->event_id; $EM_Bookings->translated = true; //go through tickets and translate to appropriate language $event_lang = EM_ML::get_the_language($EM_Event); foreach ($EM_Bookings->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if (!empty($EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_name'])) { $EM_Ticket->ticket_name = $EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_name']; } if (!empty($EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_description'])) { $EM_Ticket->ticket_description = $EM_Ticket->ticket_meta['langs'][$event_lang]['ticket_description']; } } } } return $EM_Bookings; }
public static function meta_box_bookings_translation() { global $EM_Event; $event = EM_ML::get_original_event($EM_Event); $lang = EM_ML::$current_language; ?> <p><em><?php esc_html_e('Below are translations for your tickets. If left blank, the language of the original event will be used.', 'dbem'); ?> </em></p> <table class="event-bookings-ticket-translation form-table"> <?php foreach ($event->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ $name = !empty($EM_Ticket->ticket_meta['langs'][$lang]['ticket_name']) ? $EM_Ticket->ticket_meta['langs'][$lang]['ticket_name'] : ''; $description = !empty($EM_Ticket->ticket_meta['langs'][$lang]['ticket_description']) ? $EM_Ticket->ticket_meta['langs'][$lang]['ticket_description'] : ''; $desc_ph = !empty($EM_Ticket->ticket_description) ? $EM_Ticket->ticket_description : __('Description', 'dbem'); ?> <tbody> <tr> <td><strong><?php echo esc_html($EM_Ticket->ticket_name); ?> </strong></td> <td> <input placeholder="<?php echo esc_attr($EM_Ticket->ticket_name); ?> " type="text" name="ticket_translations[<?php echo $EM_Ticket->ticket_id; ?> ][ticket_name]" value="<?php echo esc_attr($name); ?> " /> <br/> <textarea placeholder="<?php echo esc_attr($desc_ph); ?> " type="text" name="ticket_translations[<?php echo $EM_Ticket->ticket_id; ?> ][ticket_description]"><?php echo esc_html($description); ?> </textarea> </td> </tr> </tbody> <?php } ?> </table> <?php }
/** * Hooks into em_event_get_post and writes the original event translation data into the current event, to avoid validation errors and correct data saving. * @param boolean $result * @param EM_Event $EM_Event * @return boolean */ public static function event_get_post($result, $EM_Event) { //check if this is a master event, if not then we need to get the relevant master event info and populate this object with it so it passes validation and saves correctly. $event = EM_ML::get_original_event($EM_Event); /* @var $event EM_Event */ $EM_Event->original_event_id = $event->event_id; if ($EM_Event->event_id != $EM_Event->original_event_id) { $EM_Event->event_start_date = $event->event_start_date; $EM_Event->event_end_date = $event->event_end_date; $EM_Event->recurrence = $event->recurrence; $EM_Event->post_type = $event->post_type; $EM_Event->location_id = $event->location_id; $EM_Event->location = false; if ($EM_Event->location_id == 0) { $_POST['no_location'] = 1; } $EM_Event->event_all_day = $event->event_all_day; $EM_Event->event_start_time = $event->event_start_time; $EM_Event->event_end_time = $event->event_end_time; $EM_Event->start = $event->start; $EM_Event->end = $event->end; $EM_Event->event_rsvp_date = $event->event_rsvp_date; $EM_Event->event_rsvp = $event->event_rsvp; $EM_Event->event_rsvp_time = $event->event_rsvp_time; $EM_Event->blog_id = $event->blog_id; $EM_Event->group_id = $event->group_id; $EM_Event->recurrence = $event->recurrence; $EM_Event->recurrence_freq = $event->recurrence_freq; $EM_Event->recurrence_byday = $event->recurrence_byday; $EM_Event->recurrence_interval = $event->recurrence_interval; $EM_Event->recurrence_byweekno = $event->recurrence_byweekno; $EM_Event->recurrence_days = $event->recurrence_days; // We need to save ticket translations here as well to the ticket objects foreach ($EM_Event->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ $ticket_translation = array(); if (!empty($_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_name'])) { $ticket_translation['ticket_name'] = $_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_name']; } if (!empty($_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_description'])) { $ticket_translation['ticket_description'] = $_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_description']; } if (!empty($ticket_translation)) { $EM_Ticket->ticket_meta['langs'][EM_ML::$current_language] = $ticket_translation; } } } return $result; }
/** * Certain placeholders, specifically booking placeholders, will take information from the original event, so we generate the * @param string $replace * @param EM_Event $EM_Event * @param string $full_result * @return string */ public static function override_placeholders($replace, $EM_Event, $full_result) { global $em_wpml_original_events_cache; if (in_array($full_result, EM_ML_Placeholders::$event_placeholders)) { $event = EM_ML::get_original_event($EM_Event); //get the master event info, for later use if ($event->event_id != $EM_Event->event_id) { remove_filter('em_event_output_placeholder', 'EM_ML_Placeholders::override_placeholders', 100, 3); //override bookign form $replace = $event->output($full_result); add_filter('em_event_output_placeholder', 'EM_ML_Placeholders::override_placeholders', 100, 3); //override bookign form } } return $replace; }
/** * Hooks into em_event_get_post and writes the original event translation data into the current event, to avoid validation errors and correct data saving. * @param boolean $result * @param EM_Event $EM_Event * @return boolean */ public static function event_get_post_meta($result, $EM_Event) { //check if this is a master event, if not then we need to get the relevant master event info and populate this object with it so it passes validation and saves correctly. if (!EM_ML::is_original($EM_Event)) { //get original event object $event = EM_ML::get_original_event($EM_Event); EM_ML_IO::event_merge_original_meta($EM_Event, $event); if ($EM_Event->location_id == 0) { $_POST['no_location'] = 1; } // We need to save ticket translations here as well to the ticket objects foreach ($EM_Event->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ $ticket_translation = array(); if (!empty($_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_name'])) { $ticket_translation['ticket_name'] = wp_kses_data(stripslashes($_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_name'])); } if (!empty($_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_description'])) { $ticket_translation['ticket_description'] = wp_kses_post(stripslashes($_REQUEST['ticket_translations'][$EM_Ticket->ticket_id]['ticket_description'])); } if (!empty($ticket_translation)) { $EM_Ticket->ticket_meta['langs'][EM_ML::$current_language] = $ticket_translation; } } } elseif (!empty($EM_Event->location_id)) { //we need to make sure the location is the original location $EM_Location = $EM_Event->get_location(); if (!EM_ML::is_original($EM_Location)) { $EM_Event->location_id = EM_ML::get_original_location($EM_Location)->location_id; } } return $result; }
public static function event_meta_box_attributes() { global $EM_Event; //get original location for attributes $event = EM_ML::get_original_event($EM_Event); EM_ML_IO::event_merge_original_attributes($EM_Event, $event); em_locate_template('forms/event/attributes.php', true); }
/** * Modifies the duplication URL so that it contains the lang query parameter of the original event that is being duplicated. * * @param string $url * @param EM_Event $EM_Event * @return string */ public static function event_duplicate_url($url, $EM_Event) { global $sitepress; if (!EM_ML::is_original($EM_Event)) { $EM_Event = EM_ML::get_original_event($EM_Event); $sitepress_lang = $sitepress->get_language_for_element($EM_Event->post_id, 'post_' . $EM_Event->post_type); $url = add_query_arg(array('lang' => $sitepress_lang), $url); //gets escaped later } return $url; }