protected function generate_html($template_type = '') { $post_ids = array(); foreach ($this->search_results['items'] as $item_id => $item_html) { $post_ids[] = $item_id; } $conditions = array(); $conditions[] = "ad_id IN ( " . implode(',', $post_ids) . " ) "; $args = array(); $ads = AWPCP_Ad::get_enabled_ads($args, $conditions); $parity = array('displayaditemseven', 'displayaditemsodd'); if ('ajax' == $template_type) { $layout = buddyboss_global_search_buffer_template_part('loop/' . $this->type, $template_type, false); } else { $layout = get_awpcp_option('displayadlayoutcode'); if (empty($layout)) { $layout = awpcp()->settings->get_option_default_value('displayadlayoutcode'); } } if (!empty($ads)) { foreach ($ads as $i => $listing) { $rendered_listing = awpcp_do_placeholders($listing, $layout, $context); $rendered_listing = str_replace("\$awpcpdisplayaditems", $parity[$i % 2], $rendered_listing); if (function_exists('awpcp_featured_ads')) { $rendered_listing = awpcp_featured_ad_class($listing->ad_id, $rendered_listing); } $rendered_listing = apply_filters('awpcp-render-listing-item', $rendered_listing, $i + 1, $template_type); $result = array('id' => $listing->ad_id, 'type' => $this->type, 'title' => $listing->ad_title, 'html' => $rendered_listing); $this->search_results['items'][$listing->ad_id] = $result; } } }
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 (!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 static function delete($id, &$errors) { global $wpdb; $plan = self::find_by_id($id); if (is_null($plan)) { $errors[] = __("The Fee doesn't exist.", 'AWPCP'); return false; } $where = "adterm_id = %d AND payment_term_type = 'fee'"; $ads = AWPCP_Ad::find($wpdb->prepare($where, $id)); if (!empty($ads)) { $errors[] = __("The Fee can't be deleted because there are active Ads in the system that are associated with the Fee ID.", 'AWPCP'); return false; } $query = 'DELETE FROM ' . AWPCP_TABLE_ADFEES . ' WHERE adterm_id = %d'; $result = $wpdb->query($wpdb->prepare($query, $id)); return $result !== false; }
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); } }
/** * 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); }
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.0.2 */ function awpcp_clean_up_non_verified_ads($listings, $settings) { global $wpdb; if (!$settings->get_option('enable-email-verification')) { return; } $resend_email_threshold = $settings->get_option('email-verification-first-threshold'); $delete_ads_threshold = $settings->get_option('email-verification-second-threshold'); // delete Ads that have been in a non-verified state for more than M days $conditions = AWPCP_Ad::get_where_conditions_for_successfully_paid_listings(array('verified = 0', $wpdb->prepare('ad_postdate < ADDDATE( NOW(), INTERVAL -%d DAY )', $delete_ads_threshold))); foreach (AWPCP_Ad::find(join(' AND ', $conditions)) as $ad) { $ad->delete(); } // re-send verificaiton email for Ads that have been in a non-verified state for more than N days $conditions = AWPCP_Ad::get_where_conditions_for_successfully_paid_listings(array('verified = 0', $wpdb->prepare('ad_postdate < ADDDATE( NOW(), INTERVAL -%d DAY )', $resend_email_threshold))); foreach (AWPCP_Ad::find(join(' AND ', $conditions)) as $ad) { if (intval(awpcp_get_ad_meta($ad->ad_id, 'verification_emails_sent', true)) <= 1) { $listings->send_verification_email($ad); } } }
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'); }
/** * 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; }
public function handle_clear_cache_event_hook($ad_id) { $this->clear_ad_cache(AWPCP_Ad::find_by_id($ad_id)); }
public function delete() { $id = awpcp_request_param('id', 0); $fee = AWPCP_Fee::find_by_id($id); if (is_null($fee)) { awpcp_flash(__("The specified Fee doesn't exists.", 'AWPCP'), 'error'); return $this->index(); } $errors = array(); if (AWPCP_Fee::delete($fee->id, $errors)) { awpcp_flash(__('The Fee was successfully deleted.', 'AWPCP')); } else { $where = sprintf("adterm_id = %d AND payment_term_type = 'fee'", $fee->id); $ads = AWPCP_Ad::find($where); if (empty($ads)) { foreach ($errors as $error) { awpcp_flash($error, 'error'); } } else { $fees = AWPCP_Fee::query(); if (count($fees) > 1) { $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. You need to switch the Ads to a different Fee before you can delete the plan.", "AWPCP"); awpcp_flash($message, 'error'); $params = array('fee' => $fee, 'fees' => $fees); $template = AWPCP_DIR . '/admin/templates/admin-panel-fees-delete.tpl.php'; echo $this->render($template, $params); return; } else { $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. Please create a new Fee and try the delete operation again. AWPCP will help you to switch existing Ads to the new fee.", "AWPCP"); awpcp_flash($message, 'error'); } } } return $this->index(); }
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; }
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 send_access_key_step() { global $wpdb; $errors = array(); $form = array('ad_email' => awpcp_post_param('ad_email'), 'attempts' => (int) awpcp_post_param('attempts', 0)); if ($form['attempts'] == 0 && get_awpcp_option('enable-user-panel') == 1) { $url = admin_url('admin.php?page=awpcp-panel'); $message = __('You are currently not logged in, if you have an account in this website you can log in and go to the Ad Management panel to edit your Ads.', 'AWPCP'); $message = sprintf('%s <a href="%s">%s</a>', $message, $url, __('Click here', 'AWPCP')); $this->messages[] = $message; } if (empty($form['ad_email'])) { $errors['ad_email'] = __('Please enter the email address you used when you created your Ad.', 'AWPCP'); } else { if (!is_email($form['ad_email'])) { $errors['ad_email'] = __('Please enter a valid email address.', 'AWPCP'); } } $ads = array(); if (empty($errors)) { $ads = AWPCP_Ad::find_by_email($form['ad_email']); if (empty($ads)) { $errors[] = __('The email address you entered does not match any of the Ads in our system.', 'AWPCP'); } } else { if ($form['attempts'] == 0) { $errors = array(); } } // if $ads is non-empty then $errors is empty if (!empty($ads)) { $access_keys_sent = $this->send_access_keys($ads, $errors); } else { $access_keys_sent = false; } if (!$access_keys_sent) { $send_access_key_url = add_query_arg(array('step' => 'send-access-key'), $this->url()); $messages = $this->messages; $hidden = array('attempts' => $form['attempts'] + 1); $params = compact('form', 'hidden', 'messages', 'errors', 'send_access_key_url'); $template = AWPCP_DIR . '/frontend/templates/page-edit-ad-send-access-key-step.tpl.php'; return $this->render($template, $params); } else { return $this->enter_email_and_key_step(false); } }
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; }
/** * Handles AWPCPSHOWAD shortcode. * * @param $adid An Ad ID. * @param $omitmenu * @param $preview true if the function is used to show an ad just after * it was posted to the website. * @param $send_email if true and $preview=true, a success email will be send * to the admin and poster user. * * @return Show Ad page content. */ function showad($adid = null, $omitmenu = false, $preview = false, $send_email = true, $show_messages = true) { global $wpdb; awpcp_maybe_add_thickbox(); wp_enqueue_script('awpcp-page-show-ad'); $awpcp = awpcp(); $awpcp->js->set('page-show-ad-flag-ad-nonce', wp_create_nonce('flag_ad')); $awpcp->js->localize('page-show-ad', array('flag-confirmation-message' => __('Are you sure you want to flag this ad?', 'AWPCP'), 'flag-success-message' => __('This Ad has been flagged.', 'AWPCP'), 'flag-error-message' => __('An error occurred while trying to flag the Ad.', 'AWPCP'))); $preview = $preview === true || 'preview' == awpcp_array_data('adstatus', '', $_GET); $is_moderator = awpcp_current_user_is_moderator(); $messages = array(); $permastruc = get_option('permalink_structure'); if (!isset($adid) || empty($adid)) { if (isset($_REQUEST['adid']) && !empty($_REQUEST['adid'])) { $adid = $_REQUEST['adid']; } elseif (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $adid = $_REQUEST['id']; } else { if (isset($permastruc) && !empty($permastruc)) { $adid = get_query_var('id'); } else { $adid = 0; } } } $adid = absint($adid); if (!empty($adid)) { // filters to provide alternative method of storing custom // layouts (e.g. can be outside of this plugin's directory) $prefix = 'awpcp_single_ad_template'; if (has_action("{$prefix}_action") || has_filter("{$prefix}_filter")) { do_action("{$prefix}_action"); return apply_filters("{$prefix}_filter"); } else { $results = AWPCP_Ad::query(array('where' => $wpdb->prepare('ad_id = %d', $adid))); if (count($results) === 1) { $ad = array_shift($results); } else { $ad = null; } if (is_null($ad)) { $message = __('Sorry, that listing is not available. Please try browsing or searching existing listings.', 'AWPCP'); return '<div id="classiwrapper">' . awpcp_print_error($message) . '</div><!--close classiwrapper-->'; } if ($ad->user_id > 0 && $ad->user_id == wp_get_current_user()->ID) { $is_ad_owner = true; } else { $is_ad_owner = false; } $content_before_page = apply_filters('awpcp-content-before-listing-page', ''); $content_after_page = apply_filters('awpcp-content-after-listing-page', ''); $output = '<div id="classiwrapper">%s%s<!--awpcp-single-ad-layout-->%s</div><!--close classiwrapper-->'; $output = sprintf($output, $content_before_page, $omitmenu ? '' : awpcp_menu_items(), $content_after_page); if (!$is_moderator && !$is_ad_owner && !$preview && $ad->disabled == 1) { $message = __('The Ad you are trying to view is pending approval. Once the Administrator approves it, it will be active and visible.', 'AWPCP'); return str_replace('<!--awpcp-single-ad-layout-->', awpcp_print_error($message), $output); } if (awpcp_request_param('verified') && $ad->verified) { $messages[] = awpcp_print_message(__('Your email address was successfully verified.', 'AWPCP')); } if ($show_messages && $is_moderator && $ad->disabled == 1) { $message = __('This Ad is currently disabled until the Administrator approves it. Only you (the Administrator) and the author can see it.', 'AWPCP'); $messages[] = awpcp_print_error($message); } else { if ($show_messages && ($is_ad_owner || $preview) && !$ad->verified) { $message = __('This Ad is currently disabled until you verify the email address used for the contact information. Only you (the author) can see it.', 'AWPCP'); $messages[] = awpcp_print_error($message); } else { if ($show_messages && ($is_ad_owner || $preview) && $ad->disabled == 1) { $message = __('This Ad is currently disabled until the Administrator approves it. Only you (the author) can see it.', 'AWPCP'); $messages[] = awpcp_print_error($message); } } } $layout = awpcp_get_listing_single_view_layout($ad); $layout = awpcp_do_placeholders($ad, $layout, 'single'); $output = str_replace('<!--awpcp-single-ad-layout-->', join('', $messages) . $layout, $output); $output = apply_filters('awpcp-show-ad', $output, $adid); if (!awpcp_request()->is_bot()) { $ad->visit(); } $ad->save(); } } else { $query = array('limit' => absint(awpcp_request_param('results', get_awpcp_option('adresultsperpage', 10))), 'offset' => absint(awpcp_request_param('offset', 0)), 'orderby' => get_awpcp_option('groupbrowseadsby')); $output = awpcp_display_listings_in_page($query, 'show-listing'); } return $output; }
/** * @deprecated 3.4 */ function awpcp_display_ads($where, $byl, $hidepager, $grouporderby, $adorcat, $before_content = '') { _deprecated_function(__FUNCTION__, '3.4', 'awpcp_display_listings'); global $wpdb; global $awpcp_plugin_path; global $hasregionsmodule; $output = ''; $awpcp_browsecats_pageid = awpcp_get_page_id_by_ref('browse-categories-page-name'); $browseadspageid = awpcp_get_page_id_by_ref('browse-ads-page-name'); $searchadspageid = awpcp_get_page_id_by_ref('search-ads-page-name'); // filters to provide alternative method of storing custom layouts (e.g. can be outside of this plugin's directory) if (has_action('awpcp_browse_ads_template_action') || has_filter('awpcp_browse_ads_template_filter')) { do_action('awpcp_browse_ads_template_action'); $output = apply_filters('awpcp_browse_ads_template_filter'); return; } else { if (file_exists("{$awpcp_plugin_path}/awpcp_display_ads_my_layout.php") && get_awpcp_option('activatemylayoutdisplayads')) { include "{$awpcp_plugin_path}/awpcp_display_ads_my_layout.php"; } else { $output .= "<div id=\"classiwrapper\">"; $uiwelcome = stripslashes_deep(get_awpcp_option('uiwelcome')); $output .= apply_filters('awpcp-content-before-listings-page', ''); $output .= "<div class=\"uiwelcome\">{$uiwelcome}</div>"; $output .= awpcp_menu_items(); if ($hasregionsmodule == 1) { // Do not show Region Control form when showing Search Ads page // search result. Changing the current location will redirect the user // to the form instead of a filterd version of the form and that's confusing if (is_page(awpcp_get_page_id_by_ref('search-ads-page-name')) && isset($_POST['a']) && $_POST['a'] == 'dosearch') { // do nothing } else { $output .= awpcp_region_control_selector(); } } $output .= $before_content; $tbl_ads = $wpdb->prefix . "awpcp_ads"; $from = "{$tbl_ads}"; $ads_exist = ads_exist(); if (!$ads_exist) { $showcategories = "<p style=\"padding:10px\">"; $showcategories .= __("There are currently no ads in the system", "AWPCP"); $showcategories .= "</p>"; $pager1 = ''; $pager2 = ''; } else { $awpcp_image_display_list = array(); if ($adorcat == 'cat') { $tpname = get_permalink($awpcp_browsecats_pageid); } elseif ($adorcat == 'search') { $tpname = get_permalink($searchadspageid); } elseif (preg_match('/^custom:/', $adorcat)) { $tpname = str_replace('custom:', '', $adorcat); } else { $tpname = get_permalink($browseadspageid); } $results = get_awpcp_option('adresultsperpage', 10); $results = absint(awpcp_request_param('results', $results)); $offset = absint(awpcp_request_param('offset', 0)); if ($results === 0) { $results = 10; } $args = array('order' => AWPCP_Ad::get_order_conditions($grouporderby), 'offset' => $offset, 'limit' => $results); $ads = AWPCP_Ad::get_enabled_ads($args, array($where)); // get_where_conditions() is called from get_enabled_ads(), we need the // WHERE conditions here to pass them to create_pager() $where = AWPCP_Ad::get_where_conditions(array($where)); if (!isset($hidepager) || empty($hidepager)) { //Unset the page and action here...these do the wrong thing on display ad unset($_GET['page_id']); unset($_POST['page_id']); //unset($params['page_id']); $pager1 = create_pager($from, join(' AND ', $where), $offset, $results, $tpname); $pager2 = create_pager($from, join(' AND ', $where), $offset, $results, $tpname); } else { $pager1 = ''; $pager2 = ''; } $items = awpcp_render_listings_items($ads, 'listings'); $opentable = ""; $closetable = ""; if (empty($ads)) { $showcategories = "<p style=\"padding:20px;\">"; $showcategories .= __("There were no ads found", "AWPCP"); $showcategories .= "</p>"; $pager1 = ''; $pager2 = ''; } else { $showcategories = smart_table($items, intval($results / $results), $opentable, $closetable); } } $show_category_id = absint(awpcp_request_param('category_id')); if (!isset($url_browsecatselect) || empty($url_browsecatselect)) { $url_browsecatselect = get_permalink($awpcp_browsecats_pageid); } if ($ads_exist) { $category_id = (int) awpcp_request_param('category_id', -1); $category_id = $category_id === -1 ? (int) get_query_var('cid') : $category_id; $output .= "<div class=\"changecategoryselect\"><form method=\"post\" action=\"{$url_browsecatselect}\">"; $output .= '<div class="awpcp-category-dropdown-container">'; $dropdown = new AWPCP_CategoriesDropdown(); $output .= $dropdown->render(array('context' => 'search', 'name' => 'category_id', 'selected' => $category_id)); $output .= '</div>'; $output .= "<input type=\"hidden\" name=\"a\" value=\"browsecat\" /> <input class=\"button\" type=\"submit\" value=\""; $output .= __("Change Category", "AWPCP"); $output .= "\" /></form></div>"; $output .= "<div class=\"pager\">{$pager1}</div><div class=\"fixfloat\"></div>"; $output .= "<div id='awpcpcatname' class=\"fixfloat\">"; if ($category_id > 0) { $output .= "<h3>" . __("Category: ", "AWPCP") . get_adcatname($category_id) . "</h3>"; } $output .= "</div>"; } $output .= apply_filters('awpcp-display-ads-before-list', ''); $output .= "{$showcategories}"; if ($ads_exist) { $output .= " <div class=\"pager\">{$pager2}</div>"; } $output .= apply_filters('awpcp-content-after-listings-page', ''); $output .= "</div>"; } } return $output; }
/** * @since 3.0 */ function awpcp_do_placeholder_location($ad, $placeholder) { $regions = AWPCP_Ad::get_ad_regions_names($ad->ad_id); $cities = array(); $states = array(); $villages = array(); $countries = array(); $places = array(); if (get_awpcp_option('show-city-field-before-county-field')) { $order = array('country', 'state', 'city', 'county'); } else { $order = array('country', 'state', 'county', 'city'); } foreach ($regions as $region) { if (!empty($region['city'])) { $cities[] = stripslashes_deep($region['city']); } if (!empty($region['county'])) { $villages[] = stripslashes_deep($region['county']); } if (!empty($region['state'])) { $states[] = stripslashes_deep($region['state']); } if (!empty($region['country'])) { $countries[] = stripslashes_deep($region['country']); } $place = array(); foreach ($order as $field) { if (!empty($region[$field])) { $place[] = stripslashes_deep($region[$field]); } } $places[] = $place; } if (!empty($cities)) { $replacements['city'] = join(', ', $cities); } if (!empty($states)) { $replacements['state'] = join(', ', $states); } if (!empty($villages)) { $replacements['county'] = join(', ', $villages); $replacements['village'] = $replacements['county']; } if (!empty($countries)) { $replacements['country'] = join(', ', $countries); } $location = array(); foreach ($places as $place) { $location[] = join(', ', $place); } $location = join('; ', $location); if (!empty($location)) { $replacements['location'] = sprintf('<br/><label>%s</label>: %s', __('Location', 'AWPCP'), $location); $replacements['region'] = $location; } else { $replacements['location'] = ''; $replacements['region'] = ''; } if (!empty($replacements['city'])) { $replacements['awpcp_city_display'] = sprintf('%s<br/>', $replacements['city']); } else { $replacements['awpcp_city_display'] = ''; } if (!empty($replacements['state'])) { $replacements['awpcp_state_display'] = sprintf('%s<br/>', $replacements['state']); } else { $replacements['awpcp_state_display'] = ''; } if (!empty($replacements['country'])) { $replacements['awpcp_country_display'] = sprintf('%s<br/>', $replacements['country']); } else { $replacements['awpcp_country_display'] = ''; } return $replacements[$placeholder]; }
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); }
/** * @since 3.0.0 */ public function get_access_key() { if (empty($this->ad_key)) { $this->ad_key = AWPCP_Ad::generate_key(); $this->save(); } return $this->ad_key; }
/** * @since 3.3 */ private function count_valid_listings($conditions = array()) { $conditions = AWPCP_Ad::get_where_conditions_for_valid_ads($conditions); return AWPCP_Ad::count(implode(' AND ', $conditions)); }
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; }