PluginProbe
wpForo Forum / 1.4.1
wpForo Forum v1.4.1
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / class-members.php

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

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