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

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