|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package CleverStyle Framework |
|
4
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
|
5
|
|
|
* @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi |
|
6
|
|
|
* @license MIT License, see license.txt |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace cs\User; |
|
9
|
|
|
use |
|
10
|
|
|
cs\User; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class for getting of user information |
|
14
|
|
|
* |
|
15
|
|
|
* @property int $id |
|
16
|
|
|
* @property string $login |
|
17
|
|
|
* @property string $login_hash sha224 hash |
|
18
|
|
|
* @property string $username |
|
19
|
|
|
* @property string $password_hash sha512 hash |
|
20
|
|
|
* @property string $email |
|
21
|
|
|
* @property string $email_hash sha224 hash |
|
22
|
|
|
* @property string $language |
|
23
|
|
|
* @property string $timezone |
|
24
|
|
|
* @property int $reg_date unix timestamp |
|
25
|
|
|
* @property string $reg_ip hex value, obtained by function ip2hex() |
|
26
|
|
|
* @property string $reg_key random md5 hash, generated during registration |
|
27
|
|
|
* @property int $status '-1' - not activated (for example after registration), 0 - inactive, 1 - active |
|
28
|
|
|
* @property int $block_until unix timestamp |
|
29
|
|
|
* @property string $avatar |
|
30
|
|
|
*/ |
|
31
|
|
|
class Properties { |
|
32
|
|
|
/** |
|
33
|
|
|
* @var int |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $id; |
|
36
|
|
|
/** |
|
37
|
|
|
* Creating of object and saving user id inside |
|
38
|
|
|
* |
|
39
|
|
|
* @param int $user |
|
40
|
|
|
*/ |
|
41
|
2 |
|
function __construct ($user) { |
|
42
|
2 |
|
$this->id = $user; |
|
43
|
2 |
|
} |
|
44
|
|
|
/** |
|
45
|
|
|
* Get data item of user |
|
46
|
|
|
* |
|
47
|
|
|
* @param string|string[] $item |
|
48
|
|
|
* |
|
49
|
|
|
* @return false|string|mixed[] |
|
50
|
|
|
*/ |
|
51
|
2 |
|
function get ($item) { |
|
52
|
2 |
|
return User::instance()->get($item, $this->id); |
|
53
|
|
|
} |
|
54
|
|
|
/** |
|
55
|
|
|
* Set data item of specified user |
|
56
|
|
|
* |
|
57
|
|
|
* @param array|string $item |
|
58
|
|
|
* @param mixed|null $value |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool |
|
61
|
|
|
*/ |
|
62
|
2 |
|
function set ($item, $value = null) { |
|
63
|
2 |
|
return User::instance()->set($item, $value, $this->id); |
|
64
|
|
|
} |
|
65
|
|
|
/** |
|
66
|
|
|
* Get data item of user |
|
67
|
|
|
* |
|
68
|
|
|
* @param string|string[] $item |
|
69
|
|
|
* |
|
70
|
|
|
* @return array|false|string |
|
71
|
|
|
*/ |
|
72
|
2 |
|
function __get ($item) { |
|
73
|
2 |
|
return User::instance()->get($item, $this->id); |
|
74
|
|
|
} |
|
75
|
|
|
/** |
|
76
|
|
|
* Get user avatar, if no one present - uses Gravatar |
|
77
|
|
|
* |
|
78
|
|
|
* @param int|null $size Avatar size, if not specified or resizing is not possible - original image is used |
|
79
|
|
|
* |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
2 |
|
function avatar ($size = null) { |
|
83
|
2 |
|
return User::instance()->avatar($size, $this->id); |
|
84
|
|
|
} |
|
85
|
|
|
/** |
|
86
|
|
|
* Get user name or login or email, depending on existing information |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
2 |
|
function username () { |
|
91
|
2 |
|
return $this->get('username') ?: ($this->get('login') ?: $this->get('email')); |
|
92
|
|
|
} |
|
93
|
|
|
/** |
|
94
|
|
|
* Set data item of user |
|
95
|
|
|
* |
|
96
|
|
|
* @param array|string $item |
|
97
|
|
|
* @param mixed|null $value |
|
98
|
|
|
*/ |
|
99
|
2 |
|
function __set ($item, $value = null) { |
|
100
|
2 |
|
User::instance()->set($item, $value, $this->id); |
|
101
|
2 |
|
} |
|
102
|
|
|
/** |
|
103
|
|
|
* Getting additional data item(s) of specified user |
|
104
|
|
|
* |
|
105
|
|
|
* @param string|string[] $item |
|
106
|
|
|
* |
|
107
|
|
|
* @return false|string|mixed[] |
|
108
|
|
|
*/ |
|
109
|
2 |
|
function get_data ($item) { |
|
110
|
2 |
|
return User::instance()->get_data($item, $this->id); |
|
111
|
|
|
} |
|
112
|
|
|
/** |
|
113
|
|
|
* Setting additional data item(s) of specified user |
|
114
|
|
|
* |
|
115
|
|
|
* @param array|string $item |
|
116
|
|
|
* @param mixed|null $value |
|
117
|
|
|
* |
|
118
|
|
|
* @return bool |
|
119
|
|
|
*/ |
|
120
|
2 |
|
function set_data ($item, $value = null) { |
|
121
|
2 |
|
return User::instance()->set_data($item, $value, $this->id); |
|
122
|
|
|
} |
|
123
|
|
|
/** |
|
124
|
|
|
* Deletion of additional data item(s) of specified user |
|
125
|
|
|
* |
|
126
|
|
|
* @param string|string[] $item |
|
127
|
|
|
* |
|
128
|
|
|
* @return bool |
|
129
|
|
|
*/ |
|
130
|
2 |
|
function del_data ($item) { |
|
131
|
2 |
|
return User::instance()->del_data($item, $this->id); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|