1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333:
<?php
defined('ICMS_ROOT_PATH') or exit();
class icms_member_user_Object extends icms_core_Object {
private $_groups = array();
static private $_isAdmin = array();
private $_rank = null;
private $_isOnline = null;
public function __construct($id = null) {
$this->initVar('uid', XOBJ_DTYPE_INT, null, false);
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 60);
$this->initVar('uname', XOBJ_DTYPE_TXTBOX, null, true, 255);
$this->initVar('email', XOBJ_DTYPE_TXTBOX, null, true, 60);
$this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false, 255);
$this->initVar('user_avatar', XOBJ_DTYPE_TXTBOX, null, false, 30);
$this->initVar('user_regdate', XOBJ_DTYPE_INT, null, false);
$this->initVar('user_icq', XOBJ_DTYPE_TXTBOX, null, false, 15);
$this->initVar('user_from', XOBJ_DTYPE_TXTBOX, null, false, 100);
$this->initVar('user_sig', XOBJ_DTYPE_TXTAREA, null, false, null);
$this->initVar('user_viewemail', XOBJ_DTYPE_INT, 0, false);
$this->initVar('actkey', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('user_aim', XOBJ_DTYPE_TXTBOX, null, false, 18);
$this->initVar('user_yim', XOBJ_DTYPE_TXTBOX, null, false, 25);
$this->initVar('user_msnm', XOBJ_DTYPE_TXTBOX, null, false, 100);
$this->initVar('pass', XOBJ_DTYPE_TXTBOX, null, false, 255);
$this->initVar('posts', XOBJ_DTYPE_INT, null, false);
$this->initVar('attachsig', XOBJ_DTYPE_INT, 0, false);
$this->initVar('rank', XOBJ_DTYPE_INT, 0, false);
$this->initVar('level', XOBJ_DTYPE_TXTBOX, 0, false);
$this->initVar('theme', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('timezone_offset', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('last_login', XOBJ_DTYPE_INT, 0, false);
$this->initVar('umode', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('uorder', XOBJ_DTYPE_INT, 1, false);
$this->initVar('notify_method', XOBJ_DTYPE_INT, 1, false);
$this->initVar('notify_mode', XOBJ_DTYPE_INT, 0, false);
$this->initVar('user_occ', XOBJ_DTYPE_TXTBOX, null, false, 100);
$this->initVar('bio', XOBJ_DTYPE_TXTAREA, null, false, null);
$this->initVar('user_intrest', XOBJ_DTYPE_TXTBOX, null, false, 150);
$this->initVar('user_mailok', XOBJ_DTYPE_INT, 1, false);
$this->initVar('language', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('pass_expired', XOBJ_DTYPE_INT, 0, false);
$this->initVar('login_name', XOBJ_DTYPE_TXTBOX, null, true, 255);
if (isset($id)) {
if (is_array($id)) {
$this->assignVars($id);
} else {
$member_handler = icms::handler('icms_member');
$user =& $member_handler->getUser($id);
foreach ($user->vars as $k => $v) {
$this->assignVar($k, $v['value']);
}
}
}
}
public function isGuest() {
return false;
}
static public function getUnameFromId($userid, $usereal = 0) {
$userid = (int) $userid;
$usereal = (int) $usereal;
if ($userid > 0) {
$member_handler = icms::handler('icms_member');
$user =& $member_handler->getUser($userid);
if (is_object($user)) {
if ($usereal) {
$name = $user->getVar('name');
if ($name != '') {
return icms_core_DataFilter::htmlSpecialChars($name);
} else {
return icms_core_DataFilter::htmlSpecialChars($user->getVar('uname'));
}
} else {
return icms_core_DataFilter::htmlSpecialChars($user->getVar('uname'));
}
}
}
return $GLOBALS['icmsConfig']['anonymous'];
}
public function setGroups($groupsArr) {
if (is_array($groupsArr)) {
$this->_groups =& $groupsArr;
}
}
public function sendWelcomeMessage() {
global $icmsConfig, $icmsConfigUser;
if (!$icmsConfigUser['welcome_msg']) return true;
$xoopsMailer = new icms_messaging_Handler();
$xoopsMailer->useMail();
$xoopsMailer->setBody($icmsConfigUser['welcome_msg_content']);
$xoopsMailer->assign('UNAME', $this->getVar('uname'));
$user_email = $this->getVar('email');
$xoopsMailer->assign('X_UEMAIL', $user_email);
$xoopsMailer->setToEmails($user_email);
$xoopsMailer->setFromEmail($icmsConfig['adminmail']);
$xoopsMailer->setFromName($icmsConfig['sitename']);
$xoopsMailer->setSubject(sprintf(_US_YOURREGISTRATION, icms_core_DataFilter::stripSlashesGPC($icmsConfig['sitename'])));
if (!$xoopsMailer->send(true)) {
$this->setErrors(_US_WELCOMEMSGFAILED);
return false;
} else {
return true;
}
}
public function newUserNotifyAdmin() {
global $icmsConfigUser, $icmsConfig;
if ($icmsConfigUser['new_user_notify'] == 1 && !empty($icmsConfigUser['new_user_notify_group'])) {
$member_handler = icms::handler('icms_member');
$xoopsMailer = new icms_messaging_Handler();
$xoopsMailer->useMail();
$xoopsMailer->setTemplate('newuser_notify.tpl');
$xoopsMailer->assign('UNAME', $this->getVar('uname'));
$xoopsMailer->assign('EMAIL', $this->getVar('email'));
$xoopsMailer->setToGroups($member_handler->getGroup($icmsConfigUser['new_user_notify_group']));
$xoopsMailer->setFromEmail($icmsConfig['adminmail']);
$xoopsMailer->setFromName($icmsConfig['sitename']);
$xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT, $icmsConfig['sitename']));
if (!$xoopsMailer->send(true)) {
$this->setErrors(_US_NEWUSERNOTIFYADMINFAIL);
return false;
} else {
return true;
}
} else {
return true;
}
}
public function &getGroups() {
if (empty($this->_groups)) {
$member_handler = icms::handler('icms_member');
$this->_groups =& $member_handler->getGroupsByUser($this->getVar('uid'));
}
return $this->_groups;
}
public function isAdmin($module_id = null) {
static $buffer = array();
if (is_null($module_id)) {
$module_id = isset($GLOBALS['xoopsModule']) ? $GLOBALS['xoopsModule']->getVar('mid', 'n') : 1;
} elseif((int) $module_id < 1) {$module_id = 0;}
if (!isset($buffer[$module_id])) {
$moduleperm_handler = icms::handler('icms_member_groupperm');
$buffer[$module_id] = $moduleperm_handler->checkRight('module_admin', $module_id, $this->getGroups());
}
return $buffer[$module_id];
}
public function rank() {
if (!isset($this->_rank)) {
$this->_rank = icms_getModuleHandler("userrank", "system")->getRank($this->getVar('rank'), $this->getVar('posts'));
}
return $this->_rank;
}
public function isActive() {
if ($this->getVar('level') <= 0) {return false;}
return true;
}
public function isOnline() {
if (!isset($this->_isOnline)) {
$onlinehandler = icms::handler('icms_core_Online');
$this->_isOnline =
($onlinehandler->getCount(new icms_db_criteria_Item('online_uid', $this->getVar('uid'))) > 0)
? true
: false;
}
return $this->_isOnline;
}
public function gravatar($rating = false, $size = false, $default = false, $border = false, $overwrite = false) {
if (!$overwrite && is_file(ICMS_UPLOAD_PATH . '/' . $this->getVar('user_avatar')) && $this->getVar('user_avatar') != 'blank.gif') {
return ICMS_UPLOAD_URL . '/' . $this->getVar('user_avatar');
}
$ret = icms::$urls['http'] . "www.gravatar.com/avatar/" . md5(strtolower($this->getVar('email', 'E'))) . "?d=identicon";
if ($rating && $rating != '') {$ret .= "&rating=" . $rating;}
if ($size && $size != '') {$ret .="&size=" . $size;}
if ($default && $default != '') {$ret .= "&default=" . urlencode($default);}
if ($border && $border != '') {$ret .= "&border=" . $border;}
return $ret;
}
}