PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.74
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.74
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
← All changes | includes/libraries/class-geodirectory-plugin.php +2049 -1016 1.0.211.2.74 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * GeoDirectory plugin related functions
4 5 *
5 6 * This class defines all code necessary for GeoDirectory plugin.
@@ -7,1209 +8,2241 @@
7 8 * @since 1.0.0
8 9 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 10 */
10 11 class UsersWP_GeoDirectory_Plugin {
11 - private static $instance;
12 + private static $instance;
12 13
13 - public static function get_instance() {
14 - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_GeoDirectory_Plugin ) ) {
15 - self::$instance = new UsersWP_GeoDirectory_Plugin;
16 - self::$instance->setup_globals();
17 - self::$instance->includes();
18 - self::$instance->setup_actions();
19 - }
14 + private function __construct() {
15 + self::$instance = $this;
16 + }
20 17
21 - return self::$instance;
22 - }
18 + public static function get_instance() {
19 + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_GeoDirectory_Plugin ) ) {
20 + self::$instance = new UsersWP_GeoDirectory_Plugin;
21 + self::$instance->setup_actions();
22 + }
23 23
24 - private function __construct() {
25 - self::$instance = $this;
26 - }
24 + return self::$instance;
25 + }
27 26
28 - private function setup_globals() {
29 -
30 - }
31 -
32 - private function setup_actions() {
33 - if ( is_admin() ) {
34 - add_filter( 'uwp_display_form_title', array( $this, 'display_form_title' ), 10, 3 );
35 - add_action( 'uwp_geodirectory_settings_main_tab_content', array( $this, 'main_tab_content' ), 10, 1 );
36 - add_action( 'uwp_admin_sub_menus', array( $this, 'add_admin_gd_sub_menu' ), 10, 1 );
37 - add_filter( 'uwp_settings_tabs', array( $this, 'add_gd_tab' ) );
38 - add_filter( 'uwp_registered_settings', array( $this, 'add_gd_settings' ) );
39 - add_filter( 'uwp_available_tab_items', array( $this, 'available_tab_items' ) );
40 - } else {
41 - add_filter( 'uwp_profile_tabs', array( $this, 'add_profile_gd_tabs' ), 10, 3 );
42 - add_action( 'uwp_profile_listings_tab_content', array( $this, 'add_profile_listings_tab_content' ) );
43 - add_action( 'uwp_profile_reviews_tab_content', array( $this, 'add_profile_reviews_tab_content' ) );
44 - add_action( 'uwp_profile_favorites_tab_content', array( $this, 'add_profile_favorites_tab_content' ) );
45 - add_action( 'uwp_profile_gd_listings_subtab_content', array( $this, 'gd_get_listings' ), 10, 2 );
46 - add_action( 'uwp_profile_gd_reviews_subtab_content', array( $this, 'gd_get_reviews' ), 10, 2 );
47 - add_action( 'uwp_profile_gd_favorites_subtab_content', array( $this, 'gd_get_favorites' ), 10, 2 );
48 - add_action( 'geodir_after_edit_post_link_on_listing', array( $this, 'geodir_add_post_status_author_page' ), 11 );
49 - }
50 - add_filter( 'geodir_login_url', array( $this, 'get_gd_login_url' ), 10, 2 );
51 - add_action( 'wp', array( $this, 'geodir_uwp_author_redirect' ) );
52 - add_filter( 'geodir_post_status_is_author_page', array( $this, 'geodir_post_status_is_author_page' ) );
53 - add_filter( 'gd_login_wid_login_placeholder', array( $this, 'gd_login_wid_login_placeholder' ) );
54 - add_filter( 'gd_login_wid_login_name', array( $this, 'gd_login_wid_login_name' ) );
55 - add_filter( 'gd_login_wid_login_pwd', array( $this, 'gd_login_wid_login_pwd' ) );
56 - add_action( 'login_form', array( $this, 'gd_login_inject_nonce' ) );
57 - add_filter( 'uwp_check_redirect_author_page', array( $this, 'check_redirect_author_page' ), 10, 1 );
58 - add_filter( 'uwp_use_author_page_content', array( $this, 'skip_uwp_author_page' ), 10, 1 );
27 + private function setup_actions() {
28 + if ( is_admin() ) {
29 + add_filter( 'uwp_get_sections_uwp-addons', array( $this, 'add_gd_tab' ) );
30 + add_filter( 'uwp_get_settings_uwp-addons', array( $this, 'add_gd_settings' ), 10, 2 );
31 + add_filter( 'uwp_profile_tabs_predefined_fields', array(
32 + $this,
33 + 'add_profile_tabs_predefined_fields'
34 + ), 10, 2 );
35 + } else {
36 + add_action( 'uwp_profile_listings_tab_content', array( $this, 'add_profile_listings_tab_content' ) );
37 + add_action( 'uwp_profile_reviews_tab_content', array( $this, 'add_profile_reviews_tab_content' ) );
38 + add_action( 'uwp_profile_favorites_tab_content', array( $this, 'add_profile_favorites_tab_content' ) );
39 + add_action( 'uwp_profile_lists_tab_content', array( $this, 'add_profile_gd_lists_tab_content' ) );
40 + add_action( 'uwp_profile_gd_listings_subtab_content', array( $this, 'gd_get_listings' ), 10, 2 );
41 + add_action( 'uwp_profile_gd_reviews_subtab_content', array( $this, 'gd_get_reviews' ), 10, 2 );
42 + add_action( 'uwp_profile_gd_favorites_subtab_content', array( $this, 'gd_get_favorites' ), 10, 2 );
43 + add_action( 'geodir_after_edit_post_link_on_listing', array(
44 + $this,
45 + 'geodir_add_post_status_author_page'
46 + ), 11 );
47 + add_action( 'uwp_dashboard_links', array( $this, 'dashboard_output' ), 10, 2 );
48 + }
49 + add_filter( 'geodir_login_url', array( $this, 'get_gd_login_url' ), 10, 2 );
50 + add_action( 'wp', array( $this, 'geodir_uwp_author_redirect' ) );
51 + add_filter( 'geodir_post_status_is_author_page', array( $this, 'geodir_post_status_is_author_page' ) );
52 + add_filter( 'gd_login_wid_login_placeholder', array( $this, 'gd_login_wid_login_placeholder' ) );
53 + add_filter( 'gd_login_wid_login_name', array( $this, 'gd_login_wid_login_name' ) );
54 + add_filter( 'gd_login_wid_login_pwd', array( $this, 'gd_login_wid_login_pwd' ) );
55 + add_action( 'login_form', array( $this, 'gd_login_inject_nonce' ) );
56 + add_filter( 'uwp_check_redirect_author_page', array( $this, 'check_redirect_author_page' ), 10, 1 );
57 + add_filter( 'uwp_use_author_page_content', array( $this, 'skip_uwp_author_page' ), 10, 1 );
58 + add_filter( 'geodir_dashboard_link_favorite_listing', array( $this, 'dashboard_favorite_links' ), 10, 3 );
59 + add_filter( 'geodir_dashboard_link_my_listing', array( $this, 'dashboard_listing_links' ), 10, 3 );
60 + add_filter( 'widget_post_author', array( $this, 'get_widget_post_author' ), 10, 3 );
61 + add_filter( 'widget_favorites_by_user', array( $this, 'get_widget_favorites_by_user' ), 10, 3 );
59 62
60 - do_action( 'uwp_gd_setup_actions', $this );
61 - }
63 + add_filter( 'uwp_tp_posts_post_footer', array( $this, 'posts_footer' ) );
64 + add_filter( 'uwp_tp_comments_item_footer', array( $this, 'reviews_footer' ), 10, 2 );
65 + add_action( 'uwp_profile_pagination', array( $this, 'unset_gd_post' ), 1 );
62 66
63 - private function includes() {
64 - do_action( 'uwp_gd_include_files' );
67 + add_filter( 'posts_join', array( $this, 'posts_join' ), 11, 2 );
68 + add_filter( 'get_usernumposts', array( $this, 'get_usernumposts' ), 11, 4 );
65 69
66 - if ( is_admin() ) {
67 - do_action( 'uwp_gd_include_admin_files' );
68 - }
69 - }
70 + do_action( 'uwp_gd_setup_actions', $this );
71 + }
70 72
71 - /**
72 - * Modifies the settings form title.
73 - *
74 - * @since 1.0.0
75 - * @package userswp
76 - *
77 - * @param string $title Original title.
78 - * @param string $page admin.php?page=uwp_xxx.
79 - * @param string $active_tab active tab in that settings page.
80 - *
81 - * @return string Form title.
82 - */
83 - public function display_form_title( $title, $page, $active_tab ) {
84 - if ( $page == 'uwp_geodirectory' && $active_tab == 'main' ) {
85 - $title = __( 'GeoDirectory Settings', 'userswp' );
86 - }
87 - return $title;
88 - }
89 -
90 - /**
91 - * Prints the settings form.
92 - *
93 - * @since 1.0.0
94 - * @package userswp
95 - *
96 - * @param string $form Setting form html.
97 - *
98 - * @return void
99 - */
100 - public function main_tab_content( $form ) {
101 - echo $form;
102 - }
103 -
104 - /**
105 - * Adds the current userswp addon settings page menu as submenu.
106 - *
107 - * @since 1.0.0
108 - * @package userswp
109 - *
110 - * @param callable $settings_page The function to be called to output the content for this page.
111 - *
112 - * @return void
113 - */
114 - public function add_admin_gd_sub_menu( $settings_page ) {
115 - add_submenu_page(
116 - "userswp",
117 - __( 'GeoDirectory', 'userswp' ),
118 - __( 'GeoDirectory', 'userswp' ),
119 - 'manage_options',
120 - 'uwp_geodirectory',
121 - $settings_page
122 - );
123 - }
73 + /**
74 + * Change the GD listing links to point to the new profile page.
75 + *
76 + * @param $link
77 + * @param $post_type
78 + * @param $user_id
79 + *
80 + * @return string
81 + */
82 + public function dashboard_listing_links( $link, $post_type, $user_id ) {
83 + $gd_post_types = geodir_get_posttypes( 'array' );
84 + $link = uwp_build_profile_tab_url( $user_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] );
124 85
125 - /**
126 - * Adds settings tabs for the current userswp addon.
127 - *
128 - * @since 1.0.0
129 - * @package userswp
130 - *
131 - * @param array $tabs Existing tabs array.
132 - *
133 - * @return array Tabs array.
134 - */
135 - public function add_gd_tab( $tabs ) {
136 - $tabs['uwp_geodirectory'] = array(
137 - 'main' => __( 'GeoDirectory', 'userswp' ),
138 - );
139 - return $tabs;
140 - }
86 + return $link;
87 + }
141 88
142 - /**
143 - * Registers form fields for the current userswp addon settings page.
144 - *
145 - * @since 1.0.0
146 - * @package userswp
147 - *
148 - * @param array $uwp_settings Existing settings array.
149 - *
150 - * @return array Settings array.
151 - */
152 - public function add_gd_settings( $uwp_settings ) {
153 - $gd_posttypes = $this->get_gd_posttypes();
89 + /**
90 + * Change the GD fav links to point to the new profile page.
91 + *
92 + * @param $link
93 + * @param $post_type
94 + * @param $user_id
95 + *
96 + * @return string
97 + */
98 + public function dashboard_favorite_links( $link, $post_type, $user_id ) {
99 + $gd_post_types = geodir_get_posttypes( 'array' );
100 + $link = uwp_build_profile_tab_url( $user_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] );
154 101
155 - $options = array(
156 - 'gd_settings_info' => array(
157 - 'id' => 'woo_settings_info',
158 - 'name' => __( 'Info', 'userswp' ),
159 - 'desc' => __( 'You can now add Listings, Reviews and Favorites tabs under UsersWP > Profile > Choose the tabs to display in Profile', 'userswp' ),
160 - 'type' => 'info',
161 - 'std' => '1',
162 - 'class' => 'uwp_label_inline',
163 - ),
164 - 'gd_profile_listings' => array(
165 - 'id' => 'gd_profile_listings',
166 - 'name' => __( 'CPT listings in Profile', 'userswp' ),
167 - 'desc' => __( 'Choose the post types to show listings tab in UsersWP Profile', 'userswp' ),
168 - 'multiple' => true,
169 - 'chosen' => true,
170 - 'type' => 'select',
171 - 'options' => $gd_posttypes,
172 - 'placeholder' => __( 'Select Post Types', 'userswp' )
173 - ),
174 - 'gd_profile_reviews' => array(
175 - 'id' => 'gd_profile_reviews',
176 - 'name' => __( 'CPT reviews in Profile', 'userswp' ),
177 - 'desc' => __( 'Choose the post types to show reviews tab in UsersWP Profile', 'userswp' ),
178 - 'multiple' => true,
179 - 'chosen' => true,
180 - 'type' => 'select',
181 - 'options' => $gd_posttypes,
182 - 'placeholder' => __( 'Select Post Types', 'userswp' )
183 - ),
184 - 'gd_profile_favorites' => array(
185 - 'id' => 'gd_profile_favorites',
186 - 'name' => __( 'CPT favorites in Profile', 'userswp' ),
187 - 'desc' => __( 'Choose the post types to show favorites tab in UsersWP Profile', 'userswp' ),
188 - 'multiple' => true,
189 - 'chosen' => true,
190 - 'type' => 'select',
191 - 'options' => $gd_posttypes,
192 - 'placeholder' => __( 'Select Post Types', 'userswp' )
193 - ),
194 - 'geodir_uwp_link_listing' => array(
195 - 'id' => 'geodir_uwp_link_listing',
196 - 'name' => __( 'Redirect my listing link from GD loginbox to UsersWP profile', 'userswp' ),
197 - 'desc' => __( 'If this option is selected, the my listing link from GD loginbox will redirect to listings tab of UsersWP profile.', 'userswp' ),
198 - 'type' => 'checkbox',
199 - 'std' => '0',
200 - 'class' => 'uwp_label_inline',
201 - ),
202 - 'geodir_uwp_link_favorite' => array(
203 - 'id' => 'geodir_uwp_link_favorite',
204 - 'name' => __( 'Redirect favorite link from GD loginbox to UsersWP profile', 'userswp' ),
205 - 'desc' => __( 'If this option is selected, the favorite link from GD loginbox will redirect to favorites tab of UsersWP profile.', 'userswp' ),
206 - 'type' => 'checkbox',
207 - 'std' => '0',
208 - 'class' => 'uwp_label_inline',
209 - ),
210 - );
102 + return $link;
103 + }
211 104
212 - $uwp_settings['uwp_geodirectory'] = array(
213 - 'main' => apply_filters( 'uwp_settings_geodirectory', $options ),
214 - );
105 + /**
106 + * Add GD quick links to the logged in Dashboard.
107 + *
108 + * @param $links
109 + * @param $args
110 + *
111 + * @return array
112 + */
113 + public function dashboard_output( $links, $args = array() ) {
215 114
216 - return $uwp_settings;
217 - }
115 + // check its not disabled
116 + if ( empty( $args['disable_gd'] ) && class_exists( 'GeoDir_User' ) ) {
117 + $user_id = get_current_user_id();
118 + // Add listing links
119 + $add_links = GeoDir_User::show_add_listings( 'array' );
120 + if ( ! empty( $add_links ) ) {
121 + $links['gd_add'] = array();
122 + $links['gd_add'][] = array(
123 + 'optgroup' => 'open',
124 + 'text' => defined( 'ADD_LISTING_TEXT' ) ? ADD_LISTING_TEXT : __( 'Add Listing', 'userswp' )
125 + );
126 + foreach ( $add_links as $add_link ) {
127 + $links['gd_add'][] = array(
128 + 'url' => $add_link['url'],
129 + 'text' => $add_link['text']
130 + );
131 + }
132 + $links['gd_add'][] = array(
133 + 'optgroup' => 'close',
134 + );
135 + }
218 136
219 - public function get_gd_posttypes() {
220 - $post_type_arr = array();
221 - $post_types = geodir_get_posttypes( 'object' );
137 + // My Favourites in Dashboard
138 + $fav_links = GeoDir_User::show_favourites( $user_id, 'array' );
139 + if ( ! empty( $fav_links ) ) {
140 + $links['gd_favs'] = array();
141 + $links['gd_favs'][] = array(
142 + 'optgroup' => 'open',
143 + 'text' => defined( 'MY_FAVOURITE_TEXT' ) ? MY_FAVOURITE_TEXT : __( 'My Favorites', 'userswp' )
144 + );
145 + foreach ( $fav_links as $fav_link ) {
146 + $links['gd_favs'][] = array(
147 + 'url' => $fav_link['url'],
148 + 'text' => $fav_link['text']
149 + );
150 + }
151 + $links['gd_favs'][] = array(
152 + 'optgroup' => 'close',
153 + );
154 + }
222 155
223 - foreach ( $post_types as $key => $post_types_obj ) {
224 - $post_type_arr[$key] = $post_types_obj->labels->singular_name;
225 - }
226 - return $post_type_arr;
227 - }
156 + // My Listings
157 + $listing_links = GeoDir_User::show_listings( $user_id, 'array' );
158 + if ( ! empty( $listing_links ) ) {
159 + $links['gd_listings'] = array();
160 + $links['gd_listings'][] = array(
161 + 'optgroup' => 'open',
162 + 'text' => defined( 'MY_LISTINGS_TEXT' ) ? MY_LISTINGS_TEXT : __( 'My Listings', 'userswp' )
163 + );
164 + foreach ( $listing_links as $listing_link ) {
165 + $links['gd_listings'][] = array(
166 + 'url' => $listing_link['url'],
167 + 'text' => $listing_link['text']
168 + );
169 + }
170 + $links['gd_listings'][] = array(
171 + 'optgroup' => 'close',
172 + );
173 + }
228 174
229 - /**
230 - * Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting.
231 - *
232 - * @since 1.0.0
233 - * @package userswp
234 - *
235 - * @param array $tabs_arr Existing tabs array.
236 - *
237 - * @return array Tabs array.
238 - */
239 - public function available_tab_items( $tabs_arr ) {
240 - $tabs_arr['listings'] = __( 'Listings', 'userswp' );
241 - $tabs_arr['reviews'] = __( 'Reviews', 'userswp' );
242 - $tabs_arr['favorites'] = __( 'Favorites', 'userswp' );
175 + if ( class_exists( 'GeoDir_Lists_Compatibility' ) ) {
176 + $listing_links = GeoDir_Lists_Compatibility::geodirectory_dashboard( '', 'array' );
177 + if ( ! empty( $listing_links ) ) {
178 + $links['gd_lists'] = array();
179 + $links['gd_lists'][] = array(
180 + 'optgroup' => 'open',
181 + 'text' => defined( 'MY_LISTS_TEXT' ) ? MY_LISTS_TEXT : __( 'My Lists', 'userswp' )
182 + );
183 + foreach ( $listing_links as $listing_link ) {
184 + $links['gd_lists'][] = array(
185 + 'url' => $listing_link['url'],
186 + 'text' => $listing_link['text']
187 + );
188 + }
189 + $links['gd_lists'][] = array(
190 + 'optgroup' => 'close',
191 + );
192 + }
193 + }
243 194
244 - return $tabs_arr;
245 - }
246 -
247 - public function geodir_get_reviews_by_user_id($post_type = 'gd_place', $user_id, $count_only = false, $offset = 0, $limit = 20) {
248 - global $wpdb;
249 195
250 - if ($count_only) {
251 - if($this->uwp_is_gdv2()) {
252 - $results = $wpdb->get_var(
253 - $wpdb->prepare(
254 - "SELECT COUNT(reviews.rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.rating > 0 AND posts.post_status = 'publish'",
255 - array($user_id, $post_type)
256 - )
257 - );
258 - } else {
259 - $results = $wpdb->get_var(
260 - $wpdb->prepare(
261 - "SELECT COUNT(reviews.overall_rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish'",
262 - array($user_id, $post_type)
263 - )
264 - );
265 - }
266 - } else {
267 - if($this->uwp_is_gdv2()) {
268 - $results = $wpdb->get_results(
269 - $wpdb->prepare(
270 - "SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d",
271 - array($user_id, $post_type, $limit, $offset )
272 - )
273 - );
274 - } else {
275 - $results = $wpdb->get_results(
276 - $wpdb->prepare(
277 - "SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d",
278 - array($user_id, $post_type, $limit, $offset )
279 - )
280 - );
281 - }
282 - }
196 + }
283 197
284 - if (!empty($results))
285 - return $results;
286 - else
287 - return false;
288 - }
198 + return $links;
199 + }
289 200
290 - public function geodir_count_favorite( $post_type, $user_id = 0 ) {
291 - global $wpdb;
201 + /**
202 + * Adds settings tabs for the current userswp addon.
203 + *
204 + * @since 1.0.0
205 + * @package userswp
206 + *
207 + * @param array $sections Existing sections array.
208 + *
209 + * @return array Tabs array.
210 + */
211 + public function add_gd_tab( $sections ) {
292 212
293 - $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
294 - if ( $user_id && $user_id == get_current_user_id() ) {
295 - $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'gd-closed' OR " . $wpdb->posts . ".post_status = 'gd-expired'";
296 - }
213 + $sections['uwp_geodirectory'] = __( 'GeoDirectory', 'userswp' );
297 214
298 - $user_fav_posts = geodir_get_user_favourites( (int)$user_id );
299 - $user_fav_posts = !empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1";
215 + return $sections;
216 + }
300 217
301 - $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 . " )" );
218 + /**
219 + * Registers form fields for the current userswp addon settings page.
220 + *
221 + * @since 1.0.0
222 + * @package userswp
223 + *
224 + * @param array $settings Existing settings array.
225 + * @param string $current_section Currrent setting.
226 + *
227 + * @return array Settings array.
228 + */
229 + public function add_gd_settings( $settings, $current_section ) {
302 230
303 - return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id );
304 - }
305 -
306 - public function get_listings_count($post_type, $user_id = 0) {
307 - global $wpdb;
308 - if (empty($user_id)) {
309 - return 0;
310 - }
231 + if ( ! empty( $current_section ) && 'uwp_geodirectory' === $current_section ) {
311 232
312 - $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
313 - if ($user_id && $user_id == get_current_user_id()) {
314 - $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'gd-closed' OR " . $wpdb->posts . ".post_status = 'gd-expired'";
315 - }
233 + $gd_posttypes = $this->get_gd_posttypes();
316 234
317 - $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 . " )");
235 + $settings = apply_filters( 'uwp_addon_gd_options', array(
236 + array(
237 + 'title' => __( 'GeoDirectory Settings', 'userswp' ),
238 + 'type' => 'title',
239 + 'id' => 'addons_gd_settings_options',
240 + ),
241 + array(
242 + 'id' => 'gd_profile_listings',
243 + 'name' => __( 'CPT listings in profile', 'userswp' ),
244 + 'desc' => __( 'Choose the post types to show listings tab in UsersWP Profile', 'userswp' ),
245 + 'multiple' => true,
246 + 'type' => 'multiselect',
247 + 'options' => $gd_posttypes,
248 + ),
249 + array(
250 + 'id' => 'gd_profile_reviews',
251 + 'name' => __( 'CPT reviews in profile', 'userswp' ),
252 + 'desc' => __( 'Choose the post types to show reviews tab in UsersWP Profile', 'userswp' ),
253 + 'multiple' => true,
254 + 'type' => 'multiselect',
255 + 'options' => $gd_posttypes,
256 + ),
257 + array(
258 + 'id' => 'gd_profile_favorites',
259 + 'name' => __( 'CPT favorites in profile', 'userswp' ),
260 + 'desc' => __( 'Choose the post types to show favorites tab in UsersWP Profile', 'userswp' ),
261 + 'multiple' => true,
262 + 'type' => 'multiselect',
263 + 'options' => $gd_posttypes,
264 + ),
265 + array(
266 + 'id' => 'geodir_uwp_link_listing',
267 + 'name' => __( 'Redirect my listing link from GD login box to UsersWP profile', 'userswp' ),
268 + 'desc' => __( 'If this option is selected, the my listing link from GD loginbox will redirect to listings tab of UsersWP profile.', 'userswp' ),
269 + 'type' => 'checkbox',
270 + 'default' => '0',
271 + ),
272 + array(
273 + 'id' => 'geodir_uwp_link_favorite',
274 + 'name' => __( 'Redirect favorite link from GD login box to UsersWP profile', 'userswp' ),
275 + 'desc' => __( 'If this option is selected, the favorite link from GD loginbox will redirect to favorites tab of UsersWP profile.', 'userswp' ),
276 + 'type' => 'checkbox',
277 + 'default' => '0',
278 + ),
279 + ) );
318 280
319 - return apply_filters('geodir_uwp_count_total', $count, $user_id);
320 - }
281 + $settings[] = array( 'type' => 'sectionend', 'id' => 'addons_gd_settings_options' );
282 + }
321 283
322 - public function get_total_listings_count($user_id = 0) {
323 - if (empty($user_id)) {
324 - return 0;
325 - }
284 + return $settings;
285 + }
326 286
327 - $gd_post_types = geodir_get_posttypes('array');
287 + /**
288 + * Returns GD posttypes
289 + *
290 + * @since 1.0.0
291 + * @package userswp
292 + *
293 + * @return array
294 + */
295 + public function get_gd_posttypes() {
296 + $post_type_arr = array();
297 + $post_types = geodir_get_posttypes( 'object' );
328 298
329 - if (empty($gd_post_types)) {
330 - return 0;
331 - }
299 + foreach ( $post_types as $key => $post_types_obj ) {
300 + $post_type_arr[ $key ] = $post_types_obj->labels->singular_name;
301 + }
332 302
303 + return $post_type_arr;
304 + }
333 305
334 - // allowed post types
335 - $listing_post_types = uwp_get_option('gd_profile_listings', array());
306 + /**
307 + * Adds predefined field in for profile tabs.
308 + *
309 + * @package userswp
310 + *
311 + * @param array $fields Predefined field array.
312 + * @param string $form_type Form type.
313 + *
314 + * @return array $fields Predefined field array.
315 + */
316 + public function add_profile_tabs_predefined_fields( $fields, $form_type ) {
317 + if ( 'profile-tabs' != $form_type ) {
318 + return $fields;
319 + }
336 320
337 - if (!is_array($listing_post_types)) {
338 - $listing_post_types = array();
339 - }
321 + $fields[] = array(
322 + 'tab_type' => 'standard',
323 + 'tab_name' => __( 'Listings', 'userswp' ),
324 + 'tab_icon' => 'fas fa-globe-americas',
325 + 'tab_key' => 'listings',
326 + 'tab_content' => '',
327 + 'tab_privacy' => '0',
328 + 'user_decided' => '1',
329 + );
340 330
341 - $count = 0;
342 - $total_count = 0;
343 - foreach ($listing_post_types as $post_type) {
344 - if (array_key_exists($post_type, $gd_post_types)) {
331 + $fields[] = array(
332 + 'tab_type' => 'standard',
333 + 'tab_name' => __( 'Reviews', 'userswp' ),
334 + 'tab_icon' => 'fas fa-star',
335 + 'tab_key' => 'reviews',
336 + 'tab_content' => '',
337 + 'tab_privacy' => '0',
338 + 'user_decided' => '1',
339 + );
345 340
346 - // get listing count
347 - $listing_count = $this->get_listings_count($post_type, $user_id);
348 - $total_count += $listing_count;
341 + $fields[] = array(
342 + 'tab_type' => 'standard',
343 + 'tab_name' => __( 'Favorites', 'userswp' ),
344 + 'tab_icon' => 'fas fa-heart',
345 + 'tab_key' => 'favorites',
346 + 'tab_content' => '',
347 + 'tab_privacy' => '0',
348 + 'user_decided' => '1',
349 + );
349 350
350 - $count++;
351 - }
352 - }
351 + if ( class_exists( 'GeoDir_Lists' ) ) {
352 + $fields[] = array(
353 + 'tab_type' => 'standard',
354 + 'tab_name' => __( 'Lists', 'userswp' ),
355 + 'tab_icon' => 'fas fa-list',
356 + 'tab_key' => 'lists',
357 + 'tab_content' => '',
358 + 'tab_privacy' => '0',
359 + 'user_decided' => '1',
360 + );
361 + }
353 362
354 - return $total_count;
355 - }
363 + return $fields;
364 + }
356 365
357 - public function get_total_reviews_count($user_id = 0) {
358 - if (empty($user_id)) {
359 - return 0;
360 - }
366 + /**
367 + * Returns listing count
368 + *
369 + * @since 1.0.0
370 + * @package userswp
371 + *
372 + * @param int $user_id User ID
373 + *
374 + * @return int
375 + */
376 + public function get_total_listings_count( $user_id = 0 ) {
377 + if ( empty( $user_id ) ) {
378 + return 0;
379 + }
361 380
362 - $gd_post_types = geodir_get_posttypes('array');
381 + $gd_post_types = geodir_get_posttypes( 'array' );
363 382
364 - if (empty($gd_post_types)) {
365 - return 0;
366 - }
383 + if ( empty( $gd_post_types ) ) {
384 + return 0;
385 + }
367 386
368 - // allowed post types
369 - $listing_post_types = uwp_get_option('gd_profile_reviews', array());
370 387
371 - if (!is_array($listing_post_types)) {
372 - $listing_post_types = array();
373 - }
388 + // allowed post types
389 + $listing_post_types = uwp_get_option( 'gd_profile_listings', array() );
374 390
375 - $count = 0;
376 - $total_count = 0;
377 - foreach ($listing_post_types as $post_type) {
378 - if (array_key_exists($post_type, $gd_post_types)) {
391 + if ( ! is_array( $listing_post_types ) ) {
392 + $listing_post_types = array();
393 + }
379 394
380 - // get listing count
381 - $listing_count = $this->geodir_get_reviews_by_user_id($post_type, $user_id, true);
382 - $total_count += $listing_count;
395 + $count = 0;
396 + $total_count = 0;
397 + foreach ( $listing_post_types as $post_type ) {
398 + if ( array_key_exists( $post_type, $gd_post_types ) ) {
383 399
384 - $count++;
385 - }
386 - }
400 + // get listing count
401 + $listing_count = $this->get_listings_count( $post_type, $user_id );
402 + $total_count += $listing_count;
387 403
388 - return $total_count;
389 - }
404 + $count ++;
405 + }
406 + }
390 407
391 - public function get_total_favorites_count($user_id = 0) {
392 - if (empty($user_id)) {
393 - return 0;
394 - }
408 + return $total_count;
409 + }
395 410
396 - $gd_post_types = geodir_get_posttypes('array');
411 + /**
412 + * Returns listings count
413 + *
414 + * @since 1.0.0
415 + * @package userswp
416 + *
417 + * @param string $post_type Post type
418 + * @param int $user_id User ID
419 + *
420 + * @return mixed
421 + */
422 + public function get_listings_count( $post_type, $user_id = 0 ) {
423 + global $wpdb, $sitepress, $wpml_query_filter;
397 424
398 - if (empty($gd_post_types)) {
399 - return 0;
400 - }
425 + if ( empty( $user_id ) ) {
426 + return 0;
427 + }
401 428
402 - // allowed post types
403 - $listing_post_types = uwp_get_option('gd_profile_favorites', array());
429 + if ( ! empty( $user_id ) && (int) get_current_user_id() == (int) $user_id ) {
430 + $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
431 + } else {
432 + $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
433 + }
404 434
405 - if (!is_array($listing_post_types)) {
406 - $listing_post_types = array();
407 - }
435 + if ( empty( $post_status ) ) {
436 + $post_status = array( 'publish' );
437 + }
408 438
409 - $count = 0;
410 - $total_count = 0;
411 - foreach ($listing_post_types as $post_type) {
412 - if (array_key_exists($post_type, $gd_post_types)) {
439 + if ( is_super_admin() ) {
440 + $post_status[] = 'private';
441 + }
413 442
414 - // get listing count
415 - $listing_count = $this->geodir_count_favorite($post_type, $user_id);
416 - $total_count += $listing_count;
443 + $post_status = array_unique( $post_status );
444 + $post_status_where = array();
417 445
418 - $count++;
419 - }
446 + foreach ( $post_status as $status ) {
447 + $post_status_where[] = $wpdb->prepare( "p.post_status = %s", $status );
448 + }
449 +
450 + $post_status_where = implode( " OR ", $post_status_where );
451 +
452 + $join = '';
453 + $where = '';
454 + if ( uwp_is_wpml() ) {
455 + if ( ! empty( $wpml_query_filter ) && $sitepress->is_translated_post_type( $post_type ) ) {
456 + $wpml_join = $wpml_query_filter->filter_single_type_join( '', $post_type );
457 + $wpml_join = str_replace( " {$wpdb->posts}.", " p.", $wpml_join );
458 + $join .= $wpml_join;
459 +
460 + $wpml_where = $wpml_query_filter->filter_single_type_where( '', $post_type );
461 + $wpml_where = str_replace( array( " {$wpdb->posts} p", " p." ), array(
462 + " {$wpdb->posts} wpml_p",
463 + " wpml_p."
464 + ), $wpml_where );
465 + $wpml_where = str_replace( " {$wpdb->posts}.", " p.", $wpml_where );
466 +
467 + $where .= $wpml_where;
468 + }
469 + }
470 +
471 + $table = geodir_db_cpt_table( $post_type );
472 +
473 + $sql = "SELECT count( p.ID ) FROM " . $wpdb->prefix . "posts AS p INNER JOIN `" . $table . "` AS pd ON `pd`.`post_id` = `p`.`ID` {$join} WHERE p.post_author=" . (int) $user_id . " AND p.post_type='" . $post_type . "' AND ( " . $post_status_where . " ) {$where}";
474 + $sql = apply_filters( 'geodir_uwp_listings_count_sql', $sql, $post_type, $user_id );
475 +
476 + $count = (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
477 +
478 + return apply_filters( 'geodir_uwp_count_total', $count, $user_id );
479 + }
480 +
481 + /**
482 + * Returns reviews count
483 + *
484 + * @package userswp
485 + *
486 + * @param int $user_id User ID
487 + *
488 + * @return int
489 + */
490 + public function get_total_reviews_count( $user_id = 0 ) {
491 + if ( empty( $user_id ) ) {
492 + return 0;
493 + }
494 +
495 + $gd_post_types = geodir_get_posttypes( 'array' );
496 +
497 + if ( empty( $gd_post_types ) ) {
498 + return 0;
499 + }
500 +
501 + // allowed post types
502 + $listing_post_types = uwp_get_option( 'gd_profile_reviews', array() );
503 +
504 + if ( ! is_array( $listing_post_types ) ) {
505 + $listing_post_types = array();
506 + }
507 +
508 + $count = 0;
509 + $total_count = 0;
510 + foreach ( $listing_post_types as $post_type ) {
511 + if ( array_key_exists( $post_type, $gd_post_types ) ) {
512 +
513 + // get listing count
514 + $listing_count = $this->geodir_get_reviews_by_user_id( $post_type, $user_id, true );
515 + $total_count += $listing_count;
516 +
517 + $count ++;
518 + }
519 + }
520 +
521 + return $total_count;
522 + }
523 +
524 + /**
525 + * Returns reviews by user ID
526 + *
527 + * @package userswp
528 + *
529 + * @param string $post_type Post type
530 + * @param int $user_id User ID
531 + * @param bool $count_only Return count or object
532 + * @param int $offset Offset
533 + * @param int $limit Limit
534 + *
535 + * @return mixed
536 + */
537 + public function geodir_get_reviews_by_user_id( $post_type, $user_id, $count_only = false, $offset = 0, $limit = 20 ) {
538 + global $wpdb;
539 +
540 + if(empty($post_type)){
541 + $post_type = 'gd_place';
420 542 }
421 543
422 - return $total_count;
423 - }
544 + if ( $count_only ) {
545 + if ( uwp_is_gdv2() ) {
546 + $results = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
547 + $wpdb->prepare(
548 + "SELECT COUNT(reviews.rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.rating > 0 AND posts.post_status = 'publish'",
549 + array( $user_id, $post_type )
550 + )
551 + );
552 + } else {
553 + $results = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
554 + $wpdb->prepare(
555 + "SELECT COUNT(reviews.overall_rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish'",
556 + array( $user_id, $post_type )
557 + )
558 + );
559 + }
560 + } else {
561 + if ( uwp_is_gdv2() ) {
562 + $results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
563 + $wpdb->prepare(
564 + "SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d",
565 + array( $user_id, $post_type, $limit, $offset )
566 + )
567 + );
568 + } else {
569 + $results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
570 + $wpdb->prepare(
571 + "SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d",
572 + array( $user_id, $post_type, $limit, $offset )
573 + )
574 + );
575 + }
576 + }
424 577
425 - /**
426 - * Adds tab in user profile page.
427 - *
428 - * @since 1.0.0
429 - * @package userswp
430 - *
431 - * @param array $tabs Existing tabs array.
432 - * @param object $user User object.
433 - * @param array $allowed_tabs Allowed tabs array.
434 - *
435 - * @return array Tabs array.
436 - */
437 - function add_profile_gd_tabs($tabs, $user,$allowed_tabs) {
438 - // allowed post types
439 - $listing_post_types = uwp_get_option('gd_profile_listings', array());
440 - $l_counts = $this->get_total_listings_count($user->ID);
441 - if (!empty($listing_post_types) && in_array('listings', $allowed_tabs) && $l_counts > 0) {
442 - $tabs['listings'] = array(
443 - 'title' => __('Listings', 'userswp'),
444 - 'count' => $l_counts
445 - );
446 - }
578 + if ( ! empty( $results ) ) {
579 + return $results;
580 + } else {
581 + return false;
582 + }
583 + }
447 584
448 - $listing_post_types = uwp_get_option('gd_profile_reviews', array());
449 - $r_counts = $this->get_total_reviews_count($user->ID);
450 - if (!empty($listing_post_types) && in_array('reviews', $allowed_tabs) && $r_counts > 0) {
451 - $tabs['reviews'] = array(
452 - 'title' => __('Reviews', 'userswp'),
453 - 'count' => $r_counts
454 - );
455 - }
585 + /**
586 + * Returns favourite count
587 + *
588 + * @since 1.0.0
589 + * @package userswp
590 + *
591 + * @param int $user_id User ID
592 + *
593 + * @return mixed
594 + */
595 + public function get_total_favorites_count( $user_id = 0 ) {
596 + if ( empty( $user_id ) ) {
597 + return 0;
598 + }
456 599
457 - $listing_post_types = uwp_get_option('gd_profile_favorites', array());
458 - $f_counts = $this->get_total_favorites_count($user->ID);
459 - if (!empty($listing_post_types) && in_array('favorites', $allowed_tabs) && (get_current_user_id() == $user->ID) && $f_counts > 0) {
460 - $tabs['favorites'] = array(
461 - 'title' => __('Favorites', 'userswp'),
462 - 'count' => $f_counts
463 - );
464 - }
600 + $gd_post_types = geodir_get_posttypes( 'array' );
465 601
466 - return $tabs;
467 - }
602 + if ( empty( $gd_post_types ) ) {
603 + return 0;
604 + }
468 605
469 - /**
470 - * Adds GD listings tab content.
471 - *
472 - * @since 1.0.0
473 - * @package userswp
474 - *
475 - * @param object $user User object.
476 - *
477 - * @return void
478 - */
479 - public function add_profile_listings_tab_content($user) {
480 - $this->profile_gd_subtabs_content($user, 'listings');
481 - }
606 + // allowed post types
607 + $listing_post_types = uwp_get_option( 'gd_profile_favorites', array() );
482 608
483 - /**
484 - * Adds GD reviews tab content.
485 - *
486 - * @since 1.0.0
487 - * @package userswp
488 - *
489 - * @param object $user User object.
490 - *
491 - * @return void
492 - */
493 - public function add_profile_reviews_tab_content($user) {
494 - $this->profile_gd_subtabs_content($user, 'reviews');
495 - }
609 + if ( ! is_array( $listing_post_types ) ) {
610 + $listing_post_types = array();
611 + }
496 612
497 - /**
498 - * Adds GD Favorites tab content.
499 - *
500 - * @since 1.0.0
501 - * @package userswp
502 - *
503 - * @param object $user User object.
504 - *
505 - * @return void
506 - */
507 - public function add_profile_favorites_tab_content($user) {
508 - $this->profile_gd_subtabs_content($user, 'favorites');
509 - }
613 + $count = 0;
614 + $total_count = 0;
615 + foreach ( $listing_post_types as $post_type ) {
616 + if ( array_key_exists( $post_type, $gd_post_types ) ) {
510 617
511 - public function profile_gd_subtabs($user, $type = 'listings') {
512 - $tabs = array();
618 + // get listing count
619 + $listing_count = $this->geodir_count_favorite( $post_type, $user_id );
620 + $total_count += $listing_count;
513 621
514 - $gd_post_types = geodir_get_posttypes('array');
622 + $count ++;
623 + }
624 + }
515 625
516 - if (empty($gd_post_types)) {
517 - return $tabs;
518 - }
626 + return $total_count;
627 + }
519 628
520 - // allowed post types
521 - if ($type == 'listings') {
522 - $listing_post_types = uwp_get_option('gd_profile_listings', array());
523 - } elseif ($type == 'reviews') {
524 - $listing_post_types = uwp_get_option('gd_profile_reviews', array());
525 - } elseif ($type == 'favorites') {
526 - $listing_post_types = uwp_get_option('gd_profile_favorites', array());
527 - } else {
528 - $listing_post_types = array();
529 - }
629 + /**
630 + * Returns favourite listings count
631 + *
632 + * @package userswp
633 + *
634 + * @param string $post_type Post type
635 + * @param int $user_id User ID
636 + *
637 + * @return int
638 + */
639 + public function geodir_count_favorite( $post_type, $user_id = 0 ) {
640 + global $wpdb;
530 641
531 - if (!is_array($listing_post_types)) {
532 - $listing_post_types = array();
533 - }
642 + if ( ! empty( $user_id ) && (int) get_current_user_id() == (int) $user_id ) {
643 + $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
644 + } else {
645 + $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
646 + }
534 647
535 - foreach ($gd_post_types as $post_type_id => $post_type) {
536 - if (in_array($post_type_id, $listing_post_types)) {
537 - $post_type_slug = $gd_post_types[$post_type_id]['has_archive'];
648 + if ( empty( $post_status ) ) {
649 + $post_status = array( 'publish' );
650 + }
538 651
539 - if($this->uwp_is_gdv2()) {
540 - if ($type == 'favorites' && geodir_cpt_has_favourite_disabled($post_type_id)) {
541 - continue;
542 - } elseif ($type == 'reviews' && geodir_cpt_has_rating_disabled($post_type_id)) {
543 - continue;
544 - }
545 - }
652 + if ( is_super_admin() ) {
653 + $post_status[] = 'private';
654 + }
546 655
547 - if ($type == 'listings') {
548 - $all_count = geodir_user_post_listing_count($user->ID, true);
549 - $count = $all_count[$post_type_id];
550 - } elseif ($type == 'reviews') {
551 - $count = $this->geodir_get_reviews_by_user_id($post_type_id, $user->ID, true);
552 - } elseif ($type == 'favorites') {
553 - $count = $this->geodir_count_favorite($post_type_id, $user->ID);
554 - } else {
555 - $count = 0;
556 - }
656 + $post_status = array_unique( $post_status );
657 + $post_status_where = array();
557 658
558 - if (empty($count)) {
559 - $count = 0;
560 - }
561 - $tabs[$post_type_slug] = array(
562 - 'title' => $gd_post_types[$post_type_id]['labels']['name'],
563 - 'count' => $count,
564 - 'ptype' => $post_type_id
565 - );
566 - }
567 - }
659 + foreach ( $post_status as $status ) {
660 + $post_status_where[] = $wpdb->prepare( "`" . $wpdb->posts . "`.post_status = %s", $status );
661 + }
568 662
569 - return apply_filters('uwp_profile_gd_tabs', $tabs, $user, $type);
570 - }
663 + $post_status_where = implode( " OR ", $post_status_where );
571 664
572 - public function profile_gd_subtabs_content($user, $type = 'listings') {
573 - $subtab = get_query_var('uwp_subtab');
574 - $subtabs = $this->profile_gd_subtabs($user, $type);
575 - $default_tab = apply_filters('uwp_default_listing_subtab', 'places', $user, $type);
576 - $active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : $default_tab;
577 - if (!empty($subtabs)) {
578 - $subtab_keys = array_keys($subtabs);
579 - $post_type = $subtabs[$subtab_keys[0]]['ptype'];
580 - } else {
581 - $post_type = false;
582 - }
583 - ?>
584 - <div class="uwp-profile-subcontent">
585 - <div class="uwp-profile-subnav">
586 - <?php if ($subtabs) { ?>
587 - <ul class="item-list-subtabs-ul">
588 - <?php
589 - foreach ($this->profile_gd_subtabs($user, $type) as $tab_id => $tab) {
665 + $user_fav_posts = geodir_get_user_favourites( (int) $user_id );
666 + $user_fav_posts = ! empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1";
590 667
591 - $tab_url = uwp_build_profile_tab_url($user->ID, $type, $tab_id);
668 + $table = geodir_db_cpt_table( $post_type );
592 669
593 - $active = $active_tab == $tab_id ? ' active' : '';
594 - $post_type = $active_tab == $tab_id ? $tab['ptype'] : $post_type;
595 - ?>
596 - <li id="uwp-profile-gd-<?php echo $tab_id; ?>" class="<?php echo $active; ?>">
597 - <a href="<?php echo esc_url($tab_url); ?>">
598 - <span class="uwp-profile-tab-label uwp-profile-gd-<?php echo $tab_id; ?>-label "><span
599 - class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo $tab_id; ?>-count"><?php echo $tab['count']; ?></span> <?php echo esc_html($tab['title']); ?></span>
600 - </a>
601 - </li>
602 - <?php
603 - }
604 - ?>
605 - </ul>
606 - <?php } ?>
607 - </div>
670 + $sql = "SELECT count( ID ) FROM " . $wpdb->posts . " INNER JOIN `" . $table . "` ON `" . $table . "`.`post_id` = " . $wpdb->posts . ".`ID` WHERE " . $wpdb->posts . ".ID IN ('" . $user_fav_posts . "') AND post_type='" . $post_type . "' AND ( " . $post_status_where . " )";
671 + $sql = apply_filters( 'geodir_uwp_favorite_count_sql', $sql, $post_type, $user_id );
608 672
609 - <div class="uwp-profile-subtab-entries">
610 - <?php
611 - do_action('uwp_profile_gd_' . $type . '_subtab_content', $user, $post_type);
612 - ?>
613 - </div>
614 - </div>
615 - <?php
616 - }
673 + $count = (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
617 674
618 - function gd_get_listings($user, $post_type) {
619 - $gd_post_types = geodir_get_posttypes('array');
620 - ?>
621 - <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3>
675 + return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id );
676 + }
622 677
623 - <div class="uwp-profile-item-block">
624 - <?php
625 -
626 - $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
678 + /**
679 + * Adds GD listings tab content.
680 + *
681 + * @since 1.0.0
682 + * @package userswp
683 + *
684 + * @param object $user User object.
685 + *
686 + * @return void
687 + */
688 + public function add_profile_listings_tab_content( $user ) {
689 + $this->profile_gd_subtabs_content( $user, 'listings' );
690 + }
627 691
628 - $args = array(
629 - 'post_type' => $post_type,
630 - 'post_status' => array('publish'),
631 - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
632 - 'author' => $user->ID,
633 - 'paged' => $paged,
634 - );
692 + /**
693 + * Displays subtab content
694 + *
695 + * @package userswp
696 + *
697 + * @param object $user User object
698 + * @param string $type Subtab type
699 + *
700 + */
701 + public function profile_gd_subtabs_content( $user, $type = 'listings' ) {
702 + $subtab = get_query_var( 'uwp_subtab' );
703 + $subtabs = $this->profile_gd_subtabs( $user, $type );
704 + $default_tab = apply_filters( 'uwp_default_listing_subtab', 'places', $user, $type );
705 + $post_type = apply_filters( 'uwp_default_listing_post_type', 'gd_place', $user, $type );
706 + if ( ! empty( $subtab ) && array_key_exists( $subtab, $subtabs ) ) {
707 + $active_tab = $subtab;
708 + $post_type = $subtabs[ $subtab ]['ptype'];
709 + } elseif ( ! empty( $subtabs ) ) {
710 + $subtab_keys = array_keys( $subtabs );
711 + $active_tab = $subtab_keys[0];
712 + $post_type = $subtabs[ $subtab_keys[0] ]['ptype'];
713 + } else {
714 + $active_tab = $default_tab;
715 + }
635 716
636 - if (get_current_user_id() == $user->ID) {
637 - $args['post_status'] = array('publish', 'draft', 'private', 'pending', 'gd-closed', 'gd-expired');
638 - }
639 - // The Query
640 - $the_query = new WP_Query($args);
717 + if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
718 + if ( is_array( $subtabs ) && count( $subtabs ) > 1 ) {
719 + ?>
720 + <div class="pb-3">
721 + <?php
722 + foreach ( $subtabs as $tab_id => $tab ) {
641 723
642 - do_action('uwp_before_profile_listing_items', $user, $post_type);
643 - // The Loop
644 - if ($the_query->have_posts()) {
645 - echo '<ul class="uwp-profile-item-ul">';
646 - while ($the_query->have_posts()) {
647 - $the_query->the_post();
648 - $post_id = get_the_ID();
649 - global $post;
650 - $post = geodir_get_post_info($post_id);
651 - setup_postdata($post);
652 - $post_avgratings = geodir_get_post_rating($post->ID);
653 - $post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID);
654 - ob_start();
655 - geodir_comments_number($post->rating_count);
656 - $n_comments = ob_get_contents();
657 - ob_end_clean();
724 + $tab_url = uwp_build_profile_tab_url( $user->ID, $type, $tab_id );
725 + $active = $active_tab == $tab_id ? 'btn-primary' : 'btn-outline-primary';
726 + $post_type = $active_tab == $tab_id ? $tab['ptype'] : $post_type;
727 + $append_hash = apply_filters('uwp_add_tab_content_hashtag', true, $tab, $user);
728 + $tab_url = $append_hash ? esc_url($tab_url).'#tab-content' : esc_url($tab_url);
658 729
659 - do_action('uwp_before_profile_listing_item', $post_id, $user, $post_type);
660 - ?>
661 - <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-'.$post_type; ?>">
662 - <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>">
663 - <?php
664 - if (has_post_thumbnail()) {
665 - $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80));
666 - } else {
667 - $thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png";
668 - }
669 - ?>
670 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
730 + ?>
731 + <a id="uwp-profile-gd-<?php echo esc_attr( $tab_id ); ?>" href="<?php echo esc_url( $tab_url ); ?>"
732 + class=" btn btn-sm <?php echo esc_attr( $active ); ?>">
733 + <?php echo esc_html__( $tab['title'], 'userswp' ); ?>
734 + <span class="badge badge-light ml-1"><?php echo esc_html( $tab['count'] ); ?></span>
671 735 </a>
736 + <?php
737 + }
738 + ?>
739 + </div>
740 + <?php
741 + }
742 + } else {
743 + if ( ! empty( $subtabs ) ) { ?>
744 + <div class="uwp-profile-subcontent">
745 + <div class="uwp-profile-subnav">
746 + <ul class="item-list-subtabs-ul">
747 + <?php
748 + foreach ( $subtabs as $tab_id => $tab ) {
672 749
673 - <?php do_action('uwp_before_profile_listing_title', $post_id, $user, $post_type); ?>
674 - <h3 class="uwp-profile-item-title">
675 - <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
676 - </h3>
677 - <?php do_action('uwp_after_profile_listing_title', $post_id, $user, $post_type); ?>
750 + $tab_url = uwp_build_profile_tab_url( $user->ID, $type, $tab_id );
751 + $active = $active_tab == $tab_id ? ' active' : '';
752 + $post_type = $active_tab == $tab_id ? $tab['ptype'] : $post_type;
753 + $append_hash = apply_filters('uwp_add_tab_content_hashtag', true, $tab, $user);
754 + $tab_url = $append_hash ? esc_url($tab_url).'#tab-content' : esc_url($tab_url);
678 755
679 - <div class="uwp-time-ratings-wrap">
680 - <?php do_action('uwp_before_profile_listing_ratings', $post_id, $user, $post_type); ?>
681 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
682 - <?php echo get_the_date(); ?>
683 - </time>
684 - <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?>
685 - <?php
686 - if (!is_user_logged_in()) {
687 - do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
688 - }
689 - ?>
690 - <?php do_action('uwp_after_profile_listing_ratings', $post_id, $user, $post_type); ?>
756 + ?>
757 + <li id="uwp-profile-gd-<?php echo esc_attr( $tab_id ); ?>" class="<?php echo esc_attr( $active ); ?>">
758 + <a href="<?php echo esc_url( $tab_url ); ?>">
759 + <span
760 + class="uwp-profile-tab-label uwp-profile-gd-<?php echo esc_attr( $tab_id ); ?>-label "><span
761 + class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo esc_attr( $tab_id ); ?>-count"><?php echo esc_html( $tab['count'] ); ?></span> <?php echo esc_html__( $tab['title'], 'userswp' ); ?></span>
762 + </a>
763 + </li>
764 + <?php
765 + }
766 + ?>
767 + </ul>
768 + </div>
769 + </div>
770 + <?php }
771 + }
772 + if ( has_action( 'uwp_profile_gd_' . $type . '_subtab_content' ) ) {
773 + do_action( 'uwp_profile_gd_' . $type . '_subtab_content', $user, $post_type );
774 + }
775 + }
776 +
777 + /**
778 + * Returns subtab data
779 + *
780 + * @since 1.0.0
781 + * @package userswp
782 + *
783 + * @param object $user User object
784 + * @param string $type Subtab type
785 + *
786 + * @return array
787 + */
788 + public function profile_gd_subtabs( $user, $type = 'listings' ) {
789 + $tabs = array();
790 +
791 + $gd_post_types = geodir_get_posttypes( 'array' );
792 +
793 + if ( empty( $gd_post_types ) ) {
794 + return $tabs;
795 + }
796 +
797 + // allowed post types
798 + if ( $type == 'listings' ) {
799 + $listing_post_types = uwp_get_option( 'gd_profile_listings', array() );
800 + } elseif ( $type == 'reviews' ) {
801 + $listing_post_types = uwp_get_option( 'gd_profile_reviews', array() );
802 + } elseif ( $type == 'favorites' ) {
803 + $listing_post_types = uwp_get_option( 'gd_profile_favorites', array() );
804 + } else {
805 + $listing_post_types = array();
806 + }
807 +
808 + if ( ! is_array( $listing_post_types ) ) {
809 + $listing_post_types = array();
810 + }
811 +
812 + foreach ( $gd_post_types as $post_type_id => $post_type ) {
813 + if ( in_array( $post_type_id, $listing_post_types ) ) {
814 + $post_type_slug = $gd_post_types[ $post_type_id ]['has_archive'];
815 +
816 + if ( uwp_is_gdv2() ) {
817 + $reviews = apply_filters('uwp_profile_gd_show_all_reviews', false, $user, $post_type_id);
818 + if ( $type == 'favorites' && geodir_cpt_has_favourite_disabled( $post_type_id ) ) {
819 + continue;
820 + } elseif ( $type == 'reviews' && $reviews && geodir_cpt_has_rating_disabled( $post_type_id ) ) {
821 + continue;
822 + }
823 + }
824 +
825 + if ( $type == 'listings' ) {
826 + $count = $this->get_listings_count( $post_type_id, $user->ID );
827 + } elseif ( $type == 'reviews' ) {
828 + $count = $this->geodir_get_reviews_by_user_id( $post_type_id, $user->ID, true );
829 + } elseif ( $type == 'favorites' ) {
830 + $count = $this->geodir_count_favorite( $post_type_id, $user->ID );
831 + } else {
832 + $count = 0;
833 + }
834 +
835 + if ( ! empty( $count ) && $count > 0 ) {
836 + $tabs[ $post_type_slug ] = array(
837 + 'title' => $gd_post_types[ $post_type_id ]['labels']['name'],
838 + 'count' => $count,
839 + 'ptype' => $post_type_id
840 + );
841 + }
842 + }
843 + }
844 +
845 + return apply_filters( 'uwp_profile_gd_tabs', $tabs, $user, $type );
846 + }
847 +
848 + /**
849 + * Adds GD reviews tab content.
850 + *
851 + * @since 1.0.0
852 + * @package userswp
853 + *
854 + * @param object $user User object.
855 + *
856 + * @return void
857 + */
858 + public function add_profile_reviews_tab_content( $user ) {
859 + $this->profile_gd_subtabs_content( $user, 'reviews' );
860 + }
861 +
862 + /**
863 + * Adds GD Favorites tab content.
864 + *
865 + * @since 1.0.0
866 + * @package userswp
867 + *
868 + * @param object $user User object.
869 + *
870 + * @return void
871 + */
872 + public function add_profile_favorites_tab_content( $user ) {
873 + $this->profile_gd_subtabs_content( $user, 'favorites' );
874 + }
875 +
876 + /**
877 + * Adds GD Lists tab content.
878 + *
879 + * @since 1.0.0
880 + * @package userswp
881 + *
882 + * @param object $user User object.
883 + *
884 + * @return void
885 + */
886 + public function add_profile_gd_lists_tab_content( $user ) {
887 + if ( ! class_exists( 'GeoDir_Lists' ) ) {
888 + return;
889 + }
890 +
891 + $subtab = get_query_var( 'uwp_subtab' );
892 + $uwp_tab = get_query_var( 'uwp_tab' );
893 + $type = geodir_lists_slug();
894 +
895 + if ( empty( $uwp_tab ) ) {
896 + $uwp_tab = $type;
897 + }
898 +
899 + $user_lists = GeoDir_Lists_Data::get_user_lists( $user->ID );
900 +
901 + $subtabs = array();
902 + if (!empty($user_lists)) {
903 + foreach ($user_lists as $list) {
904 + $subtabs[$list->post_name] = array(
905 + 'id' => $list->ID,
906 + 'title' => $list->post_title,
907 + 'count' => count($this->get_listings_from_list($list->ID))
908 + );
909 + }
910 + }
911 +
912 + if (!empty($subtabs)) {
913 + $subtab_keys = array_keys($subtabs);
914 + $default_tab = isset($subtab_keys[0]) ? $subtab_keys[0] : '';
915 + } else {
916 + $default_tab = '';
917 + }
918 +
919 + $default_tab = apply_filters('uwp_default_gd_lists_subtab', $default_tab, $user, $type);
920 + $active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : $default_tab;
921 + if (!empty($active_tab) && isset($subtabs[$active_tab]['id'])) {
922 + $active_id = $subtabs[$active_tab]['id'];
923 + } elseif (isset($subtabs[$default_tab]['id'])) {
924 + $active_id = $subtabs[$default_tab]['id'];
925 + } else {
926 + $active_id = '';
927 + }
928 +
929 + if (uwp_get_option("design_style", 'bootstrap')) {
930 + if (is_array($subtabs) && count($subtabs) > 0) {
931 + ?>
932 + <div class="pb-3">
933 + <?php
934 + foreach ($subtabs as $tab_id => $tab) {
935 + $tab_url = uwp_build_profile_tab_url($user->ID, $uwp_tab, $tab_id);
936 + $active = $active_tab == $tab_id ? 'btn-primary' : 'btn-outline-primary';
937 + ?>
938 + <a id="uwp-profile-gd-<?php echo esc_attr($tab_id); ?>" href="<?php echo esc_url($tab_url); ?>"
939 + class=" btn btn-sm <?php echo esc_attr($active); ?>">
940 + <?php echo esc_html__($tab['title'], 'userswp'); ?>
941 + <span class="badge badge-light ml-1"><?php echo esc_html($tab['count']); ?></span>
942 + </a>
943 + <?php
944 + }
945 + ?>
946 + </div>
947 + <?php
948 + }
949 + } else {
950 + if (!empty($subtabs)) { ?>
951 + <div class="uwp-profile-subcontent">
952 + <div class="uwp-profile-subnav">
953 + <ul class="item-list-subtabs-ul">
954 + <?php
955 + foreach ($subtabs as $tab_id => $tab) {
956 + $tab_url = uwp_build_profile_tab_url($user->ID, $type, $tab_id);
957 + $active = $active_tab == $tab_id ? ' active' : '';
958 + ?>
959 + <li id="uwp-profile-gd-<?php echo esc_attr($tab_id); ?>"
960 + class="<?php echo esc_attr($active); ?>">
961 + <a href="<?php echo esc_url($tab_url); ?>">
962 + <span
963 + class="uwp-profile-tab-label uwp-profile-gd-<?php echo esc_attr($tab_id); ?>-label "><span
964 + class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo esc_attr($tab_id); ?>-count"><?php echo esc_html($tab['count']); ?></span> <?php echo esc_html__($tab['title'], 'userswp'); ?></span>
965 + </a>
966 + </li>
967 + <?php
968 + }
969 + ?>
970 + </ul>
971 + </div>
972 + </div>
973 + <?php }
974 + }
975 +
976 + $post_ids = $this->get_listings_from_list($active_id);
977 +
978 + if (!empty($post_ids)) {
979 + $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
980 +
981 + $query_args = array(
982 + 'is_geodir_loop' => true,
983 + 'gd_location' => false,
984 + 'post_type' => geodir_get_posttypes(),
985 + 'post__in' => $post_ids,
986 + 'post_status' => array('publish'),
987 + 'posts_per_page' => self::get_items_per_page( 'listings' ),
988 + 'paged' => $paged,
989 + );
990 +
991 + if (get_current_user_id() == $user->ID) {
992 + $query_args['post_status'] = array(
993 + 'publish',
994 + 'draft',
995 + 'private',
996 + 'pending',
997 + 'gd-closed',
998 + 'gd-expired'
999 + );
1000 + }
1001 +
1002 + $the_query = new WP_Query($query_args);
1003 + } else {
1004 + $the_query = array();
1005 + }
1006 +
1007 + $args = array();
1008 + $args['template_args']['the_query'] = $the_query;
1009 + $args['template_args']['title'] = $active_tab && !empty($subtabs) && !empty($subtabs[$active_tab]['title']) ? $subtabs[$active_tab]['title'] : '';
1010 + $args['template_args']['list_data'] = isset($subtabs[$active_tab]) ? $subtabs[$active_tab] : array();
1011 + $title = isset($args['template_args']['title']) ? $args['template_args']['title'] : '';
1012 + $found_posts = !empty($the_query) && !empty($the_query->found_posts) ? $the_query->found_posts : 0;
1013 +
1014 + if ($found_posts) {
1015 + $widget_args = array(
1016 + 'column_gap_class' => 'mb-4',
1017 + 'row_gap_class' => '',
1018 + 'card_border_class' => 'border-0',
1019 + 'card_shadow_class' => '',
1020 + 'layout' => '3',
1021 + );
1022 +
1023 + $template_args = apply_filters( 'uwp_profile_tab_lists_args', $widget_args );
1024 + $gd_layout_class = geodir_convert_listing_view_class( $template_args['layout'] );
1025 + ?>
1026 + <div class="container mb-1">
1027 + <div class="row">
1028 + <div class="col-sm p-0 uwp-loop-posts-title">
1029 + <h3><?php echo esc_html($title); ?></h3>
1030 + </div>
1031 + <div class="col p-0 d-sm-block uwp-loop-posts-toolbar">
1032 + <div class="btn-toolbar justify-content-end" role="toolbar" aria-label="Toolbar with button groups">
1033 + <?php geodir_list_view_select('gd_list'); ?>
1034 + </div>
1035 + </div>
1036 + </div>
1037 + </div>
1038 + <?php do_action('uwp_profile_posts_loop_wrap_start', $args, $found_posts); ?>
1039 + <div class="geodir-loop-container">
1040 + <div class="row row-cols-1 row-cols-sm-2 geodir-category-list-view <?php echo esc_attr( $gd_layout_class ); ?>">
1041 + <?php
1042 + while ($the_query->have_posts()) : $the_query->the_post();
1043 + echo geodir_get_template_html("bootstrap/content-listing.php", array(
1044 + 'column_gap_class' => $template_args['column_gap_class'],
1045 + 'row_gap_class' => $template_args['row_gap_class'],
1046 + 'card_border_class' => $template_args['card_border_class'],
1047 + 'card_shadow_class' => $template_args['card_shadow_class'],
1048 + ));
1049 + endwhile;
1050 + wp_reset_postdata();
1051 + ?>
1052 + </div>
1053 + </div>
1054 + <?php
1055 + do_action('uwp_profile_pagination', $the_query->max_num_pages);
1056 + }
1057 + }
1058 +
1059 + public function get_listings_from_list( $list_id ) {
1060 + global $wpdb;
1061 + $post_ids_obj = $wpdb->get_results( $wpdb->prepare( "SELECT p2p_from FROM $wpdb->p2p WHERE p2p_to = %d", absint( $list_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1062 + $post_ids = wp_list_pluck( $post_ids_obj, 'p2p_from' );
1063 +
1064 + return $post_ids;
1065 + }
1066 +
1067 + /**
1068 + * Adjust the post footer info for GD posts.
1069 + *
1070 + * @param $html
1071 + *
1072 + * @return string
1073 + */
1074 + public function posts_footer( $html ) {
1075 + global $post, $aui_bs5;
1076 +
1077 + if ( ! empty( $post->post_type ) && uwp_is_gdv2() && geodir_is_gd_post_type( $post->post_type ) ) {
1078 + $post_avgratings = geodir_get_post_rating( $post->ID );
1079 + $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1080 + $actions_shortcode = apply_filters('uwp_profile_gd_post_author_action', '[gd_author_actions text_color="secondary"]');
1081 + $author_actions = do_shortcode( $actions_shortcode );
1082 +
1083 + $new_html = '<div class="row">';
1084 + $new_html .= '<div class="col">' . $post_ratings . '</div>';
1085 + if ( $author_actions ) {
1086 + // add some bootstrap styles
1087 + $author_actions = str_replace(
1088 + array( "gd_user_action", "gd-author-actions", "gd_delete_post", "btn btn-sm text-white" ),
1089 + array( "gd_user_action dropdown-item position-relative", "", "uwp_gd_delete_post", "" ),
1090 + $author_actions
1091 + );
1092 +
1093 + $new_html .= '
1094 + <div class="col-2 text-right">
1095 + <div class="btn-group dropup">
1096 + <a href="#" class="dropdown h5 text-muted m-0" data-' . ( $aui_bs5 ? 'bs-' : '' ) . 'toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1097 + <i class="fas fa-ellipsis-v fa-sm fa-fw"></i>
1098 + </a>
1099 + <div class="dropdown-menu dropdown-menu-right dropdown-caret-0">
1100 + ' . $author_actions . '
1101 + </div>
691 1102 </div>
1103 + </div>
1104 + ';
1105 + }
1106 + $new_html .= '</div>';
692 1107
693 - <div class="uwp-profile-item-summary">
694 - <?php
695 - do_action('uwp_before_profile_listing_summary', $post_id, $user, $post_type);
696 - $excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...'));
697 - echo $excerpt;
698 - do_action('uwp_after_profile_listing_summary', $post_id, $user, $post_type);
699 - ?>
1108 + return $new_html;
1109 + } else {
1110 + return $html;
1111 + }
1112 + }
1113 +
1114 + /**
1115 + * Displays listings
1116 + *
1117 + * @since 1.0.0
1118 + * @package userswp
1119 + *
1120 + * @param object $user User object
1121 + * @param string $post_type Post type
1122 + *
1123 + */
1124 + public function gd_get_listings( $user, $post_type ) {
1125 + if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1126 + self::get_bootstrap_listings( $user, $post_type );
1127 + } else {
1128 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1129 +
1130 + if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1131 + $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1132 + } else {
1133 + $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1134 + }
1135 +
1136 + $args = array(
1137 + 'post_type' => $post_type,
1138 + 'post_status' => $post_status,
1139 + 'posts_per_page' => self::get_items_per_page( 'listings' ),
1140 + 'author' => $user->ID,
1141 + 'paged' => $paged,
1142 + 'uwp_geodir_query' => true
1143 + );
1144 +
1145 + $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
1146 +
1147 + // The Query
1148 + $the_query = new WP_Query( $args );
1149 +
1150 + if ( isset( $the_query->found_posts ) && $the_query->found_posts == 0 ) {
1151 + return;
1152 + }
1153 + ?>
1154 + <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ) ?></h3>
1155 +
1156 + <div class="uwp-profile-item-block">
1157 + <?php
1158 +
1159 + do_action( 'uwp_before_profile_listing_items', $user, $post_type );
1160 + // The Loop
1161 + if ( $the_query->have_posts() ) {
1162 + echo '<ul class="uwp-profile-item-ul">';
1163 + while ( $the_query->have_posts() ) {
1164 + $the_query->the_post();
1165 + $post_id = get_the_ID();
1166 + global $post;
1167 + $post = geodir_get_post_info( $post_id );
1168 + setup_postdata( $post );
1169 +
1170 + if ( empty( $post ) ) {
1171 + continue;
1172 + }
1173 +
1174 + $post_avgratings = geodir_get_post_rating( $post->ID );
1175 + $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1176 + ob_start();
1177 + if ( uwp_is_gdv2() ) {
1178 + geodir_comments_number();
1179 + } else {
1180 + geodir_comments_number( (int) $post->rating_count );
1181 + }
1182 + $n_comments = ob_get_clean();
1183 +
1184 + do_action( 'uwp_before_profile_listing_item', $post_id, $user, $post_type );
1185 + ?>
1186 + <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1187 + <a class="uwp-profile-item-img" href="<?php echo esc_url( get_the_permalink() ); ?>">
1188 + <?php
1189 + if ( has_post_thumbnail() ) {
1190 + $thumb_url = get_the_post_thumbnail_url( get_the_ID(), array( 80, 80 ) );
1191 + } else {
1192 + $thumb_url = uwp_get_default_thumb_uri();
1193 + }
1194 + ?>
1195 + <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo esc_url( $thumb_url ); ?>">
1196 + </a>
1197 +
1198 + <?php do_action( 'uwp_before_profile_listing_title', $post_id, $user, $post_type ); ?>
1199 + <h3 class="uwp-profile-item-title">
1200 + <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a>
1201 + </h3>
1202 + <?php do_action( 'uwp_after_profile_listing_title', $post_id, $user, $post_type ); ?>
1203 +
1204 + <div class="uwp-time-ratings-wrap">
1205 + <?php do_action( 'uwp_before_profile_listing_ratings', $post_id, $user, $post_type ); ?>
1206 + <time class="uwp-profile-item-time published"
1207 + datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1208 + <?php echo esc_html( get_the_date() ); ?>
1209 + </time>
1210 + <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . esc_url( get_comments_link() ) . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1211 + <?php
1212 + if ( ! is_user_logged_in() ) {
1213 + do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
1214 + }
1215 + ?>
1216 + <?php do_action( 'uwp_after_profile_listing_ratings', $post_id, $user, $post_type ); ?>
1217 + </div>
1218 +
1219 + <div class="uwp-profile-item-summary">
1220 + <?php
1221 + do_action( 'uwp_before_profile_listing_summary', $post_id, $user, $post_type );
1222 + $excerpt = strip_shortcodes( wp_trim_words( get_the_excerpt(), 15, '...' ) );
1223 + echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1224 + do_action( 'uwp_after_profile_listing_summary', $post_id, $user, $post_type );
1225 + ?>
1226 + </div>
1227 +
1228 + <div class="uwp-item-actions">
1229 + <?php
1230 + if ( is_user_logged_in() ) {
1231 + geodir_favourite_html( '', $post->ID );
1232 + }
1233 + if ( $post->post_author == get_current_user_id() ) {
1234 + if ( uwp_is_gdv2() ) {
1235 + $href = 'javascript:void(0);';
1236 + $class = '';
1237 + $editlink = geodir_edit_post_link( $post_id );
1238 + $extra = 'onclick="uwp_gd_delete_post(' . $post_id . ');"';
1239 + } else {
1240 + $ajaxlink = geodir_get_ajax_url();
1241 + $href = geodir_getlink( $ajaxlink, array(
1242 + 'geodir_ajax' => 'add_listing',
1243 + 'ajax_action' => 'delete',
1244 + 'pid' => $post->ID
1245 + ), false );
1246 + $class = 'geodir-delete';
1247 + $addplacelink = get_permalink( geodir_add_listing_page_id() );
1248 + $editlink = geodir_getlink( $addplacelink, array( 'pid' => $post->ID ), false );
1249 + $extra = '';
1250 + }
1251 + ?>
1252 +
1253 + <span class="geodir-authorlink clearfix">
1254 +
1255 + <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1256 +
1257 + <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1258 + title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1259 + <?php
1260 + $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1261 + echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
1262 + ?>
1263 + <?php esc_html_e( 'Edit', 'userswp' ); ?>
1264 + </a>
1265 + <a href="<?php echo $href; ?>" <?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="<?php echo esc_attr( $class ); ?>" title="<?php esc_attr_e( 'Delete Listing', 'userswp' ); ?>">
1266 + <?php
1267 + $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times', $post_id, $user, $post_type );
1268 + echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
1269 + ?>
1270 + <?php esc_html_e( 'Delete', 'userswp' ); ?>
1271 + </a>
1272 + <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1273 +
1274 + </span>
1275 +
1276 + <?php } ?>
1277 + </div>
1278 + </li>
1279 + <?php
1280 + do_action( 'uwp_after_profile_listing_item', $post_id, $user, $post_type );
1281 + }
1282 + echo '</ul>';
1283 + /* Restore original Post Data */
1284 + wp_reset_postdata();
1285 + } else {
1286 + echo aui()->alert( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1287 + 'type' => 'info',
1288 + 'content' => esc_html( wp_sprintf( __( "No %s found.", 'userswp' ), geodir_post_type_name( $post_type , true ) ) )
1289 + ) );
1290 + }
1291 + do_action( 'uwp_after_profile_listing_items', $user, $post_type );
1292 +
1293 + do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1294 + ?>
1295 + </div>
1296 + <?php
1297 + }
1298 + }
1299 +
1300 + /**
1301 + * Displays subtab content
1302 + *
1303 + * @package userswp
1304 + *
1305 + * @param object $user User object
1306 + * @param string $post_type Post type
1307 + *
1308 + */
1309 + public function get_bootstrap_listings( $user, $post_type ) {
1310 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1311 +
1312 + if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1313 + $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1314 + } else {
1315 + $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1316 + }
1317 +
1318 + $query_args = array(
1319 + 'post_type' => $post_type,
1320 + 'post_status' => $post_status,
1321 + 'posts_per_page' => self::get_items_per_page( 'listings' ),
1322 + 'author' => $user->ID,
1323 + 'paged' => $paged,
1324 + 'uwp_geodir_query' => true
1325 + );
1326 +
1327 + $query_args = apply_filters( 'uwp_listing_query_args', $query_args, $user, $post_type );
1328 +
1329 + // The Query
1330 + $the_query = new WP_Query( $query_args );
1331 +
1332 + $title = geodir_post_type_name( $post_type , true );
1333 + $found_posts = ! empty( $the_query ) && ! empty( $the_query->found_posts ) ? $the_query->found_posts : 0;
1334 +
1335 + if($found_posts) {
1336 + $widget_args = array(
1337 + 'column_gap_class' => 'mb-4',
1338 + 'row_gap_class' => '',
1339 + 'card_border_class' => 'border-0',
1340 + 'card_shadow_class' => '',
1341 + 'layout' => '3',
1342 + );
1343 +
1344 + $template_args = apply_filters( 'uwp_profile_tab_listings_args', $widget_args );
1345 +
1346 + $gd_layout_class = geodir_convert_listing_view_class( $template_args['layout'] );
1347 + ?>
1348 + <div class="container mb-1">
1349 + <div class="row">
1350 + <div class="col-sm p-0 uwp-loop-posts-title">
1351 + <h3><?php echo esc_html( $title ); ?></h3>
1352 + </div>
1353 + <div class="col p-0 d-sm-block uwp-loop-posts-toolbar">
1354 + <div class="btn-toolbar justify-content-end" role="toolbar" aria-label="Toolbar with button groups">
1355 + <?php
1356 + geodir_list_view_select($post_type);
1357 + ?>
700 1358 </div>
1359 + </div>
1360 + </div>
1361 + </div>
1362 + <div class="geodir-loop-container">
1363 + <div class="row row-cols-1 row-cols-sm-2 geodir-category-list-view <?php echo esc_attr( $gd_layout_class ); ?>">
1364 + <?php
1365 + while ( $the_query->have_posts() ) : $the_query->the_post();
1366 + echo geodir_get_template_html( "bootstrap/content-listing.php", array(
1367 + 'column_gap_class' => $template_args['column_gap_class'],
1368 + 'row_gap_class' => $template_args['row_gap_class'],
1369 + 'card_border_class' => $template_args['card_border_class'],
1370 + 'card_shadow_class' => $template_args['card_shadow_class'],
1371 + 'template_part' => $template_args['card_shadow_class'],
1372 + ) );
1373 + endwhile;
1374 + wp_reset_postdata();
1375 + ?>
1376 + </div>
1377 + </div>
1378 + <?php
1379 + do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1380 + }
1381 + }
701 1382
702 - <div class="uwp-item-actions">
703 - <?php
704 - if (is_user_logged_in()) {
705 - geodir_favourite_html( '', $post->ID );
706 - }
707 - if ($post->post_author == get_current_user_id()) {
708 - if($this->uwp_is_gdv2()) {
709 - $href = 'javascript:void(0);';
710 - $class = '';
711 - $editlink = geodir_edit_post_link($post_id);
712 - $extra = 'onclick="gd_delete_post('.$post_id.');"';
713 - } else {
714 - $ajaxlink = geodir_get_ajax_url();
715 - $href = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false);
716 - $class = 'geodir-delete';
717 - $addplacelink = get_permalink(geodir_add_listing_page_id());
718 - $editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false);
719 - $extra = '';
720 - }
721 - ?>
1383 + /**
1384 + * Adjust the post footer info for GD posts.
1385 + *
1386 + * @param $html
1387 + *
1388 + * @return string
1389 + */
1390 + public function reviews_footer( $html, $comment ) {
1391 + if ( ! empty( $comment->post_type ) && geodir_is_gd_post_type( $comment->post_type ) ) {
1392 + $comment_rating = geodir_get_comment_rating( $comment->ID );
1393 + $comment_rating_html = geodir_get_rating_stars( $comment_rating, $comment->comment_post_ID );
722 1394
723 - <span class="geodir-authorlink clearfix">
1395 + $new_html = '<div class="row">';
1396 + $new_html .= '<div class="col">' . $comment_rating_html . '</div>';
1397 + $comment_link = '<a href="' . get_comment_link( $comment->comment_ID ) . '" class="btn btn-sm btn-outline-primary float-right"><i class="fas fa-comments"></i> ' . esc_attr__( "View", "userswp" ) . '</a>';
724 1398
725 - <?php do_action('geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
1399 + $new_html .= '<div class="col">' . $comment_link . '</div>';
726 1400
727 - <a href="<?php echo esc_url($editlink); ?>" class="geodir-edit"
728 - title="<?php _e('Edit Listing', 'userswp'); ?>">
1401 + $new_html .= '</div>';
1402 +
1403 + return $new_html;
1404 + } else {
1405 + return $html;
1406 + }
1407 + }
1408 +
1409 + /**
1410 + * Displays reviews
1411 + *
1412 + * @since 1.0.0
1413 + * @package userswp
1414 + *
1415 + * @param object $user User object
1416 + * @param string $post_type Post type
1417 + *
1418 + */
1419 + public function gd_get_reviews( $user, $post_type ) {
1420 + if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1421 + self::get_bootstrap_reviews( $user, $post_type );
1422 + } else {
1423 +
1424 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1425 + $limit = self::get_items_per_page( 'reviews' );
1426 + $offset = ( $paged - 1 ) * $limit;
1427 +
1428 + $total_reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, true, $offset, $limit );
1429 + $maximum_pages = ceil( $total_reviews / $limit );
1430 +
1431 + $reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, false, $offset, $limit );
1432 +
1433 + // The Loop
1434 + if ( !$reviews ) {
1435 + return;
1436 + }
1437 + do_action( 'uwp_before_profile_reviews_items', $user, $post_type );
1438 + ?>
1439 + <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ); ?></h3>
1440 +
1441 + <div class="uwp-profile-item-block">
1442 + <ul class="uwp-profile-item-ul">
1443 + <?php
1444 + foreach ( $reviews as $review ) {
1445 + $rating = 0;
1446 + if ( ! empty( $review ) ) {
1447 + $rating = geodir_get_post_rating( $review->post_id );
1448 + }
1449 + do_action( 'uwp_before_profile_reviews_item', $review->comment_id, $user, $post_type );
1450 + ?>
1451 + <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1452 + <a class="uwp-profile-item-img"
1453 + href="<?php echo esc_url( get_comment_link( $review->comment_id ) ); ?>">
1454 + <?php
1455 + if ( has_post_thumbnail( $review->post_id ) ) {
1456 + $thumb_url = get_the_post_thumbnail_url( $review->post_id, array( 80, 80 ) );
1457 + } else {
1458 + $thumb_url = uwp_get_default_thumb_uri();
1459 + }
1460 + ?>
1461 + <img class="uwp-profile-item-alignleft uwp-profile-item-thumb"
1462 + src="<?php echo esc_url( $thumb_url ); ?>">
1463 + </a>
1464 +
1465 + <?php do_action( 'uwp_before_profile_reviews_title', $review->comment_id, $user, $post_type ); ?>
1466 + <h3 class="uwp-profile-item-title">
1467 + <a href="<?php echo esc_url( get_comment_link( $review->comment_id ) ); ?>"><?php echo esc_html( get_the_title( $review->post_id ) ); ?></a>
1468 + </h3>
1469 + <?php do_action( 'uwp_after_profile_reviews_title', $review->comment_id, $user, $post_type ); ?>
1470 +
1471 + <div class="uwp-time-ratings-wrap">
1472 + <?php do_action( 'uwp_before_profile_reviews_ratings', $review->comment_id, $user, $post_type ); ?>
1473 + <time class="uwp-profile-item-time published"
1474 + datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1475 + <?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( get_comment_date( "", $review->comment_id ) ) ) ); ?>
1476 + </time>
1477 + <?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars( $rating, $review->comment_id ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1478 + <?php do_action( 'uwp_after_profile_reviews_ratings', $review->comment_id, $user, $post_type ); ?>
1479 + </div>
1480 + <div class="uwp-profile-item-summary">
1481 + <?php
1482 + do_action( 'uwp_before_profile_reviews_summary', $review->comment_id, $user, $post_type );
1483 + $excerpt = strip_shortcodes( wp_trim_words( get_comment_excerpt( $review->comment_id ), 15, '...' ) );
1484 + echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1485 + do_action( 'uwp_after_profile_reviews_summary', $review->comment_id, $user, $post_type );
1486 + ?>
1487 + </div>
1488 + <div class="uwp-item-actions">
1489 + <?php
1490 + if ( is_user_logged_in() ) {
1491 + geodir_favourite_html( '', $review->post_id );
1492 + }
1493 + if ( get_post_field( 'post_author', $review->post_id ) == get_current_user_id() ) {
1494 + if ( uwp_is_gdv2() ) {
1495 + $href = 'javascript:void(0);';
1496 + $class = '';
1497 + $editlink = geodir_edit_post_link( $review->post_id );
1498 + $extra = 'onclick="uwp_gd_delete_post(' . $review->post_id . ');"';
1499 + } else {
1500 + $ajaxlink = geodir_get_ajax_url();
1501 + $href = geodir_getlink( $ajaxlink, array(
1502 + 'geodir_ajax' => 'add_listing',
1503 + 'ajax_action' => 'delete',
1504 + 'pid' => $review->post_id
1505 + ), false );
1506 + $class = 'geodir-delete';
1507 + $addplacelink = get_permalink( geodir_add_listing_page_id() );
1508 + $editlink = geodir_getlink( $addplacelink, array( 'pid' => $review->post_id ), false );
1509 + $extra = '';
1510 + }
1511 + ?>
1512 +
1513 + <span class="geodir-authorlink clearfix">
1514 +
1515 + <?php do_action( 'geodir_before_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
1516 +
1517 + <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1518 + title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
729 1519 <?php
730 - $geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fas fa-edit');
731 - echo '<i class="' . $geodir_listing_edit_icon . '"></i>';
1520 + $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1521 + echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
732 1522 ?>
733 - <?php _e('Edit', 'userswp'); ?>
1523 + <?php esc_html_e( 'Edit', 'userswp' ); ?>
734 1524 </a>
735 - <a href="<?php echo $href; ?>" <?php echo $extra; ?>class="<?php echo $class; ?>"
736 - title="<?php _e('Delete Listing', 'userswp'); ?>">
1525 + <a href="<?php echo $href; ?>" <?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1526 + class="<?php echo esc_attr( $class ); ?>"
1527 + title="<?php esc_attr_e( 'Delete Listing', 'userswp' ); ?>">
737 1528 <?php
738 - $geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fas fa-times', $post_id, $user, $post_type);
739 - echo '<i class="' . $geodir_listing_delete_icon . '"></i>';
1529 + $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times' );
1530 + echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
740 1531 ?>
741 - <?php _e('Delete', 'userswp'); ?>
1532 + <?php esc_html_e( 'Delete', 'userswp' ); ?>
742 1533 </a>
743 - <?php do_action('geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
744 1534
1535 + <?php do_action( 'geodir_after_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
1536 +
745 1537 </span>
746 1538
747 - <?php } ?>
748 - </div>
749 - </li>
750 - <?php
751 - do_action('uwp_after_profile_listing_item', $post_id, $user, $post_type);
752 - }
753 - echo '</ul>';
754 - /* Restore original Post Data */
755 - wp_reset_postdata();
756 - } else {
757 - echo sprintf( __( "No %s found.", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
758 - }
759 - do_action('uwp_after_profile_listing_items', $user, $post_type);
1539 + <?php } ?>
1540 + </div>
1541 + </li>
1542 + <?php
1543 + do_action( 'uwp_after_profile_reviews_item', $review->comment_id, $user, $post_type );
1544 + }
1545 + ?>
1546 + </ul>
760 1547
761 - do_action('uwp_profile_pagination', $the_query->max_num_pages);
762 - ?>
763 - </div>
764 - <?php
765 - }
1548 + <?php
1549 + /* Restore original Post Data */
1550 + wp_reset_postdata();
766 1551
767 - public function gd_get_reviews($user, $post_type) {
768 - $gd_post_types = geodir_get_posttypes('array');
769 - ?>
770 - <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3>
1552 + do_action( 'uwp_after_profile_reviews_items', $user, $post_type );
771 1553
772 - <div class="uwp-profile-item-block">
773 - <?php
774 - $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
775 - $limit = uwp_get_option('profile_no_of_items', 10);
776 - $offset = ($paged - 1) * $limit;
1554 + do_action( 'uwp_profile_pagination', $maximum_pages );
1555 + ?>
1556 + </div>
1557 + <?php
1558 + }
1559 + }
777 1560
778 - $total_reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true, $offset, $limit);
779 - $maximum_pages = ceil($total_reviews / $limit);
1561 + /**
1562 + * Displays reviews in bootstrap layout
1563 + *
1564 + * @since 1.0.0
1565 + * @package userswp
1566 + *
1567 + * @param object $user User object
1568 + * @param string $post_type Post type
1569 + *
1570 + */
1571 + public function get_bootstrap_reviews( $user, $post_type ) {
1572 + global $userswp, $geodir_post_type;
1573 + $geodir_post_type = $post_type;
1574 + $args = array();
780 1575
781 - $reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, false, $offset, $limit);
1576 + $args['template_args']['title'] = __( "Reviews", 'userswp' );
782 1577
783 - do_action('uwp_before_profile_reviews_items', $user, $post_type);
784 - // The Loop
785 - if ($reviews) {
786 - echo '<ul class="uwp-profile-item-ul">';
787 - foreach ($reviews as $review) {
788 - $rating = 0;
789 - if (!empty($review))
790 - $rating = geodir_get_post_rating($review->post_id);
791 - do_action('uwp_before_profile_reviews_item', $review->comment_id, $user, $post_type);
792 - ?>
793 - <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-'.$post_type; ?>">
794 - <a class="uwp-profile-item-img" href="<?php echo get_comment_link($review->comment_id); ?>">
795 - <?php
796 - if ( has_post_thumbnail($review->post_id) ) {
797 - $thumb_url = get_the_post_thumbnail_url($review->post_id, array(80, 80));
798 - } else {
799 - $thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png";
800 - }
801 - ?>
802 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
803 - </a>
1578 + $userswp->profile->get_profile_comments( $user, $post_type, $args );
804 1579
805 - <?php do_action('uwp_before_profile_reviews_title', $review->comment_id, $user, $post_type); ?>
806 - <h3 class="uwp-profile-item-title">
807 - <a href="<?php echo get_comment_link($review->comment_id); ?>"><?php echo get_the_title($review->post_id); ?></a>
808 - </h3>
809 - <?php do_action('uwp_after_profile_reviews_title', $review->comment_id, $user, $post_type); ?>
1580 + $geodir_post_type = '';
810 1581
811 - <div class="uwp-time-ratings-wrap">
812 - <?php do_action('uwp_before_profile_reviews_ratings', $review->comment_id, $user, $post_type); ?>
813 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
814 - <?php echo date_i18n(get_option('date_format'), strtotime(get_comment_date("", $review->comment_id))); ?>
815 - </time>
816 - <?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars($rating, $review->comment_id) . '</div>'; ?>
817 - <?php do_action('uwp_after_profile_reviews_ratings', $review->comment_id, $user, $post_type); ?>
818 - </div>
819 - <div class="uwp-profile-item-summary">
820 - <?php
821 - do_action('uwp_before_profile_reviews_summary', $review->comment_id, $user, $post_type);
822 - $excerpt = strip_shortcodes(wp_trim_words(get_comment_excerpt($review->comment_id), 15, '...'));
823 - echo $excerpt;
824 - do_action('uwp_after_profile_reviews_summary', $review->comment_id, $user, $post_type);
825 - ?>
826 - </div>
827 - </li>
828 - <?php
829 - do_action('uwp_after_profile_reviews_item', $review->comment_id, $user, $post_type);
830 - }
831 - echo '</ul>';
832 - /* Restore original Post Data */
833 - wp_reset_postdata();
834 - } else {
835 - echo sprintf( __( "No %s found.", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
836 - }
1582 + }
837 1583
838 - do_action('uwp_after_profile_reviews_items', $user, $post_type);
1584 + /**
1585 + * Displays favourite listings
1586 + *
1587 + * @since 1.0.0
1588 + * @package userswp
1589 + *
1590 + * @param object $user User object
1591 + * @param string $post_type Post type
1592 + *
1593 + */
1594 + public function gd_get_favorites( $user, $post_type ) {
1595 + if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1596 + self::get_bootstrap_favorites( $user, $post_type );
1597 + } else {
1598 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
839 1599
840 - do_action('uwp_profile_pagination', $maximum_pages);
841 - ?>
842 - </div>
843 - <?php
844 - }
1600 + $user_fav_posts = geodir_get_user_favourites( $user->ID );
845 1601
846 - public function gd_get_favorites($user, $post_type) {
847 - $gd_post_types = geodir_get_posttypes('array');
848 - ?>
849 - <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3>
1602 + if ( ! $user_fav_posts ) {
1603 + return;
1604 + }
850 1605
851 - <div class="uwp-profile-item-block">
852 - <?php
853 - $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
1606 + if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1607 + $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1608 + } else {
1609 + $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1610 + }
854 1611
855 - $user_fav_posts = geodir_get_user_favourites($user->ID);
1612 + $args = array(
1613 + 'post_type' => $post_type,
1614 + 'post_status' => $post_status,
1615 + 'posts_per_page' => self::get_items_per_page( 'favorites' ),
1616 + 'post__in' => $user_fav_posts,
1617 + 'paged' => $paged,
1618 + 'uwp_geodir_query' => true
1619 + );
856 1620
857 - if ($user_fav_posts) {
858 - $args = array(
859 - 'post_type' => $post_type,
860 - 'post_status' => array('publish'),
861 - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
862 - 'post__in' => $user_fav_posts,
863 - 'paged' => $paged,
864 - );
1621 + $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
865 1622
866 - if (get_current_user_id() == $user->ID) {
867 - $args['post_status'] = array('publish', 'draft', 'private', 'pending', 'gd-closed', 'gd-expired');
868 - }
1623 + // The Query
1624 + $the_query = new WP_Query( $args );
869 1625
870 - // The Query
871 - $the_query = new WP_Query($args);
1626 + if ( isset( $the_query->found_posts ) && $the_query->found_posts == 0 ) {
1627 + return;
1628 + }
1629 + ?>
1630 + <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ) ?></h3>
872 1631
873 - do_action('uwp_before_profile_favourite_items', $user, $post_type);
874 - // The Loop
875 - if ($the_query->have_posts()) {
876 - echo '<ul class="uwp-profile-item-ul">';
877 - while ($the_query->have_posts()) {
878 - $the_query->the_post();
879 - $post_id = get_the_ID();
880 - global $post;
881 - $post = geodir_get_post_info($post_id);
882 - setup_postdata($post);
883 - $post_avgratings = geodir_get_post_rating($post->ID);
884 - $post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID);
885 - ob_start();
886 - geodir_comments_number($post->rating_count);
887 - $n_comments = ob_get_contents();
888 - ob_end_clean();
889 - do_action('uwp_before_profile_favourite_item', $post_id, $user, $post_type);
890 - ?>
891 - <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-'.$post_type; ?>">
892 - <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>">
893 - <?php
894 - if (has_post_thumbnail()) {
895 - $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80));
896 - } else {
897 - $thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png";
898 - }
899 - ?>
900 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
1632 + <div class="uwp-profile-item-block">
1633 + <?php
1634 + do_action( 'uwp_before_profile_favourite_items', $user, $post_type );
1635 + // The Loop
1636 + if ( $the_query->have_posts() ) {
1637 + echo '<ul class="uwp-profile-item-ul">';
1638 + while ( $the_query->have_posts() ) {
1639 + $the_query->the_post();
1640 + $post_id = get_the_ID();
1641 + global $post;
1642 + $post = geodir_get_post_info( $post_id );
1643 + setup_postdata( $post );
1644 + $post_avgratings = geodir_get_post_rating( $post->ID );
1645 + $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1646 + ob_start();
1647 + if ( uwp_is_gdv2() ) {
1648 + geodir_comments_number();
1649 + } else {
1650 + geodir_comments_number( (int) $post->rating_count );
1651 + }
1652 + $n_comments = ob_get_clean();
1653 + do_action( 'uwp_before_profile_favourite_item', $post_id, $user, $post_type );
1654 + ?>
1655 + <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1656 + <a class="uwp-profile-item-img" href="<?php echo esc_url( get_the_permalink() ); ?>">
1657 + <?php
1658 + if ( has_post_thumbnail() ) {
1659 + $thumb_url = get_the_post_thumbnail_url( get_the_ID(), array( 80, 80 ) );
1660 + } else {
1661 + $thumb_url = uwp_get_default_thumb_uri();
1662 + }
1663 + ?>
1664 + <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo esc_url( $thumb_url ); ?>">
901 1665 </a>
902 1666
903 - <?php do_action('uwp_before_profile_favourite_title', $post_id, $user, $post_type); ?>
1667 + <?php do_action( 'uwp_before_profile_favourite_title', $post_id, $user, $post_type ); ?>
904 1668 <h3 class="uwp-profile-item-title">
905 - <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
1669 + <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a>
906 1670 </h3>
907 - <?php do_action('uwp_after_profile_favourite_title', $post_id, $user, $post_type); ?>
1671 + <?php do_action( 'uwp_after_profile_favourite_title', $post_id, $user, $post_type ); ?>
908 1672
909 1673 <div class="uwp-time-ratings-wrap">
910 - <?php do_action('uwp_before_profile_favourite_ratings', $post_id, $user, $post_type); ?>
911 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
912 - <?php echo get_the_date(); ?>
1674 + <?php do_action( 'uwp_before_profile_favourite_ratings', $post_id, $user, $post_type ); ?>
1675 + <time class="uwp-profile-item-time published"
1676 + datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1677 + <?php echo get_the_date(); ?>
913 1678 </time>
914 - <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?>
915 - <?php
916 - if (!is_user_logged_in()) {
917 - do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
918 - }
919 - ?>
920 - <?php do_action('uwp_after_profile_favourite_ratings', $post_id, $user, $post_type); ?>
1679 + <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . esc_url( get_comments_link() ) . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1680 + <?php
1681 + if ( ! is_user_logged_in() ) {
1682 + do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
1683 + }
1684 + ?>
1685 + <?php do_action( 'uwp_after_profile_favourite_ratings', $post_id, $user, $post_type ); ?>
921 1686 </div>
922 1687
923 1688 <div class="uwp-profile-item-summary">
924 - <?php
925 - do_action('uwp_before_profile_favourite_summary', $post_id, $user, $post_type);
926 - $excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...'));
927 - echo $excerpt;
928 - do_action('uwp_after_profile_favourite_summary', $post_id, $user, $post_type);
929 - ?>
1689 + <?php
1690 + do_action( 'uwp_before_profile_favourite_summary', $post_id, $user, $post_type );
1691 + $excerpt = strip_shortcodes( wp_trim_words( get_the_excerpt(), 15, '...' ) );
1692 + echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1693 + do_action( 'uwp_after_profile_favourite_summary', $post_id, $user, $post_type );
1694 + ?>
930 1695 </div>
931 1696
932 1697 <div class="uwp-item-actions">
933 - <?php
934 - if (is_user_logged_in()) {
935 - geodir_favourite_html( '', $post->ID );
936 - }
937 - if ($post->post_author == get_current_user_id()) {
938 - if($this->uwp_is_gdv2()) {
939 - $href = 'javascript:void(0);';
940 - $class = '';
941 - $editlink = geodir_edit_post_link($post_id);
942 - $extra = 'onclick="gd_delete_post('.$post_id.');"';
943 - } else {
944 - $ajaxlink = geodir_get_ajax_url();
945 - $href = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false);
946 - $class = 'geodir-delete';
947 - $addplacelink = get_permalink(geodir_add_listing_page_id());
948 - $editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false);
949 - $extra = '';
950 - }
951 - ?>
1698 + <?php
1699 + if ( is_user_logged_in() ) {
1700 + geodir_favourite_html( '', $post->ID );
1701 + }
1702 + if ( $post->post_author == get_current_user_id() ) {
1703 + if ( uwp_is_gdv2() ) {
1704 + $href = 'javascript:void(0);';
1705 + $class = '';
1706 + $editlink = geodir_edit_post_link( $post_id );
1707 + $extra = 'onclick="uwp_gd_delete_post(' . $post_id . ');"';
1708 + } else {
1709 + $ajaxlink = geodir_get_ajax_url();
1710 + $href = geodir_getlink( $ajaxlink, array(
1711 + 'geodir_ajax' => 'add_listing',
1712 + 'ajax_action' => 'delete',
1713 + 'pid' => $post->ID
1714 + ), false );
1715 + $class = 'geodir-delete';
1716 + $addplacelink = get_permalink( geodir_add_listing_page_id() );
1717 + $editlink = geodir_getlink( $addplacelink, array( 'pid' => $post->ID ), false );
1718 + $extra = '';
1719 + }
1720 + ?>
952 1721
953 1722 <span class="geodir-authorlink clearfix">
954 1723
955 - <?php do_action('geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
1724 + <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
956 1725
957 - <a href="<?php echo esc_url($editlink); ?>" class="geodir-edit"
958 - title="<?php _e('Edit Listing', 'userswp'); ?>">
1726 + <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1727 + title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
959 1728 <?php
960 - $geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fas fa-edit');
961 - echo '<i class="' . $geodir_listing_edit_icon . '"></i>';
1729 + $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1730 + echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
962 1731 ?>
963 - <?php _e('Edit', 'userswp'); ?>
1732 + <?php esc_html_e( 'Edit', 'userswp' ); ?>
964 1733 </a>
965 - <a href="<?php echo $href; ?>" <?php echo $extra; ?> class="<?php echo $class; ?>"
966 - title="<?php _e('Delete Listing', 'userswp'); ?>">
1734 + <a href="<?php echo $href; ?>" <?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1735 + class="<?php echo esc_attr( $class ); ?>"
1736 + title="<?php esc_attr_e( 'Delete Listing', 'userswp' ); ?>">
967 1737 <?php
968 - $geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fas fa-times');
969 - echo '<i class="' . $geodir_listing_delete_icon . '"></i>';
1738 + $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times' );
1739 + echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
970 1740 ?>
971 - <?php _e('Delete', 'userswp'); ?>
1741 + <?php esc_html_e( 'Delete', 'userswp' ); ?>
972 1742 </a>
973 1743
974 - <?php do_action('geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type); ?>
1744 + <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
975 1745
976 1746 </span>
977 1747
978 - <?php } ?>
1748 + <?php } ?>
979 1749 </div>
980 1750 </li>
981 - <?php
982 - do_action('uwp_after_profile_favourite_item', $post_id, $user, $post_type);
983 - }
984 - echo '</ul>';
985 - /* Restore original Post Data */
986 - wp_reset_postdata();
987 - } else {
988 - echo sprintf( __( "No %s found", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
989 - }
1751 + <?php
1752 + do_action( 'uwp_after_profile_favourite_item', $post_id, $user, $post_type );
1753 + }
1754 + echo '</ul>';
1755 + /* Restore original Post Data */
1756 + wp_reset_postdata();
1757 + }
990 1758
991 - do_action('uwp_after_profile_favourite_items', $user, $post_type);
1759 + do_action( 'uwp_after_profile_favourite_items', $user, $post_type );
992 1760
993 - do_action('uwp_profile_pagination', $the_query->max_num_pages);
1761 + do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1762 + ?>
1763 + </div>
1764 + <?php
1765 + }
1766 + }
1767 +
1768 + /**
1769 + * Displays favourite listings in bootstrap layout
1770 + *
1771 + * @since 1.0.0
1772 + * @package userswp
1773 + *
1774 + * @param object $user User object
1775 + * @param string $post_type Post type
1776 + *
1777 + */
1778 + public function get_bootstrap_favorites($user, $post_type)
1779 + {
1780 + $favorite_ids = geodir_get_user_favourites($user->ID);
1781 + if ($favorite_ids) {
1782 +
1783 + $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
1784 +
1785 + if (!empty($user) && !empty($user->ID) && (int)get_current_user_id() == (int)$user->ID) {
1786 + $post_status = geodir_get_post_stati('author-archive', array('post_type' => $post_type));
994 1787 } else {
995 - echo sprintf( __( "No %s found.", 'userswp' ), $gd_post_types[$post_type]['labels']['name']);
1788 + $post_status = geodir_get_post_stati('public', array('post_type' => $post_type));
996 1789 }
997 - ?>
998 - </div>
999 - <?php
1000 - }
1001 1790
1002 - public function get_gd_login_url($url, $args) {
1003 - $register_page = uwp_get_page_id('register_page', false);
1004 - $login_page = uwp_get_page_id('login_page', false);
1005 - $forgot_page = uwp_get_page_id('forgot_page', false);
1006 - $reset_page = uwp_get_page_id('reset_page', false);
1791 + $args = array(
1792 + 'post_type' => $post_type,
1793 + 'post_status' => $post_status,
1794 + 'posts_per_page' => self::get_items_per_page( 'favorites' ),
1795 + 'paged' => $paged,
1796 + 'post__in' => $favorite_ids,
1797 + 'uwp_geodir_query' => true
1798 + );
1007 1799
1008 - if (!empty($args)) {
1009 - if (isset($args['signup']) && $args['signup']) {
1010 - $page_id = $register_page;
1011 - } elseif (isset($args['forgot']) && $args['forgot']) {
1012 - $page_id = $forgot_page;
1013 - } elseif (isset($args['reset']) && $args['reset']) {
1014 - $page_id = $reset_page;
1015 - } else {
1016 - $page_id = $login_page;
1800 + $args = apply_filters('uwp_listing_query_args', $args, $user, $post_type);
1801 +
1802 + // The Query
1803 + $the_query = new WP_Query($args);
1804 +
1805 + $args['template_args']['the_query'] = $the_query;
1806 + $title = geodir_post_type_name($post_type, true);
1807 + $found_posts = !empty($the_query) && !empty($the_query->found_posts) ? $the_query->found_posts : 0;
1808 +
1809 + if ($found_posts) {
1810 + $widget_args = array(
1811 + 'column_gap_class' => 'mb-4',
1812 + 'row_gap_class' => '',
1813 + 'card_border_class' => 'border-0',
1814 + 'card_shadow_class' => '',
1815 + 'layout' => '3',
1816 + );
1817 +
1818 + $template_args = apply_filters('uwp_profile_tab_listings_args', $widget_args);
1819 + $gd_layout_class = geodir_convert_listing_view_class( $template_args['layout'] );
1820 + ?>
1821 + <div class="container mb-1">
1822 + <div class="row">
1823 + <div class="col-sm p-0 uwp-loop-posts-title">
1824 + <h3><?php echo esc_html($title); ?></h3>
1825 + </div>
1826 + <div class="col p-0 d-sm-block uwp-loop-posts-toolbar">
1827 + <div class="btn-toolbar justify-content-end" role="toolbar" aria-label="Toolbar with button groups">
1828 + <?php geodir_list_view_select($post_type); ?>
1829 + </div>
1830 + </div>
1831 + </div>
1832 + </div>
1833 + <div class="geodir-loop-container">
1834 + <div class="row row-cols-1 row-cols-sm-2 geodir-category-list-view <?php echo esc_attr( $gd_layout_class ); ?>">
1835 + <?php
1836 + while ($the_query->have_posts()) : $the_query->the_post();
1837 + echo geodir_get_template_html("bootstrap/content-listing.php", array(
1838 + 'column_gap_class' => $template_args['column_gap_class'],
1839 + 'row_gap_class' => $template_args['row_gap_class'],
1840 + 'card_border_class' => $template_args['card_border_class'],
1841 + 'card_shadow_class' => $template_args['card_shadow_class'],
1842 + ));
1843 + endwhile;
1844 + wp_reset_postdata();
1845 + ?>
1846 + </div>
1847 + </div>
1848 + <?php
1849 + do_action('uwp_profile_pagination', $the_query->max_num_pages);
1017 1850 }
1018 - } else {
1019 - $page_id = $login_page;
1020 1851 }
1021 - if ($page_id) {
1022 - $uwp_url = get_permalink($page_id);
1852 + }
1023 1853
1024 - if (strpos($url, 'redirect_add_listing') !== false) {
1025 - $parsed = wp_parse_url($url);
1026 - parse_str($parsed['query'], $query);
1027 - $uwp_url = add_query_arg( array(
1028 - 'redirect_to' => $query['redirect_add_listing'],
1029 - ), $uwp_url );
1030 - }
1854 + /**
1855 + * Returns login URL for GD V1 login form
1856 + *
1857 + * @since 1.0.0
1858 + * @package userswp
1859 + *
1860 + * @param string $url
1861 + * @param array $args
1862 + *
1863 + * @return mixed
1864 + */
1865 + public function get_gd_login_url( $url, $args ) {
1866 + if ( ! uwp_is_gdv2() ) {
1867 + return $url;
1868 + }
1031 1869
1032 - if(isset($args['redirect_to']) && !empty($args['redirect_to'])){
1033 - $uwp_url = add_query_arg( array(
1034 - 'redirect_to' => $args['redirect_to'],
1035 - ), $uwp_url );
1036 - }
1870 + $register_page = uwp_get_page_id( 'register_page', false );
1871 + $login_page = uwp_get_page_id( 'login_page', false );
1872 + $forgot_page = uwp_get_page_id( 'forgot_page', false );
1873 + $reset_page = uwp_get_page_id( 'reset_page', false );
1037 1874
1038 - $url = $uwp_url;
1039 - }
1040 - return $url;
1041 - }
1875 + if ( ! empty( $args ) ) {
1876 + if ( isset( $args['signup'] ) && $args['signup'] ) {
1877 + $page_id = $register_page;
1878 + } elseif ( isset( $args['forgot'] ) && $args['forgot'] ) {
1879 + $page_id = $forgot_page;
1880 + } elseif ( isset( $args['reset'] ) && $args['reset'] ) {
1881 + $page_id = $reset_page;
1882 + } else {
1883 + $page_id = $login_page;
1884 + }
1885 + } else {
1886 + $page_id = $login_page;
1887 + }
1888 + if ( $page_id ) {
1889 + $uwp_url = get_permalink( $page_id );
1042 1890
1043 - public function geodir_uwp_author_redirect() {
1044 - if ( ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1045 - $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
1891 + if ( strpos( $url, 'redirect_add_listing' ) !== false ) {
1892 + $parsed = wp_parse_url( $url );
1893 + parse_str( $parsed['query'], $query );
1894 + $uwp_url = add_query_arg( array(
1895 + 'redirect_to' => $query['redirect_add_listing'],
1896 + ), $uwp_url );
1897 + }
1046 1898
1047 - if ( !empty( $author ) && ! empty( $author->ID ) ) {
1048 - $favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false;
1049 - $post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL;
1899 + if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
1900 + $uwp_url = add_query_arg( array(
1901 + 'redirect_to' => $args['redirect_to'],
1902 + ), $uwp_url );
1903 + }
1050 1904
1051 - $author_id = $author->ID;
1052 - $author_link = uwp_build_profile_tab_url( $author_id );
1053 - $gd_post_types = geodir_get_posttypes( 'array' );
1905 + $url = $uwp_url;
1906 + }
1054 1907
1055 - if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1056 - if ( $favourite ) {
1057 - $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1908 + return $url;
1909 + }
1058 1910
1059 - if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1060 - $author_link = uwp_build_profile_tab_url( $author_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] );
1061 - } else {
1062 - return; // Do not redirect to dashboard CPT favorites.
1063 - }
1064 - } else {
1065 - $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
1066 -
1067 - if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1068 - $author_link = uwp_build_profile_tab_url( $author_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] );
1069 - } else {
1070 - return; // Do not redirect to dashboard CPT listings.
1071 - }
1072 - }
1073 - }
1911 + /**
1912 + * GD author redirect
1913 + *
1914 + * @since 1.0.0
1915 + * @package userswp
1916 + *
1917 + * @return mixed
1918 + */
1919 + public function geodir_uwp_author_redirect() {
1920 + if ( ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1921 + $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
1074 1922
1075 - wp_redirect($author_link);
1076 - exit;
1077 - }
1078 - }
1079 - return;
1080 - }
1923 + if ( ! empty( $author ) && ! empty( $author->ID ) ) {
1924 + $favourite = isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' ? true : false;
1925 + $post_type = isset( $_REQUEST['stype'] ) ? esc_attr( $_REQUEST['stype'] ) : null;
1081 1926
1082 - public function gd_is_listings_tab() {
1083 - global $wp_query;
1084 - if (is_page() && class_exists('UsersWP')) {
1085 - $profile_page = uwp_get_page_id('profile_page', false);
1086 - if ($profile_page) {
1087 - if (isset($wp_query->query_vars['uwp_profile'])
1088 - && isset($wp_query->query_vars['uwp_tab'])
1089 - && ($wp_query->query_vars['uwp_tab'] == 'listings' || $wp_query->query_vars['uwp_tab'] == 'favorites')
1090 - ) {
1927 + $author_id = $author->ID;
1928 + $author_link = uwp_build_profile_tab_url( $author_id );
1929 + $gd_post_types = geodir_get_posttypes( 'array' );
1091 1930
1092 - return true;
1931 + if ( ! empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1932 + if ( $favourite ) {
1933 + $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1093 1934
1094 - }
1095 - }
1096 - }
1097 - return false;
1098 - }
1935 + if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1936 + $author_link = uwp_build_profile_tab_url( $author_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] );
1937 + } else {
1938 + return; // Do not redirect to dashboard CPT favorites.
1939 + }
1940 + } else {
1941 + $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
1099 1942
1100 - public function geodir_post_status_is_author_page($value) {
1101 - return $value || $this->gd_is_listings_tab();
1102 - }
1943 + if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1944 + $author_link = uwp_build_profile_tab_url( $author_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] );
1945 + } else {
1946 + return; // Do not redirect to dashboard CPT listings.
1947 + }
1948 + }
1949 + }
1103 1950
1104 - public function geodir_add_post_status_author_page() {
1105 - global $wpdb, $post;
1951 + wp_redirect( $author_link );
1952 + exit;
1953 + }
1954 + }
1106 1955
1107 - $html = '';
1108 - if (get_current_user_id()) {
1109 - if ($this->gd_is_listings_tab() && !empty($post) && isset($post->post_author) && $post->post_author == get_current_user_id()) {
1956 + return;
1957 + }
1110 1958
1111 - // we need to query real status direct as we dynamically change the status for author on author page so even non author status can view them.
1112 - $real_status = $wpdb->get_var("SELECT post_status from $wpdb->posts WHERE ID=$post->ID");
1113 - $status = "<strong>(";
1114 - $status_icon = '<i class="fas fa-play"></i>';
1115 - switch ($real_status){
1116 - case 'publish' :
1117 - $status .= __('Published', 'userswp');
1118 - break;
1119 - case 'pending' :
1120 - $status .= __('Pending', 'userswp');
1121 - break;
1122 - case 'gd-closed' :
1123 - $status .= __('Closed', 'userswp');
1124 - break;
1125 - case 'gd-expired' :
1126 - $status .= __('Expired', 'userswp');
1127 - break;
1128 - default :
1129 - $status .= __('Not published', 'userswp');
1130 - break;
1131 - }
1132 - $status .= ")</strong>";
1959 + /**
1960 + * Checks if listing author page
1961 + *
1962 + * @since 1.0.0
1963 + * @package userswp
1964 + *
1965 + * @param string $value
1966 + *
1967 + * @return mixed
1968 + */
1969 + public function geodir_post_status_is_author_page( $value ) {
1970 + return $value || $this->gd_is_listings_tab();
1971 + }
1133 1972
1134 - $html = '<span class="geodir-post-status">' . $status_icon . ' <font class="geodir-status-label">' . __('Status: ', 'userswp') . '</font>' . $status . '</span>';
1135 - }
1136 - }
1973 + /**
1974 + * Check if listing tab
1975 + *
1976 + * @since 1.0.0
1977 + * @package userswp
1978 + *
1979 + * @return bool
1980 + */
1981 + public function gd_is_listings_tab() {
1982 + global $wp_query, $uwp_profile_doing_tab, $uwp_profile_first_tab, $uwp_profile_tabs_array;
1137 1983
1138 - if ($html != '') {
1139 - echo apply_filters('geodir_filter_status_text_on_author_page', $html);
1140 - }
1141 - }
1984 + //if ( is_uwp_profile_page() ) {
1985 + if ( is_page() && isset( $wp_query->query_vars['uwp_profile'] ) && uwp_get_page_id( 'profile_page', false ) ) {
1986 + $active_tab = ! empty( $wp_query->query_vars['uwp_tab'] ) ? $wp_query->query_vars['uwp_tab'] : '';
1142 1987
1143 - public function gd_login_wid_login_placeholder() {
1144 - return __( 'Username', 'userswp' );
1145 - }
1988 + if ( empty( $active_tab ) && empty( $uwp_profile_first_tab ) && $uwp_profile_doing_tab ) {
1989 + $active_tab = $uwp_profile_doing_tab;
1990 + }
1146 1991
1147 - public function gd_login_wid_login_name() {
1148 - return "uwp_login_username";
1149 - }
1992 + if ( empty( $active_tab ) && ! empty( $uwp_profile_tabs_array ) && ! empty( $uwp_profile_tabs_array[0]->tab_key ) ) {
1993 + $active_tab = $uwp_profile_tabs_array[0]->tab_key;
1994 + }
1150 1995
1151 - public function gd_login_wid_login_pwd() {
1152 - return "uwp_login_password";
1153 - }
1996 + if ( $active_tab == 'listings' || $active_tab == 'favorites' ) {
1997 + return true;
1998 + }
1999 + }
1154 2000
1155 - public function gd_login_inject_nonce() {
1156 - ?>
1157 - <input type="hidden" name="uwp_login_nonce" value="<?php echo wp_create_nonce( 'uwp-login-nonce' ); ?>" />
1158 - <?php
1159 - }
1160 -
1161 - public function check_redirect_author_page( $redirect = false ) {
1162 - if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1163 - $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
2001 + return false;
2002 + }
1164 2003
1165 - if ( !empty( $author ) && ! empty( $author->ID ) ) {
1166 - $favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false;
1167 - $post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL;
2004 + /**
2005 + * Displays post status
2006 + *
2007 + * @since 1.0.0
2008 + * @package userswp
2009 + *
2010 + * @return string|void
2011 + */
2012 + public function geodir_add_post_status_author_page() {
2013 + global $wpdb, $post;
1168 2014
1169 - $author_id = $author->ID;
1170 - $author_link = uwp_build_profile_tab_url( $author_id );
1171 - $gd_post_types = geodir_get_posttypes( 'array' );
2015 + $html = '';
2016 + if ( get_current_user_id() ) {
2017 + if ( $this->gd_is_listings_tab() && ! empty( $post ) && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
1172 2018
1173 - if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1174 - if ( $favourite ) {
1175 - $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
2019 + // we need to query real status direct as we dynamically change the status for author on author page so even non author status can view them.
2020 + $real_status = $wpdb->get_var( "SELECT post_status from $wpdb->posts WHERE ID=$post->ID" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
2021 + $status = "<strong>(";
2022 + $status_icon = '<i class="fas fa-play"></i>';
2023 + switch ( $real_status ) {
2024 + case 'publish' :
2025 + $status .= __( 'Published', 'userswp' );
2026 + break;
2027 + case 'pending' :
2028 + $status .= __( 'Pending', 'userswp' );
2029 + break;
2030 + case 'gd-closed' :
2031 + $status .= __( 'Closed', 'userswp' );
2032 + break;
2033 + case 'gd-expired' :
2034 + $status .= __( 'Expired', 'userswp' );
2035 + break;
2036 + default :
2037 + $status .= __( 'Not published', 'userswp' );
2038 + break;
2039 + }
2040 + $status .= ")</strong>";
1176 2041
1177 - if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1178 - // Redirect to dashboard CPT favorites.
1179 - } else {
1180 - $redirect = false; // Do not redirect to dashboard CPT favorites.
1181 - }
1182 - } else {
1183 - $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
2042 + $html = '<span class="geodir-post-status">' . $status_icon . ' <span class="geodir-status-label">' . __( 'Status: ', 'userswp' ) . '</span>' . $status . '</span>';
2043 + }
2044 + }
1184 2045
1185 - if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1186 - // Redirect to dashboard CPT listings.
1187 - } else {
1188 - $redirect =false; // Do not redirect to dashboard CPT listings.
1189 - }
1190 - }
1191 - }
1192 - }
1193 - }
2046 + if ( $html != '' ) {
2047 + echo apply_filters( 'geodir_filter_status_text_on_author_page', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2048 + }
2049 + }
1194 2050
1195 - return $redirect;
1196 - }
1197 -
1198 - public function skip_uwp_author_page( $uwp_author = true ) {
1199 - if ( geodir_is_page( 'author' ) ) {
1200 - $uwp_author = false;
1201 - }
1202 -
1203 - return $uwp_author;
1204 - }
2051 + /**
2052 + * Returns GD login form placeholder
2053 + *
2054 + * @since 1.0.0
2055 + * @package userswp
2056 + *
2057 + * @return string
2058 + */
2059 + public function gd_login_wid_login_placeholder() {
2060 + if ( ! uwp_is_gdv2() ) {
2061 + return __( 'Username', 'userswp' );
2062 + }
2063 + }
1205 2064
1206 - public function uwp_is_gdv2(){
2065 + /**
2066 + * Returns GD login form name
2067 + *
2068 + * @since 1.0.0
2069 + * @package userswp
2070 + *
2071 + * @return string
2072 + */
2073 + public function gd_login_wid_login_name() {
2074 + if ( ! uwp_is_gdv2() ) {
2075 + return "username";
2076 + }
2077 + }
1207 2078
1208 - if(version_compare(GEODIRECTORY_VERSION,'2.0.0.0', '>=') ) {
1209 - return true;
1210 - }
2079 + /**
2080 + * Returns GD login form password name
2081 + *
2082 + * @since 1.0.0
2083 + * @package userswp
2084 + *
2085 + * @return string
2086 + */
2087 + public function gd_login_wid_login_pwd() {
2088 + if ( ! uwp_is_gdv2() ) {
2089 + return "uwp_login_password";
2090 + }
2091 + }
1211 2092
1212 - return false;
1213 - }
2093 + /**
2094 + * Displays nonce field in GD login form
2095 + *
2096 + * @since 1.0.0
2097 + * @package userswp
2098 + *
2099 + */
2100 + public function gd_login_inject_nonce() {
2101 + if ( ! uwp_is_gdv2() ) {
2102 + ?>
2103 + <input type="hidden" name="uwp_login_nonce" value="<?php echo esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ); ?>"/>
2104 + <?php
2105 + }
2106 + }
2107 +
2108 + /**
2109 + * Check author page redirect
2110 + *
2111 + * @since 1.0.0
2112 + * @package userswp
2113 + *
2114 + * @param bool $redirect
2115 + *
2116 + * @return bool
2117 + *
2118 + */
2119 + public function check_redirect_author_page( $redirect = false ) {
2120 + if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) {
2121 + $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
2122 +
2123 + if ( ! empty( $author ) && ! empty( $author->ID ) ) {
2124 + $favourite = isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' ? true : false;
2125 + $post_type = isset( $_REQUEST['stype'] ) ? esc_attr( $_REQUEST['stype'] ) : null;
2126 +
2127 + $author_id = $author->ID;
2128 + $author_link = uwp_build_profile_tab_url( $author_id );
2129 + $gd_post_types = geodir_get_posttypes( 'array' );
2130 +
2131 + if ( ! empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
2132 + if ( $favourite ) {
2133 + $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
2134 +
2135 + if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
2136 + // Redirect to dashboard CPT favorites.
2137 + } else {
2138 + $redirect = false; // Do not redirect to dashboard CPT favorites.
2139 + }
2140 + } else {
2141 + $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
2142 +
2143 + if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
2144 + // Redirect to dashboard CPT listings.
2145 + } else {
2146 + $redirect = false; // Do not redirect to dashboard CPT listings.
2147 + }
2148 + }
2149 + }
2150 + }
2151 + }
2152 +
2153 + return $redirect;
2154 + }
2155 +
2156 + /**
2157 + * Check if skip author page
2158 + *
2159 + * @since 1.0.0
2160 + * @package userswp
2161 + *
2162 + * @param bool $uwp_author
2163 + *
2164 + * @return bool
2165 + *
2166 + */
2167 + public function skip_uwp_author_page( $uwp_author = true ) {
2168 + if ( geodir_is_page( 'author' ) ) {
2169 + $uwp_author = false;
2170 + }
2171 +
2172 + return $uwp_author;
2173 + }
2174 +
2175 + public function get_widget_post_author( $post_author, $instance, $id_base = '' ) {
2176 + if ( isset( $id_base ) && 'gd_listings' == $id_base ) {
2177 + if ( is_uwp_profile_page() && isset( $instance['post_author'] ) && 'current_author' == $instance['post_author'] ) {
2178 + $user = uwp_get_user_by_author_slug();
2179 + if ( $user && isset( $user->ID ) ) {
2180 + $post_author = $user->ID;
2181 + }
2182 + }
2183 + }
2184 +
2185 + return $post_author;
2186 + }
2187 +
2188 + public function get_widget_favorites_by_user( $favorites_by_user, $instance, $id_base = '' ) {
2189 + if ( isset( $id_base ) && 'gd_listings' == $id_base ) {
2190 + if ( is_uwp_profile_page() && isset( $instance['favorites_by_user'] ) && 'current_author' == $instance['favorites_by_user'] ) {
2191 + $user = uwp_get_user_by_author_slug();
2192 + if ( $user && isset( $user->ID ) ) {
2193 + $favorites_by_user = $user->ID;
2194 + }
2195 + }
2196 + }
2197 +
2198 + return $favorites_by_user;
2199 + }
2200 +
2201 + /**
2202 + * Unset GD Post variable after posts loop.
2203 + *
2204 + * @since 1.2.3.12
2205 + */
2206 + public function unset_gd_post() {
2207 + global $gd_post;
2208 + $gd_post = NULL;
2209 + }
2210 +
2211 + public function posts_join( $join, $wp_query ) {
2212 + global $wpdb;
2213 +
2214 + if ( ! empty( $wp_query ) && ! empty( $wp_query->query_vars ) && ! empty( $wp_query->query_vars['uwp_geodir_query'] ) && ! empty( $wp_query->query_vars['post_type'] ) ) {
2215 + $post_type = $wp_query->query_vars['post_type'];
2216 +
2217 + if ( is_scalar( $post_type ) && geodir_is_gd_post_type( $post_type ) ) {
2218 + $table = geodir_db_cpt_table( $post_type );
2219 +
2220 + $join .= ( $join ? " " : "" ) . "INNER JOIN `" . $table . "` ON ( `" . $table . "`.`post_id` = `" . $wpdb->posts . "`.`ID` )";
2221 + }
2222 + }
2223 +
2224 + return $join;
2225 + }
2226 +
2227 + public function get_usernumposts( $count, $userid, $post_type, $public_only ) {
2228 + global $_uwp_user_post_counts;
2229 +
2230 + if ( ! empty( $_uwp_user_post_counts ) && is_scalar( $post_type ) && geodir_is_gd_post_type( $post_type ) ) {
2231 + $count = $this->get_listings_count( $post_type, $userid );
2232 + }
2233 +
2234 + return $count;
2235 + }
2236 +
2237 + public static function get_items_per_page( $item = '' ) {
2238 + $per_page = (int) uwp_get_option( 'profile_no_of_items', 10 );
2239 +
2240 + if ( $per_page < 1 ) {
2241 + $per_page = 10;
2242 + }
2243 +
2244 + return (int) apply_filters( 'uwp_geodir_items_per_page', $per_page, $item );
2245 + }
1214 2246 }
2247 +
1215 2248 $userswp_geodirectory = UsersWP_GeoDirectory_Plugin::get_instance();