/** Save the Event data meta box. **/
function eventon_save_meta_data($post_id, $post)
{
    if ($post->post_type != 'ajde_events') {
        return;
    }
    // Stop WP from clearing custom fields on autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // Prevent quick edit from clearing custom fields
    if (defined('DOING_AJAX') && DOING_AJAX) {
        return;
    }
    // verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if (isset($_POST['evo_noncename'])) {
        if (!wp_verify_nonce($_POST['evo_noncename'], plugin_basename(__FILE__))) {
            return;
        }
    }
    // Check permissions
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    global $pagenow;
    $_allowed = array('post-new.php', 'post.php');
    if (!in_array($pagenow, $_allowed)) {
        return;
    }
    // $_POST FIELDS array
    $fields_ar = apply_filters('eventon_event_metafields', array('evcal_allday', 'evcal_event_color', 'evcal_event_color_n', 'evcal_location', 'evcal_location_name', 'evo_location_tax', 'evo_loc_img', 'evo_org_img', 'evcal_name_over_img', 'evcal_organizer', 'evcal_org_contact', 'evcal_org_img', 'evcal_org_exlink', 'evcal_exlink', 'evcal_lmlink', 'evcal_subtitle', 'evcal_gmap_gen', 'evcal_mu_id', 'evcal_paypal_item_price', 'evcal_paypal_text', 'evcal_paypal_email', 'evcal_repeat', 'evcal_rep_freq', 'evcal_rep_gap', 'evcal_rep_num', 'evp_repeat_rb', 'evo_repeat_wom', 'evo_rep_WK', 'evcal_lmlink_target', '_evcal_exlink_target', '_evcal_exlink_option', 'evo_hide_endtime', 'evo_span_hidden_end', 'evo_year_long', 'event_year', 'evo_evcrd_field_org', 'evo_event_timezone', 'evo_exclude_ev', '_featured', '_cancel', '_cancel_reason', '_onlyloggedin', 'evcal_lat', 'evcal_lon'));
    // append custom fields based on activated number
    $evcal_opt1 = get_option('evcal_options_evcal_1');
    $num = evo_calculate_cmd_count($evcal_opt1);
    for ($x = 1; $x <= $num; $x++) {
        if (eventon_is_custom_meta_field_good($x)) {
            $fields_ar[] = '_evcal_ec_f' . $x . 'a1_cus';
            $fields_ar[] = '_evcal_ec_f' . $x . 'a1_cusL';
            $fields_ar[] = '_evcal_ec_f' . $x . '_onw';
        }
    }
    // field names that pertains only to event date information
    $fields_sub_ar = apply_filters('eventon_event_date_metafields', array('evcal_start_date', 'evcal_end_date', 'evcal_start_time_hour', 'evcal_start_time_min', 'evcal_st_ampm', 'evcal_end_time_hour', 'evcal_end_time_min', 'evcal_et_ampm', 'evcal_allday'));
    // DATE and TIME data
    $date_POST_values = '';
    foreach ($fields_sub_ar as $ff) {
        // end date value fix for -- hide end date
        if ($ff == 'evcal_end_date' && !empty($_POST['evo_hide_endtime']) && $_POST['evo_hide_endtime'] == 'yes') {
            if ($_POST['evo_span_hidden_end'] && $_POST['evo_span_hidden_end'] == 'yes') {
                $date_POST_values['evcal_end_date'] = $_POST['evcal_end_date'];
            } else {
                $date_POST_values['evcal_end_date'] = $_POST['evcal_start_date'];
            }
            //$date_POST_values['evcal_end_date']=$_POST['evcal_end_date'];
        } else {
            if (!empty($_POST[$ff])) {
                $date_POST_values[$ff] = $_POST[$ff];
            }
        }
        // remove these values from previously saved
        delete_post_meta($post_id, $ff);
    }
    // convert the post times into proper unix time stamps
    if (!empty($_POST['_evo_date_format']) && !empty($_POST['_evo_time_format'])) {
        $proper_time = eventon_get_unix_time($date_POST_values, $_POST['_evo_date_format'], $_POST['_evo_time_format']);
    }
    // if Repeating event save repeating intervals
    if (eventon_is_good_repeat_data() && !empty($proper_time['unix_start'])) {
        $unix_E = !empty($proper_time['unix_end']) ? $proper_time['unix_end'] : $proper_time['unix_start'];
        $repeat_intervals = eventon_get_repeat_intervals($proper_time['unix_start'], $unix_E);
        // save repeat interval array as post meta
        if (!empty($repeat_intervals)) {
            asort($repeat_intervals);
            update_post_meta($post_id, 'repeat_intervals', $repeat_intervals);
        }
    }
    //update_post_meta($post_id, 'aaa', $_POST['repeat_intervals']);
    // run through all the custom meta fields
    foreach ($fields_ar as $f_val) {
        if (!empty($_POST[$f_val])) {
            $post_value = $_POST[$f_val];
            update_post_meta($post_id, $f_val, $post_value);
            // ux val for single events linking to event page
            if ($f_val == 'evcal_exlink' && $_POST['_evcal_exlink_option'] == '4') {
                update_post_meta($post_id, 'evcal_exlink', get_permalink($post_id));
            }
        } else {
            if (defined('DOING_AUTOSAVE') && !DOING_AUTOSAVE) {
                // if the meta value is set to empty, then delete that meta value
                delete_post_meta($post_id, $f_val);
            }
            delete_post_meta($post_id, $f_val);
        }
    }
    // full time converted to unix time stamp
    if (!empty($proper_time['unix_start'])) {
        update_post_meta($post_id, 'evcal_srow', $proper_time['unix_start']);
    }
    if (!empty($proper_time['unix_end'])) {
        update_post_meta($post_id, 'evcal_erow', $proper_time['unix_end']);
    }
    // save event year if not set
    if (empty($_POST['event_year']) && !empty($proper_time['unix_start']) || !empty($_POST['event_year']) && $_POST['event_year'] == 'yes') {
        $year = date('Y', $proper_time['unix_start']);
        update_post_meta($post_id, 'event_year', $year);
    }
    //set event color code to 1 for none select colors
    if (!isset($_POST['evcal_event_color_n'])) {
        update_post_meta($post_id, 'evcal_event_color_n', 1);
    }
    // save featured event data default value no
    $_featured = get_post_meta($post_id, '_featured', true);
    if (empty($_featured)) {
        update_post_meta($post_id, '_featured', 'no');
    }
    // LOCATION as taxonomy
    // if location name is choosen from the list
    if (isset($_POST['evcal_location_name_select'], $_POST['evcal_location_name']) && $_POST['evcal_location_name_select'] == $_POST['evcal_location_name']) {
        //
        if (!empty($_POST['evo_location_tax_id'])) {
            $term_name = esc_attr($_POST['evcal_location_name']);
            $term_meta = array();
            $term_meta['location_lon'] = isset($_POST['evcal_lon']) ? $_POST['evcal_lon'] : null;
            $term_meta['location_lat'] = isset($_POST['evcal_lat']) ? $_POST['evcal_lat'] : null;
            $term_meta['location_address'] = isset($_POST['evcal_location']) ? $_POST['evcal_location'] : null;
            $term_meta['evo_loc_img'] = isset($_POST['evo_loc_img']) ? $_POST['evo_loc_img'] : null;
            update_option("taxonomy_" . $_POST['evo_location_tax_id'], $term_meta);
            wp_set_post_terms($post_id, $term_name, 'event_location');
        }
    } elseif (isset($_POST['evcal_location_name'])) {
        // create new taxonomy from new values
        $term_name = esc_attr($_POST['evcal_location_name']);
        $term_slug = str_replace(" ", "-", $term_name);
        // create wp term
        $new_term_ = wp_insert_term($term_name, 'event_location', array('slug' => $term_slug));
        if (!is_wp_error($new_term_)) {
            $term_meta = array();
            $term_meta['location_lon'] = isset($_POST['evcal_lon']) ? $_POST['evcal_lon'] : null;
            $term_meta['location_lat'] = isset($_POST['evcal_lat']) ? $_POST['evcal_lat'] : null;
            $term_meta['location_address'] = isset($_POST['evcal_location']) ? $_POST['evcal_location'] : null;
            $term_meta['evo_loc_img'] = isset($_POST['evo_loc_img']) ? $_POST['evo_loc_img'] : null;
            update_option("taxonomy_" . $new_term_['term_id'], $term_meta);
            wp_set_post_terms($post_id, $term_name, 'event_location');
        }
    }
    // ORGANIZER as taxonomy
    // Selected value from list - update other values
    if (isset($_POST['evcal_organizer_name_select'], $_POST['evcal_organizer']) && $_POST['evcal_organizer_name_select'] == $_POST['evcal_organizer']) {
        if (!empty($_POST['evo_organizer_tax_id'])) {
            $term_name = esc_attr($_POST['evcal_organizer']);
            $term_meta = array();
            $term_meta['evcal_org_contact'] = isset($_POST['evcal_org_contact']) ? str_replace('"', "'", $_POST['evcal_org_contact']) : null;
            $term_meta['evo_org_img'] = isset($_POST['evo_org_img']) ? $_POST['evo_org_img'] : null;
            $term_meta['evcal_org_exlink'] = isset($_POST['evcal_org_exlink']) ? $_POST['evcal_org_exlink'] : null;
            update_option("taxonomy_" . $_POST['evo_organizer_tax_id'], $term_meta);
            wp_set_post_terms($post_id, $term_name, 'event_organizer');
        }
    } elseif (isset($_POST['evcal_organizer'])) {
        // create new taxonomy from new values
        $term_name = esc_attr($_POST['evcal_organizer']);
        $term_slug = str_replace(" ", "-", $term_name);
        // create wp term
        $new_term_ = wp_insert_term($term_name, 'event_organizer', array('slug' => $term_slug));
        if (!is_wp_error($new_term_)) {
            $term_meta = array();
            $term_meta['evcal_org_contact'] = isset($_POST['evcal_org_contact']) ? str_replace('"', "'", $_POST['evcal_org_contact']) : null;
            $term_meta['evo_org_img'] = isset($_POST['evo_org_img']) ? $_POST['evo_org_img'] : null;
            $term_meta['evcal_org_exlink'] = isset($_POST['evcal_org_exlink']) ? $_POST['evcal_org_exlink'] : null;
            update_option("taxonomy_" . $new_term_['term_id'], $term_meta);
            wp_set_post_terms($post_id, $term_name, 'event_organizer');
        }
    }
    // (---) hook for addons
    do_action('eventon_save_meta', $fields_ar, $post_id);
    // save user closed meta field boxes
    if (!empty($_POST['evo_collapse_meta_boxes'])) {
        eventon_save_collapse_metaboxes($post_id, $_POST['evo_collapse_meta_boxes'], true);
    }
}
Exemplo n.º 2
0
 function save_form_submissions()
 {
     $status = $cu_email = '';
     //process $_POST array
     foreach ($_POST as $ff => $post) {
         if (!is_array($post)) {
             $_POST[$ff] = urldecode($post);
         }
     }
     // edit or add new
     if (isset($_POST['form_action']) && isset($_POST['eventid']) && $_POST['form_action'] == 'editform') {
         $created_event_id = (int) $_POST['eventid'];
         $this->formtype = 'edit';
         $__post_content = !empty($_POST['event_description']) ? wpautop(convert_chars(stripslashes($_POST['event_description']))) : null;
         // update event name and event details
         $event = array('ID' => $created_event_id, 'post_title' => wp_strip_all_tags($_POST['event_name']), 'post_content' => $__post_content);
         wp_update_post($event);
     } else {
         $created_event_id = $this->create_post();
         $this->formtype = 'new';
     }
     if ($created_event_id) {
         // saved field valy
         $saved_fields = !empty($this->evoau_opt['evoau_fields']) && is_array($this->evoau_opt['evoau_fields']) && count($this->evoau_opt['evoau_fields']) > 0 ? $this->evoau_opt['evoau_fields'] : false;
         // SAVE DATE TIMES and start/end - meta data
         if (isset($_POST['event_start_date'])) {
             // if no end date
             $end_date = !empty($_POST['event_end_date']) ? $_POST['event_end_date'] : $_POST['event_start_date'];
             // start times
             $start_time = !empty($_POST['event_start_time']) ? $_POST['event_start_time'] : '1:00:am';
             $end_time = !empty($_POST['event_end_time']) ? $_POST['event_end_time'] : '11:55:pm';
             $start_time = explode(":", $start_time);
             $end_time = explode(":", $end_time);
             $__ampm_s = !empty($start_time[2]) ? $start_time[2] : null;
             $__ampm_e = !empty($end_time[2]) ? $end_time[2] : null;
             // date and time array
             $date_array_end = array('evcal_end_date' => $end_date, 'evcal_end_time_hour' => $end_time[0], 'evcal_end_time_min' => $end_time[1], 'evcal_et_ampm' => $__ampm_e, 'evcal_start_date' => $_POST['event_start_date'], 'evcal_start_time_hour' => $start_time[0], 'evcal_start_time_min' => $start_time[1], 'evcal_st_ampm' => $__ampm_s);
             // all day events
             if (!empty($_POST['event_all_day']) && $_POST['event_all_day'] == 'yes') {
                 $this->create_custom_fields($created_event_id, 'evcal_allday', 'yes');
             }
             if (!empty($_POST['evo_hide_endtime']) && $_POST['evo_hide_endtime'] == 'yes') {
                 $this->create_custom_fields($created_event_id, 'evo_hide_endtime', 'yes');
             }
             // merge both start and end time values
             $date_array = $date_array_end;
             $__evo_date_format = !empty($_POST['_evo_date_format']) ? $_POST['_evo_date_format'] : 'd/m/Y';
             $_evo_time_format = !empty($_POST['_evo_time_format']) ? $_POST['_evo_time_format'] : '12h';
             $proper_time = eventon_get_unix_time($date_array, $__evo_date_format, $_evo_time_format);
             // save required start time variables
             $this->create_custom_fields($created_event_id, 'evcal_srow', $proper_time['unix_start']);
             $this->create_custom_fields($created_event_id, 'evcal_erow', $proper_time['unix_end']);
         }
         // create custom meta fields and assign taxonomies
         foreach ($this->au_form_fields('savefields') as $field => $fn) {
             $__var_name = $fn[1];
             // check if value passed
             if (isset($_POST[$__var_name])) {
                 // for event taxonomies
                 if ($fn[2] == 'tax') {
                     // save post terms
                     if (count($_POST[$__var_name]) > 0 && is_array($_POST[$__var_name])) {
                         // for tax #1 and #2
                         if ($field == 'event_type_2' || $field == 'event_type') {
                             $ab = $field == 'event_type' ? '' : '_2';
                             $terms = $_POST[$__var_name];
                             // append default tax terms if activated in options
                             if (!empty($this->evoau_opt['evoau_set_def_ett' . $ab]) && !empty($this->evoau_opt['evoau_def_ett_v' . $ab]) && $this->evoau_opt['evoau_def_ett_v' . $ab] != '-' && $this->evoau_opt['evoau_set_def_ett' . $ab] == 'yes') {
                                 $terms[] = $this->evoau_opt['evoau_def_ett_v' . $ab];
                             }
                             wp_set_post_terms($created_event_id, $terms, $field);
                         } else {
                             wp_set_post_terms($created_event_id, $_POST[$__var_name], $field);
                         }
                     }
                 } else {
                     $value = addslashes($_POST[$__var_name]);
                     $this->create_custom_fields($created_event_id, $__var_name, $value);
                 }
                 // custom meta field that is a button
                 if ($fn[2] == 'button' && !empty($_POST[$__var_name . 'L'])) {
                     $this->create_custom_fields($created_event_id, $__var_name . 'L', $_POST[$__var_name . 'L']);
                 }
             }
             // end if var not set
             // create new tax term
             if ($fn[2] == 'tax' && !empty($_POST[$__var_name . '_new'])) {
                 $terms = $_POST[$__var_name . '_new'];
                 $terms = explode(',', $terms);
                 foreach ($terms as $term) {
                     $this->set_new_term($term, $__var_name, $created_event_id);
                 }
             }
             // Assign tax terms if activated but NOT visible on the form
             if ($field == 'event_type_2' || $field == 'event_type') {
                 $ab = $field == 'event_type' ? '' : '_2';
                 // append default tax terms if activated in options
                 if (!empty($this->evoau_opt['evoau_set_def_ett' . $ab]) && !empty($this->evoau_opt['evoau_def_ett_v' . $ab]) && $this->evoau_opt['evoau_def_ett_v' . $ab] != '-' && $this->evoau_opt['evoau_set_def_ett' . $ab] == 'yes') {
                     $terms[] = $this->evoau_opt['evoau_def_ett_v' . $ab];
                     wp_set_post_terms($created_event_id, $terms, $field);
                 }
             }
             // image
             if ($field == 'event_image') {
                 // on edit form if image already set
                 if (isset($_POST['event_image_exists']) && $_POST['event_image_exists'] == 'yes') {
                     continue;
                 }
                 if (!empty($_FILES) && 'POST' == $_SERVER['REQUEST_METHOD']) {
                     if ($_FILES[$__var_name]['error'] !== UPLOAD_ERR_OK) {
                         __return_false();
                     }
                     require_once ABSPATH . '/wp-admin/includes/media.php';
                     require_once ABSPATH . '/wp-admin/includes/file.php';
                     require_once ABSPATH . '/wp-admin/includes/image.php';
                     $attachmentId = media_handle_upload($__var_name, $created_event_id);
                     unset($_FILES);
                     set_post_thumbnail($created_event_id, $attachmentId);
                     $this->create_custom_fields($created_event_id, 'ftimg', $attachmentId);
                 }
             }
         }
         // end foreach
         // event color
         $COLOR = !empty($_POST['evcal_event_color']) ? $_POST['evcal_event_color'] : (!empty($this->options['evcal_hexcode']) ? $this->options['evcal_hexcode'] : '206177');
         $this->create_custom_fields($created_event_id, 'evcal_event_color', $COLOR);
         if (isset($_POST['evcal_event_color_n'])) {
             $this->create_custom_fields($created_event_id, 'evcal_event_color_n', $_POST['evcal_event_color_n']);
         }
         // current user
         $current_user = wp_get_current_user();
         // if user is logged in
         if (!empty($current_user)) {
             // get the user email if the user is logged in and has email
             $cu_email = $current_user->user_email;
         }
         // assign author is set to do so
         if ($this->formtype == 'new' && is_user_logged_in() && !empty($this->evoau_opt['evoau_assignu']) && $this->evoau_opt['evoau_assignu'] == 'yes') {
             // if user is logged in
             if (!empty($current_user)) {
                 $user_id = (string) $current_user->ID;
                 wp_set_object_terms($created_event_id, array($user_id), 'event_users');
             }
         }
         // Save user interaction fields
         if ($saved_fields && in_array('user_interaction', $saved_fields) || !empty($this->evoau_opt['evoau_ux']) && $this->evoau_opt['evoau_ux'] == 'yes') {
             if (isset($_POST['uinter'])) {
                 // only for external links
                 if ($_POST['uinter'] == 2) {
                     if (!empty($_POST['_evcal_exlink_target'])) {
                         $this->create_custom_fields($created_event_id, '_evcal_exlink_target', $_POST['_evcal_exlink_target']);
                     }
                     if (!empty($_POST['evcal_exlink'])) {
                         $this->create_custom_fields($created_event_id, 'evcal_exlink', $_POST['evcal_exlink']);
                     }
                 }
             }
             $ux_val = !empty($_POST['uinter']) ? $_POST['uinter'] : (!empty($this->evoau_opt['evoau_ux']) && $this->evoau_opt['evoau_ux'] == 'yes' ? $this->evoau_opt['evoau_ux_val'] : false);
             if ($ux_val) {
                 $this->create_custom_fields($created_event_id, '_evcal_exlink_option', $ux_val);
             }
         }
         //$this->create_custom_fields($created_event_id,'aaa', $debug);
         // generate google maps
         if (!empty($_POST['evcal_location'])) {
             $this->create_custom_fields($created_event_id, 'evcal_gmap_gen', 'yes');
         } else {
             $this->create_custom_fields($created_event_id, 'evcal_gmap_gen', 'no');
         }
         // location cordinates
         if (!empty($_POST['event_location_cord']) && strpos($_POST['event_location_cord'], ',') !== false) {
             $cord = explode(',', $_POST['event_location_cord']);
             $this->create_custom_fields($created_event_id, 'evcal_lat', $cord[0]);
             $this->create_custom_fields($created_event_id, 'evcal_lon', $cord[1]);
         }
         // save location as taxonomy
         if (!empty($_POST['evcal_location_name'])) {
             $this->set_new_term($_POST['evcal_location_name'], 'event_location', $created_event_id);
             $this->create_custom_fields($created_event_id, 'evcal_location_name_select', $_POST['evcal_location_name']);
         }
         // save organizer as taxonomy
         if (!empty($_POST['evcal_organizer'])) {
             $this->set_new_term($_POST['evcal_organizer'], 'event_organizer', $created_event_id);
             $this->create_custom_fields($created_event_id, 'evcal_organizer_name_select', $_POST['evcal_organizer']);
             $this->create_custom_fields($created_event_id, 'evo_evcrd_field_org', 'no');
         }
         // SET RSVP for event
         if (!empty($this->evoau_opt['evoar_rsvp_addon']) && $this->evoau_opt['evoar_rsvp_addon'] == 'yes') {
             $this->create_custom_fields($created_event_id, 'evors_rsvp', 'yes');
         }
         // save submitter email address
         if (!empty($_POST['yourname']) && isset($_POST['yourname'])) {
             $this->create_custom_fields($created_event_id, '_submitter_name', $_POST['yourname']);
         }
         // save email address for submitter
         if (!empty($_POST['youremail']) && isset($_POST['youremail'])) {
             $this->create_custom_fields($created_event_id, '_submitter_email', $_POST['youremail']);
         } elseif (!empty($cu_email)) {
             // save current user email if it exist
             $this->create_custom_fields($created_event_id, '_submitter_email', $cu_email);
         }
         // save whether to notify when draft is published if submission saved as draft
         if (empty($this->evoau_opt['evoau_post_status']) || !empty($this->evoau_opt['evoau_post_status']) && $this->evoau_opt['evoau_post_status'] == 'draft') {
             $this->create_custom_fields($created_event_id, '_send_publish_email', 'true');
         }
         // email notification
         $__evo_admin_email = get_option('admin_email');
         if ($this->formtype == 'new') {
             $this->send_au_email_notif($created_event_id, $__evo_admin_email);
             $this->send_submitter_email_notif($created_event_id, $__evo_admin_email);
         }
         return array('status' => 'good', 'msg' => '');
     } else {
         // could not create custom post type
         return array('status' => 'bad', 'msg' => 'nof4');
     }
 }
