Completed
Pull Request — master (#112)
by Richard
10:50
created

XoopsUser::notify_mode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 19.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * XOOPS user handler
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             kernel
15
 * @since               2.0.0
16
 * @author              Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
17
 */
18
19
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20
21
/**
22
 * Class for users
23
 * @author              Kazumi Ono <[email protected]>
24
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
25
 * @package             kernel
26
 */
27
class XoopsUser extends XoopsObject
28
{
29
    /**
30
     * Array of groups that user belongs to
31
     * @var array
32
     * @access private
33
     */
34
    public $_groups = array();
35
    /**
36
     * @var bool is the user admin?
37
     * @access private
38
     */
39
    public $_isAdmin;
40
    /**
41
     * @var string user's rank
42
     * @access private
43
     */
44
    public $_rank;
45
    /**
46
     * @var bool is the user online?
47
     * @access private
48
     */
49
    public $_isOnline;
50
51
    /**
52
     * constructor
53
     * @param array|null $id ID of the user to be loaded from the database.
54
     */
55
    public function __construct($id = null)
56
    {
57
        $this->initVar('uid', XOBJ_DTYPE_INT, null, false);
58
        $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 60);
59
        $this->initVar('uname', XOBJ_DTYPE_TXTBOX, null, true, 25);
60
        $this->initVar('email', XOBJ_DTYPE_TXTBOX, null, true, 60);
61
        $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false, 100);
62
        $this->initVar('user_avatar', XOBJ_DTYPE_TXTBOX, null, false, 30);
63
        $this->initVar('user_regdate', XOBJ_DTYPE_INT, null, false);
64
        $this->initVar('user_icq', XOBJ_DTYPE_TXTBOX, null, false, 15);
65
        $this->initVar('user_from', XOBJ_DTYPE_TXTBOX, null, false, 100);
66
        $this->initVar('user_sig', XOBJ_DTYPE_TXTAREA, null, false, null);
67
        $this->initVar('user_viewemail', XOBJ_DTYPE_INT, 0, false);
68
        $this->initVar('actkey', XOBJ_DTYPE_OTHER, null, false);
69
        $this->initVar('user_aim', XOBJ_DTYPE_TXTBOX, null, false, 18);
70
        $this->initVar('user_yim', XOBJ_DTYPE_TXTBOX, null, false, 25);
71
        $this->initVar('user_msnm', XOBJ_DTYPE_TXTBOX, null, false, 100);
72
        $this->initVar('pass', XOBJ_DTYPE_TXTBOX, null, false, 255);
73
        $this->initVar('posts', XOBJ_DTYPE_INT, null, false);
74
        $this->initVar('attachsig', XOBJ_DTYPE_INT, 0, false);
75
        $this->initVar('rank', XOBJ_DTYPE_INT, 0, false);
76
        $this->initVar('level', XOBJ_DTYPE_INT, 0, false);
77
        $this->initVar('theme', XOBJ_DTYPE_OTHER, null, false);
78
        $this->initVar('timezone_offset', XOBJ_DTYPE_OTHER, '0.0', false);
79
        $this->initVar('last_login', XOBJ_DTYPE_INT, 0, false);
80
        $this->initVar('umode', XOBJ_DTYPE_OTHER, null, false);
81
        $this->initVar('uorder', XOBJ_DTYPE_INT, 1, false);
82
        // RMV-NOTIFY
83
        $this->initVar('notify_method', XOBJ_DTYPE_OTHER, 1, false);
84
        $this->initVar('notify_mode', XOBJ_DTYPE_OTHER, 0, false);
85
        $this->initVar('user_occ', XOBJ_DTYPE_TXTBOX, null, false, 100);
86
        $this->initVar('bio', XOBJ_DTYPE_TXTAREA, null, false, null);
87
        $this->initVar('user_intrest', XOBJ_DTYPE_TXTBOX, null, false, 150);
88
        $this->initVar('user_mailok', XOBJ_DTYPE_INT, 1, false);
89
        // for backward compatibility
90 View Code Duplication
        if (isset($id)) {
91
            if (is_array($id)) {
92
                $this->assignVars($id);
93
            } else {
94
                $member_handler = xoops_getHandler('member');
95
                $user           = $member_handler->getUser($id);
96
                foreach ($user->vars as $k => $v) {
97
                    $this->assignVar($k, $v['value']);
98
                }
99
            }
100
        }
101
    }
