/**
  * @param EM_Booking $EM_Booking
  */
 function get_form($EM_Event = false, $custom_form_id = false)
 {
     //special lookup for multiple bookings
     if (is_object($custom_form_id) && get_class($custom_form_id) == 'EM_Multiple_Booking') {
         $custom_form_id = get_option('dbem_multiple_bookings_form');
     }
     //make sure we don't need to get another form rather than the one already stored in this object
     $reload = is_numeric($EM_Event) && $EM_Event != self::$event_id || !empty($EM_Event->event_id) && $EM_Event->event_id != self::$event_id || empty($EM_Event) && $custom_form_id && $custom_form_id != self::$form_id;
     //get the right form
     if (empty(self::$form) || $reload) {
         global $wpdb;
         if (is_numeric($EM_Event)) {
             $EM_Event = em_get_event($EM_Event);
         }
         $custom_form_id = !empty($EM_Event->post_id) ? get_post_meta($EM_Event->post_id, '_custom_booking_form', true) : $custom_form_id;
         $form_id = !empty($custom_form_id) && is_numeric($custom_form_id) ? $custom_form_id : get_option('em_booking_form_fields');
         $sql = $wpdb->prepare("SELECT meta_id, meta_value FROM " . EM_META_TABLE . " WHERE meta_key = 'booking-form' AND meta_id=%d", $form_id);
         $form_data_row = $wpdb->get_row($sql, ARRAY_A);
         if (empty($form_data_row)) {
             $form_data = self::$form_template;
             self::$form_name = __('Default', 'em-pro');
         } else {
             $form_data = unserialize($form_data_row['meta_value']);
             self::$form_id = $form_data_row['meta_id'];
             self::$form_name = $form_data['name'];
         }
         self::$event_id = !empty($EM_Event) ? $EM_Event->event_id : false;
         self::$form = new EM_Form($form_data['form'], 'em_bookings_form');
         self::$form->form_required_error = get_option('em_booking_form_error_required');
     }
     return self::$form;
 }
예제 #2
0
 /**
  * will redirect old links to new link structures.
  */
 public static function redirection()
 {
     global $wpdb, $wp_query;
     if (is_object($wp_query) && $wp_query->get('em_redirect')) {
         //is this a querystring url?
         if ($wp_query->get('event_slug')) {
             $event = $wpdb->get_row('SELECT event_id, post_id FROM ' . EM_EVENTS_TABLE . " WHERE event_slug='" . $wp_query->get('event_slug') . "' AND (blog_id=" . get_current_blog_id() . " OR blog_id IS NULL OR blog_id=0)", ARRAY_A);
             if (!empty($event)) {
                 $EM_Event = em_get_event($event['event_id']);
                 $url = get_permalink($EM_Event->post_id);
             }
         } elseif ($wp_query->get('location_slug')) {
             $location = $wpdb->get_row('SELECT location_id, post_id FROM ' . EM_LOCATIONS_TABLE . " WHERE location_slug='" . $wp_query->get('location_slug') . "' AND (blog_id=" . get_current_blog_id() . " OR blog_id IS NULL OR blog_id=0)", ARRAY_A);
             if (!empty($location)) {
                 $EM_Location = em_get_location($location['location_id']);
                 $url = get_permalink($EM_Location->post_id);
             }
         } elseif ($wp_query->get('category_slug')) {
             $url = get_term_link($wp_query->get('category_slug'), EM_TAXONOMY_CATEGORY);
         }
         if (!empty($url)) {
             wp_redirect($url, 301);
             exit;
         }
     }
 }
예제 #3
0
/**
 * Shows a list of events according to given specifications. Accepts any event query attribute.
 * @param array $atts
 * @return string
 */
function em_get_event_shortcode($atts, $format = '')
{
    global $EM_Event, $post;
    $the_event = is_object($EM_Event) ? clone $EM_Event : null;
    //save global temporarily
    $atts = (array) $atts;
    $atts['format'] = $format != '' || empty($atts['format']) ? $format : $atts['format'];
    $atts['format'] = html_entity_decode($atts['format']);
    //shorcode doesn't accept html
    if (!empty($atts['event']) && is_numeric($atts['event'])) {
        $EM_Event = em_get_event($atts['event']);
        $return = !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    } elseif (!empty($atts['post_id']) && is_numeric($atts['post_id'])) {
        $EM_Event = em_get_event($atts['post_id'], 'post_id');
        $return = !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    }
    //no specific event or post id supplied, check globals
    if (!empty($EM_Event)) {
        $return = !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    } elseif ($post->post_type == EM_POST_TYPE_EVENT) {
        $EM_Event = em_get_event($post->ID, 'post_id');
        $return = !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    }
    $EM_Event = is_object($the_event) ? $the_event : $EM_Event;
    //reset global
    return $return;
}
예제 #4
0
/**
 * Not yet used fully - formats event-related actions
 * @param string $action
 * @param object $activity
 * @return string
 */
function em_bp_events_format_activity_action_events($action, $activity)
{
    return '';
    $member_link = bp_core_get_userlink($activity->user_id);
    $EM_Event = em_get_event($activity->item_id);
    $action = sprintf(__('%s added the event %s', 'dbem'), $member_link, $EM_Event->output('#_EVENTLINK'));
    return apply_filters('bp_events_format_activity_action_events', $action, $activity);
}
예제 #5
0
 public static function em_ml_admin_original_event_link($link)
 {
     global $EM_Event;
     if (empty($EM_Event->event_id) && !empty($_REQUEST['trid'])) {
         $post_id = SitePress::get_original_element_id_by_trid($_REQUEST['trid']);
         $original_event_link = em_get_event($post_id, 'post_id')->get_edit_url();
     }
     return $link;
 }
예제 #6
0
 function the_category($thelist, $separator = '', $parents = '')
 {
     global $post, $wp_rewrite;
     if ($post->post_type == EM_POST_TYPE_EVENT) {
         $EM_Event = em_get_event($post);
         $categories = $EM_Event->get_categories();
         if (empty($categories)) {
             return '';
         }
         /* Copied from get_the_category_list function, with a few minor edits to make urls work, and removing parent stuff (for now) */
         $rel = is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ? 'rel="category tag"' : 'rel="category"';
         $thelist = '';
         if ('' == $separator) {
             $thelist .= '<ul class="post-categories">';
             foreach ($categories as $category) {
                 $thelist .= "\n\t<li>";
                 switch (strtolower($parents)) {
                     case 'multiple':
                         $thelist .= '<a href="' . $category->get_url() . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" ' . $rel . '>' . $category->name . '</a></li>';
                         break;
                     case 'single':
                         $thelist .= '<a href="' . $category->get_url() . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" ' . $rel . '>';
                         $thelist .= $category->name . '</a></li>';
                         break;
                     case '':
                     default:
                         $thelist .= '<a href="' . $category->get_url() . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" ' . $rel . '>' . $category->name . '</a></li>';
                 }
             }
             $thelist .= '</ul>';
         } else {
             $i = 0;
             foreach ($categories as $category) {
                 if (0 < $i) {
                     $thelist .= $separator;
                 }
                 switch (strtolower($parents)) {
                     case 'multiple':
                         $thelist .= '<a href="' . $category->get_url() . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" ' . $rel . '>' . $category->name . '</a>';
                         break;
                     case 'single':
                         $thelist .= '<a href="' . $category->get_url() . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" ' . $rel . '>';
                         $thelist .= "{$category->name}</a>";
                         break;
                     case '':
                     default:
                         $thelist .= '<a href="' . $category->get_url() . '" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" ' . $rel . '>' . $category->name . '</a>';
                 }
                 ++$i;
             }
         }
         /* End copying */
     }
     return $thelist;
 }
예제 #7
0
/**
 * Shows a list of events according to given specifications. Accepts any event query attribute.
 * @param array $atts
 * @return string
 */
function em_get_event_shortcode($atts, $format = '')
{
    $atts = (array) $atts;
    $atts['format'] = $format != '' || empty($atts['format']) ? $format : $atts['format'];
    $atts['format'] = html_entity_decode($atts['format']);
    //shorcode doesn't accept html
    if (!empty($atts['event']) && is_numeric($atts['event'])) {
        $EM_Event = em_get_event($atts['event']);
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    } elseif (!empty($atts['post_id']) && is_numeric($atts['post_id'])) {
        $EM_Event = em_get_event($atts['post_id'], 'post_id');
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    }
}
예제 #8
0
function em_ical_event()
{
    global $wpdb;
    //add endpoints to events
    if (get_query_var(EM_POST_TYPE_EVENT) && get_query_var('ical')) {
        $event_id = $wpdb->get_var('SELECT event_id FROM ' . EM_EVENTS_TABLE . " WHERE event_slug='" . get_query_var(EM_POST_TYPE_EVENT) . "' AND event_status=1 LIMIT 1");
        if (!empty($event_id)) {
            global $EM_Event;
            $EM_Event = em_get_event($event_id);
            ob_start();
            em_locate_template('templates/ical-event.php', true);
            echo preg_replace("/([^\r])\n/", "\$1\r\n", ob_get_clean());
            exit;
        }
    }
}
예제 #9
0
/**
 * Generates an ics file for a single event 
 */
