Example #1
0
function mc_location_select($location = false)
{
    global $wpdb;
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    // Grab all locations and list them
    $list = '';
    $sql = "SELECT * FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC";
    $locs = $mcdb->get_results($sql);
    foreach ($locs as $loc) {
        $l = '<option value="' . $loc->location_id . '"';
        if ($location) {
            if ($location == $loc->location_id) {
                $l .= ' selected="selected"';
            }
        }
        $l .= '>' . stripslashes($loc->location_label) . '</option>';
        $list .= $l;
    }
    return $list;
}
function mc_location_data($field, $id)
{
    if ($id) {
        global $wpdb;
        $mcdb = $wpdb;
        if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
            $mcdb = mc_remote_db();
        }
        $field = esc_sql($field);
        $sql = $wpdb->prepare("SELECT {$field} FROM " . my_calendar_locations_table() . " WHERE location_id = %d", $id);
        $result = $mcdb->get_var($sql);
        return $result;
    }
}
function mc_check_group_data($action, $post)
{
    $post = apply_filters('mc_groups_pre_checkdata', $post, $action);
    global $wpdb, $current_user, $users_entries;
    $mcdb = $wpdb;
    $url_ok = 0;
    $title_ok = 0;
    $submit = array();
    if (get_magic_quotes_gpc()) {
        $post = array_map('stripslashes_deep', $post);
    }
    if (!wp_verify_nonce($post['event_nonce_name'], 'event_nonce')) {
        return;
    }
    $errors = "";
    if ($action == 'add' || $action == 'edit' || $action == 'copy') {
        $title = !empty($post['event_title']) ? trim($post['event_title']) : '';
        $desc = !empty($post['content']) ? trim($post['content']) : '';
        $short = !empty($post['event_short']) ? trim($post['event_short']) : '';
        $repeats = empty($post['event_repeats']) || trim($post['event_repeats']) == '' ? 0 : trim($post['event_repeats']);
        $host = !empty($post['event_host']) ? $post['event_host'] : $current_user->ID;
        $category = !empty($post['event_category']) ? $post['event_category'] : '';
        $event_link = !empty($post['event_link']) ? trim($post['event_link']) : '';
        $expires = !empty($post['event_link_expires']) ? $post['event_link_expires'] : '0';
        $location_preset = !empty($post['location_preset']) ? $post['location_preset'] : '';
        $event_open = !empty($post['event_open']) ? $post['event_open'] : '2';
        $event_tickets = !empty($post['event_tickets']) ? trim($post['event_tickets']) : '';
        $event_registration = !empty($post['event_registration']) ? trim($post['event_registration']) : '';
        $event_image = esc_url_raw($post['event_image']);
        $event_span = !empty($post['event_span']) ? 1 : 0;
        // set location
        if ($location_preset != 'none') {
            $sql = "SELECT * FROM " . my_calendar_locations_table() . " WHERE location_id = {$location_preset}";
            $location = $mcdb->get_row($sql);
            $event_label = $location->location_label;
            $event_street = $location->location_street;
            $event_street2 = $location->location_street2;
            $event_city = $location->location_city;
            $event_state = $location->location_state;
            $event_postcode = $location->location_postcode;
            $event_region = $location->location_region;
            $event_country = $location->location_country;
            $event_url = $location->location_url;
            $event_longitude = $location->location_longitude;
            $event_latitude = $location->location_latitude;
            $event_zoom = $location->location_zoom;
            $event_phone = $location->location_phone;
            $event_access = $location->location_access;
        } else {
            $event_label = !empty($post['event_label']) ? $post['event_label'] : '';
            $event_street = !empty($post['event_street']) ? $post['event_street'] : '';
            $event_street2 = !empty($post['event_street2']) ? $post['event_street2'] : '';
            $event_city = !empty($post['event_city']) ? $post['event_city'] : '';
            $event_state = !empty($post['event_state']) ? $post['event_state'] : '';
            $event_postcode = !empty($post['event_postcode']) ? $post['event_postcode'] : '';
            $event_region = !empty($post['event_region']) ? $post['event_region'] : '';
            $event_country = !empty($post['event_country']) ? $post['event_country'] : '';
            $event_url = !empty($post['event_url']) ? $post['event_url'] : '';
            $event_longitude = !empty($post['event_longitude']) ? $post['event_longitude'] : '';
            $event_latitude = !empty($post['event_latitude']) ? $post['event_latitude'] : '';
            $event_zoom = !empty($post['event_zoom']) ? $post['event_zoom'] : '';
            $event_phone = !empty($post['event_phone']) ? $post['event_phone'] : '';
            $event_access = !empty($post['event_access']) ? $post['event_access'] : array();
            $event_access = !empty($post['event_access_hidden']) ? unserialize($post['event_access_hidden']) : $event_access;
        }
        // We check to make sure the URL is acceptable (blank or starting with http://)
        if ($event_link == '') {
            $url_ok = 1;
        } else {
            if (preg_match('/^(http)(s?)(:)\\/\\//', $event_link)) {
                $url_ok = 1;
            } else {
                $event_link = "http://" . $event_link;
            }
        }
    }
    // The title must be at least one character in length and no more than 255 - only basic punctuation is allowed
    $title_length = strlen($title);
    if ($title_length > 1 && $title_length <= 255) {
        $title_ok = 1;
    } else {
        $errors .= "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('The event title must be between 1 and 255 characters in length.', 'my-calendar') . "</p></div>";
    }
    if ($url_ok == 1 && $title_ok == 1) {
        $proceed = true;
        $submit = array('event_title' => $title, 'event_desc' => $desc, 'event_short' => $short, 'event_link' => $event_link, 'event_label' => $event_label, 'event_street' => $event_street, 'event_street2' => $event_street2, 'event_city' => $event_city, 'event_state' => $event_state, 'event_postcode' => $event_postcode, 'event_region' => $event_region, 'event_country' => $event_country, 'event_url' => $event_url, 'event_image' => $event_image, 'event_phone' => $event_phone, 'event_access' => serialize($event_access), 'event_tickets' => $event_tickets, 'event_registration' => $event_registration, 'event_category' => $category, 'event_link_expires' => $expires, 'event_zoom' => $event_zoom, 'event_open' => $event_open, 'event_host' => $host, 'event_span' => $event_span, 'event_longitude' => $event_longitude, 'event_latitude' => $event_latitude);
        if ($action == 'edit') {
            unset($submit['event_author']);
        }
    } else {
        // The form is going to be rejected due to field validation issues, so we preserve the users entries here
        $users_entries->event_title = $title;
        $users_entries->event_desc = $desc;
        $users_entries->event_host = $host;
        $users_entries->event_category = $category;
        $users_entries->event_link = $event_link;
        $users_entries->event_link_expires = $expires;
        $users_entries->event_label = $event_label;
        $users_entries->event_street = $event_street;
        $users_entries->event_street2 = $event_street2;
        $users_entries->event_city = $event_city;
        $users_entries->event_state = $event_state;
        $users_entries->event_postcode = $event_postcode;
        $users_entries->event_country = $event_country;
        $users_entries->event_region = $event_region;
        $users_entries->event_url = $event_url;
        $users_entries->event_longitude = $event_longitude;
        $users_entries->event_latitude = $event_latitude;
        $users_entries->event_zoom = $event_zoom;
        $users_entries->event_phone = $event_phone;
        $users_entries->event_open = $event_open;
        $users_entries->event_short = $short;
        $users_entries->event_image = $event_image;
        $users_entries->event_span = $event_span;
        $users_entries->event_access = serialize($event_access);
        $users_entries->events_access = serialize($events_access);
        $users_entries->event_tickets = $event_tickets;
        $users_entries->event_registration = $event_registration;
        $proceed = false;
    }
    $data = array($proceed, $users_entries, $submit, $errors);
    return $data;
}
function mc_transition_db()
{
    // copy to post types. Don't do this if referencing remote sites.
    if (get_option('mc_remote') != 'true') {
        global $wpdb;
        $results = $wpdb->get_results('SELECT * FROM ' . my_calendar_locations_table(), ARRAY_A);
        $locations = array();
        foreach ($results as $result) {
            $location_id = $result['location_id'];
            unset($result['location_id']);
            $hash = md5(serialize($result));
            $locations[$location_id] = $result;
        }
        $results = $wpdb->get_results('SELECT * FROM ' . my_calendar_categories_table());
        foreach ($results as $category) {
            $term = wp_insert_term($category->category_name, 'mc-event-category');
            if (!is_wp_error($term)) {
                $term_id = $term['term_id'];
                mc_update_category('category_term', $term_id, $category->category_id);
            } else {
                if (isset($term->error_data['term_exists'])) {
                    $term_id = $term->error_data['term_exists'];
                    mc_update_category('category_term', $term_id, $category->category_id);
                }
            }
        }
        $results = $wpdb->get_results('SELECT * FROM ' . my_calendar_table(), ARRAY_A);
        foreach ($results as $event) {
            $post_id = mc_create_event_post($event, $event['event_id']);
            mc_update_event('event_post', $post_id, $event['event_id']);
            // false if not found, id if found.
            $location = mc_check_location_table($event, $locations);
            if ($location) {
                mc_update_event('event_location', $location, $event['event_id']);
            } else {
                if ($event['event_label'] == '' && $event['event_street'] == '' && $event['event_url'] == '' && $event['event_city'] == '' && $event['event_state'] == '' && $event['event_country'] == '') {
                    // don't insert the row if location does not have basic data.
                } else {
                    $add = array('location_label' => $event['event_label'], 'location_street' => $event['event_street'], 'location_street2' => $event['event_street2'], 'location_city' => $event['event_city'], 'location_state' => $event['event_state'], 'location_postcode' => $event['event_postcode'], 'location_region' => $event['event_region'], 'location_country' => $event['event_country'], 'location_url' => $event['event_url'], 'location_longitude' => $event['event_longitude'], 'location_latitude' => $event['event_latitude'], 'location_zoom' => $event['event_zoom'], 'location_phone' => $event['event_phone'], 'location_access' => '');
                    mc_insert_location($add);
                }
                // could add delete routine to allow user to select what location to use for events using a given location.
            }
        }
    }
}
function mc_check_data($action, $post, $i)
{
    $post = apply_filters('mc_pre_checkdata', $post, $action, $i);
    global $wpdb, $current_user, $users_entries;
    $mcdb = $wpdb;
    $submit = array();
    $errors = '';
    $every = $recur = $events_access = $begin = $end = $short = $time = $endtime = $event_label = $event_street = $event_street2 = $event_city = $event_state = $event_postcode = $event_region = $event_country = $event_url = $event_image = $event_phone = $event_phone2 = $event_access = $event_tickets = $event_registration = $event_author = $category = $expires = $event_zoom = $event_open = $event_group = $approved = $host = $event_fifth_week = $event_holiday = $event_group_id = $event_span = $event_hide_end = $event_longitude = $event_latitude = '';
    if (get_magic_quotes_gpc()) {
        $post = array_map('stripslashes_deep', $post);
    }
    if (!wp_verify_nonce($post['event_nonce_name'], 'event_nonce')) {
        return array();
    }
    if ($action == 'add' || $action == 'edit' || $action == 'copy') {
        $title = !empty($post['event_title']) ? trim($post['event_title']) : '';
        $desc = !empty($post['content']) ? trim($post['content']) : '';
        $short = !empty($post['event_short']) ? trim($post['event_short']) : '';
        $recur = !empty($post['event_recur']) ? trim($post['event_recur']) : '';
        $every = !empty($post['event_every']) ? (int) $post['event_every'] : 1;
        // if this is an all weekdays event, and it's been scheduled to start on a weekend, the math gets nasty.
        // ...AND there's no reason to allow it, since weekday events will NEVER happen on the weekend.
        $begin = trim($post['event_begin'][$i]);
        $end = !empty($post['event_end']) ? trim($post['event_end'][$i]) : $post['event_begin'][$i];
        if ($recur == 'E' && (date('w', strtotime($begin)) == 0 || date('w', strtotime($begin)) == 6)) {
            if (date('w', strtotime($begin)) == 0) {
                $newbegin = my_calendar_add_date($begin, 1);
                if (!empty($post['event_end'][$i])) {
                    $newend = my_calendar_add_date($end, 1);
                } else {
                    $newend = $newbegin;
                }
            } else {
                if (date('w', strtotime($begin)) == 6) {
                    $newbegin = my_calendar_add_date($begin, 2);
                    if (!empty($post['event_end'][$i])) {
                        $newend = my_calendar_add_date($end, 2);
                    } else {
                        $newend = $newbegin;
                    }
                }
            }
            $begin = $newbegin;
            $end = $newend;
        } else {
            $begin = !empty($post['event_begin'][$i]) ? trim($post['event_begin'][$i]) : '';
            $end = !empty($post['event_end'][$i]) ? trim($post['event_end'][$i]) : $begin;
        }
        $begin = date('Y-m-d', strtotime($begin));
        // regardless of entry format, convert.
        $time = !empty($post['event_time'][$i]) ? trim($post['event_time'][$i]) : '';
        if ($time != '') {
            $endtime = !empty($post['event_endtime'][$i]) ? trim($post['event_endtime'][$i]) : date('H:i:s', strtotime($time . ' +1 hour'));
        } else {
            $endtime = !empty($post['event_endtime'][$i]) ? trim($post['event_endtime'][$i]) : '';
        }
        $time = $time == '' || $time == '00:00:00' ? '00:00:00' : $time;
        // set at midnight if not provided
        $endtime = $endtime == '' && $time == '00:00:00' ? '23:59:59' : $endtime;
        // set at end of night if np
        // prevent setting enddate to incorrect value on copy.
        if (strtotime($end) < strtotime($begin) && $action == 'copy') {
            $end = date('Y-m-d', strtotime($begin) + (strtotime($post['prev_event_end']) - strtotime($post['prev_event_begin'])));
        }
        if (isset($post['event_allday']) && (int) $post['event_allday'] !== 0) {
            $time = '00:00:00';
            $endtime = '23:59:59';
        }
        // verify formats
        $time = date('H:i:s', strtotime($time));
        $endtime = date('H:i:s', strtotime($endtime));
        $end = date('Y-m-d', strtotime($end));
        // regardless of entry format, convert.
        $repeats = isset($post['event_repeats']) ? trim($post['event_repeats']) : 0;
        $host = !empty($post['event_host']) ? $post['event_host'] : $current_user->ID;
        $category = isset($post['event_category']) && is_numeric($post['event_category']) ? $post['event_category'] : 1;
        $event_author = isset($post['event_author']) && is_numeric($post['event_author']) ? $post['event_author'] : 0;
        $event_link = !empty($post['event_link']) ? trim($post['event_link']) : '';
        $expires = !empty($post['event_link_expires']) ? $post['event_link_expires'] : '0';
        $approved = !empty($post['event_approved']) ? $post['event_approved'] : '0';
        $location_preset = !empty($post['location_preset']) ? $post['location_preset'] : '';
        $event_open = isset($post['event_open']) && $post['event_open'] !== 0 ? $post['event_open'] : '2';
        $event_tickets = isset($post['event_tickets']) ? trim($post['event_tickets']) : '';
        $event_registration = isset($post['event_registration']) ? trim($post['event_registration']) : '';
        $event_group = !empty($post['event_group']) ? 1 : 0;
        $event_image = isset($post['event_image']) ? esc_url_raw($post['event_image']) : '';
        $event_fifth_week = !empty($post['event_fifth_week']) ? 1 : 0;
        $event_holiday = !empty($post['event_holiday']) ? 1 : 0;
        // get group id: if multiple events submitted, auto group OR if event being submitted is already part of a group; otherwise zero.
        $group_id_submitted = (int) $post['event_group_id'];
        $event_group_id = is_array($post['event_begin']) && count($post['event_begin']) > 1 || mc_event_is_grouped($group_id_submitted) ? $group_id_submitted : 0;
        $event_span = !empty($post['event_span']) && $event_group_id != 0 ? 1 : 0;
        $event_hide_end = !empty($post['event_hide_end']) ? (int) $post['event_hide_end'] : 0;
        $event_hide_end = $time == '' || $time == '23:59:59' ? 1 : $event_hide_end;
        // hide end time automatically on all day events
        // set location
        if ($location_preset != 'none' && is_numeric($location_preset)) {
            $sql = "SELECT * FROM " . my_calendar_locations_table() . " WHERE location_id = {$location_preset}";
            $location = $mcdb->get_row($sql);
            $event_label = $location->location_label;
            $event_street = $location->location_street;
            $event_street2 = $location->location_street2;
            $event_city = $location->location_city;
            $event_state = $location->location_state;
            $event_postcode = $location->location_postcode;
            $event_region = $location->location_region;
            $event_country = $location->location_country;
            $event_url = $location->location_url;
            $event_longitude = $location->location_longitude;
            $event_latitude = $location->location_latitude;
            $event_zoom = $location->location_zoom;
            $event_phone = $location->location_phone;
            $event_phone2 = $location->location_phone2;
            $event_access = $location->location_access;
        } else {
            $event_label = !empty($post['event_label']) ? $post['event_label'] : '';
            $event_street = !empty($post['event_street']) ? $post['event_street'] : '';
            $event_street2 = !empty($post['event_street2']) ? $post['event_street2'] : '';
            $event_city = !empty($post['event_city']) ? $post['event_city'] : '';
            $event_state = !empty($post['event_state']) ? $post['event_state'] : '';
            $event_postcode = !empty($post['event_postcode']) ? $post['event_postcode'] : '';
            $event_region = !empty($post['event_region']) ? $post['event_region'] : '';
            $event_country = !empty($post['event_country']) ? $post['event_country'] : '';
            $event_url = !empty($post['event_url']) ? $post['event_url'] : '';
            $event_longitude = !empty($post['event_longitude']) ? $post['event_longitude'] : '';
            $event_latitude = !empty($post['event_latitude']) ? $post['event_latitude'] : '';
            $event_zoom = !empty($post['event_zoom']) ? $post['event_zoom'] : '';
            $event_phone = !empty($post['event_phone']) ? $post['event_phone'] : '';
            $event_phone2 = !empty($post['event_phone2']) ? $post['event_phone2'] : '';
            $event_access = !empty($post['event_access']) ? $post['event_access'] : '';
            $event_access = !empty($post['event_access_hidden']) ? unserialize($post['event_access_hidden']) : $event_access;
            if (isset($post['mc_copy_location']) && $post['mc_copy_location'] == 'on' && $i == 0) {
                // only the first event, if adding multiples.
                $add_loc = array('location_label' => $event_label, 'location_street' => $event_street, 'location_street2' => $event_street2, 'location_city' => $event_city, 'location_state' => $event_state, 'location_postcode' => $event_postcode, 'location_region' => $event_region, 'location_country' => $event_country, 'location_url' => $event_url, 'location_longitude' => $event_longitude, 'location_latitude' => $event_latitude, 'location_zoom' => $event_zoom, 'location_phone' => $event_phone, 'location_phone2' => $event_phone2, 'location_access' => is_array($event_access) ? serialize($event_access) : '');
                $add_loc = array_map('mc_kses_post', $add_loc);
                $loc_formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', '%d', '%s', '%s', '%s');
                $mcdb->insert(my_calendar_locations_table(), $add_loc, $loc_formats);
            }
        }
        // Perform validation on the submitted dates - checks for valid years and months
        if (mc_checkdate($begin) && mc_checkdate($end)) {
            // Make sure dates are equal or end date is later than start date
            if (strtotime("{$end} {$endtime}") < strtotime("{$begin} {$time}")) {
                $errors .= "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('Your event end date must be either after or the same as your event begin date', 'my-calendar') . "</p></div>";
            }
        } else {
            $errors .= "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('Your date formatting is correct but one or more of your dates is invalid. Check for number of days in month and leap year related errors.', 'my-calendar') . "</p></div>";
        }
        // We check for a valid time, or an empty one
        $time = $time == '' ? '23:59:59' : date('H:i:00', strtotime($time));
        $time_format_one = '/^([0-1][0-9]):([0-5][0-9]):([0-5][0-9])$/';
        $time_format_two = '/^([2][0-3]):([0-5][0-9]):([0-5][0-9])$/';
        if (preg_match($time_format_one, $time) || preg_match($time_format_two, $time) || $time == '') {
        } else {
            $errors .= "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('The time field must either be blank or be entered in the format hh:mm am/pm', 'my-calendar') . "</p></div>";
        }
        // We check for a valid end time, or an empty one
        if (preg_match($time_format_one, $endtime) || preg_match($time_format_two, $endtime) || $endtime == '') {
        } else {
            $errors .= "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('The end time field must either be blank or be entered in the format hh:mm am/pm', 'my-calendar') . "</p></div>";
        }
        // We check to make sure the URL is acceptable (blank or starting with http://)
        if (!($event_link == '' || preg_match('/^(http)(s?)(:)\\/\\//', $event_link))) {
            $event_link = "http://" . $event_link;
        }
    }
    // A title is required, and can't be more than 255 characters.
    $title_length = strlen($title);
    if (!($title_length >= 1 && $title_length <= 255)) {
        $title = __('Untitled Event', 'my-calendar');
    }
    // Run checks on recurrence profile
    if ($repeats == 0 && $recur == 'S' || $repeats >= 0 && ($recur == 'W' || $recur == 'B' || $recur == 'M' || $recur == 'U' || $recur == 'Y' || $recur == 'D' || $recur == 'E')) {
        $recur = $recur . $every;
    } else {
        // if it's not valid, assign a default value.
        $repeats = 0;
        $recur = 'S1';
    }
    if (function_exists('mcs_submissions') && isset($post['mcs_check_conflicts'])) {
        $conflicts = mcs_check_conflicts($begin, $time, $end, $endtime, $event_label);
        if ($conflicts) {
            $errors .= "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('That event conflicts with a previously scheduled event.', 'my-calendar') . "</p></div>";
        }
    }
    $spam = mc_spam($event_link, $desc, $post);
    // the likelihood that something will be both flagged as spam and have a zero start time
    // and yet be legitimate is crazy minimal. Just kill it.
    if ($spam == 1 && $begin == '1970-01-01') {
        die;
    }
    if ($errors == '') {
        $current_user = wp_get_current_user();
        $event_author = $event_author == $current_user->ID || current_user_can('mc_manage_events') ? $event_author : $current_user->ID;
        $event_category = !$category ? 1 : $category;
        $ok = true;
        $submit = array('event_begin' => $begin, 'event_end' => $end, 'event_title' => $title, 'event_desc' => force_balance_tags($desc), 'event_short' => force_balance_tags($short), 'event_time' => $time, 'event_endtime' => $endtime, 'event_link' => $event_link, 'event_label' => $event_label, 'event_street' => $event_street, 'event_street2' => $event_street2, 'event_city' => $event_city, 'event_state' => $event_state, 'event_postcode' => $event_postcode, 'event_region' => $event_region, 'event_country' => $event_country, 'event_url' => $event_url, 'event_recur' => $recur, 'event_image' => $event_image, 'event_phone' => $event_phone, 'event_phone2' => $event_phone2, 'event_access' => is_array($event_access) ? serialize($event_access) : '', 'event_tickets' => $event_tickets, 'event_registration' => $event_registration, 'event_repeats' => $repeats, 'event_author' => $event_author, 'event_category' => $event_category, 'event_link_expires' => $expires, 'event_zoom' => $event_zoom, 'event_open' => $event_open, 'event_group' => $event_group, 'event_approved' => $approved, 'event_host' => $host, 'event_flagged' => $spam, 'event_fifth_week' => $event_fifth_week, 'event_holiday' => $event_holiday, 'event_group_id' => $event_group_id, 'event_span' => $event_span, 'event_hide_end' => $event_hide_end, 'event_longitude' => $event_longitude, 'event_latitude' => $event_latitude);
        $submit = array_map('mc_kses_post', $submit);
    } else {
        $ok = false;
        $event_access = is_array($event_access) ? serialize($event_access) : '';
        // The form is going to be rejected due to field validation issues, so we preserve the users entries here
        // all submitted data should be in this object, regardless of data destination.
        $users_entries = !is_object($users_entries) ? new stdClass() : $users_entries;
        $users_entries->event_id = isset($_GET['event_id']) && is_numeric($_GET['event_id']) ? $_GET['event_id'] : false;
        $users_entries->event_title = $title;
        $users_entries->event_desc = $desc;
        $users_entries->event_begin = $begin;
        $users_entries->event_end = $end;
        $users_entries->event_time = $time;
        $users_entries->event_endtime = $endtime;
        $users_entries->event_recur = $recur;
        $users_entries->event_repeats = $repeats;
        $users_entries->event_host = $host;
        $users_entries->event_category = $category;
        $users_entries->event_link = $event_link;
        $users_entries->event_link_expires = $expires;
        $users_entries->event_label = $event_label;
        $users_entries->event_street = $event_street;
        $users_entries->event_street2 = $event_street2;
        $users_entries->event_city = $event_city;
        $users_entries->event_state = $event_state;
        $users_entries->event_postcode = $event_postcode;
        $users_entries->event_country = $event_country;
        $users_entries->event_region = $event_region;
        $users_entries->event_url = $event_url;
        $users_entries->event_longitude = $event_longitude;
        $users_entries->event_latitude = $event_latitude;
        $users_entries->event_zoom = $event_zoom;
        $users_entries->event_phone = $event_phone;
        $users_entries->event_phone2 = $event_phone2;
        $users_entries->event_author = $event_author;
        $users_entries->event_open = $event_open;
        $users_entries->event_short = $short;
        $users_entries->event_group = $event_group;
        $users_entries->event_approved = $approved;
        $users_entries->event_image = $event_image;
        $users_entries->event_fifth_week = $event_fifth_week;
        $users_entries->event_holiday = $event_holiday;
        $users_entries->event_flagged = 0;
        $users_entries->event_group_id = $event_group_id;
        $users_entries->event_span = $event_span;
        $users_entries->event_hide_end = $event_hide_end;
        $users_entries->event_access = $event_access;
        $users_entries->events_access = serialize($events_access);
        $users_entries->event_tickets = $event_tickets;
        $users_entries->event_registration = $event_registration;
    }
    $data = array($ok, $users_entries, $submit, $errors);
    return $data;
}
function my_calendar_locations_list($show = 'list', $type = 'saved', $datatype = 'name', $group = 'single')
{
    global $wpdb;
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    $output = '';
    if (isset($_GET['mc_id'])) {
        return '';
    }
    if ($type == 'saved') {
        switch ($datatype) {
            case "name":
                $data = "location_label";
                break;
            case "city":
                $data = "location_city";
                break;
            case "state":
                $data = "location_state";
                break;
            case "zip":
                $data = "location_postcode";
                break;
            case "country":
                $data = "location_country";
                break;
            case "region":
                $data = "location_region";
                break;
            default:
                $data = "location_label";
        }
    } else {
        $data = $datatype;
    }
    $current_url = mc_get_current_url();
    if ($type == 'saved') {
        $locations = $mcdb->get_results("SELECT DISTINCT {$data} FROM " . my_calendar_locations_table() . " ORDER BY {$data} ASC", ARRAY_A);
    } else {
        $data = get_option('mc_user_settings');
        $locations = $data['my_calendar_location_default']['values'];
        $datatype = str_replace('event_', '', get_option('mc_location_type'));
        $datatype = $datatype == 'label' ? 'name' : $datatype;
        $datatype = $datatype == 'postcode' ? 'zip' : $datatype;
    }
    if (count($locations) > 1) {
        if ($show == 'list') {
            $url = mc_build_url(array('loc' => 'all', 'ltype' => 'all'), array());
            $output .= "<ul id='mc-locations-list'>\r\n\t\t\t<li class='mc-show-all'><a href='{$url}'>" . __('Show all', 'my-calendar') . "</a></li>\n";
        } else {
            $ltype = !isset($_GET['ltype']) ? $datatype : $_GET['ltype'];
            $output .= "<div id='mc_locations'>";
            $output .= $group == 'single' ? "\r\n\t\t<form action='" . $current_url . "' method='get'>\r\n\t\t<div>" : '';
            $output .= "<input type='hidden' name='ltype' value='" . esc_attr($ltype) . "' />";
            if ($group == 'single') {
                $qsa = array();
                if (isset($_SERVER['QUERY_STRING'])) {
                    parse_str($_SERVER['QUERY_STRING'], $qsa);
                }
                if (!isset($_GET['cid'])) {
                    $output .= '<input type="hidden" name="cid" value="all" />';
                }
                foreach ($qsa as $name => $argument) {
                    $name = esc_attr(strip_tags($name));
                    $argument = esc_attr(strip_tags($argument));
                    if ($name != 'loc' && $name != 'ltype') {
                        $output .= "\n\t\t" . '<input type="hidden" name="' . $name . '" value="' . $argument . '" />';
                    }
                }
            }
            $output .= "\r\n\t\t\t<label for='mc-locations-list'>" . __('Location', 'my-calendar') . "</label>\r\n\t\t\t<select name='loc' id='mc-locations-list'>\r\n\t\t\t<option value='all'>" . __('Show all', 'my-calendar') . "</option>\n";
        }
        foreach ($locations as $key => $location) {
            if ($type == 'saved') {
                foreach ($location as $k => $value) {
                    $vt = urlencode(trim($value));
                    $value = mc_kses_post(stripcslashes($value));
                    if ($value == '') {
                        continue;
                    }
                    if (empty($_GET['loc'])) {
                        $loc = '';
                    } else {
                        $loc = $_GET['loc'];
                    }
                    if ($show == 'list') {
                        $selected = $vt == $loc ? " class='selected'" : '';
                        $this_url = esc_url(mc_build_url(array('loc' => $vt, 'ltype' => $datatype), array()));
                        $output .= "\t\t\t<li{$selected}><a rel='nofollow' href='{$this_url}'>{$value}</a></li>\n";
                    } else {
                        $selected = $vt == $loc ? " selected='selected'" : '';
                        if ($value != '') {
                            $output .= "\t\t\t<option value='" . esc_attr($vt) . "'{$selected}>{$value}</option>\n";
                        }
                    }
                }
            } else {
                $vk = urlencode(trim($key));
                $location = mc_kses_post(trim($location));
                if ($location == '') {
                    continue;
                }
                if ($show == 'list') {
                    $selected = $vk == $_GET['loc'] ? " class='selected'" : '';
                    $this_url = esc_url(mc_build_url(array('loc' => $vk, 'ltype' => $datatype), array()));
                    $output .= "\t\t\t<li{$selected}><a rel='nofollow' href='{$this_url}'>{$location}</a></li>\n";
                } else {
                    $selected = $vk == $_GET['loc'] ? " selected='selected'" : '';
                    $output .= "\t\t\t<option value='" . esc_attr($vk) . "'{$selected}>{$location}</option>\n";
                }
            }
        }
        if ($show == 'list') {
            $output .= "</ul>";
        } else {
            $output .= "</select>";
            $output .= $group == 'single' ? "<input type='submit' value=" . __('Submit', 'my-calendar') . " />\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</form>" : '';
            $output .= "\r\n\t\t\t</div>";
        }
        $output = apply_filters('mc_location_selector', $output, $locations);
        return $output;
    } else {
        return '';
    }
}
function mc_meta_box_form()
{
    global $wpdb, $post;
    $has_data = false;
    $data = false;
    if (get_option('mc_event_approve') != 'true') {
        $dvalue = 1;
    } else {
        if (current_user_can('mc_approve_events')) {
            $dvalue = 1;
        } else {
            $dvalue = 0;
        }
    }
    if (get_option('mcs_approve_from_post') == 'true') {
        $dvalue = 0;
    }
    $event_desc = mc_show_block('event_desc', $has_data, $data, false);
    if ($event_desc) {
        $description = "<div class='event_description'>\n\t\t\t\t\t\t\t<label for='event_desc'>" . __('Event Description', 'my-calendar-submissions') . "</label><br />\n\t\t\t\t\t\t\t<textarea id='event_desc' class='event_desc widefat' cols='80' rows='8' name='event_desc'></textarea>\n\t\t\t\t\t\t</div>";
    } else {
        $description = '';
    }
    $event_host = mc_show_block('event_host', $has_data, $data, false);
    $event_category = mc_show_block('event_category', $has_data, $data, false);
    $event_link = mc_show_block('event_link', $has_data, $data, false);
    $event_recurs = mc_show_block('event_recurs', $has_data, $data, false);
    $mc_datetime = apply_filters('mc_datetime_inputs', '', $has_data, $data, 'admin');
    if (mc_show_edit_block('event_location_dropdown')) {
        $locs = $wpdb->get_results("SELECT location_id,location_label FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC");
        if (!empty($locs)) {
            $location = '<p>
			<label for="l_preset">' . __('Choose a preset location:', 'my-calendar') . '</label> <select
				name="location_preset" id="l_preset">
				<option value="none"> --</option>';
            foreach ($locs as $loc) {
                if (is_object($loc)) {
                    $location .= "<option value=\"" . $loc->location_id . "\">" . wp_kses_post(stripslashes($loc->location_label)) . "</option>";
                }
            }
            $location .= '</select></p>';
        } else {
            $location = '<input type="hidden" name="location_preset" value="none" />';
        }
    } else {
        $location = '<input type="hidden" name="location_preset" value="none" />';
    }
    $return = '
	<div>
		<input type="hidden" name="event_group_id" value="' . mc_group_id() . '" />
		<input type="hidden" name="event_action" value="add" />
		<input type="hidden" name="event_source" value="post" />
		<input type="hidden" name="event_nonce_name" value="' . wp_create_nonce('event_nonce') . '" />
	</div>
	<fieldset>
		<legend class="screen-reader-text">' . __('Event Details', 'my-calendar') . '</legend>
		<p>
			<label for="e_title">' . __('Event Title', 'my-calendar') . ' <span class="required">(required)</span></label><br/><input type="text" id="e_title" name="event_title" size="50" maxlength="255" value="" />
			<input type="hidden" value="' . $dvalue . '" name="event_approved" />
		</p>' . $description . $event_host . $event_category . $event_link . '
	</fieldset>
	<fieldset>
		<legend class="screen-reader-text">' . __('Event Date and Time', 'my-calendar') . '</legend>
		<div id="e_schedule">' . $mc_datetime . '</div>
	</fieldset>' . $event_recurs . '<fieldset>
	<legend class="screen-reader-text">' . __('Event Location', 'my-calendar') . '</legend>' . $location . '</fieldset>';
    return $return;
}