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