function em_ical_event()
{
    global $wpdb, $wp_query;
    //add endpoints to events
    if (!empty($wp_query) && $wp_query->get(EM_POST_TYPE_EVENT) && $wp_query->get('ical')) {
        $event_id = $wpdb->get_var('SELECT event_id FROM ' . EM_EVENTS_TABLE . " WHERE event_slug='" . $wp_query->get(EM_POST_TYPE_EVENT) . "' AND event_status=1 LIMIT 1");
        if (!empty($event_id)) {
            global $EM_Event;
            $EM_Event = em_get_event($event_id);
            //send headers
            header('Content-type: text/calendar; charset=utf-8');
            header('Content-Disposition: inline; filename="' . $EM_Event->event_slug . '.ics"');
            em_locate_template('templates/ical.php', true);
            exit;
        }
    }
}
 function remove_booking($event_id)
 {
     if (!empty($this->bookings[$event_id])) {
         $EM_Event = em_get_event($event_id);
         //remove ticket booking records belonging to this event
         foreach ($EM_Event->get_tickets() as $EM_Ticket) {
             /* @var $EM_Ticket EM_Ticket */
             if (!empty($this->get_tickets_bookings()->tickets_bookings[$EM_Ticket->ticket_id])) {
                 unset($this->get_tickets_bookings()->tickets_bookings[$EM_Ticket->ticket_id]);
             }
         }
         //remove event from bookings array
         unset($this->bookings[$_REQUEST['event_id']]);
         //refresh price and spaces
         $this->calculate_price();
         $this->get_spaces(true);
         return true;
     }
     return false;
 }
예제 #11
0
/**
 * Shows a list of events according to given specifications. Accepts any event query attribute.
 * @param array $atts
 * @return string
 */
function em_get_event_shortcode($atts, $format = '')
{
    $atts = (array) $atts;
    $atts['format'] = $format != '' || empty($atts['format']) ? $format : $atts['format'];
    $atts['format'] = html_entity_decode($atts['format']);
    //shorcode doesn't accept html
    if (!empty($atts['event']) && is_numeric($atts['event'])) {
        $EM_Event = em_get_event($atts['event']);
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    } elseif (!empty($atts['post_id']) && is_numeric($atts['post_id'])) {
        $EM_Event = em_get_event($atts['post_id'], 'post_id');
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    }
    //no specific event or post id supplied, check globals
    global $EM_Event, $post;
    if (!empty($EM_Event)) {
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    } elseif ($post->post_type == EM_POST_TYPE_EVENT) {
        $EM_Event = em_get_event($post->ID, 'post_id');
        return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single();
    }
}
 function columns_output($column)
 {
     global $post, $EM_Event;
     if ($post->post_type == 'event-recurring') {
         $post = $EM_Event = em_get_event($post);
         /* @var $post EM_Event */
         switch ($column) {
             case 'event-id':
                 echo $EM_Event->event_id;
                 break;
             case 'location':
                 //get meta value to see if post has location, otherwise
                 $EM_Location = $EM_Event->get_location();
                 if (!empty($EM_Location->location_id)) {
                     echo "<strong>" . $EM_Location->location_name . "</strong><br/>" . $EM_Location->location_address . " - " . $EM_Location->location_town;
                 } else {
                     echo __('None', 'dbem');
                 }
                 break;
             case 'date-time':
                 echo $EM_Event->get_recurrence_description();
                 break;
         }
     }
 }
예제 #13
0
 /**
  * Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future 
  * (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array
  * containing the ids of the events you'd like to obtain 
  * 
  * @param array $args
  * @return EM_Event array()
  */
 public static function get($args = array(), $count = false)
 {
     global $wpdb;
     $events_table = EM_EVENTS_TABLE;
     $locations_table = EM_LOCATIONS_TABLE;
     //Quick version, we can accept an array of IDs, which is easy to retrieve
     if (self::array_is_numeric($args)) {
         //Array of numbers, assume they are event IDs to retreive
         //We can just get all the events here and return them
         $sql = "\r\n\t\t\t\tSELECT * FROM {$events_table}\r\n\t\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\r\n\t\t\t\tWHERE event_id=" . implode(" OR event_id=", $args) . "\r\n\t\t\t";
         $results = $wpdb->get_results(apply_filters('em_events_get_sql', $sql), ARRAY_A);
         $events = array();
         foreach ($results as $result) {
             $events[$result['event_id']] = new EM_Event($result);
         }
         return $events;
         //We return all the events matched as an EM_Event array.
     }
     //We assume it's either an empty array or array of search arguments to merge with defaults
     $args = self::get_default_search($args);
     $limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : '';
     $offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : '';
     $groupby_sql = '';
     //Get the default conditions
     $conditions = self::build_sql_conditions($args);
     //Put it all together
     $where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : '';
     //Get ordering instructions
     $EM_Event = new EM_Event();
     $EM_Location = new EM_Location();
     $orderby = self::build_sql_orderby($args, array_keys(array_merge($EM_Event->fields, $EM_Location->fields)), get_option('dbem_events_default_order'));
     //Now, build orderby sql
     $orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : '';
     //Create the SQL statement and execute
     if (!$count && $args['array']) {
         $selectors_array = array();
         foreach (array_keys($EM_Event->fields) as $field_selector) {
             $selectors_array[] = $events_table . '.' . $field_selector;
         }
         $selectors = implode(',', $selectors_array);
     } elseif (EM_MS_GLOBAL) {
         $selectors = $events_table . '.post_id, ' . $events_table . '.blog_id';
         $groupby_sql[] = $events_table . '.post_id, ' . $events_table . '.blog_id';
     } else {
         $selectors = $events_table . '.post_id';
         $groupby_sql[] = $events_table . '.post_id';
         //prevent duplicates showing in lists
     }
     if ($count) {
         $selectors = 'SQL_CALC_FOUND_ROWS *';
         $limit = 'LIMIT 1';
         $offset = 'OFFSET 0';
     }
     //add group_by if needed
     $groupby_sql = !empty($groupby_sql) && is_array($groupby_sql) ? 'GROUP BY ' . implode(',', $groupby_sql) : '';
     $sql = apply_filters('em_events_get_sql', "\r\n\t\t\tSELECT {$selectors} FROM {$events_table}\r\n\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\r\n\t\t\t{$where}\r\n\t\t\t{$groupby_sql} {$orderby_sql}\r\n\t\t\t{$limit} {$offset}\r\n\t\t", $args);
     //If we're only counting results, return the number of results
     if ($count) {
         $wpdb->query($sql);
         return apply_filters('em_events_get_count', $wpdb->get_var('SELECT FOUND_ROWS()'), $args);
     }
     $results = $wpdb->get_results($sql, ARRAY_A);
     //If we want results directly in an array, why not have a shortcut here?
     if ($args['array'] == true) {
         return apply_filters('em_events_get_array', $results, $args);
     }
     //Make returned results EM_Event objects
     $results = is_array($results) ? $results : array();
     $events = array();
     if (EM_MS_GLOBAL) {
         foreach ($results as $event) {
             $events[] = em_get_event($event['post_id'], $event['blog_id']);
         }
     } else {
         foreach ($results as $event) {
             $events[] = em_get_event($event['post_id'], 'post_id');
         }
     }
     return apply_filters('em_events_get', $events, $args);
 }
예제 #14
0
 public static function meta_boxes()
 {
     global $EM_Event, $post;
     //no need to proceed if we're not dealing with a recurring event
     if ($post->post_type != 'event-recurring') {
         return;
     }
     //since this is the first point when the admin area loads event stuff, we load our EM_Event here
     if (empty($EM_Event) && !empty($post)) {
         $EM_Event = em_get_event($post->ID, 'post_id');
     }
     add_meta_box('em-event-recurring', __('Recurrences', 'events-manager'), array('EM_Event_Recurring_Post_Admin', 'meta_box_recurrence'), 'event-recurring', 'normal', 'high');
     //add_meta_box('em-event-meta', 'Event Meta (debugging only)', array('EM_Event_Post_Admin','meta_box_metadump'),'event-recurring', 'normal','high');
     add_meta_box('em-event-where', __('Where', 'events-manager'), array('EM_Event_Post_Admin', 'meta_box_location'), 'event-recurring', 'normal', 'high');
     if (get_option('dbem_rsvp_enabled') && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) {
         add_meta_box('em-event-bookings', __('Bookings/Registration', 'events-manager'), array('EM_Event_Post_Admin', 'meta_box_bookings'), 'event-recurring', 'normal', 'high');
     }
     if (get_option('dbem_attributes_enabled')) {
         add_meta_box('em-event-attributes', __('Attributes', 'events-manager'), array('EM_Event_Post_Admin', 'meta_box_attributes'), 'event-recurring', 'normal', 'default');
     }
     if (EM_MS_GLOBAL && !is_main_site() && get_option('dbem_categories_enabled')) {
         add_meta_box('em-event-categories', __('Site Categories', 'events-manager'), array('EM_Event_Post_Admin', 'meta_box_ms_categories'), 'event-recurring', 'side', 'low');
     }
     if (defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY) {
         add_meta_box('em-event-meta', 'Event Meta (debugging only)', array('EM_Event_Post_Admin', 'meta_box_metadump'), 'event-recurring', 'normal', 'high');
     }
 }
예제 #15
0
 /**
  * Gets the event for this object, or a blank event if none exists
  * @return EM_Event
  */
 function get_event()
 {
     if (is_numeric($this->event_id)) {
         return em_get_event($this->event_id);
     } else {
         return new EM_Event();
     }
 }
예제 #16
0
 /**
  * Smart event locator, saves a database read if possible. Note that if an event doesn't exist, a blank object will be created to prevent duplicates.
  */
 function get_event()
 {
     global $EM_Event;
     if (is_object($EM_Event) && $EM_Event->event_id == $this->event_id) {
         return $EM_Event;
     } else {
         if (is_numeric($this->event_id) && $this->event_id > 0) {
             return em_get_event($this->event_id, 'event_id');
         } elseif (count($this->bookings) > 0) {
             foreach ($this->bookings as $EM_Booking) {
                 /* @var $EM_Booking EM_Booking */
                 return em_get_event($EM_Booking->event_id, 'event_id');
             }
         }
     }
     return em_get_event($this->event_id, 'event_id');
 }
예제 #17
0
<section id="eventlist" class="wrap wrap--content wrap--shadow">
        <h3 class="title title--section">Eventos</h3>
        <h3 class="sep">Listado de eventos</h3>
        <?php 
