PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.38
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.38
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/class-profile.php +1707 -1623 1.0.221.2.38 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * Profile Template related functions
4 5 *
5 6 * This class defines all code necessary for Profile template.
@@ -7,1083 +8,1814 @@
7 8 * @since 1.0.0
8 9 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 10 */
10 11 class UsersWP_Profile {
11 -
12 - /**
13 - * Prints the profile page header section.
14 - *
15 - * @since 1.0.0
16 - * @package userswp
17 - * @param object $user The User ID.
18 - */
19 - public function get_profile_header($user) {
20 - $banner = uwp_get_usermeta($user->ID, 'uwp_account_banner_thumb', '');
21 - $avatar = uwp_get_usermeta($user->ID, 'uwp_account_avatar_thumb', '');
22 - add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
23 - $uploads = wp_upload_dir();
24 - remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
25 - $upload_url = $uploads['baseurl'];
26 - if (is_user_logged_in() && get_current_user_id() == $user->ID && is_uwp_profile_page()) {
27 - $trigger_class = "uwp-profile-modal-form-trigger";
28 - } else {
29 - $trigger_class = "";
30 - }
31 12
32 - if (empty($banner)) {
33 - $banner = uwp_get_option('profile_default_banner', '');
34 - if(empty($banner)){
35 - $banner = USERSWP_PLUGIN_URL."/public/assets/images/banner.png";
36 - } else {
37 - $banner = wp_get_attachment_url($banner);
38 - }
39 - } else {
40 - $banner = $upload_url.$banner;
41 - }
42 - if (empty($avatar)) {
43 - $avatar = get_avatar($user->user_email, 150);
44 - } else {
45 - // check the image is not a full url before adding the local upload url
46 - if (strpos($avatar, 'http:') === false && strpos($avatar, 'https:') === false) {
47 - $avatar = $upload_url.$avatar;
48 - }
49 - $avatar = '<img src="'.$avatar.'" class="avatar avatar-150 photo" width="150" height="150">';
50 - }
51 - ?>
52 - <div class="uwp-profile-header clearfix">
53 - <div class="uwp-profile-header-img clearfix">
54 - <?php
55 - if (!is_uwp_profile_page()) {
56 - echo '<a href="'.apply_filters('uwp_profile_link', get_author_posts_url($user->ID), $user->ID).'" title="'.$user->display_name.'">';
57 - }
58 - ?>
59 - <img src="<?php echo $banner; ?>" alt="" class="uwp-profile-header-img-src" data-recalc-dims="0" />
60 - <?php
61 - if (!is_uwp_profile_page()) {
62 - echo '</a>';
63 - }
64 - ?>
65 - <?php if (is_user_logged_in() && (get_current_user_id() == $user->ID) && is_uwp_profile_page()) { ?>
66 - <div class="uwp-banner-change-icon">
67 - <i class="fas fa-camera" aria-hidden="true"></i>
68 - <div data-type="banner" class="uwp-profile-banner-change <?php echo $trigger_class; ?>">
69 - <span class="uwp-profile-banner-change-inner">
70 - <?php echo __( 'Update Cover Photo', 'userswp' ); ?>
71 - </span>
72 - </div>
73 - </div>
74 - <?php } ?>
75 - </div>
76 - <div class="uwp-profile-avatar clearfix">
77 - <?php
78 - if (!is_uwp_profile_page()) {
79 - echo '<a href="'.apply_filters('uwp_profile_link', get_author_posts_url($user->ID), $user->ID).'" title="'.$user->display_name.'">';
80 - }
81 - ?>
82 - <div class="uwp-profile-avatar-inner">
83 - <?php echo $avatar; ?>
84 - <?php if (is_user_logged_in() && (get_current_user_id() == $user->ID) && is_uwp_profile_page()) { ?>
85 - <div class="uwp-profile-avatar-change">
86 - <div class="uwp-profile-avatar-change-inner">
87 - <i class="fas fa-camera" aria-hidden="true"></i>
88 - <a id="uwp-profile-picture-change" data-type="avatar" class="<?php echo $trigger_class; ?>" href="#"><?php echo __( 'Update', 'userswp' ); ?></a>
89 - </div>
90 - </div>
91 - <?php } ?>
92 - </div>
93 - <?php
94 - if (!is_uwp_profile_page()) {
95 - echo '</a>';
96 - }
97 - ?>
98 - </div>
99 - </div>
100 - <?php
101 - }
13 + public static function get_author_link( $link, $user_id ) {
102 14
103 - /**
104 - * Prints the profile page title section.
105 - *
106 - * @since 1.0.0
107 - * @package userswp
108 - * @param object $user The User ID.
109 - */
110 - public function get_profile_title($user) {
111 - ?>
15 + if ( 1 == uwp_get_option( 'uwp_disable_author_link' ) && ! ( is_uwp_profile_page() || is_uwp_users_page() ) ) {
16 + return $link;
17 + }
18 +
19 + return self::get_profile_link( $link, $user_id );
20 + }
21 +
22 + /**
23 + * Returns user profile link based on user id.
24 + *
25 + * @since 1.0.0
26 + * @package userswp
27 + *
28 + * @param string $link Unmodified link.
29 + * @param int $user_id User id.
30 + *
31 + * @return string Modified link.
32 + */
33 + public static function get_profile_link( $link, $user_id ) {
34 +
35 + $page_id = uwp_get_page_id( 'profile_page', false );
36 +
37 + if ( ! $page_id ) {
38 + return $link;
39 + }
40 +
41 + $link = get_permalink( $page_id );
42 +
43 + if ( $link != '' ) {
44 +
45 + if ( isset( $_REQUEST['page_id'] ) ) {
46 + $permalink_structure = 'DEFAULT';
47 + } else {
48 + $permalink_structure = 'CUSTOM';
49 + // Add forward slash if not available
50 + $link = trailingslashit( $link );
51 + }
52 +
53 + $url_type = apply_filters( 'uwp_profile_url_type', 'slug' );
54 +
55 + if ( $url_type && 'id' == $url_type ) {
56 + if ( 'DEFAULT' == $permalink_structure ) {
57 + return add_query_arg( array( 'viewuser' => $user_id ), $link );
58 + } else {
59 + return user_trailingslashit( $link . $user_id );
60 + }
61 + } else {
62 + $user = get_userdata( $user_id );
63 + if ( $user ) {
64 + if ( ! empty( $user->user_nicename ) ) {
65 + $username = $user->user_nicename;
66 + } else {
67 + $username = $user->user_login;
68 + }
69 + } else {
70 + $username = '';
71 + }
72 +
73 + if ( 'DEFAULT' == $permalink_structure ) {
74 + return add_query_arg( array( 'username' => $username ), $link );
75 + } else {
76 + return user_trailingslashit( $link . $username );
77 + }
78 + }
79 + } else {
80 + return $link;
81 + }
82 + }
83 +
84 + /**
85 + * Prints the profile page title section.
86 + *
87 + * @since 1.0.0
88 + * @package userswp
89 + *
90 + * @param object $user The User ID.
91 + * @param string $tag Tag
92 + * @param string $title_class Title Class
93 + * @param string $link_class Link Class
94 + * @param bool $link The User ID.
95 + */
96 + public function get_profile_title( $user, $tag = 'h2', $title_class = '', $link_class = '', $link = true ) {
97 + if ( ! $user ) {
98 + return;
99 + }
100 + ?>
112 101 <div class="uwp-profile-name">
113 - <h2 class="uwp-user-title" data-user="<?php echo $user->ID; ?>">
114 - <?php echo apply_filters('uwp_profile_display_name', $user->display_name); ?>
115 - <?php do_action('uwp_profile_after_title', $user->ID ); ?>
116 - </h2>
102 + <<?php echo esc_attr( $tag ); ?> class="uwp-user-title <?php echo esc_attr( $title_class ); ?>"
103 + data-user="<?php echo absint( $user->ID ); ?>">
104 + <?php if ( $link ){ ?><a href="<?php echo esc_url( uwp_build_profile_tab_url( $user->ID ) ); ?>"
105 + class="<?php echo esc_attr( $link_class ); ?>"><?php } ?>
106 + <?php echo esc_attr( apply_filters( 'uwp_profile_display_name', esc_attr( $user->display_name ), $user ) ); ?>
107 + <?php if ( $link ){ ?></a><?php } ?>
108 + <?php do_action( 'uwp_profile_after_title', $user->ID ); ?>
109 + </<?php echo esc_attr( $tag ); ?>>
117 110 </div>
118 - <?php
119 - }
111 + <?php
112 + }
120 113
121 - /**
122 - * Prints the profile page social links section.
123 - *
124 - * @since 1.0.0
125 - * @package userswp
126 - * @param object $user The User ID.
127 - */
128 - public function get_profile_social($user) {
114 + /**
115 + * Displays edit account button
116 + */
117 + public function edit_profile_button( $user_id ) {
118 + global $uwp_in_user_loop;
119 + $account_page = uwp_get_page_id( 'account_page', false );
120 + if ( $user_id ) {
121 + $user = get_userdata( $user_id );
122 + } else {
123 + $user = uwp_get_displayed_user();
124 + }
129 125
130 - global $wpdb;
131 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
132 - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE ( form_type = 'register' OR form_type = 'account' ) AND field_type = 'url' AND css_class LIKE '%uwp_social%' ORDER BY sort_order ASC");
126 + $can_user_edit_account = apply_filters( 'uwp_user_can_edit_own_profile', true, $user->ID );
133 127
134 - if (is_uwp_profile_page()) {
135 - $show_type = '[profile_side]';
136 - } elseif (is_uwp_users_page()) {
137 - $show_type = '[users]';
138 - } else {
139 - $show_type = false;
140 - }
128 + if ( ! $uwp_in_user_loop && $account_page && is_user_logged_in() && ( get_current_user_id() == $user->ID ) && $can_user_edit_account ) { ?>
129 + <a href="<?php echo esc_url( get_permalink( $account_page ) ); ?>"
130 + class="btn btn-sm btn-outline-dark btn-circle mt-n1" data-toggle="tooltip"
131 + title="<?php esc_attr_e( 'Edit Account', 'userswp' ); ?>"><i
132 + class="fas fa-pencil-alt fa-fw fa-lg"></i></a>
133 + <?php }
134 + }
141 135
142 - if (!$show_type) {
143 - return;
144 - }
145 - ?>
136 + /**
137 + * Prints the profile page social links section.
138 + *
139 + * @since 1.0.0
140 + * @package userswp
141 + *
142 + * @param object $user The User ID.
143 + * @param string , array $exclude Fields to exclude from displaying.
144 + */
145 + public function get_profile_social( $user, $exclude = '' ) {
146 +
147 + if ( is_uwp_profile_page() ) {
148 + $show_type = '[profile_side]';
149 + } elseif ( is_uwp_users_page() ) {
150 + $show_type = '[users]';
151 + } else {
152 + $show_type = false;
153 + }
154 +
155 + if ( ! $show_type ) {
156 + return;
157 + }
158 +
159 + global $wpdb;
160 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
161 + $form_id = uwp_get_register_form_id( $user->ID );
162 + $fields = $wpdb->get_results( $wpdb->prepare("SELECT * FROM " . $table_name . " WHERE ( form_type = 'register' OR form_type = 'account' ) AND field_type = 'url' AND css_class LIKE '%uwp_social%' AND form_id = %d ORDER BY sort_order ASC", $form_id ) );
163 +
164 + $usermeta = isset( $user->ID ) ? uwp_get_usermeta_row( $user->ID ) : array();
165 + $privacy = ! empty( $usermeta ) && ! empty( $usermeta->user_privacy ) ? explode( ',', $usermeta->user_privacy ) : array();
166 +
167 + if ( ! empty( $exclude ) && ! is_array( $exclude ) ) {
168 + $exclude = explode( ',', $exclude );
169 + $exclude = array_map( 'trim', $exclude );
170 + }
171 + ?>
146 172 <div class="uwp-profile-social">
147 173 <ul class="uwp-profile-social-ul">
148 - <?php
149 - foreach($fields as $field) {
150 - $show_in = explode(',',$field->show_in);
174 + <?php
175 + foreach ( $fields as $field ) {
176 + $show_in = explode( ',', $field->show_in );
151 177
152 - if (!in_array($show_type, $show_in)) {
153 - continue;
154 - }
155 - $key = $field->htmlvar_name;
156 - // see UsersWP_Forms -> uwp_save_user_extra_fields reason for replacing key
157 - $key = str_replace('uwp_register_', 'uwp_account_', $key);
158 - $value = uwp_get_usermeta($user->ID, $key, false);
178 + if ( ! in_array( $show_type, $show_in ) ) {
179 + continue;
180 + }
159 181
160 - if ($value) {
161 - echo '<li><a target="_blank" rel="nofollow" href="'.$value.'"><i class="'.$field->field_icon.'"></i></a></li>';
162 - }
163 - }
164 - ?>
182 + $display = false;
183 + if ( $field->is_public == '0' ) {
184 + $display = false;
185 + } else if ( $field->is_public == '1' ) {
186 + $display = true;
187 + } else {
188 + if ( ! in_array( $field->htmlvar_name . '_privacy', $privacy ) ) {
189 + $display = true;
190 + }
191 + }
192 + if ( ! $display ) {
193 + continue;
194 + }
195 +
196 + $key = $field->htmlvar_name;
197 + // see UsersWP_Forms -> save_user_extra_fields reason for replacing key
198 + $key = str_replace( 'uwp_register_', '', $key );
199 + $exclude_key = str_replace( 'uwp_account_', '', $key );
200 + $value = uwp_get_usermeta( $user->ID, $key, false );
201 + $icon = uwp_get_field_icon( $field->field_icon );
202 +
203 + if ( isset( $icon ) && ! empty( $icon ) ) {
204 + $title = $icon;
205 + } else {
206 + $title = $field->site_title;
207 + }
208 +
209 + if ( ! empty( $exclude ) && in_array( $exclude_key, $exclude ) ) {
210 + continue;
211 + }
212 +
213 + if ( $value ) {
214 + echo '<li><a target="_blank" rel="nofollow" href="' . esc_url( $value ) . '">' . esc_attr( $title ) . '</a></li>';
215 + }
216 + }
217 + ?>
165 218 </ul>
166 219 </div>
167 - <?php
168 - }
220 + <?php
221 + }
169 222
170 - /**
171 - * More info tab title.
172 - *
173 - * @since 1.0.0
174 - * @package userswp
175 - * @param object $user The User ID.
176 - * @return string Tab title.
177 - */
178 - public function get_profile_count_icon($user) {
179 - return '<i class="fas fa-user"></i>';
180 - }
223 + /**
224 + * Returns the custom fields content of profile page more info tab.
225 + *
226 + * @since 1.0.0
227 + * @package userswp
228 + *
229 + * @param object $user The User ID.
230 + * @param string $show_type Location of field to display.
231 + */
232 + public function show_output_location_data( $user, $show_type ) {
233 + if ( ! $show_type ) {
234 + return;
235 + }
236 + echo $this->get_extra_fields( $user, '[' . $show_type . ']' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
237 + }
181 238
182 - /**
183 - * Returns the custom fields content of profile page more info tab.
184 - *
185 - * @since 1.0.0
186 - * @package userswp
187 - * @param object $user The User ID.
188 - * @return string More info tab content.
189 - */
190 - public function get_profile_extra($user) {
191 - return $this->uwp_get_extra_fields($user, '[more_info]');
192 - }
239 + /**
240 + * Returns the custom fields content based on type.
241 + *
242 + * @since 1.0.0
243 + * @package userswp
244 + *
245 + * @param object $user The User ID.
246 + * @param string $show_type Filter type.
247 + *
248 + * @return string Custom fields content.
249 + */
250 + public function get_extra_fields( $user, $show_type ) {
193 251
194 - /**
195 - * Returns the custom fields content of profile page sidebar.
196 - *
197 - * @since 1.0.0
198 - * @package userswp
199 - * @param object $user The User ID.
200 - * @return string Sidebar custom fields content.
201 - */
202 - public function get_profile_side_extra($user) {
203 - echo $this->uwp_get_extra_fields($user, '[profile_side]');
204 - }
252 + ob_start();
253 + global $wpdb;
254 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
255 + $form_id = uwp_get_register_form_id( $user->ID );
256 + $fields = $wpdb->get_results( $wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND css_class NOT LIKE '%uwp_social%' AND form_id = %d ORDER BY sort_order ASC", $form_id ));
257 + $wrap_html = false;
258 + if ( $fields ) {
259 + $usermeta = isset( $user->ID ) ? uwp_get_usermeta_row( $user->ID ) : array();
260 + $privacy = ! empty( $usermeta ) && ! empty( $usermeta->user_privacy ) ? explode( ',', $usermeta->user_privacy ) : array();
205 261
206 - /**
207 - * Returns the custom fields content of users page.
208 - *
209 - * @since 1.0.0
210 - * @package userswp
211 - * @param object $user The User ID.
212 - * @return string Users page custom fields content.
213 - */
214 - public function get_users_extra($user) {
215 - echo $this->uwp_get_extra_fields($user, '[users]');
216 - }
262 + foreach ( $fields as $field ) {
263 + $show_in = explode( ',', $field->show_in );
264 + if ( ! in_array( $show_type, $show_in ) ) {
265 + continue;
266 + }
217 267
218 - /**
219 - * Returns the custom fields content based on type.
220 - *
221 - * @since 1.0.0
222 - * @package userswp
223 - * @param object $user The User ID.
224 - * @param string $show_type Filter type.
225 - * @return string Custom fields content.
226 - */
227 - public function uwp_get_extra_fields($user, $show_type) {
268 + $display = false;
269 + if ( $field->is_public == '0' ) {
270 + $display = false;
271 + } else if ( $field->is_public == '1' ) {
272 + $display = true;
273 + } else {
274 + if ( ! in_array( $field->htmlvar_name . '_privacy', $privacy ) ) {
275 + $display = true;
276 + }
277 + }
278 + if ( ! $display ) {
279 + continue;
280 + }
228 281
229 - ob_start();
230 - global $wpdb;
231 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
232 - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND css_class NOT LIKE '%uwp_social%' ORDER BY sort_order ASC");
233 - $wrap_html = false;
234 - if ($fields) {
235 - foreach ($fields as $field) {
236 - $show_in = explode(',',$field->show_in);
237 - if (!in_array($show_type, $show_in)) {
238 - continue;
239 - }
240 - if ($field->is_public == '0') {
241 - continue;
242 - }
282 + $value = $this->get_field_value( $field, $user );
283 + $class = isset( $field->css_class ) ? $field->css_class : '';
243 284
244 - if ($field->is_public == '2') {
245 - $field_name = $field->htmlvar_name.'_privacy';
246 - $val = uwp_get_usermeta($user->ID, 'user_privacy', false);
247 - $meta_value = explode(',', $val);
248 - if (in_array($field_name, $meta_value)) {
249 - continue;
250 - }
251 - }
285 + // Icon
286 + $icon = uwp_get_field_icon( $field->field_icon );
287 + $site_title = isset( $field->site_title ) ? __( wp_unslash($field->site_title), 'userswp' ) : '';
252 288
253 - $value = $this->uwp_get_field_value($field, $user);
254 -
255 - // Icon
256 - $icon = uwp_get_field_icon($field->field_icon);
257 -
258 - if ($field->field_type == 'fieldset') {
259 - $icon = '';
260 - ?>
261 - <div class="uwp-profile-extra-wrap" style="margin: 0; padding: 0">
262 - <div class="uwp-profile-extra-key uwp-profile-extra-full" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;"><?php echo $icon.$field->site_title; ?></h3></div>
289 + if ( $field->field_type == 'fieldset' ) {
290 + $icon = '';
291 + ?>
292 + <div class="uwp-profile-extra-wrap m-0 p-0">
293 + <div class="uwp-profile-extra-key uwp-profile-extra-full m-0 p-0"><h3
294 + style="margin: 10px 0;"><?php echo wp_kses($icon, array('i'=>array(), 'span'=> array() ) ) . esc_attr( $site_title ); ?></h3></div>
263 295 </div>
264 - <?php
265 - } else {
266 - if ($value) {
267 - $wrap_html = true;
268 - ?>
269 - <div class="uwp-profile-extra-wrap">
270 - <div class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?><span class="uwp-profile-extra-sep">:</span></div>
271 - <div class="uwp-profile-extra-value">
272 - <?php
273 - if ($field->htmlvar_name == 'uwp_account_bio') {
274 - $is_profile_page = is_uwp_profile_page();
275 - $value = get_user_meta($user->ID, 'description', true);
276 - $value = stripslashes($value);
277 - if ($value) {
278 - ?>
279 - <div class="uwp-profile-bio <?php if ($is_profile_page) { echo "uwp_more"; } ?>">
280 - <?php
281 - if ($is_profile_page) {
282 - echo $value;
283 - } else {
284 - echo wp_trim_words( $value, 20, '...' );
285 - }
286 - ?>
296 + <?php
297 + } else {
298 + if ( $value ) {
299 + $wrap_html = true;
300 + ?>
301 + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $class ); ?>">
302 + <div class="uwp-profile-extra-key d-inline-block"><?php echo wp_kses($icon, array('i'=>array(), 'span'=> array() ) ) . " " . esc_attr( $site_title ); ?>
303 + <span class="uwp-profile-extra-sep">:</span></div>
304 + <div class="uwp-profile-extra-value d-inline-block">
305 + <?php
306 + if ( $field->htmlvar_name == 'bio' ) {
307 + $show_read_more = apply_filters( 'uwp_profile_bio_show_read_more', false );
308 + $value = get_user_meta( $user->ID, 'description', true );
309 + $value = stripslashes( $value );
310 + $limit_words = apply_filters( 'uwp_profile_bio_content_limit', 50 );
311 + if ( $value ) {
312 + ?>
313 + <div class="uwp-profile-bio <?php if ( $show_read_more ) {
314 + echo "uwp_more";
315 + } ?>">
316 + <?php
317 + if ( is_uwp_profile_page() ) {
318 + echo nl2br( esc_attr( $value ) );
319 + } else {
320 + echo esc_attr( wp_trim_words( $value, $limit_words, '...' ) );
321 + }
322 + ?>
287 323 </div>
288 - <?php
289 - }
290 - } else {
291 - echo $value;
292 - }
293 - ?>
324 + <?php
325 + }
326 + } else {
327 + echo wp_kses_post( $value );
328 + }
329 + ?>
294 330 </div>
295 331 </div>
296 - <?php
297 - }
298 - }
299 - }
300 - }
301 - $output = ob_get_contents();
302 - $wrapped_output = '';
303 - if ($wrap_html) {
304 - $wrapped_output .= '<div class="uwp-profile-extra"><div class="uwp-profile-extra-div form-table">';
305 - $wrapped_output .= $output;
306 - $wrapped_output .= '</div></div>';
307 - }
308 - ob_end_clean();
309 - return trim($wrapped_output);
310 - }
332 + <?php
333 + }
334 + }
335 + }
336 + }
337 + $output = ob_get_contents();
338 + $wrapped_output = '';
339 + if ( $wrap_html ) {
340 + $wrapped_output .= '<div class="uwp-profile-extra"><div class="uwp-profile-extra-div form-table">';
341 + $wrapped_output .= $output;
342 + $wrapped_output .= '</div></div>';
343 + }
344 + ob_end_clean();
311 345
312 - /**
313 - * Returns enabled profile tabs
314 - *
315 - * @since 1.0.0
316 - * @package userswp
317 - * @param object $user The User ID.
318 - * @return array Profile tabs
319 - */
320 - public function get_profile_tabs($user) {
346 + return trim( $wrapped_output );
347 + }
321 348
322 - $tabs = array();
349 + /**
350 + * Gets custom field value based on key.
351 + *
352 + * @since 1.0.0
353 + * @package userswp
354 + *
355 + * @param object $field Field info object.
356 + * @param object $user The User.
357 + *
358 + * @return string Custom field value.
359 + */
360 + public function get_field_value( $field, $user ) {
323 361
324 - // allowed tabs
325 - $allowed_tabs = uwp_get_option('enable_profile_tabs', array());
362 + $user_data = get_userdata( $user->ID );
326 363
327 - if (!is_array($allowed_tabs)) {
328 - $allowed_tabs = array();
329 - }
364 + if ( $field->htmlvar_name == 'email' ) {
365 + $value = $user_data->user_email;
366 + } elseif ( $field->htmlvar_name == 'password' ) {
367 + $value = '';
368 + $field->is_required = 0;
369 + } elseif ( $field->htmlvar_name == 'confirm_password' ) {
370 + $value = '';
371 + $field->is_required = 0;
372 + } else {
373 + $value = uwp_get_usermeta( $user->ID, $field->htmlvar_name, "" );
374 + }
330 375
331 - $extra = $this->get_profile_extra($user);
332 - if (in_array('more_info', $allowed_tabs) && $extra) {
333 - $tabs['more_info'] = array(
334 - 'title' => __( 'More Info', 'userswp' ),
335 - 'count' => $this->get_profile_count_icon($user)
336 - );
337 - }
376 + // Select and Multiselect needs Value to be converted
377 + if ( $field->field_type == 'select' || $field->field_type == 'multiselect' ) {
378 + $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
338 379
339 - if (in_array('posts', $allowed_tabs)) {
340 - $tabs['posts'] = array(
341 - 'title' => __( 'Posts', 'userswp' ),
342 - 'count' => uwp_post_count($user->ID, 'post')
343 - );
344 - }
380 + // Select
381 + if ( $field->field_type == 'select' ) {
345 382
346 - if (in_array('comments', $allowed_tabs)) {
347 - $tabs['comments'] = array(
348 - 'title' => __( 'Comments', 'userswp' ),
349 - 'count' => uwp_comment_count($user->ID)
350 - );
351 - }
383 + if ( $field->field_type_key != 'country' && $field->field_type_key != 'uwp_country' ) {
384 + if ( ! empty( $value ) ) {
385 + $data = $this->uwp_array_search( $option_values_arr, 'value', $value );
386 + $value = !empty( $data[0]['label'] ) ? $data[0]['label'] : '';
387 + } else {
388 + $value = '';
389 + }
390 + }
391 + }
352 392
353 - $all_tabs = apply_filters( 'uwp_profile_tabs', $tabs, $user, $allowed_tabs );
393 + //Multiselect
394 + if ( $field->field_type == 'multiselect' && ! empty( $value ) ) {
395 + if ( ! empty( $value ) && is_array( $value ) ) {
396 + $array_value = array();
397 + foreach ( $value as $v ) {
398 + if ( ! empty( $v ) ) {
399 + $data = $this->uwp_array_search( $option_values_arr, 'value', $v );
400 + $array_value[] = $data[0]['label'];
401 + }
354 402
355 - // order tabs as per option values
356 - if(!empty($allowed_tabs)){
357 - $allowed_tabs = array_reverse($allowed_tabs);
358 - foreach($allowed_tabs as $key => $val){
359 - if(isset($all_tabs[$val])){
360 - $all_tabs = array($val => $all_tabs[$val]) + $all_tabs;
361 - }
403 + }
404 + if ( ! empty( $array_value ) ) {
405 + $value = implode( ', ', $array_value );
406 + } else {
407 + $value = '';
408 + }
362 409
363 - }
364 - }
410 + } else {
411 + $value = '';
412 + }
413 + }
414 + }
365 415
366 - return $all_tabs;
367 - }
416 + // Date
417 + if ( $field->field_type == 'datepicker' ) {
418 + $date_format = get_option( 'date_format' );
368 419
369 - /**
370 - * Prints the profile tab content template
371 - *
372 - * @since 1.0.0
373 - * @package userswp
374 - * @param object $user The User ID.
375 - * @return void
376 - */
377 - public function get_profile_tabs_content($user) {
420 + if ( isset( $field->extra_fields ) && ! empty( $field->extra_fields ) ) {
421 + $extra_fields = unserialize( $field->extra_fields );
422 + if ( isset( $extra_fields['date_format'] ) && ! empty( $extra_fields['date_format'] ) ) {
423 + $date_format = $extra_fields['date_format'];
424 + }
425 + }
378 426
379 - $tab = get_query_var('uwp_tab');
427 + if ( ! empty( $value ) ) {
428 + $value = date( $date_format, $value );
429 + } else {
430 + $value = '';
431 + }
380 432
381 - $account_page = uwp_get_page_id('account_page', false);
433 + }
382 434
383 - $all_tabs = $this->get_profile_tabs($user);
435 + // Time
436 + if ( $field->field_type == 'time' ) {
437 + if ( ! empty( $value ) ) {
438 + $value = date( get_option( 'time_format' ), strtotime( $value ) );
439 + } else {
440 + $value = '';
441 + }
442 + }
384 443
385 - $tab_keys = array_keys($all_tabs);
444 + // URL
445 + if ( $field->field_type == 'url' && ! empty( $value ) ) {
446 + $link_text = $value;
447 + // if default_value is not url then it will be used as link text.
448 + if ( $field->default_value && ! empty( $field->default_value ) ) {
449 + if ( substr( $field->default_value, 0, 4 ) === "http" ) {
450 + $link_text = $value;
451 + } else {
452 + $link_text = $field->default_value;
453 + }
454 + }
455 + if ( substr( $link_text, 0, 4 ) === "http" ) {
456 + $link_text = esc_url( $link_text );
457 + }
386 458
387 - if (!empty($tab_keys)) {
388 - $default_key = $tab_keys[0];
389 - } else {
390 - $default_key = false;
391 - }
459 + $value = '<a href="' . esc_url( $value ) . '" target="_blank" rel="nofollow">' . esc_attr( $link_text ) . '</a>';
460 + }
392 461
393 - $active_tab = !empty( $tab ) && array_key_exists( $tab, $all_tabs ) ? $tab : $default_key;
394 - if (!$active_tab) {
395 - return;
396 - }
397 - ?>
398 - <div class="uwp-profile-content">
399 - <div class="uwp-profile-nav">
400 - <ul class="item-list-tabs-ul">
401 - <?php
402 - foreach( $this->get_profile_tabs($user) as $tab_id => $tab ) {
462 + // Checkbox
463 + if ( $field->field_type == 'checkbox' ) {
464 + if ( $value == '1' ) {
465 + $value = __( 'Yes', 'userswp' );
466 + } else {
467 + $value = __( 'No', 'userswp' );
468 + }
469 + }
403 470
404 - $tab_url = uwp_build_profile_tab_url($user->ID, $tab_id, false);
471 + // File
472 + if ( $field->field_type == 'file' ) {
473 + $file_obj = new UsersWP_Files();
474 + $value = $file_obj->file_upload_preview( $field, $value, false );
475 + }
405 476
406 - $active = $active_tab == $tab_id ? ' active' : '';
407 - ?>
408 - <li id="uwp-profile-<?php echo $tab_id; ?>" class="<?php echo $active; ?>">
409 - <a href="<?php echo esc_url( $tab_url ); ?>">
410 - <span class="uwp-profile-tab-label uwp-profile-<?php echo $tab_id; ?>-label "><?php echo esc_html( $tab['title'] ); ?></span>
411 - <span class="uwp-profile-tab-count uwp-profile-<?php echo $tab_id; ?>-count"><?php echo $tab['count']; ?></span>
412 - </a>
413 - </li>
414 - <?php
415 - }
416 - ?>
417 - </ul>
418 - <?php
419 - $can_user_edit_account = apply_filters('uwp_user_can_edit_own_profile', true, $user->ID);
420 - ?>
421 - <?php if ($account_page && is_user_logged_in() && (get_current_user_id() == $user->ID) && $can_user_edit_account) { ?>
422 - <div class="uwp-edit-account">
423 - <a href="<?php echo get_permalink( $account_page ); ?>" title="<?php echo __( 'Edit Account', 'userswp' ); ?>"><i class="fas fa-cog"></i></a>
424 - </div>
425 - <?php } ?>
426 - </div>
477 + // Sanitize
478 + switch ( $field->field_type ) {
479 + case 'url':
480 + // already escaped
481 + break;
482 + case 'file':
483 + // already escaped
484 + break;
485 + case 'textarea':
486 + $value = esc_textarea( $value );
487 + $value = nl2br( $value );
488 + break;
489 + case 'editor':
490 + $value = wp_kses_post( $value );
491 + $value = nl2br( $value );
492 + break;
493 + default:
494 + $value = esc_html( $value );
495 + }
427 496
428 - <div class="uwp-profile-entries">
429 - <?php
430 - do_action('uwp_profile_tab_content', $user, $active_tab);
431 - do_action('uwp_profile_'.$active_tab.'_tab_content', $user);
432 - ?>
433 - </div>
434 - </div>
435 - <?php }
497 + if ( isset( $field->field_type_key ) && $field->field_type_key == 'country' || $field->field_type_key == 'uwp_country' ) {
498 + $value = uwp_output_country_html( $value );
499 + }
436 500
437 - /**
438 - * Prints the tab content pagination section.
439 - *
440 - * @since 1.0.0
441 - * @package userswp
442 - * @param int $total Total items.
443 - * @return void
444 - */
445 - public function get_profile_pagination($total) {
446 - ?>
501 + return apply_filters('uwp_get_field_value', $value, $field, $user);
502 + }
503 +
504 + /**
505 + * Array search by value
506 + *
507 + * @since 1.0.0
508 + * @package userswp
509 + *
510 + * @param array $array Original array.
511 + * @param mixed $key Array key
512 + * @param mixed $value Array value.
513 + *
514 + * @return array Result array.
515 + */
516 + public function uwp_array_search( $array, $key, $value ) {
517 + $results = array();
518 +
519 + if ( is_array( $array ) ) {
520 + if ( isset( $array[ $key ] ) && $array[ $key ] == $value ) {
521 + $results[] = $array;
522 + }
523 +
524 + foreach ( $array as $subarray ) {
525 + $results = array_merge( $results, $this->uwp_array_search( $subarray, $key, $value ) );
526 + }
527 + }
528 +
529 + return $results;
530 + }
531 +
532 + /**
533 + * Returns the custom fields content of profile page sidebar.
534 + *
535 + * @since 1.0.0
536 + * @package userswp
537 + *
538 + * @param object $user The User ID.
539 + */
540 + public function get_profile_side_extra( $user ) {
541 + echo $this->get_extra_fields( $user, '[profile_side]' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
542 + }
543 +
544 + /**
545 + * Returns the custom fields content of users page.
546 + *
547 + * @since 1.0.0
548 + * @package userswp
549 + *
550 + * @param object $user The User ID.
551 + */
552 + public function get_users_extra( $user ) {
553 + echo $this->get_extra_fields( $user, '[users]' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
554 + }
555 +
556 + /**
557 + *
558 + * Returns profile page tabs
559 + *
560 + * @return array
561 + */
562 + public function get_tabs() {
563 +
564 + // get the settings
565 + global $uwp_profile_tabs_array;
566 + // check if we have been here before
567 + $tabs = ! empty( $uwp_profile_tabs_array ) ? $uwp_profile_tabs_array : $this->get_tab_settings();
568 +
569 + $tabs_array = array();
570 +
571 + if ( ! empty( $tabs ) ) {
572 + // get the tab contents first so we can decide to output the tab head
573 + $tabs_content = array();
574 + foreach ( $tabs as $tab ) {
575 + $tabs_content[ $tab->id . "tab" ] = $this->tab_content( $tab );
576 + }
577 +
578 + // setup the array
579 + foreach ( $tabs as $tab ) {
580 + if ( isset( $tab->tab_level ) && $tab->tab_level > 0 ) {
581 + continue;
582 + }
583 +
584 + $hide_empty = apply_filters('uwp_hide_empty_tabs', true, $tab, $tabs);
585 +
586 + if ( $hide_empty && empty( $tabs_content[ $tab->id . "tab" ] ) ) {
587 + continue;
588 + }
589 +
590 + $tab->tab_content_rendered = $tabs_content[ $tab->id . "tab" ];
591 + $tabs_array[] = (array) $tab;
592 + }
593 +
594 + }
595 +
596 + /**
597 + * Get the tabs output settings.
598 + *
599 + * @param array $tabs_array The array of tabs.
600 + */
601 + return apply_filters( 'uwp_get_profile_tabs', $tabs_array );
602 +
603 + }
604 +
605 + /**
606 + *
607 + * Returns profile tabs
608 + *
609 + * @return array $tabs Profile tabs
610 + */
611 + public function get_tab_settings() {
612 + global $wpdb, $uwp_profile_tabs_array;
613 +
614 + if ( $uwp_profile_tabs_array ) {
615 + $tabs = $uwp_profile_tabs_array;
616 + } else {
617 + $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
618 + $uwp_profile_tabs_array = array();
619 + $displayed_user = uwp_get_user_by_author_slug();
620 +
621 + if ( $displayed_user ) {
622 + $tabs_privacy = uwp_get_tabs_privacy_by_user( $displayed_user );
623 + }
624 +
625 + $form_id = uwp_get_register_form_id( $displayed_user->ID );
626 + $tabs_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $tabs_table_name . " WHERE form_type = %s and form_id = %s ORDER BY sort_order ASC", 'profile-tabs', $form_id ) );
627 + foreach ( $tabs_result as $tab ) {
628 + if ( isset( $tab->user_decided ) && 1 == $tab->user_decided && ! empty( $tabs_privacy ) ) {
629 +
630 + $field_name = $tab->tab_key . '_tab_privacy';
631 + $public_fields_keys = is_array( $tabs_privacy ) ? array_keys( $tabs_privacy ) : $tabs_privacy;
632 + if ( in_array( $field_name, $public_fields_keys ) ) {
633 + if ( 1 == $tabs_privacy[ $field_name ] && is_user_logged_in() ) { // 1 for logged in users
634 + $uwp_profile_tabs_array[] = $tab;
635 + } elseif ( 2 == $tabs_privacy[ $field_name ] && isset( $displayed_user->ID ) && ( $displayed_user->ID == get_current_user_id() || current_user_can( 'administrator' ) ) ) { // 2 for author and admin only
636 + $uwp_profile_tabs_array[] = $tab;
637 + } elseif ( 0 == $tabs_privacy[ $field_name ] ) { // for all users
638 + $uwp_profile_tabs_array[] = $tab;
639 + } else {
640 + // Skip tab
641 + }
642 + }
643 +
644 + } elseif ( isset( $tab->tab_privacy ) ) {
645 +
646 + if ( 1 == $tab->tab_privacy && is_user_logged_in() ) { // 1 for logged in users
647 + $uwp_profile_tabs_array[] = $tab;
648 + } elseif ( 2 == $tab->tab_privacy && isset( $displayed_user->ID ) && ( $displayed_user->ID == get_current_user_id() || current_user_can( 'administrator' ) ) ) { // 2 for author and admin only
649 + $uwp_profile_tabs_array[] = $tab;
650 + } elseif ( 0 == $tab->tab_privacy ) { // for all users
651 + $uwp_profile_tabs_array[] = $tab;
652 + } else {
653 + // Skip tab
654 + }
655 +
656 + } else {
657 + // Skip tab
658 + }
659 + }
660 +
661 + $tabs = $uwp_profile_tabs_array;
662 + }
663 +
664 + /**
665 + * Get the tabs output settings.
666 + *
667 + * @param array $tabs The array of stdClass settings for the tabs output.
668 + */
669 + return apply_filters( 'uwp_profile_tab_settings', $tabs );
670 + }
671 +
672 + /**
673 + * Returns profile tab content
674 + *
675 + * @since 2.0.0
676 + *
677 + * @param array $tab Tab array
678 + *
679 + * @return string
680 + */
681 + public function tab_content( $tab ) {
682 +
683 + ob_start();
684 + // main content
685 + if ( ! empty( $tab->tab_content ) ) { // override content
686 + $content = stripslashes( $tab->tab_content );
687 + echo do_shortcode( $content );
688 + } elseif ( $tab->tab_type == 'standard' ) {
689 + $user = uwp_get_displayed_user();
690 + do_action( 'uwp_profile_tab_content', $user, $tab );
691 + do_action( 'uwp_profile_' . $tab->tab_key . '_tab_content', $user, $tab );
692 + }
693 +
694 + // child elements
695 + echo self::tab_content_child( $tab ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
696 +
697 + return ob_get_clean();
698 + }
699 +
700 + /**
701 + * Returns profile child tab content
702 + *
703 + * @since 2.0.0
704 + *
705 + * @param array $tab Child tab array
706 + *
707 + * @return string
708 + */
709 + public function tab_content_child( $tab ) {
710 + ob_start();
711 + $tabs = self::get_tab_settings();
712 + $parent_id = $tab->id;
713 +
714 + foreach ( $tabs as $child_tab ) {
715 + if ( isset( $child_tab->tab_parent ) && $child_tab->tab_parent == $parent_id ) {
716 + if ( ! empty( $child_tab->tab_content ) ) { // override content
717 + echo do_shortcode( stripslashes( $child_tab->tab_content ) );
718 + } elseif ( $child_tab->tab_type == 'fieldset' ) {
719 + self::output_fieldset( $child_tab );
720 + } elseif ( $child_tab->tab_type == 'standard' ) {
721 + $user = uwp_get_displayed_user();
722 + do_action( 'uwp_profile_tab_content', $user, $child_tab );
723 + do_action( 'uwp_profile_' . $child_tab->tab_key . '_tab_content', $user, $child_tab );
724 + if ( $child_tab->tab_key == 'reviews' ) {
725 + comments_template();
726 + }
727 + }
728 + }
729 + }
730 +
731 + return ob_get_clean();
732 +
733 + }
734 +
735 + /**
736 + *
737 + * Displays fieldset content
738 + *
739 + * @param array $tab Tab array
740 + *
741 + * @return string
742 + */
743 + public function output_fieldset( $tab ) {
744 + ob_start();
745 + echo '<div class="uwp_post_meta uwp-fieldset">';
746 + echo "<h4>";
747 + if ( $tab->tab_icon ) {
748 + echo '<i class="fas ' . esc_attr( $tab->tab_icon ) . '" aria-hidden="true"></i>';
749 + }
750 + if ( $tab->tab_name ) {
751 + esc_attr_e( $tab->tab_name, 'userswp' );
752 + }
753 + echo "</h4>";
754 + echo "</div>";
755 +
756 + return ob_get_clean();
757 + }
758 +
759 + /**
760 + * Prints the tab content pagination section.
761 + *
762 + * @since 1.0.0
763 + * @package userswp
764 + *
765 + * @param int $total Total items.
766 + *
767 + * @return void
768 + */
769 + public function get_profile_pagination( $total ) {
770 + ?>
447 771 <div class="uwp-pagination">
448 - <?php
449 - $big = 999999999; // need an unlikely integer
450 - $translated = __( 'Page', 'userswp' ); // Supply translatable string
772 + <?php
773 + $design_style = uwp_get_option( "design_style", 'bootstrap' );
774 + if ( $design_style == 'bootstrap' ) {
775 + self::get_bootstrap_pagination( $total );
776 + } else {
777 + $big = 999999999; // need an unlikely integer
778 + $translated = __( 'Page', 'userswp' ); // Supply translatable string
451 779
452 - echo paginate_links( array(
453 - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
454 - 'format' => '?paged=%#%',
455 - 'current' => max( 1, get_query_var('paged') ),
456 - 'total' => $total,
457 - 'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>',
458 - 'type' => 'list'
459 - ) );
460 - ?>
780 + $args = array(
781 + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
782 + 'format' => '?paged=%#%',
783 + 'current' => max( 1, get_query_var( 'paged' ) ),
784 + 'total' => $total,
785 + 'before_page_number' => '<span class="screen-reader-text">' . $translated . ' </span>',
786 + 'type' => 'list'
787 + );
788 +
789 + echo paginate_links( $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
790 + }
791 +
792 +
793 + ?>
461 794 </div>
462 - <?php
463 - }
795 + <?php
796 + }
464 797
465 - /**
466 - * Prints the profile page more info tab content.
467 - *
468 - * @since 1.0.0
469 - * @package userswp
470 - * @param object $user The User ID.
471 - * @return void
472 - */
473 - public function get_profile_more_info($user) {
474 - $allowed_tabs = uwp_get_option('enable_profile_tabs', array());
798 + /**
799 + * Displays boostrap pagination
800 + *
801 + * @since 2.0.0
802 + *
803 + * @param int $total Total count
804 + */
805 + public function get_bootstrap_pagination( $total ) {
475 806
476 - if (!is_array($allowed_tabs)) {
477 - $allowed_tabs = array();
478 - }
479 - if (!in_array('more_info', $allowed_tabs)) {
480 - return;
481 - }
482 -
483 - $extra = $this->get_profile_extra($user);
484 - echo $extra;
485 - }
807 + $navigation = '';
808 + $args = array(
809 + 'mid_size' => 2,
810 + 'type' => 'array',
811 + 'prev_text' => sprintf(
812 + '%s <span class="nav-prev-text sr-only">%s</span>',
813 + '<i class="fas fa-chevron-left"></i>',
814 + __( 'Newer posts', 'ayetheme' )
815 + ),
816 + 'next_text' => sprintf(
817 + '<span class="nav-next-text sr-only">%s</span> %s',
818 + __( 'Older posts', 'ayetheme' ),
819 + '<i class="fas fa-chevron-right"></i>'
820 + ),
821 + );
486 822
487 - /**
488 - * Prints the profile page "posts" tab content.
489 - *
490 - * @since 1.0.0
491 - * @package userswp
492 - * @param object $user The User ID.
493 - * @return void
494 - */
495 - public function get_profile_posts($user) {
496 -
497 - $allowed_tabs = uwp_get_option('enable_profile_tabs', array());
823 + // Don't print empty markup if there's only one page.
824 + if ( $total > 1 ) {
825 + $args = wp_parse_args( $args, array(
826 + 'mid_size' => 1,
827 + 'prev_text' => _x( 'Previous', 'previous set of posts' ),
828 + 'next_text' => _x( 'Next', 'next set of posts' ),
829 + 'screen_reader_text' => __( 'Posts navigation' ),
830 + 'total' => $total,
831 + ) );
498 832
499 - if (!is_array($allowed_tabs)) {
500 - $allowed_tabs = array();
501 - }
502 - if (!in_array('posts', $allowed_tabs)) {
503 - return;
504 - }
833 + if ( is_front_page() ) {
834 + $args['current'] = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1;
835 + }
505 836
506 - uwp_generic_tab_content($user, 'post', __('Posts', 'userswp'));
507 - }
837 + // Set up paginated links.
838 + $links = paginate_links( $args );
508 839
509 - /**
510 - * Prints the profile page "comments" tab content.
511 - *
512 - * @since 1.0.0
513 - * @package userswp
514 - * @param object $user The User ID.
515 - * @return void
516 - */
517 - public function get_profile_comments($user) {
518 - $allowed_tabs = uwp_get_option('enable_profile_tabs', array());
840 + // make the output bootstrap ready
841 + $links_html = "<ul class='pagination m-0 p-0'>";
842 + if ( ! empty( $links ) ) {
843 + foreach ( $links as $link ) {
844 + $active = strpos( $link, 'current' ) !== false ? 'active' : '';
845 + $links_html .= "<li class='page-item $active'>";
846 + $links_html .= str_replace( "page-numbers", "page-link", $link );
847 + $links_html .= "</li>";
848 + }
849 + }
850 + $links_html .= "</ul>";
519 851
520 - if (!is_array($allowed_tabs)) {
521 - $allowed_tabs = array();
522 - }
523 - if (!in_array('comments', $allowed_tabs)) {
524 - return;
525 - }
526 - ?>
527 - <h3><?php echo __('Comments', 'userswp') ?></h3>
852 + if ( $links ) {
853 + $navigation .= '<section class="px-0 py-2 w-100">';
854 + $navigation .= _navigation_markup( $links_html, 'pagination', $args['screen_reader_text'] );
855 + $navigation .= '</section>';
856 + }
528 857
529 - <div class="uwp-profile-item-block">
530 - <?php
531 - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
532 - $number = uwp_get_option('profile_no_of_items', 10);
533 - $offset = ( $paged - 1 ) * $number;
858 + $navigation = str_replace( "nav-links", "uwp-nav-links", $navigation );
859 + }
534 860
535 - $total_comments = uwp_comment_count($user->ID);
536 - $maximum_pages = ceil($total_comments / $number);
861 + echo $navigation; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
537 862
538 - $args = array(
539 - 'number' => $number,
540 - 'offset' => $offset,
541 - 'author_email' => $user->user_email,
542 - 'paged' => $paged,
543 - 'post_type' => 'post',
544 - );
545 - // The Query
546 - $the_query = new WP_Comment_Query();
547 - $comments = $the_query->query( $args );
863 + }
548 864
549 - // The Loop
550 - if ($comments) {
551 - echo '<ul class="uwp-profile-item-ul">';
552 - foreach ( $comments as $comment ) {
553 - ?>
554 - <li class="uwp-profile-item-li uwp-profile-item-clearfix">
555 - <a class="uwp-profile-item-img" href="<?php echo get_comment_link($comment->comment_ID); ?>">
556 - <?php
557 - if ( has_post_thumbnail($comment->comment_post_ID) ) {
558 - $thumb_url = get_the_post_thumbnail_url($comment->comment_post_ID, array(80, 80));
559 - } else {
560 - $thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png";
561 - }
562 - ?>
563 - <img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>">
564 - </a>
865 + /**
866 + * Prints the profile page more info tab content.
867 + *
868 + * @since 1.0.0
869 + * @package userswp
870 + *
871 + * @param object $user The User ID.
872 + *
873 + * @return void
874 + */
875 + public function get_profile_more_info( $user ) {
876 + $extra = $this->get_profile_extra( $user );
877 + echo $extra; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
878 + }
565 879
566 - <h3 class="uwp-profile-item-title">
567 - <a href="<?php echo get_comment_link($comment->comment_ID); ?>"><?php echo get_the_title($comment->comment_post_ID); ?></a>
568 - </h3>
569 - <time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>">
570 - <?php echo date_i18n( get_option( 'date_format' ), strtotime( get_comment_date("", $comment->comment_ID) ) ); ?>
571 - </time>
572 - <div class="uwp-profile-item-summary">
573 - <?php
574 - $excerpt = strip_shortcodes(wp_trim_words( $comment->comment_content, 15, '...' ));
575 - echo $excerpt;
576 - ?>
577 - </div>
578 - </li>
579 - <?php
580 - }
581 - echo '</ul>';
582 - } else {
583 - // no comments found
584 - echo "<p>".__('No Comments Found', 'userswp')."</p>";
585 - }
880 + /**
881 + * Returns the custom fields content of profile page more info tab.
882 + *
883 + * @since 1.0.0
884 + * @package userswp
885 + *
886 + * @param object $user The User ID.
887 + *
888 + * @return string More info tab content.
889 + */
890 + public function get_profile_extra( $user ) {
891 + return $this->get_extra_fields( $user, '[more_info]' );
892 + }
586 893
587 - do_action('uwp_profile_pagination', $maximum_pages);
588 - ?>
589 - </div>
590 - <?php
591 - }
894 + /**
895 + * Prints the profile page "posts" tab content.
896 + *
897 + * @since 1.0.0
898 + * @package userswp
899 + *
900 + * @param object $user The User ID.
901 + *
902 + * @return void
903 + */
904 + public function get_profile_posts( $user ) {
905 + uwp_generic_tab_content( $user, 'post', __( 'Posts', 'userswp' ) );
906 + }
592 907
593 - /**
594 - * Rewrites profile page links
595 - *
596 - * @since 1.0.0
597 - * @package userswp
598 - * @return void
599 - */
600 - public function rewrite_profile_link() {
908 + /**
909 + * Prints the profile page "comments" tab content.
910 + *
911 + * @since 1.0.0
912 + * @package userswp
913 + *
914 + * @param object $user The User ID.
915 + * @param string $post_type Post type.
916 + * @param array $args Extra arguments.
917 + *
918 + * @return void
919 + */
920 + public function get_profile_comments( $user, $post_type = 'post', $args = array() ) {
601 921
602 - $page_id = uwp_get_page_id('profile_page', false);
603 - if ($page_id && !isset($_REQUEST['page_id'])) {
604 - $link = get_page_link($page_id);
605 - $uwp_profile_link = rtrim(substr(str_replace(home_url(), '', $link), 1), '/') . '/';
606 - //$uwp_profile_page_id = url_to_postid($link);
607 - $uwp_profile_page_id = $page_id;
922 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
923 + $number = uwp_get_option( 'profile_no_of_items', 10 );
924 + $offset = ( $paged - 1 ) * $number;
608 925
926 + $total_comments = $this->get_comment_count_by_user( $user->ID, $post_type );
927 + $maximum_pages = ceil( $total_comments / $number );
609 928
929 + $query_args = array(
930 + 'number' => $number,
931 + 'offset' => $offset,
932 + 'user_id' => $user->ID,
933 + 'paged' => $paged,
934 + 'post_type' => $post_type,
935 + );
936 + // The Query
937 + $the_query = new WP_Comment_Query();
938 + $comments = $the_query->query( $query_args );
610 939
611 - // {home_url}/profile/1
612 - $uwp_profile_link_empty_slash = '^' . $uwp_profile_link . '([^/]+)?$';
613 - add_rewrite_rule($uwp_profile_link_empty_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]', 'top');
940 + if(!$comments){
941 + return;
942 + }
614 943
615 - // {home_url}/profile/1/
616 - $uwp_profile_link_with_slash = '^' . $uwp_profile_link . '([^/]+)/?$';
617 - add_rewrite_rule($uwp_profile_link_with_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]', 'top');
944 + $args['template_args']['the_query'] = $comments;
945 + $args['template_args']['user'] = $user;
946 + $args['template_args']['title'] = ! empty( $args['template_args']['title'] ) ? $args['template_args']['title'] : __( "Comments", 'userswp' );
947 + $args['template_args']['maximum_pages'] = $maximum_pages;
618 948
619 - // {home_url}/profile/1/page/1
620 - $uwp_profile_link_empty_slash_paged = '^' . $uwp_profile_link . '([^/]+)/page/([0-9]+)?$';
621 - add_rewrite_rule($uwp_profile_link_empty_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&paged=$matches[2]', 'top');
949 + $design_style = ! empty( $args['design_style'] ) ? esc_attr( $args['design_style'] ) : uwp_get_option( "design_style", 'bootstrap' );
950 + $template = $design_style ? $design_style . "/loop-comments.php" : "loop-comments.php";
951 + uwp_get_template( $template, $args );
952 + }
622 953
623 - // {home_url}/profile/1/page/1/
624 - $uwp_profile_link_with_slash_paged = '^' . $uwp_profile_link . '([^/]+)/page/([0-9]+)/?$';
625 - add_rewrite_rule($uwp_profile_link_with_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&paged=$matches[2]', 'top');
954 + /**
955 + * Displays the profile page "user comments" tab content.
956 + *
957 + * @since 1.2.2.36
958 + * @package userswp
959 + *
960 + * @param object $user The User ID.
961 + * @param string $post_type Post type.
962 + * @param array $args Extra arguments.
963 + *
964 + * @return void
965 + */
966 + public function get_profile_user_comments( $user, $post_type = 'post', $args = array() ) {
626 967
627 - // {home_url}/profile/1/tab-slug
628 - $uwp_profile_tab_empty_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)?$';
629 - add_rewrite_rule($uwp_profile_tab_empty_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]', 'top');
968 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
969 + $number = uwp_get_option( 'profile_no_of_items', 10 );
970 + $offset = ( $paged - 1 ) * $number;
630 971
631 - // {home_url}/profile/1/tab-slug/
632 - $uwp_profile_tab_with_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/?$';
633 - add_rewrite_rule($uwp_profile_tab_with_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]', 'top');
972 + $args = array(
973 + 'post_type' => $post_type,
974 + 'post_status' => 'published',
975 + 'posts_per_page' => -1,
976 + 'author' => $user->ID,
977 + 'fields' => 'ids',
978 + );
634 979
635 - // {home_url}/profile/1/tab-slug/page/1
636 - $uwp_profile_tab_empty_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/page/([0-9]+)?$';
637 - add_rewrite_rule($uwp_profile_tab_empty_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&paged=$matches[3]', 'top');
980 + $wp_query = new WP_Query($args);
981 + $post_ids = $wp_query->posts;
638 982
639 - // {home_url}/profile/1/tab-slug/page/1/
640 - $uwp_profile_tab_with_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/page/([0-9]+)/?$';
641 - add_rewrite_rule($uwp_profile_tab_with_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&paged=$matches[3]', 'top');
983 + if(isset( $the_query->found_posts ) && $wp_query->found_posts == 0 || empty($post_ids) ){
984 + return;
985 + }
642 986
643 - // {home_url}/profile/1/tab-slug/subtab-slug
644 - $uwp_profile_tab_empty_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)?$';
645 - add_rewrite_rule($uwp_profile_tab_empty_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]', 'top');
987 + $query_args = array(
988 + 'count' => true,
989 + 'post_type' => $post_type,
990 + 'post__in' => $post_ids,
991 + 'author__not_in' => $user->ID,
992 + );
993 + // The Query
994 + $the_query = new WP_Comment_Query();
995 + $comments_count = $the_query->query( $query_args );
646 996
647 - // {home_url}/profile/1/tab-slug/subtab-slug/
648 - $uwp_profile_tab_with_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)/?$';
649 - add_rewrite_rule($uwp_profile_tab_with_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]', 'top');
997 + $total_comments = $comments_count;
998 + $maximum_pages = ceil( $total_comments / $number );
650 999
651 - // {home_url}/profile/1/tab-slug/subtab-slug/page/1
652 - $uwp_profile_tab_empty_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)?$';
653 - add_rewrite_rule($uwp_profile_tab_empty_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]&paged=$matches[4]', 'top');
1000 + $query_args = array(
1001 + 'number' => $number,
1002 + 'offset' => $offset,
1003 + 'paged' => $paged,
1004 + 'post_type' => $post_type,
1005 + 'post__in' => $post_ids,
1006 + 'author__not_in' => $user->ID,
1007 + );
654 1008
655 - // {home_url}/profile/1/tab-slug/subtab-slug/page/1/
656 - $uwp_profile_tab_with_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)/?$';
657 - add_rewrite_rule($uwp_profile_tab_with_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]&paged=$matches[4]', 'top');
658 -
659 - if (get_option('uwp_flush_rewrite')) {
660 - //Ensure the $wp_rewrite global is loaded
661 - global $wp_rewrite;
662 - //Call flush_rules() as a method of the $wp_rewrite object
663 - $wp_rewrite->flush_rules( false );
664 - delete_option('uwp_flush_rewrite');
665 - }
666 - }
667 - }
1009 + // The Query
1010 + $the_query = new WP_Comment_Query();
1011 + $comments = $the_query->query( $query_args );
668 1012
669 - /**
670 - * Adds profile page query variables.
671 - *
672 - * @since 1.0.0
673 - * @package userswp
674 - * @param array $query_vars Query variables.
675 - * @return array Modified Query variables array.
676 - */
677 - public function profile_query_vars($query_vars) {
678 - $query_vars[] = 'uwp_profile';
679 - $query_vars[] = 'uwp_tab';
680 - $query_vars[] = 'uwp_subtab';
681 - return $query_vars;
682 - }
1013 + if(!$comments){
1014 + return;
1015 + }
683 1016
684 - /**
685 - * Returns user profile link based on user id.
686 - *
687 - * @since 1.0.0
688 - * @package userswp
689 - * @param string $link Unmodified link.
690 - * @param int $user_id User id.
691 - * @return string Modified link.
692 - */
693 - public function get_profile_link($link, $user_id) {
1017 + $args['template_args']['the_query'] = $comments;
1018 + $args['template_args']['user'] = $user;
1019 + $args['template_args']['title'] = ! empty( $args['template_args']['title'] ) ? $args['template_args']['title'] : __( "User Comments", 'userswp' );
1020 + $args['template_args']['maximum_pages'] = $maximum_pages;
694 1021
695 - $page_id = uwp_get_page_id('profile_page', false);
1022 + $design_style = ! empty( $args['design_style'] ) ? esc_attr( $args['design_style'] ) : uwp_get_option( "design_style", 'bootstrap' );
1023 + $template = $design_style ? $design_style . "/loop-comments.php" : "loop-comments.php";
1024 + uwp_get_template( $template, $args );
1025 + }
696 1026
697 - if ($page_id) {
698 - $link = get_permalink($page_id);
699 - } else {
700 - $link = '';
701 - }
1027 + /**
1028 + * Gets the comment count.
1029 + *
1030 + * @since 1.0.0
1031 + * @package userswp
1032 + *
1033 + * @param int $user_id User ID.
1034 + *
1035 + * @return int Comment count.
1036 + */
1037 + public function get_comment_count_by_user( $user_id, $post_type = 'post' ) {
1038 + global $wpdb;
702 1039
703 - if ($link != '') {
1040 + $count = $wpdb->get_var(
1041 + "SELECT COUNT(comment_ID)
1042 + FROM " . $wpdb->comments . "
1043 + WHERE comment_post_ID in (
1044 + SELECT ID
1045 + FROM " . $wpdb->posts . "
1046 + WHERE post_type = '".$post_type."'
1047 + AND post_status = 'publish')
1048 + AND user_id = " . $user_id . "
1049 + AND comment_approved = '1'
1050 + AND comment_type NOT IN ('pingback', 'trackback' )"
1051 + );
704 1052
705 - if (isset($_REQUEST['page_id'])) {
706 - $permalink_structure = 'DEFAULT';
707 - } else {
708 - $permalink_structure = 'CUSTOM';
709 - // Add forward slash if not available
710 - $link = rtrim($link, '/') . '/';
711 - }
1053 + return $count;
1054 + }
712 1055
1056 + /**
1057 + * Rewrites profile page links
1058 + *
1059 + * @since 1.0.0
1060 + * @package userswp
1061 + * @return void
1062 + */
1063 + public function rewrite_profile_link() {
713 1064
714 - $url_type = apply_filters('uwp_profile_url_type', 'slug');
1065 + $page_id = uwp_get_page_id( 'profile_page', false );
1066 + if ( $page_id && ! isset( $_REQUEST['page_id'] ) && get_post_type( $page_id ) == 'page' ) {
1067 + $link = get_page_link( $page_id );
1068 + $uwp_profile_link = trailingslashit( $this->profile_slug() );
1069 + $uwp_profile_page_id = $page_id;
715 1070
716 - if ($url_type && 'id' == $url_type) {
717 - if ('DEFAULT' == $permalink_structure) {
718 - return add_query_arg(array('viewuser' => $user_id), $link);
719 - } else {
720 - return $link . $user_id;
721 - }
722 - } else {
723 - $user = get_userdata($user_id);
724 - if ( !empty($user->user_nicename) ) {
725 - $username = $user->user_nicename;
726 - } else {
727 - $username = $user->user_login;
728 - }
1071 + // {home_url}/profile/1
1072 + $uwp_profile_link_empty_slash = '^' . $uwp_profile_link . '([^/]+)?$';
1073 + add_rewrite_rule( $uwp_profile_link_empty_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]', 'top' );
729 1074
730 - if ('DEFAULT' == $permalink_structure) {
731 - return add_query_arg(array('username' => $username), $link);
732 - } else {
733 - return $link . $username;
734 - }
1075 + // {home_url}/profile/1/
1076 + $uwp_profile_link_with_slash = '^' . $uwp_profile_link . '([^/]+)/?$';
1077 + add_rewrite_rule( $uwp_profile_link_with_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]', 'top' );
735 1078
736 - }
737 - } else {
738 - return '';
739 - }
740 - }
1079 + // {home_url}/profile/1/page/1
1080 + $uwp_profile_link_empty_slash_paged = '^' . $uwp_profile_link . '([^/]+)/page/([0-9]+)?$';
1081 + add_rewrite_rule( $uwp_profile_link_empty_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&paged=$matches[2]', 'top' );
741 1082
742 - /**
743 - * Modifies profile page title to include username.
744 - *
745 - * @since 1.0.0
746 - * @package userswp
747 - * @param string $title Original title
748 - * @param int|null $id Page id.
749 - * @return string Modified page title.
750 - */
751 - public function modify_profile_page_title( $title, $id = null ) {
1083 + // {home_url}/profile/1/page/1/
1084 + $uwp_profile_link_with_slash_paged = '^' . $uwp_profile_link . '([^/]+)/page/([0-9]+)/?$';
1085 + add_rewrite_rule( $uwp_profile_link_with_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&paged=$matches[2]', 'top' );
752 1086
753 - global $wp_query;
754 - $page_id = uwp_get_page_id('profile_page', false);
1087 + // {home_url}/profile/1/tab-slug
1088 + $uwp_profile_tab_empty_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)?$';
1089 + add_rewrite_rule( $uwp_profile_tab_empty_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]', 'top' );
755 1090
756 - if ($page_id == $id && isset($wp_query->query_vars['uwp_profile']) && in_the_loop()) {
1091 + // {home_url}/profile/1/tab-slug/
1092 + $uwp_profile_tab_with_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/?$';
1093 + add_rewrite_rule( $uwp_profile_tab_with_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]', 'top' );
757 1094
758 - $url_type = apply_filters('uwp_profile_url_type', 'slug');
1095 + // {home_url}/profile/1/tab-slug/page/1
1096 + $uwp_profile_tab_empty_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/page/([0-9]+)?$';
1097 + add_rewrite_rule( $uwp_profile_tab_empty_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&paged=$matches[3]', 'top' );
759 1098
760 - $author_slug = $wp_query->query_vars['uwp_profile'];
1099 + // {home_url}/profile/1/tab-slug/page/1/
1100 + $uwp_profile_tab_with_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/page/([0-9]+)/?$';
1101 + add_rewrite_rule( $uwp_profile_tab_with_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&paged=$matches[3]', 'top' );
761 1102
762 - if ($url_type == 'id') {
763 - $user = get_user_by('id', $author_slug);
764 - } else {
765 - $user = get_user_by('slug', $author_slug);
766 - }
767 - $title = $user->display_name;
768 - }
1103 + // {home_url}/profile/1/tab-slug/subtab-slug
1104 + $uwp_profile_tab_empty_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)?$';
1105 + add_rewrite_rule( $uwp_profile_tab_empty_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]', 'top' );
769 1106
770 - return $title;
771 - }
1107 + // {home_url}/profile/1/tab-slug/subtab-slug/
1108 + $uwp_profile_tab_with_slash = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)/?$';
1109 + add_rewrite_rule( $uwp_profile_tab_with_slash, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]', 'top' );
772 1110
773 - /**
774 - * Returns json content for image crop.
775 - *
776 - * @since 1.0.0
777 - * @package userswp
778 - * @param string $image_url Image url
779 - * @param string $type popup type. Avatar or Banner
780 - * @return string Json
781 - */
782 - public function uwp_image_crop_popup($image_url, $type) {
1111 + // {home_url}/profile/1/tab-slug/subtab-slug/page/1
1112 + $uwp_profile_tab_empty_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)?$';
1113 + add_rewrite_rule( $uwp_profile_tab_empty_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]&paged=$matches[4]', 'top' );
783 1114
784 - add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
785 - $uploads = wp_upload_dir();
786 - remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
787 - $upload_url = $uploads['baseurl'];
788 - $upload_path = $uploads['basedir'];
789 - $image_path = str_replace($upload_url, $upload_path, $image_url);
1115 + // {home_url}/profile/1/tab-slug/subtab-slug/page/1/
1116 + $uwp_profile_tab_with_slash_paged = '^' . $uwp_profile_link . '([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)/?$';
1117 + add_rewrite_rule( $uwp_profile_tab_with_slash_paged, 'index.php?page_id=' . $uwp_profile_page_id . '&uwp_profile=$matches[1]&uwp_tab=$matches[2]&uwp_subtab=$matches[3]&paged=$matches[4]', 'top' );
790 1118
791 - $image = apply_filters( 'uwp_'.$type.'_cropper_image', getimagesize( $image_path ) );
792 - if ( empty( $image ) ) {
793 - return "";
794 - }
1119 + if ( get_option( 'uwp_flush_rewrite' ) ) {
1120 + //Ensure the $wp_rewrite global is loaded
1121 + global $wp_rewrite;
1122 + //Call flush_rules() as a method of the $wp_rewrite object
1123 + $wp_rewrite->flush_rules( false );
1124 + delete_option( 'uwp_flush_rewrite' );
1125 + }
795 1126
796 - // Get avatar full width and height.
797 - if ($type == 'avatar') {
798 - $full_width = apply_filters('uwp_avatar_image_width', 150);
799 - $full_height = apply_filters('uwp_avatar_image_height', 150);
800 - } else {
801 - $full_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000));
802 - $full_height = apply_filters('uwp_banner_image_height', 300);
803 - }
804 -
1127 + if ( function_exists('pll_current_language') ) {
1128 + $previous_lang = ! empty( $_COOKIE[ PLL_COOKIE ] ) ? $_COOKIE[ PLL_COOKIE ] : '';
1129 + $current_lang = pll_current_language();
1130 + if ( $current_lang != $previous_lang ) {
805 1131
806 - $values = array(
807 - 'error' => '',
808 - 'image_url' => $image_url,
809 - 'uwp_popup_type' => $type,
810 - 'uwp_full_width' => $full_width,
811 - 'uwp_full_height' => $full_height,
812 - 'uwp_true_width' => $image[0],
813 - 'uwp_true_height' => $image[1],
814 - 'uwp_popup_content' => $this->uwp_image_crop_modal_html($type, $image_url, $full_width, $full_height),
815 - );
816 -
817 - $json = json_encode($values);
818 1132
1133 + flush_rewrite_rules( true );
1134 + }
1135 + }
1136 + }
1137 + }
819 1138
820 - return $json;
821 - }
1139 + /**
1140 + * Get the slug for the profile page.
1141 + *
1142 + * @since 1.2.2.18
1143 + *
1144 + * @param string $slug Profile slug. Default profile.
1145 + *
1146 + * @return string
1147 + */
1148 + public function profile_slug( $slug = 'profile' ) {
1149 + if ( $page_id = uwp_get_page_id( 'profile_page', false ) ) {
1150 + if ( $_slug = get_post_field( 'post_name', absint( $page_id ) ) ) {
1151 + $slug = $_slug;
1152 + }
1153 + }
1154 + return apply_filters( 'uwp_rewrite_profile_slug', $slug );
1155 + }
822 1156
823 - /**
824 - * Initializes image crop js.
825 - *
826 - * @since 1.0.0
827 - * @package userswp
828 - * @param object $user The User ID.
829 - */
830 - public function uwp_image_crop_init($user) {
831 - if (is_user_logged_in()) {
832 - add_action( 'wp_footer', array($this,'uwp_modal_loading_html'));
833 - add_action( 'wp_footer', array($this,'uwp_modal_close_js'));
834 - if(is_admin()) {
835 - add_action('admin_footer', array($this, 'uwp_modal_loading_html'));
836 - add_action('admin_footer', array($this, 'uwp_modal_close_js'));
837 - }
838 - }
839 - }
1157 + /**
1158 + * Adds profile page query variables.
1159 + *
1160 + * @since 1.0.0
1161 + * @package userswp
1162 + *
1163 + * @param array $query_vars Query variables.
1164 + *
1165 + * @return array Modified Query variables array.
1166 + */
1167 + public function profile_query_vars( $query_vars ) {
1168 + $query_vars[] = 'uwp_profile';
1169 + $query_vars[] = 'uwp_tab';
1170 + $query_vars[] = 'uwp_subtab';
840 1171
841 - /**
842 - * Returns modal content loading html.
843 - *
844 - * @since 1.0.0
845 - * @package userswp
846 - * @return string Modal loding html.
847 - */
848 - public function uwp_modal_loading_html() {
849 - ob_start();
850 - ?>
851 - <div id="uwp-popup-modal-wrap" style="display: none;">
852 - <div class="uwp-bs-modal uwp_fade uwp_show">
853 - <div class="uwp-bs-modal-dialog">
854 - <div class="uwp-bs-modal-content">
855 - <div class="uwp-bs-modal-header">
856 - <h4 class="uwp-bs-modal-title">
857 - <?php echo __( "Loading Form ...", "userswp" ); ?>
858 - </h4>
859 - </div>
860 - <div class="uwp-bs-modal-body">
861 - <div class="uwp-bs-modal-loading-icon-wrap">
862 - <div class="uwp-bs-modal-loading-icon"></div>
863 - </div>
864 - </div>
865 - </div>
866 - </div>
867 - </div>
868 - </div>
869 - <?php
870 - $output = ob_get_contents();
871 - ob_end_clean();
872 - echo trim(preg_replace("/\s+|\n+|\r/", ' ', $output));
873 - }
1172 + return $query_vars;
1173 + }
874 1174
875 - /**
876 - * Adds modal close js.
877 - *
878 - * @since 1.0.0
879 - * @package userswp
880 - * @return void
881 - */
882 - public function uwp_modal_close_js() {
883 - ?>
1175 + /**
1176 + * Modifies profile page title to include username.
1177 + *
1178 + * @since 1.0.0
1179 + * @package userswp
1180 + *
1181 + * @param string $title Original title
1182 + * @param int|null $id Page id.
1183 + *
1184 + * @return string Modified page title.
1185 + */
1186 + public function modify_profile_page_title( $title, $id = null ) {
1187 +
1188 + global $wp_query;
1189 + $page_id = uwp_get_page_id( 'profile_page', false );
1190 +
1191 + if ( $page_id == $id && isset( $wp_query->query_vars['uwp_profile'] ) && in_the_loop() ) {
1192 +
1193 + $url_type = apply_filters( 'uwp_profile_url_type', 'slug' );
1194 +
1195 + $author_slug = $wp_query->query_vars['uwp_profile'];
1196 +
1197 + if ( $url_type == 'id' ) {
1198 + $user = get_user_by( 'id', $author_slug );
1199 + } else {
1200 + $user = get_user_by( 'slug', $author_slug );
1201 + }
1202 + $title = esc_attr( $user->display_name );
1203 + }
1204 +
1205 + return $title;
1206 + }
1207 +
1208 + /**
1209 + * Initializes image crop js.
1210 + *
1211 + * @since 1.0.0
1212 + * @package userswp
1213 + *
1214 + * @param object $user The User ID.
1215 + */
1216 + public function image_crop_init( $user ) {
1217 + if ( is_user_logged_in() ) {
1218 + add_action( 'wp_footer', array( $this, 'modal_loading_html' ) );
1219 + add_action( 'wp_footer', array( $this, 'modal_close_js' ) );
1220 + if ( is_admin() ) {
1221 + add_action( 'admin_footer', array( $this, 'modal_loading_html' ) );
1222 + add_action( 'admin_footer', array( $this, 'modal_close_js' ) );
1223 + }
1224 + }
1225 + }
1226 +
1227 + /**
1228 + * Adds modal close js.
1229 + *
1230 + * @since 1.0.0
1231 + * @package userswp
1232 + * @return void
1233 + */
1234 + public function modal_close_js() {
1235 + ?>
884 1236 <script type="text/javascript">
885 - (function( $, window, undefined ) {
1237 + (function ($, window, undefined) {
886 1238 $(document).ready(function () {
887 - $('.uwp-modal-close').click(function(e) {
1239 + $('.uwp-modal-close').click(function (e) {
888 1240 e.preventDefault();
889 - var uwp_popup_type = $( this ).data( 'type' );
1241 + var uwp_popup_type = $(this).data('type');
890 1242 // $('#uwp-'+uwp_popup_type+'-modal').hide();
891 1243 var mod_shadow = jQuery('#uwp-modal-backdrop');
892 1244 var container = jQuery('#uwp-popup-modal-wrap');
893 1245 container.hide();
894 - container.replaceWith('<?php echo $this->uwp_modal_loading_html(); ?>');
1246 + container.replaceWith('<?php echo $this->modal_loading_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>');
895 1247 mod_shadow.remove();
896 1248 });
897 1249 });
898 - }( jQuery, window ));
1250 + }(jQuery, window));
899 1251 </script>
900 - <?php
901 - }
1252 + <?php
1253 + }
902 1254
903 - /**
904 - * Returns avatar and banner crop modal html.
1255 + /*
1256 + * Modifies get_avatar_url function to use UWP avatar URL.
1257 + *
1258 + * @param string $url Default avatar URL
1259 + * @param int|string $id_or_email User ID or email
1260 + *
1261 + * @return string $url New avatar URL
905 1262 *
906 - * @since 1.0.0
907 - * @package userswp
908 - * @param string $type Avatar or Banner
909 - * @param string $image_url Image url to crop
910 - * @param int $full_width Full image width
911 - * @param int $full_height Full image height
912 - * @return string Html.
913 - */
914 - public function uwp_image_crop_modal_html($type, $image_url, $full_width, $full_height) {
915 - ob_start();
916 - ?>
917 - <div class="uwp-bs-modal uwp_fade uwp_show" id="uwp-<?php echo $type; ?>-modal">
918 - <div class="uwp-bs-modal-dialog">
919 - <div class="uwp-bs-modal-content">
920 - <div class="uwp-bs-modal-header">
921 - <h4 class="uwp-bs-modal-title">
922 - <?php
923 - if ($type == 'avatar') {
924 - echo __( 'Change your profile photo', 'userswp' );
925 - } else {
926 - echo __( 'Change your cover photo', 'userswp' );
927 - }
928 - ?>
929 - </h4>
930 - <button type="button" class="close uwp-modal-close" data-type="<?php echo $type; ?>" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
931 - </div>
932 - <div class="uwp-bs-modal-body">
933 - <div id="uwp-bs-modal-notice"></div>
934 - <div align="center">
935 - <img src="<?php echo $image_url; ?>" id="uwp-<?php echo $type; ?>-to-crop" />
936 - </div>
937 - </div>
938 - <div class="uwp-bs-modal-footer">
939 - <div class="uwp-<?php echo $type; ?>-crop-p-wrap">
940 - <div id="<?php echo $type; ?>-crop-actions">
941 - <form class="uwp-crop-form" method="post">
942 - <input type="hidden" name="x" value="" id="<?php echo $type; ?>-x" />
943 - <input type="hidden" name="y" value="" id="<?php echo $type; ?>-y" />
944 - <input type="hidden" name="w" value="" id="<?php echo $type; ?>-w" />
945 - <input type="hidden" name="h" value="" id="<?php echo $type; ?>-h" />
946 - <input type="hidden" id="uwp-<?php echo $type; ?>-crop-image" name="uwp_crop" value="<?php echo $image_url; ?>" />
947 - <input type="hidden" name="uwp_crop_nonce" value="<?php echo wp_create_nonce( 'uwp-crop-nonce' ); ?>" />
948 - <input type="submit" name="uwp_<?php echo $type; ?>_crop" value="<?php echo __('Apply', 'userswp'); ?>" class="button button-primary" id="save_uwp_<?php echo $type; ?>" />
949 - </form>
950 - </div>
951 - </div>
952 - <button type="button" data-type="<?php echo $type; ?>" class="button uwp_modal_btn uwp-modal-close" data-dismiss="modal"><?php echo __( 'Cancel', 'userswp' ); ?></button>
953 - </div>
954 - </div>
955 - </div>
956 - </div>
1263 + */
1264 + function get_avatar_url( $url, $id_or_email ) {
1265 +
1266 + // don't filter on admin side.
1267 + if ( is_admin() && ! wp_doing_ajax() ) {
1268 + return $url;
1269 + }
1270 +
1271 + $user = false;
1272 +
1273 + if ( 1 == uwp_get_option( 'disable_avatar_override' ) ) {
1274 + return $url;
1275 + }
1276 +
1277 + if ( is_numeric( $id_or_email ) ) {
1278 +
1279 + $id = (int) $id_or_email;
1280 + $user = get_user_by( 'id', $id );
1281 +
1282 + } elseif ( is_object( $id_or_email ) ) {
1283 +
1284 + if ( ! empty( $id_or_email->user_id ) ) {
1285 + $id = (int) $id_or_email->user_id;
1286 + $user = get_user_by( 'id', $id );
1287 + }
1288 +
1289 + } else {
1290 + $user = get_user_by( 'email', $id_or_email );
1291 + }
1292 +
1293 + if ( $user && is_object( $user ) ) {
1294 + $avatar_thumb = uwp_get_usermeta( $user->data->ID, 'avatar_thumb', '' );
1295 + if ( ! empty( $avatar_thumb ) ) {
1296 + add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
1297 + $uploads = wp_upload_dir();
1298 + remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
1299 + $upload_url = $uploads['baseurl'];
1300 + if ( substr( $avatar_thumb, 0, 4 ) !== "http" ) {
1301 + $url = $upload_url . $avatar_thumb;
1302 + } else {
1303 + $url = $avatar_thumb;
1304 + }
1305 + } else {
1306 + $default = uwp_get_default_avatar_uri();
1307 + if ( uwp_is_localhost() ) { // if localhost then default gravatar won't work.
1308 + $url = $default;
1309 + } else {
1310 + $url = remove_query_arg( 'd', $url );
1311 + $url = add_query_arg( array( 'd' => $default ), $url );
1312 + }
1313 +
1314 + }
1315 + }
1316 +
1317 + return $url;
1318 + }
1319 +
1320 + /**
1321 + * Modified the comment author url to profile page link for loggedin users.
1322 + *
1323 + * @since 1.0.0
1324 + * @package userswp
1325 + *
1326 + * @param string $link Original author link.
1327 + *
1328 + * @return string Modified author link.
1329 + */
1330 + public function get_comment_author_link( $link ) {
1331 + global $comment;
1332 + if ( ! empty( $comment->user_id ) && ! empty( get_userdata( $comment->user_id )->ID ) ) {
1333 + $user = get_userdata( $comment->user_id );
1334 + $link = sprintf(
1335 + '<a href="%s" rel="external nofollow" class="url">%s</a>',
1336 + uwp_build_profile_tab_url( $comment->user_id ),
1337 + strip_tags( $user->display_name )
1338 + );
1339 + }
1340 +
1341 + return $link;
1342 + }
1343 +
1344 + /**
1345 + * Redirects /author page to /profile page.
1346 + *
1347 + * @since 1.0.0
1348 + * @package userswp
1349 + * @return void
1350 + */
1351 + public function redirect_author_page() {
1352 +
1353 + if ( uwp_is_page_builder() ) {
1354 + return;
1355 + }
1356 +
1357 + if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_check_redirect_author_page', true ) ) {
1358 + $id = get_query_var( 'author' );
1359 + $link = uwp_build_profile_tab_url( $id );
1360 + $link = apply_filters( 'uwp_redirect_author_page', $link, $id );
1361 + wp_redirect( $link );
1362 + exit;
1363 + }
1364 + }
1365 +
1366 + /**
1367 + * Modifies "edit my profile" link in admin bar
1368 + *
1369 + * @since 1.0.0
1370 + * @package userswp
1371 + *
1372 + * @param string $url The complete URL including scheme and path.
1373 + * @param int $user_id The user ID.
1374 + * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login',
1375 + * 'login_post', 'admin', 'relative' or null.
1376 + *
1377 + * @return false|string Filtered url.
1378 + */
1379 + public function modify_admin_bar_edit_profile_url( $url, $user_id, $scheme ) {
1380 + // Makes the link to http://example.com/account
1381 + if ( ! is_admin() && ! user_can( $user_id, 'administrator' ) ) {
1382 + $account_page = uwp_get_page_id( 'account_page', false );
1383 + if ( $account_page ) {
1384 + $account_page_link = get_permalink( $account_page );
1385 + $url = $account_page_link;
1386 + }
1387 + }
1388 +
1389 + return $url;
1390 + }
1391 +
1392 + /**
1393 + * Restrict the files display only to current users in media popup.
1394 + *
1395 + * @since 1.0.0
1396 + * @package userswp
1397 + *
1398 + * @param object $wp_query Unmodified wp_query.
1399 + *
1400 + * @return object Modified wp_query.
1401 + */
1402 + public function restrict_attachment_display( $wp_query ) {
1403 + if ( ! is_admin() ) {
1404 + if ( ! current_user_can( 'manage_options' ) ) {
1405 + $wp_query->set( 'author', get_current_user_id() );
1406 + }
1407 + }
1408 +
1409 + return $wp_query;
1410 + }
1411 +
1412 + /**
1413 + * Allow users to upload files who has upload capability.
1414 + *
1415 + * @since 1.0.0
1416 + * @package userswp
1417 + *
1418 + * @param array $llcaps An array of all the user's capabilities.
1419 + * @param array $caps Actual capabilities for meta capability.
1420 + * @param array $args Optional parameters passed to has_cap(), typically object ID.
1421 + * @param object $user The user object.
1422 + *
1423 + * @return array User capabilities.
1424 + */
1425 + public function allow_all_users_profile_uploads( $llcaps, $caps, $args, $user ) {
1426 +
1427 + $files = new UsersWP_Files();
1428 +
1429 + if ( isset( $caps[0] ) && $caps[0] == 'upload_files' && $files->doing_upload() ) {
1430 + $llcaps['upload_files'] = true;
1431 + }
1432 +
1433 + return $llcaps;
1434 + }
1435 +
1436 + /**
1437 + * Validates file uploads and returns errors if found.
1438 + *
1439 + * @since 1.0.0
1440 + * @package userswp
1441 + *
1442 + * @param string|bool $value Original value.
1443 + * @param object $field Field info.
1444 + * @param string $file_key Field key.
1445 + * @param array $file_to_upload File data to upload.
1446 + *
1447 + * @return string|WP_Error Returns original value if no errors. Else returns errors.
1448 + */
1449 + public function handle_file_upload_error_checks( $value, $field, $file_key, $file_to_upload ) {
1450 +
1451 + if ( in_array( $field->htmlvar_name, array( 'avatar', 'banner' ) ) ) {
1452 +
1453 + if ( $field->htmlvar_name == 'avatar' ) {
1454 + $avatar_size = uwp_get_upload_image_size();
1455 + $min_width = $avatar_size['width'];
1456 + $min_height = $avatar_size['height'];
1457 + } else {
1458 + $banner_size = uwp_get_upload_image_size('banner');
1459 + $min_width = $banner_size['width'];
1460 + $min_height = $banner_size['height'];
1461 + }
1462 +
1463 + $imagedetails = getimagesize( $file_to_upload['tmp_name'] );
1464 + $width = $imagedetails[0];
1465 + $height = $imagedetails[1];
1466 +
1467 + if ( $width < $min_width ) {
1468 + return new WP_Error( 'image-too-small', sprintf( __( 'The uploaded file is too small. Minimum image width should be %s px', 'userswp' ), $min_width ) );
1469 + }
1470 + if ( $height < $min_height ) {
1471 + return new WP_Error( 'image-too-small', sprintf( __( 'The uploaded file is too small. Minimum image height should be %s px', 'userswp' ), $min_height ) );
1472 + }
1473 + }
1474 +
1475 + return $value;
1476 +
1477 + }
1478 +
1479 + /**
1480 + * Sets uwp_profile_upload to true on profile page.
1481 + *
1482 + * @since 1.0.0
1483 + * @package userswp
1484 + *
1485 + * @param array $params Plupload params
1486 + *
1487 + * @return array Plupload params
1488 + */
1489 + public function add_uwp_plupload_param( $params ) {
1490 +
1491 + if ( ! is_admin() && get_the_ID() == uwp_get_page_id( 'profile_page', false ) ) {
1492 + $params['uwp_profile_upload'] = true;
1493 + }
1494 +
1495 + return $params;
1496 + }
1497 +
1498 + /**
1499 + * Handles avatar and banner file upload.
1500 + *
1501 + * @since 1.0.0
1502 + * @package userswp
1503 + * @return void
1504 + */
1505 + public function ajax_avatar_banner_upload() {
1506 + // Image upload handler
1507 + // todo: security checks
1508 + $type = strip_tags( esc_sql( $_POST['uwp_popup_type'] ) );
1509 + $result = array();
1510 +
1511 + if ( ! in_array( $type, array( 'banner', 'avatar' ) ) ) {
1512 + $result['error'] = aui()->alert( array(
1513 + 'type' => 'danger',
1514 + 'content' => __( "Invalid request!", "userswp" )
1515 + ) );
1516 + $return = json_encode( $result );
1517 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1518 + die();
1519 + }
1520 +
1521 + global $wpdb;
1522 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1523 + $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE form_type = %s AND field_type = 'file' AND is_active = '1' ORDER BY sort_order ASC", array( $type ) ) );
1524 +
1525 + $field = false;
1526 + if ( $fields ) {
1527 + $field = $fields[0];
1528 + }
1529 +
1530 + $result = array();
1531 +
1532 + if ( ! $field ) {
1533 + $result['error'] = aui()->alert( array(
1534 + 'type' => 'danger',
1535 + 'content' => __( "No fields available", "userswp" )
1536 + ) );
1537 + $return = json_encode( $result );
1538 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1539 + die();
1540 + }
1541 +
1542 + $files = new UsersWP_Files();
1543 + $errors = $files->handle_file_upload( $field, $_FILES );
1544 +
1545 + if ( is_wp_error( $errors ) ) {
1546 + $result['error'] = aui()->alert( array(
1547 + 'type' => 'danger',
1548 + 'content' => $errors->get_error_message()
1549 + ) );
1550 + $return = json_encode( $result );
1551 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1552 + } else {
1553 + $return = $this->ajax_image_crop_popup( $errors['url'], $type );
1554 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1555 + }
1556 +
1557 + die();
1558 + }
1559 +
1560 + /**
1561 + * Returns the avatar and banner crop popup html and js.
1562 + *
1563 + * @since 1.0.0
1564 + * @package userswp
1565 + *
1566 + * @param string $image_url Image url to crop.
1567 + * @param string $type Crop type. Avatar or Banner
1568 + *
1569 + * @return string|null Html and js content.
1570 + */
1571 + public function ajax_image_crop_popup( $image_url, $type ) {
1572 + wp_enqueue_style( 'jcrop' );
1573 + wp_enqueue_script( 'jcrop', array( 'jquery' ) );
1574 +
1575 + $output = null;
1576 + if ( $image_url && $type ) {
1577 + $output = $this->image_crop_popup( $image_url, $type );
1578 + }
1579 +
1580 + return $output;
1581 + }
1582 +
1583 + /**
1584 + * Returns json content for image crop.
1585 + *
1586 + * @since 1.0.0
1587 + * @package userswp
1588 + *
1589 + * @param string $image_url Image url
1590 + * @param string $type popup type. Avatar or Banner
1591 + *
1592 + * @return string Json
1593 + */
1594 + public function image_crop_popup( $image_url, $type ) {
1595 +
1596 + add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
1597 + $uploads = wp_upload_dir();
1598 + remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
1599 + $upload_url = $uploads['baseurl'];
1600 + $upload_path = $uploads['basedir'];
1601 + $image_path = str_replace( $upload_url, $upload_path, $image_url );
1602 +
1603 + $image = apply_filters( 'uwp_' . $type . '_cropper_image', getimagesize( $image_path ) );
1604 + if ( empty( $image ) ) {
1605 + return "";
1606 + }
1607 +
1608 + if ( $type == 'avatar' ) {
1609 + $avatar_size = uwp_get_upload_image_size();
1610 + $full_width = $avatar_size['width'];
1611 + $full_height = $avatar_size['height'];
1612 + } else {
1613 + $banner_size = uwp_get_upload_image_size('banner');
1614 + $full_width = $banner_size['width'];
1615 + $full_height = $banner_size['height'];
1616 + }
1617 +
1618 + $values = array(
1619 + 'error' => '',
1620 + 'image_url' => $image_url,
1621 + 'uwp_popup_type' => $type,
1622 + 'uwp_full_width' => $full_width,
1623 + 'uwp_full_height' => $full_height,
1624 + 'uwp_true_width' => $image[0],
1625 + 'uwp_true_height' => $image[1],
1626 + 'uwp_popup_content' => $this->image_crop_modal_html( $type, $image_url, $full_width, $full_height ),
1627 + );
1628 +
1629 + $json = json_encode( $values );
1630 +
1631 +
1632 + return $json;
1633 + }
1634 +
1635 + /**
1636 + * Returns avatar and banner crop modal html.
1637 + *
1638 + * @since 1.0.0
1639 + * @package userswp
1640 + *
1641 + * @param string $type Avatar or Banner
1642 + * @param string $image_url Image url to crop
1643 + * @param int $full_width Full image width
1644 + * @param int $full_height Full image height
1645 + *
1646 + * @return string Html.
1647 + */
1648 + public function image_crop_modal_html( $type, $image_url, $full_width, $full_height ) {
1649 + $args = array(
1650 + 'type' => $type,
1651 + 'image_url' => $image_url,
1652 + 'full_width' => $full_width,
1653 + 'full_height' => $full_height,
1654 + );
1655 + ob_start();
1656 +
1657 + $design_style = uwp_get_option( "design_style", 'bootstrap' );
1658 + $template = $design_style ? $design_style . "/modal-profile-image-crop.php" : "modal-profile-image-crop.php";
1659 +
1660 + uwp_get_template( $template, $args );
1661 + ?>
957 1662 <script type="text/javascript">
958 - (function( $, window, undefined ) {
1663 + (function ($, window, undefined) {
959 1664 $(document).ready(function () {
960 - $('.uwp-modal-close').click(function(e) {
1665 + $('.uwp-modal-close').click(function (e) {
961 1666 e.preventDefault();
962 - var uwp_popup_type = $( this ).data( 'type' );
963 - // $('#uwp-'+uwp_popup_type+'-modal').hide();
1667 + var uwp_popup_type = $(this).data('type');
964 1668 var mod_shadow = jQuery('#uwp-modal-backdrop');
965 1669 var container = jQuery('#uwp-popup-modal-wrap');
966 1670 container.hide();
967 - container.replaceWith('<?php echo $this->uwp_modal_loading_html(); ?>');
1671 + container.replaceWith('<?php echo $this->modal_loading_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>');
968 1672 mod_shadow.remove();
969 1673 });
970 1674 });
971 - }( jQuery, window ));
1675 + }(jQuery, window));
972 1676 </script>
973 - <?php
974 - $output = ob_get_contents();
975 - ob_end_clean();
976 - return trim($output);
977 - }
1677 + <?php
1678 + $output = ob_get_contents();
1679 + ob_end_clean();
978 1680
979 - /**
980 - * Returns avatar and banner crop submit form.
981 - *
982 - * @since 1.0.0
983 - * @package userswp
984 - * @param string $type Avatar or Banner
985 - * @return string Html.
986 - */
987 - public function uwp_crop_submit_form($type = 'avatar') {
988 - $files = new UsersWP_Files();
989 - ob_start();
990 - ?>
991 - <div class="uwp-bs-modal uwp_fade uwp_show" id="uwp-popup-modal-wrap">
992 - <div class="uwp-bs-modal-dialog">
993 - <div class="uwp-bs-modal-content">
994 - <div class="uwp-bs-modal-header">
995 - <h4 class="uwp-bs-modal-title">
996 - <?php
997 - if ($type == 'avatar') {
998 - echo __( 'Change your profile photo', 'userswp' );
999 - } else {
1000 - echo __( 'Change your cover photo', 'userswp' );
1001 - }
1002 - ?>
1003 - </h4>
1004 - <button type="button" class="close uwp-modal-close" data-type="<?php echo $type; ?>" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1005 - </div>
1006 - <div class="uwp-bs-modal-body">
1007 - <div id="uwp-bs-modal-notice"></div>
1008 - <form id="uwp-upload-<?php echo $type; ?>-form" method="post" enctype="multipart/form-data">
1009 - <input type="hidden" name="uwp_upload_nonce" value="<?php echo wp_create_nonce( 'uwp-upload-nonce' ); ?>" />
1010 - <input type="hidden" name="uwp_<?php echo $type; ?>_submit" value="" />
1011 - <button type="button" class="uwp_upload_button" onclick="document.getElementById('uwp_upload_<?php echo $type; ?>').click();"><?php echo __( 'Upload', 'userswp' ); ?> <?php echo $type; ?></button>
1012 - <p style="text-align: center"><?php echo __('Note: Max upload image size: ', 'userswp').$files->uwp_formatSizeUnits($files->uwp_get_max_upload_size($type)); ?></p>
1013 - <div class="uwp_upload_field" style="display: none">
1014 - <input name="uwp_<?php echo $type; ?>_file" id="uwp_upload_<?php echo $type; ?>" required="required" type="file" value="">
1681 + return trim( $output );
1682 + }
1683 +
1684 + /**
1685 + * Returns modal content loading html.
1686 + *
1687 + * @since 1.0.0
1688 + * @package userswp
1689 + */
1690 + public function modal_loading_html() {
1691 + ob_start();
1692 + ?>
1693 + <div id="uwp-popup-modal-wrap" style="display: none;">
1694 + <div class="uwp-bs-modal uwp_fade uwp_show">
1695 + <div class="uwp-bs-modal-dialog">
1696 + <div class="uwp-bs-modal-content">
1697 + <div class="uwp-bs-modal-header">
1698 + <h4 class="uwp-bs-modal-title">
1699 + <?php esc_attr_e( "Loading Form ...", "userswp" ); ?>
1700 + </h4>
1701 + </div>
1702 + <div class="uwp-bs-modal-body">
1703 + <div class="uwp-bs-modal-loading-icon-wrap">
1704 + <div class="uwp-bs-modal-loading-icon"></div>
1015 1705 </div>
1016 - </form>
1017 - <div id="progressBar" class="tiny-green" style="display: none;"><div></div></div>
1018 - </div>
1019 - <div class="uwp-bs-modal-footer">
1020 - <div class="uwp-<?php echo $type; ?>-crop-p-wrap">
1021 - <div id="<?php echo $type; ?>-crop-actions">
1022 - <form class="uwp-crop-form" method="post">
1023 - <input type="submit" name="uwp_<?php echo $type; ?>_crop" disabled="disabled" value="<?php echo __('Apply', 'userswp'); ?>" class="button button-primary" id="save_uwp_<?php echo $type; ?>" />
1024 - </form>
1025 - </div>
1026 1706 </div>
1027 - <button type="button" data-type="<?php echo $type; ?>" class="button uwp_modal_btn uwp-modal-close" data-dismiss="modal"><?php echo __( 'Cancel', 'userswp' ); ?></button>
1028 1707 </div>
1029 1708 </div>
1030 1709 </div>
1031 1710 </div>
1711 + <?php
1712 + $output = ob_get_contents();
1713 + ob_end_clean();
1714 + echo trim( preg_replace( "/\s+|\n+|\r/", ' ', $output ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1715 + }
1716 +
1717 + /**
1718 + * Handles crop popup form ajax request.
1719 + *
1720 + * @since 1.0.0
1721 + * @package userswp
1722 + * @return void
1723 + */
1724 + public function ajax_image_crop_popup_form() {
1725 + $type = isset( $_POST['type'] ) ? strip_tags( esc_sql( $_POST['type'] ) ) : '';
1726 +
1727 + $output = null;
1728 +
1729 +
1730 + if ( $type && in_array( $type, array( 'banner', 'avatar' ) ) ) {
1731 + $output = $this->crop_submit_form( $type );
1732 + }
1733 + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1734 + exit();
1735 + }
1736 +
1737 + /**
1738 + * Returns avatar and banner crop submit form.
1739 + *
1740 + * @since 1.0.0
1741 + * @package userswp
1742 + *
1743 + * @param string $type Avatar or Banner
1744 + *
1745 + * @return string Html.
1746 + */
1747 + public function crop_submit_form( $type = 'avatar' ) {
1748 +
1749 + ob_start();
1750 +
1751 + // get file sizes
1752 + $files = new UsersWP_Files();
1753 + $max_file_size = $files->uwp_get_max_upload_size( $type );
1754 +
1755 + $design_style = uwp_get_option( "design_style", 'bootstrap' );
1756 + $template = $design_style ? $design_style . "/modal-profile-image.php" : "modal-profile-image.php";
1757 + uwp_get_template( $template );
1758 +
1759 + $content_wrap = $design_style == 'bootstrap' ? '.uwp-profile-image-change-modal .modal-content' : '#uwp-popup-modal-wrap';
1760 + $bg_color = apply_filters('uwp_crop_image_bg_color', '', $type);
1761 + ?>
1762 +
1032 1763 <script type="text/javascript">
1033 - (function( $, window, undefined ) {
1764 + (function ($, window, undefined) {
1034 1765
1035 - var uwp_popup_type = '<?php echo $type; ?>';
1766 + var uwp_popup_type = '<?php echo esc_attr( $type ); ?>';
1036 1767
1037 1768 $(document).ready(function () {
1038 1769 $("#progressbar").progressbar();
1039 - $('.uwp-modal-close').click(function(e) {
1770 + $('.uwp-modal-close').click(function (e) {
1040 1771 e.preventDefault();
1041 - var uwp_popup_type = $( this ).data( 'type' );
1042 - // $('#uwp-'+uwp_popup_type+'-modal').hide();
1772 + var uwp_popup_type = $(this).data('type');
1043 1773 var mod_shadow = jQuery('#uwp-modal-backdrop');
1044 1774 var container = jQuery('#uwp-popup-modal-wrap');
1045 1775 container.hide();
1046 - container.replaceWith('<?php echo $this->uwp_modal_loading_html(); ?>');
1776 + container.replaceWith('<?php $this->modal_loading_html(); ?>');
1047 1777 mod_shadow.remove();
1048 1778 });
1049 1779
1050 - $('#uwp_upload_<?php echo $type; ?>').on('change', function(e) {
1780 + $('#uwp_upload_<?php echo esc_attr( $type ); ?>').on('change', function (e) {
1051 1781 e.preventDefault();
1052 1782
1053 - var container = jQuery('#uwp-popup-modal-wrap');
1783 + var container = jQuery('<?php echo esc_attr( $content_wrap );?>');
1054 1784 var err_container = jQuery('#uwp-bs-modal-notice');
1785 + err_container.html('');// clear errors on retry
1055 1786
1056 1787 var fd = new FormData();
1057 1788 var files_data = $(this); // The <input type="file" /> field
1058 1789 var file = files_data[0].files[0];
1790 + var file_size = file.size;
1059 1791
1060 - fd.append('uwp_<?php echo $type; ?>_file', file);
1792 + // file size check
1793 + if (file_size && <?php echo absint( $max_file_size );?> && file_size > <?php echo absint( $max_file_size );?>) {
1794 + err_container.html('<div class="text-center alert alert-danger"><?php esc_attr_e( 'File too big.', 'userswp' );?></div>');
1795 + return;
1796 + }
1797 +
1798 + fd.append('<?php echo esc_attr( $type ); ?>', file);
1061 1799 // our AJAX identifier
1062 1800 fd.append('action', 'uwp_avatar_banner_upload');
1063 - fd.append('uwp_popup_type', '<?php echo $type; ?>');
1801 + fd.append('uwp_popup_type', '<?php echo esc_attr( $type ); ?>');
1064 1802
1065 - $("#progressBar").show();
1803 + $("#progressBar").show().removeClass('d-none');
1066 1804
1067 1805 $.ajax({
1068 1806 // Your server script to process the upload
1069 - url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
1807 + url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
1070 1808 type: 'POST',
1071 -
1072 - // Form data
1073 1809 data: fd,
1074 -
1075 - // Tell jQuery not to process data or worry about content-type
1076 - // You *must* include these options!
1077 1810 cache: false,
1078 1811 contentType: false,
1079 1812 processData: false,
1080 1813
1081 - // Custom XMLHttpRequest
1082 - xhr: function() {
1814 + xhr: function () {
1083 1815 myXhr = $.ajaxSettings.xhr();
1084 - if(myXhr.upload){
1085 - myXhr.upload.addEventListener('progress',showProgress, false);
1816 + if (myXhr.upload) {
1817 + myXhr.upload.addEventListener('progress', showProgress, false);
1086 1818 } else {
1087 1819 console.log("Upload progress is not supported.");
1088 1820 }
1089 1821 return myXhr;
@@ -1088,9 +1820,9 @@
1088 1820 }
1089 1821 return myXhr;
1090 1822 },
1091 1823
1092 - success:function(response) {
1824 + success: function (response) {
1093 1825 $("#progressBar").hide();
1094 1826 resp = JSON.parse(response);
1095 1827 if (resp['error'] != "") {
1096 1828 err_container.html(resp['error']);
@@ -1100,19 +1832,20 @@
1100 1832 uwp_full_height = resp['uwp_full_height'];
1101 1833 uwp_true_width = resp['uwp_true_width'];
1102 1834 uwp_true_height = resp['uwp_true_height'];
1103 1835
1104 - jQuery('#uwp-popup-modal-wrap').html(resp['uwp_popup_content']).find('#uwp-'+uwp_popup_type+'-to-crop').Jcrop({
1836 + container.html(resp['uwp_popup_content']).find('#uwp-' + uwp_popup_type + '-to-crop').Jcrop({
1105 1837 // onChange: showPreview,
1106 1838 onSelect: updateCoords,
1107 1839 allowResize: true,
1108 1840 allowSelect: false,
1841 + bgColor: '<?php echo esc_html( $bg_color ); ?>',
1109 1842 boxWidth: 650, //Maximum width you want for your bigger images
1110 1843 boxHeight: 400, //Maximum Height for your bigger images
1111 - setSelect: [ 0, 0, uwp_full_width, uwp_full_height ],
1112 - aspectRatio: uwp_full_width/uwp_full_height,
1113 - trueSize: [uwp_true_width,uwp_true_height],
1114 - minSize: [uwp_full_width,uwp_full_height]
1844 + setSelect: [0, 0, uwp_full_width, uwp_full_height],
1845 + aspectRatio: uwp_full_width / uwp_full_height,
1846 + trueSize: [uwp_true_width, uwp_true_height],
1847 + minSize: [uwp_full_width, uwp_full_height]
1115 1848 });
1116 1849 }
1117 1850 }
1118 1851 });
@@ -1120,752 +1853,103 @@
1120 1853
1121 1854 function showProgress(evt) {
1122 1855 if (evt.lengthComputable) {
1123 1856 var percentComplete = (evt.loaded / evt.total) * 100;
1124 -// $('#progressbar').progressbar("option", "value", percentComplete );
1125 1857 progress(percentComplete, $('#progressBar'));
1126 1858 }
1127 1859 }
1128 1860
1129 1861 function progress(percent, $element) {
1130 - var progressBarWidth = percent * $element.width() / 100;
1131 - $element.find('div').animate({ width: progressBarWidth }, 500).html(percent + "% ");
1862 + percent = Math.round(percent);
1863 + var progressBarWidth = percent * ( $element.width() / 100 );
1864 + $element.find('div').width(progressBarWidth).html(percent + "%");
1132 1865 }
1133 1866
1134 1867 function updateCoords(c) {
1135 - jQuery('#'+uwp_popup_type+'-x').val(c.x);
1136 - jQuery('#'+uwp_popup_type+'-y').val(c.y);
1137 - jQuery('#'+uwp_popup_type+'-w').val(c.w);
1138 - jQuery('#'+uwp_popup_type+'-h').val(c.h);
1868 + jQuery('#' + uwp_popup_type + '-x').val(c.x);
1869 + jQuery('#' + uwp_popup_type + '-y').val(c.y);
1870 + jQuery('#' + uwp_popup_type + '-w').val(c.w);
1871 + jQuery('#' + uwp_popup_type + '-h').val(c.h);
1139 1872 }
1140 1873
1141 1874 });
1142 - }( jQuery, window ));
1875 + }(jQuery, window));
1143 1876 </script>
1144 1877
1145 - <?php
1146 - $output = ob_get_contents();
1147 - ob_end_clean();
1148 - return trim($output);
1149 - }
1878 + <?php
1879 + $output = ob_get_contents();
1880 + ob_end_clean();
1150 1881
1151 -
1152 - /**
1153 - * Array search by value
1154 - *
1155 - * @since 1.0.0
1156 - * @package userswp
1157 - * @param array $array Original array.
1158 - * @param mixed $key Array key
1159 - * @param mixed $value Array value.
1160 - * @return array Result array.
1161 - */
1162 - public function uwp_array_search($array, $key, $value)
1163 - {
1164 - $results = array();
1882 + return trim( $output );
1883 + }
1165 1884
1166 - if (is_array($array)) {
1167 - if (isset($array[$key]) && $array[$key] == $value) {
1168 - $results[] = $array;
1169 - }
1885 + public function ajax_profile_image_remove() {
1886 + check_ajax_referer( 'uwp_basic_nonce', 'security' );
1170 1887
1171 - foreach ($array as $subarray) {
1172 - $results = array_merge($results, $this->uwp_array_search($subarray, $key, $value));
1173 - }
1174 - }
1888 + $type = ! empty( $_POST['type'] ) ? $_POST['type'] : '';
1175 1889
1176 - return $results;
1177 - }
1890 + if ( ! in_array( $type, array( 'banner', 'avatar' ) ) ) {
1891 + wp_die( -1 );
1892 + }
1178 1893
1179 - /**
1180 - * Modifies get_avatar function to use userswp avatar.
1181 - *
1182 - * @since 1.0.0
1183 - * @package userswp
1184 - * @param string $avatar img tag value for the user's avatar.
1185 - * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
1186 - * user email, WP_User object, WP_Post object, or WP_Comment object.
1187 - * @param int $size Square avatar width and height in pixels to retrieve.
1188 - * @param string $default URL for the default image or a default type. Accepts '404', 'retro', 'monsterid',
1189 - * 'wavatar', 'indenticon','mystery' (or 'mm', or 'mysteryman'), 'blank', or 'gravatar_default'.
1190 - * Default is the value of the 'avatar_default' option, with a fallback of 'mystery'.
1191 - * @param string $alt Alternative text to use in the avatar image tag. Default empty.
1192 - * @return string Modified img tag value
1193 - */
1194 - public function uwp_modify_get_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) {
1195 - $user = false;
1894 + $user_id = is_user_logged_in() ? (int) get_current_user_id() : 0;
1196 1895
1197 - if ( is_numeric( $id_or_email ) ) {
1896 + if ( empty( $user_id ) ) {
1897 + wp_send_json_error( __( 'Invalid access!', 'userswp' ) );
1898 + }
1198 1899
1199 - $id = (int) $id_or_email;
1200 - $user = get_user_by( 'id' , $id );
1900 + uwp_update_usermeta( $user_id, $type . '_thumb', '' );
1201 1901
1202 - } elseif ( is_object( $id_or_email ) ) {
1902 + wp_send_json_success();
1203 1903
1204 - if ( ! empty( $id_or_email->user_id ) ) {
1205 - $id = (int) $id_or_email->user_id;
1206 - $user = get_user_by( 'id' , $id );
1207 - }
1904 + wp_die();
1905 + }
1208 1906
1209 - } else {
1210 - $user = get_user_by( 'email', $id_or_email );
1211 - }
1907 + /**
1908 + * Defines javascript ajaxurl variable.
1909 + *
1910 + * @since 1.0.0
1911 + * @package userswp
1912 + * @return void
1913 + */
1914 + public function define_ajaxurl() {
1212 1915
1213 - if ( $user && is_object( $user ) ) {
1214 - $avatar_thumb = uwp_get_usermeta($user->data->ID, 'uwp_account_avatar_thumb', '');
1215 - if ( !empty($avatar_thumb) ) {
1216 - add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
1217 - $uploads = wp_upload_dir();
1218 - remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
1219 - $upload_url = $uploads['baseurl'];
1220 - if (substr( $avatar_thumb, 0, 4 ) !== "http") {
1221 - $avatar_thumb = $upload_url.$avatar_thumb;
1222 - }
1223 - $avatar = "<img alt='{$alt}' src='{$avatar_thumb}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
1224 - } else {
1225 - $default = uwp_get_default_avatar_uri();
1226 - $args = get_avatar_data( $id_or_email, $args );
1227 - $url = $args['url'];
1228 - $url = remove_query_arg('d', $url);
1229 - $url = add_query_arg(array('d' => $default), $url);
1230 - if ( ! $url || is_wp_error( $url ) ) {
1231 - return $avatar;
1232 - }
1233 - $avatar = '<img src="' .$url .'" class="gravatar avatar avatar-'.$size.' uwp-avatar" width="'.$size.'" height="'.$size.'" alt="'.$alt.'" />';
1234 - }
1235 -
1236 - }
1237 -
1238 - return $avatar;
1239 - }
1240 -
1241 - /**
1242 - * Modified the comment author url to profile page link for loggedin users.
1243 - *
1244 - * @since 1.0.0
1245 - * @package userswp
1246 - * @param string $link Original author link.
1247 - * @return string Modified author link.
1248 - */
1249 - public function uwp_get_comment_author_link($link) {
1250 - global $comment;
1251 - if ( !empty( $comment->user_id ) && !empty( get_userdata( $comment->user_id )->ID ) ) {
1252 - $user = get_userdata( $comment->user_id );
1253 - $link = sprintf(
1254 - '<a href="%s" rel="external nofollow" class="url">%s</a>',
1255 - uwp_build_profile_tab_url( $comment->user_id ),
1256 - strip_tags( $user->display_name )
1257 - );
1258 - }
1259 - return $link;
1260 - }
1261 -
1262 - /**
1263 - * Redirects /author page to /profile page.
1264 - *
1265 - * @since 1.0.0
1266 - * @package userswp
1267 - * @return void
1268 - */
1269 - public function uwp_redirect_author_page() {
1270 -
1271 - if(uwp_is_page_builder()){
1272 - return;
1273 - }
1274 -
1275 - if ( is_author() && apply_filters( 'uwp_check_redirect_author_page', true ) ) {
1276 - $id = get_query_var( 'author' );
1277 - $link = uwp_build_profile_tab_url( $id );
1278 - $link = apply_filters( 'uwp_redirect_author_page', $link, $id );
1279 - wp_redirect($link);
1280 - exit;
1281 - }
1282 - }
1283 -
1284 - /**
1285 - * Modifies "edit my profile" link in admin bar
1286 - *
1287 - * @since 1.0.0
1288 - * @package userswp
1289 - * @param string $url The complete URL including scheme and path.
1290 - * @param int $user_id The user ID.
1291 - * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login',
1292 - * 'login_post', 'admin', 'relative' or null.
1293 - * @return false|string Filtered url.
1294 - */
1295 - public function uwp_modify_admin_bar_edit_profile_url( $url, $user_id, $scheme )
1296 - {
1297 - // Makes the link to http://example.com/account
1298 - if (!is_admin()) {
1299 - $account_page = uwp_get_page_id('account_page', false);
1300 - if ($account_page) {
1301 - $account_page_link = get_permalink($account_page);
1302 - $url = $account_page_link;
1303 - }
1304 - }
1305 - return $url;
1306 - }
1307 -
1308 - /**
1309 - * Restrict the files display only to current users in media popup.
1310 - *
1311 - * @since 1.0.0
1312 - * @package userswp
1313 - * @param object $wp_query Unmodified wp_query.
1314 - * @return object Modified wp_query.
1315 - */
1316 - public function uwp_restrict_attachment_display($wp_query) {
1317 - if (!is_admin()) {
1318 - if ( ! current_user_can( 'manage_options' ) ) {
1319 - //$wp_query['author'] = get_current_user_id();
1320 - $wp_query->set( 'author', get_current_user_id() );
1321 - }
1322 - }
1323 - return $wp_query;
1324 - }
1325 -
1326 - /**
1327 - * Allow users to upload files who has upload capability.
1328 - *
1329 - * @since 1.0.0
1330 - * @package userswp
1331 - * @param array $llcaps An array of all the user's capabilities.
1332 - * @param array $caps Actual capabilities for meta capability.
1333 - * @param array $args Optional parameters passed to has_cap(), typically object ID.
1334 - * @param object $user The user object.
1335 - * @return array User capabilities.
1336 - */
1337 - public function allow_all_users_profile_uploads($llcaps, $caps, $args, $user) {
1338 -
1339 - $files = new UsersWP_Files();
1340 -
1341 - if(isset($caps[0]) && $caps[0] =='upload_files' && $files->uwp_doing_upload() ){
1342 - $llcaps['upload_files'] = true;
1343 - }
1344 -
1345 - return $llcaps;
1346 - }
1347 -
1348 - /**
1349 - * Validates file uploads and returns errors if found.
1350 - *
1351 - * @since 1.0.0
1352 - * @package userswp
1353 - * @param string|bool $value Original value.
1354 - * @param object $field Field info.
1355 - * @param string $file_key Field key.
1356 - * @param array $file_to_upload File data to upload.
1357 - * @return string|WP_Error Returns original value if no erros. Else returns errors.
1358 - */
1359 - public function uwp_handle_file_upload_error_checks($value, $field, $file_key, $file_to_upload) {
1360 -
1361 - if (in_array($field->htmlvar_name, array('uwp_avatar_file', 'uwp_banner_file'))) {
1362 -
1363 - if ($field->htmlvar_name == 'uwp_avatar_file') {
1364 - $min_width = apply_filters('uwp_avatar_image_width', 150);
1365 - $min_height = apply_filters('uwp_avatar_image_height', 150);
1366 - } else {
1367 - $min_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000));
1368 - $min_height = apply_filters('uwp_banner_image_height', 300);
1369 - }
1370 -
1371 - $imagedetails = getimagesize( $file_to_upload['tmp_name'] );
1372 - $width = $imagedetails[0];
1373 - $height = $imagedetails[1];
1374 -
1375 - if ( $width < $min_width) {
1376 - return new WP_Error( 'image-too-small', sprintf( __( 'The uploaded file is too small. Minimum image width should be %s px', 'userswp' ), $min_width));
1377 - }
1378 - if ( $height < $min_height) {
1379 - return new WP_Error( 'image-too-small', sprintf( __( 'The uploaded file is too small. Minimum image height should be %s px', 'userswp' ), $min_height) );
1380 - }
1381 - }
1382 -
1383 - return $value;
1384 -
1385 - }
1386 -
1387 - /**
1388 - * Sets uwp_profile_upload to true on profile page.
1389 - *
1390 - * @since 1.0.0
1391 - * @package userswp
1392 - * @param array $params Plupload params
1393 - * @return array Plupload params
1394 - */
1395 - public function add_uwp_plupload_param($params) {
1396 -
1397 - if(!is_admin() && get_the_ID()==uwp_get_page_id('profile_page', false)){
1398 - $params['uwp_profile_upload'] = true;
1399 - }
1400 -
1401 - return $params;
1402 - }
1403 -
1404 - /**
1405 - * Handles avatar and banner file upload.
1406 - *
1407 - * @since 1.0.0
1408 - * @package userswp
1409 - * @return void
1410 - */
1411 - public function uwp_ajax_avatar_banner_upload() {
1412 - // Image upload handler
1413 - // todo: security checks
1414 - $type = strip_tags(esc_sql($_POST['uwp_popup_type']));
1415 -
1416 - if (!in_array($type, array('banner', 'avatar'))) {
1417 - $result['error'] = uwp_wrap_notice(__("Invalid request!", "userswp"), 'error');
1418 - $return = json_encode($result);
1419 - echo $return;
1420 - die();
1421 - }
1422 -
1423 - global $wpdb;
1424 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1425 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND field_type = 'file' AND is_active = '1' ORDER BY sort_order ASC", array($type)));
1426 -
1427 - $field = false;
1428 - if ($fields) {
1429 - $field = $fields[0];
1430 - }
1431 -
1432 - $result = array();
1433 -
1434 - if (!$field) {
1435 - $result['error'] = uwp_wrap_notice(__("No fields available", "userswp"), 'error');
1436 - $return = json_encode($result);
1437 - echo $return;
1438 - die();
1439 - }
1440 -
1441 - $files = new UsersWP_Files();
1442 - $errors = $files->handle_file_upload($field, $_FILES);
1443 -
1444 - if (is_wp_error($errors)) {
1445 - $result['error'] = uwp_wrap_notice($errors->get_error_message(), 'error');
1446 - $return = json_encode($result);
1447 - echo $return;
1448 - } else {
1449 - $return = $this->uwp_ajax_image_crop_popup($errors['url'], $type);
1450 - echo $return;
1451 - }
1452 -
1453 - die();
1454 - }
1455 -
1456 - /**
1457 - * Returns the avatar and banner crop popup html and js.
1458 - *
1459 - * @since 1.0.0
1460 - * @package userswp
1461 - * @param string $image_url Image url to crop.
1462 - * @param string $type Crop type. Avatar or Banner
1463 - * @return string|null Html and js content.
1464 - */
1465 - public function uwp_ajax_image_crop_popup($image_url, $type){
1466 - wp_enqueue_style( 'jcrop' );
1467 - wp_enqueue_script( 'jcrop', array( 'jquery' ) );
1468 -
1469 - $output = null;
1470 - if ($image_url && $type ) {
1471 - $output = $this->uwp_image_crop_popup($image_url, $type);
1472 - }
1473 - return $output;
1474 - }
1475 -
1476 - /**
1477 - * Handles crop popup form ajax request.
1478 - *
1479 - * @since 1.0.0
1480 - * @package userswp
1481 - * @return void
1482 - */
1483 - public function uwp_ajax_image_crop_popup_form(){
1484 - $type = strip_tags(esc_sql($_POST['type']));
1485 -
1486 - $output = null;
1487 -
1488 -
1489 - if ($type && in_array($type, array('banner', 'avatar'))) {
1490 - $output = $this->uwp_crop_submit_form($type);
1491 - }
1492 - echo $output;
1493 - exit();
1494 - }
1495 -
1496 - /**
1497 - * Defines javascript ajaxurl variable.
1498 - *
1499 - * @since 1.0.0
1500 - * @package userswp
1501 - * @return void
1502 - */
1503 - public function uwp_define_ajaxurl() {
1504 -
1505 - echo '<script type="text/javascript">
1506 - var ajaxurl = "' . admin_url('admin-ajax.php') . '";
1916 + echo '<script type="text/javascript">
1917 + var ajaxurl = "' . esc_url( admin_url( 'admin-ajax.php' ) ) . '";
1507 1918 </script>';
1508 - }
1919 + }
1509 1920
1510 - /**
1511 - * Adds UsersWP serach form in Users page.
1512 - *
1513 - * @since 1.0.0
1514 - * @package userswp
1515 - * @return void
1516 - */
1517 - public function uwp_users_search() {
1518 - ?>
1519 - <div class="uwp-users-list-sort-search">
1520 - <div class="uwp-user-search" id="uwp_user_search">
1521 - <?php
1522 - $keyword = "";
1523 - if (isset($_GET['uwps']) && $_GET['uwps'] != '') {
1524 - $keyword = stripslashes(strip_tags($_GET['uwps']));
1525 - }
1526 - ?>
1527 - <form method="get" class="searchform search-form" action="<?php echo get_uwp_users_permalink(); ?>">
1528 - <?php do_action('uwp_users_page_search_form_inner', $keyword); ?>
1529 - </form>
1530 - </div>
1531 - <div class="uwp-user-sort">
1532 - <?php
1533 - $default_layout = uwp_get_option('users_default_layout', 'list');
1534 - ?>
1535 - <form method="get" action="">
1536 - <select name="uwp_layout" id="uwp_layout">
1537 - <option <?php selected( $default_layout, "list" ); ?> value="list"><?php echo __("List View", "userswp"); ?></option>
1538 - <option <?php selected( $default_layout, "2col" ); ?> value="2col"><?php echo __("Grid 2 Col", "userswp"); ?></option>
1539 - <option <?php selected( $default_layout, "3col" ); ?> value="3col"><?php echo __("Grid 3 Col", "userswp"); ?></option>
1540 - <option <?php selected( $default_layout, "4col" ); ?> value="4col"><?php echo __("Grid 4 Col", "userswp"); ?></option>
1541 - <option <?php selected( $default_layout, "5col" ); ?> value="5col"><?php echo __("Grid 5 Col", "userswp"); ?></option>
1542 - </select>
1543 - <?php
1544 - $sort_by = "";
1545 - if (isset($_GET['uwp_sort_by']) && $_GET['uwp_sort_by'] != '') {
1546 - $sort_by = strip_tags(esc_sql($_GET['uwp_sort_by']));
1547 - }
1548 - ?>
1549 - <select name="uwp_sort_by" id="uwp_sort_by" onchange="this.form.submit()">
1550 - <option value=""><?php echo __("Sort By:", "userswp"); ?></option>
1551 - <option <?php selected( $sort_by, "newer" ); ?> value="newer"><?php echo __("Newer", "userswp"); ?></option>
1552 - <option <?php selected( $sort_by, "older" ); ?> value="older"><?php echo __("Older", "userswp"); ?></option>
1553 - <option <?php selected( $sort_by, "alpha_asc" ); ?> value="alpha_asc"><?php echo __("A-Z", "userswp"); ?></option>
1554 - <option <?php selected( $sort_by, "alpha_desc" ); ?> value="alpha_desc"><?php echo __("Z-A", "userswp"); ?></option>
1555 - </select>
1556 - </form>
1557 - </div>
1558 - </div>
1559 - <?php
1560 - }
1561 -
1562 - /**
1563 - * Prints the users page main content.
1564 - *
1565 - * @since 1.0.0
1566 - * @package userswp
1567 - *
1568 - * @return void
1569 - */
1570 - public function uwp_users_list() {
1571 - get_uwp_users_list();
1572 - }
1573 -
1574 - /**
1575 - * Add custom fields as an available tabs
1576 - *
1577 - * @since 1.0.20
1578 - * @package userswp
1579 - * @param $tabs_arr
1580 - * @return mixed
1581 - */
1582 - public function uwp_extra_fields_available_tab_items($tabs_arr){
1583 - global $wpdb;
1584 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1585 - $fields = $wpdb->get_results("SELECT htmlvar_name, site_title FROM " . $table_name . " WHERE form_type = 'account' AND is_public != '0' AND show_in LIKE '%[own_tab]%' ORDER BY sort_order ASC");
1586 -
1587 - foreach ($fields as $field) {
1588 - $key = str_replace('uwp_account_', '', $field->htmlvar_name);
1589 - $tabs_arr[$key] = __($field->site_title, 'userswp');
1921 + public function wpdiscuz_profile_url( $profile_url, $user ) {
1922 + if(!$user){
1923 + return $profile_url;
1590 1924 }
1591 1925
1592 - return $tabs_arr;
1593 - }
1926 + $allowed = apply_filters( 'uwp_wpdiscuz_profile_url_change', true, $profile_url, $user );
1927 + if ( $allowed && isset($user->user_login) ) {
1928 + return $this->get_profile_link( $profile_url, $user->ID );
1929 + }
1594 1930
1595 - /**
1596 - * Displays custom fields as tabs
1597 - *
1598 - * @since 1.0.0
1599 - * @package userswp
1600 - * @param $tabs
1601 - * @param $user
1602 - * @return mixed
1603 - */
1604 - public function uwp_extra_fields_as_tabs($tabs, $user, $allowed_tabs)
1605 - {
1606 - global $wpdb;
1607 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1608 - $fields = $wpdb->get_results("SELECT site_title,field_icon,htmlvar_name,is_public,field_type,field_type_key FROM " . $table_name . " WHERE form_type = 'account' AND is_public != '0' AND show_in LIKE '%[own_tab]%' ORDER BY sort_order ASC");
1609 - $usermeta = uwp_get_usermeta_row($user->ID);
1610 - $privacy = ! empty( $usermeta ) && $usermeta->user_privacy ? explode(',', $usermeta->user_privacy) : array();
1931 + return $profile_url;
1932 + }
1611 1933
1612 - foreach ($fields as $field) {
1613 - if ($field->field_icon != '') {
1614 - $icon = uwp_get_field_icon($field->field_icon);
1615 - } else {
1616 - $field_icon = uwp_field_type_to_fa_icon($field->field_type);
1617 - if ($field_icon) {
1618 - $icon = '<i class="'.$field_icon.'"></i>';
1619 - } else {
1620 - $icon = '<i class="fas fa-user"></i>';
1621 - }
1622 - }
1623 - $key = str_replace('uwp_account_', '', $field->htmlvar_name);
1624 - $value = $this->uwp_get_field_value($field, $user);
1625 - if (!in_array($key, $allowed_tabs) || !$value) {
1626 - continue;
1627 - }
1628 - if ($field->is_public == '1') {
1629 - $tabs[$key] = array(
1630 - 'title' => __($field->site_title, 'userswp'),
1631 - 'count' => $icon
1632 - );
1633 - } else {
1634 - if (!in_array($field->htmlvar_name.'_privacy', $privacy)) {
1635 - $tabs[$key] = array(
1636 - 'title' => __($field->site_title, 'userswp'),
1637 - 'count' => $icon
1638 - );
1639 - }
1640 - }
1641 - }
1642 - return $tabs;
1643 - }
1644 -
1645 - /**
1646 - * Prints custom field values as tab content.
1647 - *
1648 - * @since 1.0.0
1649 - * @package userswp
1650 - * @param object $user The User ID.
1651 - * @param string $active_tab Active tab.
1652 - */
1653 - public function uwp_extra_fields_as_tab_values($user, $active_tab)
1654 - {
1655 - global $wpdb;
1656 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1657 - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_public != '0' ORDER BY sort_order ASC");
1658 - $usermeta = uwp_get_usermeta_row($user->ID);
1659 - $privacy = ! empty( $usermeta ) && $usermeta->user_privacy ? explode(',', $usermeta->user_privacy) : array();
1660 -
1661 - $fieldsets = array();
1662 - $fieldset = false;
1663 - foreach ($fields as $field) {
1664 - $key = str_replace('uwp_account_', '', $field->htmlvar_name);
1665 - if ($field->field_type == 'fieldset') {
1666 - $fieldset = $key;
1667 - }
1668 - $show_in = explode(',',$field->show_in);
1669 - if (in_array("[fieldset]", $show_in)) {
1670 - $fieldsets[$fieldset][] = $field;
1671 - }
1672 - if ($key == $active_tab && $field->field_type != 'fieldset') {
1673 - $value = $this->uwp_get_field_value($field, $user);
1674 - echo '<div class="uwp_profile_tab_field_content">';
1675 - echo $value;
1676 - echo '</div>';
1677 - }
1678 - }
1679 -
1680 - if (isset($fieldsets[$active_tab])) {
1681 - $fieldset_fields = $fieldsets[$active_tab];
1682 - ?>
1683 - <div class="uwp-profile-extra">
1684 - <div class="uwp-profile-extra-div form-table">
1685 - <?php
1686 - foreach ($fieldset_fields as $field) {
1687 - $display = false;
1688 - if ($field->is_public == '1') {
1689 - $display = true;
1690 - } else {
1691 - if (!in_array($field->htmlvar_name.'_privacy', $privacy)) {
1692 - $display = true;
1693 - }
1694 - }
1695 - if (!$display) {
1696 - continue;
1697 - }
1698 - $value = $this->uwp_get_field_value($field, $user);
1699 - // Icon
1700 - $icon = uwp_get_field_icon( $field->field_icon );
1701 - ?>
1702 - <div class="uwp-profile-extra-wrap">
1703 - <div class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?><span class="uwp-profile-extra-sep">:</span></div>
1704 - <div class="uwp-profile-extra-value">
1705 - <?php
1706 - echo $value;
1707 - ?>
1708 - </div>
1934 + /**
1935 + * Display lightbox modal
1936 + */
1937 + public function lightbox_modals() {
1938 + ?>
1939 + <div class="modal fade uwp-profile-image-change-modal" tabindex="-1" role="dialog"
1940 + aria-labelledby="uwp-profile-modal-title" aria-hidden="true">
1941 + <div class="modal-dialog modal-xl">
1942 + <div class="modal-content">
1943 + <div class="modal-header">
1944 + <h5 class="modal-title" id="uwp-profile-modal-title"></h5>
1709 1945 </div>
1710 - <?php
1711 - }
1712 - ?>
1946 + <div class="modal-body">
1947 + <i class="fas fa-circle-notch fa-spin"></i>
1948 + </div>
1713 1949 </div>
1714 1950 </div>
1715 - <?php
1716 - }
1717 - }
1718 -
1719 - /**
1720 - * Gets custom field value based on key.
1721 - *
1722 - * @since 1.0.0
1723 - * @package userswp
1724 - * @param object $field Field info object.
1725 - * @param object $user The User ID.
1726 - * @return string Custom field value.
1727 - */
1728 - public function uwp_get_field_value($field, $user) {
1729 -
1730 - $user_data = get_userdata($user->ID);
1731 - $file_obj = new UsersWP_Files();
1732 -
1733 - if ($field->htmlvar_name == 'uwp_account_email') {
1734 - $value = $user_data->user_email;
1735 - } elseif ($field->htmlvar_name == 'uwp_account_password') {
1736 - $value = '';
1737 - $field->is_required = 0;
1738 - } elseif ($field->htmlvar_name == 'uwp_account_confirm_password') {
1739 - $value = '';
1740 - $field->is_required = 0;
1741 - } else {
1742 - $value = uwp_get_usermeta($user->ID, $field->htmlvar_name, "");
1743 - }
1744 -
1745 - // Select and Multiselect needs Value to be converted
1746 - if ($field->field_type == 'select' || $field->field_type == 'multiselect') {
1747 - $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1748 -
1749 - // Select
1750 - if ($field->field_type == 'select') {
1751 -
1752 - if($field->field_type_key != 'country'){
1753 - if (!empty($value)) {
1754 - $data = $this->uwp_array_search($option_values_arr, 'value', $value);
1755 - $value = $data[0]['label'];
1756 - } else {
1757 - $value = '';
1758 - }
1759 - }
1760 - }
1761 -
1762 - //Multiselect
1763 - if ($field->field_type == 'multiselect' && !empty($value)) {
1764 - if (!empty($value) && is_array($value)) {
1765 - $array_value = array();
1766 - foreach ($value as $v) {
1767 - if(!empty($v)){
1768 - $data = $this->uwp_array_search($option_values_arr, 'value', $v);
1769 - $array_value[] = $data[0]['label'];
1770 - }
1771 -
1772 - }
1773 - if(!empty($array_value)){
1774 - $value = implode(', ', $array_value);
1775 - }else{
1776 - $value = '';
1777 - }
1778 -
1779 - } else {
1780 - $value = '';
1781 - }
1782 - }
1783 - }
1784 -
1785 - // Date
1786 - if ($field->field_type == 'datepicker') {
1787 - $extra_fields = unserialize($field->extra_fields);
1788 -
1789 - if ($extra_fields['date_format'] == '')
1790 - $extra_fields['date_format'] = 'yy-mm-dd';
1791 -
1792 - $date_format = $extra_fields['date_format'];
1793 -
1794 - if (!empty($value)) {
1795 - $value = date('Y-m-d', $value);
1796 - }
1797 -
1798 - $value = uwp_date($value, $date_format, 'Y-m-d');
1799 - }
1800 -
1801 -
1802 - // Time
1803 - if ($field->field_type == 'time') {
1804 - $value = date(get_option('time_format'), strtotime($value));
1805 - }
1806 -
1807 - // URL
1808 - if ($field->field_type == 'url' && !empty($value)) {
1809 - $link_text = $value;
1810 - // if deafult_value is not url then it will be used as link text.
1811 - if ($field->default_value && !empty($field->default_value) ) {
1812 - if (substr( $field->default_value, 0, 4 ) === "http") {
1813 - $link_text = $value;
1814 - } else {
1815 - $link_text = $field->default_value;
1816 - }
1817 - }
1818 - if (substr( $link_text, 0, 4 ) === "http") {
1819 - $link_text = esc_url($link_text);
1820 - }
1821 -
1822 - $value = '<a href="'.$value.'">'.$link_text.'</a>';
1823 - }
1824 -
1825 - // Checkbox
1826 - if ($field->field_type == 'checkbox') {
1827 - if ($value == '1') {
1828 - $value = 'Yes';
1829 - } else {
1830 - $value = 'No';
1831 - }
1832 - }
1833 -
1834 - // File
1835 - if ($field->field_type == 'file') {
1836 - $value = $file_obj->uwp_file_upload_preview($field, $value, false);
1837 - }
1838 -
1839 - // Sanitize
1840 - switch ($field->field_type) {
1841 - case 'url':
1842 - // already escaped
1843 - break;
1844 - case 'file':
1845 - // already escaped
1846 - break;
1847 - case 'textarea':
1848 - $value = esc_textarea( $value );
1849 - break;
1850 - default:
1851 - $value = esc_html( $value );
1852 - }
1853 -
1854 - if($field->field_type_key == 'country'){
1855 - $value = uwp_output_country_html($value);
1856 - }
1857 -
1858 - return $value;
1859 - }
1860 -
1861 - public function uwp_wpdiscuz_profile_url($profile_url, $user){
1862 - $profile_page_url = uwp_get_page_id('profile_page', true);
1863 - $allowed = apply_filters('uwp_wpdiscuz_profile_url_change', true, $profile_url, $user);
1864 - if (isset($profile_page_url) && !empty($profile_page_url) && $allowed ) {
1865 - return $profile_page_url;
1866 - }
1867 -
1868 - return $profile_url;
1869 - }
1951 + </div>
1952 + <?php
1953 + }
1870 1954
1871 1955 }