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;
         }
     }
 }
Esempio n. 2
0
/**
 * 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;
}
Esempio n. 3
0
/**
 * Renders each listing using the layout configured in the plugin
 * settings.
 *
 * @since 3.3.2
 *
 * @param Array $listings An array of AWPCP_Ad objects.
 * @param string $context The context where the listings will be shown: listings, ?.
 * @return Array An array of rendered items.
 */
function awpcp_render_listings_items($listings, $context)
{
    $parity = array('displayaditemseven', 'displayaditemsodd');
    $layout = get_awpcp_option('displayadlayoutcode');
    if (empty($layout)) {
        $layout = awpcp()->settings->get_option_default_value('displayadlayoutcode');
    }
    $items = array();
    foreach ($listings 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);
        }
        $items[] = apply_filters('awpcp-render-listing-item', $rendered_listing, $i + 1);
    }
    return $items;
}