PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.2
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.2
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 1.0.22 1.0.23 All 172 releases
userswp / includes / class-profile.php

class-profile.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.2, at includes/class-profile.php

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