// 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); } } // update the ad content $the_msg .= cp_update_listing(); } // MAIN PAGE STARTS HERE --> // get the ad id from the querystring. $aid = appthemes_numbers_only($_GET['aid']); // make sure the ad id is legit otherwise set it to zero which will return no results if (!empty($aid)) { $aid = $aid; } else { $aid = '0'; } // select post information and also category with joins. // filtering based off current user id which prevents people from trying to hack other peoples ads $sql = $wpdb->prepare("SELECT wposts.*, {$wpdb->term_taxonomy}.term_id " . "FROM {$wpdb->posts} wposts " . "LEFT JOIN {$wpdb->term_relationships} ON({$aid} = {$wpdb->term_relationships}.object_id) " . "LEFT JOIN {$wpdb->term_taxonomy} ON({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) " . "LEFT JOIN {$wpdb->terms} ON({$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id) " . "WHERE ID = %s AND {$wpdb->term_taxonomy}.taxonomy = '" . APP_TAX_CAT . "' ", $aid); //************************************************************************************************************* // pull ad fields from db
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); } }