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