if (have_posts()) {
    ?>
          <ul class="list">
        <?php 
    while (have_posts()) {
        the_post();
        $EM_Event = em_get_event($post->ID, 'post_id');
        $event_start_date = new DateTime($EM_Event->event_start_date . ' ' . $EM_Event->event_start_time);
        $event_end_date = new DateTime($EM_Event->event_end_date . ' ' . $EM_Event->event_end_time);
        ?>

          <!-- content -->
            <li class="item wrap wrap--frame wrap--flex">

              <div class="wrap wrap--frame__middle">
                <a href="<?php 
        the_permalink();
        ?>
"><?php 
        the_title();
        ?>
</a>
              </div>

              <div class="wrap wrap--frame__fourth">
                <span class="js-date">
                  <?php 
예제 #18
0
파일: em-posts.php 프로젝트: hscale/webento
function em_map_meta_cap($caps, $cap, $user_id, $args)
{
    /* Handle event reads */
    if ('edit_event' == $cap || 'delete_event' == $cap || 'read_event' == $cap) {
        $EM_Event = em_get_event($args[0], 'post_id');
        $post_type = get_post_type_object($EM_Event->post_type);
        /* Set an empty array for the caps. */
        $caps = array();
        //Filter according to event caps
        switch ($cap) {
            case 'read_event':
                if ('private' != $EM_Event->post_status) {
                    $caps[] = 'read';
                } elseif ($user_id == $EM_Event->event_owner) {
                    $caps[] = 'read';
                } else {
                    $caps[] = $post_type->cap->read_private_posts;
                }
                break;
            case 'edit_event':
                if ($user_id == $EM_Event->event_owner) {
                    $caps[] = $post_type->cap->edit_posts;
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
                break;
            case 'delete_event':
                if ($user_id == $EM_Event->event_owner) {
                    $caps[] = $post_type->cap->delete_posts;
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
                break;
        }
    }
    if ('edit_recurring_event' == $cap || 'delete_recurring_event' == $cap || 'read_recurring_event' == $cap) {
        $EM_Event = em_get_event($args[0], 'post_id');
        $post_type = get_post_type_object($EM_Event->post_type);
        /* Set an empty array for the caps. */
        $caps = array();
        //Filter according to recurring_event caps
        switch ($cap) {
            case 'read_recurring_event':
                if ('private' != $EM_Event->post_status) {
                    $caps[] = 'read';
                } elseif ($user_id == $EM_Event->event_owner) {
                    $caps[] = 'read';
                } else {
                    $caps[] = $post_type->cap->read_private_posts;
                }
                break;
            case 'edit_recurring_event':
                if ($user_id == $EM_Event->event_owner) {
                    $caps[] = $post_type->cap->edit_posts;
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
                break;
            case 'delete_recurring_event':
                if ($user_id == $EM_Event->event_owner) {
                    $caps[] = $post_type->cap->delete_posts;
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
                break;
        }
    }
    if ('edit_location' == $cap || 'delete_location' == $cap || 'read_location' == $cap) {
        $EM_Location = em_get_location($args[0], 'post_id');
        $post_type = get_post_type_object($EM_Location->post_type);
        /* Set an empty array for the caps. */
        $caps = array();
        //Filter according to location caps
        switch ($cap) {
            case 'read_location':
                if ('private' != $EM_Location->post_status) {
                    $caps[] = 'read';
                } elseif ($user_id == $EM_Location->location_owner) {
                    $caps[] = 'read';
                } else {
                    $caps[] = $post_type->cap->read_private_posts;
                }
                break;
            case 'edit_location':
                if ($user_id == $EM_Location->location_owner) {
                    $caps[] = $post_type->cap->edit_posts;
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
                break;
            case 'delete_location':
                if ($user_id == $EM_Location->location_owner) {
                    $caps[] = $post_type->cap->delete_posts;
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
                break;
        }
    }
    /* Return the capabilities required by the user. */
    return $caps;
}
예제 #19
0
function em_migrate_uploads()
{
    //build array of images
    global $wpdb;
    $mime_types = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
    require_once ABSPATH . "wp-admin" . '/includes/file.php';
    require_once ABSPATH . "wp-admin" . '/includes/image.php';
    $pattern = EM_IMAGE_DS == '/' ? EM_IMAGE_UPLOAD_DIR . '*/*' : EM_IMAGE_UPLOAD_DIR . '*';
    $files = glob($pattern);
    $file_array = array();
    foreach ($files as $file) {
        $matches = array();
        if (preg_match('/\\/(events|locations\\/)?(event|location)-([0-9]+).([a-zA-Z]{3})/', $file, $matches)) {
            $file_array[$matches[2]][$matches[3]] = array('file' => $file, 'url' => EM_IMAGE_UPLOAD_URI . $matches[1] . $matches[2] . '-' . $matches[3] . '.' . $matches[4], 'type' => 'image/' . $matches[4]);
        }
    }
    $result = array('success' => 0, 'fail' => 0);
    if (count($file_array) > 0) {
        foreach ($file_array as $type => $file_type) {
            foreach ($file_type as $id => $attachment) {
                if ($type == 'event') {
                    $post = em_get_event($id);
                } elseif ($type == 'location') {
                    $post = em_get_location($id);
                }
                if (!empty($post->ID)) {
                    $attachment_data = array('post_mime_type' => $attachment['type'], 'post_title' => $post->post_title, 'post_content' => '', 'post_status' => 'inherit');
                    $attachment_id = wp_insert_attachment($attachment_data, $attachment['file'], $post->ID);
                    $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $attachment['file']);
                    wp_update_attachment_metadata($attachment_id, $attachment_metadata);
                    //delete the old attachment
                    update_post_meta($post->post_id, '_thumbnail_id', $attachment_id);
                    //is it recurring? If so add attachment to recurrences
                    if ($type == 'event' && $post->is_recurring()) {
                        $results = $wpdb->get_col('SELECT post_id FROM ' . EM_EVENTS_TABLE . ' WHERE recurrence_id=' . $post->event_id);
                        foreach ($results as $post_id) {
                            update_post_meta($post_id, '_thumbnail_id', $attachment_id);
                        }
                    }
                    $result['success']++;
                }
            }
        }
    }
    delete_option('dbem_migrate_images_nag');
    delete_option('dbem_migrate_images');
    return $result;
}
예제 #20
0
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     if (function_exists('icl_translate')) {
         $form_intro = empty($instance['form_intro']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['form_intro'], 0, 10)), $instance['form_intro']);
         $btn_info = empty($instance['btn_info']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['btn_info'], 0, 10)), $instance['btn_info']);
         $btn_transport = empty($instance['btn_transport']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['btn_transport'], 0, 10)), $instance['btn_transport']);
         $btn_pay = empty($instance['btn_pay']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['btn_pay'], 0, 10)), $instance['btn_pay']);
         $btn_book = empty($instance['btn_book']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['btn_book'], 0, 10)), $instance['btn_book']);
         $btn_stay = empty($instance['btn_stay']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['btn_stay'], 0, 10)), $instance['btn_stay']);
         $btn_cancel = empty($instance['btn_cancel']) ? ' ' : icl_translate('wpml_custom', 'wpml_custom_' . sanitize_title(substr($instance['btn_cancel'], 0, 10)), $instance['btn_cancel']);
     } else {
         $form_intro = empty($instance['form_intro']) ? ' ' : apply_filters('widget_text', $instance['form_intro']);
         $btn_info = empty($instance['btn_info']) ? ' ' : apply_filters('widget_text', $instance['btn_info']);
         $btn_transport = empty($instance['btn_transport']) ? ' ' : apply_filters('widget_text', $instance['btn_transport']);
         $btn_pay = empty($instance['btn_pay']) ? ' ' : apply_filters('widget_text', $instance['btn_pay']);
         $btn_book = empty($instance['btn_book']) ? ' ' : apply_filters('widget_text', $instance['btn_book']);
         $btn_stay = empty($instance['btn_stay']) ? ' ' : apply_filters('widget_text', $instance['btn_stay']);
         $btn_cancel = empty($instance['btn_cancel']) ? ' ' : apply_filters('widget_text', $instance['btn_cancel']);
     }
     $btn_info_link = apply_filters('widget_text', $instance['btn_info_link']);
     $btn_transport_link = apply_filters('widget_text', $instance['btn_transport_link']);
     $btn_pay_link = apply_filters('widget_text', $instance['btn_pay_link']);
     $btn_book_link = apply_filters('widget_text', $instance['btn_book_link']);
     $btn_stay_link = apply_filters('widget_text', $instance['btn_stay_link']);
     $btn_cancel_link = apply_filters('widget_text', $instance['btn_cancel_link']);
     // get events-manager plugin data on single event posts
     if (is_singular('event')) {
         $EM_Event = em_get_event(get_queried_object_id(), 'post_id');
         $event_data = $EM_Event->output('#d/#m/#Y - #_EVENTNAME');
     }
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo '<div class="btn-container">';
     if ($form_intro) {
         echo '<p>' . $form_intro . '</p>';
     }
     if ($btn_info_link) {
         if (is_singular('event')) {
             echo ' <a class="btn btn-form btn-default" href="' . $btn_info_link . '?event_id=' . $event_data . '" title="Link to ' . $btn_info_link . '"><i class="fa fa-info fa-fw"></i>&nbsp;' . $btn_info . '</a> ';
         } else {
             echo ' <a class="btn btn-form btn-default" href="' . $btn_info_link . '" title="Link to ' . $btn_info_link . '"><i class="fa fa-info fa-fw"></i>&nbsp;' . $btn_info . '</a> ';
         }
     }
     if ($btn_book_link) {
         if (is_singular('event')) {
             echo ' <a class="btn btn-form btn-default" href="' . $btn_book_link . '?event_id=' . $event_data . '" title="Link to ' . $btn_book_link . '"><i class="fa fa-heart fa-fw"></i>&nbsp;' . $btn_book . '</a> ';
         } else {
             echo ' <a class="btn btn-form btn-default" href="' . $btn_book_link . '" title="Link to ' . $btn_book_link . '"><i class="fa fa-heart fa-fw"></i>&nbsp;' . $btn_book . '</a> ';
         }
     }
     if ($btn_stay_link) {
         echo ' <a class="btn btn-form btn-default" href="' . $btn_stay_link . '" title="Link to ' . $btn_stay_link . '"><i class="fa fa-star fa-fw"></i>&nbsp;' . $btn_stay . '</a> ';
     }
     if ($btn_transport_link) {
         echo ' <a class="btn btn-form btn-default" href="' . $btn_transport_link . '" title="Link to ' . $btn_transport_link . '"><i class="fa fa-automobile fa-fw"></i>&nbsp;' . $btn_transport . '</a> ';
     }
     if ($btn_pay_link) {
         echo ' <a class="btn btn-form btn-default" href="' . $btn_pay_link . '" title="Link to ' . $btn_pay_link . '"><i class="fa fa-upload fa-fw"></i>&nbsp;' . $btn_pay . '</a> ';
     }
     if ($btn_cancel_link) {
         echo ' <a class="btn btn-form btn-default" href="' . $btn_cancel_link . '" title="Link to ' . $btn_cancel_link . '"><i class="fa fa-close fa-fw"></i>&nbsp;' . $btn_cancel . '</a> ';
     }
     echo '</div>';
     echo $args['after_widget'];
 }
