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:
<?php
define('RANK_TYPE', 1);
define('GROUP_TYPE', 2);
define('USER_TYPE', 3);
class User
{
const ROBOT_LEVEL = -2;
const VISITOR_LEVEL = -1;
const MEMBER_LEVEL = 0;
const MODERATOR_LEVEL = 1;
const ADMIN_LEVEL = 2;
protected $id = -1;
protected $level = -1;
protected $groups = array();
protected $display_name;
protected $email;
protected $show_email = false;
protected $unread_pm = 0;
protected $locale;
protected $theme;
protected $timezone;
protected $editor;
protected $delay_banned = 0;
protected $delay_readonly = 0;
protected $warning_percentage = 0;
public function set_id($id)
{
$this->id = $id;
}
public function get_id()
{
return $this->id;
}
public function set_level($level)
{
$this->level = $level;
}
public function get_level()
{
return $this->level;
}
public function is_guest()
{
return $this->level == self::VISITOR_LEVEL;
}
public function is_robot()
{
return $this->level == self::ROBOT_LEVEL;
}
public function is_moderator()
{
return $this->level == self::MODERATOR_LEVEL;
}
public function is_admin()
{
return $this->level == self::ADMIN_LEVEL;
}
public function set_groups($groups)
{
if (!is_array($groups))
$groups = explode('|', $groups);
$this->groups = $groups;
}
public function get_groups()
{
return $this->groups;
}
public function set_display_name($display_name)
{
$this->display_name = $display_name;
}
public function get_display_name()
{
return $this->display_name;
}
public function set_email($email)
{
$this->email = $email;
}
public function get_email()
{
return $this->email;
}
public function set_show_email($show_email)
{
$this->show_email = $show_email;
}
public function get_show_email()
{
return $this->show_email;
}
public function set_unread_pm($unread_pm)
{
$this->unread_pm = $unread_pm;
}
public function get_unread_pm()
{
return $this->unread_pm;
}
public function set_locale($locale)
{
$this->locale = $locale;
}
public function get_locale()
{
if (!empty($this->locale))
{
return $this->locale;
}
return UserAccountsConfig::load()->get_default_lang();
}
public function set_theme($theme)
{
$this->theme = $theme;
}
public function get_theme()
{
if (!empty($this->theme))
{
return $this->theme;
}
return UserAccountsConfig::load()->get_default_theme();
}
public function set_timezone($timezone)
{
$this->timezone = $timezone;
}
public function get_timezone()
{
if (!empty($this->timezone))
{
return $this->timezone;
}
return GeneralConfig::load()->get_site_timezone();
}
public function set_editor($editor)
{
$this->editor = $editor;
}
public function get_editor()
{
if (!empty($this->editor))
{
return $this->editor;
}
return ContentFormattingConfig::load()->get_default_editor();
}
public function set_warning_percentage($warning_percentage)
{
$this->warning_percentage = $warning_percentage;
}
public function get_warning_percentage()
{
return $this->warning_percentage;
}
public function set_delay_banned($delay_banned)
{
$this->delay_banned = $delay_banned;
}
public function get_delay_banned()
{
return $this->delay_banned;
}
public function is_banned()
{
return (time() - $this->delay_banned) <= 0 || $this->warning_percentage >= '100';
}
public function set_delay_readonly($delay_readonly)
{
$this->delay_readonly = $delay_readonly;
}
public function get_delay_readonly()
{
return $this->delay_readonly;
}
public function is_readonly()
{
return (time() - $this->delay_readonly) <= 0;
}
public static function get_group_color($user_groups, $level = 0, $is_array = false)
{
if (!$is_array)
$user_groups = explode('|', $user_groups);
$i = 0;
$group_color = '';
$groups_cache = GroupsCache::load();
foreach ($user_groups as $idgroup)
{
if ($groups_cache->group_exists($idgroup))
{
$group = $groups_cache->get_group($idgroup);
$group_color = (!empty($group['color']) && $level == 0) ? (TextHelper::substr($group['color'], 0, 1) != '#' ? '#' : '') . $group['color'] : '';
}
}
return $group_color;
}
public function set_properties(array $properties)
{
$this->id = $properties['user_id'];
$this->level = $properties['level'];
$this->email = $properties['email'];
$this->show_email = $properties['show_email'];
$this->locale = $properties['locale'];
$this->theme = $properties['theme'];
$this->timezone = $properties['timezone'];
$this->editor = $properties['editor'];
$this->delay_banned = $properties['delay_banned'];
$this->delay_readonly = $properties['delay_readonly'];
$this->warning_percentage = $properties['warning_percentage'];
$this->display_name = $properties['display_name'];
$this->set_groups($properties['groups']);
}
public function init_robot_user($robot_name)
{
$this->set_properties(self::get_visitor_properties($robot_name, self::ROBOT_LEVEL));
}
public function init_visitor_user()
{
$this->set_properties(self::get_visitor_properties());
}
public static function get_visitor_properties($display_name = null, $level = self::VISITOR_LEVEL)
{
return array(
'user_id' => Session::VISITOR_SESSION_ID,
'display_name' => $display_name !== null ? $display_name : LangLoader::get_message('guest', 'main'),
'level' => $level,
'email' => null,
'show_email' => false,
'locale' => UserAccountsConfig::load()->get_default_lang(),
'theme' => UserAccountsConfig::load()->get_default_theme(),
'timezone' => GeneralConfig::load()->get_site_timezone(),
'editor' => ContentFormattingConfig::load()->get_default_editor(),
'unread_pm' => 0,
'registration_date' => 0,
'last_connection_date' => time(),
'groups' => '',
'warning_percentage' => 0,
'delay_banned' => 0,
'delay_readonly' => 0
);
}
}
?>