PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.11
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.11
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
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 1.2.11, at includes/libraries/class-geodirectory-plugin.php

2,100 lines 72.4 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
888 if ( ! class_exists( 'GeoDir_Lists' ) ) {
889 return;
890 }
891
892 $subtab = get_query_var( 'uwp_subtab' );
893 $uwp_tab = get_query_var('uwp_tab');
894 $type = geodir_lists_slug();
895 $user_lists = GeoDir_Lists_Data::get_user_lists( $user->ID );
896 $subtabs = array();
897 if ( ! empty( $user_lists ) ) {
898 foreach ( $user_lists as $list ) {
899 $subtabs[ $list->post_name ] = array(
900 'id' => $list->ID,
901 'title' => $list->post_title,
902 'count' => count( $this->get_listings_from_list( $list->ID ) ),
903 );
904 }
905 }
906
907 if ( ! empty( $subtabs ) ) {
908 $subtab_keys = array_keys( $subtabs );
909 $default_tab = isset($subtab_keys[0]) ? $subtab_keys[0] : '';
910 } else {
911 $default_tab = '';
912 }
913
914 $default_tab = apply_filters( 'uwp_default_gd_lists_subtab', $default_tab, $user, $type );
915 $active_tab = ! empty( $subtab ) && array_key_exists( $subtab, $subtabs ) ? $subtab : $default_tab;
916 if(! empty( $active_tab ) && isset($subtabs[ $active_tab ]['id'])){
917 $active_id = $subtabs[ $active_tab ]['id'];
918 } elseif(isset($subtabs[ $default_tab ]['id'])){
919 $active_id = $subtabs[ $default_tab ]['id'];
920 } else {
921 $active_id = '';
922 }
923
924 if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
925 if ( is_array( $subtabs ) && count( $subtabs ) > 0 ) {
926 ?>
927 <div class="pb-3">
928 <?php
929 foreach ( $subtabs as $tab_id => $tab ) {
930 $tab_url = uwp_build_profile_tab_url( $user->ID, $uwp_tab, $tab_id );
931 $active = $active_tab == $tab_id ? 'btn-primary' : 'btn-outline-primary';
932 ?>
933 <a id="uwp-profile-gd-<?php echo esc_attr($tab_id); ?>" href="<?php echo esc_url( $tab_url ); ?>"
934 class=" btn btn-sm <?php echo esc_attr($active); ?>">
935 <?php echo esc_html__( $tab['title'], 'userswp' ); ?>
936 <span class="badge badge-light ml-1"><?php echo esc_html( $tab['count'] ); ?></span>
937 </a>
938 <?php
939 }
940 ?>
941 </div>
942 <?php
943 }
944 } else {
945 if ( ! empty( $subtabs ) ) { ?>
946 <div class="uwp-profile-subcontent">
947 <div class="uwp-profile-subnav">
948 <ul class="item-list-subtabs-ul">
949 <?php
950 foreach ( $subtabs as $tab_id => $tab ) {
951 $tab_url = uwp_build_profile_tab_url( $user->ID, $type, $tab_id );
952 $active = $active_tab == $tab_id ? ' active' : '';
953 ?>
954 <li id="uwp-profile-gd-<?php echo esc_attr($tab_id); ?>" class="<?php echo esc_attr($active); ?>">
955 <a href="<?php echo esc_url( $tab_url ); ?>">
956 <span
957 class="uwp-profile-tab-label uwp-profile-gd-<?php echo esc_attr($tab_id); ?>-label "><span
958 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>
959 </a>
960 </li>
961 <?php
962 }
963 ?>
964 </ul>
965 </div>
966 </div>
967 <?php }
968 }
969
970 $post_ids = $this->get_listings_from_list( $active_id );
971 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
972
973 if ( ! empty( $post_ids ) ) {
974 ob_start();
975 $query_args = array(
976 'is_geodir_loop' => true,
977 'gd_location' => false,
978 'post_type' => geodir_get_posttypes(),
979 'post__in' => $post_ids,
980 'post_status' => array( 'publish' ),
981 'posts_per_page' => uwp_get_option( 'profile_no_of_items', 10 ),
982 'paged' => $paged,
983 );
984
985 if ( get_current_user_id() == $user->ID ) {
986 $query_args['post_status'] = array(
987 'publish',
988 'draft',
989 'private',
990 'pending',
991 'gd-closed',
992 'gd-expired'
993 );
994 }
995
996 $the_query = new WP_Query( $query_args );
997
998 $args = array();
999 $args['template_args']['the_query'] = $the_query;
1000 $args['template_args']['title'] = $subtabs[ $active_tab ]['title'];
1001
1002 uwp_get_template( "bootstrap/loop-posts.php", $args );
1003 echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1004 }
1005 }
1006
1007 public function get_listings_from_list( $list_id ) {
1008 global $wpdb;
1009 $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
1010 $post_ids = wp_list_pluck( $post_ids_obj, 'p2p_from' );
1011
1012 return $post_ids;
1013 }
1014
1015 /**
1016 * Adjust the post footer info for GD posts.
1017 *
1018 * @param $html
1019 *
1020 * @return string
1021 */
1022 public function posts_footer( $html ) {
1023 global $post, $aui_bs5;
1024
1025 if ( ! empty( $post->post_type ) && uwp_is_gdv2() && geodir_is_gd_post_type( $post->post_type ) ) {
1026 $post_avgratings = geodir_get_post_rating( $post->ID );
1027 $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1028 $actions_shortcode = apply_filters('uwp_profile_gd_post_author_action', '[gd_author_actions text_color="secondary"]');
1029 $author_actions = do_shortcode( $actions_shortcode );
1030
1031 $new_html = '<div class="row">';
1032 $new_html .= '<div class="col">' . $post_ratings . '</div>';
1033 if ( $author_actions ) {
1034 // add some bootstrap styles
1035 $author_actions = str_replace(
1036 array( "gd_user_action", "gd-author-actions", "gd_delete_post", "btn btn-sm text-white" ),
1037 array( "gd_user_action dropdown-item position-relative", "", "uwp_gd_delete_post", "" ),
1038 $author_actions
1039 );
1040
1041 $new_html .= '
1042 <div class="col-2 text-right">
1043 <div class="btn-group dropup">
1044 <a href="#" class="dropdown h5 text-muted m-0" data-' . ( $aui_bs5 ? 'bs-' : '' ) . 'toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1045 <i class="fas fa-ellipsis-v fa-sm fa-fw"></i>
1046 </a>
1047 <div class="dropdown-menu dropdown-menu-right dropdown-caret-0">
1048 ' . $author_actions . '
1049 </div>
1050 </div>
1051 </div>
1052 ';
1053 }
1054 $new_html .= '</div>';
1055
1056 return $new_html;
1057 } else {
1058 return $html;
1059 }
1060 }
1061
1062 /**
1063 * Displays listings
1064 *
1065 * @since 1.0.0
1066 * @package userswp
1067 *
1068 * @param object $user User object
1069 * @param string $post_type Post type
1070 *
1071 */
1072 public function gd_get_listings( $user, $post_type ) {
1073 if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1074 self::get_bootstrap_listings( $user, $post_type );
1075 } else {
1076 $gd_post_types = geodir_get_posttypes( 'array' );
1077
1078 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1079
1080 if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1081 $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1082 } else {
1083 $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1084 }
1085
1086 $args = array(
1087 'post_type' => $post_type,
1088 'post_status' => $post_status,
1089 'posts_per_page' => uwp_get_option( 'profile_no_of_items', 10 ),
1090 'author' => $user->ID,
1091 'paged' => $paged,
1092 'uwp_geodir_query' => true
1093 );
1094
1095 $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
1096
1097 // The Query
1098 $the_query = new WP_Query( $args );
1099
1100 if ( isset( $the_query->found_posts ) && $the_query->found_posts == 0 ) {
1101 return;
1102 }
1103 ?>
1104 <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ) ?></h3>
1105
1106 <div class="uwp-profile-item-block">
1107 <?php
1108
1109 do_action( 'uwp_before_profile_listing_items', $user, $post_type );
1110 // The Loop
1111 if ( $the_query->have_posts() ) {
1112 echo '<ul class="uwp-profile-item-ul">';
1113 while ( $the_query->have_posts() ) {
1114 $the_query->the_post();
1115 $post_id = get_the_ID();
1116 global $post;
1117 $post = geodir_get_post_info( $post_id );
1118 setup_postdata( $post );
1119
1120 if ( empty( $post ) ) {
1121 continue;
1122 }
1123
1124 $post_avgratings = geodir_get_post_rating( $post->ID );
1125 $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1126 ob_start();
1127 if ( uwp_is_gdv2() ) {
1128 geodir_comments_number();
1129 } else {
1130 geodir_comments_number( (int) $post->rating_count );
1131 }
1132 $n_comments = ob_get_clean();
1133
1134 do_action( 'uwp_before_profile_listing_item', $post_id, $user, $post_type );
1135 ?>
1136 <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1137 <a class="uwp-profile-item-img" href="<?php echo esc_url( get_the_permalink() ); ?>">
1138 <?php
1139 if ( has_post_thumbnail() ) {
1140 $thumb_url = get_the_post_thumbnail_url( get_the_ID(), array( 80, 80 ) );
1141 } else {
1142 $thumb_url = uwp_get_default_thumb_uri();
1143 }
1144 ?>
1145 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo esc_url( $thumb_url ); ?>">
1146 </a>
1147
1148 <?php do_action( 'uwp_before_profile_listing_title', $post_id, $user, $post_type ); ?>
1149 <h3 class="uwp-profile-item-title">
1150 <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a>
1151 </h3>
1152 <?php do_action( 'uwp_after_profile_listing_title', $post_id, $user, $post_type ); ?>
1153
1154 <div class="uwp-time-ratings-wrap">
1155 <?php do_action( 'uwp_before_profile_listing_ratings', $post_id, $user, $post_type ); ?>
1156 <time class="uwp-profile-item-time published"
1157 datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1158 <?php echo esc_html( get_the_date() ); ?>
1159 </time>
1160 <?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 ?>
1161 <?php
1162 if ( ! is_user_logged_in() ) {
1163 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
1164 }
1165 ?>
1166 <?php do_action( 'uwp_after_profile_listing_ratings', $post_id, $user, $post_type ); ?>
1167 </div>
1168
1169 <div class="uwp-profile-item-summary">
1170 <?php
1171 do_action( 'uwp_before_profile_listing_summary', $post_id, $user, $post_type );
1172 $excerpt = strip_shortcodes( wp_trim_words( get_the_excerpt(), 15, '...' ) );
1173 echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1174 do_action( 'uwp_after_profile_listing_summary', $post_id, $user, $post_type );
1175 ?>
1176 </div>
1177
1178 <div class="uwp-item-actions">
1179 <?php
1180 if ( is_user_logged_in() ) {
1181 geodir_favourite_html( '', $post->ID );
1182 }
1183 if ( $post->post_author == get_current_user_id() ) {
1184 if ( uwp_is_gdv2() ) {
1185 $href = 'javascript:void(0);';
1186 $class = '';
1187 $editlink = geodir_edit_post_link( $post_id );
1188 $extra = 'onclick="uwp_gd_delete_post(' . $post_id . ');"';
1189 } else {
1190 $ajaxlink = geodir_get_ajax_url();
1191 $href = geodir_getlink( $ajaxlink, array(
1192 'geodir_ajax' => 'add_listing',
1193 'ajax_action' => 'delete',
1194 'pid' => $post->ID
1195 ), false );
1196 $class = 'geodir-delete';
1197 $addplacelink = get_permalink( geodir_add_listing_page_id() );
1198 $editlink = geodir_getlink( $addplacelink, array( 'pid' => $post->ID ), false );
1199 $extra = '';
1200 }
1201 ?>
1202
1203 <span class="geodir-authorlink clearfix">
1204
1205 <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1206
1207 <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1208 title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1209 <?php
1210 $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1211 echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
1212 ?>
1213 <?php esc_html_e( 'Edit', 'userswp' ); ?>
1214 </a>
1215 <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' ); ?>">
1216 <?php
1217 $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times', $post_id, $user, $post_type );
1218 echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
1219 ?>
1220 <?php esc_html_e( 'Delete', 'userswp' ); ?>
1221 </a>
1222 <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1223
1224 </span>
1225
1226 <?php } ?>
1227 </div>
1228 </li>
1229 <?php
1230 do_action( 'uwp_after_profile_listing_item', $post_id, $user, $post_type );
1231 }
1232 echo '</ul>';
1233 /* Restore original Post Data */
1234 wp_reset_postdata();
1235 } else {
1236 echo aui()->alert( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1237 'type' => 'info',
1238 'content' => esc_html( wp_sprintf( __( "No %s found.", 'userswp' ), geodir_post_type_name( $post_type , true ) ) )
1239 ) );
1240 }
1241 do_action( 'uwp_after_profile_listing_items', $user, $post_type );
1242
1243 do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1244 ?>
1245 </div>
1246 <?php
1247 }
1248 }
1249
1250 /**
1251 * Displays subtab content
1252 *
1253 * @package userswp
1254 *
1255 * @param object $user User object
1256 * @param string $post_type Post type
1257 *
1258 */
1259 public function get_bootstrap_listings( $user, $post_type ) {
1260 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1261
1262 if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1263 $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1264 } else {
1265 $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1266 }
1267
1268 $query_args = array(
1269 'post_type' => $post_type,
1270 'post_status' => $post_status,
1271 'posts_per_page' => uwp_get_option( 'profile_no_of_items', 10 ),
1272 'author' => $user->ID,
1273 'paged' => $paged,
1274 'uwp_geodir_query' => true
1275 );
1276
1277 $query_args = apply_filters( 'uwp_listing_query_args', $query_args, $user, $post_type );
1278
1279 // The Query
1280 $the_query = new WP_Query( $query_args );
1281
1282 $args = array();
1283 $args['template_args']['the_query'] = $the_query;
1284 $args['template_args']['title'] = geodir_post_type_name( $post_type , true );
1285
1286 uwp_get_template( "bootstrap/loop-posts.php", $args );
1287 }
1288
1289 /**
1290 * Adjust the post footer info for GD posts.
1291 *
1292 * @param $html
1293 *
1294 * @return string
1295 */
1296 public function reviews_footer( $html, $comment ) {
1297 if ( ! empty( $comment->post_type ) && geodir_is_gd_post_type( $comment->post_type ) ) {
1298 $comment_rating = geodir_get_comment_rating( $comment->ID );
1299 $comment_rating_html = geodir_get_rating_stars( $comment_rating, $comment->comment_post_ID );
1300
1301 $new_html = '<div class="row">';
1302 $new_html .= '<div class="col">' . $comment_rating_html . '</div>';
1303 $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>';
1304
1305 $new_html .= '<div class="col">' . $comment_link . '</div>';
1306
1307 $new_html .= '</div>';
1308
1309 return $new_html;
1310 } else {
1311 return $html;
1312 }
1313 }
1314
1315 /**
1316 * Displays reviews
1317 *
1318 * @since 1.0.0
1319 * @package userswp
1320 *
1321 * @param object $user User object
1322 * @param string $post_type Post type
1323 *
1324 */
1325 public function gd_get_reviews( $user, $post_type ) {
1326 if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1327 self::get_bootstrap_reviews( $user, $post_type );
1328 } else {
1329 $gd_post_types = geodir_get_posttypes( 'array' );
1330
1331 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1332 $limit = uwp_get_option( 'profile_no_of_items', 10 );
1333 $offset = ( $paged - 1 ) * $limit;
1334
1335 $total_reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, true, $offset, $limit );
1336 $maximum_pages = ceil( $total_reviews / $limit );
1337
1338 $reviews = $this->geodir_get_reviews_by_user_id( $post_type, $user->ID, false, $offset, $limit );
1339
1340 // The Loop
1341 if ( !$reviews ) {
1342 return;
1343 }
1344 do_action( 'uwp_before_profile_reviews_items', $user, $post_type );
1345 ?>
1346 <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ); ?></h3>
1347
1348 <div class="uwp-profile-item-block">
1349 <ul class="uwp-profile-item-ul">
1350 <?php
1351 foreach ( $reviews as $review ) {
1352 $rating = 0;
1353 if ( ! empty( $review ) ) {
1354 $rating = geodir_get_post_rating( $review->post_id );
1355 }
1356 do_action( 'uwp_before_profile_reviews_item', $review->comment_id, $user, $post_type );
1357 ?>
1358 <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1359 <a class="uwp-profile-item-img"
1360 href="<?php echo esc_url( get_comment_link( $review->comment_id ) ); ?>">
1361 <?php
1362 if ( has_post_thumbnail( $review->post_id ) ) {
1363 $thumb_url = get_the_post_thumbnail_url( $review->post_id, array( 80, 80 ) );
1364 } else {
1365 $thumb_url = uwp_get_default_thumb_uri();
1366 }
1367 ?>
1368 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb"
1369 src="<?php echo esc_url( $thumb_url ); ?>">
1370 </a>
1371
1372 <?php do_action( 'uwp_before_profile_reviews_title', $review->comment_id, $user, $post_type ); ?>
1373 <h3 class="uwp-profile-item-title">
1374 <a href="<?php echo esc_url( get_comment_link( $review->comment_id ) ); ?>"><?php echo esc_html( get_the_title( $review->post_id ) ); ?></a>
1375 </h3>
1376 <?php do_action( 'uwp_after_profile_reviews_title', $review->comment_id, $user, $post_type ); ?>
1377
1378 <div class="uwp-time-ratings-wrap">
1379 <?php do_action( 'uwp_before_profile_reviews_ratings', $review->comment_id, $user, $post_type ); ?>
1380 <time class="uwp-profile-item-time published"
1381 datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1382 <?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( get_comment_date( "", $review->comment_id ) ) ) ); ?>
1383 </time>
1384 <?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars( $rating, $review->comment_id ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1385 <?php do_action( 'uwp_after_profile_reviews_ratings', $review->comment_id, $user, $post_type ); ?>
1386 </div>
1387 <div class="uwp-profile-item-summary">
1388 <?php
1389 do_action( 'uwp_before_profile_reviews_summary', $review->comment_id, $user, $post_type );
1390 $excerpt = strip_shortcodes( wp_trim_words( get_comment_excerpt( $review->comment_id ), 15, '...' ) );
1391 echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1392 do_action( 'uwp_after_profile_reviews_summary', $review->comment_id, $user, $post_type );
1393 ?>
1394 </div>
1395 <div class="uwp-item-actions">
1396 <?php
1397 if ( is_user_logged_in() ) {
1398 geodir_favourite_html( '', $review->post_id );
1399 }
1400 if ( get_post_field( 'post_author', $review->post_id ) == get_current_user_id() ) {
1401 if ( uwp_is_gdv2() ) {
1402 $href = 'javascript:void(0);';
1403 $class = '';
1404 $editlink = geodir_edit_post_link( $review->post_id );
1405 $extra = 'onclick="uwp_gd_delete_post(' . $review->post_id . ');"';
1406 } else {
1407 $ajaxlink = geodir_get_ajax_url();
1408 $href = geodir_getlink( $ajaxlink, array(
1409 'geodir_ajax' => 'add_listing',
1410 'ajax_action' => 'delete',
1411 'pid' => $review->post_id
1412 ), false );
1413 $class = 'geodir-delete';
1414 $addplacelink = get_permalink( geodir_add_listing_page_id() );
1415 $editlink = geodir_getlink( $addplacelink, array( 'pid' => $review->post_id ), false );
1416 $extra = '';
1417 }
1418 ?>
1419
1420 <span class="geodir-authorlink clearfix">
1421
1422 <?php do_action( 'geodir_before_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
1423
1424 <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1425 title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1426 <?php
1427 $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1428 echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
1429 ?>
1430 <?php esc_html_e( 'Edit', 'userswp' ); ?>
1431 </a>
1432 <a href="<?php echo $href; ?>" <?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1433 class="<?php echo esc_attr( $class ); ?>"
1434 title="<?php esc_attr_e( 'Delete Listing', 'userswp' ); ?>">
1435 <?php
1436 $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times' );
1437 echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
1438 ?>
1439 <?php esc_html_e( 'Delete', 'userswp' ); ?>
1440 </a>
1441
1442 <?php do_action( 'geodir_after_edit_post_link_on_listing', $review->post_id, $user, $post_type ); ?>
1443
1444 </span>
1445
1446 <?php } ?>
1447 </div>
1448 </li>
1449 <?php
1450 do_action( 'uwp_after_profile_reviews_item', $review->comment_id, $user, $post_type );
1451 }
1452 ?>
1453 </ul>
1454
1455 <?php
1456 /* Restore original Post Data */
1457 wp_reset_postdata();
1458
1459 do_action( 'uwp_after_profile_reviews_items', $user, $post_type );
1460
1461 do_action( 'uwp_profile_pagination', $maximum_pages );
1462 ?>
1463 </div>
1464 <?php
1465 }
1466 }
1467
1468 /**
1469 * Displays reviews in bootstrap layout
1470 *
1471 * @since 1.0.0
1472 * @package userswp
1473 *
1474 * @param object $user User object
1475 * @param string $post_type Post type
1476 *
1477 */
1478 public function get_bootstrap_reviews( $user, $post_type ) {
1479 global $userswp, $geodir_post_type;
1480 $geodir_post_type = $post_type;
1481 $args = array();
1482
1483 $args['template_args']['title'] = __( "Reviews", 'userswp' );
1484
1485 $userswp->profile->get_profile_comments( $user, $post_type, $args );
1486
1487 $geodir_post_type = '';
1488
1489 }
1490
1491 /**
1492 * Displays favourite listings
1493 *
1494 * @since 1.0.0
1495 * @package userswp
1496 *
1497 * @param object $user User object
1498 * @param string $post_type Post type
1499 *
1500 */
1501 public function gd_get_favorites( $user, $post_type ) {
1502 if ( uwp_get_option( "design_style", 'bootstrap' ) ) {
1503 self::get_bootstrap_favorites( $user, $post_type );
1504 } else {
1505 $gd_post_types = geodir_get_posttypes( 'array' );
1506
1507 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1508
1509 $user_fav_posts = geodir_get_user_favourites( $user->ID );
1510
1511 if ( ! $user_fav_posts ) {
1512 return;
1513 }
1514
1515 if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1516 $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1517 } else {
1518 $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1519 }
1520
1521 $args = array(
1522 'post_type' => $post_type,
1523 'post_status' => $post_status,
1524 'posts_per_page' => uwp_get_option( 'profile_no_of_items', 10 ),
1525 'post__in' => $user_fav_posts,
1526 'paged' => $paged,
1527 'uwp_geodir_query' => true
1528 );
1529
1530 $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
1531
1532 // The Query
1533 $the_query = new WP_Query( $args );
1534
1535 if ( isset( $the_query->found_posts ) && $the_query->found_posts == 0 ) {
1536 return;
1537 }
1538 ?>
1539 <h3><?php esc_html( geodir_post_type_name( $post_type , true ) ) ?></h3>
1540
1541 <div class="uwp-profile-item-block">
1542 <?php
1543 do_action( 'uwp_before_profile_favourite_items', $user, $post_type );
1544 // The Loop
1545 if ( $the_query->have_posts() ) {
1546 echo '<ul class="uwp-profile-item-ul">';
1547 while ( $the_query->have_posts() ) {
1548 $the_query->the_post();
1549 $post_id = get_the_ID();
1550 global $post;
1551 $post = geodir_get_post_info( $post_id );
1552 setup_postdata( $post );
1553 $post_avgratings = geodir_get_post_rating( $post->ID );
1554 $post_ratings = geodir_get_rating_stars( $post_avgratings, $post->ID );
1555 ob_start();
1556 if ( uwp_is_gdv2() ) {
1557 geodir_comments_number();
1558 } else {
1559 geodir_comments_number( (int) $post->rating_count );
1560 }
1561 $n_comments = ob_get_clean();
1562 do_action( 'uwp_before_profile_favourite_item', $post_id, $user, $post_type );
1563 ?>
1564 <li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-' . esc_attr( $post_type ); ?>">
1565 <a class="uwp-profile-item-img" href="<?php echo esc_url( get_the_permalink() ); ?>">
1566 <?php
1567 if ( has_post_thumbnail() ) {
1568 $thumb_url = get_the_post_thumbnail_url( get_the_ID(), array( 80, 80 ) );
1569 } else {
1570 $thumb_url = uwp_get_default_thumb_uri();
1571 }
1572 ?>
1573 <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo esc_url( $thumb_url ); ?>">
1574 </a>
1575
1576 <?php do_action( 'uwp_before_profile_favourite_title', $post_id, $user, $post_type ); ?>
1577 <h3 class="uwp-profile-item-title">
1578 <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a>
1579 </h3>
1580 <?php do_action( 'uwp_after_profile_favourite_title', $post_id, $user, $post_type ); ?>
1581
1582 <div class="uwp-time-ratings-wrap">
1583 <?php do_action( 'uwp_before_profile_favourite_ratings', $post_id, $user, $post_type ); ?>
1584 <time class="uwp-profile-item-time published"
1585 datetime="<?php echo esc_attr( get_the_time( 'c' ) ); ?>">
1586 <?php echo get_the_date(); ?>
1587 </time>
1588 <?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 ?>
1589 <?php
1590 if ( ! is_user_logged_in() ) {
1591 do_action( 'geodir_after_favorite_html', $post->ID, 'listing' );
1592 }
1593 ?>
1594 <?php do_action( 'uwp_after_profile_favourite_ratings', $post_id, $user, $post_type ); ?>
1595 </div>
1596
1597 <div class="uwp-profile-item-summary">
1598 <?php
1599 do_action( 'uwp_before_profile_favourite_summary', $post_id, $user, $post_type );
1600 $excerpt = strip_shortcodes( wp_trim_words( get_the_excerpt(), 15, '...' ) );
1601 echo $excerpt; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1602 do_action( 'uwp_after_profile_favourite_summary', $post_id, $user, $post_type );
1603 ?>
1604 </div>
1605
1606 <div class="uwp-item-actions">
1607 <?php
1608 if ( is_user_logged_in() ) {
1609 geodir_favourite_html( '', $post->ID );
1610 }
1611 if ( $post->post_author == get_current_user_id() ) {
1612 if ( uwp_is_gdv2() ) {
1613 $href = 'javascript:void(0);';
1614 $class = '';
1615 $editlink = geodir_edit_post_link( $post_id );
1616 $extra = 'onclick="uwp_gd_delete_post(' . $post_id . ');"';
1617 } else {
1618 $ajaxlink = geodir_get_ajax_url();
1619 $href = geodir_getlink( $ajaxlink, array(
1620 'geodir_ajax' => 'add_listing',
1621 'ajax_action' => 'delete',
1622 'pid' => $post->ID
1623 ), false );
1624 $class = 'geodir-delete';
1625 $addplacelink = get_permalink( geodir_add_listing_page_id() );
1626 $editlink = geodir_getlink( $addplacelink, array( 'pid' => $post->ID ), false );
1627 $extra = '';
1628 }
1629 ?>
1630
1631 <span class="geodir-authorlink clearfix">
1632
1633 <?php do_action( 'geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1634
1635 <a href="<?php echo esc_url( $editlink ); ?>" class="geodir-edit"
1636 title="<?php esc_attr_e( 'Edit Listing', 'userswp' ); ?>">
1637 <?php
1638 $geodir_listing_edit_icon = apply_filters( 'geodir_listing_edit_icon', 'fas fa-edit' );
1639 echo '<i class="' . esc_attr( $geodir_listing_edit_icon ) . '"></i>';
1640 ?>
1641 <?php esc_html_e( 'Edit', 'userswp' ); ?>
1642 </a>
1643 <a href="<?php echo $href; ?>" <?php echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1644 class="<?php echo esc_attr( $class ); ?>"
1645 title="<?php esc_attr_e( 'Delete Listing', 'userswp' ); ?>">
1646 <?php
1647 $geodir_listing_delete_icon = apply_filters( 'geodir_listing_delete_icon', 'fas fa-times' );
1648 echo '<i class="' . esc_attr( $geodir_listing_delete_icon ) . '"></i>';
1649 ?>
1650 <?php esc_html_e( 'Delete', 'userswp' ); ?>
1651 </a>
1652
1653 <?php do_action( 'geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type ); ?>
1654
1655 </span>
1656
1657 <?php } ?>
1658 </div>
1659 </li>
1660 <?php
1661 do_action( 'uwp_after_profile_favourite_item', $post_id, $user, $post_type );
1662 }
1663 echo '</ul>';
1664 /* Restore original Post Data */
1665 wp_reset_postdata();
1666 }
1667
1668 do_action( 'uwp_after_profile_favourite_items', $user, $post_type );
1669
1670 do_action( 'uwp_profile_pagination', $the_query->max_num_pages );
1671 ?>
1672 </div>
1673 <?php
1674 }
1675 }
1676
1677 /**
1678 * Displays favourite listings in bootstrap layout
1679 *
1680 * @since 1.0.0
1681 * @package userswp
1682 *
1683 * @param object $user User object
1684 * @param string $post_type Post type
1685 *
1686 */
1687 public function get_bootstrap_favorites( $user, $post_type ) {
1688
1689 $favorite_ids = geodir_get_user_favourites( $user->ID );
1690 if ( $favorite_ids ) {
1691
1692 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
1693
1694 if ( ! empty( $user ) && ! empty( $user->ID ) && (int) get_current_user_id() == (int) $user->ID ) {
1695 $post_status = geodir_get_post_stati( 'author-archive', array( 'post_type' => $post_type ) );
1696 } else {
1697 $post_status = geodir_get_post_stati( 'public', array( 'post_type' => $post_type ) );
1698 }
1699
1700 $args = array(
1701 'post_type' => $post_type,
1702 'post_status' => $post_status,
1703 'posts_per_page' => uwp_get_option( 'profile_no_of_items', 10 ),
1704 'paged' => $paged,
1705 'post__in' => $favorite_ids,
1706 'uwp_geodir_query' => true
1707 );
1708
1709 $args = apply_filters( 'uwp_listing_query_args', $args, $user, $post_type );
1710
1711 // The Query
1712 $the_query = new WP_Query( $args );
1713
1714 $args['template_args']['the_query'] = $the_query;
1715 $args['template_args']['title'] = geodir_post_type_name( $post_type , true );
1716
1717 uwp_get_template( "bootstrap/loop-posts.php", $args );
1718 }
1719 }
1720
1721 /**
1722 * Returns login URL for GD V1 login form
1723 *
1724 * @since 1.0.0
1725 * @package userswp
1726 *
1727 * @param string $url
1728 * @param array $args
1729 *
1730 * @return mixed
1731 */
1732 public function get_gd_login_url( $url, $args ) {
1733 if ( ! uwp_is_gdv2() ) {
1734 return $url;
1735 }
1736
1737 $register_page = uwp_get_page_id( 'register_page', false );
1738 $login_page = uwp_get_page_id( 'login_page', false );
1739 $forgot_page = uwp_get_page_id( 'forgot_page', false );
1740 $reset_page = uwp_get_page_id( 'reset_page', false );
1741
1742 if ( ! empty( $args ) ) {
1743 if ( isset( $args['signup'] ) && $args['signup'] ) {
1744 $page_id = $register_page;
1745 } elseif ( isset( $args['forgot'] ) && $args['forgot'] ) {
1746 $page_id = $forgot_page;
1747 } elseif ( isset( $args['reset'] ) && $args['reset'] ) {
1748 $page_id = $reset_page;
1749 } else {
1750 $page_id = $login_page;
1751 }
1752 } else {
1753 $page_id = $login_page;
1754 }
1755 if ( $page_id ) {
1756 $uwp_url = get_permalink( $page_id );
1757
1758 if ( strpos( $url, 'redirect_add_listing' ) !== false ) {
1759 $parsed = wp_parse_url( $url );
1760 parse_str( $parsed['query'], $query );
1761 $uwp_url = add_query_arg( array(
1762 'redirect_to' => $query['redirect_add_listing'],
1763 ), $uwp_url );
1764 }
1765
1766 if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
1767 $uwp_url = add_query_arg( array(
1768 'redirect_to' => $args['redirect_to'],
1769 ), $uwp_url );
1770 }
1771
1772 $url = $uwp_url;
1773 }
1774
1775 return $url;
1776 }
1777
1778 /**
1779 * GD author redirect
1780 *
1781 * @since 1.0.0
1782 * @package userswp
1783 *
1784 * @return mixed
1785 */
1786 public function geodir_uwp_author_redirect() {
1787 if ( ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1788 $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
1789
1790 if ( ! empty( $author ) && ! empty( $author->ID ) ) {
1791 $favourite = isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' ? true : false;
1792 $post_type = isset( $_REQUEST['stype'] ) ? esc_attr( $_REQUEST['stype'] ) : null;
1793
1794 $author_id = $author->ID;
1795 $author_link = uwp_build_profile_tab_url( $author_id );
1796 $gd_post_types = geodir_get_posttypes( 'array' );
1797
1798 if ( ! empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1799 if ( $favourite ) {
1800 $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1801
1802 if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1803 $author_link = uwp_build_profile_tab_url( $author_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] );
1804 } else {
1805 return; // Do not redirect to dashboard CPT favorites.
1806 }
1807 } else {
1808 $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
1809
1810 if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
1811 $author_link = uwp_build_profile_tab_url( $author_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] );
1812 } else {
1813 return; // Do not redirect to dashboard CPT listings.
1814 }
1815 }
1816 }
1817
1818 wp_redirect( $author_link );
1819 exit;
1820 }
1821 }
1822
1823 return;
1824 }
1825
1826 /**
1827 * Checks if listing author page
1828 *
1829 * @since 1.0.0
1830 * @package userswp
1831 *
1832 * @param string $value
1833 *
1834 * @return mixed
1835 */
1836 public function geodir_post_status_is_author_page( $value ) {
1837 return $value || $this->gd_is_listings_tab();
1838 }
1839
1840 /**
1841 * Check if listing tab
1842 *
1843 * @since 1.0.0
1844 * @package userswp
1845 *
1846 * @return bool
1847 */
1848 public function gd_is_listings_tab() {
1849 global $wp_query, $uwp_profile_tabs_array;
1850
1851 if ( is_page() && class_exists( 'UsersWP' ) && isset( $wp_query->query_vars['uwp_profile'] ) && ( $profile_page = uwp_get_page_id( 'profile_page', false ) ) ) {
1852 $active_tab = ! empty( $wp_query->query_vars['uwp_tab'] ) ? $wp_query->query_vars['uwp_tab'] : '';
1853
1854 if ( empty( $active_tab ) && ! empty( $uwp_profile_tabs_array ) && ! empty( $uwp_profile_tabs_array[0]->tab_key ) ) {
1855 $active_tab = $uwp_profile_tabs_array[0]->tab_key;
1856 }
1857
1858 if ( $active_tab == 'listings' || $active_tab == 'favorites' ) {
1859 return true;
1860 }
1861 }
1862
1863 return false;
1864 }
1865
1866 /**
1867 * Displays post status
1868 *
1869 * @since 1.0.0
1870 * @package userswp
1871 *
1872 * @return string|void
1873 */
1874 public function geodir_add_post_status_author_page() {
1875 global $wpdb, $post;
1876
1877 $html = '';
1878 if ( get_current_user_id() ) {
1879 if ( $this->gd_is_listings_tab() && ! empty( $post ) && isset( $post->post_author ) && $post->post_author == get_current_user_id() ) {
1880
1881 // 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.
1882 $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
1883 $status = "<strong>(";
1884 $status_icon = '<i class="fas fa-play"></i>';
1885 switch ( $real_status ) {
1886 case 'publish' :
1887 $status .= __( 'Published', 'userswp' );
1888 break;
1889 case 'pending' :
1890 $status .= __( 'Pending', 'userswp' );
1891 break;
1892 case 'gd-closed' :
1893 $status .= __( 'Closed', 'userswp' );
1894 break;
1895 case 'gd-expired' :
1896 $status .= __( 'Expired', 'userswp' );
1897 break;
1898 default :
1899 $status .= __( 'Not published', 'userswp' );
1900 break;
1901 }
1902 $status .= ")</strong>";
1903
1904 $html = '<span class="geodir-post-status">' . $status_icon . ' <span class="geodir-status-label">' . __( 'Status: ', 'userswp' ) . '</span>' . $status . '</span>';
1905 }
1906 }
1907
1908 if ( $html != '' ) {
1909 echo apply_filters( 'geodir_filter_status_text_on_author_page', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1910 }
1911 }
1912
1913 /**
1914 * Returns GD login form placeholder
1915 *
1916 * @since 1.0.0
1917 * @package userswp
1918 *
1919 * @return string
1920 */
1921 public function gd_login_wid_login_placeholder() {
1922 if ( ! uwp_is_gdv2() ) {
1923 return __( 'Username', 'userswp' );
1924 }
1925 }
1926
1927 /**
1928 * Returns GD login form name
1929 *
1930 * @since 1.0.0
1931 * @package userswp
1932 *
1933 * @return string
1934 */
1935 public function gd_login_wid_login_name() {
1936 if ( ! uwp_is_gdv2() ) {
1937 return "username";
1938 }
1939 }
1940
1941 /**
1942 * Returns GD login form password name
1943 *
1944 * @since 1.0.0
1945 * @package userswp
1946 *
1947 * @return string
1948 */
1949 public function gd_login_wid_login_pwd() {
1950 if ( ! uwp_is_gdv2() ) {
1951 return "uwp_login_password";
1952 }
1953 }
1954
1955 /**
1956 * Displays nonce field in GD login form
1957 *
1958 * @since 1.0.0
1959 * @package userswp
1960 *
1961 */
1962 public function gd_login_inject_nonce() {
1963 if ( ! uwp_is_gdv2() ) {
1964 ?>
1965 <input type="hidden" name="uwp_login_nonce" value="<?php echo esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ); ?>"/>
1966 <?php
1967 }
1968 }
1969
1970 /**
1971 * Check author page redirect
1972 *
1973 * @since 1.0.0
1974 * @package userswp
1975 *
1976 * @param bool $redirect
1977 *
1978 * @return bool
1979 *
1980 */
1981 public function check_redirect_author_page( $redirect = false ) {
1982 if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) {
1983 $author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
1984
1985 if ( ! empty( $author ) && ! empty( $author->ID ) ) {
1986 $favourite = isset( $_REQUEST['list'] ) && $_REQUEST['list'] == 'favourite' ? true : false;
1987 $post_type = isset( $_REQUEST['stype'] ) ? esc_attr( $_REQUEST['stype'] ) : null;
1988
1989 $author_id = $author->ID;
1990 $author_link = uwp_build_profile_tab_url( $author_id );
1991 $gd_post_types = geodir_get_posttypes( 'array' );
1992
1993 if ( ! empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) {
1994 if ( $favourite ) {
1995 $profile_favorites = uwp_get_option( 'gd_profile_favorites', array() );
1996
1997 if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) {
1998 // Redirect to dashboard CPT favorites.
1999 } else {
2000 $redirect = false; // Do not redirect to dashboard CPT favorites.
2001 }
2002 } else {
2003 $profile_listings = uwp_get_option( 'gd_profile_listings', array() );
2004
2005 if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) {
2006 // Redirect to dashboard CPT listings.
2007 } else {
2008 $redirect = false; // Do not redirect to dashboard CPT listings.
2009 }
2010 }
2011 }
2012 }
2013 }
2014
2015 return $redirect;
2016 }
2017
2018 /**
2019 * Check if skip author page
2020 *
2021 * @since 1.0.0
2022 * @package userswp
2023 *
2024 * @param bool $uwp_author
2025 *
2026 * @return bool
2027 *
2028 */
2029 public function skip_uwp_author_page( $uwp_author = true ) {
2030 if ( geodir_is_page( 'author' ) ) {
2031 $uwp_author = false;
2032 }
2033
2034 return $uwp_author;
2035 }
2036
2037 public function get_widget_post_author( $post_author, $instance, $id_base = '' ) {
2038 if ( isset( $id_base ) && 'gd_listings' == $id_base ) {
2039 if ( is_uwp_profile_page() && isset( $instance['post_author'] ) && 'current_author' == $instance['post_author'] ) {
2040 $user = uwp_get_user_by_author_slug();
2041 if ( $user && isset( $user->ID ) ) {
2042 $post_author = $user->ID;
2043 }
2044 }
2045 }
2046
2047 return $post_author;
2048 }
2049
2050 public function get_widget_favorites_by_user( $favorites_by_user, $instance, $id_base = '' ) {
2051 if ( isset( $id_base ) && 'gd_listings' == $id_base ) {
2052 if ( is_uwp_profile_page() && isset( $instance['favorites_by_user'] ) && 'current_author' == $instance['favorites_by_user'] ) {
2053 $user = uwp_get_user_by_author_slug();
2054 if ( $user && isset( $user->ID ) ) {
2055 $favorites_by_user = $user->ID;
2056 }
2057 }
2058 }
2059
2060 return $favorites_by_user;
2061 }
2062
2063 /**
2064 * Unset GD Post variable after posts loop.
2065 *
2066 * @since 1.2.3.12
2067 */
2068 public function unset_gd_post() {
2069 global $gd_post;
2070 $gd_post = NULL;
2071 }
2072
2073 public function posts_join( $join, $wp_query ) {
2074 global $wpdb;
2075
2076 if ( ! empty( $wp_query ) && ! empty( $wp_query->query_vars ) && ! empty( $wp_query->query_vars['uwp_geodir_query'] ) && ! empty( $wp_query->query_vars['post_type'] ) ) {
2077 $post_type = $wp_query->query_vars['post_type'];
2078
2079 if ( is_scalar( $post_type ) && geodir_is_gd_post_type( $post_type ) ) {
2080 $table = geodir_db_cpt_table( $post_type );
2081
2082 $join .= ( $join ? " " : "" ) . "INNER JOIN `" . $table . "` ON ( `" . $table . "`.`post_id` = `" . $wpdb->posts . "`.`ID` )";
2083 }
2084 }
2085
2086 return $join;
2087 }
2088
2089 public function get_usernumposts( $count, $userid, $post_type, $public_only ) {
2090 global $_uwp_user_post_counts;
2091
2092 if ( ! empty( $_uwp_user_post_counts ) && is_scalar( $post_type ) && geodir_is_gd_post_type( $post_type ) ) {
2093 $count = $this->get_listings_count( $post_type, $userid );
2094 }
2095
2096 return $count;
2097 }
2098 }
2099
2100 $userswp_geodirectory = UsersWP_GeoDirectory_Plugin::get_instance();