コード例 #1
0
ファイル: views.php プロジェクト: TopLineMediaTeam/horseshow
 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
ファイル: step2.php プロジェクト: TopLineMediaTeam/horseshow
 *
 * here we are processing the images and gathering all the post values.
 * using sessions would be the optimal way but WP doesn't play nice so instead
 * we take all the form post values and put them into an associative array
 * and then store it in the wp_options table as a serialized array. essentially
 * we are using the wp_options table as our session holder and can access
 * the keys and values later and process the ad in step 3
 *
 */
global $current_user, $wpdb;
$error_msg = false;
$usertype = $_POST['cp_type'];
// check to see if there are images included
// then valid the image extensions
if (!empty($_FILES['image'])) {
    $error_msg = cp_validate_image();
}
// displays error if images are required and user did not selected any image
if ($cp_options->ad_images && $cp_options->require_images) {
    if (empty($_FILES['image']['tmp_name'][0]) && empty($_POST['attachments']) && empty($_POST['app_attach_id'])) {
        $error_msg[] = __('Error: Please upload at least 1 image.', APP_TD);
    }
}
// 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);
}
コード例 #3
0
ファイル: views-checkout.php プロジェクト: kalushta/darom
 /**
  * Validates submitted fields.
  *
  * @param object $errors
  *
  * return object
  */
 public function validate_fields($errors)
 {
     global $cp_options;
     // validate images
     if (!empty($_FILES['image'])) {
         $image_errors = cp_validate_image();
         if ($image_errors) {
             $i = 0;
             foreach ($image_errors as $image_error) {
                 $errors->add('invalid-files_image', $image_error);
                 $i++;
             }
         }
     }
     // check if images are required and user uploaded some
     if ($cp_options->ad_images && $cp_options->require_images) {
         if (empty($_FILES['image']['tmp_name'][0]) && empty($this->posted_fields['attachments']) && empty($this->posted_fields['app_attach_id'])) {
             $errors->add('missed-image', __('Please upload at least 1 image.', APP_TD));
         }
     }
     // check custom form fields
     foreach ($this->form_fields as $field) {
         $field_value = $this->posted_fields[$field->field_name];
         if ($field->field_req && empty($field_value) && $field_value != '0') {
             $errors->add('missed-' . $field->field_name, sprintf(__('Error: The "%s" field is empty.', APP_TD), translate($field->field_label, APP_TD)));
         } else {
             if ($field->field_req && $field->field_min_length && mb_strlen($field_value) < $field->field_min_length) {
                 $errors->add('invalid-' . $field->field_name, sprintf(__('Error: The "%1$s" field should be at least %2$d characters long.', APP_TD), translate($field->field_label, APP_TD), $field->field_min_length));
             } else {
                 if (!empty($field_value) && in_array($field->field_type, array('checkbox', 'radio', 'drop-down'))) {
                     $options = explode(',', $field->field_values);
                     $options = array_map('trim', $options);
                     // check if the posted value is one of the provided by form
                     if (array_diff((array) $field_value, $options)) {
                         $errors->add('invalid-' . $field->field_name, sprintf(__('Error: The "%s" field is invalid.', APP_TD), translate($field->field_label, APP_TD)));
                     }
                 }
             }
         }
     }
     return $errors;
 }