PluginProbe
wpForo Forum / 3.0.8
wpForo Forum v3.0.8
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / widgets / Profile.php

Profile.php in wpForo Forum 3.0.8, at widgets/Profile.php

213 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\widgets;
4
5 use WP_Widget;
6
7 class Profile extends WP_Widget {
8 /**
9 * @var array
10 */
11 private $default_instance;
12
13 function __construct() {
14 parent::__construct( 'wpforo_profile', 'wpForo User Profile & Notifications', [ 'description' => 'wpForo profile data and notifications' ] );
15 $this->init_local_vars();
16 }
17
18 private function init_local_vars() {
19 $this->default_instance = [
20 'title' => __( 'My Profile', 'wpforo' ),
21 'title_guest' => __( 'Join Us!', 'wpforo' ),
22 'hide_avatar' => false,
23 'hide_name' => false,
24 'hide_notification' => false,
25 'hide_data' => false,
26 'hide_buttons' => false,
27 'hide_for_guests' => false,
28 ];
29 }
30
31 public function widget( $args, $instance ) {
32 $display_widget = ! ( ! is_user_logged_in() ) || ! wpfval( $instance, 'hide_for_guests' );
33 if( $display_widget ) {
34 $class = 'wpf-' . wpforo_setting( 'styles', 'color_style' );
35 echo $args['before_widget'];
36 echo '<div id="wpf-widget-profile" class="wpforo-widget-wrap ' . esc_attr( $class ) . '">';
37 if( wpfval( $instance, 'title' ) && is_user_logged_in() ) {
38 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
39 } elseif( ! is_user_logged_in() ) {
40 $title_guest = wpfval( $instance, 'title_guest' ) ? wpfval( $instance, 'title_guest' ) : apply_filters( 'wpforo_profile_widget_guest_title', __( 'Join Us!', 'wpforo' ) );
41 echo $args['before_title'] . apply_filters( 'widget_title', $title_guest ) . $args['after_title'];
42 }
43 echo '<div class="wpforo-widget-content">';
44 $member = WPF()->current_user;
45 ?>
46 <div class="wpf-prof-wrap">
47 <?php if( is_user_logged_in() ): wp_enqueue_script( 'wpforo-widgets-js' ); ?>
48 <div class="wpf-prof-header">
49 <?php if( ! wpfval( $instance, 'hide_avatar' ) && wpforo_setting( 'profiles', 'avatars' ) ): ?>
50 <div class="wpf-prof-avatar">
51 <?php echo wpforo_user_avatar( $member, 80 ); ?>
52 </div>
53 <?php endif; ?>
54 <?php if( ! wpfval( $instance, 'hide_name' ) ): ?>
55 <div class="wpf-prof-info">
56 <div class="wpf-prof-name">
57 <?php WPF()->member->show_online_indicator( $member['userid'] ) ?>
58 <?php echo wpfval( $member, 'display_name' ) ? esc_html( $member['display_name'] ) : esc_html( urldecode( (string) $member['nicename'] ) ) ?>
59 <?php if( function_exists('wpforo_is_anonymous_mask_member') && ! wpforo_is_anonymous_mask_member($member) ) { wpforo_member_nicename( $member, '@' ); } ?>
60 </div>
61 </div>
62 <?php endif; ?>
63 <?php if( ! wpfval( $instance, 'hide_notification' ) && wpforo_setting( 'notifications', 'notifications' ) ): ?>
64 <div class="wpf-prof-alerts">
65 <?php WPF()->activity->bell( 'wpf-widget-alerts' ); ?>
66 </div>
67 <?php endif; ?>
68 </div>
69 <?php if( ! wpfval( $instance, 'hide_notification' ) && wpforo_setting( 'notifications', 'notifications' ) ): ?>
70 <div class="wpf-prof-notifications" style="flex-basis: 100%;">
71 <?php wpforo_notifications() ?>
72 </div>
73 <?php endif; ?>
74 <?php if( ! wpfval( $instance, 'hide_data' ) ): ?>
75 <div class="wpf-prof-content">
76 <?php do_action( 'wpforo_wiget_profile_content_before', $member ); ?>
77 <div class="wpf-prof-data">
78 <div class="wpf-prof-rating">
79 <?php echo in_array( $member['groupid'], wpforo_setting( 'rating', 'rating_title_ug' ) ) ? '<span class="wpf-member-title wpfrt">' . esc_html(
80 $member['rating']['title']
81 ) . '</span>' : ''; ?>
82 <?php wpforo_member_badge( $member ); ?>
83 </div>
84 <?php wpforo_member_title( $member, true, '', '', [ 'rating-title' ] ); ?>
85 </div>
86 <?php do_action( 'wpforo_wiget_profile_content_after', $member ); ?>
87 </div>
88 <?php endif; ?>
89 <?php endif; ?>
90 <div class="wpf-prof-footer">
91 <?php do_action( 'wpforo_wiget_profile_footer_before', $member ); ?>
92 <?php if( is_user_logged_in() ): ?>
93 <?php if( ! wpfval( $instance, 'hide_buttons' ) ): ?>
94 <div class="wpf-prof-buttons">
95 <?php WPF()->tpl->member_buttons( $member, get_called_class() ) ?>
96 <?php if( ! wpforo_is_bot() ) : ?>
97 <a href="<?php echo wpforo_logout_url() ?>" class="wpf-logout"
98 title="<?php wpforo_phrase( 'Logout' ) ?>">
99 <svg height="12" width="12" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
100 <path fill="currentColor"
101 d="M497 273L329 441c-15 15-41 4.5-41-17v-96H152c-13.3 0-24-10.7-24-24v-96c0-13.3 10.7-24 24-24h136V88c0-21.4 25.9-32 41-17l168 168c9.3 9.4 9.3 24.6 0 34zM192 436v-40c0-6.6-5.4-12-12-12H96c-17.7 0-32-14.3-32-32V160c0-17.7 14.3-32 32-32h84c6.6 0 12-5.4 12-12V76c0-6.6-5.4-12-12-12H96c-53 0-96 43-96 96v192c0 53 43 96 96 96h84c6.6 0 12-5.4 12-12z"/>
102 </svg>
103 </a>
104 <?php endif ?>
105 </div>
106 <?php endif; ?>
107 <?php elseif( ! wpforo_is_bot() ): ?>
108 <div class="wpf-prof-loginout">
109 <a href="<?php echo wpforo_login_url(); ?>" class="wpf-button">
110 <svg height="12" width="12" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
111 <path fill="currentColor"
112 d="M416 448h-84c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h84c17.7 0 32-14.3 32-32V160c0-17.7-14.3-32-32-32h-84c-6.6 0-12-5.4-12-12V76c0-6.6 5.4-12 12-12h84c53 0 96 43 96 96v192c0 53-43 96-96 96zm-47-201L201 79c-15-15-41-4.5-41 17v96H24c-13.3 0-24 10.7-24 24v96c0 13.3 10.7 24 24 24h136v96c0 21.5 26 32 41 17l168-168c9.3-9.4 9.3-24.6 0-34z"/>
113 </svg> <?php wpforo_phrase( 'Login' ) ?></a> &nbsp;
114 <a href="<?php echo wpforo_register_url(); ?>" class="wpf-button">
115 <svg height="12" width="12" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512">
116 <path fill="currentColor"
117 d="M96 128a128 128 0 1 1 256 0A128 128 0 1 1 96 128zM0 482.3C0 383.8 79.8 304 178.3 304h91.4C368.2 304 448 383.8 448 482.3c0 16.4-13.3 29.7-29.7 29.7H29.7C13.3 512 0 498.7 0 482.3zM504 312V248H440c-13.3 0-24-10.7-24-24s10.7-24 24-24h64V136c0-13.3 10.7-24 24-24s24 10.7 24 24v64h64c13.3 0 24 10.7 24 24s-10.7 24-24 24H552v64c0 13.3-10.7 24-24 24s-24-10.7-24-24z"/>
118 </svg> <?php wpforo_phrase( 'Register' ) ?></a>
119 </div>
120 <?php endif; ?>
121 <?php do_action( 'wpforo_wiget_profile_footer_after', $member ); ?>
122 </div>
123 </div>
124 <?php
125 echo '</div></div>';
126 echo $args['after_widget'];
127 }
128 }
129
130 public function form( $instance ) {
131 $title = isset( $instance['title'] ) ? $instance['title'] : __( 'My Profile', 'wpforo' );
132 $title_guest = isset( $instance['title_guest'] ) ? $instance['title_guest'] : __( 'Join Us!', 'wpforo' );
133 $hide_avatar = isset( $instance['hide_avatar'] ) && $instance['hide_avatar'];
134 $hide_name = isset( $instance['hide_name'] ) && $instance['hide_name'];
135 $hide_notification = isset( $instance['hide_notification'] ) && $instance['hide_notification'];
136 $hide_data = isset( $instance['hide_data'] ) && $instance['hide_data'];
137 $hide_buttons = isset( $instance['hide_buttons'] ) && $instance['hide_buttons'];
138 $hide_for_guests = isset( $instance['hide_for_guests'] ) && $instance['hide_for_guests'];
139 ?>
140 <p>
141 <label><?php _e( 'Title for Users', 'wpforo' ); ?>:</label>
142 <label>
143 <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
144 value="<?php echo esc_attr( $title ); ?>">
145 </label>
146 </p>
147 <p>
148 <label><?php _e( 'Title for Guests', 'wpforo' ); ?>:</label>
149 <label>
150 <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title_guest' ) ); ?>" type="text"
151 value="<?php echo esc_attr( $title_guest ); ?>">
152 </label>
153 </p>
154 <p>
155 <label for="<?php echo $this->get_field_id( 'hide_avatar' ) ?>"><?php _e( 'Hide avatar', 'wpforo' ); ?>
156 &nbsp;</label>
157 <input id="<?php echo $this->get_field_id( 'hide_avatar' ) ?>" class="wpf_wdg_hide_avatar"
158 name="<?php echo esc_attr( $this->get_field_name( 'hide_avatar' ) ); ?>" <?php checked( $hide_avatar ); ?>
159 type="checkbox">
160 </p>
161 <p>
162 <label for="<?php echo $this->get_field_id( 'hide_name' ) ?>"><?php _e( 'Hide user name', 'wpforo' ); ?>
163 &nbsp;</label>
164 <input id="<?php echo $this->get_field_id( 'hide_name' ) ?>" class="wpf_wdg_hide_name"
165 name="<?php echo esc_attr( $this->get_field_name( 'hide_name' ) ); ?>" <?php checked( $hide_name ); ?>
166 type="checkbox">
167 </p>
168 <p>
169 <label for="<?php echo $this->get_field_id( 'hide_notification' ) ?>"><?php _e( 'Hide notification bell', 'wpforo' ); ?>
170 &nbsp;</label>
171 <input id="<?php echo $this->get_field_id( 'hide_notification' ) ?>" class="wpf_wdg_hide_notification"
172 name="<?php echo esc_attr( $this->get_field_name( 'hide_notification' ) ); ?>" <?php checked( $hide_notification ); ?>
173 type="checkbox">
174 </p>
175 <p>
176 <label for="<?php echo $this->get_field_id( 'hide_data' ) ?>"><?php _e( 'Hide user data', 'wpforo' ); ?>
177 &nbsp;</label>
178 <input id="<?php echo $this->get_field_id( 'hide_data' ) ?>" class="wpf_wdg_hide_data"
179 name="<?php echo esc_attr( $this->get_field_name( 'hide_data' ) ); ?>" <?php checked( $hide_data ); ?>
180 type="checkbox">
181 </p>
182 <p>
183 <label for="<?php echo $this->get_field_id( 'hide_buttons' ) ?>"><?php _e( 'Hide buttons', 'wpforo' ); ?>
184 &nbsp;</label>
185 <input id="<?php echo $this->get_field_id( 'hide_buttons' ) ?>" class="wpf_wdg_hide_buttons"
186 name="<?php echo esc_attr( $this->get_field_name( 'hide_buttons' ) ); ?>" <?php checked( $hide_buttons ); ?>
187 type="checkbox">
188 </p>
189 <p>
190 <label for="<?php echo $this->get_field_id( 'hide_for_guests' ) ?>"><?php _e( 'Hide this widget for guests', 'wpforo' ); ?>
191 &nbsp;</label>
192 <input id="<?php echo $this->get_field_id( 'hide_for_guests' ) ?>" class="wpf_wdg_hide_for_guests"
193 name="<?php echo esc_attr( $this->get_field_name( 'hide_for_guests' ) ); ?>" <?php checked( $hide_for_guests ); ?>
194 type="checkbox">
195 </p>
196 <?php
197 }
198
199 public function update( $new_instance, $old_instance ) {
200 $instance = [];
201 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( (string) $new_instance['title'] ) : '';
202 $instance['title_guest'] = ( ! empty( $new_instance['title_guest'] ) ) ? strip_tags( (string) $new_instance['title_guest'] ) : '';
203 $instance['hide_avatar'] = isset( $new_instance['hide_avatar'] ) ? (bool) $new_instance['hide_avatar'] : $this->default_instance['hide_avatar'];
204 $instance['hide_name'] = isset( $new_instance['hide_name'] ) ? (bool) $new_instance['hide_name'] : $this->default_instance['hide_name'];
205 $instance['hide_notification'] = isset( $new_instance['hide_notification'] ) ? (bool) $new_instance['hide_notification'] : $this->default_instance['hide_notification'];
206 $instance['hide_data'] = isset( $new_instance['hide_data'] ) ? (bool) $new_instance['hide_data'] : $this->default_instance['hide_data'];
207 $instance['hide_buttons'] = isset( $new_instance['hide_buttons'] ) ? (bool) $new_instance['hide_buttons'] : $this->default_instance['hide_buttons'];
208 $instance['hide_for_guests'] = isset( $new_instance['hide_for_guests'] ) ? (bool) $new_instance['hide_for_guests'] : $this->default_instance['hide_for_guests'];
209
210 return $instance;
211 }
212 }
213