Esempio n. 1
0
// duplicate check
if (cp_get_listing_by_ref($_POST['oid'])) {
    $error_msg[] = sprintf(__('Error: ad already exist in database. Please post an <a href="%s">new Ad</a>.', APP_TD), CP_ADD_NEW_URL);
}
// check to see is ad pack specified for fixed price option
if ($cp_options->price_scheme == 'single' && cp_payments_is_enabled() && !isset($_POST['ad_pack_id'])) {
    $error_msg[] = __('Error: no ad pack has been defined. Please contact the site administrator.', APP_TD);
}
$error_msg = apply_filters('cp_listing_validate_fields', $error_msg);
// images are valid
if (!$error_msg) {
    // create the array that will hold all the post values
    $postvals = array();
    // delete any images checked
    if (!empty($_POST['image'])) {
        cp_delete_image();
    }
    // update the image alt text
    if (!empty($_POST['attachments'])) {
        cp_update_alt_text();
    }
    // upload the images and put into the new ad array
    if (!empty($_FILES['image'])) {
        $postvals = cp_process_new_image();
    }
    if (!empty($_POST['app_attach_id'])) {
        $postvals['app_attach_id'] = $_POST['app_attach_id'];
    }
    if (!empty($_POST['app_attach_title'])) {
        $postvals['app_attach_title'] = $_POST['app_attach_title'];
    }
Esempio n. 2
0
 function update()
 {
     global $cp_options;
     if (!isset($_POST['action']) || 'cp-edit-item' != $_POST['action'] || !current_user_can('edit_posts')) {
         return;
     }
     check_admin_referer('cp-edit-item');
     // needed for image uploading and deleting to work
     include_once ABSPATH . 'wp-admin/includes/file.php';
     include_once ABSPATH . 'wp-admin/includes/image.php';
     // associate app-plupload images
     if (isset($_POST['app_attach_id'])) {
         $attachments = $_POST['app_attach_id'];
         $titles = isset($_POST['app_attach_title']) ? $_POST['app_attach_title'] : array();
         // associate the already uploaded images to the new ad and update titles
         $attach_id = appthemes_plupload_associate_images($_POST['ad_id'], $attachments, $titles, false);
     }
     // delete any images checked
     if (!empty($_POST['image'])) {
         cp_delete_image();
     }
     // update the image alt text
     if (!empty($_POST['attachments'])) {
         cp_update_alt_text();
     }
     // check to see if an image needs to be uploaded, hack since we just check if array keys are empty for 6 keys
     $process_images = false;
     for ($i = 0; $i <= 6; $i++) {
         if (!empty($_FILES['image']['tmp_name'][$i])) {
             $process_images = true;
             break;
         }
     }
     // displays error if images are required and user did not selected any image
     if ($cp_options->ad_images && $cp_options->require_images) {
         if (!$process_images && empty($_POST['attachments']) && empty($_POST['app_attach_id'])) {
             $this->error[] = __('Error: Please upload at least 1 image.', APP_TD);
         }
     }
     if ($process_images) {
         // check for valid the image extensions and sizes
         $error_msg = cp_validate_image();
         if (!$error_msg) {
             $imagecount = cp_count_ad_images($_POST['ad_id']);
             $maximages = $cp_options->num_images;
             // only allow the max number of images to each ad. prevents page reloads adding more
             if ($maximages > $imagecount) {
                 // create the array that will hold all the post values
                 $postvals = array();
                 // now upload the new image
                 $postvals = cp_process_new_image($_POST['ad_id']);
                 // associate the already uploaded images to the ad and create multiple image sizes
                 $attach_id = cp_associate_images($_POST['ad_id'], $postvals['attachment']);
             }
         } else {
             // images didn't upload
             $this->error = $error_msg;
         }
     }
     $this->error = apply_filters('cp_listing_validate_fields', $this->error);
     // update an ad
     $post_id = empty($this->error) ? cp_update_listing() : false;
     if (!$post_id) {
         $this->error[] = __('There was an error trying to update your ad.', APP_TD);
     }
 }
Esempio n. 3
0
function cp_save_meta_box($post_id)
{
    global $wpdb, $post, $key;
    // make sure something has been submitted from our nonce
    if (!isset($_POST[$key . '_wpnonce'])) {
        return $post_id;
    }
    // verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if (!wp_verify_nonce($_POST[$key . '_wpnonce'], basename(__FILE__))) {
        return $post_id;
    }
    // verify if this is an auto save routine.
    // if it is our form and it has not been submitted, dont want to do anything
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // lastly check to make sure this user has permissions to save post fields
    if (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
    // delete any images checked
    if (!empty($_POST['image'])) {
        cp_delete_image();
    }
    // update the image alt text
    if (!empty($_POST['attachments'])) {
        cp_update_alt_text();
    }
    // add a new image if one has been detected
    if ($attach_id = $_POST['new_ad_image_id']) {
        wp_update_post(array('ID' => $attach_id, 'post_parent' => $post_id));
    }
    // assemble the comma separated hidden fields back into an array so we can save them.
    $metafields = explode(',', $_POST['custom_fields_vals']);
    // loop through all custom meta fields and update values
    foreach ($metafields as $name) {
        //echo $name . ' <-- POST NAME<br/>';
        //echo $_POST["$name"] . ' <-- VALUE<br/><br/>';
        if (!isset($_POST[$name])) {
            delete_post_meta($post_id, $name);
        } else {
            if (is_array($_POST[$name])) {
                delete_post_meta($post_id, $name);
                foreach ($_POST[$name] as $checkbox_value) {
                    add_post_meta($post_id, $name, $checkbox_value);
                }
            } else {
                update_post_meta($post_id, $name, $_POST[$name]);
            }
        }
    }
    // give the ad a unique ID if it's a new ad listing
    if (!($cp_id = get_post_meta($post->ID, 'cp_sys_ad_conf_id', true))) {
        $cp_item_id = uniqid(rand(10, 1000), false);
        add_post_meta($post_id, 'cp_sys_ad_conf_id', $cp_item_id, true);
    }
    // save the IP address if it's a new ad listing
    if (!($cp_ip = get_post_meta($post->ID, 'cp_sys_userIP', true))) {
        add_post_meta($post_id, 'cp_sys_userIP', appthemes_get_ip(), true);
    }
    // set stats to zero so we at least have some data
    if (!($cp_dcount = get_post_meta($post->ID, 'cp_daily_count', true))) {
        add_post_meta($post_id, 'cp_daily_count', '0', true);
    }
    if (!($cp_tcount = get_post_meta($post->ID, 'cp_total_count', true))) {
        add_post_meta($post_id, 'cp_total_count', '0', true);
    }
    // set default ad duration, will need it to renew
    if (!($cp_ad_duration = get_post_meta($post->ID, 'cp_sys_ad_duration', true))) {
        $ad_length = get_option('cp_prun_period');
        add_post_meta($post_id, 'cp_sys_ad_duration', $ad_length, true);
    }
    // set ad cost to zero, will need it for free renew
    if (!($cp_tcost = get_post_meta($post->ID, 'cp_sys_total_ad_cost', true))) {
        add_post_meta($post_id, 'cp_sys_total_ad_cost', '0.00', true);
    }
}
Esempio n. 4
0
 /**
  * Updating attachments.
  *
  * @param object $order
  * @param object $checkout
  *
  * return void
  */
 public function update_attachments($order, $checkout)
 {
     global $cp_options;
     // needed for image uploading and deleting to work
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/image.php';
     $listing = $this->get_listing_obj();
     // associate app-plupload images
     if (!empty($this->posted_fields['app_attach_id']) && is_array($this->posted_fields['app_attach_id'])) {
         $attachments = $this->posted_fields['app_attach_id'];
         $titles = !empty($this->posted_fields['app_attach_title']) && is_array($this->posted_fields['app_attach_title']) ? $this->posted_fields['app_attach_title'] : array();
         // associate the already uploaded images to listing and update titles
         appthemes_plupload_associate_images($listing->ID, $attachments, $titles, false);
     }
     // delete any images checked
     if (!empty($this->posted_fields['image'])) {
         cp_delete_image();
     }
     // update the image alt text
     if (!empty($this->posted_fields['attachments'])) {
         cp_update_alt_text();
     }
     // upload images and associate to listing
     if (!empty($_FILES['image']) && $this->is_field_valid('files_image')) {
         $images_count = cp_count_ad_images($listing->ID);
         $max_images = $cp_options->num_images;
         if ($max_images > $images_count) {
             $images_data = cp_process_new_image();
             if (!empty($images_data['attachment'])) {
                 cp_associate_images($listing->ID, $images_data['attachment']);
             }
         }
     }
 }