예제 #21
0
 /**
  * Smart event locator, saves a database read if possible.
  * @return EM_Event 
  */
 function get_event()
 {
     return em_get_event($this->event_id);
 }
예제 #22
0
 public static function untrash_post($post_id)
 {
     if (get_post_type($post_id) == 'event-recurring') {
         global $wpdb;
         //set a constant so we know this event doesn't need 'saving'
         if (!defined('UNTRASHING_' . $post_id)) {
             define('UNTRASHING_' . $post_id, true);
         }
         $EM_Event = em_get_event($post_id, 'post_id');
         //only untrash other events if this isn't a draft-never-published event, because if so it never had other events to untrash
         if (!empty($EM_Event->event_id)) {
             $events_array = EM_Events::get(array('recurrence_id' => $EM_Event->event_id, 'scope' => 'all', 'status' => 'everything'));
             foreach ($events_array as $event) {
                 /* @var $event EM_Event */
                 if ($EM_Event->event_id == $event->recurrence_id) {
                     wp_untrash_post($event->post_id);
                 }
             }
         }
     }
 }
/**
 * Overrides the default post format of an event and can display an event as a page, which uses the page.php template.
 * @param string $template
 * @return string
 */
function bp_em_private_event_check($template)
{
    global $post, $wpdb, $wp_query, $bp;
    if ($post->post_type == EM_POST_TYPE_EVENT) {
        $EM_Event = em_get_event($post);
        //echo "<pre>"; print_r($EM_Event); echo "</pre>"; die();
        if (!empty($EM_Event->event_private) && !empty($EM_Event->group_id)) {
            if (is_user_logged_in()) {
                //make sure user is a member of this group, whether private or not, private groups just aren't shown to non-members of a group
                $id_lookup = $wpdb->get_var($wpdb->prepare("SELECT m.group_id FROM {$bp->groups->table_name_members} m WHERE m.group_id = %s AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $EM_Event->group_id, get_current_user_id()));
                if ($id_lookup != $EM_Event->group_id) {
                    unset($post);
                    $wp_query->set_404();
                    $template = locate_template(array('404.php'), false);
                }
            } else {
                unset($post);
                $wp_query->set_404();
                $template = locate_template(array('404.php'), false);
            }
        }
    }
    return $template;
}
예제 #24
0
 function get_edit_reschedule_url()
 {
     if ($this->is_recurrence()) {
         $EM_Event = em_get_event($this->recurrence_id);
         return $EM_Event->get_edit_url();
     }
 }
예제 #25
0
 public static function get($args)
 {
     global $wpdb;
     $calendar_array = array();
     $calendar_array['cells'] = array();
     $args = apply_filters('em_calendar_get_args', $args);
     $original_args = $args;
     $args = self::get_default_search($args);
     $full = $args['full'];
     //For ZDE, don't delete pls
     $month = $args['month'];
     $year = $args['year'];
     $long_events = $args['long_events'];
     $limit = $args['limit'];
     //limit arg will be used per day and not for events search
     $week_starts_on_sunday = get_option('dbem_week_starts_sunday');
     $start_of_week = get_option('start_of_week');
     if (!(is_numeric($month) && $month <= 12 && $month > 0)) {
         $month = date('m', current_time('timestamp'));
     }
     if (!is_numeric($year)) {
         $year = date('Y', current_time('timestamp'));
     }
     // Get the first day of the month
     $month_start = mktime(0, 0, 0, $month, 1, $year);
     $calendar_array['month_start'] = $month_start;
     // Get friendly month name
     $month_name = date('M', $month_start);
     // Figure out which day of the week
     // the month starts on.
     $month_start_day = date('D', $month_start);
     switch ($month_start_day) {
         case "Sun":
             $offset = 0;
             break;
         case "Mon":
             $offset = 1;
             break;
         case "Tue":
             $offset = 2;
             break;
         case "Wed":
             $offset = 3;
             break;
         case "Thu":
             $offset = 4;
             break;
         case "Fri":
             $offset = 5;
             break;
         case "Sat":
             $offset = 6;
             break;
     }
     //We need to go back to the WP defined day when the week started, in case the event day is near the end
     $offset -= $start_of_week;
     if ($offset < 0) {
         $offset += 7;
     }
     // determine how many days are in the last month.
     $month_last = $month - 1;
     $month_next = $month + 1;
     $calendar_array['month_next'] = $month_next;
     $year_last = $year;
     $year_next = $year;
     $calendar_array['year_next'] = $year_next;
     if ($month == 1) {
         $month_last = 12;
         $year_last = $year - 1;
     } elseif ($month == 12) {
         $month_next = 1;
         $year_next = $year + 1;
     }
     $calendar_array['month_last'] = $month_last;
     $calendar_array['year_last'] = $year_last;
     $num_days_last = self::days_in_month($month_last, $year_last);
     // determine how many days are in the current month.
     $num_days_current = self::days_in_month($month, $year);
     // Build an array for the current days
     // in the month
     for ($i = 1; $i <= $num_days_current; $i++) {
         $num_days_array[] = mktime(0, 0, 0, $month, $i, $year);
     }
     // Build an array for the number of days
     // in last month
     for ($i = 1; $i <= $num_days_last; $i++) {
         $num_days_last_array[] = mktime(0, 0, 0, $month_last, $i, $year_last);
     }
     // If the $offset from the starting day of the
     // week happens to be Sunday, $offset would be 0,
     // so don't need an offset correction.
     if ($offset > 0) {
         $offset_correction = array_slice($num_days_last_array, -$offset, $offset);
         $new_count = array_merge($offset_correction, $num_days_array);
         $offset_count = count($offset_correction);
     } else {
         // The else statement is to prevent building the $offset array.
         $offset_count = 0;
         $new_count = $num_days_array;
     }
     // count how many days we have with the two
     // previous arrays merged together
     $current_num = count($new_count);
     // Since we will have 5 HTML table rows (TR)
     // with 7 table data entries (TD)
     // we need to fill in 35 TDs
     // so, we will have to figure out
     // how many days to appened to the end
     // of the final array to make it 35 days.
     if (!empty($args['number_of_weeks']) && is_numeric($args['number_of_weeks'])) {
         $num_weeks = $args['number_of_weeks'];
     } elseif ($current_num > 35) {
         $num_weeks = 6;
     } else {
         $num_weeks = 5;
     }
     $outset = $num_weeks * 7 - $current_num;
     // Outset Correction
     for ($i = 1; $i <= $outset; $i++) {
         $new_count[] = mktime(0, 0, 0, $month_next, $i, $year_next);
     }
     // Now let's "chunk" the $all_days array
     // into weeks. Each week has 7 days
     // so we will array_chunk it into 7 days.
     $weeks = array_chunk($new_count, 7);
     //Get an array of arguments that don't include default valued args
     $link_args = self::get_link_args($args);
     $previous_url = "?ajaxCalendar=1&amp;mo={$month_last}&amp;yr={$year_last}&amp;{$link_args}";
     $next_url = "?ajaxCalendar=1&amp;mo={$month_next}&amp;yr={$year_next}&amp;{$link_args}";
     $weekdays = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     if (!empty($args['full'])) {
         if (get_option('dbem_full_calendar_abbreviated_weekdays')) {
             $weekdays = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
         }
         $day_initials_length = get_option('dbem_full_calendar_initials_length');
     } else {
         if (get_option('dbem_small_calendar_abbreviated_weekdays')) {
             $weekdays = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
         }
         $day_initials_length = get_option('dbem_small_calendar_initials_length');
     }
     for ($n = 0; $n < $start_of_week; $n++) {
         $last_day = array_shift($weekdays);
         $weekdays[] = $last_day;
     }
     $days_initials_array = array();
     foreach ($weekdays as $weekday) {
         $days_initials_array[] = self::translate_and_trim($weekday, $day_initials_length);
     }
     $calendar_array['links'] = array('previous_url' => $previous_url, 'next_url' => $next_url);
     $calendar_array['row_headers'] = $days_initials_array;
     // Now we break each key of the array
     // into a week and create a new table row for each
     // week with the days of that week in the table data
     $i = 0;
     $current_date = date('Y-m-d', current_time('timestamp'));
     $week_count = 0;
     foreach ($weeks as $week) {
         foreach ($week as $d) {
             $date = date('Y-m-d', $d);
             $calendar_array['cells'][$date] = array('date' => $d, 'events' => array(), 'events_count' => 0);
             //set it up so we have the exact array of dates to be filled
             if ($i < $offset_count) {
                 //if it is PREVIOUS month
                 $calendar_array['cells'][$date]['type'] = 'pre';
             }
             if ($i >= $offset_count && $i < $num_weeks * 7 - $outset) {
                 // if it is THIS month
                 if ($current_date == $date) {
                     $calendar_array['cells'][$date]['type'] = 'today';
                 }
             } elseif ($outset > 0) {
                 //if it is NEXT month
                 if ($i >= $num_weeks * 7 - $outset) {
                     $calendar_array['cells'][$date]['type'] = 'post';
                 }
             }
             $i++;
         }
         $week_count++;
     }
     //query the database for events in this time span with $offset days before and $outset days after this month to account for these cells in the calendar
     $scope_datetime_start = new DateTime("{$year}-{$month}-1");
     $scope_datetime_end = new DateTime($scope_datetime_start->format('Y-m-t'));
     $scope_datetime_start->modify("-{$offset} days");
     $scope_datetime_end->modify("+{$outset} days");
     //we have two methods here, one for high-volume event sites i.e. many thousands of events per month, and another for thousands or less per month.
     $args['array'] = true;
     //we're getting an array first to avoid extra queries during object creation
     unset($args['month']);
     unset($args['year']);
     unset($args['limit']);
     //limits in the events search won't help
     if (defined('EM_CALENDAR_OPT') && EM_CALENDAR_OPT) {
         //here we loop through each day, query that specific date, and then compile a list of event objects
         //in this mode the count will never be accurate, we're grabing at most (31 + 14 days) * (limit + 1) events to reduce memory loads
         $args['limit'] = $limit + 1;
         $scope_datetime_loop = $scope_datetime_start->format('U');
         $events = array();
         while ($scope_datetime_loop <= $scope_datetime_end->format('U')) {
             $args['scope'] = date('Y-m-d', $scope_datetime_loop);
             foreach (EM_Events::get($args) as $event) {
                 $events[$event['event_id']] = $event;
             }
             $scope_datetime_loop += 86400;
             //add a day
         }
     } else {
         //just load all the events for this time-range
         $args['scope'] = array($scope_datetime_start->format('Y-m-d'), $scope_datetime_end->format('Y-m-d'));
         $events = EM_Events::get($args);
     }
     //back to what it was
     $args['month'] = $month;
     $args['year'] = $year;
     $args['limit'] = $limit;
     $event_format = get_option('dbem_full_calendar_event_format');
     $event_title_format = get_option('dbem_small_calendar_event_title_format');
     $event_title_separator_format = get_option('dbem_small_calendar_event_title_separator');
     $eventful_days = array();
     $eventful_days_count = array();
     if ($events) {
         //Go through the events and slot them into the right d-m index
         foreach ($events as $event) {
             $event = apply_filters('em_calendar_output_loop_start', $event);
             if ($long_events) {
                 //If $long_events is set then show a date as eventful if there is an multi-day event which runs during that day
                 $event_start_ts = strtotime($event['event_start_date']);
                 $event_end_ts = strtotime($event['event_end_date']);
                 $event_end_ts = $event_end_ts > $scope_datetime_end->format('U') ? $scope_datetime_end->format('U') : $event_end_ts;
                 while ($event_start_ts <= $event_end_ts) {
                     //we loop until the last day of our time-range, not the end date of the event, which could be in a year
                     //Ensure date is within event dates and also within the limits of events to show per day, if so add to eventful days array
                     $event_eventful_date = date('Y-m-d', $event_start_ts);
                     if (empty($eventful_days_count[$event_eventful_date]) || !$limit || $eventful_days_count[$event_eventful_date] < $limit) {
                         //now we know this is an event that'll be used, convert it to an object
                         $EM_Event = EM_MS_GLOBAL ? em_get_event($event['post_id'], $event['blog_id']) : ($EM_Event = em_get_event($event['post_id'], 'post_id'));
                         if (empty($eventful_days[$event_eventful_date]) || !is_array($eventful_days[$event_eventful_date])) {
                             $eventful_days[$event_eventful_date] = array();
                         }
                         //add event to array with a corresponding timestamp for sorting of times including long and all-day events
                         $event_ts_marker = $EM_Event->event_all_day ? 0 : (int) strtotime($event_eventful_date . ' ' . $EM_Event->event_start_time);
                         while (!empty($eventful_days[$event_eventful_date][$event_ts_marker])) {
                             $event_ts_marker++;
                             //add a second
                         }
                         $eventful_days[$event_eventful_date][$event_ts_marker] = $EM_Event;
                     }
                     //count events for that day
                     $eventful_days_count[$event_eventful_date] = empty($eventful_days_count[$event_eventful_date]) ? 1 : $eventful_days_count[$event_eventful_date] + 1;
                     $event_start_ts += 86400;
                     //add a day
                 }
             } else {
                 //Only show events on the day that they start
                 $event_eventful_date = $event['event_start_date'];
                 if (empty($eventful_days_count[$event_eventful_date]) || !$limit || $eventful_days_count[$event_eventful_date] < $limit) {
                     $EM_Event = EM_MS_GLOBAL ? em_get_event($event['post_id'], $event['blog_id']) : em_get_event($event['post_id'], 'post_id');
                     if (empty($eventful_days[$event_eventful_date]) || !is_array($eventful_days[$event_eventful_date])) {
                         $eventful_days[$event_eventful_date] = array();
                     }
                     //add event to array with a corresponding timestamp for sorting of times including long and all-day events
                     $event_ts_marker = $EM_Event->event_all_day ? 0 : (int) $EM_Event->start;
                     while (!empty($eventful_days[$event_eventful_date][$event_ts_marker])) {
                         $event_ts_marker++;
                         //add a second
                     }
                     $eventful_days[$event_eventful_date][$event_ts_marker] = $EM_Event;
                 }
                 //count events for that day
                 $eventful_days_count[$event['event_start_date']] = empty($eventful_days_count[$event['event_start_date']]) ? 1 : $eventful_days_count[$event['event_start_date']] + 1;
             }
         }
     }
     //generate a link argument string containing event search only
     $day_link_args = self::get_link_args(array_intersect_key($original_args, EM_Events::get_post_search($args, true)));
     foreach ($eventful_days as $day_key => $events) {
         if (array_key_exists($day_key, $calendar_array['cells'])) {
             //Get link title for this date
             $events_titles = array();
             foreach ($events as $event) {
                 if (!$limit || count($events_titles) < $limit) {
                     $events_titles[] = $event->output($event_title_format);
                 } else {
                     $events_titles[] = get_option('dbem_display_calendar_events_limit_msg');
                     break;
                 }
             }
             $calendar_array['cells'][$day_key]['link_title'] = implode($event_title_separator_format, $events_titles);
             //Get the link to this calendar day
             global $wp_rewrite;
             if ($eventful_days_count[$day_key] > 1 || !get_option('dbem_calendar_direct_links')) {
                 if (get_option("dbem_events_page") > 0) {
                     $event_page_link = get_permalink(get_option("dbem_events_page"));
                     //PAGE URI OF EM
                 } else {
                     if ($wp_rewrite->using_permalinks()) {
                         $event_page_link = trailingslashit(home_url()) . EM_POST_TYPE_EVENT_SLUG . '/';
                         //don't use EM_URI here, since ajax calls this before EM_URI is defined.
                     } else {
                         $event_page_link = trailingslashit(home_url()) . '?post_type=' . EM_POST_TYPE_EVENT;
                         //don't use EM_URI here, since ajax calls this before EM_URI is defined.
                     }
                 }
                 if ($wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS')) {
                     $calendar_array['cells'][$day_key]['link'] = trailingslashit($event_page_link) . $day_key . "/";
                     if (!empty($day_link_args)) {
                         $calendar_array['cells'][$day_key]['link'] .= '?' . $day_link_args;
                     }
                 } else {
                     $joiner = stristr($event_page_link, "?") ? "&amp;" : "?";
                     $calendar_array['cells'][$day_key]['link'] = $event_page_link . $joiner . "calendar_day=" . $day_key;
                     if (!empty($day_link_args)) {
                         $calendar_array['cells'][$day_key]['link'] .= '&amp;' . $day_link_args;
                     }
                 }
             } else {
                 foreach ($events as $EM_Event) {
                     $calendar_array['cells'][$day_key]['link'] = $EM_Event->get_permalink();
                 }
             }
             //Add events to array
             $calendar_array['cells'][$day_key]['events_count'] = $eventful_days_count[$day_key];
             $calendar_array['cells'][$day_key]['events'] = $events;
         }
     }
     return apply_filters('em_calendar_get', $calendar_array, $args);
 }
예제 #26
0
/**
 * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET.
 */
function em_init_actions()
{
    global $wpdb, $EM_Notices, $EM_Event;
    if (defined('DOING_AJAX') && DOING_AJAX) {
        $_REQUEST['em_ajax'] = true;
    }
    //NOTE - No EM objects are globalized at this point, as we're hitting early init mode.
    //TODO Clean this up.... use a uniformed way of calling EM Ajax actions
    if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) {
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') {
            if (isset($_REQUEST['id'])) {
                $EM_Location = new EM_Location($_REQUEST['id'], 'location_id');
                $location_array = $EM_Location->to_array();
                $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format'));
                echo EM_Object::json_encode($location_array);
            }
            die;
        }
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') {
            if (isset($_REQUEST['id'])) {
                $EM_Ticket = new EM_Ticket($_REQUEST['id']);
                $result = $EM_Ticket->delete();
                if ($result) {
                    $result = array('result' => true);
                } else {
                    $result = array('result' => false, 'error' => $EM_Ticket->feedback_message);
                }
            } else {
                $result = array('result' => false, 'error' => __('No ticket id provided', 'dbem'));
            }
            echo EM_Object::json_encode($result);
            die;
        }
        if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') {
            $EM_Locations = EM_Locations::get($_REQUEST);
            $json_locations = array();
            foreach ($EM_Locations as $location_key => $EM_Location) {
                $json_locations[$location_key] = $EM_Location->to_array();
                $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format'));
            }
            echo EM_Object::json_encode($json_locations);
            die;
        }
        if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) {
            //FIXME if long events enabled originally, this won't show up on ajax call
            echo EM_Calendar::output($_REQUEST, false);
            die;
        }
    }
    //Event Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 5) == 'event') {
        //Load the event object, with saved event if requested
        if (!empty($_REQUEST['event_id'])) {
            $EM_Event = new EM_Event($_REQUEST['event_id']);
        } else {
            $EM_Event = new EM_Event();
        }
        //Save Event, only via BP or via [event_form]
        if ($_REQUEST['action'] == 'event_save' && $EM_Event->can_manage('edit_events', 'edit_others_events')) {
            //Check Nonces
            if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'wpnonce_event_save')) {
                exit('Trying to perform an illegal action.');
            }
            //Grab and validate submitted data
            if ($EM_Event->get_post() && $EM_Event->save()) {
                //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
                $events_result = true;
                //Success notice
                if (is_user_logged_in()) {
                    if (empty($_REQUEST['event_id'])) {
                        $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_form_result_success')), true);
                    } else {
                        $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_form_result_success_updated')), true);
                    }
                } else {
                    $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_anonymous_result_success')), true);
                }
                $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                $redirect = em_add_get_params($redirect, array('success' => 1));
                wp_redirect($redirect);
                exit;
            } else {
                $EM_Notices->add_error($EM_Event->get_errors());
                $events_result = false;
            }
        }
        if ($_REQUEST['action'] == 'event_duplicate' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_duplicate_' . $EM_Event->event_id)) {
            $EM_Event = $EM_Event->duplicate();
            if ($EM_Event === false) {
                $EM_Notices->add_error($EM_Event->errors, true);
            } else {
                $EM_Notices->add_confirm($EM_Event->feedback_message, true);
            }
            wp_redirect(wp_get_referer());
            exit;
        }
        if ($_REQUEST['action'] == 'event_delete' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_delete_' . $EM_Event->event_id)) {
            //DELETE action
            $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : '';
            if (EM_Object::array_is_numeric($selectedEvents)) {
                $events_result = EM_Events::delete($selectedEvents);
            } elseif (is_object($EM_Event)) {
                $events_result = $EM_Event->delete();
            }
            $plural = count($selectedEvents) > 1 ? __('Events', 'dbem') : __('Event', 'dbem');
            if ($events_result) {
                $message = !empty($EM_Event->feedback_message) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural);
                $EM_Notices->add_confirm($message, true);
            } else {
                $message = !empty($EM_Event->errors) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural);
                $EM_Notices->add_error($message, true);
            }
            wp_redirect(wp_get_referer());
            exit;
        } elseif ($_REQUEST['action'] == 'event_detach' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_detach_' . get_current_user_id() . '_' . $EM_Event->event_id)) {
            //Detach event and move on
            if ($EM_Event->detach()) {
                $EM_Notices->add_confirm($EM_Event->feedback_message, true);
            } else {
                $EM_Notices->add_error($EM_Event->errors, true);
            }
            wp_redirect(wp_get_referer());
            exit;
        } elseif ($_REQUEST['action'] == 'event_attach' && !empty($_REQUEST['undo_id']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_attach_' . get_current_user_id() . '_' . $EM_Event->event_id)) {
            //Detach event and move on
            if ($EM_Event->attach($_REQUEST['undo_id'])) {
                $EM_Notices->add_confirm($EM_Event->feedback_message, true);
            } else {
                $EM_Notices->add_error($EM_Event->errors, true);
            }
            wp_redirect(wp_get_referer());
            exit;
        }
        //AJAX Exit
        if (isset($events_result) && !empty($_REQUEST['em_ajax'])) {
            if ($events_result) {
                $return = array('result' => true, 'message' => $EM_Event->feedback_message);
            } else {
                $return = array('result' => false, 'message' => $EM_Event->feedback_message, 'errors' => $EM_Event->errors);
            }
        }
    }
    //Location Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'location') {
        global $EM_Location, $EM_Notices;
        //Load the location object, with saved event if requested
        if (!empty($_REQUEST['location_id'])) {
            $EM_Location = new EM_Location($_REQUEST['location_id']);
        } else {
            $EM_Location = new EM_Location();
        }
        if ($_REQUEST['action'] == 'location_save' && current_user_can('edit_locations')) {
            //Check Nonces
            em_verify_nonce('location_save');
            //Grab and validate submitted data
            if ($EM_Location->get_post() && $EM_Location->save()) {
                //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Location->feedback_message, true);
                $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                wp_redirect($redirect);
                exit;
            } else {
                $EM_Notices->add_error($EM_Location->get_errors());
                $result = false;
            }
        } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete") {
            //delete location
            //get object or objects
            if (!empty($_REQUEST['locations']) || !empty($_REQUEST['location_id'])) {
                $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations'] : $_REQUEST['location_id'];
                $locations = EM_Locations::get($args);
                foreach ($locations as $location) {
                    if (!$location->delete()) {
                        $EM_Notices->add_error($location->get_errors());
                        $errors = true;
                    }
                }
                if (empty($errors)) {
                    $result = true;
                    $location_term = count($locations) > 1 ? __('Locations', 'dbem') : __('Location', 'dbem');
                    $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $location_term));
                } else {
                    $result = false;
                }
            }
        } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "locations_search" && (!empty($_REQUEST['term']) || !empty($_REQUEST['q']))) {
            $results = array();
            if (is_user_logged_in() || get_option('dbem_events_anonymous_submissions') && user_can(get_option('dbem_events_anonymous_user'), 'read_others_locations')) {
                $location_cond = is_user_logged_in() && !current_user_can('read_others_locations') ? "AND location_owner=" . get_current_user_id() : '';
                if (!is_user_logged_in() && get_option('dbem_events_anonymous_submissions')) {
                    if (!user_can(get_option('dbem_events_anonymous_user'), 'read_private_locations')) {
                        $location_cond = " AND location_private=0";
                    }
                } elseif (is_user_logged_in() && !current_user_can('read_private_locations')) {
                    $location_cond = " AND location_private=0";
                } elseif (!is_user_logged_in()) {
                    $location_cond = " AND location_private=0";
                }
                $location_cond = apply_filters('em_actions_locations_search_cond', $location_cond);
                $term = isset($_REQUEST['term']) ? '%' . $_REQUEST['term'] . '%' : '%' . $_REQUEST['q'] . '%';
                $sql = $wpdb->prepare("\r\n\t\t\t\t\tSELECT \r\n\t\t\t\t\t\tlocation_id AS `id`,\r\n\t\t\t\t\t\tConcat( location_name )  AS `label`,\r\n\t\t\t\t\t\tlocation_name AS `value`,\r\n\t\t\t\t\t\tlocation_address AS `address`, \r\n\t\t\t\t\t\tlocation_town AS `town`, \r\n\t\t\t\t\t\tlocation_state AS `state`,\r\n\t\t\t\t\t\tlocation_region AS `region`,\r\n\t\t\t\t\t\tlocation_postcode AS `postcode`,\r\n\t\t\t\t\t\tlocation_country AS `country`\r\n\t\t\t\t\tFROM " . EM_LOCATIONS_TABLE . " \r\n\t\t\t\t\tWHERE ( `location_name` LIKE %s ) AND location_status=1 {$location_cond} LIMIT 10\r\n\t\t\t\t", $term);
                $results = $wpdb->get_results($sql);
            }
            echo EM_Object::json_encode($results);
            die;
        }
        if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => true, 'message' => $EM_Location->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => false, 'message' => $EM_Location->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    }
    //Booking Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 7) == 'booking' && (is_user_logged_in() || $_REQUEST['action'] == 'booking_add' && get_option('dbem_bookings_anonymous'))) {
        global $EM_Event, $EM_Booking, $EM_Person;
        //Load the booking object, with saved booking if requested
        $EM_Booking = !empty($_REQUEST['booking_id']) ? em_get_booking($_REQUEST['booking_id']) : em_get_booking();
        if (!empty($EM_Booking->event_id)) {
            //Load the event object, with saved event if requested
            $EM_Event = $EM_Booking->get_event();
        } elseif (!empty($_REQUEST['event_id'])) {
            $EM_Event = new EM_Event($_REQUEST['event_id']);
        }
        $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete');
        $result = false;
        $feedback = '';
        if ($_REQUEST['action'] == 'booking_add') {
            //ADD/EDIT Booking
            ob_start();
            if (!defined('WP_CACHE') || !WP_CACHE) {
                em_verify_nonce('booking_add');
            }
            if (!is_user_logged_in() || get_option('dbem_bookings_double') || !$EM_Event->get_bookings()->has_booking(get_current_user_id())) {
                $EM_Booking->get_post();
                $post_validation = $EM_Booking->validate();
                do_action('em_booking_add', $EM_Event, $EM_Booking, $post_validation);
                if ($post_validation) {
                    //register the user - or not depending - according to the booking
                    $registration = em_booking_add_registration($EM_Booking);
                    $EM_Bookings = $EM_Event->get_bookings();
                    if ($registration && $EM_Bookings->add($EM_Booking)) {
                        if (is_user_logged_in() && is_multisite() && !is_user_member_of_blog(get_current_user_id(), get_current_blog_id())) {
                            add_user_to_blog(get_current_blog_id(), get_current_user_id(), get_option('default_role'));
                        }
                        $result = true;
                        $EM_Notices->add_confirm($EM_Bookings->feedback_message);
                        $feedback = $EM_Bookings->feedback_message;
                    } else {
                        $result = false;
                        $EM_Notices->add_error($EM_Bookings->get_errors());
                        $feedback = $EM_Bookings->feedback_message;
                    }
                    global $em_temp_user_data;
                    $em_temp_user_data = false;
                    //delete registered user temp info (if exists)
                } else {
                    $result = false;
                    $EM_Notices->add_error($EM_Booking->get_errors());
                }
            } else {
                $result = false;
                $feedback = get_option('dbem_booking_feedback_already_booked');
                $EM_Notices->add_error($feedback);
            }
            ob_clean();
        } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) {
            //ADD/EDIT Booking
            em_verify_nonce('booking_add_one');
            if (!$EM_Event->get_bookings()->has_booking(get_current_user_id()) || get_option('dbem_bookings_double')) {
                $EM_Booking = em_get_booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->event_id, 'booking_spaces' => 1));
                //new booking
                $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first();
                //get first ticket in this event and book one place there. similar to getting the form values in EM_Booking::get_post_values()
                $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->ticket_id, 'ticket_booking_spaces' => 1));
                $EM_Booking->tickets_bookings = new EM_Tickets_Bookings();
                $EM_Booking->tickets_bookings->booking = $EM_Ticket_Booking->booking = $EM_Booking;
                $EM_Booking->tickets_bookings->add($EM_Ticket_Booking);
                //Now save booking
                if ($EM_Event->get_bookings()->add($EM_Booking)) {
                    $result = true;
                    $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message);
                    $feedback = $EM_Event->get_bookings()->feedback_message;
                } else {
                    $result = false;
                    $EM_Notices->add_error($EM_Event->get_bookings()->get_errors());
                    $feedback = $EM_Event->get_bookings()->feedback_message;
                }
            } else {
                $result = false;
                $feedback = get_option('dbem_booking_feedback_already_booked');
                $EM_Notices->add_error($feedback);
            }
        } elseif ($_REQUEST['action'] == 'booking_cancel') {
            //Cancel Booking
            em_verify_nonce('booking_cancel');
            if ($EM_Booking->can_manage() || $EM_Booking->person->ID == get_current_user_id() && get_option('dbem_bookings_user_cancellation')) {
                if ($EM_Booking->cancel()) {
                    $result = true;
                    if (!defined('DOING_AJAX')) {
                        if ($EM_Booking->person->ID == get_current_user_id()) {
                            $EM_Notices->add_confirm(get_option('dbem_booking_feedback_cancelled'), true);
                        } else {
                            $EM_Notices->add_confirm($EM_Booking->feedback_message, true);
                        }
                        wp_redirect($_SERVER['HTTP_REFERER']);
                        exit;
                    }
                } else {
                    $result = false;
                    $EM_Notices->add_error($EM_Booking->get_errors());
                    $feedback = $EM_Booking->feedback_message;
                }
            } else {
                $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem'));
            }
            //TODO user action shouldn't check permission, booking object should.
        } elseif (array_key_exists($_REQUEST['action'], $allowed_actions) && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) {
            //Event Admin only actions
            $action = $allowed_actions[$_REQUEST['action']];
            //Just do it here, since we may be deleting bookings of different events.
            if (!empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])) {
                $results = array();
                foreach ($_REQUEST['bookings'] as $booking_id) {
                    $EM_Booking = em_get_booking($booking_id);
                    $result = $EM_Booking->{$action}();
                    $results[] = $result;
                    if (!in_array(false, $results) && !$result) {
                        $feedback = $EM_Booking->feedback_message;
                    }
                }
                $result = !in_array(false, $results);
            } elseif (is_object($EM_Booking)) {
                $result = $EM_Booking->{$action}();
                $feedback = $EM_Booking->feedback_message;
            }
            //FIXME not adhereing to object's feedback or error message, like other bits in this file.
            //TODO multiple deletion won't work in ajax
            if (!empty($_REQUEST['em_ajax'])) {
                if ($result) {
                    echo $feedback;
                } else {
                    echo '<span style="color:red">' . $feedback . '</span>';
                }
                die;
            }
        } elseif ($_REQUEST['action'] == 'booking_save') {
            em_verify_nonce('booking_save_' . $EM_Booking->booking_id);
            do_action('em_booking_save', $EM_Event, $EM_Booking);
            if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) {
                if ($EM_Booking->get_post(true) && $EM_Booking->validate(true) && $EM_Booking->save(false)) {
                    $EM_Notices->add_confirm($EM_Booking->feedback_message, true);
                    $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                    wp_redirect($redirect);
                    exit;
                } else {
                    $result = false;
                    $EM_Notices->add_error($EM_Booking->get_errors());
                    $feedback = $EM_Booking->feedback_message;
                }
            }
        } elseif ($_REQUEST['action'] == 'booking_set_status') {
            em_verify_nonce('booking_set_status_' . $EM_Booking->booking_id);
            if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings') && $_REQUEST['booking_status'] != $EM_Booking->booking_status) {
                if ($EM_Booking->set_status($_REQUEST['booking_status'], false, true)) {
                    if (!empty($_REQUEST['send_email'])) {
                        if ($EM_Booking->email(false)) {
                            $EM_Booking->feedback_message .= " " . __('Mail Sent.', 'dbem');
                        } else {
                            $EM_Booking->feedback_message .= ' <span style="color:red">' . __('ERROR : Mail Not Sent.', 'dbem') . '</span>';
                        }
                    }
                    $EM_Notices->add_confirm($EM_Booking->feedback_message, true);
                    $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                    wp_redirect($redirect);
                    exit;
                } else {
                    $result = false;
                    $EM_Notices->add_error($EM_Booking->get_errors());
                    $feedback = $EM_Booking->feedback_message;
                }
            }
        } elseif ($_REQUEST['action'] == 'booking_resend_email') {
            em_verify_nonce('booking_resend_email_' . $EM_Booking->booking_id);
            if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) {
                if ($EM_Booking->email(false, true)) {
                    $EM_Notices->add_confirm(__('Mail Sent.', 'dbem'), true);
                    $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                    wp_redirect($redirect);
                    exit;
                } else {
                    $result = false;
                    $EM_Notices->add_error(__('ERROR : Mail Not Sent.', 'dbem'));
                    $feedback = $EM_Booking->feedback_message;
                }
            }
        } elseif ($_REQUEST['action'] == 'booking_modify_person') {
            em_verify_nonce('booking_modify_person_' . $EM_Booking->booking_id);
            if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) {
                global $wpdb;
                $no_user = get_option('dbem_bookings_registration_disable') && $EM_Booking->get_person()->ID == get_option('dbem_bookings_registration_user');
                if ($no_user && $EM_Booking->get_person_post() && $wpdb->update(EM_BOOKINGS_TABLE, array('booking_meta' => serialize($EM_Booking->booking_meta)), array('booking_id' => $EM_Booking->booking_id))) {
                    $EM_Notices->add_confirm($EM_Booking->feedback_message, true);
                    $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                    wp_redirect($redirect);
                    exit;
                } else {
                    $result = false;
                    $EM_Notices->add_error($EM_Booking->get_errors());
                    $feedback = $EM_Booking->feedback_message;
                }
            }
            do_action('em_booking_modify_person', $EM_Event, $EM_Booking);
        }
        if ($result && defined('DOING_AJAX')) {
            $return = array('result' => true, 'message' => $feedback);
            echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking));
            die;
        } elseif (!$result && defined('DOING_AJAX')) {
            $return = array('result' => false, 'message' => $feedback, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking));
            die;
        }
    } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) {
        $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in'));
        if (!$result && defined('DOING_AJAX')) {
            $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking));
        }
        die;
    }
    //AJAX call for searches
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') {
        if ($_REQUEST['action'] == 'search_states') {
            $results = array();
            $conds = array();
            if (!empty($_REQUEST['country'])) {
                $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']);
            }
            if (!empty($_REQUEST['region'])) {
                $conds[] = $wpdb->prepare("( location_region = '%s' OR location_region IS NULL )", $_REQUEST['region']);
            }
            $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : '';
            $results = $wpdb->get_col("SELECT DISTINCT location_state FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' {$cond} ORDER BY location_state");
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                echo get_option('dbem_search_form_states_label');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_states', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        }
        if ($_REQUEST['action'] == 'search_towns') {
            $results = array();
            $conds = array();
            if (!empty($_REQUEST['country'])) {
                $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']);
            }
            if (!empty($_REQUEST['region'])) {
                $conds[] = $wpdb->prepare("( location_region = '%s' OR location_region IS NULL )", $_REQUEST['region']);
            }
            if (!empty($_REQUEST['state'])) {
                $conds[] = $wpdb->prepare("(location_state = '%s' OR location_state IS NULL )", $_REQUEST['state']);
            }
            $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : '';
            $results = $wpdb->get_col("SELECT DISTINCT location_town FROM " . EM_LOCATIONS_TABLE . " WHERE location_town IS NOT NULL AND location_town != '' {$cond}  ORDER BY location_town");
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                echo get_option('dbem_search_form_towns_label');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_towns', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        }
        if ($_REQUEST['action'] == 'search_regions') {
            if (!empty($_REQUEST['country'])) {
                $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']);
            }
            $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : '';
            $results = $wpdb->get_results("SELECT DISTINCT location_region AS value FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' {$cond}  ORDER BY location_region");
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                echo get_option('dbem_search_form_regions_label');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result->value}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_regions', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        } elseif ($_REQUEST['action'] == 'search_events' && get_option('dbem_events_page_search') && defined('DOING_AJAX')) {
            $args = EM_Events::get_post_search();
            $args['owner'] = false;
            ob_start();
            em_locate_template('templates/events-list.php', true, array('args' => $args));
            //if successful, this template overrides the settings and defaults, including search
            echo apply_filters('em_ajax_search_events', ob_get_clean(), $args);
            exit;
        }
    }
    //EM Ajax requests require this flag.
    if (is_user_logged_in()) {
        //Admin operations
        //Specific Oject Ajax
        if (!empty($_REQUEST['em_obj'])) {
            switch ($_REQUEST['em_obj']) {
                case 'em_bookings_events_table':
                case 'em_bookings_pending_table':
                case 'em_bookings_confirmed_table':
                    //add some admin files just in case
                    include_once 'admin/bookings/em-confirmed.php';
                    include_once 'admin/bookings/em-events.php';
                    include_once 'admin/bookings/em-pending.php';
                    call_user_func($_REQUEST['em_obj']);
                    exit;
                    break;
            }
        }
    }
    //Export CSV - WIP
    if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_bookings_csv' && wp_verify_nonce($_REQUEST['_wpnonce'], 'export_bookings_csv')) {
        if (!empty($_REQUEST['event_id'])) {
            $EM_Event = em_get_event($_REQUEST['event_id']);
        }
        //sort out cols
        if (!empty($_REQUEST['cols']) && is_array($_REQUEST['cols'])) {
            $cols = array();
            foreach ($_REQUEST['cols'] as $col => $active) {
                if ($active) {
                    $cols[] = $col;
                }
            }
            $_REQUEST['cols'] = $cols;
        }
        $_REQUEST['limit'] = 0;
        //generate bookings export according to search request
        $show_tickets = !empty($_REQUEST['show_tickets']);
        $EM_Bookings_Table = new EM_Bookings_Table($show_tickets);
        header("Content-Type: application/octet-stream; charset=utf-8");
        $file_name = !empty($EM_Event->event_slug) ? $EM_Event->event_slug : get_bloginfo();
        header("Content-Disposition: Attachment; filename=" . sanitize_title($file_name) . "-bookings-export.csv");
        do_action('em_csv_header_output');
        if (!defined('EM_CSV_DISABLE_HEADERS') || !EM_CSV_DISABLE_HEADERS) {
            if (!empty($_REQUEST['event_id'])) {
                echo __('Event', 'dbem') . ' : ' . $EM_Event->event_name . "\n";
                if ($EM_Event->location_id > 0) {
                    echo __('Where', 'dbem') . ' - ' . $EM_Event->get_location()->location_name . "\n";
                }
                echo __('When', 'dbem') . ' : ' . $EM_Event->output('#_EVENTDATES - #_EVENTTIMES') . "\n";
            }
            echo sprintf(__('Exported booking on %s', 'dbem'), date_i18n('D d M Y h:i', current_time('timestamp'))) . "\n";
        }
        echo '"' . implode('","', $EM_Bookings_Table->get_headers(true)) . '"' . "\n";
        //Rows
        $EM_Bookings_Table->limit = 150;
        //if you're having server memory issues, try messing with this number
        $EM_Bookings = $EM_Bookings_Table->get_bookings();
        $handle = fopen("php://output", "w");
        while (!empty($EM_Bookings->bookings)) {
            foreach ($EM_Bookings->bookings as $EM_Booking) {
                //Display all values
                /* @var $EM_Booking EM_Booking */
                /* @var $EM_Ticket_Booking EM_Ticket_Booking */
                if ($show_tickets) {
                    foreach ($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking) {
                        $row = $EM_Bookings_Table->get_row_csv($EM_Ticket_Booking);
                        fputcsv($handle, $row);
                    }
                } else {
                    $row = $EM_Bookings_Table->get_row_csv($EM_Booking);
                    fputcsv($handle, $row);
                }
            }
            //reiterate loop
            $EM_Bookings_Table->offset += $EM_Bookings_Table->limit;
            $EM_Bookings = $EM_Bookings_Table->get_bookings();
        }
        fclose($handle);
        exit;
    }
}
예제 #27
0
 public static function untrash_post($post_id)
 {
     if (get_post_type($post_id) == 'event-recurring') {
         global $wpdb;
         //set a constant so we know this event doesn't need 'saving'
         if (!defined('UNTRASHING_' . $post_id)) {
             define('UNTRASHING_' . $post_id, true);
         }
         $EM_Event = em_get_event($post_id, 'post_id');
         $events_array = EM_Events::get(array('recurrence_id' => $EM_Event->event_id, 'scope' => 'all', 'status' => 'all'));
         foreach ($events_array as $event) {
             /* @var $event EM_Event */
             if ($EM_Event->event_id == $event->recurrence_id) {
                 wp_untrash_post($event->post_id);
             }
         }
     }
 }
