PluginProbe
wpForo Forum / 1.4.0
wpForo Forum v1.4.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.4.0, at wpf-includes/class-members.php

2,241 lines 86.3 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 private $wpforo;
8 public $default;
9 public $options;
10 private $fields;
11 private $countries;
12 private $timezones;
13 public $login_min_length;
14 public $login_max_length;
15 public $pass_min_length;
16 public $pass_max_length;
17
18 static $cache = array( 'users' => array(), 'user' => array(), 'guest' => array() );
19
20 function __construct( $wpForo ){
21 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
22
23 $this->init_defaults();
24 $this->init_options();
25
26 add_action('delete_user_form', array(&$this, 'show_delete_form'), 10, 2);
27 }
28
29 private function init_defaults(){
30 $this->default = new stdClass;
31
32 $this->default->options = array(
33 'default_title' => 'Member',
34 'online_status_timeout' => 240,
35 'url_structure' => 'nicename',
36 'search_type' => 'search', // can to be 'search' or 'filter'
37 'login_url' => '',
38 'register_url' => '',
39 'lost_password_url' => '',
40 'rating_title_ug' => array ( 1 => '0', 5 => '1', 4 => '1', 2 => '0', 3 => '1' ),
41 'rating_badge_ug' => array ( 1 => '1', 5 => '1', 4 => '1', 2 => '1', 3 => '1' ),
42 'title_usergroup' => array ( 1 => '1', 5 => '1', 4 => '1', 2 => '1', 3 => '0' )
43 );
44
45 $this->default->login_min_length = 3;
46 $this->default->login_max_length = 30;
47 $this->default->pass_min_length = 6;
48 $this->default->pass_max_length = 20;
49 }
50
51 private function init_options(){
52 $this->options = get_wpf_option('wpforo_member_options', $this->default->options);
53
54 $this->login_min_length = $this->default->login_min_length;
55 $this->login_max_length = $this->default->login_max_length;
56 $this->pass_min_length = $this->default->pass_min_length;
57 $this->pass_max_length = $this->default->pass_max_length;
58 }
59
60 public function get_cache( $var ){
61 if( isset(self::$cache[$var]) ) return self::$cache[$var];
62 }
63
64 public function send_new_user_notifications($user_id, $notify = 'admin'){
65 wp_send_new_user_notifications( $user_id, $notify );
66 }
67
68 private function add_profile($args){
69 if(empty($args)) return FALSE;
70 if(!isset($args['userid']) || !$args['userid'] || !isset($args['username']) || !$args['username'] ) return FALSE;
71 extract( $args, EXTR_OVERWRITE );
72 $this->reset($userid);
73 return $this->wpforo->db->insert(
74 $this->wpforo->db->prefix . 'wpforo_profiles',
75 array( 'userid' => intval($userid),
76 'title' => ( isset($title) && $title ? $title : $this->wpforo->member->options['default_title'] ),
77 'username' => sanitize_user($username),
78 'groupid' => intval((isset($groupid) && $groupid ? $groupid : $this->wpforo->usergroup->default_groupid)),
79 'site' => (isset($site) ? sanitize_text_field($site) : '' ),
80 'timezone' => ( isset($timezone) ? sanitize_text_field($timezone) : 'UTC+0' ),
81 'about' => ( isset($about) ? stripslashes( wpforo_kses(trim($about), 'user_description') ) : '' ),
82 'last_login' => ( isset($last_login) ? $last_login : current_time('mysql', 1) ) ),
83 array( '%d', '%s', '%s', '%d', '%s', '%s', '%s', '%s' )
84 );
85 }
86
87 function edit_profile($args){
88 if(empty($args)) return FALSE;
89 if( !isset($args['userid']) || !$args['userid'] ) return FALSE;
90 extract( $args, EXTR_OVERWRITE );
91
92 $fields = array();
93 $fields_types = array();
94
95 if(isset($last_login) && $last_login){
96 $fields['last_login'] = sanitize_text_field($last_login);
97 $fields_types[] = '%s';
98 }
99
100 if(isset($groupid) && $groupid){
101 if( $this->wpforo->current_user_groupid == 1 || current_user_can('administrator') || apply_filters('wpforo_allow_edit_profile_groupid', false) ){
102 $groupid = intval($groupid);
103 if( !(!$this->wpforo->current_object['user_is_same_current_user'] && ($this->wpforo->current_user_groupid == 1 || current_user_can('administrator') )) ) {
104 $flds = $this->get_fields();
105 if( !in_array($groupid, wpforo_parse_args($flds['groupid']['allowedGroupIds'])) ) $groupid = $this->wpforo->usergroup->default_groupid;
106 }
107 $fields['groupid'] = $groupid;
108 $fields_types[] = '%d';
109 }
110 }
111
112 if(isset($title) && $title){
113 $fields['title'] = sanitize_text_field(trim($title));
114 $fields_types[] = '%s';
115 }
116 if(isset($site)){
117 $fields['site'] = sanitize_text_field(trim($site));
118 $fields_types[] = '%s';
119 }
120 if(isset($icq)){
121 $fields['icq'] = sanitize_text_field(trim($icq));
122 $fields_types[] = '%s';
123 }
124 if(isset($aim)){
125 $fields['aim'] = sanitize_text_field(trim($aim));
126 $fields_types[] = '%s';
127 }
128 if(isset($yahoo)){
129 $fields['yahoo'] = sanitize_text_field(trim($yahoo));
130 $fields_types[] = '%s';
131 }
132 if(isset($msn)){
133 $fields['msn'] = sanitize_text_field(trim($msn));
134 $fields_types[] = '%s';
135 }
136 if(isset($facebook)){
137 $fields['facebook'] = sanitize_text_field(trim($facebook));
138 $fields_types[] = '%s';
139 }
140 if(isset($twitter)){
141 $fields['twitter'] = sanitize_text_field(trim($twitter));
142 $fields_types[] = '%s';
143 }
144 if(isset($gtalk)){
145 $fields['gtalk'] = sanitize_text_field(trim($gtalk));
146 $fields_types[] = '%s';
147 }
148 if(isset($skype)){
149 $fields['skype'] = sanitize_text_field(trim($skype));
150 $fields_types[] = '%s';
151 }
152 if(isset($signature)){
153 $fields['signature'] = stripslashes(wpforo_kses(trim($signature), 'user_description'));
154 $fields_types[] = '%s';
155 }
156 if(isset($about)){
157 $fields['about'] = stripslashes(wpforo_kses(trim($about), 'user_description'));
158 $fields_types[] = '%s';
159 }
160 if(isset($occupation)){
161 $fields['occupation'] = stripslashes(sanitize_text_field(trim($occupation)));
162 $fields_types[] = '%s';
163 }
164 if(isset($location)){
165 $fields['location'] = stripslashes(sanitize_text_field(trim($location)));
166 $fields_types[] = '%s';
167 }
168 if(isset($timezone)){
169 $fields['timezone'] = sanitize_text_field(trim($timezone));
170 $fields_types[] = '%s';
171 }
172 if(isset($avatar_type) && $avatar_type != 'gravatar' && isset($avatar_url) && $avatar_url){
173 $fields['avatar'] = esc_url(trim($avatar_url));
174 $fields_types[] = '%s';
175 }
176 if(isset($avatar_type) && $avatar_type == 'gravatar'){
177 $fields['avatar'] = '';
178 $fields_types[] = '%s';
179 }
180
181 $this->reset($userid);
182
183 $result = $this->wpforo->db->update(
184 $this->wpforo->db->prefix.'wpforo_profiles',
185 $fields,
186 array('userid' => intval($userid)),
187 $fields_types,
188 array('%d')
189 );
190
191 if( $result !== FALSE ){
192 $user_info = get_userdata( $args['userid'] );
193 $wp_user_data = array(
194 'ID' => $args['userid'],
195 'user_url' => ( isset($fields['site']) ? $fields['site'] : $user_info->user_url ),
196 'description' => ( isset($fields['about']) ? $fields['about'] : $user_info->description ),
197 );
198 wp_update_user( $wp_user_data );
199 }
200
201 return $result;
202 }
203
204 function create($args){
205 if(!wpforo_feature('user-register', $this->wpforo)){
206 $this->wpforo->notice->add('User registration is disabled.', 'error');
207 return FALSE;
208 }
209
210 $args = apply_filters( 'wpforo_create_profile', $args );
211
212 if( (isset($args['error']) && $args['error']) || !$args ){
213 return FALSE;
214 }
215
216 $this->login_min_length = apply_filters('wpforo_login_min_length', $this->login_min_length);
217 $this->login_max_length = apply_filters('wpforo_login_max_length', $this->login_max_length);
218 $this->pass_min_length = apply_filters('wpforo_pass_min_length', $this->pass_min_length);
219 $this->pass_max_length = apply_filters('wpforo_pass_max_length', $this->pass_max_length);
220
221 if( !empty($args) && is_array($args) && !empty($args['user_pass1']) ){
222 remove_action('register_new_user', 'wp_send_new_user_notifications');
223 add_action('register_new_user', array($this, 'send_new_user_notifications'));
224
225 do_action( 'wpforo_create_profile_before', $args );
226
227 $errors = new WP_Error();
228
229 extract($args, EXTR_OVERWRITE);
230 $sanitized_user_login = sanitize_user( $user_login );
231 $user_email = apply_filters( 'user_registration_email', $user_email );
232 $user_pass1 = trim(substr($user_pass1, 0, 100));
233 $user_pass2 = trim(substr($user_pass2, 0, 100));
234 $illegal_user_logins = array_map( 'strtolower', (array) apply_filters( 'illegal_user_logins', array() ) );
235 if ( $sanitized_user_login == '' ) {
236 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );
237 $this->wpforo->notice->add('Username is missed.', 'error');
238 return FALSE;
239 }elseif ( ! validate_username( $user_login ) ) {
240 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
241 $sanitized_user_login = '';
242 $this->wpforo->notice->add('Illegal character in username.', 'error');
243 $user_login = '';
244 return FALSE;
245 }elseif( strlen($user_login) < $this->login_min_length || strlen($user_login) > $this->login_max_length ){
246 $this->wpforo->notice->add( 'Username length must be between %d characters and %d characters.', 'error', array($this->login_min_length, $this->login_max_length) );
247 return FALSE;
248 }elseif ( username_exists( $sanitized_user_login ) ) {
249 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );
250 $this->wpforo->notice->add('Username exists. Please insert another.', 'error');
251 return FALSE;
252 }elseif ( in_array( strtolower( $sanitized_user_login ), $illegal_user_logins ) ) {
253 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) );
254 $this->wpforo->notice->add('ERROR: invalid_username. Sorry, that username is not allowed. Please insert another.', 'error');
255 return FALSE;
256 }elseif ( $user_email == '' ) {
257 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) );
258 $this->wpforo->notice->add('Insert your Email address.', 'error');
259 return FALSE;
260 }elseif ( ! is_email( $user_email ) ) {
261 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ) );
262 $this->wpforo->notice->add('Invalid Email address', 'error');
263 $user_email = '';
264 return FALSE;
265 }elseif ( email_exists( $user_email ) ) {
266 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
267 $this->wpforo->notice->add('Email address exists. Please insert another.', 'error');
268 return FALSE;
269 }elseif( strlen($user_pass1) < $this->pass_min_length || strlen($user_pass1) > $this->pass_max_length ){
270 $this->wpforo->notice->add( 'Password length must be between %d characters and %d characters.', 'error', array($this->pass_min_length, $this->pass_max_length) );
271 return FALSE;
272 }elseif($user_pass1 != $user_pass2){
273 $this->wpforo->notice->add('Password mismatch.', 'error');
274 return FALSE;
275 }else{
276 do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
277 $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
278 if ( $errors->get_error_code() ){
279 $args = array();
280 foreach($errors->errors as $u_err) $args[] = $u_err[0];
281 $this->wpforo->notice->add($args, 'error');
282 return FALSE;
283 }
284 $user_id = wp_create_user( $sanitized_user_login, $user_pass1, $user_email );
285 if ( !is_wp_error( $user_id ) && $user_id ) {
286 $args['userid'] = $user_id;
287 $creds = array('user_login' => $sanitized_user_login, 'user_password' => $user_pass1 );
288 wp_signon($creds);
289 do_action( 'wpforo_create_profile_after', $args );
290 do_action( 'register_new_user', $user_id );
291 $this->wpforo->notice->add('Success! Thank you Dear Friend', 'success');
292 return $user_id;
293 }
294 }
295 }elseif( !empty($args['user_login']) && !empty($args['user_email']) ){
296 if( strlen($args['user_login']) < $this->login_min_length || strlen($args['user_login']) > $this->login_max_length ){
297 $this->wpforo->notice->add( 'Username length must be between %d characters and %d characters.', 'error', array($this->login_min_length, $this->login_max_length) );
298 return FALSE;
299 }
300 $user_id = register_new_user( $args['user_login'], $args['user_email'] );
301 if ( !is_wp_error( $user_id ) && $user_id ) {
302 $args['userid'] = $user_id;
303 do_action( 'wpforo_create_profile_after', $args );
304 $this->wpforo->notice->add('Success! Please check your mail for confirmation.', 'success');
305 return $user_id;
306 }
307 }
308 if(!empty($user_id->errors)){
309 $args = array();
310 foreach($user_id->errors as $u_err) $args[] = $u_err[0];
311 $this->wpforo->notice->add($args, 'error');
312 return FALSE;
313 }
314 $this->wpforo->notice->add('Registration Error', 'error');
315 return FALSE;
316 }
317
318 function edit( $args = array() ){
319 if( empty($args) && empty($_REQUEST['member']) ) return FALSE;
320 if( empty($args) && !empty($_REQUEST['member']) ) $args = $_REQUEST['member'];
321
322 $args = apply_filters( 'wpforo_edit_profile', $args );
323 do_action( 'wpforo_edit_profile_before', $args );
324
325 if( (isset($args['error']) && $args['error']) || !$args ){
326 return FALSE;
327 }
328
329 extract($args, EXTR_OVERWRITE);
330
331 if( isset($userid) && isset($display_name) && isset($user_email) && isset($user_nicename) ){
332 $userid = intval($userid);
333 $user_email = sanitize_email($user_email);
334 if ( ! is_email( $user_email ) ) {
335 $this->wpforo->notice->add('Invalid Email address', 'error');
336 $user_email = '';
337 return FALSE;
338 }elseif ( ( $owner_id = email_exists( $user_email ) ) && ( $owner_id != $userid ) ) {
339 $this->wpforo->notice->add('This email address is already registered. Please insert another.', 'error');
340 return FALSE;
341 }
342
343 $user_nicename = sanitize_title($user_nicename);
344 if( is_numeric($user_nicename) ){
345 $this->wpforo->notice->add('Numerical nicknames are not allowed. Please insert another.', 'error');
346 return FALSE;
347 }
348 $sql = "SELECT `ID` FROM `".$this->wpforo->db->base_prefix."users` WHERE `ID` != ". intval($userid) ." AND ( `user_nicename` LIKE '".esc_sql($user_nicename)."' OR `ID` LIKE '".esc_sql($user_nicename)."' )";
349 if( $this->wpforo->db->get_var($sql)){
350 $this->wpforo->notice->add('This nickname is already registered. Please insert another.', 'error');
351 return FALSE;
352 }
353
354 $isRegister = ( isset($args['template']) && $args['template'] == 'register' ) ? true : false;
355
356 if ( !$isRegister && ( !is_user_logged_in() || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, $userid ) ) ) {
357 $this->wpforo->notice->add('Permission denied', 'error');
358 return FALSE;
359 }
360
361 if( $display_name && $user_email && $user_nicename ){
362 $this->wpforo->db->update(
363 $this->wpforo->db->base_prefix."users",
364 array(
365 'display_name' => sanitize_text_field($display_name),
366 'user_nicename' => sanitize_title($user_nicename),
367 'user_email' => sanitize_email($user_email)
368 ),
369 array('ID' => $userid),
370 array('%s','%s','%s'),
371 array('%d')
372 );
373 $this->wpforo->db->update(
374 $this->wpforo->db->base_prefix."usermeta",
375 array('meta_value' => sanitize_title($user_nicename)),
376 array('user_id' => $userid, 'meta_key' => 'nickname'),
377 array('%s'),
378 array('%d', '%s')
379 );
380 $this->reset($userid);
381 }
382
383 if( FALSE !== $this->edit_profile($args) ){
384 do_action( 'wpforo_edit_profile_after', $args );
385 $this->wpforo->notice->add('Your profile data have been successfully updated.', 'success');
386 return $userid;
387 }
388 }
389
390 $this->wpforo->notice->add('Something wrong with profile data.', 'error');
391 return FALSE;
392 }
393
394 public function change_password($old_passw, $new_passw, $userid){
395 if( !$userid = wpforo_bigintval($userid) ){
396 $this->wpforo->notice->clear();
397 $this->wpforo->notice->add('Userid is wrong', 'error');
398 return false;
399 }
400
401 $user = $this->get_member($userid);
402 if( !apply_filters('wpforo_change_password_validate', true, $old_passw, $new_passw, $user) ) return false;
403
404 if ( wp_check_password( $old_passw, $user['user_pass'], $userid) ){
405 wp_set_password( $new_passw, $userid );
406
407 /**
408 * Login user after change password with new pass
409 */
410 $creds = array('user_login' => sanitize_user( $user['user_login'] ), 'user_password' => $new_passw );
411 wp_signon($creds);
412
413 $this->wpforo->notice->add('Password successfully changed', 'success');
414 return true;
415 }
416
417 $this->wpforo->notice->clear();
418 $this->wpforo->notice->add('Old password is wrong', 'error');
419 return false;
420 }
421
422 function upload_avatar( $userid = 0 ){
423
424 $userid = intval($userid);
425 if( !$this->wpforo->perm->usergroup_can('upa') ) return;
426
427 if( !$userid ){
428 if( !isset($_POST['member']['userid']) || !$userid = intval($_POST['member']['userid']) ) return;
429 }
430
431 if( !$user = $this->get_member($userid) ) return;
432 $username = urldecode($user['user_nicename']);
433 if(isset($_FILES['avatar']) && !empty($_FILES['avatar']) && isset($_FILES['avatar']['name']) && $_FILES['avatar']['name']){
434
435 $name = sanitize_file_name($_FILES['avatar']['name']); //myimg.png
436 $type = sanitize_mime_type($_FILES['avatar']['type']); //image/png
437 $tmp_name = sanitize_text_field($_FILES['avatar']['tmp_name']); //D:\wamp\tmp\php986B.tmp
438 $error = sanitize_text_field($_FILES['avatar']['error']); //0
439 $size = intval($_FILES['avatar']['size']); //6112
440
441 if( $size > 2*1048576 ){
442 $this->wpforo->notice->clear();
443 $this->wpforo->notice->add('Avatar image is too big maximum allowed size is 2MB', 'error');
444 return FALSE;
445 }
446
447 if( $error ){
448 $error = wpforo_file_upload_error($error);
449 $this->wpforo->notice->clear();
450 $this->wpforo->notice->add($error, 'error');
451 return FALSE;
452 }
453
454 $upload_dir = wp_upload_dir();
455 $uplds_dir = $upload_dir['basedir']."/wpforo";
456 $avatar_dir = $upload_dir['basedir']."/wpforo/avatars";
457 if(!is_dir($uplds_dir)) wp_mkdir_p($uplds_dir);
458 if(!is_dir($avatar_dir)) wp_mkdir_p($avatar_dir);
459
460 $ext = pathinfo($name, PATHINFO_EXTENSION);
461 if( !wpforo_is_image($ext) ){
462 $this->wpforo->notice->clear();
463 $this->wpforo->notice->add('Incorrect file format. Allowed formats: jpeg, jpg, png, gif.', 'error');
464 return FALSE;
465 }
466
467 $fnm = pathinfo($username, PATHINFO_FILENAME);
468 $fnm = str_replace(' ', '-', $fnm);
469 while(strpos($fnm, '--') !== FALSE) $fnm = str_replace('--', '-', $fnm);
470 $fnm = preg_replace("/[^-a-zA-Z0-9]/", "", $fnm);
471 $fnm = trim($fnm, "-");
472
473 $avatar_fname = $fnm.( $fnm ? '_' : '' ).$userid.".".$ext;
474 $avatar_path = $avatar_dir."/".$avatar_fname;
475
476 if(is_dir($avatar_dir)){
477 if(move_uploaded_file($tmp_name, $avatar_path)) {
478 $image = wp_get_image_editor( $avatar_path );
479 if ( ! is_wp_error( $image ) ) {
480 $image->resize( 150, 150, true );
481 $image->save( $avatar_path );
482 }
483 $blog_url = preg_replace('#^https?\:#is', '', $upload_dir['baseurl']);
484 $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'));
485 $this->reset($userid);
486 }
487 }
488 }
489 }
490
491 function synchronize_user($userid){
492 if(!$userid) return FALSE;
493 $user = get_userdata($userid);
494 if( !empty($user->roles) ){
495 if( is_super_admin( $userid ) || in_array('administrator', $user->roles) ){
496 $groupid = 1;
497 }elseif( in_array('editor', $user->roles) ){
498 $groupid = 2;
499 }elseif( in_array('customer', $user->roles) ){
500 $groupid = 5;
501 }else{
502 $groupid = $this->wpforo->usergroup->default_groupid;
503 }
504 $insert_groupid = (isset($_POST['wpforo_usergroup'])) ? intval($_POST['wpforo_usergroup']) : $groupid;
505 $insert_timezone = (isset($_POST['wpforo_usertimezone'])) ? sanitize_text_field($_POST['wpforo_usertimezone']) : '';
506 $about = get_user_meta( $userid, 'description', true );
507 return $this->add_profile(
508 array( 'userid' => intval($userid),
509 'username' => sanitize_user($user->user_login),
510 'groupid' => intval($insert_groupid),
511 'site' => esc_url($user->user_url),
512 'timezone' => sanitize_text_field($insert_timezone),
513 'about' => stripslashes( wpforo_kses(trim($about), 'user_description') ),
514 'last_login' => sanitize_text_field($user->user_registered) ) );
515 }
516 return FALSE;
517 }
518
519 function synchronize_users(){
520 $sql = "SELECT `user_id` FROM `".$this->wpforo->db->base_prefix."usermeta`
521 WHERE `meta_key` LIKE '".$this->wpforo->db->prefix."capabilities'
522 AND `user_id` NOT IN( SELECT `userid` FROM `".$this->wpforo->db->prefix."wpforo_profiles` )";
523 $userids = $this->wpforo->db->get_col($sql);
524 if( !empty($userids) ){
525 foreach($userids as $userid){
526 $this->synchronize_user($userid);
527 }
528 }
529
530 ## -- START -- delete profiles where not participant on multisite blog
531 $sql = "DELETE FROM `".$this->wpforo->db->prefix."wpforo_profiles`
532 WHERE `userid` NOT IN( SELECT `user_id` FROM `".$this->wpforo->db->base_prefix."usermeta`
533 WHERE `meta_key` LIKE '".$this->wpforo->db->prefix."capabilities' )";
534 $this->wpforo->db->query($sql);
535 ## -- END -- delete profiles where not participant on multisite blog
536 }
537
538 function get_member($args = array(), $cache = false){
539
540 $cache = $this->wpforo->cache->on('memory_cashe');
541
542 if(is_array($args)){
543
544 $default = array(
545 'userid' => NULL, // userid
546 'username' => '' // username
547 );
548
549 }else{
550
551 $default = array(
552 'userid' => $args, // userid
553 'username' => '' // username
554 );
555
556 }
557
558 $args = wpforo_parse_args( $args, $default );
559
560 if(isset($args['userid'])){
561 if( $cache && isset(self::$cache['user'][$args['userid']]) ){
562 return self::$cache['user'][$args['userid']];
563 }
564 }
565
566 $user_meta_obj = true;
567
568 if(!empty($args)){
569
570 extract($args, EXTR_OVERWRITE);
571
572 $do_db_cache = wpforo_feature('member_cashe', $this->wpforo);
573
574 $userid = intval($userid);
575 $username = sanitize_user($username);
576
577 if( $do_db_cache ){
578 if( $username ){
579 $user_obj = get_user_by( 'user_nicename', $username );
580 if(!empty($user_obj)) $userid = $user_obj->ID;
581 $member = get_user_meta( $userid, '_wpf_member_obj', true );
582 }elseif( $userid ){
583 $member = get_user_meta( $userid, '_wpf_member_obj', true );
584 }else{
585 $user_meta_obj = true;
586 }
587 }else{
588 $member = array();
589 }
590
591 if(empty($member)){
592 $user_meta_obj = false;
593 $sql = "SELECT *, ug.name AS groupname FROM `".$this->wpforo->db->base_prefix."users` u
594 INNER JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`
595 LEFT JOIN `".$this->wpforo->db->prefix."wpforo_usergroups` ug ON ug.`groupid` = p.`groupid`";
596 $wheres = array();
597 if($userid) $wheres[] = "`ID` = " . intval($userid);
598 if($username) $wheres[] = "`user_nicename` = '" . esc_sql($username) . "'";
599 if( !empty($wheres) ) $sql .= " WHERE " . implode($wheres, " AND ");
600 $member = $this->wpforo->db->get_row($sql, ARRAY_A);
601 }
602
603 if(!empty($member)) {
604 if( $do_db_cache ){
605 if(!$user_meta_obj) {
606 $member['profile_url'] = $this->profile_url( $member );
607 $member['stat'] = $this->get_stat( $member, false, true );
608 update_user_meta( $userid, '_wpf_member_obj', $member );
609 }
610 }else{
611 $member['profile_url'] = $this->profile_url( $member );
612 $member['stat'] = $this->get_stat( $member, false, true );
613 }
614 }
615
616 if($cache && isset($userid)){
617 return self::$cache['user'][$userid] = $member;
618 }else{
619 return $member;
620 }
621 }
622 }
623
624 function get_members($args = array(), &$items_count = 0){
625
626 $default = array(
627 'include' => array(), // array( 2, 10, 25 )
628 'exclude' => array(), // array( 2, 10, 25 )
629 'status' => array('active', 'banned'), // 'active', 'blocked', 'trashed', 'spamer'
630 'groupid' => NULL, // groupid
631 'orderby' => 'userid', //
632 'order' => 'ASC', // ASC DESC
633 'offset' => 0, // OFFSET
634 'row_count' => NULL // ROW COUNT
635 );
636
637 $args = wpforo_parse_args( $args, $default );
638 if(!empty($args)){
639 extract($args, EXTR_OVERWRITE);
640
641 $include = wpforo_parse_args( $include );
642 $exclude = wpforo_parse_args( $exclude );
643
644 $sql = "SELECT *, ug.name AS groupname FROM `".$this->wpforo->db->base_prefix."users` u
645 INNER JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`
646 LEFT JOIN `".$this->wpforo->db->prefix."wpforo_usergroups` ug ON ug.`groupid` = p.`groupid`";
647 $wheres = array();
648 if(!empty($include)) $wheres[] = "u.`ID` IN(" . implode(', ', array_map('intval', $include)) . ")";
649 if(!empty($exclude)) $wheres[] = "u.`ID` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
650 if(!empty($status)) $wheres[] = " p.`status` IN('" . implode("','", array_map('esc_sql', array_map('sanitize_text_field', $status)) ) . "')";
651 if($groupid != NULL) $wheres[] = "p.`groupid` = " . intval($groupid);
652
653 if(!empty($wheres)) $sql .= " WHERE " . implode($wheres, " AND ");
654
655 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
656 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
657
658 if( $orderby == 'groupid' ) $orderby = 'p.`groupid`';
659 $sql .= esc_sql(" ORDER BY $orderby " . $order);
660 if($row_count) $sql .= esc_sql(" LIMIT $offset,$row_count");
661
662 return $this->wpforo->db->get_results($sql, ARRAY_A);
663 }
664 }
665
666 function search($needle, $fields = array(), $limit = NULL){
667
668 if($needle != ''){
669 $needle = sanitize_text_field($needle);
670 if(empty($fields)){
671 $fields = array(
672 'title',
673 'user_nicename',
674 'user_email',
675 'signature'
676 );
677 }
678
679 $sql = "SELECT `ID` FROM `".$this->wpforo->db->base_prefix."users` u
680 INNER JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`";
681 $wheres = array();
682
683 foreach($fields as $field){
684 $field = sanitize_text_field($field);
685 $wheres[] = "`".esc_sql($field)."` LIKE '%" . esc_sql($needle) ."%'";
686 }
687
688 if(!empty($wheres)){
689 $sql .= " WHERE " . implode($wheres, " OR ");
690 if( $limit ) $sql .= " LIMIT " . intval($limit);
691
692 return $this->wpforo->db->get_col($sql);
693 }else{
694 return array();
695 }
696 }else{
697 return array();
698 }
699
700 }
701
702 public function filter($args, $limit = NULL){
703 if($args && is_array($args)){
704 $sql = "SELECT `ID` FROM `".$this->wpforo->db->base_prefix."users` u
705 INNER JOIN `".$this->wpforo->db->prefix."wpforo_profiles` p ON p.`userid` = u.`ID`";
706 $wheres = array();
707
708 foreach($args as $field => $needle){
709 $field = sanitize_text_field($field);
710 $needle = sanitize_text_field($needle);
711 $wheres[] = "`".esc_sql($field)."` LIKE '%" . esc_sql($needle) ."%'";
712 }
713
714 if($wheres){
715 $sql .= " WHERE " . implode($wheres, " AND ");
716 if( $limit ) $sql .= " LIMIT " . intval($limit);
717
718 return $this->wpforo->db->get_col($sql);
719 }
720 }
721
722 return array();
723 }
724
725 function ban($userid){
726 if( $userid == $this->wpforo->current_userid ){
727 $this->wpforo->notice->add('You can\'t make yourself banned user', 'error');
728 return FALSE;
729 }
730 if( !$this->wpforo->perm->usergroup_can('bm') || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, intval( $userid ) )){
731 $this->wpforo->notice->add('Permission denied for this action', 'error');
732 return FALSE;
733 }
734 if( FALSE !== $this->wpforo->db->update(
735 $this->wpforo->db->prefix.'wpforo_profiles',
736 array('status' => 'banned'),
737 array('userid' => intval( $userid )),
738 array('%s'),
739 array('%d')
740 )
741 ){
742 $this->reset($userid);
743 $this->wpforo->notice->add('User successfully banned from wpforo', 'success');
744 return TRUE;
745 }
746
747 $this->wpforo->notice->add('User ban action error', 'error');
748 return FALSE;
749 }
750
751 function unban($userid){
752 if( !$this->wpforo->perm->usergroup_can('bm') || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, intval( $userid ) )){
753 $this->wpforo->notice->add('Permission denied for this action', 'error');
754 return FALSE;
755 }
756 if( FALSE !== $this->wpforo->db->update(
757 $this->wpforo->db->prefix.'wpforo_profiles',
758 array('status' => 'active'),
759 array('userid' => intval( $userid )),
760 array('%s'),
761 array('%d')
762 )
763 ){
764 $this->reset($userid);
765 $this->wpforo->notice->add('User successfully unbanned from wpforo', 'success');
766 return TRUE;
767 }
768
769 $this->wpforo->notice->add('User unban action error', 'error');
770 return FALSE;
771 }
772
773 /**
774 *
775 * @param int $userid
776 * @param int $reassign
777 *
778 * @return bool true | false if user successfully deleted
779 */
780 public function delete( $userid, $reassign = NULL ){
781 if( !($userid = intval($userid)) ) return FALSE;
782 if( !$this->wpforo->perm->usergroup_can('dm') || !$this->wpforo->perm->user_can_manage_user( $this->wpforo->current_userid, intval( $userid ) )){
783 $this->wpforo->notice->add('Permission denied for this action', 'error');
784 return FALSE;
785 }
786
787 do_action('wpforo_before_delete_user', $userid, $reassign);
788
789 if( !($reassign = intval($reassign)) ){
790 if( $postids = $this->wpforo->db->get_col( $this->wpforo->db->prepare( "SELECT postid FROM {$this->wpforo->db->prefix}wpforo_posts WHERE userid = %d", $userid ) ) ){
791 foreach( $postids as $postid ) $this->wpforo->post->delete($postid);
792 }
793
794 if( $topicids = $this->wpforo->db->get_col( $this->wpforo->db->prepare( "SELECT topicid FROM {$this->wpforo->db->prefix}wpforo_topics WHERE userid = %d", $userid ) ) ){
795 foreach( $topicids as $topicid ) $this->wpforo->topic->delete($topicid, false);
796 }
797 }else{
798 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_topics", array('userid' => $reassign), array('userid' => $userid) );
799 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_posts", array('userid' => $reassign), array('userid' => $userid) );
800 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_likes", array('post_userid' => $reassign), array('post_userid' => $userid) );
801 $this->wpforo->db->update( $this->wpforo->db->prefix."wpforo_votes", array('post_userid' => $reassign), array('post_userid' => $userid) );
802 if( $user_stats = $this->wpforo->db->get_row(
803 $this->wpforo->db->prepare( "SELECT
804 SUM(`posts`) AS posts,
805 SUM(`questions`) AS questions,
806 SUM(`answers`) AS answers,
807 SUM(`comments`) AS comments
808 FROM {$this->wpforo->db->prefix}wpforo_profiles
809 WHERE userid IN( %d , %d )", $userid, $reassign
810 ),
811 ARRAY_A
812 )
813 ){
814 $this->wpforo->db->update(
815 $this->wpforo->db->prefix.'wpforo_profiles',
816 array(
817 'posts' => $user_stats['posts'],
818 'questions' => $user_stats['questions'],
819 'answers' => $user_stats['answers'],
820 'comments' => $user_stats['comments']
821 ),
822 array('userid' => $reassign),
823 array('%d','%d','%d','%d'),
824 array('%d')
825 );
826 }
827 }
828
829 $this->wpforo->db->delete(
830 $this->wpforo->db->prefix.'wpforo_subscribes', array( 'userid' => $userid ), array( '%d' )
831 );
832
833 $this->wpforo->db->delete(
834 $this->wpforo->db->prefix.'wpforo_views', array( 'userid' => $userid ), array( '%d' )
835 );
836
837 $this->wpforo->db->delete(
838 $this->wpforo->db->prefix.'wpforo_likes', array( 'userid' => $userid ), array( '%d' )
839 );
840
841 $this->wpforo->db->delete(
842 $this->wpforo->db->prefix.'wpforo_votes', array( 'userid' => $userid ), array( '%d' )
843 );
844
845 if( FALSE !== $this->wpforo->db->delete(
846 $this->wpforo->db->prefix.'wpforo_profiles', array( 'userid' => $userid ), array( '%d' )
847 )
848 ){
849
850 do_action('wpforo_after_delete_user', $userid, $reassign);
851
852 $this->wpforo->notice->add('User successfully deleted from wpforo', 'success');
853 return TRUE;
854 }
855
856 $this->wpforo->notice->add('User delete error', 'error');
857 return FALSE;
858 }
859
860 public function avatar($member, $attr = '', $size = ''){
861
862 if(!isset($member['userid'])) return;
863 $cache = $this->wpforo->cache->on('memory_cashe');
864
865 $src = $member['avatar'];
866 $userid = $member['userid'];
867 if($cache && isset(self::$cache['avatar'][$userid])){
868 if(self::$cache['avatar'][$userid]['attr'] == $attr && self::$cache['avatar'][$userid]['size'] == $size){
869 if(isset(self::$cache['avatar'][$userid]['img'])){
870 return self::$cache['avatar'][$userid]['img'];
871 }
872 }
873 }
874 if($src && wpforo_feature('custom-avatars', $this->wpforo)){
875 $attr = ($attr ? $attr : 'height="96" width="96"');
876 $img = '<img class="avatar" src="'.esc_url($src).'" '. $attr .' />';
877 }else{
878 $img = ($size) ? get_avatar($userid, $size) : get_avatar($userid);
879 if($attr) $img = str_replace('<img', '<img ' . $attr, $img);
880 }
881 if($cache){
882 self::$cache['avatar'][$userid]['attr'] = $attr;
883 self::$cache['avatar'][$userid]['size'] = $size;
884 return self::$cache['avatar'][$userid]['img'] = $img;
885 }
886 else{
887 return $img;
888 }
889 }
890
891 function get_avatar($userid, $attr = '', $size = '', $cache = false){
892
893 $cache = $this->wpforo->cache->on('memory_cashe');
894
895 if($cache && isset(self::$cache['avatar'][$userid])){
896 if(self::$cache['avatar'][$userid]['attr'] == $attr && self::$cache['avatar'][$userid]['size'] == $size){
897 if(isset(self::$cache['avatar'][$userid]['img'])){
898 return self::$cache['avatar'][$userid]['img'];
899 }
900 }
901 }
902 $src = $this->wpforo->db->get_var("SELECT `avatar` FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `userid` = ".intval($userid));
903 if($src && wpforo_feature('custom-avatars', $this->wpforo)){
904 $attr = ($attr ? $attr : 'height="96" width="96"');
905 $img = '<img class="avatar" src="'.esc_url($src).'" '. $attr .' />';
906 }else{
907 $img = ($size) ? get_avatar($userid, $size) : get_avatar($userid);
908 if($attr) $img = str_replace('<img', '<img ' . $attr, $img);
909 }
910 if($cache){
911 self::$cache['avatar'][$userid]['attr'] = $attr;
912 self::$cache['avatar'][$userid]['size'] = $size;
913 return self::$cache['avatar'][$userid]['img'] = $img;
914 }
915 else{
916 return $img;
917 }
918 }
919
920 public function get_avatar_url($userid){
921 return $this->wpforo->db->get_var("SELECT `avatar` FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `userid` = ".intval($userid));
922 }
923
924 function get_topics_count( $userid ){
925 $count = $this->wpforo->db->get_var("SELECT count(topicid) FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `userid` = ".intval($userid));
926 return $count;
927 }
928
929 function get_questions_count( $userid ){
930 $count = $this->wpforo->db->get_var("SELECT count(topicid) FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `userid` = ".intval($userid));
931 return $count;
932 }
933
934 function get_answers_count( $userid ){
935 $count = $this->wpforo->db->get_var("SELECT count(postid) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `is_answer` = 1 AND `userid` = ".intval($userid));
936 return $count;
937 }
938
939 function get_question_comments_count( $userid ){
940 $count = $this->wpforo->db->get_var("SELECT count(postid) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `parentid` > 0 AND `userid` = ".intval($userid));
941 return $count;
942 }
943
944 function get_replies_count( $userid ){
945 $count = $this->wpforo->db->get_var("SELECT count(postid) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `userid` = ".intval($userid));
946 return $count;
947 }
948
949 function get_likes_count( $userid ){
950 $count = $this->wpforo->db->get_var("SELECT count(likeid) FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `userid` = ".intval($userid));
951 return $count;
952 }
953
954 function get_votes_count( $userid ){
955 $count = $this->wpforo->db->get_var("SELECT count(voteid) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `userid` = ".intval($userid));
956 return $count;
957 }
958
959 // how many times the user like or vote
960 function get_votes_and_likes_count( $userid ){
961 return $this->get_votes_count( intval($userid) ) + $this->get_likes_count( intval($userid) );
962 }
963
964 //getting user's posts votes and likes count
965 function get_user_votes_and_likes_count( $userid ){
966 $votes_count = $this->wpforo->db->get_var("SELECT count(voteid) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `post_userid` = ".intval($userid));
967 $likes_count = $this->wpforo->db->get_var("SELECT count(likeid) FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `post_userid` = ".intval($userid));
968 return $votes_count + $likes_count;
969 }
970
971 function get_profile_url( $arg, $template = 'profile' ){
972 if(!$arg) return wpforo_home_url();
973 $userid = intval( basename($arg) );
974 $member_args = ( $userid ? $userid : array( 'username' => basename($arg) ) );
975 $user = $this->get_member( $member_args );
976 if(empty($user)) return wpforo_home_url();
977 $user_slug = ( wpfo($this->wpforo->member->options['url_structure'], false) == 'id' ? $user['ID'] : $user['user_nicename'] );
978 return wpforo_home_url("$template/$user_slug");
979 }
980
981 function profile_url( $member = array(), $template = 'profile' ){
982 if(isset($member['ID']) || isset($member['user_nicename'])){
983 $user_slug = ( wpfo($this->wpforo->member->options['url_structure'], false) == 'id' ? $member['ID'] : $member['user_nicename'] );
984 $profile_url = wpforo_home_url("$template/$user_slug");
985 $profile_url = apply_filters( 'wpforo_profile_url', $profile_url, $member, $template );
986 }
987 else{
988 $profile_url = wpforo_home_url();
989 $profile_url = apply_filters( 'wpforo_no_profile_url', $profile_url, $template );
990
991 }
992 return $profile_url;
993 }
994
995 //$args = UserID or Member Object
996 //$live_count = TRUE / FALSE
997 function get_stat( $args = array(), $live_count = false, $cache = false ){
998
999 $cache = $this->wpforo->cache->on('memory_cashe');
1000
1001 $stat = array( 'points' => 0,
1002 'rating' => 0,
1003 'rating_procent' => 0,
1004 'color' => $this->rating(0, 'color'),
1005 'badge' => $this->rating(0, 'icon'),
1006 'posts' => 0,
1007 'topics' => 0,
1008 'questions' => 0,
1009 'answers' => 0,
1010 'question_comments' => 0,
1011 'likes' => 0,
1012 'liked' => 0,
1013 'title' => $this->rating(0, 'title'));
1014
1015 $userid = ( isset($args['userid']) && $args['userid'] ) ? $args['userid'] : $args;
1016
1017 if( $cache && isset(self::$cache['stat'][$userid]) ){
1018 return self::$cache['stat'][$userid];
1019 }
1020
1021 if( is_array($args) && isset($args['userid']) ){
1022 $userid = $args['userid'];
1023 $stat['topics'] = (int)$this->get_topics_count( $userid );
1024 if(isset($args['questions'])) $stat['questions'] = intval($args['questions']);
1025 if(isset($args['answers'])) $stat['answers'] = intval($args['answers']);
1026 if(isset($args['posts'])) $stat['posts'] = intval($args['posts']);
1027 if(isset($args['comments'])) $stat['question_comments'] = intval($args['comments']);
1028 }
1029 elseif($userid = wpforo_bigintval($args)){
1030 $stat['topics'] = (int)$this->get_topics_count( $userid );
1031 if($live_count){
1032 if($questions = $this->get_questions_count( $userid )) $stat['questions'] = $questions;
1033 if($answers = $this->get_answers_count( $userid )) $stat['answers'] = $answers;
1034 if($posts = $this->get_replies_count( $userid )) $stat['posts'] = $posts;
1035 if($question_comments = $this->get_question_comments_count( $userid )) $stat['question_comments'] = $question_comments;
1036 }
1037 else{
1038 $profile = $this->wpforo->db->get_var("SELECT `posts`, `questions`, `answers`, `comments` FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `userid` = ".intval($userid));
1039 if(isset($profile['questions'])) $stat['questions'] = intval($profile['questions']);
1040 if(isset($profile['answers'])) $stat['answers'] = intval($profile['answers']);
1041 if(isset($profile['posts'])) $stat['posts'] = intval($profile['posts']);
1042 if(isset($profile['comments'])) $stat['question_comments'] = intval($profile['comments']);
1043 }
1044 }
1045
1046 if( $userid ){
1047 if($likes = $this->get_votes_and_likes_count( $userid )) $stat['likes'] = $likes;
1048 if($liked = $this->get_user_votes_and_likes_count( $userid )) $stat['liked'] = $liked;
1049 if($stat['posts']) $stat['points'] = $stat['posts']; //TO-DO: Point counter function based on all stat values.
1050 if($stat['points']) $stat['rating'] = $this->rating_level($stat['points'], false);
1051 if($stat['rating']) {
1052 $stat['rating_procent'] = $stat['rating'] * 10;
1053 $stat['title'] = $this->rating(intval($stat['rating']), 'title');
1054 $stat['color'] = $this->rating(intval($stat['rating']), 'color');
1055 $stat['badge'] = $this->rating(intval($stat['rating']), 'icon');
1056 }
1057 }
1058
1059 if($cache && isset($userid)){
1060 return self::$cache['stat'][$userid] = $stat;
1061 }
1062 else{
1063 return $stat;
1064 }
1065 }
1066
1067 function get_count(){
1068 return $this->wpforo->db->get_var( "SELECT COUNT(p.`userid`) FROM `".$this->wpforo->db->prefix."wpforo_profiles` p
1069 INNER JOIN `".$this->wpforo->db->base_prefix."users` u ON u.`ID` = p.`userid` WHERE p.`status` NOT LIKE 'trashed'" );
1070 }
1071
1072
1073 function is_online( $userid, $duration = 240 ){
1074
1075 $cache = $this->wpforo->cache->on('memory_cashe');
1076
1077 if( $cache && isset(self::$cache['online'][$userid]) ){
1078 if(self::$cache['online'][$userid]['durration'] == $duration ){
1079 if(isset(self::$cache['online'][$userid]['status'])){
1080 return self::$cache['online'][$userid]['status'];
1081 }
1082 }
1083 }
1084 if($duration == 240) $duration = $this->wpforo->member->options['online_status_timeout'];
1085 $online_time = intval( get_user_meta($userid, 'wpforo_online_time', TRUE) );
1086 $current_time = current_time( 'timestamp', 1 );
1087 $online_duration = $current_time - $online_time;
1088 if( $online_duration < $duration ) {
1089 $status = true;
1090 }
1091 else{
1092 $status = false;
1093 }
1094 if( $cache ){
1095 self::$cache['online'][$userid]['durration'] = $duration;
1096 return self::$cache['online'][$userid]['status'] = $status;
1097 }
1098 else{
1099 return $status;
1100 }
1101 }
1102
1103 public function show_online_indicator($userid, $ico = TRUE){
1104 if( $this->is_online($userid)) : ?>
1105
1106 <?php if($ico) : ?>
1107 <i class="fa fa-lightbulb-o fa-0x wpfcl-8" title="<?php wpforo_phrase('Online') ?>"></i>
1108 <?php else : wpforo_phrase('Online'); endif ?>
1109
1110 <?php else : ?>
1111
1112 <?php if($ico) : ?>
1113 <i class="fa fa-lightbulb-o fa-0x wpfcl-0" title="<?php wpforo_phrase('Offline') ?>"></i>
1114 <?php else : wpforo_phrase('Offline'); endif ?>
1115
1116 <?php endif;
1117 }
1118
1119 function online_members_count( $duration = 240 ){
1120 if($duration == 240) $duration = $this->wpforo->member->options['online_status_timeout'];
1121 $current_time = current_time( 'timestamp', 1 );
1122 $online_timeframe = $current_time - $duration;
1123 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) );
1124
1125 }
1126
1127 function get_online_members( $count = 1, $duration = 240 ){
1128 if($duration == 240) $duration = $this->wpforo->member->options['online_status_timeout'];
1129 $current_time = current_time( 'timestamp', 1 );
1130 $online_timeframe = $current_time - $duration;
1131 $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) );
1132 if(!empty($onlinemembers_ids)){
1133 $args = array(
1134 'include' => $onlinemembers_ids, // array( 2, 10, 25 )
1135 'orderby' => 'userid', // forumid, order, parentid
1136 'row_count' => $count,
1137 'order' => 'ASC', // ASC DESC
1138 );
1139 return $this->get_members( $args );
1140 }
1141 else{
1142 return array();
1143 }
1144 }
1145
1146 function levels(){
1147 $levels = array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
1148 return $levels;
1149 }
1150
1151 function rating( $level = false, $var = false, $default = false ){
1152
1153 $rating = array();
1154 $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' );
1155 $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 );
1156 $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' );
1157 $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' );
1158
1159 if(!empty($this->wpforo->member->options['rating'])){
1160
1161 if($level === false) return $this->wpforo->member->options['rating'];
1162 if(!empty($this->wpforo->member->options['rating'][$level])){
1163
1164 if(!$var) return $this->wpforo->member->options['rating'][$level];
1165 if(!empty($this->wpforo->member->options['rating'][$level][$var])){
1166
1167 return $this->wpforo->member->options['rating'][$level][$var];
1168
1169 }
1170 }
1171 }
1172 if( $level !== false && $var ) { return $rating[$var][$level]; }
1173 elseif( $level !== false && !$var ){ foreach( $rating as $variable => $values ){ $level_data[$variable] = $values[$level];} return $level_data; }
1174 elseif( $level === false && !$var ) return $rating;
1175 else return array();
1176 }
1177
1178 function rating_level($member_posts, $percent = TRUE){
1179 $bar = 0;
1180 if($member_posts < $this->rating(1, 'points')){$bar = 0;}
1181 elseif($member_posts < $this->rating(2, 'points')){$bar = 10;}
1182 elseif($member_posts < $this->rating(3, 'points')){$bar = 20;}
1183 elseif($member_posts < $this->rating(4, 'points')){$bar = 30;}
1184 elseif($member_posts < $this->rating(5, 'points')){$bar = 40;}
1185 elseif($member_posts < $this->rating(6, 'points')){$bar = 50;}
1186 elseif($member_posts < $this->rating(7, 'points')){$bar = 60;}
1187 elseif($member_posts < $this->rating(8, 'points')){$bar = 70;}
1188 elseif($member_posts < $this->rating(9, 'points')){$bar = 80;}
1189 elseif($member_posts < $this->rating(10, 'points')){$bar = 90;}
1190 else{$bar = 100;}
1191 if($percent){
1192 return $bar;
1193 }else{
1194 return floor($bar/10);
1195 }
1196 }
1197
1198 function rating_badge($level = 0, $view = 'short'){
1199
1200 $level = ( $level > 10 ) ? floor($level/10) : $level;
1201
1202 if($level == 0){
1203 return '<i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1204 }
1205 elseif($level > 0 && $level < 6){
1206 if( $view == 'full' ){
1207 return str_repeat(' <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i> ', $level);
1208 }
1209 else{
1210 return '<span>' . esc_html($level) . '</span> <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1211 }
1212 }
1213 elseif($level > 5 && $level < 9){
1214 if( $view == 'full' ){
1215 return str_repeat(' <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i> ', ($level-5));
1216 }
1217 else{
1218 return '<span>' . esc_html($level-5) . '</span> <i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1219 }
1220 }
1221 elseif($level > 8){
1222 return '<i class="fa '. sanitize_html_class($this->rating($level, 'icon')) .'"></i>';
1223 }
1224 else{
1225 return;
1226 }
1227 }
1228
1229 public function reset($userid){
1230 if( !$userid ) return;
1231 $this->wpforo->db->query( "DELETE FROM `" . $this->wpforo->db->base_prefix ."usermeta` WHERE `meta_key` = '_wpf_member_obj' AND `user_id` = " . intval($userid) );
1232 wpforo_clean_cache( $userid, 'user' );
1233 }
1234
1235 public function clear_db_cache(){
1236 $this->wpforo->db->query( "DELETE FROM `" . $this->wpforo->db->base_prefix ."usermeta` WHERE `meta_key` = '_wpf_member_obj'" );
1237 }
1238
1239 public function init_current_user(){
1240 $current_user = wp_get_current_user();
1241 if( $current_user->exists() ){
1242 $user = $this->get_member( $current_user->ID );
1243 $status = ( isset($user['status']) ? $user['status'] : '' );
1244 if( $status == 'active' ){
1245 update_user_meta( $current_user->ID, 'wpforo_online_time', current_time( 'timestamp', 1 ) );
1246 $this->wpforo->current_user = $user;
1247 $this->wpforo->current_user_groupid = $this->wpforo->current_user['groupid'];
1248 $this->wpforo->current_userid = $current_user->ID;
1249 $this->wpforo->current_username = $current_user->user_login;
1250 $this->wpforo->current_user_email = $current_user->user_email;
1251 $this->wpforo->current_user_display_name = $current_user->display_name;
1252 }else{
1253 $this->wpforo->current_user = array();
1254 $this->wpforo->current_user_groupid = 4;
1255 $this->wpforo->current_userid = 0;
1256 $this->wpforo->current_username = '';
1257 $this->wpforo->current_user_email = '';
1258 $this->wpforo->current_user_display_name = '';
1259 }
1260 $this->wpforo->current_user_status = $status;
1261 }else{
1262 $this->wpforo->current_user = array();
1263 $this->wpforo->current_user_groupid = 4;
1264 $this->wpforo->current_userid = 0;
1265 $this->wpforo->current_username = '';
1266 $this->wpforo->current_user_email = '';
1267 $this->wpforo->current_user_display_name = '';
1268 $this->wpforo->current_user_status = '';
1269 }
1270 }
1271
1272 public function blog_posts( $userid ){
1273 if( isset($userid) && $userid ) return count_user_posts( $userid , 'post' );
1274 }
1275
1276 public function blog_comments($userid, $user_email){
1277 global $wpdb;
1278 if( !$userid || !$user_email ) return 0;
1279 return (int) $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->comments. " WHERE `user_id` = " . intval($userid) . " OR `comment_author_email` = '" . esc_sql($user_email) . "'");
1280 }
1281
1282 public function show_delete_form($current_user, $userids){
1283 if( empty($current_user) || empty($userids) ) return;
1284
1285 $userids = array_diff( $userids, array( $current_user->ID ) );
1286 $users_have_content = false;
1287 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" ) ) {
1288 $users_have_content = true;
1289 }
1290 ?>
1291 <hr /><strong>#wpForo</strong>
1292 <?php if ( ! $users_have_content ) : ?>
1293 <input type="hidden" name="wpforo_user_delete_option" value="delete" />
1294 <?php else: ?>
1295 <?php if ( 1 == count($userids) ) : ?>
1296 <fieldset><p><legend><?php _e( 'What should be done with wpForo content owned by this user?', 'wpforo' ); ?></legend></p>
1297 <?php else : ?>
1298 <fieldset><p><legend><?php _e( 'What should be done with wpForo content owned by these users?', 'wpforo' ); ?></legend></p>
1299 <?php endif; ?>
1300 <ul style="list-style:none;">
1301 <li><label><input type="radio" id="wpforo_delete_option0" name="wpforo_user_delete_option" value="delete" />
1302 <?php _e('Delete all wpForo content.', 'wpforo'); ?></label></li>
1303 <li><input type="radio" id="wpforo_delete_option1" name="wpforo_user_delete_option" value="reassign" />
1304 <?php echo '<label for="wpforo_delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
1305 wp_dropdown_users( array(
1306 'name' => 'wpforo_reassign_user',
1307 'exclude' => $userids,
1308 'show' => 'display_name_with_login',
1309 ) ); ?></li>
1310 </ul></fieldset>
1311 <script type="text/javascript">
1312 jQuery(document).ready( function($) {
1313 $('#wpforo_reassign_user').focus( function() {
1314 $('#wpforo_delete_option1').prop('checked', true).trigger('change');
1315 });
1316 });
1317 </script>
1318 <?php endif;
1319 }
1320
1321
1322
1323 public function autoban($userid){
1324 if( !$this->wpforo->perm->usergroup_can( 'em' ) ){
1325 $this->wpforo->db->update(
1326 $this->wpforo->db->prefix.'wpforo_profiles',
1327 array('status' => 'banned'),
1328 array('userid' => intval( $userid )),
1329 array('%s'),
1330 array('%d')
1331 );
1332 }
1333 }
1334
1335 public function member_approved_posts( $member = array() ){
1336 if(is_numeric($member)){
1337 if( isset($this->wpforo->current_user['posts']) && $this->wpforo->current_user['posts'] && $member == $this->wpforo->current_userid ){
1338 return $this->wpforo->current_user['posts'];
1339 }
1340 else{
1341 return $this->wpforo->db->get_var( "SELECT COUNT(*) as posts FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `status` = 0 AND `userid` = " . intval($member) );
1342 }
1343 }
1344 elseif(is_array($member) && !empty($member)){
1345 return intval($member['posts']);
1346 }
1347 else{
1348 return 0;
1349 }
1350 }
1351
1352 public function current_user_is_new(){
1353 if( $this->wpforo->perm->usergroup_can( 'em' ) ){
1354 //This is an admin or moderator. The number of posts doesn't matter.
1355 return false;
1356 }
1357 else{
1358 $posts = $this->member_approved_posts( $this->wpforo->current_userid );
1359 if ( $posts < $this->wpforo->tools_antispam['new_user_max_posts'] ) {
1360 return true;
1361 }
1362 }
1363 }
1364
1365 public function banned_count(){
1366 $count = $this->wpforo->db->get_var("SELECT count(*) FROM `".$this->wpforo->db->prefix."wpforo_profiles` WHERE `status` = 'banned' " );
1367 return $count;
1368 }
1369
1370 public function get_guest( $args = array() ){
1371
1372 $cache = $this->wpforo->cache->on('memory_cashe');
1373
1374 if( !isset($args['name']) || $args['name'] == '' ) $args['name'] = wpforo_phrase('Anonymous', false);
1375 if( !isset($args['email']) || $args['email'] == '' ) $args['email'] = 'anonymous@example.com';
1376
1377 $args['name'] = strip_tags($args['name']);
1378 $args['email'] = strip_tags($args['email']);
1379 $args['posts'] = 0;
1380 $args['user_registered'] = 0;
1381
1382 if(isset($args['email'])){
1383 if( $cache && isset(self::$cache['guest'][$args['email']]) ){
1384 return self::$cache['guest'][$args['email']];
1385 }
1386 }
1387
1388 if( $args['email'] ){
1389 $post_args = array( 'email' => $args['email'], 'orderby' => 'created', 'order' => 'ASC' );
1390 $posts = $this->wpforo->post->get_posts( $post_args );
1391 if( !empty($posts) ){
1392 $args['posts'] = count($posts);
1393 if( isset($posts[0]['created']) || $posts[0]['created'] ) $args['user_registered'] = $posts[0]['created'];
1394 }
1395 }
1396
1397 $member = array( 'ID' => 0,
1398 'userid' => 0,
1399 'user_login' => $args['name'],
1400 'user_pass' => '',
1401 'user_nicename' => sanitize_text_field($args['name']),
1402 'user_email' => $args['email'],
1403 'user_url' => '',
1404 'user_registered' => $args['user_registered'],
1405 'user_activation_key' => '',
1406 'user_status' => 0,
1407 'display_name' => $args['name'],
1408 'title' => '',
1409 'username' => $args['name'],
1410 'groupid' => 4,
1411 'posts' => $args['posts'], 'questions' => 0, 'answers' => 0, 'comments' => 0, 'site' => '', 'icq' => '', 'aim' => '', 'yahoo' => '', 'msn' => '', 'facebook' => '', 'twitter' => '', 'gtalk' => '', 'skype' => '', 'avatar' => '', 'signature' => '', 'about' => '', 'occupation' => '', 'location' => '', 'last_login' => '', 'rank' => 0, 'like' => 0,
1412 'status' => 'active',
1413 'timezone' => '',
1414 'name' => $args['name'],
1415 'cans' => '',
1416 'description' => '',
1417 'groupname' => wpforo_phrase('Guest', false),
1418 'profile_url' => '',
1419 'stat' => array( 'points' => 0, 'rating' => 0, 'rating_procent' => 0, 'color' => '', 'badge' => '', 'posts' => $args['posts'], 'topics' => 0, 'questions' => 0, 'answers' => 0, 'question_comments' => 0, 'likes' => 0, 'liked' => 0, 'title' => '' ),
1420 );
1421
1422 if( $cache && $args['email'] ){
1423 return self::$cache['guest'][$args['email']] = $member;
1424 }else{
1425 return $member;
1426 }
1427
1428 }
1429
1430 public function init_fields(){
1431 if( !empty($this->fields) ) return;
1432
1433 $this->init_countries();
1434 $this->init_timezones();
1435
1436 $this->fields = apply_filters('wpforo_member_before_init_fields', $this->fields);
1437
1438 $usergroupids = $this->wpforo->usergroup->get_usergroups('groupid');
1439 $usergroupids_can_edit_fields = $this->wpforo->perm->usergroups_can('em');
1440 $usergroupids_can_view_social_net = $this->wpforo->perm->usergroups_can('vmsn');
1441
1442 $this->fields['user_login'] = array(
1443 'fieldKey' => 'user_login',
1444 'type' => 'text',
1445 'isDefault' => 1,
1446 'isRemovable' => 0,
1447 'isRequired' => 1,
1448 'isEditable' => 0,
1449 'label' => wpforo_phrase('Username', false),
1450 'title' => wpforo_phrase('Username', false),
1451 'placeholder' => wpforo_phrase('Username', false),
1452 'description' => wpforo_phrase('Length must be between 3 characters and 15 characters.', false),
1453 'minLength' => $this->default->login_min_length,
1454 'maxLength' => $this->default->login_max_length,
1455 'faIcon' => 'fa-user',
1456 'name' => 'user_login',
1457 'canBeInactive' => array(
1458 'account',
1459 'profile',
1460 'search'
1461 ),
1462 'canEdit' => $usergroupids_can_edit_fields,
1463 'canView' => $this->wpforo->perm->usergroups_can('vmu'),
1464 'can' => 'vmu',
1465 'isSearchable' => 0
1466 );
1467
1468 $this->fields['user_email'] = array(
1469 'fieldKey' => 'user_email',
1470 'type' => 'email',
1471 'isDefault' => 1,
1472 'isRemovable' => 0,
1473 'isRequired' => 1,
1474 'isEditable' => 1,
1475 'label' => wpforo_phrase('Email', false),
1476 'title' => wpforo_phrase('Email', false),
1477 'placeholder' => wpforo_phrase('Email', false),
1478 'minLength' => 0,
1479 'maxLength' => 0,
1480 'faIcon' => 'fa-envelope',
1481 'name' => 'user_email',
1482 'canBeInactive' => array(
1483 'profile',
1484 'search'
1485 ),
1486 'canEdit' => $usergroupids_can_edit_fields,
1487 'canView' => $this->wpforo->perm->usergroups_can('vmm'),
1488 'can' => 'vmm',
1489 'isSearchable' => 1
1490 );
1491
1492 $this->fields['user_pass'] = array(
1493 'fieldKey' => 'user_pass',
1494 'type' => 'password',
1495 'isDefault' => 1,
1496 'isRemovable' => 0,
1497 'isRequired' => 1,
1498 'isEditable' => 1,
1499 'isConfirmPassword' => 1,
1500 'label' => wpforo_phrase('Password', false),
1501 'title' => wpforo_phrase('Password', false),
1502 'placeholder' => wpforo_phrase('Password', false),
1503 'description' => wpforo_phrase('Must be minimum 6 characters.', false),
1504 'minLength' => $this->default->pass_min_length,
1505 'maxLength' => $this->default->pass_max_length,
1506 'faIcon' => 'fa-key',
1507 'name' => 'user_pass',
1508 'canBeInactive' => array(
1509 'profile',
1510 'search'
1511 ),
1512 'canEdit' => $usergroupids_can_edit_fields,
1513 'canView' => array(),
1514 'can' => '',
1515 'isSearchable' => 0
1516 );
1517
1518 $this->fields['display_name'] = array(
1519 'fieldKey' => 'display_name',
1520 'type' => 'text',
1521 'isDefault' => 1,
1522 'isRemovable' => 0,
1523 'isRequired' => 1,
1524 'isEditable' => 1,
1525 'label' => wpforo_phrase('Display Name', false),
1526 'title' => wpforo_phrase('Display Name', false),
1527 'placeholder' => wpforo_phrase('Display Name', false),
1528 'faIcon' => 'fa-user',
1529 'name' => 'display_name',
1530 'canBeInactive' => array(
1531 'profile',
1532 'search'
1533 ),
1534 'canEdit' => $usergroupids_can_edit_fields,
1535 'canView' => $usergroupids,
1536 'can' => '',
1537 'isSearchable' => 1
1538 );
1539
1540 $this->fields['user_nicename'] = array(
1541 'fieldKey' => 'user_nicename',
1542 'type' => 'text',
1543 'isDefault' => 1,
1544 'isRemovable' => 0,
1545 'isRequired' => 1,
1546 'isEditable' => 1,
1547 'label' => wpforo_phrase('Nickname', false),
1548 'title' => wpforo_phrase('Nickname', false),
1549 'placeholder' => wpforo_phrase('Nickname', false),
1550 'description' => wpforo_phrase('URL Address Identifier', false),
1551 'minLength' => 0,
1552 'maxLength' => 0,
1553 'faIcon' => 'fa-link',
1554 'name' => 'user_nicename',
1555 'canBeInactive' => array(
1556 'register',
1557 'account',
1558 'profile',
1559 'search'
1560 ),
1561 'canEdit' => $usergroupids_can_edit_fields,
1562 'canView' => $usergroupids,
1563 'can' => '',
1564 'isSearchable' => 1
1565 );
1566
1567 $this->fields['title'] = array(
1568 'fieldKey' => 'title',
1569 'type' => 'text',
1570 'isDefault' => 1,
1571 'isRemovable' => 0,
1572 'isRequired' => 1,
1573 'isEditable' => 1,
1574 'label' => wpforo_phrase('Title', false),
1575 'title' => wpforo_phrase('Title', false),
1576 'placeholder' => wpforo_phrase('Title', false),
1577 'minLength' => 0,
1578 'maxLength' => 0,
1579 'faIcon' => 'fa-user',
1580 'name' => 'title',
1581 'canBeInactive' => array(
1582 'register',
1583 'account',
1584 'profile',
1585 'search'
1586 ),
1587 'canEdit' => $usergroupids_can_edit_fields,
1588 'canView' => $this->wpforo->perm->usergroups_can('vmt'),
1589 'can' => 'vmt',
1590 'isSearchable' => 1
1591 );
1592
1593 $this->fields['groupid'] = array(
1594 'fieldKey' => 'groupid',
1595 'type' => 'usergroup',
1596 'isDefault' => 1,
1597 'isRemovable' => 0,
1598 'isRequired' => 1,
1599 'isEditable' => 1,
1600 'label' => wpforo_phrase('User Group', false),
1601 'title' => wpforo_phrase('User Group', false),
1602 'placeholder' => wpforo_phrase('User Group', false),
1603 'faIcon' => 'fa-users',
1604 'name' => 'groupid',
1605 'allowedGroupIds' => array(3,5),
1606 'canBeInactive' => array(
1607 'register',
1608 'account',
1609 'profile',
1610 'search'
1611 ),
1612 'canEdit' => $usergroupids_can_edit_fields,
1613 'canView' => $usergroupids,
1614 'can' => '',
1615 'isSearchable' => 1
1616 );
1617
1618 $this->fields['avatar'] = array(
1619 'fieldKey' => 'avatar',
1620 'type' => 'avatar',
1621 'isDefault' => 1,
1622 'isRemovable' => 0,
1623 'isRequired' => 0,
1624 'isEditable' => 1,
1625 'label' => wpforo_phrase('Avatar', false),
1626 'title' => wpforo_phrase('Avatar', false),
1627 'placeholder' => wpforo_phrase('Avatar', false),
1628 'name' => 'avatar',
1629 'canBeInactive' => array(
1630 'register',
1631 'account',
1632 'profile',
1633 'search'
1634 ),
1635 'canEdit' => $usergroupids_can_edit_fields,
1636 'canView' => $this->wpforo->perm->usergroups_can('va'),
1637 'can' => 'va',
1638 'isSearchable' => 0
1639 );
1640
1641 $this->fields['site'] = array(
1642 'fieldKey' => 'site',
1643 'type' => 'url',
1644 'isDefault' => 1,
1645 'isRemovable' => 0,
1646 'isRequired' => 0,
1647 'isEditable' => 1,
1648 'label' => wpforo_phrase('Website', false),
1649 'title' => wpforo_phrase('Website', false),
1650 'placeholder' => wpforo_phrase('Website', false),
1651 'faIcon' => 'fa-sitemap',
1652 'name' => 'site',
1653 'canBeInactive' => array(
1654 'register',
1655 'account',
1656 'profile',
1657 'search'
1658 ),
1659 'canEdit' => $usergroupids_can_edit_fields,
1660 'canView' => $this->wpforo->perm->usergroups_can('vmw'),
1661 'can' => 'vmw',
1662 'isSearchable' => 1
1663 );
1664
1665 $this->fields['facebook'] = array(
1666 'fieldKey' => 'facebook',
1667 'type' => 'url',
1668 'isDefault' => 1,
1669 'isRemovable' => 0,
1670 'isRequired' => 0,
1671 'isEditable' => 1,
1672 'label' => wpforo_phrase('Facebook', false),
1673 'title' => wpforo_phrase('Facebook', false),
1674 'placeholder' => wpforo_phrase('Facebook', false),
1675 'faIcon' => 'fa-facebook-official',
1676 'name' => 'facebook',
1677 'canBeInactive' => array(
1678 'register',
1679 'account',
1680 'profile',
1681 'search'
1682 ),
1683 'canEdit' => $usergroupids_can_edit_fields,
1684 'canView' => $usergroupids_can_view_social_net,
1685 'can' => 'vmsn',
1686 'isSearchable' => 1
1687 );
1688
1689 $this->fields['twitter'] = array(
1690 'fieldKey' => 'twitter',
1691 'type' => 'url',
1692 'isDefault' => 1,
1693 'isRemovable' => 0,
1694 'isRequired' => 0,
1695 'isEditable' => 1,
1696 'label' => wpforo_phrase('Twitter', false),
1697 'title' => wpforo_phrase('Twitter', false),
1698 'placeholder' => wpforo_phrase('Twitter', false),
1699 'faIcon' => 'fa-twitter-square',
1700 'name' => 'twitter',
1701 'canBeInactive' => array(
1702 'register',
1703 'account',
1704 'profile',
1705 'search'
1706 ),
1707 'canEdit' => $usergroupids_can_edit_fields,
1708 'canView' => $usergroupids_can_view_social_net,
1709 'can' => 'vmsn',
1710 'isSearchable' => 1
1711 );
1712
1713 $this->fields['gtalk'] = array(
1714 'fieldKey' => 'gtalk',
1715 'type' => 'url',
1716 'isDefault' => 1,
1717 'isRemovable' => 0,
1718 'isRequired' => 0,
1719 'isEditable' => 1,
1720 'label' => wpforo_phrase('Google+', false),
1721 'title' => wpforo_phrase('Google+', false),
1722 'placeholder' => wpforo_phrase('Google+', false),
1723 'faIcon' => 'fa-google-plus-square',
1724 'name' => 'gtalk',
1725 'canBeInactive' => array(
1726 'register',
1727 'account',
1728 'profile',
1729 'search'
1730 ),
1731 'canEdit' => $usergroupids_can_edit_fields,
1732 'canView' => $usergroupids_can_view_social_net,
1733 'can' => 'vmsn',
1734 'isSearchable' => 1
1735 );
1736
1737 $this->fields['yahoo'] = array(
1738 'fieldKey' => 'yahoo',
1739 'type' => 'text',
1740 'isDefault' => 1,
1741 'isRemovable' => 0,
1742 'isRequired' => 0,
1743 'isEditable' => 1,
1744 'label' => wpforo_phrase('Yahoo', false),
1745 'title' => wpforo_phrase('Yahoo', false),
1746 'placeholder' => wpforo_phrase('Yahoo', false),
1747 'faIcon' => 'fa-yahoo',
1748 'name' => 'yahoo',
1749 'canBeInactive' => array(
1750 'register',
1751 'account',
1752 'profile',
1753 'search'
1754 ),
1755 'canEdit' => $usergroupids_can_edit_fields,
1756 'canView' => $usergroupids_can_view_social_net,
1757 'can' => 'vmsn',
1758 'isSearchable' => 1
1759 );
1760
1761 $this->fields['aim']= array(
1762 'fieldKey' => 'aim',
1763 'type' => 'text',
1764 'isDefault' => 1,
1765 'isRemovable' => 0,
1766 'isRequired' => 0,
1767 'isEditable' => 1,
1768 'label' => wpforo_phrase('AOL IM', false),
1769 'title' => wpforo_phrase('AOL IM', false),
1770 'placeholder' => wpforo_phrase('AOL IM', false),
1771 'faIcon' => 'fa-share-alt',
1772 'name' => 'aim',
1773 'canBeInactive' => array(
1774 'register',
1775 'account',
1776 'profile',
1777 'search'
1778 ),
1779 'canEdit' => $usergroupids_can_edit_fields,
1780 'canView' => $usergroupids_can_view_social_net,
1781 'can' => 'vmsn',
1782 'isSearchable' => 1
1783 );
1784
1785 $this->fields['icq'] = array(
1786 'fieldKey' => 'icq',
1787 'type' => 'text',
1788 'isDefault' => 1,
1789 'isRemovable' => 0,
1790 'isRequired' => 0,
1791 'isEditable' => 1,
1792 'label' => wpforo_phrase('ICQ', false),
1793 'title' => wpforo_phrase('ICQ', false),
1794 'placeholder' => wpforo_phrase('ICQ', false),
1795 'faIcon' => 'fa-share-alt',
1796 'name' => 'icq',
1797 'canBeInactive' => array(
1798 'register',
1799 'account',
1800 'profile',
1801 'search'
1802 ),
1803 'canEdit' => $usergroupids_can_edit_fields,
1804 'canView' => $usergroupids_can_view_social_net,
1805 'can' => 'vmsn',
1806 'isSearchable' => 1
1807 );
1808
1809 $this->fields['msn'] = array(
1810 'fieldKey' => 'msn',
1811 'type' => 'text',
1812 'isDefault' => 1,
1813 'isRemovable' => 0,
1814 'isRequired' => 0,
1815 'isEditable' => 1,
1816 'label' => wpforo_phrase('MSN', false),
1817 'title' => wpforo_phrase('MSN', false),
1818 'placeholder' => wpforo_phrase('MSN', false),
1819 'faIcon' => 'fa-share-alt',
1820 'name' => 'msn',
1821 'canBeInactive' => array(
1822 'register',
1823 'account',
1824 'profile',
1825 'search'
1826 ),
1827 'canEdit' => $usergroupids_can_edit_fields,
1828 'canView' => $usergroupids_can_view_social_net,
1829 'can' => 'vmsn',
1830 'isSearchable' => 1
1831 );
1832
1833 $this->fields['skype'] = array(
1834 'fieldKey' => 'skype',
1835 'type' => 'text',
1836 'isDefault' => 1,
1837 'isRemovable' => 0,
1838 'isRequired' => 0,
1839 'isEditable' => 1,
1840 'label' => wpforo_phrase('Skype', false),
1841 'title' => wpforo_phrase('Skype', false),
1842 'placeholder' => wpforo_phrase('Skype', false),
1843 'faIcon' => 'fa-skype',
1844 'name' => 'skype',
1845 'canBeInactive' => array(
1846 'register',
1847 'account',
1848 'profile',
1849 'search'
1850 ),
1851 'canEdit' => $usergroupids_can_edit_fields,
1852 'canView' => $usergroupids_can_view_social_net,
1853 'can' => 'vmsn',
1854 'isSearchable' => 1
1855 );
1856
1857 $this->fields['location'] = array(
1858 'fieldKey' => 'location',
1859 'type' => 'select',
1860 'isDefault' => 1,
1861 'isRemovable' => 0,
1862 'isRequired' => 0,
1863 'isEditable' => 1,
1864 'label' => wpforo_phrase('Location', false),
1865 'title' => wpforo_phrase('Location', false),
1866 'placeholder' => wpforo_phrase('Location', false),
1867 'faIcon' => 'fa-globe',
1868 'values' => $this->countries,
1869 'name' => 'location',
1870 'canBeInactive' => array(
1871 'register',
1872 'account',
1873 'profile',
1874 'search'
1875 ),
1876 'canEdit' => $usergroupids_can_edit_fields,
1877 'canView' => $this->wpforo->perm->usergroups_can('vml'),
1878 'can' => 'vml',
1879 'isSearchable' => 1
1880 );
1881
1882 $this->fields['timezone'] = array(
1883 'fieldKey' => 'timezone',
1884 'type' => 'select',
1885 'isDefault' => 1,
1886 'isRemovable' => 0,
1887 'isRequired' => 0,
1888 'isEditable' => 1,
1889 'label' => wpforo_phrase('Timezone', false),
1890 'title' => wpforo_phrase('Timezone', false),
1891 'placeholder' => wpforo_phrase('Timezone', false),
1892 'faIcon' => 'fa-globe',
1893 'values' => $this->timezones,
1894 'name' => 'timezone',
1895 'canBeInactive' => array(
1896 'register',
1897 'account',
1898 'profile',
1899 'search'
1900 ),
1901 'canEdit' => $usergroupids_can_edit_fields,
1902 'canView' => $usergroupids,
1903 'can' => '',
1904 'isSearchable' => 1
1905 );
1906
1907 $this->fields['occupation'] = array(
1908 'fieldKey' => 'occupation',
1909 'type' => 'text',
1910 'isDefault' => 1,
1911 'isRemovable' => 0,
1912 'isRequired' => 0,
1913 'isEditable' => 1,
1914 'label' => wpforo_phrase('Occupation', false),
1915 'title' => wpforo_phrase('Occupation', false),
1916 'placeholder' => wpforo_phrase('Occupation', false),
1917 'faIcon' => 'fa-address-card',
1918 'name' => 'occupation',
1919 'canBeInactive' => array(
1920 'register',
1921 'account',
1922 'profile',
1923 'search'
1924 ),
1925 'canEdit' => $usergroupids_can_edit_fields,
1926 'canView' => $this->wpforo->perm->usergroups_can('vmo'),
1927 'can' => 'vmo',
1928 'isSearchable' => 1
1929 );
1930
1931 $this->fields['signature'] = array(
1932 'fieldKey' => 'signature',
1933 'type' => 'textarea',
1934 'isDefault' => 1,
1935 'isRemovable' => 0,
1936 'isRequired' => 0,
1937 'isEditable' => 1,
1938 'label' => wpforo_phrase('Signature', false),
1939 'title' => wpforo_phrase('Signature', false),
1940 'placeholder' => wpforo_phrase('Signature', false),
1941 'faIcon' => 'fa-address-card',
1942 'name' => 'signature',
1943 'canBeInactive' => array(
1944 'register',
1945 'account',
1946 'profile',
1947 'search'
1948 ),
1949 'canEdit' => $usergroupids_can_edit_fields,
1950 'canView' => $this->wpforo->perm->usergroups_can('vms'),
1951 'can' => 'vms',
1952 'isSearchable' => 1
1953 );
1954
1955 $this->fields['about'] = array(
1956 'fieldKey' => 'about',
1957 'type' => 'textarea',
1958 'isDefault' => 1,
1959 'isRemovable' => 0,
1960 'isRequired' => 0,
1961 'isEditable' => 1,
1962 'label' => wpforo_phrase('About Me', false),
1963 'title' => wpforo_phrase('About Me', false),
1964 'placeholder' => wpforo_phrase('About Me', false),
1965 'faIcon' => 'fa-address-card',
1966 'name' => 'about',
1967 'canBeInactive' => array(
1968 'register',
1969 'account',
1970 'profile',
1971 'search'
1972 ),
1973 'canEdit' => $usergroupids_can_edit_fields,
1974 'canView' => $this->wpforo->perm->usergroups_can('vmam'),
1975 'can' => 'vmam',
1976 'isSearchable' => 1
1977 );
1978
1979 $this->fields['html_soc_net'] = array(
1980 'fieldKey' => 'html_soc_net',
1981 'type' => 'html',
1982 'isDefault' => 1,
1983 'isRemovable' => 0,
1984 'isRequired' => 0,
1985 'isEditable' => 1,
1986 'label' => wpforo_phrase('Social Networks', false),
1987 'title' => wpforo_phrase('Social Networks', false),
1988 'placeholder' => wpforo_phrase('Social Networks', false),
1989 'description' => wpforo_phrase('Social Networks', false),
1990 'html' => '<div class="wpf-label">' . wpforo_phrase('Social Networks', false) . '</div>',
1991 'name' => 'html_soc_net',
1992 'canBeInactive' => array(
1993 'register',
1994 'account',
1995 'profile',
1996 'search'
1997 ),
1998 'canEdit' => $usergroupids_can_edit_fields,
1999 'canView' => $usergroupids_can_view_social_net,
2000 'can' => 'vmsn',
2001 'isSearchable' => 0
2002 );
2003
2004 $this->fields = apply_filters('wpforo_member_after_init_fields', $this->fields);
2005 }
2006
2007 private function init_countries(){
2008 $this->countries = array( "Afghanistan","�
2009 land Islands","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica",
2010 "Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain",
2011 "Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina",
2012 "Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso",
2013 "Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile",
2014 "China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Congo, The Democratic Republic of The",
2015 "Cook Islands","Costa Rica","Cote D'ivoire","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica",
2016 "Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands (Malvinas)",
2017 "Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon",
2018 "Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala",
2019 "Guernsey","Guinea","Guinea-bissau","Guyana","Haiti","Heard Island and Mcdonald Islands","Holy See (Vatican City State)",
2020 "Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran, Islamic Republic of","Iraq","Ireland",
2021 "Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kiribati","Korea, Democratic People's Republic of",
2022 "Korea, Republic of","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia",
2023 "Libyan Arab Jamahiriya","Liechtenstein","Lithuania","Luxembourg","Macao","Macedonia, The Former Yugoslav Republic of",
2024 "Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius",
2025 "Mayotte","Mexico","Micronesia, Federated States of","Moldova, Republic of","Monaco","Mongolia","Montenegro","Montserrat",
2026 "Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","Netherlands Antilles","New Caledonia",
2027 "New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Northern Mariana Islands","Norway","Oman",
2028 "Pakistan","Palau","Palestinian Territory, Occupied","Panama","Papua New Guinea","Paraguay","Peru","Philippines",
2029 "Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saint Helena",
2030 "Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and The Grenadines","Samoa",
2031 "San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore",
2032 "Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Georgia and The South Sandwich Islands",
2033 "Spain","Sri Lanka","Sudan","Suriname","Svalbard and Jan Mayen","Swaziland","Sweden","Switzerland","Syrian Arab Republic",
2034 "Taiwan, Province of China","Tajikistan","Tanzania, United Republic of","Thailand","Timor-leste","Togo","Tokelau",
2035 "Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine",
2036 "United Arab Emirates","United Kingdom","United States","United States Minor Outlying Islands","Uruguay","Uzbekistan",
2037 "Vanuatu","Venezuela","Viet Nam","Virgin Islands, British","Virgin Islands, U.S.","Wallis and Futuna","Western Sahara",
2038 "Yemen","Zambia","Zimbabwe" );
2039 }
2040
2041 private function init_timezones(){
2042 $this->timezones = timezone_identifiers_list();
2043 $offset_range = array (-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5,
2044 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
2045 foreach ( $offset_range as $offset ) {
2046 if ( 0 <= $offset )
2047 $offset_name = '+' . $offset;
2048 else
2049 $offset_name = (string) $offset;
2050
2051 $offset_value = $offset_name;
2052 $offset_value = 'UTC' . $offset_value;
2053 $this->timezones[] = 'UTC/' . $offset_value;
2054 }
2055
2056 $zones = $this->timezones;
2057 $timezones = array();
2058 foreach($zones as $zone){
2059 if(strpos($zone, '/') === false) continue;
2060
2061 $zone = str_replace('_', ' ', $zone);
2062
2063 $group = function_exists('mb_substr') ? mb_substr($zone, 0, strpos($zone, '/')) : substr($zone, 0, strpos($zone, '/'));
2064 $index = function_exists('mb_strlen') ? mb_strlen($group) + 1 : strlen($group) + 1;
2065 $optionValue = substr($zone, $index);
2066
2067 if(strpos($optionValue, 'UTC') !== false){
2068 $optionTitle = str_replace(array('.25', '.5', '.75',), array(':15', ':30', ':45',), $optionValue);
2069 $optionValue = "$optionValue=>$optionTitle";
2070 }else{
2071 $optionValue = "$zone=>$optionValue";
2072 }
2073
2074 $timezones[$group][] = $optionValue;
2075 }
2076
2077 $this->timezones = $timezones;
2078 }
2079
2080 public function get_fields($only_defaults = false){
2081 $this->init_fields();
2082 $fields = $this->fields;
2083
2084 if(!$only_defaults) $fields = apply_filters('wpforo_get_fields', $fields);
2085 return $fields;
2086 }
2087
2088 public function get_register_fields($only_defaults = false){
2089 $this->init_fields();
2090
2091 $regform = array(
2092 $this->fields['user_login'],
2093 $this->fields['user_email']
2094 );
2095 if( !wpforo_feature('user-register-email-confirm', $this->wpforo) ) $regform[] = $this->fields['user_pass'];
2096 $fields = array(
2097 array(
2098 $regform
2099 )
2100 );
2101
2102 if(!$only_defaults) $fields = apply_filters('wpforo_get_register_fields', $fields);
2103 return $fields;
2104 }
2105
2106 public function get_account_fields($only_defaults = false){
2107 $this->init_fields();
2108
2109 $fields = array(
2110 array(
2111 array(
2112 $this->fields['user_login'],
2113 $this->fields['display_name'],
2114 $this->fields['user_nicename'],
2115 $this->fields['user_email'],
2116 $this->fields['title'],
2117 $this->fields['groupid'],
2118 $this->fields['avatar'],
2119 $this->fields['about'],
2120 $this->fields['site'],
2121 $this->fields['occupation'],
2122 $this->fields['signature']
2123 )
2124 ),
2125 array(
2126 array(
2127 $this->fields['html_soc_net']
2128 ),
2129 array(
2130 $this->fields['facebook'],
2131 $this->fields['gtalk'],
2132 $this->fields['aim'],
2133 $this->fields['msn']
2134 ),
2135 array(
2136 $this->fields['twitter'],
2137 $this->fields['yahoo'],
2138 $this->fields['icq'],
2139 $this->fields['skype']
2140 )
2141 ),
2142 array(
2143 array(
2144 $this->fields['location'],
2145 $this->fields['timezone'],
2146 $this->fields['user_pass']
2147 )
2148 )
2149 );
2150
2151 if(!$only_defaults) $fields = apply_filters('wpforo_get_account_fields', $fields);
2152 return $fields;
2153 }
2154
2155 public function get_profile_fields($only_defaults = false){
2156 $this->init_fields();
2157
2158 $fields = array(
2159 array(
2160 array(
2161 $this->fields['about'],
2162 $this->fields['site'],
2163 )
2164 ),
2165 array(
2166 array(
2167 $this->fields['location'],
2168 $this->fields['timezone'],
2169 $this->fields['occupation'],
2170 $this->fields['signature']
2171 )
2172 ),
2173 array(
2174 array(
2175 $this->fields['html_soc_net']
2176 ),
2177 ),
2178 array(
2179 array(
2180 $this->fields['facebook'],
2181 $this->fields['gtalk'],
2182 $this->fields['aim'],
2183 $this->fields['msn'],
2184 ),
2185 array(
2186 $this->fields['twitter'],
2187 $this->fields['yahoo'],
2188 $this->fields['icq'],
2189 $this->fields['skype']
2190 )
2191 ),
2192 );
2193
2194 if(!$only_defaults) $fields = apply_filters('wpforo_get_profile_fields', $fields);
2195 return $fields;
2196 }
2197
2198 public function get_search_fields($only_defaults = false){
2199 $this->init_fields();
2200
2201 $fields = array(
2202 array(
2203 array(
2204 $this->fields['display_name'],
2205 $this->fields['user_nicename'],
2206 )
2207 )
2208 );
2209
2210 if(!$only_defaults) $fields = apply_filters('wpforo_get_search_fields', $fields);
2211
2212 foreach ($fields as $row_key => $row){
2213 foreach ($row as $col_key => $col){
2214 foreach ($col as $field_key => $field){
2215 $fields[$row_key][$col_key][$field_key]['isRequired'] = 0;
2216 $fields[$row_key][$col_key][$field_key]['class'] = 'wpf-member-search-field';
2217 if( $field['type'] == 'text' || $field['type'] == 'textarea' || $field['type'] == 'email' || $field['type'] == 'url' )
2218 $fields[$row_key][$col_key][$field_key]['type'] = 'search';
2219 }
2220 }
2221 }
2222
2223 return $fields;
2224 }
2225
2226 public function get_search_fields_names($only_defaults = false){
2227 $names = array();
2228 $fields = $this->get_search_fields($only_defaults);
2229
2230 foreach ($fields as $row_key => $row){
2231 foreach ($row as $col_key => $col){
2232 foreach ($col as $field_key => $field){
2233 $names[] = $field['name'];
2234 }
2235 }
2236 }
2237
2238 return $names;
2239 }
2240
2241 }