Пример #1
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);
     }
 }
Пример #2
0
 // 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
 if (!empty($_FILES['image']['tmp_name'][0]) || !empty($_FILES['image']['tmp_name'][1]) || !empty($_FILES['image']['tmp_name'][2]) || !empty($_FILES['image']['tmp_name'][3]) || !empty($_FILES['image']['tmp_name'][4]) || !empty($_FILES['image']['tmp_name'][5])) {
     // check for valid the image extensions and sizes
     $error_msg = cp_validate_image();
     // images are valid
     if (!$error_msg) {
         $imagecount = cp_count_ad_images($_POST['ad_id']);
         //1
         $maximages = get_option('cp_num_images');
         //2
         // 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
         $the_msg = appthemes_error_msg($error_msg);
Пример #3
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']);
             }
         }
     }
 }