예제 #28
0
/**
 * Overrides the original qtip_content function and provides Event Manager formatted event information
 * @param string $content
 * @return string
 */
function wpfc_em_qtip_content($content = '')
{
    if (!empty($_REQUEST['event_id']) && trim(get_option('dbem_emfc_qtips_format')) != '') {
        global $EM_Event;
        $EM_Event = em_get_event($_REQUEST['event_id']);
        if (!empty($EM_Event->event_id)) {
            $content = $EM_Event->output(get_option('dbem_emfc_qtips_format', '#_EXCERPT'));
        }
    }
    return $content;
}
예제 #29
0
/**
 * Makes sure we're in "THE Loop", which is determinied by a flag set when the_post() (start) is first called, and when have_posts() (end) returns false.
 * @param string $data
 * @return string
 */
function em_wp_the_title($data, $id = null)
{
    global $post, $wp_query, $EM_Location, $EM_Event;
    if (empty($post)) {
        return $data;
    }
    //fix for any other plugins calling the_content outside the loop
    //because we're only editing the main title of the page here, we make sure we're in the main query
    if (is_main_query()) {
        $events_page_id = get_option('dbem_events_page');
        $locations_page_id = get_option('dbem_locations_page');
        $edit_events_page_id = get_option('dbem_edit_events_page');
        $edit_locations_page_id = get_option('dbem_edit_locations_page');
        $edit_bookings_page_id = get_option('dbem_edit_bookings_page');
        if (is_main_query() && !empty($post->ID) && in_array($post->ID, array($events_page_id, $locations_page_id, $edit_events_page_id, $edit_locations_page_id, $edit_bookings_page_id))) {
            if ($wp_query->in_the_loop) {
                return apply_filters('em_wp_the_title', em_content_page_title($data, $id));
            }
        } elseif (is_main_query() && is_single() && !empty($post->post_type)) {
            if ($post->post_type == EM_POST_TYPE_EVENT) {
                $EM_Event = em_get_event($post);
                return apply_filters('em_wp_the_title', $EM_Event->output($data));
            } elseif ($post->post_type == EM_POST_TYPE_LOCATION) {
                $EM_Location = em_get_location($post);
                return apply_filters('em_wp_the_title', $EM_Location->output($data));
            }
        }
    }
    return $data;
}
/**
 * This function will load an event into the global $EM_Event variable during page initialization, provided an event_id is given in the url via GET or POST.
 * global $EM_Recurrences also holds global array of recurrence objects when loaded in this instance for performance
 * All functions (admin and public) can now work off this object rather than it around via arguments.
 * @return null
 */