102
103
    /**
104
     * check if the user is a guest user
105
     *
106
     * @return bool returns false
107
     *
108
     */
109
    public function isGuest()
110
    {
111
        return false;
112
    }
113
114
    /**
115
     * Updated by Catzwolf 11 Jan 2004
116
     * find the username for a given ID
117
     *
118
     * @param  int $userid  ID of the user to find
119
     * @param  int $usereal switch for usename or realname
120
     * @return string name of the user. name for 'anonymous' if not found.
121
     */
122
    public static function getUnameFromId($userid, $usereal = 0)
123
    {
124
        $userid  = (int)$userid;
125
        $usereal = (int)$usereal;
126
        if ($userid > 0) {
127
            $member_handler = xoops_getHandler('member');
128
            $user           = $member_handler->getUser($userid);
129
            if (is_object($user)) {
130
                $ts = MyTextSanitizer::getInstance();
131
                if ($usereal) {
132
                    $name = $user->getVar('name');
133
                    if ($name != '') {
134
                        return $ts->htmlSpecialChars($name);
135
                    } else {
136
                        return $ts->htmlSpecialChars($user->getVar('uname'));
137
                    }
138
                } else {
139
                    return $ts->htmlSpecialChars($user->getVar('uname'));
140
                }
141
            }
142
        }
143
144
        return $GLOBALS['xoopsConfig']['anonymous'];
145
    }
146
147
    /**
148
     * increase the number of posts for the user
149
     *
150
     * @deprecated
151
     */
152
    public function incrementPost()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
153
    {
154
        $member_handler = xoops_getHandler('member');
155
156
        return $member_handler->updateUserByField($this, 'posts', $this->getVar('posts') + 1);
157
    }
158
159
    /**
160
     * set the groups for the user
161
     *
162
     * @param array $groupsArr Array of groups that user belongs to
163
     */
164
    public function setGroups($groupsArr)
165
    {
166
        if (is_array($groupsArr)) {
167
            $this->_groups =& $groupsArr;
168
        }
169
    }
170
171
    /**
172
     * get the groups that the user belongs to
173
     *
174
     * @return array array of groups
175
     */
176
    public function &getGroups()
177
    {
178
        if (empty($this->_groups)) {
179
            $member_handler = xoops_getHandler('member');
180
            $this->_groups  = $member_handler->getGroupsByUser($this->getVar('uid'));
181
        }
182
183
        return $this->_groups;
184
    }
185
186
    /**
187
     * alias for {@link getGroups()}
188
     * @see getGroups()
189
     * @return array array of groups
190
     * @deprecated
191
     */
192
    public function &groups()
193
    {
194
        $groups =& $this->getGroups();
195
196
        return $groups;
197
    }
198
199
    /**
200
     * Is the user admin ?
201
     *
202
     * This method will return true if this user has admin rights for the specified module.<br />
203
     * - If you don't specify any module ID, the current module will be checked.<br />
204
     * - If you set the module_id to -1, it will return true if the user has admin rights for at least one module
205
     *
206
     * @param  int $module_id check if user is admin of this module
207
     * @return bool is the user admin of that module?
208
     */
209
    public function isAdmin($module_id = null)
210
    {
211
        if (null === $module_id) {
212
            $module_id = (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) ? $GLOBALS['xoopsModule']->getVar('mid', 'n') : 1;
213
        } elseif ((int)$module_id < 1) {
214
            $module_id = 0;
215
        }
216
        $moduleperm_handler = xoops_getHandler('groupperm');
217
218
        return $moduleperm_handler->checkRight('module_admin', $module_id, $this->getGroups());
219
    }
220
221
    /**
222
     * get the user's rank
223
     * @return array array of rank ID and title
0 ignored issues
show
Documentation introduced by
Should the return type not be array<string,string|integer>|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
224
     */
225
    public function rank()
226
    {
227
        if (!isset($this->_rank)) {
228
            $this->_rank = xoops_getrank($this->getVar('rank'), $this->getVar('posts'));
0 ignored issues
show
Documentation Bug introduced by
It seems like xoops_getrank($this->get...$this->getVar('posts')) of type array<string,string|integer,{"id":"integer"}> is incompatible with the declared type string of property $_rank.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
229
        }
230
231
        return $this->_rank;
232
    }
233
234
    /**
235
     * is the user activated?
236
     * @return bool
237
     */
238
    public function isActive()
239
    {
240
        return !($this->getVar('level') == 0);
241
    }
