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