1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: |
|
18: |
|
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
20: |
|
21: | require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
|
22: |
|
23: | |
24: | |
25: | |
26: | |
27: | |
28: |
|
29: | class XoopsUser extends XoopsObject
|
30: | {
|
31: | |
32: | |
33: | |
34: | |
35: |
|
36: | public $_groups = array();
|
37: | |
38: | |
39: | |
40: |
|
41: | public $_isAdmin;
|
42: | |
43: | |
44: | |
45: |
|
46: | public $_rank;
|
47: | |
48: | |
49: | |
50: |
|
51: | public $_isOnline;
|
52: |
|
53: |
|
54: | public $uid;
|
55: | public $name;
|
56: | public $uname;
|
57: | public $email;
|
58: | public $url;
|
59: | public $user_avatar;
|
60: | public $user_regdate;
|
61: | public $user_icq;
|
62: | public $user_from;
|
63: | public $user_sig;
|
64: | public $user_viewemail;
|
65: | public $actkey;
|
66: | public $user_aim;
|
67: | public $user_yim;
|
68: | public $user_msnm;
|
69: | public $pass;
|
70: | public $posts;
|
71: | public $attachsig;
|
72: | public $rank;
|
73: | public $level;
|
74: | public $theme;
|
75: | public $timezone_offset;
|
76: | public $last_login;
|
77: | public $umode;
|
78: | public $uorder;
|
79: |
|
80: | public $notify_method;
|
81: | public $notify_mode;
|
82: | public $user_occ;
|
83: | public $bio;
|
84: | public $user_intrest;
|
85: | public $user_mailok;
|
86: |
|
87: | |
88: | |
89: | |
90: |
|
91: | public function __construct($id = null)
|
92: | {
|
93: | $this->initVar('uid', XOBJ_DTYPE_INT, null, false);
|
94: | $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 60);
|
95: | $this->initVar('uname', XOBJ_DTYPE_TXTBOX, null, true, 25);
|
96: | $this->initVar('email', XOBJ_DTYPE_TXTBOX, null, true, 60);
|
97: | $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false, 100);
|
98: | $this->initVar('user_avatar', XOBJ_DTYPE_TXTBOX, null, false, 30);
|
99: | $this->initVar('user_regdate', XOBJ_DTYPE_INT, null, false);
|
100: | $this->initVar('user_icq', XOBJ_DTYPE_TXTBOX, null, false, 15);
|
101: | $this->initVar('user_from', XOBJ_DTYPE_TXTBOX, null, false, 100);
|
102: | $this->initVar('user_sig', XOBJ_DTYPE_TXTAREA, null, false, null);
|
103: | $this->initVar('user_viewemail', XOBJ_DTYPE_INT, 0, false);
|
104: | $this->initVar('actkey', XOBJ_DTYPE_OTHER, null, false);
|
105: | $this->initVar('user_aim', XOBJ_DTYPE_TXTBOX, null, false, 18);
|
106: | $this->initVar('user_yim', XOBJ_DTYPE_TXTBOX, null, false, 25);
|
107: | $this->initVar('user_msnm', XOBJ_DTYPE_TXTBOX, null, false, 100);
|
108: | $this->initVar('pass', XOBJ_DTYPE_TXTBOX, null, false, 255);
|
109: | $this->initVar('posts', XOBJ_DTYPE_INT, null, false);
|
110: | $this->initVar('attachsig', XOBJ_DTYPE_INT, 0, false);
|
111: | $this->initVar('rank', XOBJ_DTYPE_INT, 0, false);
|
112: | $this->initVar('level', XOBJ_DTYPE_INT, 0, false);
|
113: | $this->initVar('theme', XOBJ_DTYPE_OTHER, null, false);
|
114: | $this->initVar('timezone_offset', XOBJ_DTYPE_OTHER, '0.0', false);
|
115: | $this->initVar('last_login', XOBJ_DTYPE_INT, 0, false);
|
116: | $this->initVar('umode', XOBJ_DTYPE_OTHER, null, false);
|
117: | $this->initVar('uorder', XOBJ_DTYPE_INT, 1, false);
|
118: |
|
119: | $this->initVar('notify_method', XOBJ_DTYPE_OTHER, XOOPS_NOTIFICATION_METHOD_PM, false);
|
120: | $this->initVar('notify_mode', XOBJ_DTYPE_OTHER, XOOPS_NOTIFICATION_MODE_SENDALWAYS, false);
|
121: | $this->initVar('user_occ', XOBJ_DTYPE_TXTBOX, null, false, 100);
|
122: | $this->initVar('bio', XOBJ_DTYPE_TXTAREA, null, false, null);
|
123: | $this->initVar('user_intrest', XOBJ_DTYPE_TXTBOX, null, false, 150);
|
124: | $this->initVar('user_mailok', XOBJ_DTYPE_INT, 1, false);
|
125: |
|
126: | if (isset($id)) {
|
127: | if (is_array($id)) {
|
128: | $this->assignVars($id);
|
129: | } else {
|
130: |
|
131: | $member_handler = xoops_getHandler('member');
|
132: | $user = $member_handler->getUser($id);
|
133: | foreach ($user->vars as $k => $v) {
|
134: | $this->assignVar($k, $v['value']);
|
135: | }
|
136: | }
|
137: | }
|
138: | }
|
139: |
|
140: | |
141: | |
142: | |
143: | |
144: | |
145: |
|
146: | public function isGuest()
|
147: | {
|
148: | return false;
|
149: | }
|
150: |
|
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: |
|
160: | public static function getUnameFromId($userid, $usereal = 0, $linked = false)
|
161: | {
|
162: | $userid = (int)$userid;
|
163: | $usereal = (int)$usereal;
|
164: | if ($userid > 0) {
|
165: |
|
166: | $member_handler = xoops_getHandler('member');
|
167: | $user = $member_handler->getUser($userid);
|
168: | if (is_object($user)) {
|
169: | $myts = \MyTextSanitizer::getInstance();
|
170: | if ($usereal && $user->getVar('name')) {
|
171: | $username = $myts->htmlSpecialChars($user->getVar('name'));
|
172: | } else {
|
173: | $username = $myts->htmlSpecialChars($user->getVar('uname'));
|
174: | }
|
175: | if (!empty($linked)) {
|
176: | $username = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $userid . '" title="' . $username . '">' . $username . '</a>';
|
177: | }
|
178: | return $username;
|
179: | }
|
180: | }
|
181: |
|
182: | return $GLOBALS['xoopsConfig']['anonymous'];
|
183: | }
|
184: |
|
185: | |
186: | |
187: | |
188: | |
189: |
|
190: | public function incrementPost()
|
191: | {
|
192: |
|
193: | $member_handler = xoops_getHandler('member');
|
194: |
|
195: | return $member_handler->updateUserByField($this, 'posts', $this->getVar('posts') + 1);
|
196: | }
|
197: |
|
198: | |
199: | |
200: | |
201: | |
202: |
|
203: | public function setGroups($groupsArr)
|
204: | {
|
205: | if (is_array($groupsArr)) {
|
206: | $this->_groups =& $groupsArr;
|
207: | }
|
208: | }
|
209: |
|
210: | |
211: | |
212: | |
213: | |
214: |
|
215: | public function &getGroups()
|
216: | {
|
217: | if (empty($this->_groups)) {
|
218: |
|
219: | $member_handler = xoops_getHandler('member');
|
220: | $this->_groups = $member_handler->getGroupsByUser($this->getVar('uid'));
|
221: | }
|
222: |
|
223: | return $this->_groups;
|
224: | }
|
225: |
|
226: | |
227: | |
228: | |
229: | |
230: | |
231: |
|
232: | public function &groups()
|
233: | {
|
234: | $groups =& $this->getGroups();
|
235: |
|
236: | return $groups;
|
237: | }
|
238: |
|
239: | |
240: | |
241: | |
242: | |
243: | |
244: | |
245: | |
246: | |
247: | |
248: |
|
249: | public function isAdmin($module_id = null)
|
250: | {
|
251: | if (null === $module_id) {
|
252: | $module_id = (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) ? $GLOBALS['xoopsModule']->getVar('mid', 'n') : 1;
|
253: | } elseif ((int)$module_id < 1) {
|
254: | $module_id = 0;
|
255: | }
|
256: |
|
257: | $moduleperm_handler = xoops_getHandler('groupperm');
|
258: |
|
259: | return $moduleperm_handler->checkRight('module_admin', $module_id, $this->getGroups());
|
260: | }
|
261: |
|
262: | |
263: | |
264: | |
265: |
|
266: | public function rank()
|
267: | {
|
268: | if (!isset($this->_rank)) {
|
269: | $this->_rank = xoops_getrank($this->getVar('rank'), $this->getVar('posts'));
|
270: | }
|
271: |
|
272: | return $this->_rank;
|
273: | }
|
274: |
|
275: | |
276: | |
277: | |
278: |
|
279: | public function isActive()
|
280: | {
|
281: | return !($this->getVar('level') == 0);
|
282: | }
|
283: |
|
284: | |
285: | |
286: | |
287: |
|
288: | public function isOnline()
|
289: | {
|
290: | if (!isset($this->_isOnline)) {
|
291: |
|
292: | $onlinehandler = xoops_getHandler('online');
|
293: | $this->_isOnline = ($onlinehandler->getCount(new Criteria('online_uid', $this->getVar('uid'))) > 0);
|
294: | }
|
295: |
|
296: | return $this->_isOnline;
|
297: | }
|
298: |
|
299: | |
300: | |
301: | |
302: | |
303: |
|
304: | public function uid($format = '')
|
305: | {
|
306: | return $this->getVar('uid', $format);
|
307: | }
|
308: |
|
309: | |
310: | |
311: | |
312: | |
313: |
|
314: | public function id($format = 'N')
|
315: | {
|
316: | return $this->getVar('uid', $format);
|
317: | }
|
318: |
|
319: | |
320: | |
321: | |
322: | |
323: |
|
324: | public function name($format = 'S')
|
325: | {
|
326: | return $this->getVar('name', $format);
|
327: | }
|
328: |
|
329: | |
330: | |
331: | |
332: | |
333: |
|
334: | public function uname($format = 'S')
|
335: | {
|
336: | return $this->getVar('uname', $format);
|
337: | }
|
338: |
|
339: | |
340: | |
341: | |
342: | |
343: | |
344: |
|
345: | public function email($format = 'S')
|
346: | {
|
347: | return $this->getVar('email', $format);
|
348: | }
|
349: |
|
350: | |
351: | |
352: | |
353: | |
354: |
|
355: | public function url($format = 'S')
|
356: | {
|
357: | return $this->getVar('url', $format);
|
358: | }
|
359: |
|
360: | |
361: | |
362: | |
363: | |
364: |
|
365: | public function user_avatar($format = 'S')
|
366: | {
|
367: | return $this->getVar('user_avatar', $format);
|
368: | }
|
369: |
|
370: | |
371: | |
372: | |
373: | |
374: |
|
375: | public function user_regdate($format = '')
|
376: | {
|
377: | return $this->getVar('user_regdate', $format);
|
378: | }
|
379: |
|
380: | |
381: | |
382: | |
383: | |
384: |
|
385: | public function user_icq($format = 'S')
|
386: | {
|
387: | return $this->getVar('user_icq', $format);
|
388: | }
|
389: |
|
390: | |
391: | |
392: | |
393: | |
394: |
|
395: | public function user_from($format = 'S')
|
396: | {
|
397: | return $this->getVar('user_from', $format);
|
398: | }
|
399: |
|
400: | |
401: | |
402: | |
403: | |
404: |
|
405: | public function user_sig($format = 'S')
|
406: | {
|
407: | return $this->getVar('user_sig', $format);
|
408: | }
|
409: |
|
410: | |
411: | |
412: | |
413: | |
414: |
|
415: | public function user_viewemail($format = '')
|
416: | {
|
417: | return $this->getVar('user_viewemail', $format);
|
418: | }
|
419: |
|
420: | |
421: | |
422: | |
423: | |
424: |
|
425: | public function actkey($format = '')
|
426: | {
|
427: | return $this->getVar('actkey', $format);
|
428: | }
|
429: |
|
430: | |
431: | |
432: | |
433: | |
434: |
|
435: | public function user_aim($format = 'S')
|
436: | {
|
437: | return $this->getVar('user_aim', $format);
|
438: | }
|
439: |
|
440: | |
441: | |
442: | |
443: | |
444: |
|
445: | public function user_yim($format = 'S')
|
446: | {
|
447: | return $this->getVar('user_yim', $format);
|
448: | }
|
449: |
|
450: | |
451: | |
452: | |
453: | |
454: |
|
455: | public function user_msnm($format = 'S')
|
456: | {
|
457: | return $this->getVar('user_msnm', $format);
|
458: | }
|
459: |
|
460: | |
461: | |
462: | |
463: | |
464: |
|
465: | public function pass($format = '')
|
466: | {
|
467: | return $this->getVar('pass', $format);
|
468: | }
|
469: |
|
470: | |
471: | |
472: | |
473: | |
474: |
|
475: | public function posts($format = '')
|
476: | {
|
477: | return $this->getVar('posts', $format);
|
478: | }
|
479: |
|
480: | |
481: | |
482: | |
483: | |
484: |
|
485: | public function attachsig($format = '')
|
486: | {
|
487: | return $this->getVar('attachsig', $format);
|
488: | }
|
489: |
|
490: | |
491: | |
492: | |
493: | |
494: |
|
495: | public function level($format = '')
|
496: | {
|
497: | return $this->getVar('level', $format);
|
498: | }
|
499: |
|
500: | |
501: | |
502: | |
503: | |
504: |
|
505: | public function theme($format = '')
|
506: | {
|
507: | return $this->getVar('theme', $format);
|
508: | }
|
509: |
|
510: | |
511: | |
512: | |
513: | |
514: |
|
515: | public function timezone($format = '')
|
516: | {
|
517: | return $this->getVar('timezone_offset', $format);
|
518: | }
|
519: |
|
520: | |
521: | |
522: | |
523: | |
524: |
|
525: | public function umode($format = '')
|
526: | {
|
527: | return $this->getVar('umode', $format);
|
528: | }
|
529: |
|
530: | |
531: | |
532: | |
533: | |
534: |
|
535: | public function uorder($format = '')
|
536: | {
|
537: | return $this->getVar('uorder', $format);
|
538: | }
|
539: |
|
540: |
|
541: | |
542: | |
543: | |
544: | |
545: |
|
546: | public function notify_method($format = '')
|
547: | {
|
548: | return $this->getVar('notify_method', $format);
|
549: | }
|
550: |
|
551: | |
552: | |
553: | |
554: | |
555: |
|
556: | public function notify_mode($format = '')
|
557: | {
|
558: | return $this->getVar('notify_mode', $format);
|
559: | }
|
560: |
|
561: | |
562: | |
563: | |
564: | |
565: |
|
566: | public function user_occ($format = 'S')
|
567: | {
|
568: | return $this->getVar('user_occ', $format);
|
569: | }
|
570: |
|
571: | |
572: | |
573: | |
574: | |
575: |
|
576: | public function bio($format = 'S')
|
577: | {
|
578: | return $this->getVar('bio', $format);
|
579: | }
|
580: |
|
581: | |
582: | |
583: | |
584: | |
585: |
|
586: | public function user_intrest($format = 'S')
|
587: | {
|
588: | return $this->getVar('user_intrest', $format);
|
589: | }
|
590: |
|
591: |
|
592: | |
593: | |
594: |
|
595: | public function getProfile()
|
596: | {
|
597: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated');
|
598: |
|
599: | return false;
|
600: | }
|
601: |
|
602: | }
|
603: |
|
604: | |
605: | |
606: | |
607: | |
608: | |
609: |
|
610: | class XoopsGuestUser extends XoopsUser
|
611: | {
|
612: | |
613: | |
614: | |
615: | |
616: | |
617: |
|
618: | public function isGuest()
|
619: | {
|
620: | return true;
|
621: | }
|
622: | }
|
623: |
|
624: | |
625: | |
626: | |
627: | |
628: | |
629: | |
630: | |
631: | |
632: |
|
633: | class XoopsUserHandler extends XoopsPersistableObjectHandler
|
634: | {
|
635: | |
636: | |
637: |
|
638: | public function __construct(XoopsDatabase $db)
|
639: | {
|
640: | parent::__construct($db, 'users', 'XoopsUser', 'uid', 'uname');
|
641: | }
|
642: |
|
643: | |
644: | |
645: | |
646: | |
647: | |
648: | |
649: |
|
650: | public function loginUser($uname, $pwd, $md5 = false)
|
651: | {
|
652: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated');
|
653: |
|
654: | return false;
|
655: | }
|
656: |
|
657: | |
658: | |
659: | |
660: | |
661: | |
662: | |
663: |
|
664: | public function updateUserByField($fieldName, $fieldValue, $uid)
|
665: | {
|
666: | $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated');
|
667: |
|
668: | return false;
|
669: | }
|
670: |
|
671: | }
|
672: | |