242
243
    /**
244
     * is the user currently logged in?
245
     * @return bool
246
     */
247
    public function isOnline()
248
    {
249
        if (!isset($this->_isOnline)) {
250
            $onlinehandler   = xoops_getHandler('online');
251
            $this->_isOnline = ($onlinehandler->getCount(new Criteria('online_uid', $this->getVar('uid'))) > 0);// ? true : false;
252
        }
253
254
        return $this->_isOnline;
255
    }
256
257
    /**
258
     * get the users UID
259
     * @param  string $format
260
     * @return int
261
     */
262
    public function uid($format = '')
263
    {
264
        return $this->getVar('uid', $format);
265
    }
266
267
    /**
268
     * get the users UID
269
     * @param  string $format
270
     * @return int
271
     */
272
    public function id($format = 'N')
273
    {
274
        return $this->getVar('uid', $format);
275
    }
276
277
    /**
278
     * get the users name
279
     * @param  string $format format for the output, see {@link XoopsObject::getVar($format = '')}
280
     * @return string
281
     */
282
    public function name($format = 'S')
283
    {
284
        return $this->getVar('name', $format);
285
    }
286
287
    /**
288
     * get the user's uname
289
     * @param  string $format format for the output, see {@link XoopsObject::getVar($format = '')}
290
     * @return string
291
     */
292
    public function uname($format = 'S')
293
    {
294
        return $this->getVar('uname', $format);
295
    }
296
297
    /**
298
     * get the user's email
299
     *
300
     * @param  string $format format for the output, see {@link XoopsObject::getVar($format = '')}
301
     * @return string
302
     */
303
    public function email($format = 'S')
304
    {
305
        return $this->getVar('email', $format);
306
    }
307
308
    /**
309
     * @param string $format
310
     *
311
     * @return mixed
312
     */
313
    public function url($format = 'S')
314
    {
315
        return $this->getVar('url', $format);
316
    }
317
318
    /**
319
     * @param string $format
320
     *
321
     * @return mixed
322
     */
323
    public function user_avatar($format = 'S')
324
    {
325
        return $this->getVar('user_avatar', $format);
326
    }
327
328
    /**
329
     * @param string $format
330
     *
331
     * @return mixed
332
     */
333
    public function user_regdate($format = '')
334
    {
335
        return $this->getVar('user_regdate', $format);
336
    }
337
338
    /**
339
     * @param string $format
340
     *
341
     * @return mixed
342
     */
343
    public function user_icq($format = 'S')
344
    {
345
        return $this->getVar('user_icq', $format);
346
    }
347
348
    /**
349
     * @param string $format
350
     *
351
     * @return mixed
352
     */
353
    public function user_from($format = 'S')
354
    {
355
        return $this->getVar('user_from', $format);
356
    }
357
358
    /**
359
     * @param string $format
360
     *
361
     * @return mixed
362
     */
363
    public function user_sig($format = 'S')
364
    {
365
        return $this->getVar('user_sig', $format);
366
    }
367
368
    /**
369
     * @param string $format
370
     *
371
     * @return mixed
372
     */
373
    public function user_viewemail($format = '')
374
    {
375
        return $this->getVar('user_viewemail', $format);
376
    }
377
378
    /**
379
     * @param string $format
380
     *
381
     * @return mixed
382
     */
383
    public function actkey($format = '')
384
    {
385
        return $this->getVar('actkey', $format);
386
    }
387
388
    /**
389
     * @param string $format
390
     *
391
     * @return mixed
392
     */
393
    public function user_aim($format = 'S')
394
    {
395
        return $this->getVar('user_aim', $format);
396
    }
397
398
    /**
399
     * @param string $format
400
     *
401
     * @return mixed
402
     */
403
    public function user_yim($format = 'S')
404
    {
405
        return $this->getVar('user_yim', $format);
406
    }
407
408
    /**
409
     * @param string $format
410
     *
411
     * @return mixed
412
     */
413
    public function user_msnm($format = 'S')
414
    {
415
        return $this->getVar('user_msnm', $format);
416
    }
417
418
    /**
419
     * @param string $format
420
     *
421
     * @return mixed
422
     */
423
    public function pass($format = '')
424
    {
425
        return $this->getVar('pass', $format);
426
    }
427
428
    /**
429
     * @param string $format
430
     *
431
     * @return mixed
432
     */
433
    public function posts($format = '')
434
    {
435
        return $this->getVar('posts', $format);
436
    }
