private function _send_notification_email($event_id, $user_id) { $user = get_user_by('id', $user_id); $subject = $this->_data->get_option('eab_rsvps-email_me-subject'); $body = $this->_data->get_option('eab_rsvps-email_me-body'); $admin_email = get_option('admin_email'); if (empty($subject) || empty($body)) { return false; } $headers = array('Content-Type: ' . $this->email_charset() . '; charset="' . get_option('blog_charset') . '"'); $codec = new Eab_Events_RsvpEmailMe_Codec($event_id, $user_id); add_filter('wp_mail_content_type', array($this, 'email_charset')); if ($this->_data->get_option('eab_rsvps-email_me-notify_admin')) { wp_mail($admin_email, $codec->expand($subject, Eab_Macro_Codec::FILTER_TITLE), $codec->expand($body, Eab_Macro_Codec::FILTER_BODY), $headers); } if ($this->_data->get_option('eab_rsvps-email_me-notify_author')) { $event = new Eab_EventModel(get_post($event_id)); $author_id = $event->get_author(); if ($author_id) { $author = get_user_by('id', $author_id); if ($author->user_email != $admin_email) { wp_mail($author->user_email, $codec->expand($subject, Eab_Macro_Codec::FILTER_TITLE), $codec->expand($body, Eab_Macro_Codec::FILTER_BODY), $headers); } } } remove_filter('wp_mail_content_type', array($this, 'email_charset')); }
/** * Gets a list of upcoming events. * Only the events that are not yet over will be returned. */ public static function get_upcoming_events($limit = 5) { if (!eab_has_post_indexer()) { return array(); } $limit = (int) $limit ? (int) $limit : 5; global $wpdb; $result = array(); $count = 0; $pi_table = eab_pi_get_table(); $pi_published = eab_pi_get_post_date(); $pi_blog_id = eab_pi_get_blog_id(); $pi_post_id = eab_pi_get_post_id(); $raw_network_events = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}{$pi_table} WHERE post_type='incsub_event' ORDER BY {$pi_published} DESC"); if (!$raw_network_events) { return $result; } foreach ($raw_network_events as $event) { if ($count == $limit) { break; } switch_to_blog($event->{$pi_blog_id}); $post = get_post($event->{$pi_post_id}); $tmp_event_instance = new Eab_EventModel($post); $tmp_event_instance->cache_data(); if ($tmp_event_instance->is_expired()) { continue; } $post->blog_id = $event->{$pi_blog_id}; $result[] = $post; $count++; restore_current_blog(); } return $result; }
function my_events_time_format($formatted, $original, $event_id) { $event = new Eab_EventModel(get_post($event_id)); if ($event->has_no_start_time()) { return "All day event"; } return "Starting Time: " . date_i18n('h:i A', $original); }
function widget($args, $instance) { global $wpdb, $current_site, $post, $wiki_tree; extract($args); if ($post->post_type != 'incsub_event') { return; } $options = $instance; $event = new Eab_EventModel($post); $title = apply_filters('widget_title', empty($instance['title']) ? __('Attendees', $this->translation_domain) : $instance['title'], $instance, $this->id_base); if (is_single() && $event->has_bookings()) { ?> <?php echo $before_widget; ?> <?php echo $before_title . $title . $after_title; ?> <div id="event-bookings"> <div id="event-booking-yes"> <?php echo Eab_Template::get_bookings(Eab_EventModel::BOOKING_YES, $event); ?> </div> <div class="clear"></div> <div id="event-booking-maybe"> <?php echo Eab_Template::get_bookings(Eab_EventModel::BOOKING_MAYBE, $event); ?> </div> </div> <br /> <?php echo $after_widget; ?> <?php } ?> <?php }
function send_email_non_paid_members_callback() { global $wpdb; $data = stripslashes_deep($_POST); $event_id = !empty($data['event_id']) && (int) $data['event_id'] ? (int) $data['event_id'] : false; $status = 'yes'; //!empty($data['status']) ? $data['status'] : false; $response = array('status' => 1, 'sent' => 0); if (!$event_id || !$status) { die(json_encode($response)); } $event = new Eab_EventModel(get_post($event_id)); if (!$event->is_premium()) { die(json_encode($response)); } // Not a paid event $all_events = array($event); if ($event->is_recurring()) { $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event); } $all_event_ids = array(); foreach ($all_events as $e) { $all_event_ids[] = $e->get_id(); } $all_event_ids = array_filter(array_map('intval', $all_event_ids)); $bookings = $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status = %s ORDER BY timestamp;", $status)); if (!count($bookings)) { die(json_encode($response)); } foreach ($bookings as $booking) { if ($event->user_paid($booking->user_id)) { continue; } $this->_send_notification_email($event->get_id(), $user_id); $response['sent'] += 1; } $response['status'] = 0; die(json_encode($response)); }
private function _reset_expired_bookings($since) { //$rsvps = Eab_EventModel::get_bookings(Eab_EventModel::BOOKING_YES, $since); $rsvps = Eab_EventModel::get_bookings(Eab_EventModel::BOOKING_YES); // Just reset all the expired bookings. $now = eab_current_time(); $cutoff_limit = $this->_data->get_option('rsvp_auto_reset-cutoff'); $cutoff_limit = $cutoff_limit ? $cutoff_limit : 3600; $callback = (int) $this->_data->get_option('rsvp_auto_reset-remove_attendance') ? 'delete_attendance' : 'cancel_attendance'; $events = array(); // Events cache foreach ($rsvps as $rsvp) { // Check time difference $time_diff = $now - strtotime($rsvp->timestamp); if ($time_diff < $cutoff_limit) { continue; } // This one still has time to pay // Check event premium status if (empty($events[$rsvp->event_id])) { $events[$rsvp->event_id] = new Eab_EventModel(get_post($rsvp->event_id)); } if (!$events[$rsvp->event_id]->is_premium()) { continue; } // Not a paid event, carry on // Check user payment if ($events[$rsvp->event_id]->user_paid($rsvp->user_id)) { continue; } // User paid for event, we're good here. // If we got here, we should reset the users RSVP if (is_callable(array($events[$rsvp->event_id], $callback))) { $events[$rsvp->event_id]->{$callback}($rsvp->user_id); } } }
public function export_attendees() { error_reporting(0); if (!$this->_event_id) { wp_die(__('No event to export', Eab_EventsHub::TEXT_DOMAIN)); } $event = new Eab_EventModel(get_post($this->_event_id)); $attendees = array(); $statuses = $this->_get_statuses(); foreach ($statuses as $status => $title) { $bookings = $this->_get_bookings($status); foreach ($bookings as $booking) { $user_data = get_userdata($booking->user_id); if ($event->get_id() !== $booking->event_id) { $event = new Eab_EventModel(get_post($booking->event_id)); } $payment_status = $ticket_count = __('N/A', Eab_EventsHub::TEXT_DOMAIN); if (Eab_EventModel::BOOKING_NO != $status) { $ticket_count = $event->get_booking_meta($booking->id, 'booking_ticket_count'); $ticket_count = $ticket_count ? $ticket_count : 1; if ($event->is_premium()) { $payment_status = $event->user_paid($booking->user_id) ? __('Yes', Eab_EventsHub::TEXT_DOMAIN) : __('No', Eab_EventsHub::TEXT_DOMAIN); } } $attendees[] = apply_filters('eab-exporter-csv-row', array(__('User ID', Eab_EventsHub::TEXT_DOMAIN) => $user_data->id, __('User Name', Eab_EventsHub::TEXT_DOMAIN) => apply_filters('eab-guest_list-export-guest_name', $user_data->display_name, $booking->user_id, $user_data), __('User Email', Eab_EventsHub::TEXT_DOMAIN) => $user_data->user_email, __('Attending', Eab_EventsHub::TEXT_DOMAIN) => $title, __('Ticket Count', Eab_EventsHub::TEXT_DOMAIN) => $ticket_count, __('Payment Status', Eab_EventsHub::TEXT_DOMAIN) => $payment_status), $event, $booking, $user_data); } } $delimiter = apply_filters('eab-exporter-csv-field_delimiter', $this->_delimiter); $fp = fopen('php://output', 'w'); fputcsv($fp, array_keys($attendees[0]), $delimiter); foreach ($attendees as $res) { fputcsv($fp, $res, $delimiter); } }
public function json_import_nearby_events() { $data = stripslashes_deep($_POST); $lat = (double) $data['lat']; $lng = (double) $data['lng']; if (empty($lat) || empty($lng)) { wp_send_json(array('status' => 0, 'msg' => __('Invalid location', Eab_EventsHub::TEXT_DOMAIN))); } $events = $this->_meetup->get_nearby_events($lat, $lng, 100); if (empty($events) || empty($events['results'])) { wp_send_json(array('status' => 1, 'msg' => __('There were no events to import', Eab_EventsHub::TEXT_DOMAIN))); } $imported = $this->_import_events($events); if (empty($imported)) { wp_send_json(array('status' => 0, 'msg' => __('No events imported.', Eab_EventsHub::TEXT_DOMAIN))); } $result = array(); foreach ($imported as $event_id) { if (empty($event_id)) { continue; } $event = new Eab_EventModel(get_post($event_id)); $result[] = '<a href="' . admin_url('post.php?action=edit&post=' . $event->get_id()) . '">' . $event->get_title() . '</a>'; } $result[] = sprintf(__('%s events successfully imported', Eab_EventsHub::TEXT_DOMAIN), count($result)); wp_send_json(array('status' => 1, 'msg' => join('<br />', $result))); }
<?php global $blog_id, $wp_query, $booking, $post, $current_user; $event = new Eab_EventModel($post); get_header(); ?> <?php the_post(); $start_day = date_i18n('m', strtotime(get_post_meta($post->ID, 'incsub_event_start', true))); ?> <div id="primary"> <div id="content" role="main"> <div class="event <?php echo Eab_Template::get_status_class($post); ?> " id="wpmudevevents-wrapper"> <div id="wpmudevents-single"> <div class="wpmudevevents-header"> <h2><?php echo $event->get_title(); ?> </h2><br /> <div class="wpmudevevents-contentmeta" style="clear:both"> <?php echo Eab_Template::get_event_details($event); ?> </div> </div>
/** * Add manual payment link inside the RSVP box */ function add_approve_payment($content, $user_id) { global $post; $payments = maybe_unserialize(stripslashes(Eab_EventModel::get_booking_meta($post->ID, "manual_payment"))); if (is_array($payments)) { foreach ($payments as $payment) { if ($payment["id"] == $user_id and $payment["stat"] == 'pending') { $content .= '<div class="eab-guest-actions" id="div_approve_payment_' . $user_id . '"> <a id="approve_payment_' . $user_id . '" href="javascript:void(0)" class="eab-guest-manual_payment" >' . __('Approve Payment', Eab_EventsHub::TEXT_DOMAIN) . '</a></div>'; $content .= '<script type="text/javascript">'; $content .= 'jQuery(document).ready(function($){ $("#approve_payment_' . $user_id . '").click(function() { if (confirm("Are you sure to approve this payment?")){ $.post(ajaxurl, { "action": "eab_approve_manual_payment", "user_id":' . $user_id . ', "event_id":' . $post->ID . ' }, function (data) { if (data && data.error) {alert(data.error);} else { $("#div_approve_payment_' . $user_id . '").parent(".eab-guest").find(".eab-guest-payment_info").html("paid"); $("#div_approve_payment_' . $user_id . '").remove(); } }, "json"); return false; } else {return false;} }); });'; $content .= '</script>'; } } } return $content; }
function handle_attendance_add() { $eab = events_and_bookings(); $data = stripslashes_deep($_POST); $email = $data['user']; $status = $data['status']; $post_id = (int) $data['post_id']; $allowed = array(Eab_EventModel::BOOKING_YES, Eab_EventModel::BOOKING_NO, Eab_EventModel::BOOKING_MAYBE); $post = get_post($post_id); if (is_email($email) && $post_id && in_array($status, $allowed)) { $user = get_user_by('email', $email); if ($user && !empty($user->ID)) { $event = new Eab_EventModel($post); $event->add_attendance($user->ID, $status); } } echo $eab->meta_box_part_bookings($post); die; }
/** * Maps order to a related Event ID, if possible. */ function order_to_event_id($product_id, $variation = array()) { $event_id = get_post_meta($product_id, 'eab_event_id', true); if (!$event_id) { return false; } $event = new Eab_EventModel(get_post($event_id)); if (!$event->is_recurring()) { return $event_id; } // Event is recurring, check SKUs return !empty($variation['SKU']) ? $variation['SKU'] : false; }
function get_payment_forms($form, $event_id) { $event = new Eab_EventModel($event_id); $price = $event->get_price(); if (!is_array($price)) { return $form; } $selection = '<select id="" name="amount">'; foreach ($price as $tier) { $selection .= '<option value="' . (double) $tier['fee'] . '">' . $tier['label'] . ": " . $this->_data->get_option("currency") . " " . $tier['fee'] . '</option>'; } $selection .= '</select>'; global $blog_id, $current_user; $content .= $this->_data->get_option('paypal_sandbox') ? '<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">' : '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">'; $content .= '<input type="hidden" name="business" value="' . $this->_data->get_option('paypal_email') . '" />'; $content .= '<input type="hidden" name="item_name" value="' . esc_attr($event->get_title()) . '" />'; $content .= '<input type="hidden" name="item_number" value="' . $event->get_id() . '" />'; $content .= '<input type="hidden" name="notify_url" value="' . admin_url('admin-ajax.php?action=eab_paypal_ipn&blog_id=' . $blog_id . '&booking_id=' . $booking_id) . '" />'; $content .= '<br />' . __('Please, select price tier', Eab_EventsHub::TEXT_DOMAIN) . ' ' . $selection; $content .= '<input type="hidden" name="return" value="' . get_permalink($event->get_id()) . '" />'; $content .= '<input type="hidden" name="currency_code" value="' . $this->_data->get_option('currency') . '">'; $content .= '<input type="hidden" name="cmd" value="_xclick" />'; // Add multiple tickets $extra_attributes = apply_filters('eab-payment-paypal_tickets-extra_attributes', $extra_attributes, $event->get_id(), $booking_id); $content .= '' . sprintf('<p>' . __('I want to buy %s ticket(s)', Eab_EventsHub::TEXT_DOMAIN) . '</p>', '<input type="number" size="2" name="quantity" value="1" min="1" ' . $extra_attributes . ' />'); $content .= '<input type="image" name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif" alt="PayPal - The safer, easier way to pay online" />'; $content .= '<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" />'; $content .= '</form>'; return $content; }
private function _edit_event_form($event_id) { add_action('get_footer', array($this, 'enqueue_dependency_data')); $post = $event_id ? get_post($event_id) : false; $event = new Eab_EventModel($post); $this->_enqueue_dependencies(); $style = $event->get_id() ? '' : 'style="display:none"'; $ret .= '<div id="eab-events-fpe">'; $ret .= '<a id="eab-events-fpe-back_to_event" href="' . get_permalink($event->get_id()) . '" ' . $style . '>' . __('Back to Event', Eab_EventsHub::TEXT_DOMAIN) . '</a>'; $ret .= '<input type="hidden" id="eab-events-fpe-event_id" value="' . (int) $event->get_id() . '" />'; $ret .= '<div>'; $ret .= '<label>' . __('Title', Eab_EventsHub::TEXT_DOMAIN) . '</label>'; $ret .= '<br /><input type="text" name="" id="eab-events-fpe-event_title" value="' . esc_attr($event->get_title()) . '" />'; $ret .= '</div>'; $ret .= '<div id="fpe-editor"></div>'; $ret .= $this->_get_event_meta_boxes($event); $ret .= '</div>'; return $ret; }
protected function _get_item_data($post) { if (isset($post->blog_id)) { // Originates from network switch_to_blog($post->blog_id); $event = new Eab_EventModel($post); $event_starts = $event->get_start_dates(); $event_ends = $event->get_end_dates(); restore_current_blog(); } else { // Originates from this blog $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post); $event_starts = $event->get_start_dates(); $event_ends = $event->get_end_dates(); } $res = array('id' => $event->get_id(), 'title' => $event->get_title(), 'event_starts' => $event_starts, 'event_ends' => $event_ends, 'status_class' => Eab_Template::get_status_class($event), 'event_venue' => $event->get_venue_location(), 'categories' => $event->get_categories()); if (isset($post->blog_id)) { $res['blog_id'] = $post->blog_id; } return $res; }
public static function get_admin_bookings($status, $post) { global $wpdb; if (!current_user_can('edit_posts')) { return false; } // Basic sanity check $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post); $statuses = self::get_rsvp_status_list(); if (!in_array($status, array_keys($statuses))) { return false; } // Unknown status $status_name = $statuses[$status]; //$content = Eab_Template::get_admin_attendance_addition_form($event, $statuses); // Moved to actual bookings areas $content .= '<h4>' . __($status_name, Eab_EventsHub::TEXT_DOMAIN) . '</h4>'; $content .= '<ul class="eab-guest-list">'; $all_events = array($event); if ($event->is_recurring()) { $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event); } $all_event_ids = array(); foreach ($all_events as $e) { $all_event_ids[] = $e->get_id(); } $all_event_ids = array_filter(array_map('intval', $all_event_ids)); $bookings = $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status = %s ORDER BY timestamp;", $status)); if (!count($bookings)) { return false; } foreach ($bookings as $booking) { $user_data = get_userdata($booking->user_id); if ($event->get_id() !== $booking->event_id) { $event = new Eab_EventModel(get_post($booking->event_id)); } $content .= '<li>'; $content .= '<div class="eab-guest">'; $content .= '<a href="user-edit.php?user_id=' . $booking->user_id . '" title="' . $user_data->display_name . '">' . get_avatar($booking->user_id, 32) . '<br />' . apply_filters('eab-guest_list-admin-guest_name', $user_data->display_name, $booking->user_id, $user_data) . '</a>'; if ($event->is_premium()) { if ($event->user_paid($booking->user_id)) { $ticket_count = $event->get_booking_meta($booking->id, 'booking_ticket_count'); $ticket_count = $ticket_count ? $ticket_count : 1; $payment_status = '' . '<span class="eab-guest-payment_info-paid">' . __('Paid', Eab_EventsHub::TEXT_DOMAIN) . '</span>' . ' ' . sprintf(__('(%s tickets)', Eab_EventsHub::TEXT_DOMAIN), $ticket_count) . ''; } else { $payment_status = '<span class="eab-guest-payment_info-not_paid">' . __('Not paid', Eab_EventsHub::TEXT_DOMAIN) . '</span>'; } // Added by Hakan $payment_status = apply_filters('eab-event-payment_status', $payment_status, $booking->user_id, $event); $content .= "<div class='eab-guest-payment_info'>{$payment_status}</div>"; } if (in_array($status, array(Eab_EventModel::BOOKING_YES, Eab_EventModel::BOOKING_MAYBE))) { $content .= '<div class="eab-guest-actions"><a href="#cancel-attendance" class="eab-guest-cancel_attendance" data-eab-user_id="' . $booking->user_id . '" data-eab-event_id="' . $event->get_id() . '">' . __('Cancel attendance', Eab_EventsHub::TEXT_DOMAIN) . '</a></div>'; } $content .= '<div class="eab-guest-actions"><a href="#delete-attendance" class="eab-guest-delete_attendance" data-eab-user_id="' . $booking->user_id . '" data-eab-event_id="' . $event->get_id() . '">' . __('Delete attendance entirely', Eab_EventsHub::TEXT_DOMAIN) . '</a></div>'; $content = apply_filters('eab-event-booking_metabox_content', $content, $booking->user_id); $content .= '</div>'; // .eab-guest $content .= '</li>'; } $content .= '</ul>'; $content .= '<div class="clear"></div>'; return $content; }
function post_twitter_update($event_id, $user_id) { $tw = get_user_meta($user_id, '_eab_tw', true); if (!$tw) { return false; } // Can't post this if (!$tw['id']) { return false; } // No profile id if (!$tw['token']) { return false; } // No access_token //die(var_export($tw)); $event = new Eab_EventModel(get_post($event_id)); if ($event->get_meta('_eab-social_rsvp-twitter-' . $user_id)) { return false; } // Already posted if (!class_exists('TwitterOAuth')) { include_once EAB_PLUGIN_DIR . 'lib/twitteroauth/twitteroauth.php'; } $twitter = new TwitterOAuth($this->_data->get_option('twitter-app_id'), $this->_data->get_option('twitter-app_secret'), $tw['token']['oauth_token'], $tw['token']['oauth_token_secret']); $send = array('status' => substr(sprintf("I'm going to %s!", $event->get_title()) . ' ' . get_permalink($event_id), 0, 140)); try { $resp = $twitter->post('statuses/update', $send); } catch (Exception $e) { return false; } $event->set_meta('_eab-social_rsvp-twitter-' . $user_id, $resp->id); }
private function _send_cancel_event_email($event_id) { $event = new Eab_EventModel(get_post($event_id)); $rsvps = $event->get_event_bookings(Eab_EventModel::BOOKING_YES); if (empty($rsvps)) { return false; } $from = $this->_data->get_option('eab_cancelations-email-from'); $from = $from ? $from : get_option('admin_email'); $subject = trim($this->_data->get_option('eab_cancelations-email-subject')); $subject = !empty($subject) ? $subject : $this->_default_subject; $body = trim($this->_data->get_option('eab_cancelations-email-body')); $body = !empty($body) ? $body : $this->_default_message; if (empty($from) || empty($subject) || empty($body)) { return false; } $already_sent = $this->_get_users_notification_queue($event->get_id()); $limit = $this->_get_email_batch_limit(); $counter = 0; $codec = new Eab_Macro_Codec($event_id); $headers = array('From: ' . $from, 'Content-Type: ' . $this->email_charset() . '; charset="' . get_option('blog_charset') . '"'); add_filter('wp_mail_content_type', array($this, 'email_charset')); foreach ($rsvps as $rsvp) { if (in_array($rsvp->user_id, $already_sent)) { continue; } // Don't send email twice $user = get_user_by('id', $rsvp->user_id); if (!is_email($user->user_email)) { continue; } $codec->set_user($user); wp_mail($user->user_email, $codec->expand($subject, Eab_Macro_Codec::FILTER_TITLE), $codec->expand($body, Eab_Macro_Codec::FILTER_BODY), $headers); $already_sent[] = $rsvp->user_id; $counter++; if ($counter == $limit) { break; } } remove_filter('wp_mail_content_type', array($this, 'email_charset')); $this->_set_users_notification_queue($event->get_id(), $already_sent); if (count($rsvps) == count($already_sent)) { $this->_remove_event_from_schedule_queue($event->get_id()); } return $counter; }
/** * Order is completed = payment done. * Update event booking meta to indicate this, for Event-related Products. */ function mp_product_order_paid($order) { $user_id = $order->post_author; $total_payment = $event_ids = array(); $cart_info = is_object($order) && is_callable(array($order, 'get_cart')) ? $order->get_cart()->get_items() : (isset($order->mp_cart_info) ? $order->mp_cart_info : array()); if (is_array($cart_info) && count($cart_info)) { foreach ($cart_info as $cart_id => $count) { $event_id = $product_id = false; $event_id = $this->order_to_event_id($cart_id); if ($this->_is_product_id($cart_id)) { $product_id = $cart_id; } else { $variation = get_post($cart_id); $product_id = $variation->post_parent; } // No variations, go for quantities if (!$event_id) { continue; } $event_ids[] = $event_id; $tickets = !empty($total_payment[$event_id]) ? $total_payment[$event_id] : array('count' => 0, 'order_id' => $order->ID, 'product_id' => $product_id); $tickets['count'] += (int) $count; $total_payment[$event_id] = $tickets; } } $user_bookings = array(); $event_ids = join(',', array_unique($event_ids)); global $wpdb; $table = Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE); $bookings = $wpdb->get_results($wpdb->prepare("SELECT event_id,id FROM {$table} WHERE user_id=%d AND event_id IN ({$event_ids})", $user_id)); foreach ($bookings as $booking) { $user_bookings[$booking->event_id] = $booking->id; } foreach ($total_payment as $event_id => $booking_info) { if (empty($user_bookings[$event_id])) { //continue; // Possibly paying for wrong variation! // Well, the guy apparently paid... so book him $wpdb->query($wpdb->prepare("INSERT INTO " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " VALUES(null, %d, %d, NOW(), 'yes') ON DUPLICATE KEY UPDATE `status` = 'yes';", $event_id, $user_id)); $user_bookings[$event_id] = $wpdb->insert_id; // --todo: Add to BP activity stream do_action('incsub_event_booking_yes', $event_id, $user_id); // End booking extras } $booking_id = $user_bookings[$event_id]; Eab_EventModel::update_booking_meta($booking_id, 'booking_transaction_key', serialize($booking_info)); Eab_EventModel::update_booking_meta($booking_id, 'booking_ticket_count', $booking_info['count']); } }
function manage_posts_custom_column($column) { global $post; switch ($column) { case "attendees": global $wpdb; $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post); $yes = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_YES)); $no = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_NO)); $maybe = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id = %d AND status = %s;", $event->get_id(), Eab_EventModel::BOOKING_MAYBE)); printf('<b>' . __('Attending / Undecided', self::TEXT_DOMAIN) . ':</b> %d / %d<br />', $yes, $maybe); printf('<b>' . __('Not Attending', self::TEXT_DOMAIN) . ':</b> %d', $no); echo ' '; echo '<a class="button" href="' . admin_url('index.php?eab_export=attendees&event_id=' . $event->get_id()) . '" class="eab-export_attendees">' . __('Export', self::TEXT_DOMAIN) . '</a>'; break; case "start": $event = new Eab_EventModel($post); $df = get_option('date_format', 'Y-m-d'); if (!$event->is_recurring()) { echo date_i18n($df, $event->get_start_timestamp()) . ' - ' . date_i18n($df, $event->get_end_timestamp()); } else { $repeats = $event->get_supported_recurrence_intervals(); $title = @$repeats[$event->get_recurrence()]; $start = date_i18n($df, $event->get_recurrence_starts()); $end = date_i18n($df, $event->get_recurrence_ends()); printf(__("From %s, repeats every %s until %s", self::TEXT_DOMAIN), $start, $title, $end); } break; case "venue": $event = new Eab_EventModel($post); echo $event->get_venue_location(); break; case "event": $event = new Eab_EventModel($post); $post_type_object = get_post_type_object($post->post_type); $edit_link = get_edit_post_link($event->get_id()); $statuses = array(); if ('draft' == $post->post_status) { $statuses[] = __('Draft'); } if ('private' == $post->post_status) { $statuses[] = __('Private'); } if ('pending' == $post->post_status) { $statuses[] = __('Pending'); } $status = $statuses ? ' - <span class="post-state">' . join(', ', $statuses) . '</span>' : ''; $title = current_user_can($post_type_object->cap->edit_post, $event->get_id()) && 'trash' != $post->post_status ? '<strong>' . '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit “%s”'), $event->get_title())) . '">' . $event->get_title() . '</a> ' . $status . '</strong>' : '<strong>' . $event->get_title() . ' ' . $status . '</strong>'; if (current_user_can($post_type_object->cap->edit_post, $event->get_id()) && 'trash' != $post->post_status) { $actions['edit'] = '<a title="' . esc_attr(__('Edit Event', self::TEXT_DOMAIN)) . '" href="' . $edit_link . '">' . __('Edit') . '</a>'; if (!$event->is_recurring()) { $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this Event inline', self::TEXT_DOMAIN)) . '">' . __('Quick Edit') . '</a>'; } } if (current_user_can($post_type_object->cap->delete_post, $event->get_id())) { if ('trash' == $post->post_status) { $actions['untrash'] = "<a title='" . esc_attr(__('Restore this Event from the Trash', self::TEXT_DOMAIN)) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $event->get_id())), 'untrash-' . $post->post_type . '_' . $event->get_id()) . "'>" . __('Restore') . "</a>"; } else { if (EMPTY_TRASH_DAYS) { $actions['trash'] = '<a class="submitdelete" title="' . esc_attr(__('Move this Event to the Trash', self::TEXT_DOMAIN)) . '" href="' . get_delete_post_link($event->get_id()) . '">' . __('Trash') . '</a>'; } } if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) { $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this Event permanently', self::TEXT_DOMAIN)) . "' href='" . get_delete_post_link($event->get_id(), '', true) . "'>" . __('Delete Permanently') . "</a>"; } } if ('trash' != $post->post_status) { $event_id = $event->get_id(); if ($event->is_recurring()) { $children = Eab_CollectionFactory::get_all_recurring_children_events($event); if (!$children || !$children[0] instanceof Eab_EventModel) { $event_id = false; } else { $event_id = $children[0]->get_id(); } } if ($event_id) { $actions['view'] = '<a href="' . get_permalink($event_id) . '" title="' . esc_attr(sprintf(__('View “%s”'), $event->get_title())) . '" rel="permalink">' . __('View') . '</a>'; } } echo $title; if (!empty($actions)) { foreach ($actions as $action => $link) { $actions[$action] = "<span class='{$action}'>{$link}</span>"; } } echo '<div class="row-actions">' . join(' | ', $actions) . '</div>'; get_inline_data($post); break; } }
private function _construct_unique_rsvp_activity($event_id, $user_id, $rsvp) { $group_id = $this->_is_group_event($event_id); if ($this->_data->get_option('bp-activity_autoupdate-user_rsvp_group_only') && !$group_id) { return false; } $event = new Eab_EventModel(get_post($event_id)); $user_link = bp_core_get_userlink($user_id); $update = false; switch ($rsvp) { case Eab_EventModel::BOOKING_YES: $update = sprintf(__('%s will be attending <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, get_permalink($event->get_id()), $event->get_title()); break; case Eab_EventModel::BOOKING_MAYBE: $update = sprintf(__('%s will maybe attend <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, get_permalink($event->get_id()), $event->get_title()); break; case Eab_EventModel::BOOKING_NO: $update = sprintf(__('%s won\'t be attending <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, get_permalink($event->get_id()), $event->get_title()); break; } if (!$update) { return false; } $raw_activity = array('user_id' => $user_id, 'action' => $update, 'type' => 'event_rsvp', 'item_id' => $event->get_id()); if ($this->_data->get_option('bp-activity_autoupdate-user_rsvp_group_post') && $group_id) { global $bp; $group_activity = $raw_activity; $group_activity['component'] = $bp->groups->id; $group_activity['item_id'] = $group_id; $group_activity['secondary_item_id'] = $event->get_id(); $existing = bp_activity_get(array("filter" => array('user_id' => $user_id, "object" => $bp->groups->id, "action" => 'event_rsvp', 'primary_id' => $group_id, 'secondary_id' => $event->get_id()))); if (isset($existing['activities']) && !empty($existing['activities'])) { $old = reset($existing['activities']); if (is_object($old) && isset($old->id)) { $group_activity['id'] = $old->id; } } // Add group activity update groups_record_activity($group_activity); } else { $activity = $raw_activity; $activity['component'] = 'eab_events'; $existing = bp_activity_get(array("filter" => array('user_id' => $user_id, "object" => 'eab_events', "action" => 'event_rsvp', 'primary_id' => $event->get_id()))); if (isset($existing['activities']) && !empty($existing['activities'])) { $old = reset($existing['activities']); if (is_object($old) && isset($old->id)) { $activity['id'] = $old->id; } } // Add site/user activity update bp_activity_add($activity); } }
/** * Converts event RSVPs into a send list. */ public function rsvps_to_member_group($event_id, $bookings = array()) { if (empty($event_id) || empty($bookings)) { return false; } $event = new Eab_EventModel(get_post($event_id)); $all_events = array($event); if ($event->is_recurring()) { $all_events = Eab_CollectionFactory::get_all_recurring_children_events($event); } $all_event_ids = array(); foreach ($all_events as $e) { $all_event_ids[] = $e->get_id(); } $all_event_ids = array_filter(array_map('intval', $all_event_ids)); $rsvps = $this->_db->get_col("SELECT DISTINCT user_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") AND status IN ('" . join("','", $bookings) . "')"); //if (empty($rsvps)) return false; $group_id = $this->_spawn_event_rsvp_group($event, $bookings); if (empty($group_id)) { return false; } return !empty($rsvps) ? $this->_newsletter->add_members_to_groups($rsvps, $group_id, false) : true; }
function eab__event_categories_to_classes($cls, $event_id) { $event = new Eab_EventModel(get_post($event_id)); $taxonomies = $event->get_categories(); if (empty($taxonomies)) { return $cls; } $classes = array_values(wp_list_pluck($taxonomies, 'slug')); if (empty($classes)) { return $cls; } return trim($cls . ' ' . join(' ', array_map('sanitize_html_class', $classes))); }
private function _get_overbooked_message($post_id = false) { $message = apply_filters('eab-rsvps-event_capacity_reached-message', __('Sorry, the event sold out.', Eab_EventsHub::TEXT_DOMAIN), $post_id); if ($post_id && $this->_data->get_option('eab-limit_capacity-show_cancel')) { $login_url_n = apply_filters('eab-rsvps-rsvp_login_page-no', wp_login_url(get_permalink($post_id)) . '&eab=n'); if (is_user_logged_in()) { $user_id = get_current_user_id(); $event = new Eab_EventModel($post_id); $is_coming = $event->user_is_coming(false, $user_id); $cancel = '<input class="current wpmudevevents-no-submit" type="submit" name="action_no" value="' . __('Cancel', Eab_EventsHub::TEXT_DOMAIN) . '" ' . ($is_coming ? '' : 'style="display:none"') . ' />'; if ($is_coming) { $cancel .= '<input type="hidden" name="user_id" value="' . get_current_user_id() . '" />'; } } else { $cancel = '<a class="wpmudevevents-no-submit" href="' . $login_url_n . '" >' . __('Cancel', Eab_EventsHub::TEXT_DOMAIN) . '</a>'; } $message .= '<div class="wpmudevevents-buttons">' . '<form action="' . get_permalink($post_id) . '" method="post" >' . '<input type="hidden" name="event_id" value="' . $post_id . '" />' . $cancel . '</form>' . '</div>'; } return '<div class="wpmudevevents-event_reached_capacity">' . $message . '</div>'; }
<?php global $blog_id, $wp_query, $booking, $post, $current_user; $event = new Eab_EventModel($post); get_header(); ?> <div id="primary"> <div id="content" role="main"> <div class="event <?php echo Eab_Template::get_status_class($post); ?> " id="wpmudevevents-wrapper"> <div id="wpmudevents-single"> <?php the_post(); $start_day = date_i18n('m', strtotime(get_post_meta($post->ID, 'incsub_event_start', true))); ?> <div class="wpmudevevents-header"> <h2><?php echo $event->get_title(); ?> </h2> <div class="eab-needtomove"><div id="event-bread-crumbs" ><?php echo Eab_Template::get_breadcrumbs($event); ?> </div></div> <?php echo Eab_Template::get_rsvp_form($post); echo Eab_Template::get_inline_rsvps($post);