function em_load_event()
{
    global $EM_Event, $EM_Recurrences, $EM_Location, $EM_Person, $EM_Booking, $EM_Category, $EM_Ticket, $current_user;
    if (!defined('EM_LOADED')) {
        $EM_Recurrences = array();
        if (isset($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id']) && !is_object($EM_Event)) {
            $EM_Event = new EM_Event($_REQUEST['event_id']);
        } elseif (isset($_REQUEST['post']) && (get_post_type($_REQUEST['post']) == 'event' || get_post_type($_REQUEST['post']) == 'event-recurring')) {
            $EM_Event = em_get_event($_REQUEST['post'], 'post_id');
        } elseif (!empty($_REQUEST['event_slug']) && EM_MS_GLOBAL && is_main_site() && !get_site_option('dbem_ms_global_events_links')) {
            // single event page for a subsite event being shown on the main blog
            global $wpdb;
            $matches = array();
            if (preg_match('/\\-([0-9]+)$/', $_REQUEST['event_slug'], $matches)) {
                $event_id = $matches[1];
            } else {
                $event_id = $wpdb->get_var('SELECT event_id FROM ' . EM_EVENTS_TABLE . " WHERE event_slug='{$_REQUEST['event_slug']}' AND blog_id!=" . get_current_blog_id());
            }
            $EM_Event = em_get_event($event_id);
        }
        if (isset($_REQUEST['location_id']) && is_numeric($_REQUEST['location_id']) && !is_object($EM_Location)) {
            $EM_Location = new EM_Location($_REQUEST['location_id']);
        } elseif (isset($_REQUEST['post']) && get_post_type($_REQUEST['post']) == 'location') {
            $EM_Location = em_get_location($_REQUEST['post'], 'post_id');
        } elseif (!empty($_REQUEST['location_slug']) && EM_MS_GLOBAL && is_main_site() && !get_site_option('dbem_ms_global_locations_links')) {
            // single event page for a subsite event being shown on the main blog
            global $wpdb;
            $matches = array();
            if (preg_match('/\\-([0-9]+)$/', $_REQUEST['location_slug'], $matches)) {
                $location_id = $matches[1];
            } else {
                $location_id = $wpdb->get_var('SELECT location_id FROM ' . EM_LOCATIONS_TABLE . " WHERE location_slug='{$_REQUEST['location_slug']}' AND blog_id!=" . get_current_blog_id());
            }
            $EM_Location = em_get_location($location_id);
        }
        if (is_user_logged_in() || !empty($_REQUEST['person_id']) && is_numeric($_REQUEST['person_id'])) {
            //make the request id take priority, this shouldn't make it into unwanted objects if they use theobj::get_person().
            if (!empty($_REQUEST['person_id'])) {
                $EM_Person = new EM_Person($_REQUEST['person_id']);
            } else {
                $EM_Person = new EM_Person(get_current_user_id());
            }
        }
        if (isset($_REQUEST['booking_id']) && is_numeric($_REQUEST['booking_id']) && !is_object($_REQUEST['booking_id'])) {
            $EM_Booking = new EM_Booking($_REQUEST['booking_id']);
        }
        if (isset($_REQUEST['category_id']) && is_numeric($_REQUEST['category_id']) && !is_object($_REQUEST['category_id'])) {
            $EM_Category = new EM_Category($_REQUEST['category_id']);
        } elseif (isset($_REQUEST['category_slug']) && !is_object($EM_Category)) {
            $EM_Category = new EM_Category($_REQUEST['category_slug']);
        }
        if (isset($_REQUEST['ticket_id']) && is_numeric($_REQUEST['ticket_id']) && !is_object($_REQUEST['ticket_id'])) {
            $EM_Ticket = new EM_Ticket($_REQUEST['ticket_id']);
        }
        define('EM_LOADED', true);
    }
}