$args['page'] = !empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) ? $_REQUEST['pno'] : 1; if ($events_count > 0) { //If there's a search, let's change the pagination a little here if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'search_events') { $args['pagination'] = false; if (get_option('dbem_event_list_groupby')) { $args['mode'] = get_option('dbem_event_list_groupby'); $args['date_format'] = get_option('dbem_event_list_groupby_format'); echo em_events_list_grouped($args); } else { echo EM_Events::output($args); } //do some custom pagination (if needed/requested) if (!empty($args['limit']) && $events_count > $args['limit']) { //Show the pagination links (unless there's less than $limit events), note that we set em_search instead of search to prevent conflicts $search_args = array_merge(EM_Events::get_post_search(), array('pno' => '%PAGE%', 'action' => 'search_events', 'search' => null, 'em_search' => $args['search'])); $page_link_template = em_add_get_params($_SERVER['REQUEST_URI'], $search_args, false); //don't html encode, so em_paginate does its thing echo apply_filters('em_events_output_pagination', em_paginate($page_link_template, $events_count, $args['limit'], $args['pno']), $page_link_template, $events_count, $args['limit'], $args['pno']); } } else { if (get_option('dbem_event_list_groupby')) { $args['mode'] = get_option('dbem_event_list_groupby'); $args['date_format'] = get_option('dbem_event_list_groupby_format'); echo em_events_list_grouped($args); } else { echo EM_Events::output($args); } } } else { echo get_option('dbem_no_events_message');
/** * Filters for page content and if an event replaces it with the relevant event data. * @param $data * @return string */ function em_content($page_content) { global $post, $wpdb, $wp_query, $EM_Event, $EM_Location, $EM_Category; if (empty($post)) { return $page_content; } //fix for any other plugins calling the_content outside the loop $events_page_id = get_option('dbem_events_page'); $locations_page_id = get_option('dbem_locations_page'); $categories_page_id = get_option('dbem_categories_page'); $tags_page_id = get_option('dbem_tags_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'); $my_bookings_page_id = get_option('dbem_my_bookings_page'); //general defaults $args = array('owner' => false, 'pagination' => 1); $args['ajax'] = isset($args['ajax']) ? $args['ajax'] : !defined('EM_AJAX') || EM_AJAX; if (!post_password_required() && in_array($post->ID, array($events_page_id, $locations_page_id, $categories_page_id, $edit_bookings_page_id, $edit_events_page_id, $edit_locations_page_id, $my_bookings_page_id, $tags_page_id))) { $content = apply_filters('em_content_pre', '', $page_content); if (empty($content)) { ob_start(); if ($post->ID == $events_page_id && $events_page_id != 0) { if (!empty($_REQUEST['calendar_day'])) { //Events for a specific day $args = EM_Events::get_post_search(array_merge($args, $_REQUEST)); em_locate_template('templates/calendar-day.php', true, array('args' => $args)); } elseif (is_object($EM_Event)) { em_locate_template('templates/event-single.php', true, array('args' => $args)); } else { // Multiple events page $args['orderby'] = get_option('dbem_events_default_orderby'); $args['order'] = get_option('dbem_events_default_order'); if (get_option('dbem_display_calendar_in_events_page')) { $args['long_events'] = 1; em_locate_template('templates/events-calendar.php', true, array('args' => $args)); } else { //Intercept search request, if defined if (!empty($_REQUEST['action']) && ($_REQUEST['action'] == 'search_events' || $_REQUEST['action'] == 'search_events_grouped')) { $args = EM_Events::get_post_search(array_merge($args, $_REQUEST)); } if (empty($args['scope'])) { $args['scope'] = get_option('dbem_events_page_scope'); } if (get_option('dbem_events_page_search_form')) { //load the search form and pass on custom arguments (from settings page) $search_args = em_get_search_form_defaults(); em_locate_template('templates/events-search.php', true, array('args' => $search_args)); } $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit'); if (!empty($args['ajax'])) { echo '<div class="em-search-ajax">'; } //AJAX wrapper open if (get_option('dbem_event_list_groupby')) { em_locate_template('templates/events-list-grouped.php', true, array('args' => $args)); } else { em_locate_template('templates/events-list.php', true, array('args' => $args)); } if (!empty($args['ajax'])) { echo "</div>"; } //AJAX wrapper close } } } elseif ($post->ID == $locations_page_id && $locations_page_id != 0) { $args['orderby'] = get_option('dbem_locations_default_orderby'); $args['order'] = get_option('dbem_locations_default_order'); $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_locations_default_limit'); if (EM_MS_GLOBAL && is_object($EM_Location)) { em_locate_template('templates/location-single.php', true, array('args' => $args)); } else { //Intercept search request, if defined if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'search_locations') { $args = EM_Locations::get_post_search(array_merge($args, $_REQUEST)); } if (get_option('dbem_locations_page_search_form')) { //load the search form and pass on custom arguments (from settings page) $search_args = em_get_search_form_defaults(); //remove date and category $search_args['search_categories'] = $search_args['search_scope'] = false; em_locate_template('templates/locations-search.php', true, array('args' => $search_args)); } if (!empty($args['ajax'])) { echo '<div class="em-search-ajax">'; } //AJAX wrapper open em_locate_template('templates/locations-list.php', true, array('args' => $args)); if (!empty($args['ajax'])) { echo "</div>"; } //AJAX wrapper close } } elseif ($post->ID == $categories_page_id && $categories_page_id != 0) { $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_categories_default_limit'); if (!empty($args['ajax'])) { echo '<div class="em-search-ajax">'; } //AJAX wrapper open em_locate_template('templates/categories-list.php', true, array('args' => $args)); if (!empty($args['ajax'])) { echo "</div>"; } //AJAX wrapper close } elseif ($post->ID == $tags_page_id && $tags_page_id != 0) { $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_tags_default_limit'); if (!empty($args['ajax'])) { echo '<div class="em-search-ajax">'; } //AJAX wrapper open em_locate_template('templates/tags-list.php', true, array('args' => $args)); if (!empty($args['ajax'])) { echo "</div>"; } //AJAX wrapper close } elseif ($post->ID == $edit_events_page_id && $edit_events_page_id != 0) { em_events_admin(); } elseif ($post->ID == $edit_locations_page_id && $edit_locations_page_id != 0) { em_locations_admin(); } elseif ($post->ID == $my_bookings_page_id && $my_bookings_page_id != 0) { em_my_bookings(); } elseif ($post->ID == $edit_bookings_page_id && $edit_bookings_page_id != 0) { em_bookings_admin(); } $content = ob_get_clean(); //If disable rewrite flag is on, then we need to add a placeholder here if (get_option('dbem_disable_title_rewrites') == 1) { $content = str_replace('#_PAGETITLE', em_content_page_title(''), get_option('dbem_title_html')) . $content; } //Now, we either replace CONTENTS or just replace the whole page if (preg_match('/CONTENTS/', $page_content)) { $content = str_replace('CONTENTS', $content, $page_content); } if (get_option('dbem_credits')) { $content .= '<p style="color:#999; font-size:11px;">Powered by <a href="http://wp-events-plugin.com" style="color:#999;" target="_blank">Events Manager</a></p>'; } } return apply_filters('em_content', '<div id="em-wrapper">' . $content . '</div>'); } return $page_content; }
function get($args) { global $wpdb; $calendar_array = array(); $calendar_array['cells'] = array(); $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']; $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'); } if (!is_numeric($year)) { $year = date('Y'); } // 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 ($current_num > 35) { $num_weeks = 6; $outset = 42 - $current_num; } elseif ($current_num < 35) { $num_weeks = 5; $outset = 35 - $current_num; } if ($current_num == 35) { $num_weeks = 5; $outset = 0; } // 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&mo={$month_last}&yr={$year_last}&{$link_args}"; $next_url = "?ajaxCalendar=1&mo={$month_next}&yr={$year_next}&{$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); //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 if ($month == 1) { $month_pre = 12; $month_post = 2; $year_pre = $year - 1; $year_post = $year; } elseif ($month == 12) { $month_pre = 11; $month_post = 1; $year_pre = $year; $year_post = $year + 1; } else { $month_pre = $month - 1; $month_post = $month + 1; $year_pre = $year; $year_post = $year; } $args['year'] = array($year_pre, $year_post); $args['month'] = array($month_pre, $month_post); $events = EM_Events::get($args); $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(); 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_date = strtotime($event->start_date); $event_end_date = mktime(0, 0, 0, $month_post, date('t', $event_start_date), $year_post); if ($event_end_date == '') { $event_end_date = $event_start_date; } while ($event_start_date <= $event->end) { //Ensure date is within event dates, if so add to eventful days array $event_eventful_date = date('Y-m-d', $event_start_date); if (array_key_exists($event_eventful_date, $eventful_days) && is_array($eventful_days[$event_eventful_date])) { $eventful_days[$event_eventful_date][] = $event; } else { $eventful_days[$event_eventful_date] = array($event); } $event_start_date += 86400; //add a day } } else { //Only show events on the day that they start if (isset($eventful_days[$event->event_start_date]) && is_array($eventful_days[$event->event_start_date])) { $eventful_days[$event->event_start_date][] = $event; } else { $eventful_days[$event->event_start_date] = array($event); } } } } //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 (!get_option('dbem_display_calendar_events_limit') || count($events_titles) < get_option('dbem_display_calendar_events_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 (count($events) > 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, "?") ? "&" : "?"; $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'] .= '&' . $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'] = $events; } } return apply_filters('em_calendar_get', $calendar_array, $args); }
/** * 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()) { $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_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')) { if (get_site_option('dbem_ms_mainblog_locations')) { EM_Object::ms_global_switch(); } //switch to main blog if locations are global //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; } if (get_site_option('dbem_ms_mainblog_locations')) { EM_Object::ms_global_switch_back(); } } 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() : ''; $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, ', ', location_address, ', ', location_town) 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']) ? new EM_Booking($_REQUEST['booking_id']) : new EM_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(); 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())) { $post_validation = $EM_Booking->get_post(); do_action('em_booking_add', $EM_Event, $EM_Booking, $post_validation); if ($post_validation) { //Does this user need to be registered first? $registration = true; //TODO do some ticket validation before registering the user if ($EM_Event->get_bookings()->get_available_spaces() >= $EM_Booking->get_spaces(true)) { if ((!is_user_logged_in() || defined('EM_FORCE_REGISTRATION')) && get_option('dbem_bookings_anonymous') && !get_option('dbem_bookings_registration_disable')) { //find random username - less options for user, less things go wrong $username_root = explode('@', $_REQUEST['user_email']); $username_rand = $username_root[0] . rand(1, 1000); while (username_exists($username_root[0] . rand(1, 1000))) { $username_rand = $username_root[0] . rand(1, 1000); } $_REQUEST['dbem_phone'] = !empty($_REQUEST['dbem_phone']) ? $_REQUEST['dbem_phone'] : ''; //fix to prevent warnings $_REQUEST['user_name'] = !empty($_REQUEST['user_name']) ? $_REQUEST['user_name'] : ''; //fix to prevent warnings $user_data = array('user_login' => $username_rand, 'user_email' => $_REQUEST['user_email'], 'user_name' => $_REQUEST['user_name'], 'dbem_phone' => $_REQUEST['dbem_phone']); $id = em_register_new_user($user_data); if (is_numeric($id)) { $EM_Person = new EM_Person($id); $EM_Booking->person_id = $id; $feedback = get_option('dbem_booking_feedback_new_user'); $EM_Notices->add_confirm($feedback); } else { $registration = false; if (is_object($id) && get_class($id) == 'WP_Error') { /* @var $id WP_Error */ if ($id->get_error_code() == 'email_exists') { $EM_Notices->add_error(get_option('dbem_booking_feedback_email_exists')); } else { $EM_Notices->add_error($id->get_error_messages()); } } else { $EM_Notices->add_error(get_option('dbem_booking_feedback_reg_error')); } } } elseif ((!is_user_logged_in() || defined('EM_FORCE_REGISTRATION')) && get_option('dbem_bookings_registration_disable')) { //Validate name, phone and email $user_data = array(); if (empty($EM_Booking->booking_meta['registration'])) { $EM_Booking->booking_meta['registration'] = array(); } // Check the e-mail address if ($_REQUEST['user_email'] == '') { $registration = false; $EM_Notices->add_error(__('<strong>ERROR</strong>: Please type your e-mail address.', 'dbem')); } elseif (!is_email($_REQUEST['user_email'])) { $registration = false; $EM_Notices->add_error(__('<strong>ERROR</strong>: The email address isn’t correct.', 'dbem')); } elseif (email_exists($_REQUEST['user_email'])) { $registration = false; $EM_Notices->add_error(get_option('dbem_booking_feedback_email_exists')); } else { $user_data['user_email'] = $_REQUEST['user_email']; } //Check the user name if (!empty($_REQUEST['user_name'])) { $name_string = explode(' ', wp_kses($_REQUEST['user_name'], array())); $user_data['first_name'] = array_shift($name_string); $user_data['last_name'] = implode(' ', $name_string); } //Check the first/last name if (!empty($_REQUEST['first_name'])) { $user_data['first_name'] = wp_kses($_REQUEST['first_name'], array()); } if (!empty($_REQUEST['last_name'])) { $user_data['last_name'] = wp_kses($_REQUEST['last_name'], array()); } //Check the phone if (!empty($_REQUEST['dbem_phone'])) { $user_data['dbem_phone'] = wp_kses($_REQUEST['dbem_phone'], array()); } //Add booking meta $EM_Booking->booking_meta['registration'] = array_merge($EM_Booking->booking_meta['registration'], $user_data); //in case someone else added stuff //Save default person to booking $EM_Booking->person_id = get_option('dbem_bookings_registration_user'); } elseif (!is_user_logged_in()) { $registration = false; $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in')); } elseif (empty($EM_Booking->person_id)) { //user must be logged in, so we make this person the current user id $EM_Booking->person_id = get_current_user_id(); } } $EM_Bookings = $EM_Event->get_bookings(); if ($registration && $EM_Bookings->add($EM_Booking)) { $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; } } 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 = new EM_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 = new EM_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->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)) { 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; } } } 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')) { //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"); header("Content-Disposition: Attachment; filename=" . sanitize_title(get_bloginfo()) . "-bookings-export.csv"); 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)) { foreach ($EM_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; } }
/** * Handles AJAX Searching and Pagination for events, locations, tags and categories */ function em_ajax_search_and_pagination() { $args = array('owner' => false, 'pagination' => 1, 'ajax' => true); if (empty($args['scope'])) { $args['scope'] = get_option('dbem_events_page_scope'); } echo '<div class="em-search-ajax">'; ob_start(); if ($_REQUEST['action'] == 'search_events') { $args = EM_Events::get_post_search($args); $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit'); em_locate_template('templates/events-list.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search } elseif ($_REQUEST['action'] == 'search_events_grouped' && defined('DOING_AJAX')) { $args = EM_Events::get_post_search($args); $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit'); em_locate_template('templates/events-list-grouped.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search } elseif ($_REQUEST['action'] == 'search_locations' && defined('DOING_AJAX')) { $args = EM_Locations::get_post_search($args); $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_locations_default_limit'); em_locate_template('templates/locations-list.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search } elseif ($_REQUEST['action'] == 'search_tags' && defined('DOING_AJAX')) { $args = EM_Tags::get_post_search($args); $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_tags_default_limit'); em_locate_template('templates/tags-list.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search } elseif ($_REQUEST['action'] == 'search_cats' && defined('DOING_AJAX')) { $args = EM_Categories::get_post_search($args); $args['limit'] = !empty($args['limit']) ? $args['limit'] : get_option('dbem_categories_default_limit'); em_locate_template('templates/categories-list.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search } echo '</div>'; echo apply_filters('em_ajax_' . $_REQUEST['action'], ob_get_clean(), $args); exit; }
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&mo={$month_last}&yr={$year_last}&{$link_args}"; $next_url = "?ajaxCalendar=1&mo={$month_next}&yr={$year_next}&{$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, "?") ? "&" : "?"; $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'] .= '&' . $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); }
* * $args - the args passed onto EM_Events::output() * */ $events = EM_Events::get(apply_filters('em_content_events_args', $args)); $args['limit'] = get_option('dbem_events_default_limit'); //since we are passing this info to an output function or template, we should get all the events first $args['page'] = !empty($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 1; $events_count = count($events); if (get_option('dbem_events_page_search')) { em_locate_template('templates/events-search.php', true); } if ($events_count > 0) { //If there's a search, let's change the pagination a little here if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_events')) { $args['pagination'] = false; echo EM_Events::output($events, $args); //do some custom pagination (if needed/requested) if (!empty($args['limit']) && $events_count > $args['limit']) { //Show the pagination links (unless there's less than $limit events) $search_args = EM_Events::get_post_search() + array('page' => '%PAGE%', '_wpnonce' => $_REQUEST['_wpnonce']); $page_link_template = preg_replace('/(&|\\?)page=\\d+/i', '', $_SERVER['REQUEST_URI']); $page_link_template = em_add_get_params($page_link_template, $search_args); echo apply_filters('em_events_output_pagination', em_paginate($page_link_template, $events_count, $args['limit'], $args['page']), $page_link_template, $events_count, $args['limit'], $args['page']); } } else { echo EM_Events::output($events, $args); } } else { echo get_option('dbem_no_events_message'); }
/** * 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; //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_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); 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(); } if ($_REQUEST['action'] == 'event_save' && current_user_can('edit_events')) { //Check Nonces if (is_admin()) { if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) { check_admin_referer('trigger_error'); } } else { if (!wp_verify_nonce($_REQUEST['_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) $EM_Notices->add_confirm($EM_Event->feedback_message); if (is_admin()) { $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : ''; $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : ''; //wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager&pno='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message)); } else { $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); } $events_result = true; } else { $EM_Notices->add_error($EM_Event->get_errors()); $events_result = false; } } if ($_REQUEST['action'] == 'event_duplicate') { global $EZSQL_ERROR; $EM_Event = $EM_Event->duplicate(); if ($EM_Event === false) { $EM_Notices->add_error($EM_Event->errors, true); } else { if ($EM_Event->id == $_REQUEST['event_id']) { $EM_Notices->add_confirm($EM_Event->feedback_message . " " . sprintf(__('You are now viewing the duplicated %s.', 'dbem'), __('event', 'dbem')), true); } else { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } } } if ($_REQUEST['action'] == 'event_delete') { //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 = is_object($EM_Event) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural); $EM_Notices->add_confirm($message); } else { $message = is_object($EM_Event) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural); $EM_Notices->add_confirm($message); } } elseif ($_REQUEST['action'] == 'event_approve') { //Approve Action $events_result = $EM_Event->approve(); if ($events_result) { $EM_Notices->add_confirm($EM_Event->feedback_message); } else { $EM_Notices->add_error($EM_Event->errors); } } //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); $result = true; } 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; } } } 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; } } //Category Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'category') { global $EM_Category, $EM_Notices; //Load the category object, with saved event if requested if (!empty($_REQUEST['category_id'])) { $EM_Category = new EM_Category($_REQUEST['category_id']); } else { $EM_Category = new EM_Category(); } if ($_REQUEST['action'] == 'category_save' && current_user_can('edit_categories')) { //Check Nonces em_verify_nonce('category_save'); //Grab and validate submitted data if ($EM_Category->get_post() && $EM_Category->save()) { //EM_Category gets the category if submitted via POST and validates it (safer than to depend on JS) $EM_Notices->add_confirm($EM_Category->feedback_message); $result = true; } else { $EM_Notices->add_error($EM_Category->get_errors()); $result = false; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "category_delete") { //delete category //get object or objects if (!empty($_REQUEST['categories']) || !empty($_REQUEST['category_id'])) { $args = !empty($_REQUEST['categories']) ? $_REQUEST['categories'] : $_REQUEST['category_id']; $categories = EM_Categories::get($args); foreach ($categories as $category) { if (!$category->delete()) { $EM_Notices->add_error($category->get_errors()); $errors = true; } } if (empty($errors)) { $result = true; $category_term = count($categories) > 1 ? __('EM_Categories', 'dbem') : __('Category', 'dbem'); $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $category_term)); } else { $result = false; } } } if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => true, 'message' => $EM_Category->feedback_message); echo EM_Object::json_encode($return); die; } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => false, 'message' => $EM_Category->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 event object, with saved event if requested $EM_Event = !empty($_REQUEST['event_id']) ? new EM_Event($_REQUEST['event_id']) : new EM_Event(); //Load the booking object, with saved booking if requested $EM_Booking = !empty($_REQUEST['booking_id']) ? new EM_Booking($_REQUEST['booking_id']) : new EM_Booking(); $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete'); $result = false; if ($_REQUEST['action'] == 'booking_add') { //ADD/EDIT Booking em_verify_nonce('booking_add'); do_action('em_booking_add', $EM_Event, $EM_Booking); if ($EM_Booking->get_post()) { //Does this user need to be registered first? $registration = true; //TODO do some ticket validation before registering the user if ($_REQUEST['register_user'] && get_option('dbem_bookings_anonymous')) { //find random username - less options for user, less things go wrong $username_root = explode('@', $_REQUEST['user_email']); $username_rand = $username_root[0] . rand(1, 1000); while (username_exists($username_root[0] . rand(1, 1000))) { $username_rand = $username_root[0] . rand(1, 1000); } $id = em_register_new_user($username_rand, $_REQUEST['user_email'], $_REQUEST['user_name'], $_REQUEST['user_phone']); if (is_numeric($id)) { $EM_Person = new EM_Person($id); $EM_Booking->person_id = $id; $EM_Notices->add_confirm(__('A new user account has been created for you. Please check your email for access details.', 'dbem')); } else { $registration = false; if (is_object($id) && get_class($id) == 'WP_Error') { /* @var $id WP_Error */ if ($id->get_error_code() == 'email_exists') { $EM_Notices->add_error(__('This email already exists in our system, please log in to register to proceed with your booking.', 'dbem')); } else { $EM_Notices->add_error($id->get_error_messages()); } } else { $EM_Notices->add_error(__('There was a problem creating a user account, please contact a website administrator.', 'dbem')); } } } if ($EM_Event->get_bookings()->add($EM_Booking) && $registration) { $result = true; $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message); } else { ob_start(); echo "<pre>"; print_r($id); echo "</pre>"; $EM_Booking->feedback_message = ob_get_clean(); $EM_Notices->add_error($EM_Event->get_bookings()->get_errors()); } } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); } } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) { //ADD/EDIT Booking em_verify_nonce('booking_add_one'); $EM_Booking = new EM_Booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->id)); //new booking //get first ticket in this event and book one place there. $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first(); $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->id, 'ticket_booking_spaces' => 1)); $EM_Booking->get_tickets_bookings(); $EM_Booking->tickets_bookings->tickets_bookings[] = $EM_Ticket_Booking; //Now save booking if ($EM_Event->get_bookings()->add($EM_Booking)) { $EM_Booking = $booking; $result = true; $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message); } else { $EM_Notices->add_error($EM_Event->get_bookings()->get_errors()); } } 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()) { if ($EM_Booking->cancel()) { $result = true; if (!defined('DOING_AJAX')) { if ($EM_Booking->person->ID == get_current_user_id()) { $EM_Notices->add_confirm(sprintf(__('Booking %s', 'dbem'), __('Cancelled', 'dbem')), true); } else { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); } wp_redirect($_SERVER['HTTP_REFERER']); exit; } } else { $EM_Notices->add_error($EM_Booking->get_errors()); } } else { $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem')); } } 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 = new EM_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 (isset($result) && !empty($_REQUEST['em_ajax'])) { if ($result) { echo $feedback; } else { echo '<span style="color:red">' . $feedback . '</span>'; } die; } } if ($result && defined('DOING_AJAX')) { $return = array('result' => true, 'message' => $EM_Booking->feedback_message); echo EM_Object::json_encode($return); die; } elseif (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); die; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) { $EM_Notices->add_error(__('You must log in before you make a booking.', 'dbem')); if (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); } die; } //AJAX call for searches if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') { if ($_REQUEST['action'] == 'search_states' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_states')) { if (!empty($_REQUEST['country'])) { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_country=%s", $_REQUEST['country'])); } elseif (!empty($_REQUEST['region'])) { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_region=%s", $_REQUEST['region'])); } else { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE, $_REQUEST['country'] . "WHERE location_state IS NOT NULL AND location_state != ''")); } if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php _e('All States', 'dbem'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result->value}</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_regions' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_regions')) { if (!empty($_REQUEST['country'])) { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' AND location_country=%s", $_REQUEST['country'])); } else { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != ''", $_REQUEST['country'])); } if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php _e('All Regions', 'dbem'); ?> </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' && wp_verify_nonce($_POST['_wpnonce'], 'search_events') && get_option('dbem_events_page_search')) { $args = EM_Events::get_post_search(); 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_admin() && 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': call_user_func($_REQUEST['em_obj']); break; } die; } } }
/** * Filters for page content and if an event replaces it with the relevant event data. * @param $data * @return string */ function em_content($page_content) { global $post, $wpdb, $wp_query, $EM_Event, $EM_Location, $EM_Category; if (empty($post)) { return $page_content; } //fix for any other plugins calling the_content outside the loop $events_page_id = get_option('dbem_events_page'); $locations_page_id = get_option('dbem_locations_page'); $categories_page_id = get_option('dbem_categories_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'); $my_bookings_page_id = get_option('dbem_my_bookings_page'); //general defaults $args = array('owner' => false, 'pagination' => 1); if (in_array($post->ID, array($events_page_id, $locations_page_id, $categories_page_id, $edit_bookings_page_id, $edit_events_page_id, $edit_locations_page_id, $my_bookings_page_id))) { $content = apply_filters('em_content_pre', '', $page_content); if (empty($content)) { ob_start(); if ($post->ID == $events_page_id && $events_page_id != 0) { if (!empty($_REQUEST['calendar_day'])) { //Events for a specific day $args = EM_Events::get_post_search(array_merge($args, $_REQUEST)); em_locate_template('templates/calendar-day.php', true, array('args' => $args)); } elseif ($wp_query->get('bookings_page') && empty($my_bookings_page_id)) { //Bookings Page em_locate_template('templates/my-bookings.php', true); } elseif (is_object($EM_Event)) { em_locate_template('templates/event-single.php', true, array('args' => $args)); } else { // Multiple events page $args['orderby'] = get_option('dbem_events_default_orderby'); $args['order'] = get_option('dbem_events_default_order'); if (get_option('dbem_display_calendar_in_events_page')) { $args['long_events'] = 1; em_locate_template('templates/events-calendar.php', true, array('args' => $args)); } else { //Intercept search request, if defined $args['scope'] = get_option('dbem_events_page_scope'); if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'search_events') { $args = EM_Events::get_post_search(array_merge($args, $_REQUEST)); } em_locate_template('templates/events-list.php', true, array('args' => $args)); } } } elseif ($post->ID == $locations_page_id && $locations_page_id != 0) { $args['orderby'] = get_option('dbem_locations_default_orderby'); $args['order'] = get_option('dbem_locations_default_order'); if (EM_MS_GLOBAL && is_object($EM_Location)) { em_locate_template('templates/location-single.php', true, array('args' => $args)); } else { em_locate_template('templates/locations-list.php', true, array('args' => $args)); } } elseif ($post->ID == $categories_page_id && $categories_page_id != 0) { $args['orderby'] = get_option('dbem_categories_default_orderby'); $args['order'] = get_option('dbem_categories_default_order'); em_locate_template('templates/categories-list.php', true, array('args' => $args)); } elseif ($post->ID == $edit_events_page_id && $edit_events_page_id != 0) { em_events_admin(); } elseif ($post->ID == $edit_locations_page_id && $edit_locations_page_id != 0) { em_locations_admin(); } elseif ($post->ID == $edit_bookings_page_id && $edit_bookings_page_id != 0) { em_bookings_admin(); } elseif ($post->ID == $my_bookings_page_id && $my_bookings_page_id != 0) { em_my_bookings(); } $content = ob_get_clean(); //If disable rewrite flag is on, then we need to add a placeholder here if (get_option('dbem_disable_title_rewrites') == 1) { $content = str_replace('#_PAGETITLE', em_content_page_title(''), get_option('dbem_title_html')) . $content; } //Now, we either replace CONTENTS or just replace the whole page if (preg_match('/CONTENTS/', $page_content)) { $content = str_replace('CONTENTS', $content, $page_content); } if (get_option('dbem_credits')) { $content .= '<p style="color:#999; font-size:11px;">Powered by <a href="http://wp-events-plugin.com" style="color:#999;" target="_blank">Events Manager</a></p>'; } } return apply_filters('em_content', '<div id="em-wrapper">' . $content . '</div>'); } return $page_content; }
/** * Filters for page content and if an event replaces it with the relevant event data. * @param $data * @return string */ function em_content($page_content) { $events_page_id = get_option('dbem_events_page'); if (get_the_ID() == $events_page_id && $events_page_id != 0) { /* echo "<h2>WP_REWRITE</h2>"; echo "<pre>"; global $wp_rewrite; print_r($wp_rewrite); echo "</pre>"; echo "<h2>WP_QUERY</h2>"; echo "<pre>"; global $wp_query; print_r($wp_query->query_vars); echo "</pre>"; die(); */ global $wpdb, $wp_query, $EM_Event, $EM_Location, $EM_Category; //general defaults $args = array('owner' => false, 'pagination' => 1); $content = apply_filters('em_content_pre', '', $page_content); if (empty($content)) { ob_start(); if (!empty($_REQUEST['calendar_day'])) { //Events for a specific day em_locate_template('templates/calendar-day.php', true, array('args' => $args)); } elseif (is_object($EM_Location)) { //Just a single location em_locate_template('templates/location-single.php', true); } elseif (is_object($EM_Category)) { //Just a single category em_locate_template('templates/category-single.php', true); } elseif ($wp_query->get('bookings_page')) { //Bookings Page em_locate_template('templates/my-bookings.php', true); } elseif (is_object($EM_Event)) { // single event page em_locate_template('templates/event-single.php', true, array('args' => $args)); } elseif (!empty($_REQUEST['event_locations'])) { $args['orderby'] = get_option('dbem_locations_default_orderby'); $args['order'] = get_option('dbem_locations_default_order'); em_locate_template('templates/locations-list.php', true, array('args' => $args)); } elseif (!empty($_REQUEST['event_categories'])) { $args['orderby'] = get_option('dbem_categories_default_orderby'); $args['order'] = get_option('dbem_categories_default_order'); em_locate_template('templates/categories-list.php', true, array('args' => $args)); } else { // Multiple events page $args['orderby'] = get_option('dbem_events_default_orderby'); $args['order'] = get_option('dbem_events_default_order'); if (get_option('dbem_display_calendar_in_events_page')) { $args['long_events'] = 1; em_locate_template('templates/events-calendar.php', true, array('args' => $args)); } else { //Intercept search request, if defined $args['scope'] = get_option('dbem_events_page_scope'); if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_events') && get_option('dbem_events_page_search')) { $args = EM_Events::get_post_search($args); } em_locate_template('templates/events-list.php', true, array('args' => $args)); } } $content = ob_get_clean(); } //If disable rewrite flag is on, then we need to add a placeholder here if (get_option('dbem_disable_title_rewrites') == 1) { $content = str_replace('#_PAGETITLE', em_content_page_title(''), get_option('dbem_title_html')) . $content; } //Now, we either replace CONTENTS or just replace the whole page if (preg_match('/CONTENTS/', $page_content)) { $content = str_replace('CONTENTS', $content, $page_content); } if (get_option('dbem_credits')) { $content .= '<p style="color:#999; font-size:11px;">Powered by <a href="http://wp-events-plugin.com" style="color:#999;" target="_blank">Events Manager</a></p>'; } //TODO FILTER - filter em page content before display return apply_filters('em_content', '<div id="em-wrapper">' . $content . '</div>'); } return $page_content; }
/** * Hooks into icl_ls_languages and fixes links for when viewing an events list page specific to a calendar day. * @param array $langs * @return array */ public static function icl_ls_languages($langs) { global $wp_rewrite; //modify the URL if we're dealing with calendar day URLs if (!empty($_REQUEST['calendar_day']) && preg_match('/\\d{4}-\\d{2}-\\d{2}/', $_REQUEST['calendar_day'])) { $query_args = EM_Calendar::get_query_args(array_intersect_key(EM_Calendar::get_default_search($_GET), EM_Events::get_post_search($_GET, true))); if ($wp_rewrite->using_permalinks()) { //if using rewrites, add as a slug foreach ($langs as $lang => $lang_array) { $lang_url_parts = explode('?', $lang_array['url']); $lang_url_parts[0] = trailingslashit($lang_url_parts[0]) . $_REQUEST['calendar_day'] . '/'; $langs[$lang]['url'] = esc_url_raw(add_query_arg($query_args, implode('?', $lang_url_parts))); } } else { $query_args['calendar_day'] = $_REQUEST['calendar_day']; foreach ($langs as $lang => $lang_array) { $langs[$lang]['url'] = esc_url_raw(add_query_arg($query_args, $lang_array['url'])); } } } return $langs; }