PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / trunk
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP vtrunk
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 1.0.22 1.0.23 All 172 releases
userswp / includes / libraries / class-geodirectory-plugin.php

class-geodirectory-plugin.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP trunk, at includes/libraries/class-geodirectory-plugin.php

2,248 lines 78.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * GeoDirectory plugin related functions
5 *
6 * This class defines all code necessary for GeoDirectory plugin.
7 *
8 * @since 1.0.0
9 * @author GeoDirectory Team <info@wpgeodirectory.com>
10 */
11 class UsersWP_GeoDirectory_Plugin {
12 private static $instance;
13
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';
542 }
543
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 }
577
578 if ( ! empty( $results ) ) {
579 return $results;
580 } else {
581 return false;
582 }
583 }
584
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 }
599
600 $gd_post_types = geodir_get_posttypes( 'array' );
601
602 if ( empty( $gd_post_types ) ) {
603 return 0;
604 }
605
606 // allowed post types
607 $listing_post_types = uwp_get_option( 'gd_profile_favorites', array() );
608
609 if ( ! is_array( $listing_post_types ) ) {
610 $listing_post_types = array();
611 }
612
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 ) ) {
617
618 // get listing count
619 $listing_count = $this->geodir_count_favorite( $post_type, $user_id );
620 $total_count += $listing_count;
621
622 $count ++;
623 }
624 }
625
626 return $total_count;
627 }
628
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;
641
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 }
647
648 if ( empty( $post_status ) ) {
649 $post_status = array( 'publish' );
650 }
651
652 if ( is_super_admin() ) {
653 $post_status[] = 'private';
654 }
655
656 $post_status = array_unique( $post_status );
657 $post_status_where = array();
658
659 foreach ( $post_status as $status ) {
660 $post_status_where[] = $wpdb->prepare( "`" . $wpdb->posts . "`.post_status = %s", $status );
661 }
662
663 $post_status_where = implode( " OR ", $post_status_where );
664
665 $user_fav_posts = geodir_get_user_favourites( (int) $user_id );
666 $user_fav_posts = ! empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1";
667
668 $table = geodir_db_cpt_table( $post_type );
669
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 );
672
673 $count = (int) $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
674
675 return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id );
676 }
677
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 }
691
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 }
716
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 ) {
723
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);
729
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 ) {
749
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);
755
756 ?>
757 <li id="uwp-profile-gd-<?php echo esc_attr( $tab_id ); ?>" class="<?php echo esc_attr( $active ); ?>">
758 <a href="<?php echo esc_url( $tab_url ); ?>">
759 <span
760 class="uwp-profile-tab-label uwp-profile-gd-<?php echo esc_attr( $tab_id ); ?>-label "><span
761 class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo esc_attr( $tab_id ); ?>-count"><?php echo esc_html( $tab['count'] ); ?></span> <?php echo esc_html__( $tab['title'], 'userswp' ); ?></span>
762 </a>
763 </li>
764 <?php
765 }
766 ?>
767 </ul>
768 </div>
769 </div>
770 <?php }
771 }
772 if ( has_action( 'uwp_profile_gd_' . $type . '_subtab_content' ) ) {
773 do_action( 'uwp_profile_gd_' . $type . '_subtab_content', $user, $post_type );
774 }
775 }
776
777 /**
778 * Returns subtab data
779 *
780 * @since 1.0.0
781 * @package userswp
782 *
783 * @param object $user User object
784 * @param string $type Subtab type
785 *
786 * @return array
787 */
788 public function profile_gd_subtabs( $user, $type = 'listings' ) {
789 $tabs = array();
790
791 $gd_post_types = geodir_get_posttypes( 'array' );
792
793 if ( empty( $gd_post_types ) ) {
794 return $tabs;
795 }
796
797 // allowed post types
798 if ( $type == 'listings' ) {
799 $listing_post_types = uwp_get_option( 'gd_profile_listings', array() );
800 } elseif ( $type == 'reviews' ) {
801 $listing_post_types = uwp_get_option( 'gd_profile_reviews', array() );
802 } elseif ( $type == 'favorites' ) {
803 $listing_post_types = uwp_get_option( 'gd_profile_favorites', array() );
804 } else {
805 $listing_post_types = array();
806 }
807
808 if ( ! is_array( $listing_post_types ) ) {
809 $listing_post_types = array();
810 }
811
812 foreach ( $gd_post_types as $post_type_id => $post_type ) {
813 if ( in_array( $post_type_id, $listing_post_types ) ) {
814 $post_type_slug = $gd_post_types[ $post_type_id ]['has_archive'];
815
816 if ( uwp_is_gdv2() ) {
817 $reviews = apply_filters('uwp_profile_gd_show_all_reviews', false, $user, $post_type_id);
818 if ( $type == 'favorites' && geodir_cpt_has_favourite_disabled( $post_type_id ) ) {
819 continue;
820 } elseif ( $type == 'reviews' && $reviews && geodir_cpt_has_rating_disabled( $post_type_id ) ) {
821 continue;
822 }
823 }
824
825 if ( $type == 'listings' ) {
826 $count = $this->get_listings_count( $post_type_id, $user->ID );
827 } elseif ( $type == 'reviews' ) {
828 $count = $this->geodir_get_reviews_by_user_id( $post_type_id, $user->ID, true );
829 } elseif ( $type == 'favorites' ) {
830 $count = $this->geodir_count_favorite( $post_type_id, $user->ID );
831 } else {
832 $count = 0;
833 }
834
835 if ( ! empty( $count ) && $count > 0 ) {
836 $tabs[ $post_type_slug ] = array(
837 'title' => $gd_post_types[ $post_type_id ]['labels']['name'],
838 'count' => $count,
839 'ptype' => $post_type_id
840 );
841 }
842 }
843 }
844
845 return apply_filters( 'uwp_profile_gd_tabs', $tabs, $user, $type );
846 }
847
848 /**
849 * Adds GD reviews tab content.
850 *
851 * @since 1.0.0
852 * @package userswp
853 *
854 * @param object $user User object.
855 *
856 * @return void
857 */
858 public function add_profile_reviews_tab_content( $user ) {
859 $this->profile_gd_subtabs_content( $user, 'reviews' );
860 }
861
862 /**
863 * Adds GD Favorites tab content.
864 *
865 * @since 1.0.0
866 * @package userswp
867 *
868 * @param object $user User object.
869 *
870 * @return void
871 */
872 public function add_profile_favorites_tab_content( $user ) {
873 $this->profile_gd_subtabs_content( $user, 'favorites' );
874 }
875
876 /**
877 * Adds GD Lists tab content.
878 *
879 * @since 1.0.0
880 * @package userswp
881 *
882 * @param object $user User object.
883 *
884 * @return void
885 */
886 public function add_profile_gd_lists_tab_content( $user ) {
887 if ( ! class_exists( 'GeoDir_Lists' ) ) {
888 return;
889 }
890
891 $subtab = get_query_var( 'uwp_subtab' );
892 $uwp_tab = get_query_var( 'uwp_tab' );
893 $type = geodir_lists_slug();
894
895 if ( empty( $uwp_tab ) ) {
896 $uwp_tab = $type;
897 }
898
899 $user_lists = GeoDir_Lists_Data::get_user_lists( $user->ID );
900
901 $subtabs = array();
902 if (!empty($user_lists)) {
903 foreach ($user_lists as $list) {
904 $subtabs[$list->post_name] = array(
905 'id' => $list->ID,
906 'title' => $list->post_title,
907 'count' => count($this->get_listings_from_list($list->ID))
908 );
909 }
910 }
911
912 if (!empty($subtabs)) {
913 $subtab_keys = array_keys($subtabs);
914 $default_tab = isset($subtab_keys[0]) ? $subtab_keys[0] : '';
915 } else {
916 $default_tab = '';
917 }
918
919 $default_tab = apply_filters('uwp_default_gd_lists_subtab', $default_tab, $user, $type);
920 $active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : $default_tab;
921 if (!empty($active_tab) && isset($subtabs[$active_tab]['id'])) {
922 $active_id = $subtabs[$active_tab]['id'];
923 } elseif (isset($subtabs[$default_tab]['id'])) {
924 $active_id = $subtabs[$default_tab]['id'];
925 } else {
926 $active_id = '';
927 }
928
929 if (uwp_get_option("design_style", 'bootstrap')) {
930 if (is_array($subtabs) && count($subtabs) > 0) {
931 ?>
932 <div class="pb-3">
933 <?php
934 foreach ($subtabs as $tab_id => $tab) {
935 $tab_url = uwp_build_profile_tab_url($user->ID, $uwp_tab, $tab_id);
936 $active = $active_tab == $tab_id ? 'btn-primary' : 'btn-outline-primary';
937 ?>
938 <a id="uwp-profile-gd-<?php echo esc_attr($tab_id); ?>" href="<?php echo esc_url($tab_url); ?>"
939 class=" btn btn-sm <?php echo esc_attr($active); ?>">
940 <?php echo esc_html__($tab['title'], 'userswp'); ?>
941 <span class="badge badge-light ml-1"><?php echo esc_html($tab['count']); ?></span>
942 </a>
943 <?php
944 }
945 ?>
946 </div>
947 <?php
948 }
949 } else {
950 if (!empty($subtabs)) { ?>
951 <div class="uwp-profile-subcontent">
952 <div class="uwp-profile-subnav">
953 <ul class="item-list-subtabs-ul">
954 <?php
955 foreach ($subtabs as $tab_id => $tab) {
956 $tab_url = uwp_build_profile_tab_url($user->ID, $type, $tab_id);
957 $active = $active_tab == $tab_id ? ' active' : '';
958 ?>
959 <li id="uwp-profile-gd-<?php echo esc_attr($tab_id); ?>"
960 class="<?php echo esc_attr($active); ?>">
961 <a href="<?php echo esc_url($tab_url); ?>">
962 <span
963 class="uwp-profile-tab-label uwp-profile-gd-<?php echo esc_attr($tab_id); ?>-label "><span
964 class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo esc_attr($tab_id); ?>-count"><?php echo esc_html($tab['count']); ?></span> <?php echo esc_html__($tab['title'], 'userswp'); ?></span>
965 </a>
966 </li>
967 <?php
968 }
969 ?>
970 </ul>
971 </div>
972 </div>
973 <?php }
974 }
975
976 $post_ids = $this->get_listings_from_list($active_id);
977
978 if (!empty($post_ids)) {
979 $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
980
981 $query_args = array(
982 'is_geodir_loop' => true,
983 'gd_location' => false,
984 'post_type' => geodir_get_posttypes(),
985 'post__in' => $post_ids,
986 'post_status' => array('publish'),
987 'posts_per_page' => self::get_items_per_page( 'listings' ),
988 'paged' => $paged,
989 );
990
991 if (get_current_user_id() == $user->ID) {
992 $query_args['post_status'] = array(
993 'publish',
994 'draft',
995 'private',
996 'pending',
997 'gd-closed',
998 'gd-expired'
999 );
1000 }
1001
1002 $the_query = new WP_Query($query_args);
1003 } else {
1004 $the_query = array();
1005 }
1006
1007 $args = array();
1008 $args['template_args']['the_query'] = $the_query;
1009 $args['template_args']['title'] = $active_tab && !empty($subtabs) && !empty($subtabs[$active_tab]['title']) ? $subtabs[$active_tab]['title'] : '';
1010 $args['template_args']['list_data'] = isset($subtabs[$active_tab]) ? $subtabs[$active_tab] : array();
1011 $title = isset($args['template_args']['title']) ? $args['template_args']['title'] : '';
1012 $found_posts = !empty($the_query) && !empty($the_query->found_posts) ? $the_query->found_posts : 0;
1013
1014 if ($found_posts) {
1015 $widget_args = array(
1016 'column_gap_class' => 'mb-4',
1017 'row_gap_class' => '',
1018 'card_border_class' => 'border-0',
1019 'card_shadow_class' => '',
1020 'layout' => '3',
1021 );
1022
1023 $template_args = apply_filters( 'uwp_profile_tab_lists_args', $widget_args );
1024 $gd_layout_class = geodir_convert_listing_view_class( $template_args['layout'] );
1025 ?>
1026 <div class="container mb-1">
1027 <div class="row">
1028 <div class="col-sm p-0 uwp-loop-posts-title">
1029 <h3><?php echo esc_html($title); ?></h3>
1030 </div>
1031 <div class="col p-0 d-sm-block uwp-loop-posts-toolbar">
1032 <div class="btn-toolbar justify-content-end" role="toolbar" aria-label="Toolbar with button groups">
1033 <?php geodir_list_view_select('gd_list'); ?>
1034 </div>
1035 </div>
1036 </div>
1037 </div>
1038 <?php do_action('uwp_profile_posts_loop_wrap_start', $args, $found_posts); ?>
1039 <div class="geodir-loop-container">
1040 <div class="row row-cols-1 row-cols-sm-2 geodir-category-list-view <?php echo esc_attr( $gd_layout_class ); ?>">
1041 <?php
1042 while ($the_query->have_posts()) : $the_query->the_post();
1043 echo geodir_get_template_html("bootstrap/content-listing.php", array(
1044 'column_gap_class' => $template_args['column_gap_class'],
1045 'row_gap_class' => $template_args['row_gap_class'],
1046 'card_border_class' => $template_args['card_border_class'],
1047 'card_shadow_class' => $template_args['card_shadow_class'],
1048 ));
1049 endwhile;
1050 wp_reset_postdata();
1051 ?>
1052 </div>
1053 </div>
1054 <?php
1055 do_action('uwp_profile_pagination', $the_query->max_num_pages);
1056 }
1057 }
1058
1059 public function get_listings_from_list( $list_id ) {
1060 global $wpdb;
1061 $post_ids_obj = $wpdb->get_results( $wpdb->prepare( "SELECT p2p_from FROM $wpdb->p2p WHERE p2p_to = %d", absint( $list_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1062 $post_ids = wp_list_pluck( $post_ids_obj, 'p2p_from' );
1063
1064 return $post_ids;
1065 }
1066
1067 /**
1068 * Adjust the post footer info for GD posts.
1069 *
1070 * @param $html
1071 *
1072 * @return string
1073 */
1074 public function posts_footer( $html ) {
1075 global $post, $aui_bs5;
1076
1077 if ( ! empty( $post->post_type ) && uwp_is_gdv2() && geodir_is_gd_post_type( $post->post_type ) ) {
1078 $post_avgratings = geodir_get_post_rating( $post->ID );
1079 $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1080 $actions_shortcode = apply_filters('uwp_profile_gd_post_author_action', '[gd_author_actions text_color="secondary"]');
1081 $author_actions = do_shortcode( $actions_shortcode );
1082
1083 $new_html = '<div class="row">';
1084 $new_html .= '<div class="col">' . $post_ratings . '</div>';
1085 if ( $author_actions ) {
1086 // add some bootstrap styles
1087 $author_actions = str_replace(
1088 array( "gd_user_action", "gd-author-actions", "gd_delete_post", "btn btn-sm text-white" ),
1089 array( "gd_user_action dropdown-item position-relative", "", "uwp_gd_delete_post", "" ),
1090 $author_actions
1091 );
1092
1093 $new_html .= '
1094 <div class="col-2 text-right">
1095 <div class="btn-group dropup">
1096 <a href="#" class="dropdown h5 text-muted m-0" data-' . ( $aui_bs5 ? 'bs-' : '' ) . 'toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1097 <i class="fas fa-ellipsis-v fa-sm fa-fw"></i>
1098 </a>
1099 <div class="dropdown-menu dropdown-menu-right dropdown-caret-0">
1100 ' . $author_actions . '
1101 </div>
1102 </div>
1103 </div>
1104 ';
1105 }
1106 $new_html .= '</div>';
1107
1108 return $new_html;
1109 } else {
1110 return $html;
1111 }
1112 }
1113
1114 /**
1115 * Displays listings
1116 *
1117 * @since 1.0.0
1118 * @package userswp
1119 *
1120 * @param object $user User object
1121 * @param string $post_type Post type
1122 *
1123 */
1124 public function gd_get_listings( $user, $post_type ) {
1125 if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1126 self::get_bootstrap_listings( $user, $post_type );
1127 } else {
1128 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1129
1130 if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1131 $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1132 } else {
1133 $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1134 }
1135
1136 $args = array(
1137 'post_type' => $post_type,
1138 'post_status' => $post_status,
1139 'posts_per_page' => self::get_items_per_page( 'listings' ),
1140 'author' => $user->ID,
1141 'paged' => $paged,
1142 'uwp_geodir_query' => true
1143 );
1144
1145 $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
1146
1147 // The Query
1148 $the_query = new WP_Query( $args );
1149
1150 if ( isset( $the_query->found_posts ) && $the_query->found_posts == 0 ) {
1151 return;
1152 }
1153 ?>
1154 <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ) ?></h3>
1155
1156 <div class="uwp-profile-item-block">
1157 <?php
1158
1159 do_action( 'uwp_before_profile_listing_items', $user, $post_type );
1160 // The Loop
1161 if ( $the_query->have_posts() ) {
1162 echo '<ul class="uwp-profile-item-ul">';
1163 while ( $the_query->have_posts() ) {
1164 $the_query->the_post();
1165 $post_id = get_the_ID();
1166 global $post;
1167 $post = geodir_get_post_info( $post_id );
1168 setup_postdata( $post );
1169
1170 if ( empty( $post ) ) {
1171 continue;
1172 }
1173
1174 $post_avgratings = geodir_get_post_rating( $post->ID );
1175 $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1176 ob_start();
1177 if ( uwp_is_gdv2() ) {
1178 geodir_comments_number();
1179 } else {
1180 geodir_comments_number( (int) $post->rating_count );
1181 }
1182 $n_comments = ob_get_clean();
1183
1184 do_action( 'uwp_before_profile_listing_item', $post_id, $user, $post_type );
1185 ?>
1186 <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1187 <a class="uwp-profile-item-img" href="<?php echo esc_url( get_the_permalink() ); ?>">
1188 <?php
1189 if ( has_post_thumbnail() ) {
1190 $thumb_url = get_the_post_thumbnail_url( get_the_ID(), array( 80, 80 ) );
1191 } else {
1192 $thumb_url = uwp_get_default_thumb_uri();
1193 }
1194 ?>
1195 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo esc_url( $thumb_url ); ?>">
1196 </a>
1197
1198 <?php do_action( 'uwp_before_profile_listing_title', $post_id, $user, $post_type ); ?>
1199 <h3 class="uwp-profile-item-title">
1200 <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a>
1201 </h3>
1202 <?php do_action( 'uwp_after_profile_listing_title', $post_id, $user, $post_type ); ?>
1203
1204 <div class="uwp-time-ratings-wrap">
1205 <?php do_action( 'uwp_before_profile_listing_ratings', $post_id, $user, $post_type ); ?>
1206 <time class="uwp-profile-item-time published"
1207 datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1208 <?php echo esc_html( get_the_date() ); ?>
1209 </time>
1210 <?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . esc_url( get_comments_link() ) . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1211 <?php
1212 if ( ! is_user_logged_in() ) {
1213 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
1214 }
1215 ?>
1216 <?php do_action( 'uwp_after_profile_listing_ratings', $post_id, $user, $post_type ); ?>
1217 </div>
1218
1219 <div class="uwp-profile-item-summary">
1220 <?php
1221 do_action( 'uwp_before_profile_listing_summary', $post_id, $user, $post_type );
1222 $excerpt = strip_shortcodes( wp_trim_words( get_the_excerpt(), 15, '...' ) );
1223 echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1224 do_action( 'uwp_after_profile_listing_summary', $post_id, $user, $post_type );
1225 ?>
1226 </div>
1227
1228 <div class="uwp-item-actions">
1229 <?php
1230 if ( is_user_logged_in() ) {
1231 geodir_favourite_html( '', $post->ID );
1232 }
1233 if ( $post->post_author == get_current_user_id() ) {
1234 if ( uwp_is_gdv2() ) {
1235 $href = 'javascript:void(0);';
1236 $class = '';
1237 $editlink = geodir_edit_post_link( $post_id );
1238 $extra = 'onclick="uwp_gd_delete_post(' . $post_id . ');"';
1239 } else {
1240 $ajaxlink = geodir_get_ajax_url();
1241 $href = geodir_getlink( $ajaxlink, array(
1242 'geodir_ajax' => 'add_listing',
1243 'ajax_action' => 'delete',
1244 'pid' => $post->ID
1245 ), false );
1246 $class = 'geodir-delete';
1247 $addplacelink = get_permalink( geodir_add_listing_page_id() );
1248 $editlink = geodir_getlink( $addplacelink, array( 'pid' => $post->ID ), false );
1249 $extra = '';
1250 }
1251 ?>
1252
1253 <span class="geodir-authorlink clearfix">
1254
1255 <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1256
1257 <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1258 title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1259 <?php
1260 $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1261 echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
1262 ?>
1263 <?php esc_html_e( 'Edit', 'userswp' ); ?>
1264 </a>
1265 <a href="<?php echo $href; ?>" <?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="<?php echo esc_attr( $class ); ?>" title="<?php esc_attr_e( 'Delete Listing', 'userswp' ); ?>">
1266 <?php
1267 $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times', $post_id, $user, $post_type );
1268 echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
1269 ?>
1270 <?php esc_html_e( 'Delete', 'userswp' ); ?>
1271 </a>
1272 <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1273
1274 </span>
1275
1276 <?php } ?>
1277 </div>
1278 </li>
1279 <?php
1280 do_action( 'uwp_after_profile_listing_item', $post_id, $user, $post_type );
1281 }
1282 echo '</ul>';
1283 /* Restore original Post Data */
1284 wp_reset_postdata();
1285 } else {
1286 echo aui()->alert( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1287 'type' => 'info',
1288 'content' => esc_html( wp_sprintf( __( "No %s found.", 'userswp' ), geodir_post_type_name( $post_type , true ) ) )
1289 ) );
1290 }
1291 do_action( 'uwp_after_profile_listing_items', $user, $post_type );
1292
1293 do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1294 ?>
1295 </div>
1296 <?php
1297 }
1298 }
1299
1300 /**
1301 * Displays subtab content
1302 *
1303 * @package userswp
1304 *
1305 * @param object $user User object
1306 * @param string $post_type Post type
1307 *
1308 */
1309 public function get_bootstrap_listings( $user, $post_type ) {
1310 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1311
1312 if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1313 $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1314 } else {
1315 $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1316 }
1317
1318 $query_args = array(
1319 'post_type' => $post_type,
1320 'post_status' => $post_status,
1321 'posts_per_page' => self::get_items_per_page( 'listings' ),
1322 'author' => $user->ID,
1323 'paged' => $paged,
1324 'uwp_geodir_query' => true
1325 );
1326
1327 $query_args = apply_filters( 'uwp_listing_query_args', $query_args, $user, $post_type );
1328
1329 // The Query
1330 $the_query = new WP_Query( $query_args );
1331
1332 $title = geodir_post_type_name( $post_type , true );
1333 $found_posts = ! empty( $the_query ) && ! empty( $the_query->found_posts ) ? $the_query->found_posts : 0;
1334
1335 if($found_posts) {
1336 $widget_args = array(
1337 'column_gap_class' => 'mb-4',
1338 'row_gap_class' => '',
1339 'card_border_class' => 'border-0',
1340 'card_shadow_class' => '',
1341 'layout' => '3',
1342 );
1343
1344 $template_args = apply_filters( 'uwp_profile_tab_listings_args', $widget_args );
1345
1346 $gd_layout_class = geodir_convert_listing_view_class( $template_args['layout'] );
1347 ?>
1348 <div class="container mb-1">
1349 <div class="row">
1350 <div class="col-sm p-0 uwp-loop-posts-title">
1351 <h3><?php echo esc_html( $title ); ?></h3>
1352 </div>
1353 <div class="col p-0 d-sm-block uwp-loop-posts-toolbar">
1354 <div class="btn-toolbar justify-content-end" role="toolbar" aria-label="Toolbar with button groups">
1355 <?php
1356 geodir_list_view_select($post_type);
1357 ?>
1358 </div>
1359 </div>
1360 </div>
1361 </div>
1362 <div class="geodir-loop-container">
1363 <div class="row row-cols-1 row-cols-sm-2 geodir-category-list-view <?php echo esc_attr( $gd_layout_class ); ?>">
1364 <?php
1365 while ( $the_query->have_posts() ) : $the_query->the_post();
1366 echo geodir_get_template_html( "bootstrap/content-listing.php", array(
1367 'column_gap_class' => $template_args['column_gap_class'],
1368 'row_gap_class' => $template_args['row_gap_class'],
1369 'card_border_class' => $template_args['card_border_class'],
1370 'card_shadow_class' => $template_args['card_shadow_class'],
1371 'template_part' => $template_args['card_shadow_class'],
1372 ) );
1373 endwhile;
1374 wp_reset_postdata();
1375 ?>
1376 </div>
1377 </div>
1378 <?php
1379 do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1380 }
1381 }
1382
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 );
1394
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>';
1398
1399 $new_html .= '<div class="col">' . $comment_link . '</div>';
1400
1401 $new_html .= '</div>';
1402
1403 return $new_html;
1404 } else {
1405 return $html;
1406 }
1407 }
1408
1409 /**
1410 * Displays reviews
1411 *
1412 * @since 1.0.0
1413 * @package userswp
1414 *
1415 * @param object $user User object
1416 * @param string $post_type Post type
1417 *
1418 */
1419 public function gd_get_reviews( $user, $post_type ) {
1420 if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1421 self::get_bootstrap_reviews( $user, $post_type );
1422 } else {
1423
1424 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1425 $limit = self::get_items_per_page( 'reviews' );
1426 $offset = ( $paged - 1 ) * $limit;
1427
1428 $total_reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, true, $offset, $limit );
1429 $maximum_pages = ceil( $total_reviews / $limit );
1430
1431 $reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, false, $offset, $limit );
1432
1433 // The Loop
1434 if ( !$reviews ) {
1435 return;
1436 }
1437 do_action( 'uwp_before_profile_reviews_items', $user, $post_type );
1438 ?>
1439 <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ); ?></h3>
1440
1441 <div class="uwp-profile-item-block">
1442 <ul class="uwp-profile-item-ul">
1443 <?php
1444 foreach ( $reviews as $review ) {
1445 $rating = 0;
1446 if ( ! empty( $review ) ) {
1447 $rating = geodir_get_post_rating( $review->post_id );
1448 }
1449 do_action( 'uwp_before_profile_reviews_item', $review->comment_id, $user, $post_type );
1450 ?>
1451 <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1452 <a class="uwp-profile-item-img"
1453 href="<?php echo esc_url( get_comment_link( $review->comment_id ) ); ?>">
1454 <?php
1455 if ( has_post_thumbnail( $review->post_id ) ) {
1456 $thumb_url = get_the_post_thumbnail_url( $review->post_id, array( 80, 80 ) );
1457 } else {
1458 $thumb_url = uwp_get_default_thumb_uri();
1459 }
1460 ?>
1461 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb"
1462 src="<?php echo esc_url( $thumb_url ); ?>">
1463 </a>
1464
1465 <?php do_action( 'uwp_before_profile_reviews_title', $review->comment_id, $user, $post_type ); ?>
1466 <h3 class="uwp-profile-item-title">
1467 <a href="<?php echo esc_url( get_comment_link( $review->comment_id ) ); ?>"><?php echo esc_html( get_the_title( $review->post_id ) ); ?></a>
1468 </h3>
1469 <?php do_action( 'uwp_after_profile_reviews_title', $review->comment_id, $user, $post_type ); ?>
1470
1471 <div class="uwp-time-ratings-wrap">
1472 <?php do_action( 'uwp_before_profile_reviews_ratings', $review->comment_id, $user, $post_type ); ?>
1473 <time class="uwp-profile-item-time published"
1474 datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1475 <?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( get_comment_date( "", $review->comment_id ) ) ) ); ?>
1476 </time>
1477 <?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars( $rating, $review->comment_id ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1478 <?php do_action( 'uwp_after_profile_reviews_ratings', $review->comment_id, $user, $post_type ); ?>
1479 </div>
1480 <div class="uwp-profile-item-summary">
1481 <?php
1482 do_action( 'uwp_before_profile_reviews_summary', $review->comment_id, $user, $post_type );
1483 $excerpt = strip_shortcodes( wp_trim_words( get_comment_excerpt( $review->comment_id ), 15, '...' ) );
1484 echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1485 do_action( 'uwp_after_profile_reviews_summary', $review->comment_id, $user, $post_type );
1486 ?>
1487 </div>
1488 <div class="uwp-item-actions">
1489 <?php
1490 if ( is_user_logged_in() ) {
1491 geodir_favourite_html( '', $review->post_id );
1492 }
1493 if ( get_post_field( 'post_author', $review->post_id ) == get_current_user_id() ) {
1494 if ( uwp_is_gdv2() ) {
1495 $href = 'javascript:void(0);';
1496 $class = '';
1497 $editlink = geodir_edit_post_link( $review->post_id );
1498 $extra = 'onclick="uwp_gd_delete_post(' . $review->post_id . ');"';
1499 } else {
1500 $ajaxlink = geodir_get_ajax_url();
1501 $href = geodir_getlink( $ajaxlink, array(
1502 'geodir_ajax' => 'add_listing',
1503 'ajax_action' => 'delete',
1504 'pid' => $review->post_id
1505 ), false );
1506 $class = 'geodir-delete';
1507 $addplacelink = get_permalink( geodir_add_listing_page_id() );
1508 $editlink = geodir_getlink( $addplacelink, array( 'pid' => $review->post_id ), false );
1509 $extra = '';
1510 }
1511 ?>
1512
1513 <span class="geodir-authorlink clearfix">
1514
1515 <?php do_action( 'geodir_before_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
1516
1517 <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1518 title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1519 <?php
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>';
1522 ?>
1523 <?php esc_html_e( 'Edit', 'userswp' ); ?>
1524 </a>
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' ); ?>">
1528 <?php
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>';
1531 ?>
1532 <?php esc_html_e( 'Delete', 'userswp' ); ?>
1533 </a>
1534
1535 <?php do_action( 'geodir_after_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
1536
1537 </span>
1538
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>
1547
1548 <?php
1549 /* Restore original Post Data */
1550 wp_reset_postdata();
1551
1552 do_action( 'uwp_after_profile_reviews_items', $user, $post_type );
1553
1554 do_action( 'uwp_profile_pagination', $maximum_pages );
1555 ?>
1556 </div>
1557 <?php
1558 }
1559 }
1560
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();
1575
1576 $args['template_args']['title'] = __( "Reviews", 'userswp' );
1577
1578 $userswp->profile->get_profile_comments( $user, $post_type, $args );
1579
1580 $geodir_post_type = '';
1581
1582 }
1583
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;
1599
1600 $user_fav_posts = geodir_get_user_favourites( $user->ID );
1601
1602 if ( ! $user_fav_posts ) {
1603 return;
1604 }
1605
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 }
1611
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 );
1620
1621 $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
1622
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 ); ?>">
1665 </a>
1666
1667 <?php do_action( 'uwp_before_profile_favourite_title', $post_id, $user, $post_type ); ?>
1668 <h3 class="uwp-profile-item-title">
1669 <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a>
1670 </h3>
1671 <?php do_action( 'uwp_after_profile_favourite_title', $post_id, $user, $post_type ); ?>
1672
1673 <div class="uwp-time-ratings-wrap">
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(); ?>
1678 </time>
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 ); ?>
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
1697 <div class="uwp-item-actions">
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 ?>
1721
1722 <span class="geodir-authorlink clearfix">
1723
1724 <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1725
1726 <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1727 title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1728 <?php
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>';
1731 ?>
1732 <?php esc_html_e( 'Edit', 'userswp' ); ?>
1733 </a>
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' ); ?>">
1737 <?php
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>';
1740 ?>
1741 <?php esc_html_e( 'Delete', 'userswp' ); ?>
1742 </a>
1743
1744 <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1745
1746 </span>
1747
1748 <?php } ?>
1749 </div>
1750 </li>
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 }
1758
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));
1787 } else {
1788 $post_status = geodir_get_post_stati('public', array('post_type' => $post_type));
1789 }
1790
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 );
1799
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);
1850 }
1851 }
1852 }
1853
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 }
1869
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 );
1874
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 );
1890
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 }
1898
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 }
1904
1905 $url = $uwp_url;
1906 }
1907
1908 return $url;
1909 }
1910
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' ) );
1922
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;
1926
1927 $author_id = $author->ID;
1928 $author_link = uwp_build_profile_tab_url( $author_id );
1929 $gd_post_types = geodir_get_posttypes( 'array' );
1930
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() );
1934
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() );
1942
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 }
1950
1951 wp_redirect( $author_link );
1952 exit;
1953 }
1954 }
1955
1956 return;
1957 }
1958
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 }
1972
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;
1983
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'] : '';
1987
1988 if ( empty( $active_tab ) && empty( $uwp_profile_first_tab ) && $uwp_profile_doing_tab ) {
1989 $active_tab = $uwp_profile_doing_tab;
1990 }
1991
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 }
1995
1996 if ( $active_tab == 'listings' || $active_tab == 'favorites' ) {
1997 return true;
1998 }
1999 }
2000
2001 return false;
2002 }
2003
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;
2014
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() ) {
2018
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>";
2041
2042 $html = '<span class="geodir-post-status">' . $status_icon . ' <span class="geodir-status-label">' . __( 'Status: ', 'userswp' ) . '</span>' . $status . '</span>';
2043 }
2044 }
2045
2046 if ( $html != '' ) {
2047 echo apply_filters( 'geodir_filter_status_text_on_author_page', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2048 }
2049 }
2050
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 }
2064
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 }
2078
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 }
2092
2093 /**
2094 * Displays nonce field in GD login form
2095 *
2096 * @since 1.0.0
2097 * @package userswp
2098 *
2099 */
2100 public function gd_login_inject_nonce() {
2101 if ( ! uwp_is_gdv2() ) {
2102 ?>
2103 <input type="hidden" name="uwp_login_nonce" value="<?php echo esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ); ?>"/>
2104 <?php
2105 }
2106 }
2107
2108 /**
2109 * Check author page redirect
2110 *
2111 * @since 1.0.0
2112 * @package userswp
2113 *
2114 * @param bool $redirect
2115 *
2116 * @return bool
2117 *
2118 */
2119 public function check_redirect_author_page( $redirect = false ) {
2120 if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) {
2121 $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
2122
2123 if ( ! empty( $author ) && ! empty( $author->ID ) ) {
2124 $favourite = isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' ? true : false;
2125 $post_type = isset( $_REQUEST['stype'] ) ? esc_attr( $_REQUEST['stype'] ) : null;
2126
2127 $author_id = $author->ID;
2128 $author_link = uwp_build_profile_tab_url( $author_id );
2129 $gd_post_types = geodir_get_posttypes( 'array' );
2130
2131 if ( ! empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
2132 if ( $favourite ) {
2133 $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
2134
2135 if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
2136 // Redirect to dashboard CPT favorites.
2137 } else {
2138 $redirect = false; // Do not redirect to dashboard CPT favorites.
2139 }
2140 } else {
2141 $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
2142
2143 if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
2144 // Redirect to dashboard CPT listings.
2145 } else {
2146 $redirect = false; // Do not redirect to dashboard CPT listings.
2147 }
2148 }
2149 }
2150 }
2151 }
2152
2153 return $redirect;
2154 }
2155
2156 /**
2157 * Check if skip author page
2158 *
2159 * @since 1.0.0
2160 * @package userswp
2161 *
2162 * @param bool $uwp_author
2163 *
2164 * @return bool
2165 *
2166 */
2167 public function skip_uwp_author_page( $uwp_author = true ) {
2168 if ( geodir_is_page( 'author' ) ) {
2169 $uwp_author = false;
2170 }
2171
2172 return $uwp_author;
2173 }
2174
2175 public function get_widget_post_author( $post_author, $instance, $id_base = '' ) {
2176 if ( isset( $id_base ) && 'gd_listings' == $id_base ) {
2177 if ( is_uwp_profile_page() && isset( $instance['post_author'] ) && 'current_author' == $instance['post_author'] ) {
2178 $user = uwp_get_user_by_author_slug();
2179 if ( $user && isset( $user->ID ) ) {
2180 $post_author = $user->ID;
2181 }
2182 }
2183 }
2184
2185 return $post_author;
2186 }
2187
2188 public function get_widget_favorites_by_user( $favorites_by_user, $instance, $id_base = '' ) {
2189 if ( isset( $id_base ) && 'gd_listings' == $id_base ) {
2190 if ( is_uwp_profile_page() && isset( $instance['favorites_by_user'] ) && 'current_author' == $instance['favorites_by_user'] ) {
2191 $user = uwp_get_user_by_author_slug();
2192 if ( $user && isset( $user->ID ) ) {
2193 $favorites_by_user = $user->ID;
2194 }
2195 }
2196 }
2197
2198 return $favorites_by_user;
2199 }
2200
2201 /**
2202 * Unset GD Post variable after posts loop.
2203 *
2204 * @since 1.2.3.12
2205 */
2206 public function unset_gd_post() {
2207 global $gd_post;
2208 $gd_post = NULL;
2209 }
2210
2211 public function posts_join( $join, $wp_query ) {
2212 global $wpdb;
2213
2214 if ( ! empty( $wp_query ) && ! empty( $wp_query->query_vars ) && ! empty( $wp_query->query_vars['uwp_geodir_query'] ) && ! empty( $wp_query->query_vars['post_type'] ) ) {
2215 $post_type = $wp_query->query_vars['post_type'];
2216
2217 if ( is_scalar( $post_type ) && geodir_is_gd_post_type( $post_type ) ) {
2218 $table = geodir_db_cpt_table( $post_type );
2219
2220 $join .= ( $join ? " " : "" ) . "INNER JOIN `" . $table . "` ON ( `" . $table . "`.`post_id` = `" . $wpdb->posts . "`.`ID` )";
2221 }
2222 }
2223
2224 return $join;
2225 }
2226
2227 public function get_usernumposts( $count, $userid, $post_type, $public_only ) {
2228 global $_uwp_user_post_counts;
2229
2230 if ( ! empty( $_uwp_user_post_counts ) && is_scalar( $post_type ) && geodir_is_gd_post_type( $post_type ) ) {
2231 $count = $this->get_listings_count( $post_type, $userid );
2232 }
2233
2234 return $count;
2235 }
2236
2237 public static function get_items_per_page( $item = '' ) {
2238 $per_page = (int) uwp_get_option( 'profile_no_of_items', 10 );
2239
2240 if ( $per_page < 1 ) {
2241 $per_page = 10;
2242 }
2243
2244 return (int) apply_filters( 'uwp_geodir_items_per_page', $per_page, $item );
2245 }
2246 }
2247
2248 $userswp_geodirectory = UsersWP_GeoDirectory_Plugin::get_instance();