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 +2054 -1033 1.0.121.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,1221 +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();
14 + private function __construct() {
15 + self::$instance = $this;
16 + }
17 +
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 +
24 + return self::$instance;
25 + }
26 +
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 );
62 +
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 );
66 +
67 + add_filter( 'posts_join', array( $this, 'posts_join' ), 11, 2 );
68 + add_filter( 'get_usernumposts', array( $this, 'get_usernumposts' ), 11, 4 );
69 +
70 + do_action( 'uwp_gd_setup_actions', $this );
71 + }
72 +
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'] );
85 +
86 + return $link;
87 + }
88 +
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'] );
101 +
102 + return $link;
103 + }
104 +
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() ) {
114 +
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 + }
136 +
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 + }
155 +
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 + }
174 +
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 + }
194 +
195 +
196 + }
197 +
198 + return $links;
199 + }
200 +
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 ) {
212 +
213 + $sections['uwp_geodirectory'] = __( 'GeoDirectory', 'userswp' );
214 +
215 + return $sections;
216 + }
217 +
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 ) {
230 +
231 + if ( ! empty( $current_section ) && 'uwp_geodirectory' === $current_section ) {
232 +
233 + $gd_posttypes = $this->get_gd_posttypes();
234 +
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 + ) );
280 +
281 + $settings[] = array( 'type' => 'sectionend', 'id' => 'addons_gd_settings_options' );
282 + }
283 +
284 + return $settings;
285 + }
286 +
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' );
298 +
299 + foreach ( $post_types as $key => $post_types_obj ) {
300 + $post_type_arr[ $key ] = $post_types_obj->labels->singular_name;
301 + }
302 +
303 + return $post_type_arr;
304 + }
305 +
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 + }
320 +
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 + );
330 +
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 + );
340 +
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 + );
350 +
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 + }
362 +
363 + return $fields;
364 + }
365 +
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 + }
380 +
381 + $gd_post_types = geodir_get_posttypes( 'array' );
382 +
383 + if ( empty( $gd_post_types ) ) {
384 + return 0;
385 + }
386 +
387 +
388 + // allowed post types
389 + $listing_post_types = uwp_get_option( 'gd_profile_listings', array() );
390 +
391 + if ( ! is_array( $listing_post_types ) ) {
392 + $listing_post_types = array();
393 + }
394 +
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 ) ) {
399 +
400 + // get listing count
401 + $listing_count = $this->get_listings_count( $post_type, $user_id );
402 + $total_count += $listing_count;
403 +
404 + $count ++;
405 + }
406 + }
407 +
408 + return $total_count;
409 + }
410 +
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;
424 +
425 + if ( empty( $user_id ) ) {
426 + return 0;
427 + }
428 +
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 + }
434 +
435 + if ( empty( $post_status ) ) {
436 + $post_status = array( 'publish' );
437 + }
438 +
439 + if ( is_super_admin() ) {
440 + $post_status[] = 'private';
441 + }
442 +
443 + $post_status = array_unique( $post_status );
444 + $post_status_where = array();
445 +
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';
19 542 }
20 543
21 - return self::$instance;
22 - }
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 + }
23 577
24 - private function __construct() {
25 - self::$instance = $this;
26 - }
578 + if ( ! empty( $results ) ) {
579 + return $results;
580 + } else {
581 + return false;
582 + }
583 + }
27 584
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_invoices_tab_content', array( $this, 'add_profile_invoices_tab_content' ) );
46 - add_action( 'uwp_profile_gd_listings_subtab_content', array( $this, 'gd_get_listings' ), 10, 2 );
47 - add_action( 'uwp_profile_gd_reviews_subtab_content', array( $this, 'gd_get_reviews' ), 10, 2 );
48 - add_action( 'uwp_profile_gd_favorites_subtab_content', array( $this, 'gd_get_favorites' ), 10, 2 );
49 - //add_action( 'geodir_after_edit_post_link_on_listing', array( $this, 'geodir_add_post_status_author_page' ), 11 );
50 - }
51 - add_filter( 'geodir_login_url', array( $this, 'get_gd_login_url' ), 10, 2 );
52 - add_action( 'wp', array( $this, 'geodir_uwp_author_redirect' ) );
53 - add_filter( 'geodir_post_status_is_author_page', array( $this, 'geodir_post_status_is_author_page' ) );
54 - add_filter( 'gd_login_wid_login_placeholder', array( $this, 'gd_login_wid_login_placeholder' ) );
55 - add_filter( 'gd_login_wid_login_name', array( $this, 'gd_login_wid_login_name' ) );
56 - add_filter( 'gd_login_wid_login_pwd', array( $this, 'gd_login_wid_login_pwd' ) );
57 - add_action( 'login_form', array( $this, 'gd_login_inject_nonce' ) );
58 - add_filter( 'uwp_check_redirect_author_page', array( $this, 'check_redirect_author_page' ), 10, 1 );
59 - add_filter( 'uwp_use_author_page_content', array( $this, 'skip_uwp_author_page' ), 10, 1 );
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 + }
60 599
61 - do_action( 'uwp_gd_setup_actions', $this );
62 - }
600 + $gd_post_types = geodir_get_posttypes( 'array' );
63 601
64 - private function includes() {
65 - do_action( 'uwp_gd_include_files' );
602 + if ( empty( $gd_post_types ) ) {
603 + return 0;
604 + }
66 605
67 - if ( is_admin() ) {
68 - do_action( 'uwp_gd_include_admin_files' );
69 - }
70 - }
606 + // allowed post types
607 + $listing_post_types = uwp_get_option( 'gd_profile_favorites', array() );
71 608
72 - /**
73 - * Modifies the settings form title.
74 - *
75 - * @since 1.0.0
76 - * @package userswp
77 - *
78 - * @param string $title Original title.
79 - * @param string $page admin.php?page=uwp_xxx.
80 - * @param string $active_tab active tab in that settings page.
81 - *
82 - * @return string Form title.
83 - */
84 - public function display_form_title( $title, $page, $active_tab ) {
85 - if ( $page == 'uwp_geodirectory' && $active_tab == 'main' ) {
86 - $title = __( 'GeoDirectory Settings', 'userswp' );
87 - }
88 - return $title;
89 - }
90 -
91 - /**
92 - * Prints the settings form.
93 - *
94 - * @since 1.0.0
95 - * @package userswp
96 - *
97 - * @param string $form Setting form html.
98 - *
99 - * @return void
100 - */
101 - public function main_tab_content( $form ) {
102 - echo $form;
103 - }
104 -
105 - /**
106 - * Adds the current userswp addon settings page menu as submenu.
107 - *
108 - * @since 1.0.0
109 - * @package userswp
110 - *
111 - * @param callable $settings_page The function to be called to output the content for this page.
112 - *
113 - * @return void
114 - */
115 - public function add_admin_gd_sub_menu( $settings_page ) {
116 - add_submenu_page(
117 - "userswp",
118 - __( 'GeoDirectory', 'userswp' ),
119 - __( 'GeoDirectory', 'userswp' ),
120 - 'manage_options',
121 - 'uwp_geodirectory',
122 - $settings_page
123 - );
124 - }
609 + if ( ! is_array( $listing_post_types ) ) {
610 + $listing_post_types = array();
611 + }
125 612
126 - /**
127 - * Adds settings tabs for the current userswp addon.
128 - *
129 - * @since 1.0.0
130 - * @package userswp
131 - *
132 - * @param array $tabs Existing tabs array.
133 - *
134 - * @return array Tabs array.
135 - */
136 - public function add_gd_tab( $tabs ) {
137 - $tabs['uwp_geodirectory'] = array(
138 - 'main' => __( 'GeoDirectory', 'userswp' ),
139 - );
140 - return $tabs;
141 - }
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 ) ) {
142 617
143 - /**
144 - * Registers form fields for the current userswp addon settings page.
145 - *
146 - * @since 1.0.0
147 - * @package userswp
148 - *
149 - * @param array $uwp_settings Existing settings array.
150 - *
151 - * @return array Settings array.
152 - */
153 - public function add_gd_settings( $uwp_settings ) {
154 - $gd_posttypes = $this->get_gd_posttypes();
618 + // get listing count
619 + $listing_count = $this->geodir_count_favorite( $post_type, $user_id );
620 + $total_count += $listing_count;
155 621
156 - $options = array(
157 - 'gd_settings_info' => array(
158 - 'id' => 'woo_settings_info',
159 - 'name' => __( 'Info', 'userswp' ),
160 - 'desc' => __( 'You can now add Listings, Reviews and Favorites tabs under UsersWP > Profile > Choose the tabs to display in Profile', 'userswp' ),
161 - 'type' => 'info',
162 - 'std' => '1',
163 - 'class' => 'uwp_label_inline',
164 - ),
165 - 'gd_profile_listings' => array(
166 - 'id' => 'gd_profile_listings',
167 - 'name' => __( 'CPT listings in Profile', 'userswp' ),
168 - 'desc' => __( 'Choose the post types to show listings tab in UsersWP Profile', 'userswp' ),
169 - 'multiple' => true,
170 - 'chosen' => true,
171 - 'type' => 'select',
172 - 'options' => $gd_posttypes,
173 - 'placeholder' => __( 'Select Post Types', 'userswp' )
174 - ),
175 - 'gd_profile_reviews' => array(
176 - 'id' => 'gd_profile_reviews',
177 - 'name' => __( 'CPT reviews in Profile', 'userswp' ),
178 - 'desc' => __( 'Choose the post types to show reviews tab in UsersWP Profile', 'userswp' ),
179 - 'multiple' => true,
180 - 'chosen' => true,
181 - 'type' => 'select',
182 - 'options' => $gd_posttypes,
183 - 'placeholder' => __( 'Select Post Types', 'userswp' )
184 - ),
185 - 'gd_profile_favorites' => array(
186 - 'id' => 'gd_profile_favorites',
187 - 'name' => __( 'CPT favorites in Profile', 'userswp' ),
188 - 'desc' => __( 'Choose the post types to show favorites tab in UsersWP Profile', 'userswp' ),
189 - 'multiple' => true,
190 - 'chosen' => true,
191 - 'type' => 'select',
192 - 'options' => $gd_posttypes,
193 - 'placeholder' => __( 'Select Post Types', 'userswp' )
194 - ),
195 - 'geodir_uwp_link_listing' => array(
196 - 'id' => 'geodir_uwp_link_listing',
197 - 'name' => __( 'Redirect GD dashboard my listing link to UsersWP profile', 'userswp' ),
198 - 'desc' => __( 'If this option is selected, the my listing link from GD dashboard will redirect to listings tab of UsersWP profile.', 'userswp' ),
199 - 'type' => 'checkbox',
200 - 'std' => '0',
201 - 'class' => 'uwp_label_inline',
202 - ),
203 - 'geodir_uwp_link_favorite' => array(
204 - 'id' => 'geodir_uwp_link_favorite',
205 - 'name' => __( 'Redirect GD dashboard favorite link to UsersWP profile', 'userswp' ),
206 - 'desc' => __( 'If this option is selected, the favorite link from GD dashboard will redirect to favorites tab of UsersWP profile.', 'userswp' ),
207 - 'type' => 'checkbox',
208 - 'std' => '0',
209 - 'class' => 'uwp_label_inline',
210 - ),
211 - );
622 + $count ++;
623 + }
624 + }
212 625
213 - $uwp_settings['uwp_geodirectory'] = array(
214 - 'main' => apply_filters( 'uwp_settings_geodirectory', $options ),
215 - );
626 + return $total_count;
627 + }
216 628
217 - return $uwp_settings;
218 - }
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;
219 641
220 - public function get_gd_posttypes() {
221 - $post_type_arr = array();
222 - $post_types = geodir_get_posttypes( 'object' );
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 + }
223 647
224 - foreach ( $post_types as $key => $post_types_obj ) {
225 - $post_type_arr[$key] = $post_types_obj->labels->singular_name;
226 - }
227 - return $post_type_arr;
228 - }
648 + if ( empty( $post_status ) ) {
649 + $post_status = array( 'publish' );
650 + }
229 651
230 - /**
231 - * Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting.
232 - *
233 - * @since 1.0.0
234 - * @package userswp
235 - *
236 - * @param array $tabs_arr Existing tabs array.
237 - *
238 - * @return array Tabs array.
239 - */
240 - public function available_tab_items( $tabs_arr ) {
241 - $tabs_arr['listings'] = __( 'Listings', 'userswp' );
242 - $tabs_arr['reviews'] = __( 'Reviews', 'userswp' );
243 - $tabs_arr['favorites'] = __( 'Favorites', 'userswp' );
652 + if ( is_super_admin() ) {
653 + $post_status[] = 'private';
654 + }
244 655
245 - if ( class_exists( 'WPInv_Invoice' ) ) {
246 - $tabs_arr['invoices'] = __( 'Invoices', 'userswp' );
247 - }
656 + $post_status = array_unique( $post_status );
657 + $post_status_where = array();
248 658
249 - return $tabs_arr;
250 - }
251 -
252 - public function geodir_get_reviews_by_user_id($post_type = 'gd_place', $user_id, $count_only = false, $offset = 0, $limit = 20) {
253 - global $wpdb;
659 + foreach ( $post_status as $status ) {
660 + $post_status_where[] = $wpdb->prepare( "`" . $wpdb->posts . "`.post_status = %s", $status );
661 + }
254 662
255 - if ($count_only) {
256 - $results = $wpdb->get_var(
257 - $wpdb->prepare(
258 - "SELECT COUNT(overall_rating) FROM " . GEODIR_REVIEW_TABLE . " WHERE user_id = %d AND post_type = %s AND status=1 AND overall_rating>0",
259 - array($user_id, $post_type)
260 - )
261 - );
262 - } else {
263 - $results = $wpdb->get_results(
264 - $wpdb->prepare(
265 - "SELECT * FROM " . GEODIR_REVIEW_TABLE . " WHERE user_id = %d AND post_type = %s AND status=1 AND overall_rating>0 LIMIT %d OFFSET %d",
266 - array($user_id, $post_type, $limit, $offset )
267 - )
268 - );
269 - }
663 + $post_status_where = implode( " OR ", $post_status_where );
270 664
271 - if (!empty($results))
272 - return $results;
273 - else
274 - return false;
275 - }
665 + $user_fav_posts = geodir_get_user_favourites( (int) $user_id );
666 + $user_fav_posts = ! empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1";
276 667
277 - public function geodir_count_favorite( $post_type, $user_id = 0 ) {
278 - global $wpdb;
668 + $table = geodir_db_cpt_table( $post_type );
279 669
280 - $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
281 - if ( $user_id && $user_id == get_current_user_id() ) {
282 - $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private'";
283 - }
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 );
284 672
285 - $user_fav_posts = geodir_get_user_favourites( (int)$user_id );
286 - $user_fav_posts = !empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1";
673 + $count = (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
287 674
288 - $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 . " )" );
675 + return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id );
676 + }
289 677
290 - return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id );
291 - }
292 -
293 - public function get_listings_count($post_type, $user_id = 0) {
294 - global $wpdb;
295 - if (empty($user_id)) {
296 - return 0;
297 - }
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 + }
298 691
299 - $post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : '';
300 - if ($user_id && $user_id == get_current_user_id()) {
301 - $post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private'";
302 - }
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 + }
303 716
304 - $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 . " )");
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 ) {
305 723
306 - return apply_filters('geodir_uwp_count_total', $count, $user_id);
307 - }
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);
308 729
309 - public function get_total_listings_count($user_id = 0) {
310 - if (empty($user_id)) {
311 - return 0;
312 - }
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>
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 ) {
313 749
314 - $gd_post_types = geodir_get_posttypes('array');
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);
315 755
316 - if (empty($gd_post_types)) {
317 - return 0;
318 - }
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 + }
319 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();
320 790
321 - // allowed post types
322 - $listing_post_types = uwp_get_option('gd_profile_listings', array());
791 + $gd_post_types = geodir_get_posttypes( 'array' );
323 792
324 - if (!is_array($listing_post_types)) {
325 - $listing_post_types = array();
326 - }
793 + if ( empty( $gd_post_types ) ) {
794 + return $tabs;
795 + }
327 796
328 - $count = 0;
329 - $total_count = 0;
330 - foreach ($listing_post_types as $post_type) {
331 - if (array_key_exists($post_type, $gd_post_types)) {
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 + }
332 807
333 - // get listing count
334 - $listing_count = $this->get_listings_count($post_type, $user_id);
335 - $total_count += $listing_count;
808 + if ( ! is_array( $listing_post_types ) ) {
809 + $listing_post_types = array();
810 + }
336 811
337 - $count++;
338 - }
339 - }
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'];
340 815
341 - return $total_count;
342 - }
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 + }
343 824
344 - public function get_total_reviews_count($user_id = 0) {
345 - if (empty($user_id)) {
346 - return 0;
347 - }
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 + }
348 834
349 - $gd_post_types = geodir_get_posttypes('array');
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 + }
350 844
351 - if (empty($gd_post_types)) {
352 - return 0;
353 - }
845 + return apply_filters( 'uwp_profile_gd_tabs', $tabs, $user, $type );
846 + }
354 847
355 - // allowed post types
356 - $listing_post_types = uwp_get_option('gd_profile_reviews', array());
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 + }
357 861
358 - if (!is_array($listing_post_types)) {
359 - $listing_post_types = array();
360 - }
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 + }
361 875
362 - $count = 0;
363 - $total_count = 0;
364 - foreach ($listing_post_types as $post_type) {
365 - if (array_key_exists($post_type, $gd_post_types)) {
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 + }
366 890
367 - // get listing count
368 - $listing_count = $this->geodir_get_reviews_by_user_id($post_type, $user_id, true);
369 - $total_count += $listing_count;
891 + $subtab = get_query_var( 'uwp_subtab' );
892 + $uwp_tab = get_query_var( 'uwp_tab' );
893 + $type = geodir_lists_slug();
370 894
371 - $count++;
372 - }
373 - }
895 + if ( empty( $uwp_tab ) ) {
896 + $uwp_tab = $type;
897 + }
374 898
375 - return $total_count;
376 - }
899 + $user_lists = GeoDir_Lists_Data::get_user_lists( $user->ID );
377 900
378 - public function get_total_favorites_count($user_id = 0) {
379 - if (empty($user_id)) {
380 - return 0;
381 - }
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 + }
382 911
383 - $gd_post_types = geodir_get_posttypes('array');
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 + }
384 918
385 - if (empty($gd_post_types)) {
386 - return 0;
387 - }
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 + }
388 928
389 - // allowed post types
390 - $listing_post_types = uwp_get_option('gd_profile_favorites', array());
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 + }
391 975
392 - if (!is_array($listing_post_types)) {
393 - $listing_post_types = array();
394 - }
976 + $post_ids = $this->get_listings_from_list($active_id);
395 977
396 - $count = 0;
397 - $total_count = 0;
398 - foreach ($listing_post_types as $post_type) {
399 - if (array_key_exists($post_type, $gd_post_types)) {
978 + if (!empty($post_ids)) {
979 + $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
400 980
401 - // get listing count
402 - $listing_count = $this->geodir_count_favorite($post_type, $user_id);
403 - $total_count += $listing_count;
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 + );
404 990
405 - $count++;
406 - }
407 - }
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 + }
408 1001
409 - return $total_count;
410 - }
1002 + $the_query = new WP_Query($query_args);
1003 + } else {
1004 + $the_query = array();
1005 + }
411 1006
412 - /**
413 - * Adds tab in user profile page.
414 - *
415 - * @since 1.0.0
416 - * @package userswp
417 - *
418 - * @param array $tabs Existing tabs array.
419 - * @param object $user User object.
420 - * @param array $allowed_tabs Allowed tabs array.
421 - *
422 - * @return array Tabs array.
423 - */
424 - function add_profile_gd_tabs($tabs, $user,$allowed_tabs) {
425 - // allowed post types
426 - $listing_post_types = uwp_get_option('gd_profile_listings', array());
427 - if (!empty($listing_post_types) && in_array('listings', $allowed_tabs)) {
428 - $tabs['listings'] = array(
429 - 'title' => __('Listings', 'uwp-gd'),
430 - 'count' => $this->get_total_listings_count($user->ID)
431 - );
432 - }
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;
433 1013
434 - $listing_post_types = uwp_get_option('gd_profile_reviews', array());
435 - if (!empty($listing_post_types) && in_array('reviews', $allowed_tabs)) {
436 - $tabs['reviews'] = array(
437 - 'title' => __('Reviews', 'uwp-gd'),
438 - 'count' => $this->get_total_reviews_count($user->ID)
439 - );
440 - }
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 + );
441 1022
442 - $listing_post_types = uwp_get_option('gd_profile_favorites', array());
443 - if (!empty($listing_post_types) && in_array('favorites', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
444 - $tabs['favorites'] = array(
445 - 'title' => __('Favorites', 'uwp-gd'),
446 - 'count' => $this->get_total_favorites_count($user->ID)
447 - );
448 - }
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 + }
449 1058
450 - if (class_exists('WPInv_Invoice') && in_array('invoices', $allowed_tabs) && (get_current_user_id() == $user->ID)) {
451 - $tabs['invoices'] = array(
452 - 'title' => __('Invoices', 'uwp-gd'),
453 - 'count' => $this->invoice_count($user->ID)
454 - );
455 - }
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' );
456 1063
457 - return $tabs;
458 - }
1064 + return $post_ids;
1065 + }
459 1066
460 - /**
461 - * Adds GD listings tab content.
462 - *
463 - * @since 1.0.0
464 - * @package userswp
465 - *
466 - * @param object $user User object.
467 - *
468 - * @return void
469 - */
470 - public function add_profile_listings_tab_content($user) {
471 - $this->profile_gd_subtabs_content($user, 'listings');
472 - }
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;
473 1076
474 - /**
475 - * Adds GD reviews tab content.
476 - *
477 - * @since 1.0.0
478 - * @package userswp
479 - *
480 - * @param object $user User object.
481 - *
482 - * @return void
483 - */
484 - public function add_profile_reviews_tab_content($user) {
485 - $this->profile_gd_subtabs_content($user, 'reviews');
486 - }
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 );
487 1082
488 - /**
489 - * Adds GD Favorites tab content.
490 - *
491 - * @since 1.0.0
492 - * @package userswp
493 - *
494 - * @param object $user User object.
495 - *
496 - * @return void
497 - */
498 - public function add_profile_favorites_tab_content($user) {
499 - $this->profile_gd_subtabs_content($user, 'favorites');
500 - }
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 + );
501 1092
502 - /**
503 - * Adds GD Invoices tab content.
504 - *
505 - * @since 1.0.0
506 - * @package userswp
507 - *
508 - * @param object $user User object.
509 - *
510 - * @return void
511 - */
512 - public function add_profile_invoices_tab_content($user) {
513 - $this->profile_gd_invoices_content($user);
514 - }
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>
1102 + </div>
1103 + </div>
1104 + ';
1105 + }
1106 + $new_html .= '</div>';
515 1107
516 - public function profile_gd_subtabs($user, $type = 'listings') {
517 - $tabs = array();
1108 + return $new_html;
1109 + } else {
1110 + return $html;
1111 + }
1112 + }
518 1113
519 - $gd_post_types = geodir_get_posttypes('array');
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;
520 1129
521 - if (empty($gd_post_types)) {
522 - return $tabs;
523 - }
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 + }
524 1135
525 - // allowed post types
526 - if ($type == 'listings') {
527 - $listing_post_types = uwp_get_option('gd_profile_listings', array());
528 - } elseif ($type == 'reviews') {
529 - $listing_post_types = uwp_get_option('gd_profile_reviews', array());
530 - } elseif ($type == 'favorites') {
531 - $listing_post_types = uwp_get_option('gd_profile_favorites', array());
532 - } else {
533 - $listing_post_types = array();
534 - }
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 + );
535 1144
536 - if (!is_array($listing_post_types)) {
537 - $listing_post_types = array();
538 - }
1145 + $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
539 1146
540 - foreach ($listing_post_types as $post_type) {
541 - if (array_key_exists($post_type, $gd_post_types)) {
542 - $post_type_slug = $gd_post_types[$post_type]['has_archive'];
1147 + // The Query
1148 + $the_query = new WP_Query( $args );
543 1149
544 - if ($type == 'listings') {
545 - $count = uwp_post_count($user->ID, $post_type);
546 - } elseif ($type == 'reviews') {
547 - $count = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true);
548 - } elseif ($type == 'favorites') {
549 - $count = $this->geodir_count_favorite($post_type, $user->ID);
550 - } else {
551 - $count = 0;
552 - }
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>
553 1155
554 - if (empty($count)) {
555 - $count = 0;
556 - }
557 - $tabs[$post_type_slug] = array(
558 - 'title' => $gd_post_types[$post_type]['labels']['name'],
559 - 'count' => $count,
560 - 'ptype' => $post_type
561 - );
562 - }
563 - }
1156 + <div class="uwp-profile-item-block">
1157 + <?php
564 1158
565 - return apply_filters('uwp_profile_gd_tabs', $tabs, $user, $type);
566 - }
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 );
567 1169
568 - public function profile_gd_subtabs_content($user, $type = 'listings') {
569 - $subtab = get_query_var('uwp_subtab');
570 - $subtabs = $this->profile_gd_subtabs($user, $type);
571 - $active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : 'places';
572 - if (!empty($subtabs)) {
573 - $subtab_keys = array_keys($subtabs);
574 - $post_type = $subtabs[$subtab_keys[0]]['ptype'];
575 - } else {
576 - $post_type = false;
577 - }
578 - ?>
579 - <div class="uwp-profile-subcontent">
580 - <div class="uwp-profile-subnav">
581 - <?php if ($subtabs) { ?>
582 - <ul class="item-list-subtabs-ul">
583 - <?php
584 - foreach ($this->profile_gd_subtabs($user, $type) as $tab_id => $tab) {
1170 + if ( empty( $post ) ) {
1171 + continue;
1172 + }
585 1173
586 - $tab_url = uwp_build_profile_tab_url($user->ID, $type, $tab_id);
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();
587 1183
588 - $active = $active_tab == $tab_id ? ' active' : '';
589 - $post_type = $active_tab == $tab_id ? $tab['ptype'] : $post_type;
590 - ?>
591 - <li id="uwp-profile-gd-<?php echo $tab_id; ?>" class="<?php echo $active; ?>">
592 - <a href="<?php echo esc_url($tab_url); ?>">
593 - <span class="uwp-profile-tab-label uwp-profile-gd-<?php echo $tab_id; ?>-label "><span
594 - 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>
595 - </a>
596 - </li>
597 - <?php
598 - }
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);
599 1357 ?>
600 - </ul>
601 - <?php } ?>
1358 + </div>
1359 + </div>
1360 + </div>
602 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 + }
603 1382
604 - <div class="uwp-profile-subtab-entries">
605 - <?php
606 - do_action('uwp_profile_gd_' . $type . '_subtab_content', $user, $post_type);
607 - ?>
608 - </div>
609 - </div>
610 - <?php
611 - }
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 );
612 1394
613 - function gd_get_listings($user, $post_type) {
614 - $gd_post_types = geodir_get_posttypes('array');
615 - ?>
616 - <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'uwp-gd') ?></h3>
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>';
617 1398
618 - <div class="uwp-profile-item-block">
619 - <?php
620 -
621 - $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
1399 + $new_html .= '<div class="col">' . $comment_link . '</div>';
622 1400
623 - $args = array(
624 - 'post_type' => $post_type,
625 - 'post_status' => array('publish'),
626 - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
627 - 'author' => $user->ID,
628 - 'paged' => $paged,
629 - );
1401 + $new_html .= '</div>';
630 1402
631 - if (get_current_user_id() == $user->ID) {
632 - $args['post_status'] = array('publish', 'draft', 'private');
633 - }
634 - // The Query
635 - $the_query = new WP_Query($args);
1403 + return $new_html;
1404 + } else {
1405 + return $html;
1406 + }
1407 + }
636 1408
637 - // The Loop
638 - if ($the_query->have_posts()) {
639 - echo '<ul class="uwp-profile-item-ul">';
640 - while ($the_query->have_posts()) {
641 - $the_query->the_post();
642 - $post_id = get_the_ID();
643 - global $post;
644 - $post = geodir_get_post_info($post_id);
645 - setup_postdata($post);
646 - $post_avgratings = geodir_get_post_rating($post->ID);
647 - $post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID);
648 - ob_start();
649 - geodir_comments_number($post->rating_count);
650 - $n_comments = ob_get_contents();
651 - ob_end_clean();
652 - ?>
653 - <li class="uwp-profile-item-li uwp-profile-item-clearfix">
654 - <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>">
655 - <?php
656 - if (has_post_thumbnail()) {
657 - $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80));
658 - } else {
659 - $thumb_url = $thumb_url = plugins_url() . "/userswp/public/assets/images/no_thumb.png";
660 - }
661 - ?>
662 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
663 - </a>
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 {
664 1423
665 - <h3 class="uwp-profile-item-title">
666 - <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
667 - </h3>
668 - <div class="uwp-time-ratings-wrap">
669 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
670 - <?php echo get_the_date(); ?>
671 - </time>
672 - <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?>
673 - <?php
674 - if (!is_user_logged_in()) {
675 - do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
676 - }
677 - ?>
678 - </div>
679 - <div class="uwp-item-actions">
680 - <?php
681 - if (is_user_logged_in()) {
682 - do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
683 - }
684 - if ($post->post_author == get_current_user_id()) {
685 - $addplacelink = get_permalink(geodir_add_listing_page_id());
686 - $editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false);
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;
687 1427
688 - $ajaxlink = geodir_get_ajax_url();
689 - $deletelink = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false);
690 - ?>
1428 + $total_reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, true, $offset, $limit );
1429 + $maximum_pages = ceil( $total_reviews / $limit );
691 1430
692 - <span class="geodir-authorlink clearfix">
1431 + $reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, false, $offset, $limit );
693 1432
694 - <?php do_action('geodir_before_edit_post_link_on_listing'); ?>
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>
695 1440
696 - <a href="<?php echo esc_url($editlink); ?>" class="geodir-edit"
697 - title="<?php _e('Edit Listing', 'uwp-gd'); ?>">
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' ); ?>">
698 1519 <?php
699 - $geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fa fa-edit');
700 - 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>';
701 1522 ?>
702 - <?php _e('Edit', 'uwp-gd'); ?>
1523 + <?php esc_html_e( 'Edit', 'userswp' ); ?>
703 1524 </a>
704 - <a href="<?php echo esc_url($deletelink); ?>" class="geodir-delete"
705 - title="<?php _e('Delete Listing', 'uwp-gd'); ?>">
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' ); ?>">
706 1528 <?php
707 - $geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fa fa-close');
708 - 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>';
709 1531 ?>
710 - <?php _e('Delete', 'uwp-gd'); ?>
1532 + <?php esc_html_e( 'Delete', 'userswp' ); ?>
711 1533 </a>
712 1534
713 - <?php do_action('geodir_after_edit_post_link_on_listing'); ?>
1535 + <?php do_action( 'geodir_after_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
714 1536
715 1537 </span>
716 1538
717 - <?php } ?>
718 - </div>
719 - <div class="uwp-profile-item-summary">
720 - <?php
721 - $excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...'));
722 - echo $excerpt;
723 - if ($excerpt) {
724 - ?>
725 - <a href="<?php echo get_the_permalink(); ?>" class="more-link"><?php echo __( 'Read More »', 'uwp-gd' ); ?></a>
726 - <?php
727 - }
728 - ?>
729 - </div>
730 - </li>
731 - <?php
732 - }
733 - echo '</ul>';
734 - /* Restore original Post Data */
735 - wp_reset_postdata();
736 - } else {
737 - echo sprintf( __( "No %s found", 'uwp-gd' ), $gd_post_types[$post_type]['labels']['name']);
738 - }
739 - do_action('uwp_profile_pagination', $the_query->max_num_pages);
740 - ?>
741 - </div>
742 - <?php
743 - }
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>
744 1547
745 - public function gd_get_reviews($user, $post_type) {
746 - $gd_post_types = geodir_get_posttypes('array');
747 - ?>
748 - <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'uwp-gd') ?></h3>
1548 + <?php
1549 + /* Restore original Post Data */
1550 + wp_reset_postdata();
749 1551
750 - <div class="uwp-profile-item-block">
751 - <?php
752 - $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
753 - $limit = uwp_get_option('profile_no_of_items', 10);
754 - $offset = ($paged - 1) * $limit;
1552 + do_action( 'uwp_after_profile_reviews_items', $user, $post_type );
755 1553
756 - $total_reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true, $offset, $limit);
757 - $maximum_pages = ceil($total_reviews / $limit);
1554 + do_action( 'uwp_profile_pagination', $maximum_pages );
1555 + ?>
1556 + </div>
1557 + <?php
1558 + }
1559 + }
758 1560
759 - $reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, false, $offset, $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();
760 1575
761 - // The Loop
762 - if ($reviews) {
763 - echo '<ul class="uwp-profile-item-ul">';
764 - foreach ($reviews as $review) {
765 - $rating = 0;
766 - if (!empty($review))
767 - $rating = geodir_get_commentoverall($review->comment_id);
1576 + $args['template_args']['title'] = __( "Reviews", 'userswp' );
768 1577
769 - ?>
770 - <li class="uwp-profile-item-li uwp-profile-item-clearfix">
771 - <a class="uwp-profile-item-img" href="<?php echo get_comment_link($review->comment_id); ?>">
772 - <?php
773 - $args = array(
774 - 'size' => 80
775 - );
776 - $thumb_url = get_avatar_url($review->user_id, $args);
777 - ?>
778 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>"/>
779 - </a>
1578 + $userswp->profile->get_profile_comments( $user, $post_type, $args );
780 1579
781 - <h3 class="uwp-profile-item-title">
782 - <a href="<?php echo get_comment_link($review->comment_id); ?>"><?php echo get_the_title($review->post_id); ?></a>
783 - </h3>
784 - <div class="uwp-time-ratings-wrap">
785 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
786 - <?php echo date_i18n(get_option('date_format'), strtotime(get_comment_date("", $review->comment_id))); ?>
787 - </time>
788 - <?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars($rating, $review->comment_id) . '</div>'; ?>
789 - </div>
790 - <div class="uwp-profile-item-summary">
791 - <?php
792 - $excerpt = strip_shortcodes(wp_trim_words($review->comment_content, 15, '...'));
793 - echo $excerpt;
794 - if ($excerpt) {
795 - ?>
796 - <a href="<?php echo get_comment_link($review->comment_id); ?>" class="more-link">Read More
797 - »</a>
798 - <?php
799 - }
800 - ?>
801 - </div>
802 - </li>
803 - <?php
804 - }
805 - echo '</ul>';
806 - /* Restore original Post Data */
807 - wp_reset_postdata();
808 - } else {
809 - echo sprintf( __( "No %s found", 'uwp-gd' ), $gd_post_types[$post_type]['labels']['name']);
810 - }
1580 + $geodir_post_type = '';
811 1581
812 - do_action('uwp_profile_pagination', $maximum_pages);
813 - ?>
814 - </div>
815 - <?php
816 - }
1582 + }
817 1583
818 - public function gd_get_favorites($user, $post_type) {
819 - $gd_post_types = geodir_get_posttypes('array');
820 - ?>
821 - <h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'uwp-gd') ?></h3>
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;
822 1599
823 - <div class="uwp-profile-item-block">
824 - <?php
825 - $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
1600 + $user_fav_posts = geodir_get_user_favourites( $user->ID );
826 1601
827 - $user_fav_posts = geodir_get_user_favourites($user->ID);
1602 + if ( ! $user_fav_posts ) {
1603 + return;
1604 + }
828 1605
829 - if ($user_fav_posts) {
830 - $args = array(
831 - 'post_type' => $post_type,
832 - 'post_status' => array('publish'),
833 - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
834 - 'post__in' => $user_fav_posts,
835 - 'paged' => $paged,
836 - );
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 + }
837 1611
838 - if (get_current_user_id() == $user->ID) {
839 - $args['post_status'] = array('publish', 'draft', 'private');
840 - }
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 + );
841 1620
842 - // The Query
843 - $the_query = new WP_Query($args);
1621 + $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
844 1622
845 - // The Loop
846 - if ($the_query->have_posts()) {
847 - echo '<ul class="uwp-profile-item-ul">';
848 - while ($the_query->have_posts()) {
849 - $the_query->the_post();
850 - $post_id = get_the_ID();
851 - global $post;
852 - $post = geodir_get_post_info($post_id);
853 - setup_postdata($post);
854 - $post_avgratings = geodir_get_post_rating($post->ID);
855 - $post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID);
856 - ob_start();
857 - geodir_comments_number($post->rating_count);
858 - $n_comments = ob_get_contents();
859 - ob_end_clean();
860 - ?>
861 - <li class="uwp-profile-item-li uwp-profile-item-clearfix">
862 - <a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>">
863 - <?php
864 - if (has_post_thumbnail()) {
865 - $thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80));
866 - } else {
867 - $thumb_url = $thumb_url = plugins_url() . "/userswp/public/assets/images/no_thumb.png";
868 - }
869 - ?>
870 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
1623 + // The Query
1624 + $the_query = new WP_Query( $args );
1625 +
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>
1631 +
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 ); ?>">
871 1665 </a>
872 1666
1667 + <?php do_action( 'uwp_before_profile_favourite_title', $post_id, $user, $post_type ); ?>
873 1668 <h3 class="uwp-profile-item-title">
874 - <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>
875 1670 </h3>
1671 + <?php do_action( 'uwp_after_profile_favourite_title', $post_id, $user, $post_type ); ?>
1672 +
876 1673 <div class="uwp-time-ratings-wrap">
877 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
878 - <?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(); ?>
879 1678 </time>
880 - <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?>
881 - <?php
882 - if (!is_user_logged_in()) {
883 - do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
884 - }
885 - ?>
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 ); ?>
886 1686 </div>
1687 +
1688 + <div class="uwp-profile-item-summary">
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 + ?>
1695 + </div>
1696 +
887 1697 <div class="uwp-item-actions">
888 - <?php
889 - if (is_user_logged_in()) {
890 - do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
891 - }
892 - if ($post->post_author == get_current_user_id()) {
893 - $addplacelink = get_permalink(geodir_add_listing_page_id());
894 - $editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false);
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 + ?>
895 1721
896 - $ajaxlink = geodir_get_ajax_url();
897 - $deletelink = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false);
898 - ?>
899 -
900 1722 <span class="geodir-authorlink clearfix">
901 1723
902 - <?php do_action('geodir_before_edit_post_link_on_listing'); ?>
1724 + <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
903 1725
904 - <a href="<?php echo esc_url($editlink); ?>" class="geodir-edit"
905 - title="<?php _e('Edit Listing', 'uwp-gd'); ?>">
1726 + <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1727 + title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
906 1728 <?php
907 - $geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fa fa-edit');
908 - 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>';
909 1731 ?>
910 - <?php _e('Edit', 'uwp-gd'); ?>
1732 + <?php esc_html_e( 'Edit', 'userswp' ); ?>
911 1733 </a>
912 - <a href="<?php echo esc_url($deletelink); ?>" class="geodir-delete"
913 - title="<?php _e('Delete Listing', 'uwp-gd'); ?>">
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' ); ?>">
914 1737 <?php
915 - $geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fa fa-close');
916 - 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>';
917 1740 ?>
918 - <?php _e('Delete', 'uwp-gd'); ?>
1741 + <?php esc_html_e( 'Delete', 'userswp' ); ?>
919 1742 </a>
920 1743
921 - <?php do_action('geodir_after_edit_post_link_on_listing'); ?>
1744 + <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
922 1745
923 1746 </span>
924 1747
925 - <?php } ?>
1748 + <?php } ?>
926 1749 </div>
927 - <div class="uwp-profile-item-summary">
928 - <?php
929 - $excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...'));
930 - echo $excerpt;
931 - if ($excerpt) {
932 - ?>
933 - <a href="<?php echo get_the_permalink(); ?>" class="more-link"><?php echo __( 'Read More »', 'uwp-gd' ); ?></a>
934 - <?php
935 - }
936 - ?>
937 - </div>
938 1750 </li>
939 - <?php
940 - }
941 - echo '</ul>';
942 - /* Restore original Post Data */
943 - wp_reset_postdata();
944 - } else {
945 - echo sprintf( __( "No %s found", 'uwp-gd' ), $gd_post_types[$post_type]['labels']['name']);
946 - }
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 + }
947 1758
948 - do_action('uwp_profile_pagination', $the_query->max_num_pages);
1759 + do_action( 'uwp_after_profile_favourite_items', $user, $post_type );
1760 +
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));
949 1787 } else {
950 - echo sprintf( __( "No %s found", 'uwp-gd' ), $gd_post_types[$post_type]['labels']['name']);
1788 + $post_status = geodir_get_post_stati('public', array('post_type' => $post_type));
951 1789 }
952 - ?>
953 - </div>
954 - <?php
955 - }
956 1790
957 - public function get_gd_login_url($url, $args) {
958 - $register_page = uwp_get_option('register_page', false);
959 - $login_page = uwp_get_option('login_page', false);
960 - $forgot_page = uwp_get_option('forgot_page', false);
961 - $reset_page = uwp_get_option('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 + );
962 1799
963 - if (!empty($args)) {
964 - if (isset($args['signup']) && $args['signup']) {
965 - $page_id = $register_page;
966 - } elseif (isset($args['forgot']) && $args['forgot']) {
967 - $page_id = $forgot_page;
968 - } elseif (isset($args['reset']) && $args['reset']) {
969 - $page_id = $reset_page;
970 - } else {
971 - $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);
972 1850 }
973 - } else {
974 - $page_id = $login_page;
975 1851 }
976 - if ($page_id) {
977 - $uwp_url = get_permalink($page_id);
1852 + }
978 1853
979 - if (strpos($url, 'redirect_add_listing') !== false) {
980 - $parsed = wp_parse_url($url);
981 - parse_str($parsed['query'], $query);
982 - $uwp_url = add_query_arg( array(
983 - 'redirect_to' => $query['redirect_add_listing'],
984 - ), $uwp_url );
985 - }
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 + }
986 1869
987 - $url = $uwp_url;
988 - }
989 - return $url;
990 - }
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 );
991 1874
992 - public function geodir_uwp_author_redirect() {
993 - if ( ! empty( $_REQUEST['geodir_dashbord'] ) ) {
994 - $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
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 );
995 1890
996 - if ( !empty( $author ) && ! empty( $author->ID ) ) {
997 - $favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false;
998 - $post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL;
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 + }
999 1898
1000 - $author_id = $author->ID;
1001 - $author_link = uwp_build_profile_tab_url( $author_id );
1002 - $gd_post_types = geodir_get_posttypes( 'array' );
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 + }
1003 1904
1004 - if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1005 - if ( $favourite ) {
1006 - $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1905 + $url = $uwp_url;
1906 + }
1007 1907
1008 - if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1009 - $author_link = uwp_build_profile_tab_url( $author_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] );
1010 - } else {
1011 - return; // Do not redirect to dashboard CPT favorites.
1012 - }
1013 - } else {
1014 - $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
1015 -
1016 - if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1017 - $author_link = uwp_build_profile_tab_url( $author_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] );
1018 - } else {
1019 - return; // Do not redirect to dashboard CPT listings.
1020 - }
1021 - }
1022 - }
1908 + return $url;
1909 + }
1023 1910
1024 - wp_redirect($author_link);
1025 - exit;
1026 - }
1027 - }
1028 - return;
1029 - }
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' ) );
1030 1922
1031 - public function gd_is_listings_tab() {
1032 - global $wp_query;
1033 - if (is_page() && class_exists('UsersWP')) {
1034 - $profile_page = uwp_get_option('profile_page', false);
1035 - if ($profile_page) {
1036 - if (isset($wp_query->query_vars['uwp_profile'])
1037 - && isset($wp_query->query_vars['uwp_tab'])
1038 - && ($wp_query->query_vars['uwp_tab'] == 'listings' || $wp_query->query_vars['uwp_tab'] == 'favorites')
1039 - ) {
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;
1040 1926
1041 - return true;
1927 + $author_id = $author->ID;
1928 + $author_link = uwp_build_profile_tab_url( $author_id );
1929 + $gd_post_types = geodir_get_posttypes( 'array' );
1042 1930
1043 - }
1044 - }
1045 - }
1046 - return false;
1047 - }
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() );
1048 1934
1049 - public function geodir_post_status_is_author_page($value) {
1050 - return $value || $this->gd_is_listings_tab();
1051 - }
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() );
1052 1942
1053 - public function geodir_add_post_status_author_page() {
1054 - global $wpdb, $post;
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 + }
1055 1950
1056 - $html = '';
1057 - if (get_current_user_id()) {
1058 - if ($this->gd_is_listings_tab() && !empty($post) && isset($post->post_author) && $post->post_author == get_current_user_id()) {
1951 + wp_redirect( $author_link );
1952 + exit;
1953 + }
1954 + }
1059 1955
1060 - // 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.
1061 - $real_status = $wpdb->get_var("SELECT post_status from $wpdb->posts WHERE ID=$post->ID");
1062 - $status = "<strong>(";
1063 - $status_icon = '<i class="fa fa-play"></i>';
1064 - if ($real_status == 'publish') {
1065 - $status .= __('Published', 'uwp-gd');
1066 - } else {
1067 - $status .= __('Not published', 'uwp-gd');
1068 - $status_icon = '<i class="fa fa-pause"></i>';
1069 - }
1070 - $status .= ")</strong>";
1956 + return;
1957 + }
1071 1958
1072 - $html = '<span class="geodir-post-status">' . $status_icon . ' <font class="geodir-status-label">' . __('Status: ', 'uwp-gd') . '</font>' . $status . '</span>';
1073 - }
1074 - }
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 + }
1075 1972
1076 - if ($html != '') {
1077 - echo apply_filters('geodir_filter_status_text_on_author_page', $html);
1078 - }
1079 - }
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;
1080 1983
1081 - public function profile_gd_invoices_content($user) {
1082 - if (!is_user_logged_in()) {
1083 - return;
1084 - }
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'] : '';
1085 1987
1086 - if (get_current_user_id() != $user->ID) {
1087 - return;
1088 - }
1089 - ?>
1090 - <h3><?php echo __('Invoices', 'uwp-gd'); ?></h3>
1988 + if ( empty( $active_tab ) && empty( $uwp_profile_first_tab ) && $uwp_profile_doing_tab ) {
1989 + $active_tab = $uwp_profile_doing_tab;
1990 + }
1091 1991
1092 - <div class="uwp-profile-item-block">
1093 - <?php
1094 - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
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 + }
1095 1995
1096 - $args = array(
1097 - 'post_type' => 'wpi_invoice',
1098 - 'post_status' => array_keys(wpinv_get_invoice_statuses()),
1099 - 'posts_per_page' => uwp_get_option('profile_no_of_items', 10),
1100 - 'author' => $user->ID,
1101 - 'paged' => $paged,
1102 - );
1103 - // The Query
1104 - $the_query = new WP_Query($args);
1996 + if ( $active_tab == 'listings' || $active_tab == 'favorites' ) {
1997 + return true;
1998 + }
1999 + }
1105 2000
1106 - // The Loop
1107 - if ($the_query->have_posts()) {
1108 - echo '<ul class="uwp-profile-item-ul">';
1109 - while ($the_query->have_posts()) {
1110 - $the_query->the_post();
1111 - $wpi_invoice = new WPInv_Invoice( get_the_ID() );
1112 - ?>
1113 - <li class="uwp-profile-item-li uwp-profile-item-clearfix">
1114 - <h3 class="uwp-profile-item-title">
1115 - <a href="<?php echo get_the_permalink(); ?>"><?php _e('Invoice','uwp-gd');?> <?php echo get_the_title(); ?></a>
1116 - </h3>
1117 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
1118 - <?php echo get_the_date(); ?>
1119 - </time>
1120 - <div class="uwp-profile-item-summary">
1121 - <div class="uwp-order-status">
1122 - <?php
1123 - echo __('Invoice Status: ', 'uwp-gd').$wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
1124 - ?>
1125 - </div>
1126 - <div class="uwp-order-total">
1127 - <?php
1128 - echo __('Invoice Total: ', 'uwp-gd'). $wpi_invoice->get_total( true );
1129 - ?>
1130 - </div
1131 - </div>
1132 - </li>
1133 - <?php
1134 - }
1135 - echo '</ul>';
1136 - /* Restore original Post Data */
1137 - wp_reset_postdata();
1138 - } else {
1139 - // no posts found
1140 - echo "<p>".__('No Invoices Found', 'uwp-gd')."</p>";
1141 - }
1142 - do_action('uwp_profile_pagination', $the_query->max_num_pages);
1143 - ?>
1144 - </div>
1145 - <?php
1146 - }
2001 + return false;
2002 + }
1147 2003
1148 - public function invoice_count($user_id) {
1149 - global $wpdb;
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;
1150 2014
1151 - $post_status_array = array_keys(wpinv_get_invoice_statuses());
1152 - $post_status = "'" . implode("','", $post_status_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() ) {
1153 2018
1154 - $count = $wpdb->get_var('
1155 - SELECT COUNT(ID)
1156 - FROM ' . $wpdb->posts. '
1157 - WHERE post_author = "' . $user_id . '"
1158 - AND post_status IN ('.$post_status.')
1159 - AND post_type = "wpi_invoice"'
1160 - );
1161 - return $count;
1162 - }
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>";
1163 2041
1164 - public function gd_login_wid_login_placeholder() {
1165 - return __( 'Username', 'userswp' );
1166 - }
2042 + $html = '<span class="geodir-post-status">' . $status_icon . ' <span class="geodir-status-label">' . __( 'Status: ', 'userswp' ) . '</span>' . $status . '</span>';
2043 + }
2044 + }
1167 2045
1168 - public function gd_login_wid_login_name() {
1169 - return "uwp_login_username";
1170 - }
2046 + if ( $html != '' ) {
2047 + echo apply_filters( 'geodir_filter_status_text_on_author_page', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2048 + }
2049 + }
1171 2050
1172 - public function gd_login_wid_login_pwd() {
1173 - return "uwp_login_password";
1174 - }
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 + }
1175 2064
1176 - public function gd_login_inject_nonce() {
1177 - ?>
1178 - <input type="hidden" name="uwp_login_nonce" value="<?php echo wp_create_nonce( 'uwp-login-nonce' ); ?>" />
1179 - <?php
1180 - }
1181 -
1182 - public function check_redirect_author_page( $redirect = false ) {
1183 - if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1184 - $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
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 + }
1185 2078
1186 - if ( !empty( $author ) && ! empty( $author->ID ) ) {
1187 - $favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false;
1188 - $post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL;
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 + }
1189 2092
1190 - $author_id = $author->ID;
1191 - $author_link = uwp_build_profile_tab_url( $author_id );
1192 - $gd_post_types = geodir_get_posttypes( 'array' );
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 + }
1193 2107
1194 - if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1195 - if ( $favourite ) {
1196 - $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
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' ) );
1197 2122
1198 - if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1199 - // Redirect to dashboard CPT favorites.
1200 - } else {
1201 - $redirect = false; // Do not redirect to dashboard CPT favorites.
1202 - }
1203 - } else {
1204 - $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
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;
1205 2126
1206 - if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1207 - // Redirect to dashboard CPT listings.
1208 - } else {
1209 - $redirect =false; // Do not redirect to dashboard CPT listings.
1210 - }
1211 - }
1212 - }
1213 - }
1214 - }
2127 + $author_id = $author->ID;
2128 + $author_link = uwp_build_profile_tab_url( $author_id );
2129 + $gd_post_types = geodir_get_posttypes( 'array' );
1215 2130
1216 - return $redirect;
1217 - }
1218 -
1219 - public function skip_uwp_author_page( $uwp_author = true ) {
1220 - if ( geodir_is_page( 'author' ) ) {
1221 - $uwp_author = false;
1222 - }
1223 -
1224 - return $uwp_author;
1225 - }
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 + }
1226 2246 }
2247 +
1227 2248 $userswp_geodirectory = UsersWP_GeoDirectory_Plugin::get_instance();