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