*/ class UsersWP_GeoDirectory_Plugin { private static $instance; public static function get_instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_GeoDirectory_Plugin ) ) { self::$instance = new UsersWP_GeoDirectory_Plugin; self::$instance->setup_globals(); self::$instance->includes(); self::$instance->setup_actions(); } return self::$instance; } private function __construct() { self::$instance = $this; } private function setup_globals() { } private function setup_actions() { if ( is_admin() ) { add_filter( 'uwp_display_form_title', array( $this, 'display_form_title' ), 10, 3 ); add_action( 'uwp_geodirectory_settings_main_tab_content', array( $this, 'main_tab_content' ), 10, 1 ); add_action( 'uwp_admin_sub_menus', array( $this, 'add_admin_gd_sub_menu' ), 10, 1 ); add_filter( 'uwp_settings_tabs', array( $this, 'add_gd_tab' ) ); add_filter( 'uwp_registered_settings', array( $this, 'add_gd_settings' ) ); add_filter( 'uwp_available_tab_items', array( $this, 'available_tab_items' ) ); } else { add_filter( 'uwp_profile_tabs', array( $this, 'add_profile_gd_tabs' ), 10, 3 ); add_action( 'uwp_profile_listings_tab_content', array( $this, 'add_profile_listings_tab_content' ) ); add_action( 'uwp_profile_reviews_tab_content', array( $this, 'add_profile_reviews_tab_content' ) ); add_action( 'uwp_profile_favorites_tab_content', array( $this, 'add_profile_favorites_tab_content' ) ); add_action( 'uwp_profile_invoices_tab_content', array( $this, 'add_profile_invoices_tab_content' ) ); add_action( 'uwp_profile_gd_listings_subtab_content', array( $this, 'gd_get_listings' ), 10, 2 ); add_action( 'uwp_profile_gd_reviews_subtab_content', array( $this, 'gd_get_reviews' ), 10, 2 ); add_action( 'uwp_profile_gd_favorites_subtab_content', array( $this, 'gd_get_favorites' ), 10, 2 ); //add_action( 'geodir_after_edit_post_link_on_listing', array( $this, 'geodir_add_post_status_author_page' ), 11 ); } add_filter( 'geodir_login_url', array( $this, 'get_gd_login_url' ), 10, 2 ); add_action( 'wp', array( $this, 'geodir_uwp_author_redirect' ) ); add_filter( 'geodir_post_status_is_author_page', array( $this, 'geodir_post_status_is_author_page' ) ); add_filter( 'gd_login_wid_login_placeholder', array( $this, 'gd_login_wid_login_placeholder' ) ); add_filter( 'gd_login_wid_login_name', array( $this, 'gd_login_wid_login_name' ) ); add_filter( 'gd_login_wid_login_pwd', array( $this, 'gd_login_wid_login_pwd' ) ); add_action( 'login_form', array( $this, 'gd_login_inject_nonce' ) ); add_filter( 'uwp_check_redirect_author_page', array( $this, 'check_redirect_author_page' ), 10, 1 ); add_filter( 'uwp_use_author_page_content', array( $this, 'skip_uwp_author_page' ), 10, 1 ); do_action( 'uwp_gd_setup_actions', $this ); } private function includes() { do_action( 'uwp_gd_include_files' ); if ( is_admin() ) { do_action( 'uwp_gd_include_admin_files' ); } } /** * Modifies the settings form title. * * @since 1.0.0 * @package userswp * * @param string $title Original title. * @param string $page admin.php?page=uwp_xxx. * @param string $active_tab active tab in that settings page. * * @return string Form title. */ public function display_form_title( $title, $page, $active_tab ) { if ( $page == 'uwp_geodirectory' && $active_tab == 'main' ) { $title = __( 'GeoDirectory Settings', 'userswp' ); } return $title; } /** * Prints the settings form. * * @since 1.0.0 * @package userswp * * @param string $form Setting form html. * * @return void */ public function main_tab_content( $form ) { echo $form; } /** * Adds the current userswp addon settings page menu as submenu. * * @since 1.0.0 * @package userswp * * @param callable $settings_page The function to be called to output the content for this page. * * @return void */ public function add_admin_gd_sub_menu( $settings_page ) { add_submenu_page( "userswp", __( 'GeoDirectory', 'userswp' ), __( 'GeoDirectory', 'userswp' ), 'manage_options', 'uwp_geodirectory', $settings_page ); } /** * Adds settings tabs for the current userswp addon. * * @since 1.0.0 * @package userswp * * @param array $tabs Existing tabs array. * * @return array Tabs array. */ public function add_gd_tab( $tabs ) { $tabs['uwp_geodirectory'] = array( 'main' => __( 'GeoDirectory', 'userswp' ), ); return $tabs; } /** * Registers form fields for the current userswp addon settings page. * * @since 1.0.0 * @package userswp * * @param array $uwp_settings Existing settings array. * * @return array Settings array. */ public function add_gd_settings( $uwp_settings ) { $gd_posttypes = $this->get_gd_posttypes(); $options = array( 'gd_settings_info' => array( 'id' => 'woo_settings_info', 'name' => __( 'Info', 'userswp' ), 'desc' => __( 'You can now add Listings, Reviews and Favorites tabs under UsersWP > Profile > Choose the tabs to display in Profile', 'userswp' ), 'type' => 'info', 'std' => '1', 'class' => 'uwp_label_inline', ), 'gd_profile_listings' => array( 'id' => 'gd_profile_listings', 'name' => __( 'CPT listings in Profile', 'userswp' ), 'desc' => __( 'Choose the post types to show listings tab in UsersWP Profile', 'userswp' ), 'multiple' => true, 'chosen' => true, 'type' => 'select', 'options' => $gd_posttypes, 'placeholder' => __( 'Select Post Types', 'userswp' ) ), 'gd_profile_reviews' => array( 'id' => 'gd_profile_reviews', 'name' => __( 'CPT reviews in Profile', 'userswp' ), 'desc' => __( 'Choose the post types to show reviews tab in UsersWP Profile', 'userswp' ), 'multiple' => true, 'chosen' => true, 'type' => 'select', 'options' => $gd_posttypes, 'placeholder' => __( 'Select Post Types', 'userswp' ) ), 'gd_profile_favorites' => array( 'id' => 'gd_profile_favorites', 'name' => __( 'CPT favorites in Profile', 'userswp' ), 'desc' => __( 'Choose the post types to show favorites tab in UsersWP Profile', 'userswp' ), 'multiple' => true, 'chosen' => true, 'type' => 'select', 'options' => $gd_posttypes, 'placeholder' => __( 'Select Post Types', 'userswp' ) ), 'geodir_uwp_link_listing' => array( 'id' => 'geodir_uwp_link_listing', 'name' => __( 'Redirect GD dashboard my listing link to UsersWP profile', 'userswp' ), 'desc' => __( 'If this option is selected, the my listing link from GD dashboard will redirect to listings tab of UsersWP profile.', 'userswp' ), 'type' => 'checkbox', 'std' => '0', 'class' => 'uwp_label_inline', ), 'geodir_uwp_link_favorite' => array( 'id' => 'geodir_uwp_link_favorite', 'name' => __( 'Redirect GD dashboard favorite link to UsersWP profile', 'userswp' ), 'desc' => __( 'If this option is selected, the favorite link from GD dashboard will redirect to favorites tab of UsersWP profile.', 'userswp' ), 'type' => 'checkbox', 'std' => '0', 'class' => 'uwp_label_inline', ), ); $uwp_settings['uwp_geodirectory'] = array( 'main' => apply_filters( 'uwp_settings_geodirectory', $options ), ); return $uwp_settings; } public function get_gd_posttypes() { $post_type_arr = array(); $post_types = geodir_get_posttypes( 'object' ); foreach ( $post_types as $key => $post_types_obj ) { $post_type_arr[$key] = $post_types_obj->labels->singular_name; } return $post_type_arr; } /** * Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting. * * @since 1.0.0 * @package userswp * * @param array $tabs_arr Existing tabs array. * * @return array Tabs array. */ public function available_tab_items( $tabs_arr ) { $tabs_arr['listings'] = __( 'Listings', 'userswp' ); $tabs_arr['reviews'] = __( 'Reviews', 'userswp' ); $tabs_arr['favorites'] = __( 'Favorites', 'userswp' ); if ( class_exists( 'WPInv_Invoice' ) ) { $tabs_arr['invoices'] = __( 'Invoices', 'userswp' ); } return $tabs_arr; } public function geodir_get_reviews_by_user_id($post_type = 'gd_place', $user_id, $count_only = false, $offset = 0, $limit = 20) { global $wpdb; if ($count_only) { $results = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE user_id = %d AND post_type = %s AND status=1 AND overall_rating>0", array($user_id, $post_type) ) ); } else { $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . GEODIR_REVIEW_TABLE . " WHERE user_id = %d AND post_type = %s AND status=1 AND overall_rating>0 LIMIT %d OFFSET %d", array($user_id, $post_type, $limit, $offset ) ) ); } if (!empty($results)) return $results; else return false; } public function geodir_count_favorite( $post_type, $user_id = 0 ) { global $wpdb; $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : ''; if ( $user_id && $user_id == get_current_user_id() ) { $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private'"; } $user_fav_posts = geodir_get_user_favourites( (int)$user_id ); $user_fav_posts = !empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1"; $count = (int)$wpdb->get_var( "SELECT count( ID ) FROM ".$wpdb->posts." WHERE " . $wpdb->posts . ".ID IN ('" . $user_fav_posts . "') AND post_type='" . $post_type . "' AND ( post_status = 'publish' " . $post_status . " )" ); return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id ); } public function get_listings_count($post_type, $user_id = 0) { global $wpdb; if (empty($user_id)) { return 0; } $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : ''; if ($user_id && $user_id == get_current_user_id()) { $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private'"; } $count = (int)$wpdb->get_var("SELECT count( ID ) FROM " . $wpdb->prefix . "posts WHERE post_author=" . (int)$user_id . " AND post_type='" . $post_type . "' AND ( post_status = 'publish' " . $post_status . " )"); return apply_filters('geodir_uwp_count_total', $count, $user_id); } public function get_total_listings_count($user_id = 0) { if (empty($user_id)) { return 0; } $gd_post_types = geodir_get_posttypes('array'); if (empty($gd_post_types)) { return 0; } // allowed post types $listing_post_types = uwp_get_option('gd_profile_listings', array()); if (!is_array($listing_post_types)) { $listing_post_types = array(); } $count = 0; $total_count = 0; foreach ($listing_post_types as $post_type) { if (array_key_exists($post_type, $gd_post_types)) { // get listing count $listing_count = $this->get_listings_count($post_type, $user_id); $total_count += $listing_count; $count++; } } return $total_count; } public function get_total_reviews_count($user_id = 0) { if (empty($user_id)) { return 0; } $gd_post_types = geodir_get_posttypes('array'); if (empty($gd_post_types)) { return 0; } // allowed post types $listing_post_types = uwp_get_option('gd_profile_reviews', array()); if (!is_array($listing_post_types)) { $listing_post_types = array(); } $count = 0; $total_count = 0; foreach ($listing_post_types as $post_type) { if (array_key_exists($post_type, $gd_post_types)) { // get listing count $listing_count = $this->geodir_get_reviews_by_user_id($post_type, $user_id, true); $total_count += $listing_count; $count++; } } return $total_count; } public function get_total_favorites_count($user_id = 0) { if (empty($user_id)) { return 0; } $gd_post_types = geodir_get_posttypes('array'); if (empty($gd_post_types)) { return 0; } // allowed post types $listing_post_types = uwp_get_option('gd_profile_favorites', array()); if (!is_array($listing_post_types)) { $listing_post_types = array(); } $count = 0; $total_count = 0; foreach ($listing_post_types as $post_type) { if (array_key_exists($post_type, $gd_post_types)) { // get listing count $listing_count = $this->geodir_count_favorite($post_type, $user_id); $total_count += $listing_count; $count++; } } return $total_count; } /** * Adds tab in user profile page. * * @since 1.0.0 * @package userswp * * @param array $tabs Existing tabs array. * @param object $user User object. * @param array $allowed_tabs Allowed tabs array. * * @return array Tabs array. */ function add_profile_gd_tabs($tabs, $user,$allowed_tabs) { // allowed post types $listing_post_types = uwp_get_option('gd_profile_listings', array()); if (!empty($listing_post_types) && in_array('listings', $allowed_tabs)) { $tabs['listings'] = array( 'title' => __('Listings', 'uwp-gd'), 'count' => $this->get_total_listings_count($user->ID) ); } $listing_post_types = uwp_get_option('gd_profile_reviews', array()); if (!empty($listing_post_types) && in_array('reviews', $allowed_tabs)) { $tabs['reviews'] = array( 'title' => __('Reviews', 'uwp-gd'), 'count' => $this->get_total_reviews_count($user->ID) ); } $listing_post_types = uwp_get_option('gd_profile_favorites', array()); if (!empty($listing_post_types) && in_array('favorites', $allowed_tabs) && (get_current_user_id() == $user->ID)) { $tabs['favorites'] = array( 'title' => __('Favorites', 'uwp-gd'), 'count' => $this->get_total_favorites_count($user->ID) ); } if (class_exists('WPInv_Invoice') && in_array('invoices', $allowed_tabs) && (get_current_user_id() == $user->ID)) { $tabs['invoices'] = array( 'title' => __('Invoices', 'uwp-gd'), 'count' => $this->invoice_count($user->ID) ); } return $tabs; } /** * Adds GD listings tab content. * * @since 1.0.0 * @package userswp * * @param object $user User object. * * @return void */ public function add_profile_listings_tab_content($user) { $this->profile_gd_subtabs_content($user, 'listings'); } /** * Adds GD reviews tab content. * * @since 1.0.0 * @package userswp * * @param object $user User object. * * @return void */ public function add_profile_reviews_tab_content($user) { $this->profile_gd_subtabs_content($user, 'reviews'); } /** * Adds GD Favorites tab content. * * @since 1.0.0 * @package userswp * * @param object $user User object. * * @return void */ public function add_profile_favorites_tab_content($user) { $this->profile_gd_subtabs_content($user, 'favorites'); } /** * Adds GD Invoices tab content. * * @since 1.0.0 * @package userswp * * @param object $user User object. * * @return void */ public function add_profile_invoices_tab_content($user) { $this->profile_gd_invoices_content($user); } public function profile_gd_subtabs($user, $type = 'listings') { $tabs = array(); $gd_post_types = geodir_get_posttypes('array'); if (empty($gd_post_types)) { return $tabs; } // allowed post types if ($type == 'listings') { $listing_post_types = uwp_get_option('gd_profile_listings', array()); } elseif ($type == 'reviews') { $listing_post_types = uwp_get_option('gd_profile_reviews', array()); } elseif ($type == 'favorites') { $listing_post_types = uwp_get_option('gd_profile_favorites', array()); } else { $listing_post_types = array(); } if (!is_array($listing_post_types)) { $listing_post_types = array(); } foreach ($listing_post_types as $post_type) { if (array_key_exists($post_type, $gd_post_types)) { $post_type_slug = $gd_post_types[$post_type]['has_archive']; if ($type == 'listings') { $count = uwp_post_count($user->ID, $post_type); } elseif ($type == 'reviews') { $count = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true); } elseif ($type == 'favorites') { $count = $this->geodir_count_favorite($post_type, $user->ID); } else { $count = 0; } if (empty($count)) { $count = 0; } $tabs[$post_type_slug] = array( 'title' => $gd_post_types[$post_type]['labels']['name'], 'count' => $count, 'ptype' => $post_type ); } } return apply_filters('uwp_profile_gd_tabs', $tabs, $user, $type); } public function profile_gd_subtabs_content($user, $type = 'listings') { $subtab = get_query_var('uwp_subtab'); $subtabs = $this->profile_gd_subtabs($user, $type); $active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : 'places'; if (!empty($subtabs)) { $subtab_keys = array_keys($subtabs); $post_type = $subtabs[$subtab_keys[0]]['ptype']; } else { $post_type = false; } ?>
".__('No Invoices Found', 'uwp-gd')."
"; } do_action('uwp_profile_pagination', $the_query->max_num_pages); ?>