function cp_add_new_listing($advals)
{
    global $wpdb;
    $new_tags = '';
    $ad_length = '';
    $attach_id = '';
    $the_attachment = '';
    // tags are tricky and need to be put into an array before saving the ad
    if (!empty($advals['tags_input'])) {
        $new_tags = explode(',', $advals['tags_input']);
    }
    // put all the new ad elements into an array
    // these are the minimum required fields for WP (except tags)
    $new_ad = array();
    $new_ad['post_title'] = appthemes_filter($advals['post_title']);
    $new_ad['post_content'] = trim($advals['post_content']);
    $new_ad['post_status'] = 'pending';
    // no longer setting final status until after images are set
    $new_ad['post_author'] = 0;
    if (!empty($_SESSION['anonym']) && $_SESSION['anonym'] != '') {
        $new_ad['post_author'] = 0;
    } else {
        $new_ad['post_author'] = $advals['user_id'];
    }
    $new_ad['post_type'] = APP_POST_TYPE;
    // make sure the WP sanitize_post function doesn't strip out embed & other html
    if (get_option('cp_allow_html') == 'yes') {
        $new_ad['filter'] = true;
    }
    //print_r($new_ad).' <- new ad array<br>';
    // insert the new ad
    $post_id = wp_insert_post($new_ad);
    //set the custom post type categories
    wp_set_post_terms($post_id, appthemes_filter($advals['cat']), APP_TAX_CAT, false);
    //set the custom post type tags
    wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false);
    //$location = get_field('location');
    //**************************************EKLEME**********************************************
    // Google Maps ten Pozisyon Seçilmiþse O pozisyonu kaydeder seçimemiþse adresten bulur
    if (!empty($_SESSION['kordinat']) && $_SESSION['kordinat'] != '') {
        $category = get_the_terms($post_id, 'ad_cat');
        $address1 = explode('|', $_SESSION['kordinat']);
        $address2 = explode(',', $address1[1]);
        cp_add_geocode($post_id, $category[0]->name, $address2[0], $address2[1]);
        $_SESSION['kordinat'] = '';
    } else {
        $_SESSION['kordinat'] == 'yok';
    }
    //************************************************************************************
    // the unique order ID we created becomes the ad confirmation ID
    // we will use this for payment systems and for activating the ad
    // later if need be. it needs to start with cp_ otherwise it won't
    // be loaded in with the ad so let's give it a new name
    $advals['cp_sys_ad_conf_id'] = $advals['oid'];
    // get the ad duration and first see if ad packs are being used
    // if so, get the length of time in days otherwise use the default
    // prune period defined on the CP settings page
    if (isset($advals['pack_duration'])) {
        $ad_length = $advals['pack_duration'];
    } else {
        $ad_length = get_option('cp_prun_period');
    }
    // set the ad listing expiration date and put into a session
    $ad_expire_date = date_i18n('m/d/Y H:i:s', strtotime('+' . $ad_length . ' days'));
    // don't localize the word 'days'
    $advals['cp_sys_expire_date'] = $ad_expire_date;
    $advals['cp_sys_ad_duration'] = $ad_length;
    // now add all the custom fields into WP post meta fields
    foreach ($advals as $meta_key => $meta_value) {
        if (appthemes_str_starts_with($meta_key, 'cp_') && !is_array($advals[$meta_key])) {
            add_post_meta($post_id, $meta_key, $meta_value, true);
        }
        if (appthemes_str_starts_with($meta_key, 'cp_') && is_array($advals[$meta_key])) {
            foreach ($advals[$meta_key] as $checkbox_value) {
                add_post_meta($post_id, $meta_key, $checkbox_value);
            }
        }
    }
    // if they checked the box for a featured ad, then make the post sticky
    if (isset($advals['featured_ad'])) {
        stick_post($post_id);
    }
    if (isset($advals['attachment'])) {
        $the_attachment = $advals['attachment'];
        // associate the already uploaded images to the new ad and create multiple image sizes
        $attach_id = cp_associate_images($post_id, $the_attachment, true);
    }
    // set the thumbnail pic on the WP post
    //cp_set_ad_thumbnail($post_id, $attach_id);
    //last step is to publish the ad when its appropriate to publish immediately
    $final_status = cp_set_post_status($advals);
    if ($final_status == 'publish') {
        $final_post = array();
        $final_post['ID'] = $post_id;
        $final_post['post_status'] = $final_status;
        $update_result = wp_update_post($final_post);
    }
    // kick back the post id in case we want to use it
    return $post_id;
}
function cp_add_new_listing($advals, $renew_id = false)
{
    global $wpdb, $cp_options;
    $new_tags = '';
    $ad_length = '';
    $attach_id = '';
    $the_attachment = '';
    // check to see if html is allowed
    if (!$cp_options->allow_html) {
        $post_content = appthemes_filter($advals['post_content']);
    } else {
        $post_content = wp_kses_post($advals['post_content']);
    }
    // tags are tricky and need to be put into an array before saving the ad
    if (!empty($advals['tags_input'])) {
        $new_tags = explode(',', $advals['tags_input']);
    }
    // put all the new ad elements into an array
    // these are the minimum required fields for WP (except tags)
    $new_ad = array();
    $new_ad['post_title'] = appthemes_filter($advals['post_title']);
    $new_ad['post_content'] = trim($post_content);
    $new_ad['post_status'] = 'pending';
    // no longer setting final status until after images are set
    $new_ad['post_author'] = $advals['user_id'];
    $new_ad['post_type'] = APP_POST_TYPE;
    if ($renew_id) {
        $new_ad['ID'] = $renew_id;
        $new_ad['post_date'] = current_time('mysql');
        $new_ad['post_date_gmt'] = current_time('mysql', 1);
        $post_id = wp_update_post($new_ad);
    } else {
        // insert the new ad
        $post_id = wp_insert_post($new_ad);
    }
    //set the custom post type categories
    wp_set_post_terms($post_id, appthemes_filter($advals['cat']), APP_TAX_CAT, false);
    //set the custom post type tags
    wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false);
    // the unique order ID we created becomes the ad confirmation ID
    // we will use this for payment systems and for activating the ad
    // later if need be. it needs to start with cp_ otherwise it won't
    // be loaded in with the ad so let's give it a new name
    $advals['cp_sys_ad_conf_id'] = $advals['oid'];
    // get the ad duration and first see if ad packs are being used
    // if so, get the length of time in days otherwise use the default
    // prune period defined on the CP settings page
    if (isset($advals['pack_duration'])) {
        $ad_length = $advals['pack_duration'];
    } else {
        $ad_length = $cp_options->prun_period;
    }
    // set the ad listing expiration date and put into a session
    $ad_expire_date = appthemes_mysql_date(current_time('mysql'), $ad_length);
    $advals['cp_sys_expire_date'] = $ad_expire_date;
    $advals['cp_sys_ad_duration'] = $ad_length;
    // if renew ad - delete all old post meta and unmark ad as featured
    if ($renew_id) {
        unstick_post($renew_id);
        $custom_field_keys = get_post_custom_keys($renew_id);
        foreach ($custom_field_keys as $custom_key) {
            delete_post_meta($renew_id, $custom_key);
        }
    }
    // now add all the custom fields into WP post meta fields
    foreach ($advals as $meta_key => $meta_value) {
        if (appthemes_str_starts_with($meta_key, 'cp_') && !is_array($advals[$meta_key])) {
            add_post_meta($post_id, $meta_key, wp_kses_post($meta_value), true);
        }
        if (appthemes_str_starts_with($meta_key, 'cp_') && is_array($advals[$meta_key])) {
            foreach ($advals[$meta_key] as $checkbox_value) {
                add_post_meta($post_id, $meta_key, wp_kses_post($checkbox_value));
            }
        }
    }
    // if they checked the box for a featured ad, then make the post sticky
    if (isset($advals['featured_ad'])) {
        stick_post($post_id);
    }
    if (isset($advals['attachment'])) {
        $the_attachment = $advals['attachment'];
        // associate the already uploaded images to the new ad and create multiple image sizes
        $attach_id = cp_associate_images($post_id, $the_attachment, true);
    }
    if (isset($advals['app_attach_id'])) {
        $attachments = $advals['app_attach_id'];
        $titles = isset($advals['app_attach_title']) ? $advals['app_attach_title'] : array();
        // associate the already uploaded images to the new ad and update titles
        $attach_id = appthemes_plupload_associate_images($post_id, $attachments, $titles, true);
    }
    // set the thumbnail pic on the WP post
    //cp_set_ad_thumbnail($post_id, $attach_id);
    //last step is to publish the ad when its appropriate to publish immediately
    $final_status = cp_set_post_status($advals);
    if ($final_status == 'publish') {
        $final_post = array();
        $final_post['ID'] = $post_id;
        $final_post['post_status'] = $final_status;
        $update_result = wp_update_post($final_post);
    }
    cp_action_add_new_listing($post_id);
    // kick back the post id in case we want to use it
    return $post_id;
}
Esempio n. 3
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);
     }
 }
        // 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);
        }
    }
    // 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;
Esempio n. 5
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']);
             }
         }
     }
 }