437
438
    /**
439
     * @param string $format
440
     *
441
     * @return mixed
442
     */
443
    public function attachsig($format = '')
444
    {
445
        return $this->getVar('attachsig', $format);
446
    }
447
448
    /**
449
     * @param string $format
450
     *
451
     * @return mixed
452
     */
453
    public function level($format = '')
454
    {
455
        return $this->getVar('level', $format);
456
    }
457
458
    /**
459
     * @param string $format
460
     *
461
     * @return mixed
462
     */
463
    public function theme($format = '')
464
    {
465
        return $this->getVar('theme', $format);
466
    }
467
468
    /**
469
     * @param string $format
470
     *
471
     * @return mixed
472
     */
473
    public function timezone($format = '')
474
    {
475
        return $this->getVar('timezone_offset', $format);
476
    }
477
478
    /**
479
     * @param string $format
480
     *
481
     * @return mixed
482
     */
483
    public function umode($format = '')
484
    {
485
        return $this->getVar('umode', $format);
486
    }
487
488
    /**
489
     * @param string $format
490
     *
491
     * @return mixed
492
     */
493
    public function uorder($format = '')
494
    {
495
        return $this->getVar('uorder', $format);
496
    }
497
498
    // RMV-NOTIFY
499
    /**
500
     * @param string $format
501
     *
502
     * @return mixed
503
     */
504
    public function notify_method($format = '')
505
    {
506
        return $this->getVar('notify_method', $format);
507
    }
508
509
    /**
510
     * @param string $format
511
     *
512
     * @return mixed
513
     */
514
    public function notify_mode($format = '')
515
    {
516
        return $this->getVar('notify_mode', $format);
517
    }
518
519
    /**
520
     * @param string $format
521
     *
522
     * @return mixed
523
     */
524
    public function user_occ($format = 'S')
525
    {
526
        return $this->getVar('user_occ', $format);
527
    }
528
529
    /**
530
     * @param string $format
531
     *
532
     * @return mixed
533
     */
534
    public function bio($format = 'S')
535
    {
536
        return $this->getVar('bio', $format);
537
    }
538
539
    /**
540
     * @param string $format
541
     *
542
     * @return mixed
543
     */
544
    public function user_intrest($format = 'S')
545
    {
546
        return $this->getVar('user_intrest', $format);
547
    }
548
    /**#@-*/
549
550
    /**#@+
551
     * @deprecated
552
     */
553
    public function getProfile()
554
    {
555
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
556
557
        return false;
558
    }
559
    /**#@-*/
560
}
561
562
/**
563
 * Class that represents a guest user
564
 * @author              Kazumi Ono <[email protected]>
565
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
566
 * @package             kernel
567
 */
568
class XoopsGuestUser extends XoopsUser
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
569
{
570
    /**
571
     * check if the user is a guest user
572
     *
573
     * @return bool returns true
574
     *
575
     */
576
    public function isGuest()
577
    {
578
        return true;
579
    }
580
}
581
582
/**
583
 * XOOPS user handler class.
584
 * This class is responsible for providing data access mechanisms to the data source
585
 * of XOOPS user class objects.
586
 *
587
 * @author  Kazumi Ono <[email protected]>
588
 * @author  Taiwen Jiang <[email protected]>
589
 * @package kernel
590
 */
591
class XoopsUserHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
592
{
593
    /**
594
     * @param XoopsDatabase|null| $db
595
     */
596
    public function __construct(XoopsDatabase $db)
597
    {
598
        parent::__construct($db, 'users', 'XoopsUser', 'uid', 'uname');
599
    }
600
601
    /**#@+
602
     * @deprecated
603
     * @param bool $uname
604
     * @param      $pwd
605
     * @param bool $md5
606
     * @return bool|object
607
     */
608
    public function &loginUser($uname, $pwd, $md5 = false)
0 ignored issues
show
Unused Code introduced by
The parameter $uname is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pwd is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $md5 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
609
    {
610
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
611
612
        return false;
613
    }
614
615
    /**
616
     * @param $fieldName
617
     * @param $fieldValue
618
     * @param $uid
619
     *
620
     * @return bool
621
     */
622
    public function updateUserByField($fieldName, $fieldValue, $uid)
0 ignored issues
show
Unused Code introduced by
The parameter $fieldName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $fieldValue is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $uid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
623
    {
624
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
625
626
        return false;
627
    }
628
    /**#@-*/
629
}
630