Пример #1
0
 /**
  * Prevents duplicate entries while importing.
  */
 function prevent_duplicate($data)
 {
     if (!empty($data['post_meta']['cp_sys_ad_conf_id'])) {
         if (cp_get_listing_by_ref($data['post_meta']['cp_sys_ad_conf_id'])) {
             return false;
         }
     }
     return $data;
 }
Пример #2
0
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);
}
$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();
    }
/**
 * Generates unique ID for ads and memberships
 * @since 3.3.1
 *
 * @param string $type
 *
 * @return string
 */
function cp_generate_id($type = 'ad')
{
    $id = uniqid(rand(10, 1000), false);
    if ($type == 'ad') {
        if (cp_get_listing_by_ref($id)) {
            return cp_generate_id();
        }
    }
    return $id;
}