PluginProbe
wpForo Forum / 1.1.0
wpForo Forum v1.1.0
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.0, at wpf-includes/class-members.php

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