public function form_fields() { $form_fields = array(array('title' => __('Reference ID', APP_TD), 'type' => 'text', 'name' => 'cp_sys_ad_conf_id', 'default' => cp_generate_id(), 'extra' => array('readonly' => 'readonly')), array('title' => __('Views Today', APP_TD), 'type' => 'text', 'name' => 'cp_daily_count', 'sanitize' => 'absint', 'default' => '0', 'extra' => array('readonly' => 'readonly')), array('title' => __('Views Total', APP_TD), 'type' => 'text', 'name' => 'cp_total_count', 'sanitize' => 'absint', 'default' => '0', 'extra' => array('readonly' => 'readonly')), array('title' => __('Submitted from IP', APP_TD), 'type' => 'text', 'name' => 'cp_sys_userIP', 'default' => appthemes_get_ip(), 'extra' => array('readonly' => 'readonly'))); if (cp_payments_is_enabled()) { $form_fields[] = array('title' => __('Last Payment', APP_TD), 'type' => 'text', 'name' => 'cp_sys_total_ad_cost', 'default' => '0', 'desc' => APP_Currencies::get_current_symbol(), 'extra' => array('readonly' => 'readonly')); } return $form_fields; }
/** * 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; }
function cp_save_meta_box($post_id) { global $wpdb, $post, $cp_options; // make sure something has been submitted from our nonce if (!isset($_POST['ad_meta_wpnonce'])) { return $post_id; } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!wp_verify_nonce($_POST['ad_meta_wpnonce'], basename(__FILE__))) { return $post_id; } // verify if this is an auto save routine. // if it is our form and it has not been submitted, dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // lastly check to make sure this user has permissions to save post fields if (!current_user_can('edit_post', $post_id)) { return $post_id; } // delete any images checked if (!empty($_POST['image'])) { cp_delete_image(); } // update the image alt text if (!empty($_POST['attachments'])) { cp_update_alt_text(); } // add a new image if one has been detected if ($attach_id = $_POST['new_ad_image_id']) { wp_update_post(array('ID' => $attach_id, 'post_parent' => $post_id)); } // assemble the comma separated hidden fields back into an array so we can save them. $metafields = explode(',', $_POST['custom_fields_vals']); // loop through all custom meta fields and update values foreach ($metafields as $name) { if (!isset($_POST[$name])) { delete_post_meta($post_id, $name); } else { if (is_array($_POST[$name])) { delete_post_meta($post_id, $name); foreach ($_POST[$name] as $checkbox_value) { add_post_meta($post_id, $name, $checkbox_value); } } else { update_post_meta($post_id, $name, $_POST[$name]); } } } // give the ad a unique ID if it's a new ad listing if (!($cp_id = get_post_meta($post->ID, 'cp_sys_ad_conf_id', true))) { $cp_item_id = cp_generate_id(); add_post_meta($post_id, 'cp_sys_ad_conf_id', $cp_item_id, true); } // save the IP address if it's a new ad listing if (!($cp_ip = get_post_meta($post->ID, 'cp_sys_userIP', true))) { add_post_meta($post_id, 'cp_sys_userIP', appthemes_get_ip(), true); } // set stats to zero so we at least have some data if (!($cp_dcount = get_post_meta($post->ID, 'cp_daily_count', true))) { add_post_meta($post_id, 'cp_daily_count', '0', true); } if (!($cp_tcount = get_post_meta($post->ID, 'cp_total_count', true))) { add_post_meta($post_id, 'cp_total_count', '0', true); } // set default ad duration, will need it to renew if (!($cp_ad_duration = get_post_meta($post->ID, 'cp_sys_ad_duration', true))) { $ad_length = $cp_options->prun_period; add_post_meta($post_id, 'cp_sys_ad_duration', $ad_length, true); } // set ad cost to zero, will need it for free renew if (!($cp_tcost = get_post_meta($post->ID, 'cp_sys_total_ad_cost', true))) { add_post_meta($post_id, 'cp_sys_total_ad_cost', '0.00', true); } }
<div class="content"> <!-- full block --> <div class="shadowblock_out"> <div class="shadowblock"> <?php // check and make sure the form was submitted from step1 and the session value exists if (isset($_POST['step1'])) { include_once get_template_directory() . '/includes/forms/step2.php'; } elseif (isset($_POST['step2'])) { include_once get_template_directory() . '/includes/forms/step3.php'; } else { // create a unique ID for this new ad order $order_id = cp_generate_id(); include_once get_template_directory() . '/includes/forms/step1.php'; } ?> </div><!-- /shadowblock --> </div><!-- /shadowblock_out --> </div> <div class="clr"></div> </div><!-- /content_res --> </div><!-- /content_botbg -->
$order['option_order_id'] = 'cp_order_' . $current_user->ID . '_' . $_POST['oid']; $order['pack_type'] = 'membership'; $order['total_cost'] = $membership->pack_membership_price; //save the order for use when payment is completed $order = array_merge($order, (array) $membership); update_option($order['option_order_id'], $order); $cp_user_orders = get_user_orders($current_user->ID); $cp_user_recent_order = $cp_user_orders ? $cp_user_orders[0] : false; include_once get_template_directory() . '/includes/forms/step3-membership.php'; } } elseif (!$errors->get_error_code()) { // create a unique ID for this new ad order if ($cp_user_recent_order) { $order_id = get_order_id($cp_user_recent_order); } else { $order_id = cp_generate_id('membership'); } include_once get_template_directory() . '/includes/forms/step1-membership.php'; } ?> <?php } else { ?> <h2 class="dotted"><?php _e('Membership Not Enabled', APP_TD); ?> </h2> <div class="info">
/** * Sets listing internal data. * * return void */ protected function set_internal_data() { global $cp_options, $current_user; $listing = $this->get_listing_obj(); // add items needed for function that displays listing preview $this->posted_fields['fid'] = $this->form_id; $this->posted_fields['cat'] = $this->category_id; // set listing unique id if ($unique_id = get_post_meta($listing->ID, 'cp_sys_ad_conf_id', true)) { $this->posted_fields['cp_sys_ad_conf_id'] = $unique_id; } else { $this->posted_fields['cp_sys_ad_conf_id'] = cp_generate_id(); } // set user IP $this->posted_fields['cp_sys_userIP'] = appthemes_get_ip(); // set listing duration if ($this->posted_fields['ad_pack_id']) { $this->posted_fields['cp_sys_ad_duration'] = cp_get_ad_pack_length($this->posted_fields['ad_pack_id']); } else { $this->posted_fields['cp_sys_ad_duration'] = $cp_options->prun_period; } $listing_price_currency = !empty($this->posted_fields['cp_currency']) ? $this->posted_fields['cp_currency'] : $cp_options->curr_symbol; $coupon = false; // legacy coupon value if (cp_payments_is_enabled()) { // see if the featured ad checkbox has been checked if (!empty($this->posted_fields['featured_ad'])) { $this->posted_fields['featured_ad'] = 1; // save featured ad price $this->posted_fields['cp_sys_feat_price'] = $cp_options->sys_feat_price; } // calculate the ad listing fee and put into a variable $this->posted_fields['cp_sys_ad_listing_fee'] = cp_ad_listing_fee($this->category_id, $this->posted_fields['ad_pack_id'], $this->posted_fields['cp_price'], $listing_price_currency); $featured_price = isset($this->posted_fields['cp_sys_feat_price']) ? $this->posted_fields['cp_sys_feat_price'] : 0; $this->posted_fields['cp_sys_total_ad_cost'] = cp_calc_ad_cost($this->category_id, $this->posted_fields['ad_pack_id'], $featured_price, $this->posted_fields['cp_price'], $coupon, $listing_price_currency); $this->posted_fields['cp_sys_total_ad_cost_no_benefit'] = $this->posted_fields['cp_sys_total_ad_cost']; // apply membership benefit if ($cp_options->enable_membership_packs && ($membership = cp_get_user_membership_package($current_user->ID))) { $this->posted_fields['membership_pack'] = $membership->ID; // update the total cost based on the membership pack ID and current total cost $this->posted_fields['cp_sys_total_ad_cost'] = cp_calculate_membership_package_benefit($membership->ID, $this->posted_fields['cp_sys_total_ad_cost']); // add featured cost to static pack type if ($featured_price && $membership->pack_type == 'static') { $this->posted_fields['cp_sys_total_ad_cost'] += $featured_price; } } } // prevent from minus prices if bigger discount applied if (!isset($this->posted_fields['cp_sys_total_ad_cost']) || $this->posted_fields['cp_sys_total_ad_cost'] < 0) { $this->posted_fields['cp_sys_total_ad_cost'] = 0; } }