/** * Display the page html */ public function display_page() { $api = $this->_registry->get('model.api'); $ticketing_enabled = $api->is_signed(); $ticketing_message = $api->get_sign_message(); $loader = $this->_registry->get('theme.loader'); if (!$ticketing_enabled) { if (false === ai1ec_is_blank($ticketing_message)) { $api->clear_sign_message(); } $args = array('title' => Ai1ec_I18n::__('Time.ly Ticketing<sup>beta</sup>'), 'sign_up_text' => 'Please, <a href="edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings">Sign Up for a Timely Network account</a> to use Ticketing.'); $file = $loader->get_file('ticketing/signup.twig', $args, true); } else { $response = $api->get_payment_preferences(); $purchases = $api->get_purchases(); $args = array('title' => Ai1ec_I18n::__('Time.ly Ticketing<sup>beta</sup>'), 'settings_text' => Ai1ec_I18n::__('Settings'), 'sales_text' => Ai1ec_I18n::__('Sales'), 'select_payment_text' => Ai1ec_I18n::__('How do you want the tickets revenue to be sent to you?'), 'select_payment_description_text' => Ai1ec_I18n::__('If no payout method is selected, Time.ly will collect the revenue on behalf of you. Please contact payouts@time.ly for any outstanding payouts.'), 'cheque_text' => Ai1ec_I18n::__('Cheque'), 'paypal_text' => Ai1ec_I18n::__('Paypal'), 'required_text' => Ai1ec_I18n::__('This field is required.'), 'save_changes_text' => Ai1ec_I18n::__('Save Changes'), 'date_text' => Ai1ec_I18n::__('Date'), 'event_text' => Ai1ec_I18n::__('Event'), 'purchaser_text' => Ai1ec_I18n::__('Purchaser'), 'tickets_text' => Ai1ec_I18n::__('Tickets'), 'email_text' => Ai1ec_I18n::__('Email'), 'status_text' => Ai1ec_I18n::__('Status'), 'total_text' => Ai1ec_I18n::__('Total'), 'sign_out_button_text' => Ai1ec_I18n::__('Sign Out'), 'payment_method' => $response->payment_method, 'paypal_email' => $response->paypal_email, 'first_name' => $response->first_name, 'last_name' => $response->last_name, 'street' => $response->street, 'city' => $response->city, 'state' => $response->state, 'postcode' => $response->postcode, 'country' => $response->country, 'nonce' => array('action' => self::NONCE_ACTION, 'name' => self::NONCE_NAME, 'referrer' => false), 'action' => '?controller=front&action=ai1ec_api_ticketing_signup&plugin=' . AI1EC_PLUGIN_NAME, 'purchases' => $purchases); $file = $loader->get_file('ticketing/manage.twig', $args, true); } $this->_registry->get('css.admin')->admin_enqueue_scripts('ai1ec_event_page_all-in-one-event-calendar-settings'); $this->_registry->get('css.admin')->process_enqueue(array(array('style', 'ticketing.css'))); if (isset($_POST['ai1ec_save_settings'])) { $response = $api->save_payment_preferences(); // this redirect makes sure that the error messages appear on the screen header("Location: " . $_SERVER['HTTP_REFERER']); } return $file->render(); }
/** * Display the page html */ public function display_page() { $signed_to_api = $this->_api_registration->is_signed(); $signup_available = $this->_api_registration->is_api_sign_up_available(); $ticketing_available = $this->_api_registration->is_ticket_available(); $ticketing_message = $this->_api_registration->get_sign_message(); $loader = $this->_registry->get('theme.loader'); if (!$signed_to_api) { if (false === ai1ec_is_blank($ticketing_message)) { $this->_api_registration->clear_sign_message(); } $args = array('title' => Ai1ec_I18n::__('Time.ly Ticketing'), 'sign_up_text' => 'Please, <a href="edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings">Sign Up for a Timely Network account</a> to use Ticketing.', 'signup_form' => Ai1ec_I18n::__('You need to sign up for a Timely Network account in order to use Ticketing<br /><br />') . ($signup_available ? Ai1ec_I18n::__('<a href="edit.php?post_type=ai1ec_event&page=all-in-one-event-calendar-settings" class="ai1ec-btn ai1ec-btn-primary ai1ec-btn-lg">Sign In to Timely Network</a>') : Ai1ec_I18n::__('<b>Signing up for a Timely Network account is currently unavailable. Please, try again later.</b>'))); $file = $loader->get_file('ticketing/signup.twig', $args, true); } elseif (!$ticketing_available) { $args = array('title' => Ai1ec_I18n::__('Time.ly Ticketing'), 'sign_up_text' => '', 'signup_form' => 'Ticketing is currently not available for this website. Please, try again later.'); $file = $loader->get_file('ticketing/signup.twig', $args, true); } else { $response = $this->_api_registration->get_payment_preferences(); $purchases = $this->_api_registration->get_purchases(); $args = array('title' => Ai1ec_I18n::__('Time.ly Ticketing'), 'settings_text' => Ai1ec_I18n::__('Settings'), 'sales_text' => Ai1ec_I18n::__('Sales'), 'select_payment_text' => Ai1ec_I18n::__('Please provide your PayPal details.'), 'cheque_text' => Ai1ec_I18n::__('Cheque'), 'paypal_text' => Ai1ec_I18n::__('PayPal'), 'currency_text' => Ai1ec_I18n::__('Preferred currency for tickets:'), 'required_text' => Ai1ec_I18n::__('This field is required.'), 'save_changes_text' => Ai1ec_I18n::__('Save Changes'), 'date_text' => Ai1ec_I18n::__('Date'), 'event_text' => Ai1ec_I18n::__('Event'), 'purchaser_text' => Ai1ec_I18n::__('Purchaser'), 'tickets_text' => Ai1ec_I18n::__('Tickets'), 'email_text' => Ai1ec_I18n::__('Email'), 'status_text' => Ai1ec_I18n::__('Status'), 'total_text' => Ai1ec_I18n::__('Total'), 'sign_out_button_text' => Ai1ec_I18n::__('Sign Out'), 'payment_method' => $response->payment_method, 'paypal_email' => $response->paypal_email, 'first_name' => $response->first_name, 'last_name' => $response->last_name, 'currency' => $response->currency, 'nonce' => array('action' => self::NONCE_ACTION, 'name' => self::NONCE_NAME, 'referrer' => false), 'action' => '?controller=front&action=ai1ec_api_ticketing_signup&plugin=' . AI1EC_PLUGIN_NAME, 'purchases' => $purchases, 'paypal_currencies' => array(array('description' => Ai1ec_I18n::__('United States Dollar'), 'code' => 'USD'), array('description' => Ai1ec_I18n::__('Canadian Dollar'), 'code' => 'CAD'), array('description' => Ai1ec_I18n::__('Australian Dollar'), 'code' => 'AUD'), array('description' => Ai1ec_I18n::__('Brazilian Real'), 'code' => 'BRL', 'note' => Ai1ec_I18n::__('Note: This currency is supported as a payment currency and a currency balance for in-country PayPal accounts only.')), array('description' => Ai1ec_I18n::__('Czech Koruna'), 'code' => 'CZK'), array('description' => Ai1ec_I18n::__('Danish Krone'), 'code' => 'DKK'), array('description' => Ai1ec_I18n::__('Euro'), 'code' => 'EUR'), array('description' => Ai1ec_I18n::__('Hong Kong Dollar'), 'code' => 'HKD'), array('description' => Ai1ec_I18n::__('Hungarian Forint'), 'code' => 'HUF', 'note' => Ai1ec_I18n::__('Note: Decimal amounts are not supported for this currency. Passing a decimal amount will throw an error.')), array('description' => Ai1ec_I18n::__('Israeli New Sheqel'), 'code' => 'ILS'), array('description' => Ai1ec_I18n::__('Japanese Yen'), 'code' => 'JPY', 'note' => Ai1ec_I18n::__('Note: This currency does not support decimals. Passing a decimal amount will throw an error. 1,000,000')), array('description' => Ai1ec_I18n::__('Malaysian Ringgit'), 'code' => 'MYR', 'note' => Ai1ec_I18n::__('Note: This currency is supported as a payment currency and a currency balance for in-country PayPal accounts only.')), array('description' => Ai1ec_I18n::__('Mexican Peso'), 'code' => 'MXN'), array('description' => Ai1ec_I18n::__('Norwegian Krone'), 'code' => 'NOK'), array('description' => Ai1ec_I18n::__('New Zealand Dollar'), 'code' => 'NZD'), array('description' => Ai1ec_I18n::__('Philippine Peso'), 'code' => 'PHP'), array('description' => Ai1ec_I18n::__('Polish Zloty'), 'code' => 'PLN'), array('description' => Ai1ec_I18n::__('Pound Sterling'), 'code' => 'GBP'), array('description' => Ai1ec_I18n::__('Russian Ruble'), 'code' => 'RUB', 'note' => Ai1ec_I18n::__('For in-border payments (payments made within Russia), the Russian Ruble is the only accepted currency. If you use another currency for in-border payments, the transaction will fail')), array('description' => Ai1ec_I18n::__('Singapore Dollar'), 'code' => 'SGD'), array('description' => Ai1ec_I18n::__('Swedish Krona'), 'code' => 'SEK'), array('description' => Ai1ec_I18n::__('Swiss Franc'), 'code' => 'CHF'), array('description' => Ai1ec_I18n::__('Taiwan New Dollar'), 'code' => 'TWD', 'note' => Ai1ec_I18n::__('Note: Decimal amounts are not supported for this currency. Passing a decimal amount will throw an error.')), array('description' => Ai1ec_I18n::__('Thai Baht'), 'code' => 'THB'), array('description' => Ai1ec_I18n::__('Turkish Lira'), 'code' => 'TRY', 'note' => Ai1ec_I18n::__('Note: This currency is supported as a payment currency and a currency balance for in-country PayPal accounts only.')))); $file = $loader->get_file('ticketing/manage.twig', $args, true); } $this->_registry->get('css.admin')->admin_enqueue_scripts('ai1ec_event_page_all-in-one-event-calendar-settings'); $this->_registry->get('css.admin')->process_enqueue(array(array('style', 'ticketing.css'))); if (isset($_POST['ai1ec_save_settings'])) { $response = $this->_api_registration->save_payment_preferences(); // this redirect makes sure that the error messages appear on the screen header("Location: " . $_SERVER['HTTP_REFERER']); } return $file->render(); }
/** * Renders the html of the page and returns it. * * @param Ai1ec_Event $event * * @return string the html of the page */ public function get_content(Ai1ec_Event $event) { $settings = $this->_registry->get('model.settings'); $rrule = $this->_registry->get('recurrence.rule'); $taxonomy = $this->_registry->get('view.event.taxonomy'); $location = $this->_registry->get('view.event.location'); $ticket = $this->_registry->get('view.event.ticket'); $content = $this->_registry->get('view.event.content'); $time = $this->_registry->get('view.event.time'); $subscribe_url = AI1EC_EXPORT_URL . '&ai1ec_post_ids=' . $event->get('post_id'); $event->set_runtime('tickets_url_label', $ticket->get_tickets_url_label($event, false)); $event->set_runtime('content_img_url', $content->get_content_img_url($event)); $extra_buttons = apply_filters('ai1ec_rendering_single_event_actions', '', $event); $venues_html = apply_filters('ai1ec_rendering_single_event_venues', nl2br($location->get_location($event)), $event); $timezone_info = array('show_timezone' => false, 'text_timezone_title' => null, 'event_timezone' => null); $default_tz = $this->_registry->get('date.timezone')->get_default_timezone(); /** * Only display the timezone information if: * -) local timezone is not enforced -- because if it is enforced * then site owner knows that it's clear, from event contents, * where event happens and what time means; * -) the timezone is different from the site timezone because if * they do match then it is likely obvious when and wheere the * event is about to take place. */ if ($this->_registry->get('model.settings')->get('always_use_calendar_timezone') && $event->get('timezone_name') !== $default_tz) { $timezone_info = array('show_timezone' => true, 'event_timezone' => $event->get('timezone_name'), 'text_timezone_title' => sprintf(Ai1ec_I18n::__('Event was created in the %s time zone'), $event->get('start')->get_gmt_offset_as_text())); } $banner_image_meta = get_post_meta($event->get('post_id'), 'ai1ec_banner_image'); $banner_image = $banner_image_meta ? $banner_image_meta[0] : ''; // objects are passed by reference so an action is ok do_action('ai1ec_single_event_page_before_render', $event); $filter_groups_html = apply_filters('ai1ec_get_filter_groups_html', $event); $args = array('event' => $event, 'recurrence' => $rrule->rrule_to_text($event->get('recurrence_rules')), 'exclude' => $time->get_exclude_html($event, $rrule), 'categories' => $taxonomy->get_categories_html($event), 'tags' => $taxonomy->get_tags_html($event), 'location' => html_entity_decode($venues_html), 'filter_groups' => $filter_groups_html, 'map' => $location->get_map_view($event), 'contact' => $ticket->get_contact_html($event), 'back_to_calendar' => $content->get_back_to_calendar_button_html(), 'subscribe_url' => $subscribe_url, 'subscribe_url_no_html' => $subscribe_url . '&no_html=true', 'edit_instance_url' => null, 'edit_instance_text' => null, 'google_url' => 'http://www.google.com/calendar/render?cid=' . urlencode($subscribe_url), 'show_subscribe_buttons' => !$settings->get('turn_off_subscription_buttons'), 'hide_featured_image' => $settings->get('hide_featured_image'), 'extra_buttons' => $extra_buttons, 'show_get_calendar' => !$settings->get('disable_get_calendar_button'), 'text_add_calendar' => __('Add to Calendar', AI1EC_PLUGIN_NAME), 'subscribe_buttons_text' => $this->_registry->get('view.calendar.subscribe-button')->get_labels(), 'text_get_calendar' => Ai1ec_I18n::__('Get a Timely Calendar'), 'text_when' => __('When:', AI1EC_PLUGIN_NAME), 'text_where' => __('Where:', AI1EC_PLUGIN_NAME), 'text_cost' => __('Cost:', AI1EC_PLUGIN_NAME), 'text_contact' => __('Contact:', AI1EC_PLUGIN_NAME), 'text_tickets' => __('Tickets:', AI1EC_PLUGIN_NAME), 'text_free' => __('Free', AI1EC_PLUGIN_NAME), 'text_categories' => __('Categories', AI1EC_PLUGIN_NAME), 'text_tags' => __('Tags', AI1EC_PLUGIN_NAME), 'buy_tickets_text' => __('Buy Tickets', AI1EC_PLUGIN_NAME), 'timezone_info' => $timezone_info, 'banner_image' => $banner_image, 'content_img_url' => $event->get_runtime('content_img_url'), 'post_id' => $event->get('post_id'), 'ticket_url' => $event->get('ticket_url'), 'tickets_url_label' => $event->get_runtime('tickets_url_label'), 'start' => $event->get('start'), 'end' => $event->get('end'), 'cost' => $event->get('cost'), 'instance_id' => $event->get('instance_id')); if (!empty($args['recurrence']) && $event->get('instance_id') && current_user_can('edit_ai1ec_events')) { $args['edit_instance_url'] = ai1ec_admin_url('post.php?post=' . $event->get('post_id') . '&action=edit&instance=' . $event->get('instance_id')); $args['edit_instance_text'] = sprintf(Ai1ec_I18n::__('Edit this occurrence (%s)'), $event->get('start')->format_i18n('M j')); } $loader = $this->_registry->get('theme.loader'); $api = $this->_registry->get('model.api.api-ticketing'); if (false === ai1ec_is_blank($event->get('ical_feed_url'))) { $args['ticket_url'] = $api->get_api_event_buy_ticket_url($event->get('post_id')); } else { $api_event_id = $api->get_api_event_id($event->get('post_id')); if ($api_event_id) { $api = $this->_registry->get('model.api.api-ticketing'); $ticket_types = json_decode($api->get_ticket_types($event->get('post_id'), false)); $args['has_tickets'] = true; $args['API_URL'] = AI1EC_API_URL; $args['tickets_block'] = $loader->get_file('tickets.twig', array('tickets_checkout_url' => $api->get_api_event_buy_ticket_url($event->get('post_id')), 'tickets' => $ticket_types->data, 'text_tickets' => $args['text_tickets'], 'buy_tickets_text' => $args['buy_tickets_text'], 'api_event_id' => $api_event_id), false)->get_content(); } } return $loader->get_file('event-single.twig', $args, false)->get_content(); }
/** * Add Event Details meta box to the Add/Edit Event screen in the dashboard. * * @return void */ public function meta_box_view($post) { $theme_loader = $this->_registry->get('theme.loader'); $empty_event = $this->_registry->get('model.event'); // ================== // = Default values = // ================== // ATTENTION - When adding new fields to the event remember that you must // also set up the duplicate-controller. // TODO: Fix this duplication. $all_day_event = ''; $instant_event = ''; $start = $this->_registry->get('date.time'); $end = $this->_registry->get('date.time', '+1 hour'); $timezone_name = null; $timezones_list = $this->_registry->get('date.timezone')->get_timezones(true); $show_map = false; $google_map = ''; $venue = ''; $country = ''; $address = ''; $city = ''; $province = ''; $postal_code = ''; $contact_name = ''; $contact_phone = ''; $contact_email = ''; $contact_url = ''; $cost = ''; $is_free = 'checked="checked"'; $cost_type = 'free'; $rrule = ''; $rrule_text = ''; $repeating_event = false; $exrule = ''; $exrule_text = ''; $exclude_event = false; $exdate = ''; $show_coordinates = false; $longitude = ''; $latitude = ''; $coordinates = ''; $ticket_url = ''; $tickets = array(null); $ticketing = false; $message = false; $loading_error = false; $ticket_event_imported = false; $instance_id = false; if (isset($_REQUEST['instance'])) { $instance_id = absint($_REQUEST['instance']); } if ($instance_id) { add_filter('print_scripts_array', array($this, 'disable_autosave')); } try { // on some php version, nested try catch blocks fail and the exception would never be caught. // this is why we use this approach. $excpt = null; $event = null; try { $event = $this->_registry->get('model.event', get_the_ID(), $instance_id); } catch (Ai1ec_Event_Not_Found_Exception $excpt) { $ai1ec_localization_helper = $this->_registry->get('p28n.wpml'); $translatable_id = $ai1ec_localization_helper->get_translatable_id(); if (false !== $translatable_id) { $event = $this->_registry->get('model.event', $translatable_id, $instance_id); } } if (null !== $excpt) { throw $excpt; } // Existing event was found. Initialize form values with values from // event object. $all_day_event = $event->is_allday() ? 'checked' : ''; $instant_event = $event->is_instant() ? 'checked' : ''; $start = $event->get('start'); $end = $event->get('end'); $timezone_name = $event->get('timezone_name'); $multi_day = $event->is_multiday(); $show_map = $event->get('show_map'); $google_map = $show_map ? 'checked="checked"' : ''; $show_coordinates = $event->get('show_coordinates'); $coordinates = $show_coordinates ? 'checked="checked"' : ''; $longitude = (double) $event->get('longitude', 0); $latitude = (double) $event->get('latitude', 0); // There is a known bug in Wordpress (https://core.trac.wordpress.org/ticket/15158) that saves 0 to the DB instead of null. // We handle a special case here to avoid having the fields with a value of 0 when the user never inputted any coordinates if (!$show_coordinates) { $longitude = ''; $latitude = ''; } $venue = $event->get('venue'); $country = $event->get('country'); $address = $event->get('address'); $city = $event->get('city'); $province = $event->get('province'); $postal_code = $event->get('postal_code'); $contact_name = $event->get('contact_name'); $contact_phone = $event->get('contact_phone'); $contact_email = $event->get('contact_email'); $contact_url = $event->get('contact_url'); $cost = $event->get('cost'); $ticket_url = $event->get('ticket_url'); $rrule = $event->get('recurrence_rules'); $exrule = $event->get('exception_rules'); $exdate = $event->get('exception_dates'); $repeating_event = !empty($rrule); $exclude_event = !empty($exrule); $is_free = ''; $free = $event->is_free(); if (!empty($free)) { $is_free = 'checked="checked" '; $cost = ''; } if ($repeating_event) { $rrule_text = ucfirst($this->_registry->get('recurrence.rule')->rrule_to_text($rrule)); } if ($exclude_event) { $exrule_text = ucfirst($this->_registry->get('recurrence.rule')->rrule_to_text($exrule)); } } catch (Ai1ec_Event_Not_Found_Exception $excpt) { // Event does not exist. // Leave form fields undefined (= zero-length strings) $event = null; } // Time zone; display if set. $timezone = ''; $timezone_string = null; $date_timezone = $this->_registry->get('date.timezone'); if (!empty($timezone_name) && ($local_name = $date_timezone->get_name($timezone_name))) { $timezone_string = $local_name; } if (null === $timezone_string) { $timezone_string = $date_timezone->get_default_timezone(); } if ($timezone_string) { $timezone = $this->_registry->get('date.system')->get_gmt_offset_expr($timezone_string); } if (empty($timezone_name)) { /** * Actual Olsen timezone name is used when value is to be directly * exposed to user in some mean. It's possible to use named const. * `'sys.default'` only when passing value to date.time library. */ $timezone_name = $date_timezone->get_default_timezone(); } // This will store each of the accordion tabs' markup, and passed as an // argument to the final view. $boxes = array(); $parent_event_id = null; if ($event) { $parent_event_id = $this->_registry->get('model.event.parent')->event_parent($event->get('post_id')); } // =============================== // = Display event time and date = // =============================== $args = array('all_day_event' => $all_day_event, 'instant_event' => $instant_event, 'start' => $start, 'end' => $end, 'repeating_event' => $repeating_event, 'rrule' => $rrule, 'rrule_text' => $rrule_text, 'exclude_event' => $exclude_event, 'exrule' => $exrule, 'exrule_text' => $exrule_text, 'timezone' => $timezone, 'timezone_string' => $timezone_string, 'timezone_name' => $timezone_name, 'exdate' => $exdate, 'parent_event_id' => $parent_event_id, 'instance_id' => $instance_id, 'timezones_list' => $timezones_list); $boxes[] = $theme_loader->get_file('box_time_and_date.php', $args, true)->get_content(); // ================================================= // = Display event location details and Google map = // ================================================= $args = array('select_venue' => apply_filters('ai1ec_admin_pre_venue_html', ''), 'save_venue' => apply_filters('ai1ec_admin_post_venue_html', ''), 'venue' => $venue, 'country' => $country, 'address' => $address, 'city' => $city, 'province' => $province, 'postal_code' => $postal_code, 'google_map' => $google_map, 'show_map' => $show_map, 'show_coordinates' => $show_coordinates, 'longitude' => $longitude, 'latitude' => $latitude, 'coordinates' => $coordinates); $boxes[] = $theme_loader->get_file('box_event_location.php', $args, true)->get_content(); // =================================== // = Display event ticketing options = // =================================== if ($event) { $cost_type = get_post_meta($event->get('post_id'), '_ai1ec_cost_type', true); if (!$cost_type) { if ($ticket_url || $cost) { $cost_type = 'external'; } else { $cost_type = 'free'; } } } if ($this->_registry->get('helper.api-settings')->ai1ec_api_enabled()) { $api = $this->_registry->get('model.api'); $ticketing = $api->is_signed(); $message = $api->get_sign_message(); $loading_error = null; $ticket_event_imported = false; if ($event) { $ticket_event_imported = $api->is_ticket_event_imported($event->get('post_id')); if ($ticketing || $ticket_event_imported) { if ('tickets' === $cost_type) { $response = json_decode($api->get_ticket_types($event->get('post_id'))); if (isset($response->data)) { $tickets = array_merge($tickets, $response->data); } if (isset($response->error)) { $loading_error = $response->error; } } } $uid = $event->get_uid(); } else { $uid = $empty_event->get_uid(); } } if ($event) { $uid = $event->get_uid(); } else { $uid = $empty_event->get_uid(); } $args = array('cost' => $cost, 'cost_type' => $cost_type, 'ticket_url' => $ticket_url, 'event' => $empty_event, 'uid' => $uid, 'tickets' => $tickets, 'ticketing' => $ticketing, 'tickets_message' => $message, 'start' => $start, 'end' => $end, 'tickets_loading_error' => $loading_error, 'ticket_event_imported' => $ticket_event_imported); $boxes[] = $theme_loader->get_file('box_event_cost.php', $args, true)->get_content(); // ========================================= // = Display organizer contact information = // ========================================= $args = array('contact_name' => $contact_name, 'contact_phone' => $contact_phone, 'contact_email' => $contact_email, 'contact_url' => $contact_url, 'event' => $empty_event); $boxes[] = $theme_loader->get_file('box_event_contact.php', $args, true)->get_content(); // ========================== // = Parent/Child relations = // ========================== if ($event) { $parent = $this->_registry->get('model.event.parent')->get_parent_event($event->get('post_id')); if ($parent) { try { $parent = $this->_registry->get('model.event', $parent); } catch (Ai1ec_Event_Not_Found_Exception $exception) { // ignore $parent = null; } } if ($parent) { $children = $this->_registry->get('model.event.parent')->get_child_event_objects($event->get('post_id')); $args = compact('parent', 'children'); $args['registry'] = $this->_registry; $boxes[] = $theme_loader->get_file('box_event_children.php', $args, true)->get_content(); } } $boxes = apply_filters('ai1ec_add_new_event_boxes', $boxes, $event); // Display the final view of the meta box. $args = array('boxes' => $boxes); if ($this->_is_post_event($post)) { // ====================== // = Display Box Review = // ====================== $review = $this->_registry->get('model.review'); $review_content = $review->get_content($theme_loader); if (false === ai1ec_is_blank($review_content)) { $args['review_box'] = $review_content; } } echo $theme_loader->get_file('add_new_event_meta_box.php', $args, true)->get_content(); }
/** * Save the API event data * @param int $post_id Post ID * @param int $api_event_id (optional) Id of the event on the API * @param string $ics_api_url (optional) API URL of the event on the API (used when importing an ICS feed) * @param string $ics_checkout_url (optional) API CHECKOUT URL of the event on the API (used when importing an ICS feed) * @param string $currency (optional) Currency code of the event * @param string $thumbnail_id (optional) Id of the Thumbnail (Featured Image id) */ public function save_api_event_data($post_id, $api_event_id, $ics_api_url = null, $ics_checkout_url = null, $currency = null, $thumbnail_id = null) { if (ai1ec_is_blank($api_event_id)) { throw new Error('Api event id should never be null'); } $api_data[self::ATTR_EVENT_ID] = $api_event_id; $api_data[self::ATTR_ICS_API_URL] = $ics_api_url; $api_data[self::ATTR_ICS_CHECKOUT_URL] = $ics_checkout_url; $api_data[self::ATTR_CURRENCY] = $currency; $api_data[self::ATTR_THUMBNAIL_ID] = $thumbnail_id; if (ai1ec_is_blank($ics_api_url)) { $api_data[self::ATTR_ACCOUNT] = $this->get_current_account(); $api_data[self::ATTR_CALENDAR_ID] = $this->get_current_calendar(); } $previous_data = $this->get_api_event_data($post_id); $new_data = array(); if (is_array($previous_data)) { foreach ($previous_data as $key => $value) { $new_data[$key] = $value; } } foreach ($api_data as $key => $value) { if (ai1ec_is_blank($value)) { unset($new_data[$key]); } else { $new_data[$key] = $api_data[$key]; } } return update_post_meta($post_id, self::API_EVENT_DATA, $new_data, $previous_data); }
/** * check if we are viewing events list * * @return boolean TRUE if we are on the events list FALSE otherwise */ private function _are_we_managing_events_list() { $path_details = pathinfo($_SERVER['SCRIPT_NAME']); $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : FALSE; if (FALSE === $post_type) { return FALSE; } $page = isset($_GET['page']) ? $_GET['page'] : ''; $events_list = 'edit.php' === $path_details['basename'] && 'ai1ec_event' === $post_type && ai1ec_is_blank($page); return $events_list; }
/** * Process vcalendar instance - add events to database. * * @param vcalendar $v Calendar to retrieve data from. * @param array $args Arbitrary arguments map. * * @throws Ai1ec_Parse_Exception * * @internal param array $args Array with events and configuration * * @return int Count of events added to database. */ public function add_vcalendar_events_to_db(array $args) { $cal = $this->_normalize_google_uids($args['source']); $feed = isset($args['feed']) ? $args['feed'] : null; $comment_status = isset($args['comment_status']) ? $args['comment_status'] : 'open'; $do_show_map = isset($args['do_show_map']) ? $args['do_show_map'] : 0; $count = 0; $events_in_db = isset($args['events_in_db']) ? $args['events_in_db'] : 0; $feed_name = $feed->feed_url; // Fetch default timezone in case individual properties don't define it $local_timezone = $this->_registry->get('date.timezone')->get_default_timezone(); $messages = array(); $current_timestamp = $this->_registry->get('date.time')->format_to_gmt(); // initialize empty custom exclusions structure $exclusions = array(); // go over each event foreach ($cal as $e) { // Event data array. $data = array(); // ===================== // = Start & end times = // ===================== $start = (array) $e->dtstart; $end = (array) $e->dtend; // For cases where a "VEVENT" calendar component // specifies a "DTSTART" property with a DATE value type but none // of "DTEND" nor "DURATION" property, the event duration is taken to // be one day. For cases where a "VEVENT" calendar component // specifies a "DTSTART" property with a DATE-TIME value type but no // "DTEND" property, the event ends on the same calendar date and // time of day specified by the "DTSTART" property. if (empty($end)) { // #1 if duration is present, assign it to end time $end = $e->duration; if (empty($end)) { // #2 if only DATE value is set for start, set duration to 1 day if (!isset($start['time']['hour'])) { $end = array('date' => array('year' => $start['date']['year'], 'month' => $start['date']['month'], 'day' => $start['date']['day'] + 1), 'time' => array('hour' => 0, 'minute' => 0, 'second' => 0)); // #3 set end date to start time $end = $start; } } } $categories = $e->categories; $imported_cat = array(Ai1ec_Event_Taxonomy::CATEGORIES => array()); // If the user chose to preserve taxonomies during import, add categories. if ($categories && $feed->keep_tags_categories) { $imported_cat = $this->add_categories_and_tags($categories, $imported_cat, false, true); } $feed_categories = $feed->feed_category; if (!empty($feed_categories)) { $imported_cat = $this->add_categories_and_tags($feed_categories, $imported_cat, false, false); } $tags = $e->x_tags; $imported_tags = array(Ai1ec_Event_Taxonomy::TAGS => array()); // If the user chose to preserve taxonomies during import, add tags. if ($tags && $feed->keep_tags_categories) { $imported_tags = $this->add_categories_and_tags($tags, $imported_tags, true, true); } $feed_tags = $feed->feed_tags; if (!empty($feed_tags)) { $imported_tags = $this->add_categories_and_tags($feed_tags, $imported_tags, true, true); } // Event is all-day if no time components are defined $allday = $this->_is_timeless((array) $start['time']) && $this->_is_timeless((array) $end['time']); // Also check the proprietary MS all-day field. $ms_allday = $e->x_microsoft_cdo_alldayevent; if (!empty($ms_allday) && 'TRUE' == $ms_allday) { $allday = true; } $event_timezone = $e->timezone; if ($allday) { $event_timezone = $local_timezone; } $start = $this->_time_array_to_datetime((array) $start['date'], (array) $start['time'], $event_timezone, $feed->import_timezone ? $local_timezone : null); $end = $this->_time_array_to_datetime((array) $end['date'], (array) $end['time'], $event_timezone, $feed->import_timezone ? $local_timezone : null); if (false === $start || false === $end) { throw new Ai1ec_Parse_Exception('Failed to parse one or more dates given timezone "' . var_export($event_timezone, true) . '"'); continue; } // If all-day, and start and end times are equal, then this event has // invalid end time (happens sometimes with poorly implemented iCalendar // exports, such as in The Event Calendar), so set end time to 1 day // after start time. if ($allday && $start->format() === $end->format()) { $end->adjust_day(+1); } $data += compact('start', 'end', 'allday'); // ======================================= // = Recurrence rules & recurrence dates = // ======================================= $rrule = $e->rrule; $rdate = $e->rdate; // ======================================= // = Exclusion rules & exclusion dates = // ======================================= $exrule = $e->exrule; $exdate = $e->exdate; // Add custom exclusions if there any $recurrence_id = $e->recurrence_id; if ('' === $recurrence_id && !empty($exclusions[$e->uid])) { if (isset($exdate[0])) { $exdate .= ','; } $exdate .= implode(',', $exclusions[$e->uid]); } // ======================== // = Latitude & longitude = // ======================== $latitude = $longitude = NULL; $geo_tag = $e->geo; if (!empty($geo_tag) && false !== strpos($geo_tag, ',')) { list($latitude, $longitude) = explode(',', $geo_tag, 2); $latitude = (double) $latitude; $longitude = (double) $longitude; } unset($geo_tag); if (NULL !== $latitude) { $data += compact('latitude', 'longitude'); // Check the input coordinates checkbox, otherwise lat/long data // is not present on the edit event page $data['show_coordinates'] = 1; } // =================== // = Venue & address = // =================== $data['country'] = ''; $data['city'] = ''; $data['province'] = ''; $data['postal_code'] = ''; $address = ''; $venue = ''; $location = $e->location; $matches = array(); // This regexp matches a venue / address in the format // "venue @ address" or "venue - address". preg_match('/\\s*(.*\\S)\\s+[\\-@]\\s+(.*)\\s*/', $location, $matches); // if there is no match, it's not a combined venue + address if (empty($matches)) { // temporary fix for Mac ICS import. Se AIOEC-2187 // and https://github.com/iCalcreator/iCalcreator/issues/13 $location = str_replace('\\n', "\n", $location); // if there is a comma, probably it's an address if (false === strpos($location, ',')) { $venue = $location; } else { $address = $location; } } else { $venue = isset($matches[1]) ? $matches[1] : ''; $address = isset($matches[2]) ? $matches[2] : ''; } // ===================================================== // = Set show map status based on presence of location = // ===================================================== $event_do_show_map = $do_show_map; if (1 === $do_show_map && NULL === $latitude && empty($address)) { $event_do_show_map = 0; } // ================== // = Cost & tickets = // ================== $cost = $e->x_cost; $ticket_url = $e->x_tickets_url; // =============================== // = Contact name, phone, e-mail = // =============================== // Initialize default values $data['contact_email'] = ''; $data['contact_url'] = ''; $data['contact_phone'] = ''; $data['contact_name'] = ''; $organizer = $e->organizer; if ('MAILTO:' === substr($organizer, 0, 7) && false === strpos($organizer, '@')) { $organizer = substr($organizer, 7); } $contact = $e->contact; $elements = explode(';', $contact, 4); foreach ($elements as $el) { $el = trim($el); // Detect e-mail address. if (false !== strpos($el, '@')) { $data['contact_email'] = $el; } elseif (false !== strpos($el, '://')) { $data['contact_url'] = $el; } elseif (preg_match('/\\d/', $el)) { $data['contact_phone'] = $el; } else { $data['contact_name'] = $el; } } if (!isset($data['contact_name']) || !$data['contact_name']) { // If no contact name, default to organizer property. $data['contact_name'] = $organizer; } $description = stripslashes(str_replace('\\n', "\n", $e->description)); $description = $this->_remove_ticket_url($description); // Store yet-unsaved values to the $data array. $data += array('recurrence_rules' => $rrule, 'exception_rules' => $exrule, 'recurrence_dates' => $rdate, 'exception_dates' => $exdate, 'venue' => $venue, 'address' => $address, 'cost' => $cost, 'ticket_url' => $ticket_url, 'show_map' => $event_do_show_map, 'ical_feed_url' => $feed->feed_url, 'ical_source_url' => $e->url, 'ical_organizer' => $organizer, 'ical_contact' => $contact, 'ical_uid' => $this->_get_ical_uid($e), 'categories' => array_keys($imported_cat[Ai1ec_Event_Taxonomy::CATEGORIES]), 'tags' => array_keys($imported_tags[Ai1ec_Event_Taxonomy::TAGS]), 'feed' => $feed, 'post' => array('post_status' => 'publish', 'comment_status' => $comment_status, 'post_type' => AI1EC_POST_TYPE, 'post_author' => 1, 'post_title' => $e->summary, 'post_content' => $description)); // register any custom exclusions for given event $exclusions = $this->_add_recurring_events_exclusions($e, $exclusions, $start); // Create event object. $data = apply_filters('ai1ec_pre_init_event_from_feed', $data, $e, $feed); $event = $this->_registry->get('model.event', $data); // Instant Event $is_instant = $e->x_instant_event; if ($is_instant) { $event->set_no_end_time(); } $recurrence = $event->get('recurrence_rules'); $search = $this->_registry->get('model.search'); // first let's check by UID $matching_event_id = $search->get_matching_event_by_uid_and_url($event->get('ical_uid'), $event->get('ical_feed_url')); // if no result, perform the legacy check. if (null === $matching_event_id) { $matching_event_id = $search->get_matching_event_id($event->get('ical_uid'), $event->get('ical_feed_url'), $event->get('start'), !empty($recurrence)); } if (null === $matching_event_id) { // ================================================= // = Event was not found, so store it and the post = // ================================================= $event->save(); $count++; } else { // ====================================================== // = Event was found, let's store the new event details = // ====================================================== $uid_cal = $e->uid; if (!ai1ec_is_blank($uid_cal)) { $uid_cal_original = sprintf($event->get_uid_pattern(), $matching_event_id); if ($uid_cal_original === $uid_cal) { //avoiding cycle import //ignore the event, it belongs to site unset($events_in_db[$matching_event_id]); continue; } } // Update the post $post = get_post($matching_event_id); if (null !== $post) { $post->post_title = $event->get('post')->post_title; $post->post_content = $event->get('post')->post_content; wp_update_post($post); // Update the event $event->set('post_id', $matching_event_id); $event->set('post', $post); $event->save(true); $count++; } } do_action('ai1ec_ics_event_saved', $event, $feed); // import not standard taxonomies. unset($imported_cat[Ai1ec_Event_Taxonomy::CATEGORIES]); foreach ($imported_cat as $tax_name => $ids) { wp_set_post_terms($event->get('post_id'), array_keys($ids), $tax_name); } unset($imported_tags[Ai1ec_Event_Taxonomy::TAGS]); foreach ($imported_tags as $tax_name => $ids) { wp_set_post_terms($event->get('post_id'), array_keys($ids), $tax_name); } // import the metadata used by ticket events $cost_type = $e->x_cost_type; if ($cost_type && false === ai1ec_is_blank($cost_type)) { update_post_meta($event->get('post_id'), '_ai1ec_cost_type', $cost_type); } $api_event_id = $e->x_api_event_id; if ($api_event_id && false === ai1ec_is_blank($api_event_id)) { $api_event_id = $api_event_id; } else { $api_event_id = null; } $api_url = $e->x_api_url; if ($api_url && false === ai1ec_is_blank($api_url)) { $api_url = $api_url; } else { $api_url = null; } $checkout_url = $e->x_checkout_url; if ($checkout_url && false === ai1ec_is_blank($checkout_url)) { $checkout_url = $checkout_url; } else { $checkout_url = null; } $currency = $e->x_api_event_currency; if (!$currency || ai1ec_is_blank($currency)) { $currency = null; } if ($api_event_id || $api_url || $checkout_url || $currency) { if (!isset($api)) { $api = $this->_registry->get('model.api.api-ticketing'); } $api->save_api_event_data($event->get('post_id'), $api_event_id, $api_url, $checkout_url, $currency); } $wp_images_url = $e->x_wp_image_url; if ($wp_images_url && false === ai1ec_is_blank($wp_images_url)) { $images_arr = explode(',', $wp_images_url); foreach ($images_arr as $key => $value) { $images_arr[$key] = explode(';', $value); } if (count($images_arr) > 0) { update_post_meta($event->get('post_id'), '_featured_image', $images_arr); } } unset($events_in_db[$event->get('post_id')]); } //close while iteration return array('count' => $count, 'events_to_delete' => $events_in_db, 'messages' => $messages, 'name' => $feed_name); }
/** * Handle PRE (ticket event) update. * Just handle the Ticket Events, other kind of post are ignored * @wp_hook pre_post_update * */ public function pre_post_update($post_id, $new_post_data) { // LABEL:magicquotes // remove WordPress `magical` slashes - we work around it ourselves $_POST = stripslashes_deep($_POST); $api = $this->_registry->get('model.api.api-ticketing'); $action = $this->current_action(); switch ($action) { case 'inline-save': //quick edit from edit page $fields = array(); if (false === ai1ec_is_blank($_REQUEST['post_title'])) { $fields['title'] = $_REQUEST['post_title']; } if (false === ai1ec_is_blank($_REQUEST['_status'])) { $fields['status'] = $_REQUEST['_status']; } if (isset($_REQUEST['keep_private']) && 'private' === $_REQUEST['keep_private']) { $fields['visibility'] = 'private'; } else { if (isset($_REQUEST['post_password']) && false === ai1ec_is_blank($_REQUEST['post_password'])) { $fields['visibility'] = 'password'; } } if (0 < count($fields)) { $post = get_post($post_id); $ajax = defined('DOING_AJAX') && DOING_AJAX; $message = $api->update_api_event_fields($post, $fields, 'update', $ajax); if (null !== $message) { if ($ajax) { wp_die($message); } else { wp_redirect($this->get_sendback_page($post_id)); exit; } } } return; case 'edit': //bulk edition from edit page $fields = array(); if (false === ai1ec_is_blank($_REQUEST['_status'])) { $fields['status'] = $_REQUEST['_status']; } if (0 < count($fields)) { $post = get_post($post_id); $ajax = defined('DOING_AJAX') && DOING_AJAX; $message = $api->update_api_event_fields($post, $fields, 'update', $ajax); if (null !== $message) { if ($ajax) { wp_die($message); } else { wp_redirect($this->get_sendback_page($post_id)); exit; } } } return; case 'editpost': //edition from post page $new_post_data['ID'] = $post_id; $post = new WP_Post((object) $new_post_data); if (false === $this->is_valid_event($post)) { break; } $data = $this->_parse_post_to_event($post_id); if (!$data) { break; } $event = $data['event']; $cost_type = isset($_REQUEST['ai1ec_cost_type']) ? $_REQUEST['ai1ec_cost_type'] : ''; if ('tickets' === $cost_type) { $result = $api->store_event($event, $post, true); if (true !== $result) { wp_redirect($this->get_sendback_page($post_id)); exit; } } else { $message = $api->delete_api_event($post_id, 'update', false); if (null !== $message) { wp_redirect($this->get_sendback_page($post_id)); exit; } } break; default: break; } // LABEL:magicquotes // restore `magic` WordPress quotes to maintain compatibility $_POST = add_magic_quotes($_POST); }
/** * Convert an event from a feed into a new Ai1ec_Event object and add it to * the calendar. * * @param Ai1ec_Event $event Event object. * @param vcalendar $calendar Calendar object. * @param bool $export States whether events are created for export. * @param array $params Additional parameters for export. * * @return void */ protected function _insert_event_in_calendar(Ai1ec_Event $event, vcalendar $calendar, $export = false, array $params = array()) { $tz = $this->_registry->get('date.timezone')->get_default_timezone(); $e =& $calendar->newComponent('vevent'); $uid = ''; if ($event->get('ical_uid')) { $uid = addcslashes($event->get('ical_uid'), "\\;,\n"); } else { $uid = $event->get_uid(); $event->set('ical_uid', $uid); $event->save(true); } $e->setProperty('uid', $this->_sanitize_value($uid)); $e->setProperty('url', get_permalink($event->get('post_id'))); // ========================= // = Summary & description = // ========================= $e->setProperty('summary', $this->_sanitize_value(html_entity_decode(apply_filters('the_title', $event->get('post')->post_title), ENT_QUOTES, 'UTF-8'))); $content = apply_filters('ai1ec_the_content', apply_filters('the_content', $event->get('post')->post_content)); $post_meta_values = get_post_meta($event->get('post_id'), '', false); $cost_type = null; if ($post_meta_values) { foreach ($post_meta_values as $key => $value) { if ('_ai1ec_cost_type' === $key) { $cost_type = $value[0]; } if (isset($params['xml']) && $params['xml'] && false !== preg_match('/^x\\-meta\\-/i', $key)) { $e->setProperty($key, $this->_sanitize_value($value)); } } } if (false === ai1ec_is_blank($cost_type)) { $e->setProperty('X-COST-TYPE', $this->_sanitize_value($cost_type)); } $url = ''; $api = $this->_registry->get('model.api.api-ticketing'); $api_event_id = $api->get_api_event_id($event->get('post_id')); if ($api_event_id) { //getting all necessary informations that will be necessary on imported ticket events $e->setProperty('X-API-EVENT-ID', $api_event_id); $e->setProperty('X-API-URL', $api->get_api_event_url($event->get('post_id'))); $e->setProperty('X-CHECKOUT-URL', $api->get_api_event_checkout_url($event->get('post_id'))); $e->setProperty('X-API-EVENT-CURRENCY', $api->get_api_event_currency($event->get('post_id'))); } else { if ($event->get('ticket_url')) { $url = $event->get('ticket_url'); } } //Adding Ticket URL to the Description field if (false === ai1ec_is_blank($url)) { $content = $this->_remove_ticket_url($content); $content = $content . '<p>' . __('Tickets: ', AI1EC_PLUGIN_NAME) . '<a class="ai1ec-ticket-url-exported" href="' . $url . '">' . $url . '</a>.</p>'; } $content = str_replace(']]>', ']]>', $content); $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8'); // Prepend featured image if available. $size = null; $avatar = $this->_registry->get('view.event.avatar'); $matches = $avatar->get_image_from_content($content); // if no img is already present - add thumbnail if (empty($matches)) { $post_id = get_post_thumbnail_id($event->get('post_id')); $images = null; $added = null; foreach (array('thumbnail', 'medium', 'large', 'full') as $_size) { $attributes = wp_get_attachment_image_src($post_id, $_size); if (false !== $attributes) { $key_str = sprintf('%d_%d', $attributes[1], $attributes[2]); if (null === $added || false === isset($added[$key_str])) { $added[$key_str] = true; array_unshift($attributes, $_size); $images[] = implode(';', $attributes); } } } if (null !== $images) { $e->setProperty('X-WP-IMAGES-URL', $this->_sanitize_value(implode(',', $images))); } if ($img_url = $avatar->get_post_thumbnail_url($event, $size)) { $content = '<div class="ai1ec-event-avatar alignleft timely"><img src="' . esc_attr($img_url) . '" width="' . $size[0] . '" height="' . $size[1] . '" /></div>' . $content; } } if (isset($params['no_html']) && $params['no_html']) { $e->setProperty('description', $this->_sanitize_value(strip_tags(strip_shortcodes($content)))); if (!empty($content)) { $html_content = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">\\n' . '<HTML>\\n<HEAD>\\n<TITLE></TITLE>\\n</HEAD>\\n<BODY>' . $content . '</BODY></HTML>'; $e->setProperty('X-ALT-DESC', $this->_sanitize_value($html_content), array('FMTTYPE' => 'text/html')); unset($html_content); } } else { $e->setProperty('description', $this->_sanitize_value($content)); } $revision = (int) current(array_keys(wp_get_post_revisions($event->get('post_id')))); $e->setProperty('sequence', $revision); // ===================== // = Start & end times = // ===================== $dtstartstring = ''; $dtstart = $dtend = array(); if ($event->is_allday()) { $dtstart['VALUE'] = $dtend['VALUE'] = 'DATE'; // For exporting all day events, don't set a timezone if ($tz && !$export) { $dtstart['TZID'] = $dtend['TZID'] = $tz; } // For exportin' all day events, only set the date not the time if ($export) { $e->setProperty('dtstart', $this->_sanitize_value($event->get('start')->format('Ymd')), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format('Ymd')), $dtend); } else { $e->setProperty('dtstart', $this->_sanitize_value($event->get('start')->format("Ymd\\T")), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format("Ymd\\T")), $dtend); } } else { if ($tz) { $dtstart['TZID'] = $dtend['TZID'] = $tz; } // This is used later. $dtstartstring = $event->get('start')->format("Ymd\\THis"); $e->setProperty('dtstart', $this->_sanitize_value($dtstartstring), $dtstart); if (false === (bool) $event->get('instant_event')) { $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format("Ymd\\THis")), $dtend); } } // ======================== // = Latitude & longitude = // ======================== if (floatval($event->get('latitude')) || floatval($event->get('longitude'))) { $e->setProperty('geo', $event->get('latitude'), $event->get('longitude')); } // =================== // = Venue & address = // =================== if ($event->get('venue') || $event->get('address')) { $location = array($event->get('venue'), $event->get('address')); $location = array_filter($location); $location = implode(' @ ', $location); $e->setProperty('location', $this->_sanitize_value($location)); } $categories = array(); $language = get_bloginfo('language'); foreach ($this->_taxonomy_model->get_post_categories($event->get('post_id')) as $cat) { if ('events_categories' === $cat->taxonomy) { $categories[] = $cat->name; } } $e->setProperty('categories', implode(',', $categories), array("LANGUAGE" => $language)); $tags = array(); foreach ($this->_taxonomy_model->get_post_tags($event->get('post_id')) as $tag) { $tags[] = $tag->name; } if (!empty($tags)) { $e->setProperty('X-TAGS', implode(',', $tags), array("LANGUAGE" => $language)); } // ================== // = Cost & tickets = // ================== if ($event->get('cost')) { $e->setProperty('X-COST', $this->_sanitize_value($event->get('cost'))); } if ($event->get('ticket_url')) { $e->setProperty('X-TICKETS-URL', $this->_sanitize_value($event->get('ticket_url'))); } // ================= // = Instant Event = // ================= if ($event->is_instant()) { $e->setProperty('X-INSTANT-EVENT', $this->_sanitize_value($event->is_instant())); } // ==================================== // = Contact name, phone, e-mail, URL = // ==================================== $contact = array($event->get('contact_name'), $event->get('contact_phone'), $event->get('contact_email'), $event->get('contact_url')); $contact = array_filter($contact); $contact = implode('; ', $contact); $e->setProperty('contact', $this->_sanitize_value($contact)); // ==================== // = Recurrence rules = // ==================== $rrule = array(); $recurrence = $event->get('recurrence_rules'); $recurrence = $this->_filter_rule($recurrence); if (!empty($recurrence)) { $rules = array(); foreach (explode(';', $recurrence) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $rrule[$k] = $v; } } // =================== // = Exception rules = // =================== $exceptions = $event->get('exception_rules'); $exceptions = $this->_filter_rule($exceptions); $exrule = array(); if (!empty($exceptions)) { $rules = array(); foreach (explode(';', $exceptions) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $exrule[$k] = $v; } } // add rrule to exported calendar if (!empty($rrule) && !isset($rrule['RDATE'])) { $e->setProperty('rrule', $this->_sanitize_value($rrule)); } // add exrule to exported calendar if (!empty($exrule) && !isset($exrule['EXDATE'])) { $e->setProperty('exrule', $this->_sanitize_value($exrule)); } // =================== // = Exception dates = // =================== // For all day events that use a date as DTSTART, date must be supplied // For other other events which use DATETIME, we must use that as well // We must also match the exact starting time $recurrence_dates = $event->get('recurrence_dates'); $recurrence_dates = $this->_filter_rule($recurrence_dates); if (!empty($recurrence_dates)) { $params = array('VALUE' => 'DATE-TIME', 'TZID' => $tz); $dt_suffix = $event->get('start')->format('\\THis'); foreach (explode(',', $recurrence_dates) as $exdate) { // date-time string in EXDATES is formatted as 'Ymd\THis\Z', that // means - in UTC timezone, thus we use `format_to_gmt` here. $exdate = $this->_registry->get('date.time', $exdate)->format_to_gmt('Ymd'); $e->setProperty('rdate', array($exdate . $dt_suffix), $params); } } $exception_dates = $event->get('exception_dates'); $exception_dates = $this->_filter_rule($exception_dates); if (!empty($exception_dates)) { $params = array('VALUE' => 'DATE-TIME', 'TZID' => $tz); $dt_suffix = $event->get('start')->format('\\THis'); foreach (explode(',', $exception_dates) as $exdate) { // date-time string in EXDATES is formatted as 'Ymd\THis\Z', that // means - in UTC timezone, thus we use `format_to_gmt` here. $exdate = $this->_registry->get('date.time', $exdate)->format_to_gmt('Ymd'); $e->setProperty('exdate', array($exdate . $dt_suffix), $params); } } return $calendar; }
/** * Search for the API message error */ protected function _get_api_error_msg($response) { if (isset($response) && false === is_wp_error($response)) { $response_body = json_decode($response['body'], true); if (json_last_error() === JSON_ERROR_NONE && isset($response_body) && isset($response_body['errors'])) { $errors = $response_body['errors']; if (false === is_array($errors)) { $errors = array($errors); } $messages = null; foreach ($errors as $key => $value) { if (false === ai1ec_is_blank($value)) { if (is_array($value)) { $value = implode(', ', $value); } $messages[] = $value; } } if (null !== $messages && false === empty($messages)) { return implode(', ', $messages); } } } return null; }
/** * Save the submitter information into post metadata */ public function save_submitter_info($is_submitter, $submitter_email, $submitter_name) { $post_id = $this->get('post_id'); if (empty($post_id)) { throw new Exception('Post id empty'); } $save = false; if (1 === intval($is_submitter)) { $submitter_info['is_organizer'] = 1; if (false === ai1ec_is_blank($this->get('contact_email'))) { $save = true; } } else { $submitter_info['is_organizer'] = 0; if (false === ai1ec_is_blank($submitter_email)) { $submitter_info['email'] = trim($submitter_email); $submitter_info['name'] = trim($submitter_name); $save = true; } } if ($save) { update_post_meta($post_id, '_submitter_info', json_encode($submitter_info)); } }
public function send_feedback_message() { if (ai1ec_is_blank($_POST['name']) || ai1ec_is_blank($_POST['email']) || ai1ec_is_blank($_POST['site']) || ai1ec_is_blank($_POST['message'])) { throw new Exception('All fields are required'); } $subject = __('Feedback provided by user', AI1EC_PLUGIN_NAME); $content = sprintf('<b>%s:</b><br/>%s<br/><br/><b>%s:</b><br/>%s<br/><br/><b>%s:</b><br/>%s<br/><br/><b>%s:</b><br/>%s', __('Name', AI1EC_PLUGIN_NAME), $_POST['name'], __('E-mail', AI1EC_PLUGIN_NAME), $_POST['email'], __('Site URL', AI1EC_PLUGIN_NAME), $_POST['site'], __('Message', AI1EC_PLUGIN_NAME), nl2br($_POST['message'])); $dispatcher = $this->_registry->get('notification.email', $content, explode(',', self::EMAIL_FEEDBACK_DESTINATION), $subject); $headers = array('Content-type: text/html', sprintf('From: %s <%s>', $_POST['name'], $_POST['email'])); if ($dispatcher->send($headers)) { $_POST['feedback'] = 'n'; $this->save_feedback_review(); } }