Exemplo n.º 3
0
/** Custom quick edit - save */
function eventon_admin_event_quick_edit_save($post_id, $post)
{
    if (!$_POST || is_int(wp_is_post_revision($post_id)) || is_int(wp_is_post_autosave($post_id))) {
        return $post_id;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    if (!isset($_POST['eventon_quick_edit_nonce']) || !wp_verify_nonce($_POST['eventon_quick_edit_nonce'], 'eventon_quick_edit_nonce')) {
        return $post_id;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
    if ($post->post_type != 'ajde_events') {
        return $post_id;
    }
    global $eventon, $wpdb;
    // Save fields
    if (isset($_POST['evcal_location'])) {
        update_post_meta($post_id, 'evcal_location', eventon_clean($_POST['evcal_location']));
    }
    if (isset($_POST['evcal_organizer'])) {
        update_post_meta($post_id, 'evcal_organizer', eventon_clean($_POST['evcal_organizer']));
    }
    // field names that pertains only to event date information
    $fields_sub_ar = apply_filters('eventon_event_date_metafields', array('evcal_start_date', 'evcal_end_date', 'evcal_start_time_hour', 'evcal_start_time_min', 'evcal_st_ampm', 'evcal_end_time_hour', 'evcal_end_time_min', 'evcal_et_ampm'));
    // DATE and TIME data
    $date_POST_values = '';
    foreach ($fields_sub_ar as $ff) {
        // end date value fix for -- hide end date
        if ($ff == 'evcal_end_date' && empty($_POST['evcal_end_date'])) {
            $date_POST_values['evcal_end_date'] = $_POST['evcal_start_date'];
        } else {
            if (!empty($_POST[$ff])) {
                $date_POST_values[$ff] = $_POST[$ff];
            }
        }
    }
    // convert the post times into proper unix time stamps
    if (!empty($_POST['_evo_date_format']) && !empty($_POST['_evo_time_format'])) {
        $proper_time = eventon_get_unix_time($date_POST_values, $_POST['_evo_date_format'], $_POST['_evo_time_format']);
    }
    //print_r($date_POST_values);
    // start time
    //$proper_time = eventon_get_unix_time();
    // full time converted to unix time stamp
    if (!empty($proper_time['unix_start'])) {
        update_post_meta($post_id, 'evcal_srow', $proper_time['unix_start']);
    }
    if (!empty($proper_time['unix_end'])) {
        update_post_meta($post_id, 'evcal_erow', $proper_time['unix_end']);
    }
    // featured
    if (isset($_POST['_featured'])) {
        update_post_meta($post_id, '_featured', 'yes');
    } else {
        update_post_meta($post_id, '_featured', 'no');
    }
    // menu order
    if (isset($_POST['_menu_order'])) {
        $newpostdata['menu_order'] = 5;
        $newpostdata['ID'] = $post_id;
        //wp_update_post($newpostdata);
    }
}
Exemplo n.º 4
0
    /**
     * Content for each step of the CSV import stages
     * Via switch statement
     */
    function step_content($steps)
    {
        global $eventon_csv;
        $evo_opt = get_option('evcal_options_evcal_1');
        $event_type_count = evo_get_ett_count($evo_opt);
        $cmd_count = evo_calculate_cmd_count($evo_opt);
        switch ($steps) {
            // Step nuber 1
            case 'uno':
                ?>
					
			<h2><?php 
                _e('Step 1: Upload CSV file', 'eventon');
                ?>
</h2>
			<?php 
                $this->form();
                $this->print_guidelines();
                break;
                // Step number 2
            // Step number 2
            case 'dos':
                if ($this->csv_verify_nonce_post('eventon_csvi_noncename')) {
                    ?>
				<h2><?php 
                    _e('Step 2: Verify uploaded events', 'eventon');
                    ?>
</h2>
				<p><?php 
                    _e('In this step you can see below the events we found from your uploaded CSV file. Please making sure the data is present correctly. You can also click on each event to deselect them from being imported to EventON - in the next step.', 'eventon');
                    ?>
</p>
				<?php 
                    // verified nonce
                    if (empty($_FILES['csv_import']['tmp_name'])) {
                        $this->log['error'][] = 'No file uploaded, Please try again!.';
                        $this->print_messages();
                        $this->step_content('uno');
                        return;
                    }
                    // get csv helper file
                    require_once $eventon_csv->plugin_path . '/assets/DataSource.php';
                    $time_start = microtime(true);
                    $csv = new File_CSV_DataSource();
                    $file = $_FILES['csv_import']['tmp_name'];
                    $this->stripBOM($file);
                    if (!$csv->load($file)) {
                        $this->log['error'][] = 'Failed to load file, Please try again!.';
                        $this->print_messages();
                        $this->step_content('uno');
                        return;
                    }
                    // pad shorter rows with empty values
                    $csv->symmetrize();
                    // correct wordpress time zone for event posts
                    $tz = get_option('timezone_string');
                    if ($tz && function_exists('date_default_timezone_set')) {
                        date_default_timezone_set($tz);
                    }
                    ?>
					<form class="" action='<?php 
                    echo admin_url();
                    ?>
admin.php?page=eventon&tab=evcal_csv&steps=thres' method="post" enctype="multipart/form-data">
					<?php 
                    settings_fields('eventon_csvi_field_grp');
                    wp_nonce_field($eventon_csv->plugin_path, 'eventon_csvi_dos_noncename');
                    echo "<table id='eventon_csv_data_list' class='wp-list-table widefat'>\r\n\t\t\t\t\t\t\t<thead>\r\n\t\t\t\t\t\t\t<th></th>\r\n\t\t\t\t\t\t\t<th title='Publish status for event'>Status</th>\r\n\t\t\t\t\t\t\t<th>Event Name</th>\r\n\t\t\t\t\t\t\t<th>Description</th>\r\n\t\t\t\t\t\t\t<th>Start Date & Time</th>\r\n\t\t\t\t\t\t\t<th>End Date & Time</th>\r\n\t\t\t\t\t\t\t<th>Location</th>\r\n\t\t\t\t\t\t\t<th>Organizer</th>\r\n\t\t\t\t\t\t\t</thead>";
                    // for each record
                    $x = 0;
                    foreach ($csv->connect() as $csv_data) {
                        $ev_desc_class = !empty($csv_data['event_description']) ? 'inner_check' : 'inner_check_no';
                        $ev_location_class = !empty($csv_data['event_location']) ? 'inner_check' : 'inner_check_no';
                        $ev_orga_class = !empty($csv_data['event_organizer']) ? 'inner_check' : 'inner_check_no';
                        // event date validation
                        if (!empty($csv_data['event_start_date'])) {
                            if (preg_match('/^(\\d{1,2})\\/(\\d{1,2})\\/((?:\\d{2}){1,2})$/', $csv_data['event_start_date'])) {
                                $event_start_date = $event_start_date_val = $csv_data['event_start_date'];
                            } else {
                                $event_start_date = "<p class='inner_check_no eventon_csv_icons'></p>";
                                $event_start_date_val = null;
                            }
                        } else {
                            $event_start_date = "<p class='inner_check_no eventon_csv_icons'></p>";
                            $event_start_date_val = null;
                        }
                        // event start time validation
                        if (!empty($csv_data['event_start_time'])) {
                            if (preg_match('/(1[0-2]|0?[0-9]):[0-5]?[0-9]?:(AM|PM)/', $csv_data['event_start_time'])) {
                                $event_start_time = $event_start_time_val = $csv_data['event_start_time'];
                            } else {
                                $event_start_time = "<p class='inner_check_no eventon_csv_icons'></p>";
                                $event_start_time_val = null;
                            }
                        } else {
                            $event_start_time = "<p class='inner_check_no eventon_csv_icons'></p>";
                            $event_start_time_val = null;
                        }
                        // end time
                        if (!empty($csv_data['event_end_time'])) {
                            if (preg_match('/(1[0-2]|0?[0-9]):[0-5]?[0-9]?:(AM|PM)/', $csv_data['event_end_time'])) {
                                $event_end_time = $event_end_time_val = $csv_data['event_end_time'];
                            } else {
                                $event_end_time = "<p class='inner_check_no eventon_csv_icons'></p>";
                                $event_end_time_val = $event_start_time_val;
                            }
                        } else {
                            $event_end_time = "<p class='inner_check_no eventon_csv_icons'></p>";
                            $event_end_time_val = $event_start_time_val;
                        }
                        // event end date
                        if (!empty($csv_data['event_end_date'])) {
                            if (preg_match('/^(\\d{1,2})\\/(\\d{1,2})\\/((?:\\d{2}){1,2})$/', $csv_data['event_end_date'])) {
                                $event_end_date = $event_end_date_val = $csv_data['event_end_date'];
                            } else {
                                $event_end_date = "<p class='inner_check_no eventon_csv_icons'></p>";
                                $event_end_date_val = $event_start_date_val;
                            }
                        } else {
                            // no end date present
                            $event_end_date = "<p class='inner_check_no eventon_csv_icons'></p>";
                            $event_end_date_val = $event_start_date_val;
                        }
                        // description
                        $event_description = !empty($csv_data['event_description']) ? convert_chars(addslashes($csv_data['event_description'])) : null;
                        // /print_r($csv_data);
                        $updated_csv_data = $csv_data;
                        $updated_csv_data['event_start_date'] = $event_start_date_val;
                        $updated_csv_data['event_start_time'] = $event_start_time_val;
                        $updated_csv_data['event_end_date'] = $event_end_date_val;
                        $updated_csv_data['event_end_time'] = $event_end_time_val;
                        $updated_csv_data['event_description'] = $event_description;
                        ?>
	
						<tr class='csv_list_row'>
							<?php 
                        echo $this->_html_get_hidden_input_fields($updated_csv_data, $x, $event_type_count, $cmd_count);
                        ?>
							<td class='col1'><p class='outter_check eventon_csv_icons'></p></td>
							<td><i><?php 
                        echo $csv_data['publish_status'];
                        ?>
</i></td>
							<td><?php 
                        echo $csv_data['event_name'];
                        ?>
</td>
							<td><p class='<?php 
                        echo $ev_desc_class;
                        ?>
 eventon_csv_icons'></p></td>
							<td><?php 
                        echo $event_start_date . '<br/>' . $event_start_time;
                        ?>
</td>
							<td><?php 
                        echo $event_end_date . '<br/>' . $event_end_time;
                        ?>
</td>
							<td title='<?php 
                        echo $csv_data['event_location'];
                        ?>
'><p class='<?php 
                        echo $ev_location_class;
                        ?>
 eventon_csv_icons'></p></td>
							<td title='<?php 
                        echo $csv_data['event_organizer'];
                        ?>
'><p class='<?php 
                        echo $ev_orga_class;
                        ?>
 eventon_csv_icons'></p></td>
						</tr>
						
						<?php 
                        $x++;
                    }
                    echo "</table><p class='submit'><input type='submit' class='evo_admin_btn btn_tritiary' name='submit' value='Next: Import selected events' /></p></form>";
                    if (file_exists($file)) {
                        @unlink($file);
                    }
                    $exec_time = microtime(true) - $time_start;
                    $this->log['notice'][] = sprintf("<b>Found {$x} events in %.2f seconds from the csv file.</b>", $exec_time);
                    $this->print_messages();
                }
                break;
                // Step three
            // Step three
            case 'thres':
                if ($this->csv_verify_nonce_post('eventon_csvi_dos_noncename')) {
                    if (isset($_POST['csvi'])) {
                        $skipped = 0;
                        $imported = 0;
                        $event_names_imp = array();
                        $event_names_skip = array();
                        $time_start = microtime(true);
                        //$date_format = eventon_get_timeNdate_format();
                        // Run through each event row and add them
                        foreach ($_POST['csvi'] as $event) {
                            // check is the event is selected to be imported
                            if ($event['status'] == 'yes') {
                                if ($post_id = $this->create_post($event)) {
                                    $imported++;
                                    $event_names_imp[] = $event['event_name'];
                                    /*	Event Start and end time and dates	*/
                                    if (isset($event['event_start_date']) && isset($event['event_end_date']) && isset($event['event_start_time']) && isset($event['event_end_time'])) {
                                        $start_time = explode(":", $event['event_start_time']);
                                        $end_time = explode(":", $event['event_end_time']);
                                        $date_array = array('evcal_start_date' => $event['event_start_date'], 'evcal_start_time_hour' => $start_time[0], 'evcal_start_time_min' => $start_time[1], 'evcal_st_ampm' => $start_time[2], 'evcal_end_date' => $event['event_end_date'], 'evcal_end_time_hour' => $end_time[0], 'evcal_end_time_min' => $end_time[1], 'evcal_et_ampm' => $end_time[2], 'evcal_allday' => !empty($event['all_day']) ? $event['all_day'] : 'no');
                                        $proper_time = eventon_get_unix_time($date_array, 'm/d/Y');
                                        // save required start time variables
                                        $this->create_custom_fields($post_id, 'evcal_srow', $proper_time['unix_start']);
                                        $this->create_custom_fields($post_id, 'evcal_erow', $proper_time['unix_end']);
                                        //$this->create_custom_fields($post_id, 'data', $date_format[1]);
                                    }
                                    // rest of the custom meta fields
                                    $this->save_custom_meta_fields($event, $post_id, $event_type_count, $cmd_count);
                                } else {
                                    $skipped++;
                                    $event_names_skip[] = $event['event_name'];
                                }
                            }
                        }
                        // create notices
                        if ($skipped > 0) {
                            $this->log['notice'][] = "<b>Skipped {$skipped} events (most likely due to empty title or description).</b>";
                        }
                        $exec_time = microtime(true) - $time_start;
                        $this->log['notice'][] = sprintf("<b>Imported {$imported} events in %.2f seconds.</b>", $exec_time);
                        $this->print_messages();
                        // =====
                        // Show the report on import process
                        _e('<h2>Done!</h2>', 'eventon');
                        echo "<p>Please go to <a href='" . admin_url() . "edit.php?post_type=ajde_events'>All Events</a> to further customize the events you just imported.</p>";
                        // Success report
                        if (count($event_names_imp) > 0) {
                            echo "<table id='eventon_csv_data_list' class='wp-list-table widefat'>\r\n\t\t\t\t\t\t\t\t\t<thead>\r\n\t\t\t\t\t\t\t\t\t<th>Event Name</th>\r\n\t\t\t\t\t\t\t\t\t<th>Status</th>\r\n\t\t\t\t\t\t\t\t\t</thead>";
                            foreach ($event_names_imp as $event_name) {
                                echo "<tr><td>{$event_name}</td><td>Imported</td></tr>";
                            }
                            // didnt import
                            if (count($event_names_skip) > 0) {
                                foreach ($event_names_skip as $event_name) {
                                    echo "<tr><td>{$event_name}</td><td>Not Imported</td></tr>";
                                }
                            }
                            echo "</table>";
                        }
                    }
                }
                break;
                // default step
            // default step
            default:
                ?>
				<h3><?php 
                _e('Import Events from a CSV file', 'eventon');
                ?>
</h3>
				<p>CSV Importer addon for EventON will allow you to export events from another event plugin or another event calendar, into CSV file format, and import those events into EventON Calendar.</p>
				
				<hr/>
				
				<a href='<?php 
                echo admin_url();
                ?>
admin.php?page=eventon&tab=evcal_csv&steps=uno' class='csv_import_get_start_btn evo_admin_btn btn_prime'><?php 
                _e('Get Started Now', 'eventon');
                ?>
</a>		
						
				<?php 
                $this->print_guidelines();
                break;
        }
        // end switch statement
    }