-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser.php
117 lines (108 loc) · 2.99 KB
/
User.php
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
<?PHP
class User {
protected $id;
protected $nick;
protected $user;
protected $host;
protected $realName;
protected $modes;
protected $snomask;
protected $operFlags;
protected $servicesWhois;
protected $ip;
protected $virtualHost;
protected $server;
protected $account;
public static function newFromId( $id ) {
return self::newFrom( 'id', $id );
}
public static function newFromNick( $nick ) {
return self::newFrom( 'nick', $user );
}
protected static function newFrom( $field, $value ) {
$userData = MySQL::get( MySQL::sql( 'SELECT * FROM `nicks` WHERE `' . $field . '` = ' . MySQL::escape( $value ) . ' LIMIT 1' ) );
if( isset( $userData ) )
return new self(
$userData[ 'userid' ],
$userData[ 'nick' ],
$userData[ 'user' ],
$userData[ 'host' ],
$userData[ 'realname' ],
$userData[ 'modes' ],
$userData[ 'snomask' ],
$userData[ 'oflags' ],
$userData[ 'swhois' ],
$userData[ 'ip' ],
$userData[ 'vhost' ],
Server::newFromId( $userData[ 'servid' ] ),
Account::newFromId( $userData[ 'loggedin' ] )
);
return null;
}
protected function __construct( $id, $nick, $user, $host, $realName, $modes, $snomask, $operFlags, $servicesWhois, $ip, $virtualHost, $server, $account ) {
$this->id = $id;
$this->nick = $nick;
$this->user = $user;
$this->host = $host;
$this->realName = $realName;
$this->modes = $modes;
$this->snomask = $snomask;
$this->operFlags = $operFlags;
$this->servicesWhois = $servicesWhois;
$this->ip = $ip;
$this->virtualHost = $virtualHost;
$this->server = $server;
$this->account = $account;
}
public function __set( $name, $value ) {
switch( $name ) {
case 'id':
case 'ip':
case 'server':
throw new Exception( 'Cannot set ' . $name . 'property.' );
break;
case 'nick':
case 'user':
case 'host':
case 'realName':
case 'modes':
case 'snomask':
case 'servicesWhois':
case 'virtualHost':
$this->update( $name, $value );
break;
case 'account':
MySQL::sql( 'UPDATE `access` SET `loggedin` = ' . MySQL::escape( $value->id ) );
$this->account = $value;
break;
default:
throw new Exception( 'Unknown property: ' . $name );
}
}
public function __get( $name ) {
switch( $name ) {
case 'id':
case 'nick':
case 'user':
case 'host':
case 'realName':
//case 'gecos': -- I think this should be used instead of real name (preference; less typing) --SnoFox
case 'modes':
case 'snomask':
case 'operFlags':
case 'servicesWhois':
case 'ip':
case 'vhost':
case 'server':
case 'account':
return $this->$name;
default:
throw new Exception( 'No such property: ' . $name );
}
}
protected function update( $name, $value ) {
MySQL::sql( 'UPDATE `access` SET `' . $name . '` = ' . MySQL::escape( $value ) . ' WHERE `id` = ' . MySQL::escape( $this->id ) );
$this->$name = $value;
}
}
?>