PluginProbe
wpForo Forum / 2.2.9
wpForo Forum v2.2.9
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 2.2.9, at widgets/Profile.php

201 lines 10.9 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 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( $member['rating']['title'] ) . '</span>' : ''; ?>
80 <?php wpforo_member_badge( $member ); ?>
81 </div>
82 <?php wpforo_member_title( $member, true, '', '', [ 'rating-title' ] ); ?>
83 </div>
84 <?php do_action( 'wpforo_wiget_profile_content_after', $member ); ?>
85 </div>
86 <?php endif; ?>
87 <?php endif; ?>
88 <div class="wpf-prof-footer">
89 <?php do_action( 'wpforo_wiget_profile_footer_before', $member ); ?>
90 <?php if( is_user_logged_in() ): ?>
91 <?php if( ! wpfval( $instance, 'hide_buttons' ) ): ?>
92 <div class="wpf-prof-buttons">
93 <?php WPF()->tpl->member_buttons( $member, get_called_class() ) ?>
94 <?php if( ! wpforo_is_bot() ) : ?>
95 <a href="<?php echo wpforo_logout_url() ?>" class="wpf-logout"
96 title="<?php wpforo_phrase( 'Logout' ) ?>"><i
97 class="fas fa-sign-out-alt"></i></a>
98 <?php endif ?>
99 </div>
100 <?php endif; ?>
101 <?php elseif( ! wpforo_is_bot() ): ?>
102 <div class="wpf-prof-loginout">
103 <a href="<?php echo wpforo_login_url(); ?>" class="wpf-button"><i
104 class="fas fa-sign-in-alt"></i> <?php wpforo_phrase( 'Login' ) ?></a> &nbsp;
105 <a href="<?php echo wpforo_register_url(); ?>" class="wpf-button"><i
106 class="fas fa-user-plus"></i> <?php wpforo_phrase( 'Register' ) ?></a>
107 </div>
108 <?php endif; ?>
109 <?php do_action( 'wpforo_wiget_profile_footer_after', $member ); ?>
110 </div>
111 </div>
112 <?php
113 echo '</div></div>';
114 echo $args['after_widget'];
115 }
116 }
117
118 public function form( $instance ) {
119 $title = isset( $instance['title'] ) ? $instance['title'] : __( 'My Profile', 'wpforo' );
120 $title_guest = isset( $instance['title_guest'] ) ? $instance['title_guest'] : __( 'Join Us!', 'wpforo' );
121 $hide_avatar = isset( $instance['hide_avatar'] ) && $instance['hide_avatar'];
122 $hide_name = isset( $instance['hide_name'] ) && $instance['hide_name'];
123 $hide_notification = isset( $instance['hide_notification'] ) && $instance['hide_notification'];
124 $hide_data = isset( $instance['hide_data'] ) && $instance['hide_data'];
125 $hide_buttons = isset( $instance['hide_buttons'] ) && $instance['hide_buttons'];
126 $hide_for_guests = isset( $instance['hide_for_guests'] ) && $instance['hide_for_guests'];
127 ?>
128 <p>
129 <label><?php _e( 'Title for Users', 'wpforo' ); ?>:</label>
130 <label>
131 <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
132 value="<?php echo esc_attr( $title ); ?>">
133 </label>
134 </p>
135 <p>
136 <label><?php _e( 'Title for Guests', 'wpforo' ); ?>:</label>
137 <label>
138 <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title_guest' ) ); ?>" type="text"
139 value="<?php echo esc_attr( $title_guest ); ?>">
140 </label>
141 </p>
142 <p>
143 <label for="<?php echo $this->get_field_id( 'hide_avatar' ) ?>"><?php _e( 'Hide avatar', 'wpforo' ); ?>
144 &nbsp;</label>
145 <input id="<?php echo $this->get_field_id( 'hide_avatar' ) ?>" class="wpf_wdg_hide_avatar"
146 name="<?php echo esc_attr( $this->get_field_name( 'hide_avatar' ) ); ?>" <?php checked( $hide_avatar ); ?>
147 type="checkbox">
148 </p>
149 <p>
150 <label for="<?php echo $this->get_field_id( 'hide_name' ) ?>"><?php _e( 'Hide user name', 'wpforo' ); ?>
151 &nbsp;</label>
152 <input id="<?php echo $this->get_field_id( 'hide_name' ) ?>" class="wpf_wdg_hide_name"
153 name="<?php echo esc_attr( $this->get_field_name( 'hide_name' ) ); ?>" <?php checked( $hide_name ); ?>
154 type="checkbox">
155 </p>
156 <p>
157 <label for="<?php echo $this->get_field_id( 'hide_notification' ) ?>"><?php _e( 'Hide notification bell', 'wpforo' ); ?>
158 &nbsp;</label>
159 <input id="<?php echo $this->get_field_id( 'hide_notification' ) ?>" class="wpf_wdg_hide_notification"
160 name="<?php echo esc_attr( $this->get_field_name( 'hide_notification' ) ); ?>" <?php checked( $hide_notification ); ?>
161 type="checkbox">
162 </p>
163 <p>
164 <label for="<?php echo $this->get_field_id( 'hide_data' ) ?>"><?php _e( 'Hide user data', 'wpforo' ); ?>
165 &nbsp;</label>
166 <input id="<?php echo $this->get_field_id( 'hide_data' ) ?>" class="wpf_wdg_hide_data"
167 name="<?php echo esc_attr( $this->get_field_name( 'hide_data' ) ); ?>" <?php checked( $hide_data ); ?>
168 type="checkbox">
169 </p>
170 <p>
171 <label for="<?php echo $this->get_field_id( 'hide_buttons' ) ?>"><?php _e( 'Hide buttons', 'wpforo' ); ?>
172 &nbsp;</label>
173 <input id="<?php echo $this->get_field_id( 'hide_buttons' ) ?>" class="wpf_wdg_hide_buttons"
174 name="<?php echo esc_attr( $this->get_field_name( 'hide_buttons' ) ); ?>" <?php checked( $hide_buttons ); ?>
175 type="checkbox">
176 </p>
177 <p>
178 <label for="<?php echo $this->get_field_id( 'hide_for_guests' ) ?>"><?php _e( 'Hide this widget for guests', 'wpforo' ); ?>
179 &nbsp;</label>
180 <input id="<?php echo $this->get_field_id( 'hide_for_guests' ) ?>" class="wpf_wdg_hide_for_guests"
181 name="<?php echo esc_attr( $this->get_field_name( 'hide_for_guests' ) ); ?>" <?php checked( $hide_for_guests ); ?>
182 type="checkbox">
183 </p>
184 <?php
185 }
186
187 public function update( $new_instance, $old_instance ) {
188 $instance = [];
189 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( (string) $new_instance['title'] ) : '';
190 $instance['title_guest'] = ( ! empty( $new_instance['title_guest'] ) ) ? strip_tags( (string) $new_instance['title_guest'] ) : '';
191 $instance['hide_avatar'] = isset( $new_instance['hide_avatar'] ) ? (bool) $new_instance['hide_avatar'] : $this->default_instance['hide_avatar'];
192 $instance['hide_name'] = isset( $new_instance['hide_name'] ) ? (bool) $new_instance['hide_name'] : $this->default_instance['hide_name'];
193 $instance['hide_notification'] = isset( $new_instance['hide_notification'] ) ? (bool) $new_instance['hide_notification'] : $this->default_instance['hide_notification'];
194 $instance['hide_data'] = isset( $new_instance['hide_data'] ) ? (bool) $new_instance['hide_data'] : $this->default_instance['hide_data'];
195 $instance['hide_buttons'] = isset( $new_instance['hide_buttons'] ) ? (bool) $new_instance['hide_buttons'] : $this->default_instance['hide_buttons'];
196 $instance['hide_for_guests'] = isset( $new_instance['hide_for_guests'] ) ? (bool) $new_instance['hide_for_guests'] : $this->default_instance['hide_for_guests'];
197
198 return $instance;
199 }
200 }
201