private function find_current_listing() { $this->ad_id = absint($this->request->get_ad_id()); if ($this->ad_id === 0) { return null; } $this->ad = AWPCP_Ad::find_by_id($this->ad_id); $this->properties = awpcp_get_ad_share_info($this->ad_id); }
public function get_ad() { if (is_null($this->ad)) { if ($id = $this->get_listing_id()) { $this->ad = AWPCP_Ad::find_by_id($id); } } return $this->ad; }
public function get_ad() { if (!isset($this->ad)) { $this->ad = null; } if (is_null($this->ad)) { $this->ad = AWPCP_Ad::find_by_id(awpcp_request_param(is_admin() ? 'id' : 'ad_id')); } return $this->ad; }
/** * @since 3.0.2 */ public function handle_email_verification_link() { $ad_id = $this->request->get_query_var('awpcp-ad'); $hash = $this->request->get_query_var('awpcp-hash'); $ad = AWPCP_Ad::find_by_id($ad_id); if (is_null($ad) || !awpcp_verify_email_verification_hash($ad_id, $hash)) { wp_redirect(awpcp_get_main_page_url()); return; } $this->verify_ad($ad); wp_redirect(esc_url_raw(add_query_arg('verified', true, url_showad($ad->ad_id)))); return; }
public function get_ad() { if (is_null($this->ad)) { $ad_id = absint(awpcp_request_param('i')); if ($ad_id === 0 && get_awpcp_option('seofriendlyurls')) { $permalinks = get_option('permalink_structure'); if (!empty($permalinks)) { $ad_id = absint(get_query_var('id')); } } $this->ad = AWPCP_Ad::find_by_id($ad_id); } return $this->ad; }
public function dispatch($page) { $this->page = $page; $action = $page->get_current_action(); $ad = AWPCP_Ad::find_by_id(awpcp_request_param('id', awpcp_request_param('adid', false))); $media = awpcp_media_api()->find_by_id(awpcp_request_param('picid')); $current_user_id = get_current_user_id(); $is_admin_user = awpcp_current_user_is_admin(); $ad_belongs_to_user = AWPCP_Ad::belongs_to_user($ad->ad_id, $current_user_id); if (!$is_admin_user && !$ad_belongs_to_user) { $message = _x("You don't have sufficient permissions to modify that Ad's media", 'media manager', 'AWPCP'); return $this->page->render('content', awpcp_print_error($message)); } if (!is_null($media) && $ad->ad_id != $media->ad_id) { $message = _x('The specified file does not belongs to the specified Ad. No action will be performed.', 'media managear', 'AWPCP'); awpcp_flash($message, 'error'); $action = 'show_images'; } $media_actions = array('deletepic', 'rejectpic', 'approvepic', 'set-primary-image'); if (is_null($media) && in_array($action, $media_actions)) { $message = _x('The specified file does not exists. No action will be performed.', 'media managear', 'AWPCP'); awpcp_flash($message, 'error'); $action = 'show_images'; } switch ($action) { case 'deletepic': return $this->delete_file($ad, $media); case 'rejectpic': return $this->disable_picture($ad, $media); case 'approvepic': return $this->enable_picture($ad, $media); case 'approve-file': return $this->approve_file($ad, $media); case 'reject-file': return $this->reject_file($ad, $media); case 'set-primary-image': return $this->set_primary_image($ad, $media); case 'add-image': return $this->add_image($ad, $media); default: return $this->show_images($ad); } }
public function finish_step() { $transaction = $this->get_transaction(); $messages = $this->messages; $send_email = false; if (is_null($transaction)) { $message = __('We were unable to find a Payment Transaction assigned to this operation.', 'AWPCP'); return $this->render('content', awpcp_print_error($message)); } $ad = AWPCP_Ad::find_by_id($transaction->get('ad-id', 0)); if (is_null($ad)) { $message = __('The Ad associated with this transaction doesn\'t exists.', 'AWPCP'); return $this->render('content', awpcp_print_error($message)); } if (!$transaction->is_completed()) { awpcp_payments_api()->set_transaction_status_to_completed($transaction, $errors); if (!empty($errors)) { return $this->render('content', join(',', array_map('awpcp_print_error', $errors))); } $transaction->save(); } // reload Ad, since modifications were probably made as part of the // transaction handling workflow $ad = AWPCP_Ad::find_by_id($transaction->get('ad-id', 0)); $params = array('edit' => false, 'ad' => $ad, 'messages' => array_merge($messages, awpcp_listings_api()->get_ad_alerts($ad)), 'transaction' => $transaction, 'transaction_id' => $transaction->id); $template = AWPCP_DIR . '/frontend/templates/page-place-ad-finish-step.tpl.php'; return $this->render($template, $params); }
public function ajax_flag_ad() { $response = 0; if (check_ajax_referer('flag_ad', 'nonce')) { $ad = AWPCP_Ad::find_by_id(intval(awpcp_request_param('ad', 0))); if (!is_null($ad)) { $response = awpcp_listings_api()->flag_listing($ad); } } echo $response; die; }
function display_x_fields_data($adid, $single = true) { global $wpdb; $ad = AWPCP_Ad::find_by_id($adid); $fields = awpcp_get_extra_fields_by_category($ad->ad_category_id, array('hide_private' => true, 'context' => $single ? 'single' : 'listings')); $show_empty = get_awpcp_option('show-empty-extra-fields-in-ads'); $visible = array(); foreach ($fields as $i => $field) { $value = (array) get_field_value($adid, $field->field_name); if ($show_empty || !empty($value) && strlen($value[0]) > 0) { $visible[] = array('field' => $field, 'value' => $value); } } $allow_html_in_labels = get_awpcp_option('allow-html-in-extra-field-labels'); $count = count($visible); $columns = get_awpcp_option('display-extra-fields-in-columns', 1); $rows = ceil($count / $columns); $shown = 0; $classes = array('awpcp-extra-fields', 'awpcp-extra-fields-columns-' . $columns, 'clearfix'); $html = '<div class="' . join(' ', $classes) . '">'; foreach ($visible as $i => $data) { $field = $data['field']; $value = $data['value']; $classes = array('cladinfo', 'awpcp-extra-field-' . $field->field_name); $css = awpcp_get_grid_item_css_class($classes, $shown, $columns, $rows); $field_label = stripslashes($field->field_label_view); $field_label = $allow_html_in_labels ? $field_label : esc_html($field_label); if ($show_empty || !empty($value) && strlen($value[0]) > 0) { $html .= '<div class="' . esc_attr(join(' ', $css)) . '">'; $html .= '<label>' . $field_label . ':</label> '; if (count($value) > 1) { $html .= '<ul class="awpcp-extra-field-value-list">'; foreach ($value as $v) { $v = awpcp_extra_fields_render_field_single_value($field, $v); $html .= '<li>' . $v . '</li>'; } $html .= '</ul>'; } else { if (count($value) > 0) { $value = awpcp_extra_fields_render_field_single_value($field, $value[0]); if ($field->field_input_type === 'Textarea Input') { $html .= sprintf('<div class="awpcp-extra-field-value">%s</div>', $value); } else { $html .= sprintf('<span class="awpcp-extra-field-value">%s</span>', $value); } } } $html .= '</div>'; $shown++; } } $html .= '</div>'; return $html; }
/** * WP Affiliate Platform integration. * * Notifies WP Affiliate Platform plugin when a transaction * that involves money exchange has been completed. * * @since 3.0.2 */ public function process_transaction_notify_wp_affiliate_platform($transaction) { if (!($transaction->is_payment_completed() || $transaction->is_completed())) { return; } if ($transaction->payment_is_not_required()) { return; } if (!$transaction->was_payment_successful()) { return; } $allowed_context = array('add-credit', 'place-ad', 'renew-ad', 'buy-subscription'); $context = $transaction->get('context'); if (!in_array($context, $allowed_context)) { return; } $amount = $transaction->get_total_amount(); if ($amount <= 0) { return; } $unique_transaction_id = $transaction->id; $referrer = isset($_COOKIE['ap_id']) ? $_COOKIE['ap_id'] : null; $email = ''; if ($transaction->get('ad_id')) { $ad = AWPCP_Ad::find_by_id($transaction->get('ad_id')); $email = $ad->ad_contact_email; } else { if ($transaction->user_id) { $user = get_userdata($transaction->user_id); $email = $user->user_email; } } $data = array('sale_amt' => $amount, 'txn_id' => $unique_transaction_id, 'referrer' => $referrer, 'buyer_email' => $email); do_action('wp_affiliate_process_cart_commission', $data); }
public function send_access_key() { global $nameofsite; $ad = AWPCP_Ad::find_by_id($this->id); $recipient = "{$ad->ad_contact_name} <{$ad->ad_contact_email}>"; $template = AWPCP_DIR . '/frontend/templates/email-send-ad-access-key.tpl.php'; $message = new AWPCP_Email(); $message->to[] = $recipient; $message->subject = sprintf('Access Key for "%s"', $ad->get_title()); $message->prepare($template, array('ad' => $ad, 'nameofsite' => $nameofsite)); if ($message->send()) { awpcp_flash(sprintf(__('The access key was sent to %s.', 'AWPCP'), esc_html($recipient))); } else { awpcp_flash(sprintf(__('There was an error trying to send the email to %s.', 'AWPCP'), esc_html($recipient))); } return $this->redirect('index'); }
private function save_regions($region, $ad_id, $row, &$errors) { if (!$this->options['test-import']) { $ad = AWPCP_Ad::find_by_id($ad_id); awpcp_basic_regions_api()->update_ad_regions($ad, array($region), 1); } }
public function handle_clear_cache_event_hook($ad_id) { $this->clear_ad_cache(AWPCP_Ad::find_by_id($ad_id)); }
/** * Return number of allowed images for an Ad, according to its * Ad ID or Fee Term ID. * * @param $ad_id int Ad ID. * @param $ad_term_id int Ad Term ID. */ function awpcp_get_ad_number_allowed_images($ad_id) { $ad = AWPCP_Ad::find_by_id($ad_id); if (is_null($ad)) { return 0; } $payment_term = $ad->get_payment_term(); if (!is_null($payment_term)) { $allowed = $payment_term->images; } else { $allowed = get_awpcp_option('imagesallowedfree'); } return $allowed; }
/** * Returns a link to the page where visitors can contact the Ad's owner * * @since 3.0.0 */ function awpcp_get_reply_to_ad_url($ad_id, $ad_title = null) { $base_url = awpcp_get_page_url('reply-to-ad-page-name'); $permalinks = get_option('permalink_structure'); $url = false; if (!is_null($ad_title)) { $title = sanitize_title($ad_title); } else { $title = sanitize_title(AWPCP_Ad::find_by_id($ad_id)->ad_title); } if (get_awpcp_option('seofriendlyurls')) { if (get_option('permalink_structure')) { $url = sprintf("%s/%s/%s", $base_url, $ad_id, $title); $url = user_trailingslashit($url); } } if ($url === false) { $base_url = user_trailingslashit($base_url); $url = add_query_arg(array('i' => urlencode($ad_id)), $base_url); } return $url; }
function deletead($adid, $adkey, $editemail, $force = false, &$errors = array()) { $output = ''; $awpcppage = get_currentpagename(); $awpcppagename = sanitize_title($awpcppage, $post_ID = ''); $isadmin = checkifisadmin() || $force; if (get_awpcp_option('onlyadmincanplaceads') && $isadmin != 1) { $message = __("You do not have permission to perform the function you are trying to perform. Access to this page has been denied", "AWPCP"); $errors[] = $message; } else { global $wpdb, $nameofsite; $tbl_ads = $wpdb->prefix . "awpcp_ads"; $tbl_ad_photos = $wpdb->prefix . "awpcp_adphotos"; $savedemail = get_adposteremail($adid); if ($isadmin == 1 || strcasecmp($editemail, $savedemail) == 0) { $ad = AWPCP_Ad::find_by_id($adid); if ($ad && $ad->delete()) { if ($isadmin == 1 && is_admin()) { $message = __("The Ad has been deleted", "AWPCP"); return $message; } else { $message = __("Your Ad details and any photos you have uploaded have been deleted from the system", "AWPCP"); $errors[] = $message; } } else { if ($ad === null) { $errors[] = __("The specified Ad doesn't exists.", 'AWPCP'); } else { $errors[] = __("There was an error trying to delete the Ad. The Ad was not deleted.", 'AWPCP'); } } } else { $message = __("Problem encountered. Cannot complete request", "AWPCP"); $errors[] = $message; } } $output .= "<div id=\"classiwrapper\">"; $output .= awpcp_menu_items(); $output .= "<p>"; $output .= $message; $output .= "</p>"; $output .= "</div>"; return $output; }
/** * @since 3.2.2 */ public function find_by_id($ad_id) { return AWPCP_Ad::find_by_id($ad_id); }
function awpcp_get_ad_share_info($id) { global $wpdb; $ad = AWPCP_Ad::find_by_id($id); $info = array(); if (is_null($ad)) { return null; } $info['url'] = url_showad($id); $info['title'] = stripslashes($ad->ad_title); $info['description'] = strip_tags(stripslashes($ad->ad_details)); $info['description'] = str_replace("\n", " ", $info['description']); if (awpcp_utf8_strlen($info['description']) > 300) { $info['description'] = awpcp_utf8_substr($info['description'], 0, 300) . '...'; } $info['images'] = array(); $info['published-time'] = awpcp_datetime('Y-m-d', $ad->ad_postdate); $info['modified-time'] = awpcp_datetime('Y-m-d', $ad->ad_last_updated); $images = awpcp_media_api()->find_by_ad_id($ad->ad_id, array('enabled' => true)); foreach ($images as $image) { $info['images'][] = $image->get_url('large'); } return $info; }