PluginProbe
wpForo Forum / 1.1.1
wpForo Forum v1.1.1
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 / wpf-includes / class-members.php

class-members.php in wpForo Forum 1.1.1, at wpf-includes/class-members.php

1,136 lines 44.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 class wpForoMember{
7
8 private $wpforo;
9 private static $cache = array();
10
11 function __construct( $wpForo ){
12 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
13 add_action('delete_user_form', array(&$this, 'show_delete_form'), 10, 2);
14 }
15
16 public function send_new_user_notifications($user_id, $notify = 'admin'){
17 wp_send_new_user_notifications( $user_id, $notify );
18 }
19
20 private function add_profile($args){
21 if(empty($args)) return FALSE;
22 if(!isset($args['userid']) || !$args['userid'] || !isset($args['username']) || !$args['username'] ) return FALSE;
23 extract( $args, EXTR_OVERWRITE );
24 $this->reset($userid);
25 return $this->wpforo->db->insert(
26 $this->wpforo->db->prefix . 'wpforo_profiles',
27 array( 'userid' => intval($userid),
28 'username' => sanitize_user($username),
29 'groupid' => intval((isset($groupid) && $groupid ? $groupid : $this->wpforo->default_groupid)),
30 'site' => (isset($site) ? sanitize_text_field($site) : '' ),
31 'timezone' => ( isset($timezone) ? sanitize_text_field($timezone) : 'UTC+0' ),
32 'about' => ( isset($about) ? stripslashes( wpforo_kses(trim($about), 'user_description') ) : '' ),
33 'last_login' => ( isset($last_login) ? $last_login : current_time('mysql', 1) ) ),
34 array( '%d', '%s', '%d', '%s', '%s', '%s', '%s' )
35 );
36 }
37
38 function edit_profile($args){
39 if(empty($args)) return FALSE;
40 if( !isset($args['userid']) || !$args['userid'] ) return FALSE;
41 extract( $args, EXTR_OVERWRITE );
42
43 $fields = array();
44 $fields_types = array();
45
46 if(isset($last_login) && $last_login){
47 $fields['last_login'] = sanitize_text_field($last_login);
48 $fields_types[] = '%s';
49 }
50
51 if(isset($groupid) && $groupid){
52 if( $this->wpforo->current_user_groupid == 1 || current_user_can('administrator') ){
53 $fields['groupid'] = intval($groupid);
54 $fields_types[] = '%d';
55 }
56 }
57
58 if(isset($title) && $title){
59 $fields['title'] = sanitize_text_field(trim($title));
60 $fields_types[] = '%s';
61 }
62 if(isset($site)){
63 $fields['site'] = sanitize_text_field(trim($site));
64 $fields_types[] = '%s';
65 }
66 if(isset($icq)){
67 $fields['icq'] = sanitize_text_field(trim($icq));
68 $fields_types[] = '%s';
69 }
70 if(isset($aim)){
71 $fields['aim'] = sanitize_text_field(trim($aim));
72 $fields_types[] = '%s';
73 }
74 if(isset($yahoo)){
75 $fields['yahoo'] = sanitize_text_field(trim($yahoo));
76 $fields_types[] = '%s';
77 }
78 if(isset($msn)){
79 $fields['msn'] = sanitize_text_field(trim($msn));
80 $fields_types[] = '%s';
81 }
82 if(isset($facebook)){
83 $fields['facebook'] = sanitize_text_field(trim($facebook));
84 $fields_types[] = '%s';
85 }
86 if(isset($twitter)){
87 $fields['twitter'] = sanitize_text_field(trim($twitter));
88 $fields_types[] = '%s';
89 }
90 if(isset($gtalk)){
91 $fields['gtalk'] = sanitize_text_field(trim($gtalk));
92 $fields_types[] = '%s';
93 }
94 if(isset($skype)){
95 $fields['skype'] = sanitize_text_field(trim($skype));
96 $fields_types[] = '%s';
97 }
98 if(isset($signature)){
99 $fields['signature'] = stripslashes(wpforo_kses(trim($signature), 'user_description'));
100 $fields_types[] = '%s';
101 }
102 if(isset($about)){
103 $fields['about'] = stripslashes(wpforo_kses(trim($about), 'user_description'));
104 $fields_types[] = '%s';
105 }
106 if(isset($occupation)){
107 $fields['occupation'] = stripslashes(sanitize_text_field(trim($occupation)));
108 $fields_types[] = '%s';
109 }
110 if(isset($location)){
111 $fields['location'] = stripslashes(sanitize_text_field(trim($location)));
112 $fields_types[] = '%s';
113 }
114 if(isset($timezone)){
115 $fields['timezone'] = sanitize_text_field(trim($timezone));
116 $fields_types[] = '%s';
117 }
118 if(isset($avatar_type) && $avatar_type != 'gravatar' && isset($avatar_url) && $avatar_url){
119 $fields['avatar'] = esc_url(trim($avatar_url));
120 $fields_types[] = '%s';
121 }
122 if(isset($avatar_type) && $avatar_type == 'gravatar'){
123 $fields['avatar'] = '';
124 $fields_types[] = '%s';
125 }
126
127 $this->reset($userid);
128
129 return $this->wpforo->db->update(
130 $this->wpforo->db->prefix.'wpforo_profiles',
131 $fields,
132 array('userid' => intval($userid)),
133 $fields_types,
134 array('%d')
135 );
136 }
137
138 function create($args){
139 if(!wpforo_feature('user-register', $this->wpforo)){
140 $this->wpforo->notice->add('User registration is disabled.', 'error');
141 return FALSE;
142 }
143 if( !empty($args) && is_array($args) && !empty($args['user_pass1']) ){
144 remove_action('register_new_user', 'wp_send_new_user_notifications');
145 add_action('register_new_user', array($this, 'send_new_user_notifications'));
146
147 $errors = new WP_Error();
148
149 extract($args, EXTR_OVERWRITE);
150 $sanitized_user_login = sanitize_user( $user_login );
151 $user_email = apply_filters( 'user_registration_email', $user_email );
152 $user_pass1 = trim(substr($user_pass1, 0, 100));
153 $user_pass2 = trim(substr($user_pass2, 0, 100));
154 $illegal_user_logins = array_map( 'strtolower', (array) apply_filters( 'illegal_user_logins', array() ) );
155 if ( $sanitized_user_login == '' ) {
156 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );
157 $this->wpforo->notice->add('Username is missed.', 'error');
158 return FALSE;
159 }elseif ( ! validate_username( $user_login ) ) {
160 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
161 $sanitized_user_login = '';
162 $this->wpforo->notice->add('Illegal character in username.', 'error');
163 $user_login = '';
164 return FALSE;
165 }elseif( strlen($user_login) < 3 || strlen($user_login) > 15 ){
166 $this->wpforo->notice->add('Username length must be between 3 characters and 15 characters.', 'error');
167 return FALSE;
168 }elseif ( username_exists( $sanitized_user_login ) ) {
169 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );
170 $this->wpforo->notice->add('Username exists. Please insert another.', 'error');
171 return FALSE;
172 }elseif ( in_array( strtolower( $sanitized_user_login ), $illegal_user_logins ) ) {
173 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) );
174 $this->wpforo->notice->add('ERROR: invalid_username. Sorry, that username is not allowed. Please insert another.', 'error');
175 return FALSE;
176 }elseif ( $user_email == '' ) {
177 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) );
178 $this->wpforo->notice->add('Insert your Email address.', 'error');
179 return FALSE;
180 }elseif ( ! is_email( $user_email ) ) {
181 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ) );
182 $this->wpforo->notice->add('Invalid Email address', 'error');
183 $user_email = '';
184 return FALSE;
185 }elseif ( email_exists( $user_email ) ) {
186 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
187 $this->wpforo->notice->add('Email address exists. Please insert another.', 'error');
188 return FALSE;
189 }elseif( strlen($user_pass1) < 6 || strlen($user_pass1) > 20 ){
190 $this->wpforo->notice->add('Password length must be between 6 characters and 20 characters.', 'error');
191 return FALSE;
192 }elseif($user_pass1 != $user_pass2){
193 $this->wpforo->notice->add('Password mismatch.', 'error');
194 return FALSE;
195 }else{
196 do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
197 $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
198 if ( $errors->get_error_code() ){
199 $args = array();
200 foreach($errors->errors as $u_err) $args[] = $u_err[0];
201 $this->wpforo->notice->add($args, 'error');
202 return FALSE;
203 }
204 $user_id = wp_create_user( $sanitized_user_login, $user_pass1, $user_email );
205 if ( !is_wp_error( $user_id ) && $user_id ) {
206 $creds = array('user_login' => $sanitized_user_login, 'user_password' => $user_pass1 );
207 wp_signon($creds);
208 $this->wpforo->notice->add('Success! Thank you Dear Friend', 'success');
209 do_action( 'register_new_user', $user_id );
210 return $user_id;
211 }
212 }
213 }elseif( !empty($args['user_login']) && !empty($args['user_email']) ){
214 $user_id = register_new_user( $args['user_login'], $args['user_email'] );
215 if ( !is_wp_error( $user_id ) && $user_id ) {
216 $this->wpforo->notice->add('Success! Please check your mail for confirmation.', 'success');
217 return $user_id;
218 }
219 }
220 if(!empty($user_id->errors)){
221 $args = array();
222 foreach($user_id->errors as $u_err) $args[] = $u_err[0];
223 $this->wpforo->notice->add($args, 'error');
224 return FALSE;
225 }
226 $this->wpforo->notice->add('Registration Error', 'error');
227 return FALSE;
228 }
229
230 function edit( $args = array() ){
231 if( empty($args) && empty($_REQUEST['member']) ) return FALSE;
232 if( empty($args) && !empty($_REQUEST['member']) ) $args = $_REQUEST['member'];
233 extract($args, EXTR_OVERWRITE);
234
235 if( isset($userid) && isset($display_name) && isset($user_email) && isset($user_nickname) ){
236 $userid = intval($userid);
237 $user_email = sanitize_email($user_email);
238 if ( ! is_email( $user_email ) ) {
239 $this->wpforo->notice->add('Invalid Email address', 'error');
240 $user_email = '';
241 return FALSE;
242 }elseif ( ( $owner_id = email_exists( $user_email ) ) && ( $owner_id != $userid ) ) {
243 $this->wpforo->notice->add('This email address is already registered. Please insert another.', 'error');
244 return FALSE;
245 }
246
247 $user_nickname = sanitize_title($user_nickname);
248 if( is_numeric($user_nickname) ){
249 $this->wpforo->notice->add('Numerical nicknames are not allowed. Please insert another.', 'error');
250 return FALSE;
251 }
252 $sql = "SELECT `ID` FROM `".$this->wpforo->db->base_prefix."users` WHERE `ID` != ". intval($userid) ." AND ( `user_nicename` LIKE '".esc_sql($user_nickname)."' OR `ID` LIKE '".esc_sql($user_nickname)."' )";
253 if( $this->wpforo->db->get_var($sql)){
254 $this->wpforo->notice->add('This nickname is already registered. Please insert another.', 'error');
255 return FALSE;
256 }
257
258 if ( !is_user_logged_in() || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, $userid ) ) {
259 $this->wpforo->notice->add('Permission denied', 'error');
260 return FALSE;
261 }
262
263 if( $display_name && $user_email && $user_nickname ){
264 $this->wpforo->db->update(
265 $this->wpforo->db->base_prefix."users",
266 array(
267 'display_name' => sanitize_text_field($display_name),
268 'user_nicename' => sanitize_title($user_nickname),
269 'user_email' => sanitize_email($user_email)
270 ),
271 array('ID' => $userid),
272 array('%s','%s','%s'),
273 array('%d')
274 );
275 $this->wpforo->db->update(
276 $this->wpforo->db->base_prefix."usermeta",
277 array('meta_value' => sanitize_title($user_nickname)),
278 array('user_id' => $userid, 'meta_key' => 'nickname'),
279 array('%s'),
280 array('%d', '%s')
281 );
282 $this->reset($userid);
283 }
284
285 if( FALSE !== $this->edit_profile($args) ){
286 $this->wpforo->notice->add('Your profile data have been successfully updated.', 'success');
287 return $userid;
288 }
289 }
290
291 $this->wpforo->notice->add('Something wrong with profile data.', 'error');
292 return FALSE;
293 }
294
295 function upload_avatar(){
296 if( !isset($_POST['member']['userid']) || !$userid = intval($_POST['member']['userid']) ) return;
297 if( !$user = $this->get_member($userid) ) return;
298 $username = urldecode($user['user_nicename']);
299 if(isset($_FILES['avatar']) && !empty($_FILES['avatar']) && isset($_FILES['avatar']['name']) && $_FILES['avatar']['name']){
300
301 $name = sanitize_file_name($_FILES['avatar']['name']); //myimg.png
302 $type = sanitize_mime_type($_FILES['avatar']['type']); //image/png
303 $tmp_name = sanitize_text_field($_FILES['avatar']['tmp_name']); //D:\wamp\tmp\php986B.tmp
304 $error = sanitize_text_field($_FILES['avatar']['error']); //0
305 $size = intval($_FILES['avatar']['size']); //6112
306
307 if( $error ){
308 $error = wpforo_file_upload_error($error);
309 $this->wpforo->notice->clear();
310 $this->wpforo->notice->add($error, 'error');
311 return FALSE;
312 }
313
314 $upload_dir = wp_upload_dir();
315 $uplds_dir = $upload_dir['basedir']."/wpforo";
316 $avatar_dir = $upload_dir['basedir']."/wpforo/avatars";
317 if(!is_dir($uplds_dir)) wp_mkdir_p($uplds_dir);
318 if(!is_dir($avatar_dir)) wp_mkdir_p($avatar_dir);
319
320 $ext = pathinfo($name, PATHINFO_EXTENSION);
321 if( !wpforo_is_image($ext) ){
322 $this->wpforo->notice->clear();
323 $this->wpforo->notice->add('Incorrect file format. Allowed formats: jpeg, jpg, png, gif.', 'error');
324 return FALSE;
325 }
326
327 $fnm = pathinfo($username, PATHINFO_FILENAME);
328 $fnm = str_replace(' ', '-', $fnm);
329 while(strpos($fnm, '--') !== FALSE) $fnm = str_replace('--', '-', $fnm);
330 $fnm = preg_replace("/[^-a-zA-Z0-9]/", "", $fnm);
331 $fnm = trim($fnm, "-");
332
333 $avatar_fname = $fnm.( $fnm ? '_' : '' ).$userid.".".$ext;
334 $avatar_path = $avatar_dir."/".$avatar_fname;
335
336 if(is_dir($avatar_dir)){
337 if(move_uploaded_file($tmp_name, $avatar_path)) {
338 $image = wp_get_image_editor( $avatar_path );
339 if ( ! is_wp_error( $image ) ) {
340 $image->resize( 150, 150, true );
341 $image->save( $avatar_path );
342 }
343 $blog_url = preg_replace('|^https?\:|is', '', $upload_dir['baseurl']);
344 $this->wpforo->db->update($this->wpforo->db->prefix.'wpforo_profiles', array('avatar' => $blog_url . "/wpforo/avatars/" . $avatar_fname), array('userid' => intval($userid)), array('%s'), array('%d'));
345 $this->reset($userid);
346 }
347 }
348 }
349 }
350
351 function synchronize_user($userid){
352 if(!$userid) return FALSE;
353 if( $user = get_userdata($userid) ){
354 if( is_super_admin( $userid ) || in_array('administrator', $user->roles) ){
355 $groupid = 1;
356 }elseif( in_array('editor', $user->roles) ){
357 $groupid = 2;
358 }elseif( in_array('customer', $user->roles) ){
359 $groupid = 5;
360 }else{
361 $groupid = $this->wpforo->default_groupid;
362 }
363 $insert_groupid = (isset($_POST['wpforo_usergroup'])) ? intval($_POST['wpforo_usergroup']) : $groupid;
364 $insert_timezone = (isset($_POST['wpforo_usertimezone'])) ? sanitize_text_field($_POST['wpforo_usertimezone']) : '';
365 $about = get_user_meta( $userid, 'description', true );
366 return $this->add_profile(
367 array( 'userid' => intval($userid),
368 'username' => sanitize_user($user->user_login),
369 'groupid' => intval($insert_groupid),
370 'site' => esc_url($user->user_url),
371 'timezone' => sanitize_text_field($insert_timezone),
372 'about' => stripslashes( wpforo_kses(trim($about), 'user_description') ),
373 'last_login' => sanitize_text_field($user->user_registered) ) );
374 }
375 return FALSE;
376 }
377
378 function synchronize_users(){
379 $sql = "SELECT `ID` FROM `".$this->wpforo->db->base_prefix."users` WHERE `ID` NOT IN( SELECT `userid` FROM `".$this->wpforo->db->prefix."wpforo_profiles` )";
380 $userids = $this->wpforo->db->get_col($sql);
381 if( !empty($userids) ){
382 foreach($userids as $userid){
383 $this->synchronize_user($userid);
384 }
385 }
386 }
387
388 function get_member($args = array(), $cache = false){
389
390 if(is_array($args)){
391
392 $default = array(
393 'userid' => NULL, // userid
394 'username' => '' // username
395 );
396
397 }else{
398
399 $default = array(
400 'userid' => $args, // userid
401 'username' => '' // username
402 );
403
404 }
405
406 $args = wpforo_parse_args( $args, $default );
407
408 if(isset($args['userid'])){
409 if( $cache && isset(self::$cache['user'][$args['userid']]) ){
410 return self::$cache['user'][$args['userid']];
411 }
412 }
413
414 $user_meta_obj = true;
415
416 if(!empty($args)){
417
418 extract($args, EXTR_OVERWRITE);
419
420 $do_db_cache = wpforo_feature('member_cashe', $this->wpforo);
421
422 $userid = intval($userid);
423 $username = sanitize_user($username);
424
425 if( $do_db_cache ){
426 if( $username ){
427 $user_obj = get_user_by( 'user_nicename', $username );
428 if(!empty($user_obj)) $userid = $user_obj->ID;
429 $member = get_user_meta( $userid, '_wpf_member_obj', true );
430 }elseif( $userid ){
431 $member = get_user_meta( $userid, '_wpf_member_obj', true );
432 }else{
433 $user_meta_obj = true;
434 }
435 }else{
436 $member = array();
437 }
438
439 if(empty($member)){
440 $user_meta_obj = false;
441 $sql = "SELECT *, ug.name AS groupname FROM `".$this->wpforo->db->base_prefix."users` u
442 LEFT JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`
443 LEFT JOIN `".$this->wpforo->db->prefix."wpforo_usergroups` ug ON ug.`groupid` = p.`groupid`";
444 $wheres = array();
445 if($userid) $wheres[] = "`ID` = " . intval($userid);
446 if($username) $wheres[] = "`user_nicename` = '" . esc_sql($username) . "'";
447 if( !empty($wheres) ) $sql .= " WHERE " . implode($wheres, " AND ");
448 $member = $this->wpforo->db->get_row($sql, ARRAY_A);
449 }
450
451 if(!empty($member)) {
452 if( $do_db_cache ){
453 if(!$user_meta_obj) {
454 $member['profile_url'] = $this->profile_url( $member );
455 $member['stat'] = $this->get_stat( $member, false, true );
456 update_user_meta( $userid, '_wpf_member_obj', $member );
457 }
458 }else{
459 $member['profile_url'] = $this->profile_url( $member );
460 $member['stat'] = $this->get_stat( $member, false, true );
461 }
462 }
463
464 if($cache && isset($userid)){
465 return self::$cache['user'][$userid] = $member;
466 }else{
467 return $member;
468 }
469 }
470 }
471
472 function get_members($args = array(), &$items_count = 0){
473
474 $default = array(
475 'include' => array(), // array( 2, 10, 25 )
476 'exclude' => array(), // array( 2, 10, 25 )
477 'status' => array('active', 'banned'), // 'active', 'blocked', 'trashed', 'spamer'
478 'groupid' => NULL, // groupid
479 'orderby' => 'userid', //
480 'order' => 'ASC', // ASC DESC
481 'offset' => 0, // OFFSET
482 'row_count' => NULL // ROW COUNT
483 );
484
485 $args = wpforo_parse_args( $args, $default );
486 if(!empty($args)){
487 extract($args, EXTR_OVERWRITE);
488
489 $include = wpforo_parse_args( $include );
490 $exclude = wpforo_parse_args( $exclude );
491
492 $sql = "SELECT *, ug.name AS groupname FROM `".$this->wpforo->db->base_prefix."users` u
493 LEFT JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`
494 LEFT JOIN `".$this->wpforo->db->prefix."wpforo_usergroups` ug ON ug.`groupid` = p.`groupid`";
495 $wheres = array();
496 if(!empty($include)) $wheres[] = "u.`ID` IN(" . implode(', ', array_map('intval', $include)) . ")";
497 if(!empty($exclude)) $wheres[] = "u.`ID` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
498 if(!empty($status)) $wheres[] = " p.`status` IN('" . implode("','", array_map('esc_sql', array_map('sanitize_text_field', $status)) ) . "')";
499 if($groupid != NULL) $wheres[] = "p.`groupid` = " . intval($groupid);
500
501 if(!empty($wheres)) $sql .= " WHERE " . implode($wheres, " AND ");
502
503 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
504 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
505
506 if( $orderby == 'groupid' ) $orderby = 'p.`groupid`';
507 $sql .= esc_sql(" ORDER BY $orderby " . $order);
508 if($row_count) $sql .= esc_sql(" LIMIT $offset,$row_count");
509
510 return $this->wpforo->db->get_results($sql, ARRAY_A);
511 }
512 }
513
514 function search($needle, $fields = array()){
515
516 if($needle != ''){
517 $needle = sanitize_text_field($needle);
518 if(empty($fields)){
519 $fields = array(
520 'title',
521 'user_nicename',
522 'user_email',
523 'signature'
524 );
525 }
526
527 $sql = "SELECT `ID` FROM `".$this->wpforo->db->base_prefix."users` u LEFT JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`";
528 $wheres = array();
529
530 foreach($fields as $field){
531 $field = sanitize_text_field($field);
532 $wheres[] = "`".esc_sql($field)."` LIKE '%" . esc_sql($needle) ."%'";
533 }
534
535 if(!empty($wheres)){
536 $sql .= " WHERE " . implode($wheres, " OR ");
537 $results = $this->wpforo->db->get_results($sql, ARRAY_A);
538 $userids = array();
539 foreach($results as $result){
540 $userids[] = $result['ID'];
541 }
542 return $userids;
543 }else{
544 return array();
545 }
546 }else{
547 return array();
548 }
549
550 }
551
552 function ban($userid){
553 if( $userid == $this->wpforo->current_userid ){
554 $this->wpforo->notice->add('You can\'t make yourself banned user', 'error');
555 return FALSE;
556 }
557 if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid , 'bm' ) || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, intval( $userid ) )){
558 $this->wpforo->notice->add('Permission denied for this action', 'error');
559 return FALSE;
560 }
561 if( FALSE !== $this->wpforo->db->update(
562 $this->wpforo->db->prefix.'wpforo_profiles',
563 array('status' => 'banned'),
564 array('userid' => intval( $userid )),
565 array('%s'),
566 array('%d')
567 )
568 ){
569 $this->reset($userid);
570 $this->wpforo->notice->add('User successfully banned from wpforo', 'success');
571 return TRUE;
572 }
573
574 $this->wpforo->notice->add('User ban action error', 'error');
575 return FALSE;
576 }
577
578 function unban($userid){
579 if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid , 'bm' ) || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, intval( $userid ) )){
580 $this->wpforo->notice->add('Permission denied for this action', 'error');
581 return FALSE;
582 }
583 if( FALSE !== $this->wpforo->db->update(
584 $this->wpforo->db->prefix.'wpforo_profiles',
585 array('status' => 'active'),
586 array('userid' => intval( $userid )),
587 array('%s'),
588 array('%d')
589 )
590 ){
591 $this->reset($userid);
592 $this->wpforo->notice->add('User successfully unbanned from wpforo', 'success');
593 return TRUE;
594 }
595
596 $this->wpforo->notice->add('User unban action error', 'error');
597 return FALSE;
598 }
599
600 /**
601 *
602 * @param int $userid
603 * @param int $reassign
604 *
605 * @return bool true | false if user successfully deleted
606 */
607 public function delete( $userid, $reassign = NULL ){
608 if( !($userid = intval($userid)) ) return FALSE;
609 if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid , 'dm' ) || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, intval( $userid ) )){
610 $this->wpforo->notice->add('Permission denied for this action', 'error');
611 return FALSE;
612 }
613
614 if( !($reassign = intval($reassign)) ){
615 if( $postids = $this->wpforo->db->get_col( $this->wpforo->db->prepare( "SELECT postid FROM {$this->wpforo->db->prefix}wpforo_posts WHERE userid = %d", $userid ) ) ){
616 foreach( $postids as $postid ) $this->wpforo->post->delete($postid);
617 }
618
619 if( $topicids = $this->wpforo->db->get_col( $this->wpforo->db->prepare( "SELECT topicid FROM {$this->wpforo->db->prefix}wpforo_topics WHERE userid = %d", $userid ) ) ){
620 foreach( $topicids as $topicid ) $this->wpforo->topic->delete($topicid);
621 }
622 }else{
623 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_topics", array('userid' => $reassign), array('userid' => $userid) );
624 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_posts", array('userid' => $reassign), array('userid' => $userid) );
625 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_likes", array('post_userid' => $reassign), array('post_userid' => $userid) );
626 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_votes", array('post_userid' => $reassign), array('post_userid' => $userid) );
627 if( $user_stats = $this->wpforo->db->get_row(
628 $this->wpforo->db->prepare( "SELECT
629 SUM(`posts`) AS posts,
630 SUM(`questions`) AS questions,
631 SUM(`answers`) AS answers,
632 SUM(`comments`) AS comments
633 FROM {$this->wpforo->db->prefix}wpforo_profiles
634 WHERE userid IN( %d , %d )", $userid, $reassign
635 ),
636 ARRAY_A
637 )
638 ){
639 $this->wpforo->db->update(
640 $this->wpforo->db->prefix.'wpforo_profiles',
641 array(
642 'posts' => $user_stats['posts'],
643 'questions' => $user_stats['questions'],
644 'answers' => $user_stats['answers'],
645 'comments' => $user_stats['comments']
646 ),
647 array('userid' => $reassign),
648 array('%d','%d','%d','%d'),
649 array('%d')
650 );
651 }
652 }
653
654 $this->wpforo->db->delete(
655 $this->wpforo->db->prefix.'wpforo_subscribes', array( 'userid' => $userid ), array( '%d' )
656 );
657
658 $this->wpforo->db->delete(
659 $this->wpforo->db->prefix.'wpforo_views', array( 'userid' => $userid ), array( '%d' )
660 );
661
662 $this->wpforo->db->delete(
663 $this->wpforo->db->prefix.'wpforo_likes', array( 'userid' => $userid ), array( '%d' )
664 );
665
666 $this->wpforo->db->delete(
667 $this->wpforo->db->prefix.'wpforo_votes', array( 'userid' => $userid ), array( '%d' )
668 );
669
670 if( FALSE !== $this->wpforo->db->delete(
671 $this->wpforo->db->prefix.'wpforo_profiles', array( 'userid' => $userid ), array( '%d' )
672 )
673 ){
674 $this->clear_db_cache();
675 $this->wpforo->notice->add('User successfully deleted from wpforo', 'success');
676 return TRUE;
677 }
678
679 $this->wpforo->notice->add('User delete error', 'error');
680 return FALSE;
681 }
682
683 public function avatar($member, $attr = '', $size = '', $cache = false){
684
685 if(!isset($member['userid'])) return;
686
687 $src = $member['avatar'];
688 $userid = $member['userid'];
689 if(isset(self::$cache['avatar'][$userid])){
690 if(self::$cache['avatar'][$userid]['attr'] == $attr && self::$cache['avatar'][$userid]['size'] == $size){
691 if(isset(self::$cache['avatar'][$userid]['img'])){
692 return self::$cache['avatar'][$userid]['img'];
693 }
694 }
695 }
696 if($src && wpforo_feature('custom-avatars', $this->wpforo)){
697 $attr = ($attr ? $attr : 'height="96" width="96"');
698 $img = '<img class="avatar" src="'.esc_url($src).'" '. $attr .' />';
699 }else{
700 $img = ($size) ? get_avatar($userid, $size) : get_avatar($userid);
701 if($attr) $img = str_replace('<img', '<img ' . $attr, $img);
702 }
703 if($cache){
704 self::$cache['avatar'][$userid]['attr'] = $attr;
705 self::$cache['avatar'][$userid]['size'] = $size;
706 return self::$cache['avatar'][$userid]['img'] = $img;
707 }
708 else{
709 return $img;
710 }
711 }
712
713 function get_avatar($userid, $attr = '', $size = '', $cache = false){
714 if(isset(self::$cache['avatar'][$userid])){
715 if(self::$cache['avatar'][$userid]['attr'] == $attr && self::$cache['avatar'][$userid]['size'] == $size){
716 if(isset(self::$cache['avatar'][$userid]['img'])){
717 return self::$cache['avatar'][$userid]['img'];
718 }
719 }
720 }
721 $src = $this->wpforo->db->get_var("SELECT `avatar` FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `userid` = ".intval($userid));
722 if($src && wpforo_feature('custom-avatars', $this->wpforo)){
723 $attr = ($attr ? $attr : 'height="96" width="96"');
724 $img = '<img class="avatar" src="'.esc_url($src).'" '. $attr .' />';
725 }else{
726 $img = ($size) ? get_avatar($userid, $size) : get_avatar($userid);
727 if($attr) $img = str_replace('<img', '<img ' . $attr, $img);
728 }
729 if($cache){
730 self::$cache['avatar'][$userid]['attr'] = $attr;
731 self::$cache['avatar'][$userid]['size'] = $size;
732 return self::$cache['avatar'][$userid]['img'] = $img;
733 }
734 else{
735 return $img;
736 }
737 }
738
739 public function get_avatar_url($userid){
740 return $this->wpforo->db->get_var("SELECT `avatar` FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `userid` = ".intval($userid));
741 }
742
743 function get_topics_count( $userid ){
744 $count = $this->wpforo->db->get_var("SELECT count(topicid) FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `userid` = ".intval($userid));
745 return $count;
746 }
747
748 function get_questions_count( $userid ){
749 $count = $this->wpforo->db->get_var("SELECT count(topicid) FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `userid` = ".intval($userid));
750 return $count;
751 }
752
753 function get_answers_count( $userid ){
754 $count = $this->wpforo->db->get_var("SELECT count(postid) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `is_answer` = 1 AND `userid` = ".intval($userid));
755 return $count;
756 }
757
758 function get_question_comments_count( $userid ){
759 $count = $this->wpforo->db->get_var("SELECT count(postid) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `parentid` > 0 AND `userid` = ".intval($userid));
760 return $count;
761 }
762
763 function get_replies_count( $userid ){
764 $count = $this->wpforo->db->get_var("SELECT count(postid) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `userid` = ".intval($userid));
765 return $count;
766 }
767
768 function get_likes_count( $userid ){
769 $count = $this->wpforo->db->get_var("SELECT count(likeid) FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `userid` = ".intval($userid));
770 return $count;
771 }
772
773 function get_votes_count( $userid ){
774 $count = $this->wpforo->db->get_var("SELECT count(voteid) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `userid` = ".intval($userid));
775 return $count;
776 }
777
778 // how many times the user like or vote
779 function get_votes_and_likes_count( $userid ){
780 return $this->get_votes_count( intval($userid) ) + $this->get_likes_count( intval($userid) );
781 }
782
783 //getting user's posts votes and likes count
784 function get_user_votes_and_likes_count( $userid ){
785 $votes_count = $this->wpforo->db->get_var("SELECT count(voteid) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `post_userid` = ".intval($userid));
786 $likes_count = $this->wpforo->db->get_var("SELECT count(likeid) FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `post_userid` = ".intval($userid));
787 return $votes_count + $likes_count;
788 }
789
790 function get_profile_url( $arg, $template = 'profile' ){
791 if(!$arg) return WPFORO_BASE_URL;
792 $userid = intval( basename($arg) );
793 $member_args = ( $userid ? $userid : array( 'username' => basename($arg) ) );
794 $user = $this->get_member( $member_args );
795 if(empty($user)) return WPFORO_BASE_URL;
796 $user_slug = ( wpfo($this->wpforo->member_options['url_structure'], false) == 'id' ? $user['ID'] : $user['user_nicename'] );
797 return WPFORO_BASE_URL . "$template/$user_slug";
798 }
799
800 function profile_url( $member = array(), $template = 'profile' ){
801 if(isset($member['ID']) || isset($member['user_nicename'])){
802 $user_slug = ( wpfo($this->wpforo->member_options['url_structure'], false) == 'id' ? $member['ID'] : $member['user_nicename'] );
803 $profile_url = WPFORO_BASE_URL . "$template/$user_slug";
804 $profile_url = apply_filters( 'wpforo_profile_url', $profile_url, $member, $template );
805 }
806 else{
807 $profile_url = WPFORO_BASE_URL;
808 $profile_url = apply_filters( 'wpforo_no_profile_url', $profile_url, $template );
809
810 }
811 return $profile_url;
812 }
813
814 //$args = UserID or Member Object
815 //$live_count = TRUE / FALSE
816 function get_stat( $args = array(), $live_count = false, $cache = false ){
817
818 $stat = array( 'points' => 0,
819 'rating' => 0,
820 'rating_procent' => 0,
821 'color' => $this->rating(0, 'color'),
822 'badge' => $this->rating(0, 'icon'),
823 'posts' => 0,
824 'topics' => 0,
825 'questions' => 0,
826 'answers' => 0,
827 'question_comments' => 0,
828 'likes' => 0,
829 'liked' => 0,
830 'title' => $this->rating(0, 'title'));
831
832 $userid = ( isset($args['userid']) && $args['userid'] ) ? $args['userid'] : $args;
833
834 if( $cache && isset(self::$cache['stat'][$userid]) ){
835 return self::$cache['stat'][$userid];
836 }
837
838 if( is_array($args) && isset($args['userid']) ){
839 $userid = $args['userid'];
840 $stat['topics'] = (int)$this->get_topics_count( $userid );
841 if(isset($args['questions'])) $stat['questions'] = intval($args['questions']);
842 if(isset($args['answers'])) $stat['answers'] = intval($args['answers']);
843 if(isset($args['posts'])) $stat['posts'] = intval($args['posts']);
844 if(isset($args['comments'])) $stat['question_comments'] = intval($args['comments']);
845 }
846 elseif($userid = wpforo_bigintval($args)){
847 $stat['topics'] = (int)$this->get_topics_count( $userid );
848 if($live_count){
849 if($questions = $this->get_questions_count( $userid )) $stat['questions'] = $questions;
850 if($answers = $this->get_answers_count( $userid )) $stat['answers'] = $answers;
851 if($posts = $this->get_replies_count( $userid )) $stat['posts'] = $posts;
852 if($question_comments = $this->get_question_comments_count( $userid )) $stat['question_comments'] = $question_comments;
853 }
854 else{
855 $profile = $this->wpforo->db->get_var("SELECT `posts`, `questions`, `answers`, `comments` FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `userid` = ".intval($userid));
856 if(isset($profile['questions'])) $stat['questions'] = intval($profile['questions']);
857 if(isset($profile['answers'])) $stat['answers'] = intval($profile['answers']);
858 if(isset($profile['posts'])) $stat['posts'] = intval($profile['posts']);
859 if(isset($profile['comments'])) $stat['question_comments'] = intval($profile['comments']);
860 }
861 }
862
863 if( $userid ){
864 if($likes = $this->get_votes_and_likes_count( $userid )) $stat['likes'] = $likes;
865 if($liked = $this->get_user_votes_and_likes_count( $userid )) $stat['liked'] = $liked;
866 if($stat['posts']) $stat['points'] = $stat['posts']; //TO-DO: Point counter function based on all stat values.
867 if($stat['points']) $stat['rating'] = $this->rating_level($stat['points'], false);
868 if($stat['rating']) {
869 $stat['rating_procent'] = $stat['rating'] * 10;
870 $stat['title'] = $this->rating(intval($stat['rating']), 'title');
871 $stat['color'] = $this->rating(intval($stat['rating']), 'color');
872 $stat['badge'] = $this->rating(intval($stat['rating']), 'icon');
873 }
874 }
875
876 if($cache && isset($userid)){
877 return self::$cache['stat'][$userid] = $stat;
878 }
879 else{
880 return $stat;
881 }
882 }
883
884 function get_count(){
885 return $this->wpforo->db->get_var( "SELECT COUNT(p.`userid`) FROM `".$this->wpforo->db->prefix."wpforo_profiles` p
886 INNER JOIN `".$this->wpforo->db->base_prefix."users` u ON u.`ID` = p.`userid` WHERE p.`status` NOT LIKE 'trashed'" );
887 }
888
889
890 function is_online( $userid, $duration = 240, $cache = true ){
891 if(isset(self::$cache['online'][$userid])){
892 if(self::$cache['online'][$userid]['durration'] == $duration ){
893 if(isset(self::$cache['online'][$userid]['status'])){
894 return self::$cache['online'][$userid]['status'];
895 }
896 }
897 }
898 if($duration == 240) $duration = $this->wpforo->member_options['online_status_timeout'];
899 $online_time = intval( get_user_meta($userid, 'wpforo_online_time', TRUE) );
900 $current_time = current_time( 'timestamp', 1 );
901 $online_duration = $current_time - $online_time;
902 if( $online_duration < $duration ) {
903 $status = true;
904 }
905 else{
906 $status = false;
907 }
908 if($cache){
909 self::$cache['online'][$userid]['durration'] = $duration;
910 return self::$cache['online'][$userid]['status'] = $status;
911 }
912 else{
913 return $status;
914 }
915 }
916
917 public function show_online_indicator($userid, $ico = TRUE){
918 if( $this->is_online($userid)) : ?>
919
920 <?php if($ico) : ?>
921 <i class="fa fa-lightbulb-o fa-0x wpfcl-8" title="<?php wpforo_phrase('Online') ?>"></i>
922 <?php else : wpforo_phrase('Online'); endif ?>
923
924 <?php else : ?>
925
926 <?php if($ico) : ?>
927 <i class="fa fa-lightbulb-o fa-0x wpfcl-0" title="<?php wpforo_phrase('Offline') ?>"></i>
928 <?php else : wpforo_phrase('Offline'); endif ?>
929
930 <?php endif;
931 }
932
933 function online_members_count( $duration = 240 ){
934 if($duration == 240) $duration = $this->wpforo->member_options['online_status_timeout'];
935 $current_time = current_time( 'timestamp', 1 );
936 $online_timeframe = $current_time - $duration;
937 return $this->wpforo->db->get_var( "SELECT COUNT(`user_id`) FROM `".$this->wpforo->db->base_prefix."usermeta` WHERE meta_key = 'wpforo_online_time' AND meta_value > " . wpforo_bigintval($online_timeframe) );
938
939 }
940
941 function get_online_members( $count = 1, $duration = 240 ){
942 if($duration == 240) $duration = $this->wpforo->member_options['online_status_timeout'];
943 $current_time = current_time( 'timestamp', 1 );
944 $online_timeframe = $current_time - $duration;
945 $onlinemembers_ids = $this->wpforo->db->get_col( "SELECT `user_id` FROM `".$this->wpforo->db->base_prefix."usermeta` WHERE meta_key = 'wpforo_online_time' AND meta_value > " . wpforo_bigintval($online_timeframe) );
946 if(!empty($onlinemembers_ids)){
947 $args = array(
948 'include' => $onlinemembers_ids, // array( 2, 10, 25 )
949 'orderby' => 'userid', // forumid, order, parentid
950 'row_count' => $count,
951 'order' => 'ASC', // ASC DESC
952 );
953 return $this->get_members( $args );
954 }
955 else{
956 return array();
957 }
958 }
959
960 function levels(){
961 $levels = array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
962 return $levels;
963 }
964
965 function rating( $level = false, $var = false, $default = false ){
966
967 $rating = array();
968 $rating['color'] = array( 0 => '#d2d2d2', 1 => '#4dca5c', 2 => '#4dca5c', 3 => '#4dca5c', 4 => '#4dca5c', 5 => '#4dca5c', 6 => '#E5D600', 7 => '#E5D600', 8 => '#E5D600', 9 => '#FF812D', 10 => '#E04A47' );
969 $rating['points'] = array( 0 => 0, 1 => 5, 2 => 20, 3 => 50, 4 => 100, 5 => 250, 6 => 500, 7 => 750, 8 => 1000, 9 => 2500, 10 => 5000 );
970 $rating['title'] = array( 0 => 'New Member', 1 => 'Active Member', 2 => 'Eminent Member', 3 => 'Trusted Member', 4 => 'Estimable Member', 5 => 'Reputable Member', 6 => 'Honorable Member', 7 => 'Prominent Member', 8 => 'Noble Member', 9 => 'Famed Member', 10 => 'Illustrious Member' );
971 $rating['icon'] = array( 0 => 'fa-star-half-o', 1 => 'fa-star', 2 => 'fa-star', 3 => 'fa-star', 4 => 'fa-star', 5 => 'fa-star', 6 => 'fa-certificate', 7 => 'fa-certificate', 8 => 'fa-certificate', 9 => 'fa-shield', 10 => 'fa-trophy' );
972
973 if(!empty($this->wpforo->member_options['rating'])){
974
975 if($level === false) return $this->wpforo->member_options['rating'];
976 if(!empty($this->wpforo->member_options['rating'][$level])){
977
978 if(!$var) return $this->wpforo->member_options['rating'][$level];
979 if(!empty($this->wpforo->member_options['rating'][$level][$var])){
980
981 return $this->wpforo->member_options['rating'][$level][$var];
982
983 }
984 }
985 }
986 if( $level !== false && $var ) { return $rating[$var][$level]; }
987 elseif( $level !== false && !$var ){ foreach( $rating as $variable => $values ){ $level_data[$variable] = $values[$level];} return $level_data; }
988 elseif( $level === false && !$var ) return $rating;
989 else return array();
990 }
991
992 function rating_level($member_posts, $percent = TRUE){
993 $bar = 0;
994 if($member_posts < $this->rating(1, 'points')){$bar = 0;}
995 elseif($member_posts < $this->rating(2, 'points')){$bar = 10;}
996 elseif($member_posts < $this->rating(3, 'points')){$bar = 20;}
997 elseif($member_posts < $this->rating(4, 'points')){$bar = 30;}
998 elseif($member_posts < $this->rating(5, 'points')){$bar = 40;}
999 elseif($member_posts < $this->rating(6, 'points')){$bar = 50;}
1000 elseif($member_posts < $this->rating(7, 'points')){$bar = 60;}
1001 elseif($member_posts < $this->rating(8, 'points')){$bar = 70;}
1002 elseif($member_posts < $this->rating(9, 'points')){$bar = 80;}
1003 elseif($member_posts < $this->rating(10, 'points')){$bar = 90;}
1004 else{$bar = 100;}
1005 if($percent){
1006 return $bar;
1007 }else{
1008 return floor($bar/10);
1009 }
1010 }
1011
1012 function rating_badge($level = 0, $view = 'short'){
1013
1014 $level = ( $level > 10 ) ? floor($level/10) : $level;
1015
1016 if($level == 0){
1017 return '<i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1018 }
1019 elseif($level > 0 && $level < 6){
1020 if( $view == 'full' ){
1021 return str_repeat(' <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i> ', $level);
1022 }
1023 else{
1024 return '<span>' . esc_html($level) . '</span> <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1025 }
1026 }
1027 elseif($level > 5 && $level < 9){
1028 if( $view == 'full' ){
1029 return str_repeat(' <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i> ', ($level-5));
1030 }
1031 else{
1032 return '<span>' . esc_html($level-5) . '</span> <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1033 }
1034 }
1035 elseif($level > 8){
1036 return '<i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1037 }
1038 else{
1039 return;
1040 }
1041 }
1042
1043 public function reset($userid){
1044 if( !$userid ) return;
1045 $this->wpforo->db->query( "DELETE FROM `" . $this->wpforo->db->base_prefix ."usermeta` WHERE `meta_key` = '_wpf_member_obj' AND `user_id` = " . intval($userid) );
1046 }
1047
1048 public function clear_db_cache(){
1049 $this->wpforo->db->query( "DELETE FROM `" . $this->wpforo->db->base_prefix ."usermeta` WHERE `meta_key` = '_wpf_member_obj'" );
1050 }
1051
1052 public function init_current_user(){
1053 $current_user = wp_get_current_user();
1054 if( $current_user->exists() ){
1055 $user = $this->get_member( $current_user->ID );
1056 $status = ( isset($user['status']) ? $user['status'] : '' );
1057 if( $status == 'active' ){
1058 update_user_meta( $current_user->ID, 'wpforo_online_time', current_time( 'timestamp', 1 ) );
1059 $this->wpforo->current_user = $user;
1060 $this->wpforo->current_user_groupid = $this->wpforo->current_user['groupid'];
1061 $this->wpforo->current_userid = $current_user->ID;
1062 $this->wpforo->current_username = $current_user->user_login;
1063 $this->wpforo->current_user_email = $current_user->user_email;
1064 $this->wpforo->current_user_display_name = $current_user->display_name;
1065 }else{
1066 $this->wpforo->current_user = array();
1067 $this->wpforo->current_user_groupid = 4;
1068 $this->wpforo->current_userid = 0;
1069 $this->wpforo->current_username = '';
1070 $this->wpforo->current_user_email = '';
1071 $this->wpforo->current_user_display_name = '';
1072 }
1073 $this->wpforo->current_user_status = $status;
1074 }else{
1075 $this->wpforo->current_user = array();
1076 $this->wpforo->current_user_groupid = 4;
1077 $this->wpforo->current_userid = 0;
1078 $this->wpforo->current_username = '';
1079 $this->wpforo->current_user_email = '';
1080 $this->wpforo->current_user_display_name = '';
1081 $this->wpforo->current_user_status = '';
1082 }
1083 }
1084
1085 public function blog_posts( $userid ){
1086 if( isset($userid) && $userid ) return count_user_posts( $userid , 'post' );
1087 }
1088
1089 public function blog_comments($userid, $user_email){
1090 global $wpdb;
1091 if( !$userid || !$user_email ) return 0;
1092 return (int) $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->comments. " WHERE `user_id` = " . intval($userid) . " OR `comment_author_email` = '" . esc_sql($user_email) . "'");
1093 }
1094
1095 public function show_delete_form($current_user, $userids){
1096 if( empty($current_user) || empty($userids) ) return;
1097
1098 $userids = array_diff( $userids, array( $current_user->ID ) );
1099 $users_have_content = false;
1100 if ( $this->wpforo->db->get_var( "SELECT postid FROM {$this->wpforo->db->prefix}wpforo_posts WHERE userid IN( " . implode( ',', array_map('intval', $userids) ) . " ) LIMIT 1" ) ) {
1101 $users_have_content = true;
1102 }
1103 ?>
1104 <hr /><strong>#wpForo</strong>
1105 <?php if ( ! $users_have_content ) : ?>
1106 <input type="hidden" name="wpforo_user_delete_option" value="delete" />
1107 <?php else: ?>
1108 <?php if ( 1 == count($userids) ) : ?>
1109 <fieldset><p><legend><?php _e( 'What should be done with wpForo content owned by this user?', 'wpforo' ); ?></legend></p>
1110 <?php else : ?>
1111 <fieldset><p><legend><?php _e( 'What should be done with wpForo content owned by these users?', 'wpforo' ); ?></legend></p>
1112 <?php endif; ?>
1113 <ul style="list-style:none;">
1114 <li><label><input type="radio" id="wpforo_delete_option0" name="wpforo_user_delete_option" value="delete" />
1115 <?php _e('Delete all wpForo content.', 'wpforo'); ?></label></li>
1116 <li><input type="radio" id="wpforo_delete_option1" name="wpforo_user_delete_option" value="reassign" />
1117 <?php echo '<label for="wpforo_delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
1118 wp_dropdown_users( array(
1119 'name' => 'wpforo_reassign_user',
1120 'exclude' => $userids,
1121 'show' => 'display_name_with_login',
1122 ) ); ?></li>
1123 </ul></fieldset>
1124 <script type="text/javascript">
1125 jQuery(document).ready( function($) {
1126 $('#wpforo_reassign_user').focus( function() {
1127 $('#wpforo_delete_option1').prop('checked', true).trigger('change');
1128 });
1129 });
1130 </script>
1131 <?php endif;
1132 }
1133
1134 }
1135
1136 ?>