meta = awpcp_meta(); $this->show_ad = new AWPCP_Show_Ad_Page(); $this->browse_ads = new AWPCP_BrowseAdsPage(); // fix for theme conflict with ThemeForest themes. new AWPCP_RawShortcode(); add_action('init', array($this, 'init')); } public function init() { // page shortcodes add_shortcode('AWPCPPLACEAD', array($this, 'place_ad')); add_shortcode('AWPCPEDITAD', array($this, 'edit_ad')); add_shortcode('AWPCP-RENEW-AD', array($this, 'renew_ad')); add_shortcode('AWPCPSEARCHADS', array($this, 'search_ads')); add_shortcode('AWPCPREPLYTOAD', array($this, 'reply_to_ad')); add_shortcode('AWPCPPAYMENTTHANKYOU', array($this, 'noop')); add_shortcode('AWPCPCANCELPAYMENT', array($this, 'noop')); add_shortcode( 'AWPCPBROWSECATS', array( $this->browse_ads, 'dispatch' ) ); add_shortcode('AWPCPBROWSEADS', array($this->browse_ads, 'dispatch')); add_shortcode('AWPCPSHOWAD', array( $this, 'show_ad' ) ); add_shortcode('AWPCPCLASSIFIEDSUI', 'awpcpui_homescreen'); add_shortcode('AWPCPLATESTLISTINGS', array($this, 'listings_shortcode')); add_shortcode('AWPCPRANDOMLISTINGS', array($this, 'random_listings_shortcode')); add_shortcode('AWPCPSHOWCAT', array($this, 'category_shortcode')); add_shortcode( 'AWPCPUSERLISTINGS', array( $this, 'user_listings_shortcode' ) ); add_shortcode( 'AWPCPBUYCREDITS', array( $this, 'buy_credits' ) ); add_action( 'wp_ajax_awpcp-flag-ad', array( $this, 'ajax_flag_ad' ) ); add_action( 'wp_ajax_nopriv_awpcp-flag-ad', array( $this, 'ajax_flag_ad' ) ); do_action('awpcp_setup_shortcode'); } public function noop() { return ''; } public function place_ad() { if ( ! isset( $this->output['place-ad'] ) ) { do_action('awpcp-shortcode', 'place-ad'); if ( ! isset( $this->place_ad_page ) ) { $this->place_ad_page = new AWPCP_Place_Ad_Page(); } $this->output['place-ad'] = $this->place_ad_page->dispatch(); } return $this->output['place-ad']; } public function edit_ad() { if ( ! isset( $this->output['edit-ad'] ) ) { do_action('awpcp-shortcode', 'edit-ad'); if ( ! isset( $this->edit_ad_page ) ) { $this->edit_ad_page = new AWPCP_EditAdPage(); } $this->output['edit-ad'] = $this->edit_ad_page->dispatch(); } return $this->output['edit-ad']; } public function renew_ad() { if (!isset($this->renew_ad_page)) $this->renew_ad_page = new AWPCP_RenewAdPage(); return is_null($this->renew_ad_page) ? '' : $this->renew_ad_page->dispatch(); } public function show_ad() { if ( ! isset( $this->output['show-ad'] ) ) { $this->output['show-ad'] = $this->show_ad->dispatch(); } return $this->output['show-ad']; } public function search_ads() { if ( ! isset( $this->output['search-ads'] ) ) { $page = new AWPCP_SearchAdsPage(); $this->output['search-ads'] = $page->dispatch(); } return $this->output['search-ads']; } public function reply_to_ad() { if ( ! isset( $this->output['reply-to-ad'] ) ) { do_action('awpcp-shortcode', 'reply-to-ad'); $page = new AWPCP_ReplyToAdPage(); $this->output['reply-to-ad'] = $page->dispatch(); } return $this->output['reply-to-ad']; } /** * @since 3.0.2 */ public function buy_credits() { static $output = null; if ( is_null( $output ) ) { $output = awpcp_buy_credits_page()->dispatch(); } return $output; } /* Shortcodes */ public function user_listings_shortcode( $attrs ) { wp_enqueue_script( 'awpcp' ); $attrs = shortcode_atts( array( 'user_id' => get_current_user_id(), 'menu' => true, 'limit' => null ), $attrs ); $user_id = absint( $attrs['user_id'] ); if ( $user_id === 0 ) { return ''; } $query = array( 'context' => 'public-listings', 'limit' => absint( $attrs['limit'] ), 'user_id' => $user_id, ); $options = array( 'show_menu_items' => awpcp_parse_bool( $attrs['menu'] ) ); return awpcp_display_listings( $query, 'user-listings-shortcode', $options ); } public function listings_shortcode($attrs) { wp_enqueue_script('awpcp'); $default_attrs = array( 'menu' => true, 'pagination' => false, 'limit' => 10, ); $attrs = shortcode_atts( $default_attrs, $attrs ); $show_menu = awpcp_parse_bool($attrs['menu']); $show_pagination = awpcp_parse_bool( $attrs['pagination'] ); $limit = absint($attrs['limit']); $query = array( 'context' => 'public-listings', 'limit' => $limit, ); $options = array( 'show_menu_items' => $show_menu, 'show_pagination' => $show_pagination, ); return awpcp_display_listings( $query, 'latest-listings-shortcode', $options ); } public function random_listings_shortcode($attrs) { wp_enqueue_script('awpcp'); $attrs = shortcode_atts( array( 'category' => null, 'menu' => true, 'limit' => 10 ), $attrs ); $categories = array_filter( array_map( 'absint', explode( ',', $attrs['category'] ) ) ); $show_menu = awpcp_parse_bool($attrs['menu']); $limit = absint($attrs['limit']); $query = array( 'context' => 'public-listings', 'category_id' => $categories, 'orderby' => 'random', 'limit' => $limit, ); $options = array( 'show_menu_items' => $show_menu, ); return awpcp_display_listings( $query, 'random-listings-shortcode', $options ); } public function category_shortcode( $attrs ) { wp_enqueue_script('awpcp'); $cache_key = crc32( maybe_serialize( $attrs ) ); if ( ! isset( $this->output[ $cache_key ] ) ) { $this->output[ $cache_key ] = awpcp_category_shortcode()->render( $attrs ); } return $this->output[ $cache_key ]; } /* Ajax handlers */ 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(); } } // Set Home Screen function awpcpui_homescreen() { global $classicontent; $awpcppagename = sanitize_title( get_currentpagename() ); if (!isset($classicontent) || empty($classicontent)) { $classicontent=awpcpui_process($awpcppagename); } return $classicontent; } function awpcpui_process($awpcppagename) { global $hasrssmodule, $hasregionsmodule, $awpcp_plugin_url; $output = ''; $awpcppage = get_currentpagename(); if (!isset($awpcppagename) || empty($awpcppagename)) { $awpcppagename = sanitize_title($awpcppage, $post_ID=''); } $layout = get_query_var('layout'); $isadmin=checkifisadmin(); awpcp_enqueue_main_script(); $isclassifiedpage = checkifclassifiedpage($awpcppage); if (($isclassifiedpage == false) && ($isadmin == 1)) { $output .= __("Hi admin, you need to go to your dashboard and setup your classifieds.", 'another-wordpress-classifieds-plugin'); } elseif (($isclassifiedpage == false) && ($isadmin != 1)) { $output .= __("You currently have no classifieds", 'another-wordpress-classifieds-plugin'); } elseif ($layout == 2) { $output .= awpcp_display_the_classifieds_page_body($awpcppagename); } else { $output .= awpcp_load_classifieds($awpcppagename); } return $output; } function awpcp_load_classifieds($awpcppagename) { if (get_awpcp_option('main_page_display') == 1) { $query = array( 'context' => 'public-listings', '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, 'main-page' ); } else { $output = awpcp_display_the_classifieds_page_body( $awpcppagename ); } return $output; } // START FUNCTION: show the classifieds page body function awpcp_display_the_classifieds_page_body($awpcppagename) { global $hasregionsmodule; $output = ''; if (!isset($awpcppagename) || empty($awpcppagename)) { $awpcppage=get_currentpagename(); $awpcppagename = sanitize_title($awpcppage, $post_ID=''); } $output .= "