function eab_calendar_recurring_cb($args) { $args = shortcode_atts(array('id' => false, 'network' => false, 'date' => false, 'relative_date' => false, 'category' => false, 'categories' => false, 'footer' => false, 'class' => 'eab-shortcode_calendar', 'navigation' => false, 'title_format' => 'M Y', 'short_title_format' => 'm-Y', 'long_date_format' => false, 'template' => 'get_shortcode_calendar_output', 'override_styles' => false, 'override_scripts' => false, 'with_thumbnail' => false, 'default_thumbnail' => false, 'show_excerpt' => false, 'excerpt_length' => 55), $args, 'eab_recurring'); if (!empty($_GET['date'])) { $date = strtotime($_GET['date']); if ($date) { $args['date'] = $date; } } if ($args['id']) { $event = new Eab_EventModel(get_post($args['id'])); } else { $q = new WP_Query(array('post_type' => Eab_EventModel::POST_TYPE, 'name' => $args['slug'], 'posts_per_page' => 1)); if (isset($q->posts[0])) { $event = new Eab_EventModel($q->posts[0]); } } if (!$event) { return $content; } $rec_events = Eab_CollectionFactory::get_all_recurring_children_events($event); $output = $this->get_shortcode_calendar_output($rec_events, $args); $output = $output ? $output : $content; if (!$args['override_styles']) { wp_enqueue_style('eab_calendar_shortcode', eab_call_template('util_get_default_template_style', 'calendar')); } return $output; }
function eab_recurring_cb($args) { $args = shortcode_atts(array('id' => false, 'slug' => false, 'class' => false, 'template' => 'get_shortcode_recurring_output', 'override_styles' => false, 'override_scripts' => false), $args, 'eab_recurring'); $event = false; if ($args['id']) { $event = new Eab_EventModel(get_post($args['id'])); } else { $q = new WP_Query(array('post_type' => Eab_EventModel::POST_TYPE, 'name' => $args['slug'], 'posts_per_page' => 1)); if (isset($q->posts[0])) { $event = new Eab_EventModel($q->posts[0]); } } if (!$event) { return $content; } $rec_events = Eab_CollectionFactory::get_all_recurring_children_events($event); $out = '<section class="eab-events-archive ' . $args['class'] . '">'; foreach ($rec_events as $event) { $event = $event instanceof Eab_EventModel ? $event : new Eab_EventModel($event); $out .= '<article class="eab-event ' . eab_call_template('get_status_class', $event) . '" id="eab-event-' . $event->get_id() . '">' . '<h4>' . $event->get_title() . '</h4>' . '<div class="eab-event-body">' . $this->get_recurring_content($event) . '</div>' . '</article>'; } $out .= '</section>'; $output = $out ? $out : $content; if (!$args['override_styles']) { wp_enqueue_style('eab_front'); } if (!$args['override_scripts']) { wp_enqueue_script('eab_event_js'); do_action('eab-javascript-do_enqueue_api_scripts'); } return $output; }
public function notify_rsvp_on_update_event($post_id, $post) { if (!current_user_can('edit_posts')) { return false; } if (wp_is_post_revision($post_id)) { return; } if ('incsub_event' == get_post_type($post_id)) { global $wpdb; $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post); $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("SELECT id,user_id,event_id FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE event_id IN(" . join(',', $all_event_ids) . ") ORDER BY timestamp;"); if (!count($bookings)) { return false; } $eab_alert = $this->_data->get_option('eab_alert'); $start_dates = $event->get_start_dates(); foreach ($start_dates as $key => $date) { $start = $event->get_start_timestamp($key); $end = $event->get_end_timestamp($key); } foreach ($bookings as $booking) { $user_data = get_userdata($booking->user_id); $subject = str_replace(array('DISPLAY_NAME', 'EVENT_NAME', 'START_DATE', 'START_TIME', 'END_DATE', 'END_TIME'), array($user_data->display_name, $event->get_title(), date('Y-m-d', $start), date('H:i', $start), date('Y-m-d', $end), date('H:i', $end)), $eab_alert['subject']); $content = str_replace(array('DISPLAY_NAME', 'EVENT_NAME', 'START_DATE', 'START_TIME', 'END_DATE', 'END_TIME'), array($user_data->display_name, $event->get_title(), date('Y-m-d', $start), date('H:i', $start), date('Y-m-d', $end), date('H:i', $end)), $eab_alert['content']); add_filter('wp_mail_content_type', array($this, 'set_content_type')); wp_mail($user_data->user_email, $subject, nl2br($content)); remove_filter('wp_mail_content_type', array($this, 'set_content_type')); } } }
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)); }
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; }
/** * 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; }
protected function _get_bookings($status) { $event = new Eab_EventModel($this->_event_id); $event_id = "event_id = " . (int) $this->_event_id; if ($event->is_recurring()) { $all_event_ids = array(); $events = Eab_CollectionFactory::get_all_recurring_children_events($event); foreach ($events as $e) { $all_event_ids[] = $e->get_id(); } $all_event_ids = array_filter(array_map('intval', $all_event_ids)); $event_id = "event_id IN(" . join(',', $all_event_ids) . ")"; } global $wpdb; return $wpdb->get_results($wpdb->prepare("SELECT id,user_id,event_id,timestamp FROM " . Eab_EventsHub::tablename(Eab_EventsHub::BOOKING_TABLE) . " WHERE {$event_id} AND status = %s ORDER BY timestamp;", $status)); }
protected function _get_recurring_children_ids() { $events = Eab_CollectionFactory::get_all_recurring_children_events($this); $ids = array(); foreach ($events as $event) { $ids[] = $event->get_id(); } return $ids; }
private function _cancel_event($event_id) { $event = new Eab_EventModel(get_post($event_id)); if ($event->is_recurring() && !$event->is_recurring_child()) { // Recurring root - cancel children too update_post_meta($event_id, 'incsub_event_status', self::STATUS_CANCEL); $events = Eab_CollectionFactory::get_all_recurring_children_events($event); foreach ($events as $event) { $this->_cancel_event($event->get_id()); } } else { // Regular event or single instance. All good update_post_meta($event_id, 'incsub_event_status', self::STATUS_CANCEL); $this->_add_event_to_schedule_queue($event_id); } }
private function _get_event_as_ical($post, $recurring_instances = false) { $ret = ''; $event = $post instanceof Eab_EventModel ? $post : new Eab_EventModel($post); if (in_array($event->get_id(), $this->_processed)) { return ''; } // Branch off into recurrence processing if ($event->is_recurring()) { $events = Eab_CollectionFactory::get_all_recurring_children_events($event); foreach ($events as $event) { $ret .= $this->_get_event_as_ical($event, $recurring_instances); } return $ret; } else { if ($event->is_recurring_child() && $recurring_instances) { return $this->_get_event_as_ical(get_post($event->get_parent()), false); } } $domain = preg_replace('/^www\\./', '', parse_url(home_url(), PHP_URL_HOST)); $author = get_userdata($event->get_author()); $location = $event->get_venue_location(Eab_EventModel::VENUE_AS_ADDRESS); $start_dates = $event->get_start_dates(); $tz_offset = get_option('gmt_offset') * 3600; $time_callback = 'date'; $zulu = ''; $tzid = ''; if ('gmt' == $this->_calculus) { $zulu = 'Z'; } else { if ('tz_local' == $this->_calculus) { $zone_string = get_option('timezone_string'); if (!empty($zone_string)) { $tzid = ";TZID={$zone_string}"; } } } foreach ($start_dates as $key => $start) { $start = $event->get_start_timestamp($key) + ('gmt' == $this->_calculus ? $tz_offset : 0); $end = $event->get_end_timestamp($key) + ('gmt' == $this->_calculus ? $tz_offset : 0); $ret .= "BEGIN:VEVENT\n" . 'UID:' . $event->get_id() . rand() . "@{$domain}\n" . "ORGANIZER;CN={$author->display_name}:MAILTO:{$author->user_email}\n" . "DTSTART{$tzid}:" . $time_callback('Ymd', $start) . "T" . $time_callback('His', $start) . "{$zulu}\n" . "DTEND{$tzid}:" . $time_callback('Ymd', $end) . "T" . $time_callback('His', $end) . "{$zulu}\n" . "SUMMARY:" . $event->get_title() . "\n" . "DESCRIPTION:" . str_replace("\r\n", "\\n", $event->get_content()) . "\n" . "URL:" . get_permalink($event->get_id()) . "\n" . ($location ? "LOCATION:{$location}\n" : '') . "END:VEVENT\n"; } $this->_processed[] = $event->get_id(); return "\n{$ret}\n"; }
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; } }