-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
209 lines (173 loc) · 5.07 KB
/
User.php
File metadata and controls
209 lines (173 loc) · 5.07 KB
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
<?php
/**
* Elite Dangerous Star Map
* @link https://www.edsm.net/
*/
namespace Component;
class User extends Instance
{
use \Component\User\Activity;
use \Component\User\Badge;
use \Component\User\Cargo;
use \Component\User\Credit;
use \Component\User\Data;
use \Component\User\Exploration;
use \Component\User\Faction;
use \Component\User\Friend;
use \Component\User\Guild;
use \Component\User\HoloMe;
use \Component\User\Locale;
use \Component\User\Material;
use \Component\User\Mission;
use \Component\User\Pin;
use \Component\User\Power;
use \Component\User\PublicProfile;
use \Component\User\Rank;
use \Component\User\Reputation;
use \Component\User\Role;
use \Component\User\Ship;
protected $_defaultModel = 'Models_Users';
protected $_primaryKey = 'id';
//TODO: Remove cache here
static protected $cache = null;
public function getSaltedPassword()
{
if(!$this->isValid())
{
return null;
}
return $this->getIdentity('password');
}
public function getCMDR()
{
if(!$this->isValid())
{
return 'Guest';
}
return $this->getIdentity('commanderName');
}
public function getEmail()
{
return $this->getIdentity('email');
}
public function getPlatform()
{
$platform = $this->getIdentity('platform');
// Stay compatible with the code, but need PC to catch the new UNIQUE index
if($platform == 'PC')
{
return null;
}
return $this->getIdentity('platform');
}
public function getConfirmationString()
{
return $this->getIdentity('confirmation_string');
}
public function havePassword()
{
$password = $this->getIdentity('password');
if(!is_null($password))
{
return true;
}
return false;
}
/**
* LINKED ACCOUNT
*/
protected $_linkedAccount = false;
public function getLinkedAccounts()
{
if($this->_linkedAccount === false)
{
$linkedAccounts = self::getModel('Models_Users_Links')->getByRefUser($this->getId());
$this->_linkedAccount = null;
if(!is_null($linkedAccounts))
{
$tempAccounts = array();
foreach($linkedAccounts AS $linkedAccount)
{
if($linkedAccount['confirmed'] == 1)
{
if($linkedAccount['refUser'] == $this->getId())
{
$tempUser = \Component\User::getInstance($linkedAccount['refLink']);
}
else
{
$tempUser = \Component\User::getInstance($linkedAccount['refUser']);
}
if($tempUser->isValid() && $tempUser->getRole() != 'guest')
{
if(!in_array($tempUser->getId(), $tempAccounts))
{
$tempAccounts[] = $tempUser->getId();
}
}
}
}
if(count($tempAccounts) > 0)
{
$this->_linkedAccount = $tempAccounts;
}
}
}
return $this->_linkedAccount;
}
/**
* API
*/
public function getApiKey()
{
if(!empty($this->getIdentity('apiKey')))
{
return $this->getIdentity('apiKey');
}
return null;
}
public function useNewJournalApi()
{
if($this->getIdentity('useNewJournalApi') == 1)
{
return true;
}
return false;
}
/**
* Generate a unique color based on user PRIMARY id
*
* @param type $minimumBrightness
* @param type $spec
* @return int
*/
public function getColor($minimumBrightness = 100, $spec = 10)
{
$spec = min(max(0, $spec), 10);
$minimumBrightness = min(max(0, $minimumBrightness), 255);
$hash = md5('EDSM' . $this->getId());
$colors = array();
//convert hash into 3 decimal values between 0 and 255
for($i = 0; $i < 3; $i++)
{
$colors[$i] = max(
array(
round(((hexdec(substr($hash, $spec * $i, $spec))) / hexdec(str_pad('', $spec, 'F'))) * 255),
$minimumBrightness
)
);
}
if($minimumBrightness > 0)
{
// Loop until brightness is above or equal to minimumBrightness
while((array_sum($colors) / 3) < $minimumBrightness)
{
for($i = 0; $i < 3; $i++)
{
$colors[$i] += 10; //increase each color by 10
}
}
}
return $colors;
}
}