1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 04.12.2017 4:20 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
global $nickSorting; |
|
|
|
|
7
|
|
|
$nickSorting = [ |
8
|
|
|
NICK_HTML, |
9
|
|
|
|
10
|
|
|
NICK_FIRST, |
11
|
|
|
|
12
|
|
|
NICK_RACE, |
13
|
|
|
NICK_GENDER, |
14
|
|
|
NICK_AWARD, |
15
|
|
|
NICK_VACATION, |
16
|
|
|
NICK_BIRTHSDAY, |
17
|
|
|
NICK_PREMIUM, |
18
|
|
|
NICK_AUTH_LEVEL, |
19
|
|
|
|
20
|
|
|
NICK_HIGHLIGHT, |
21
|
|
|
NICK_CLASS, |
22
|
|
|
NICK_NICK_CLASS, |
23
|
|
|
NICK_NICK, |
24
|
|
|
NICK_NICK_CLASS_END, |
25
|
|
|
NICK_ALLY_CLASS, |
26
|
|
|
NICK_ALLY, |
27
|
|
|
NICK_ALLY_CLASS_END, |
28
|
|
|
NICK_CLASS_END, |
29
|
|
|
NICK_HIGHLIGHT_END, |
30
|
|
|
|
31
|
|
|
NICK_LAST, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Ordering nick parts according to predefined part order |
36
|
|
|
* |
37
|
|
|
* @param array $array |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
function playerNickOrder($array) { |
42
|
|
|
global $nickSorting; |
|
|
|
|
43
|
|
|
|
44
|
|
|
$result = []; |
45
|
|
|
// Rearranging nick parts according to sort array |
46
|
|
|
foreach ($nickSorting as $nickPartId) { |
47
|
|
|
if (array_key_exists($nickPartId, $array)) { |
48
|
|
|
$result[$nickPartId] = $array[$nickPartId]; |
49
|
|
|
unset($array[$nickPartId]); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Adding what left of nick parts to resulting array |
54
|
|
|
return array_merge($result, $array); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Может принимать: (array)$user, $nick_render_array, $nick_render_array_html, $nick_render_string_compact |
|
|
|
|
58
|
|
|
function player_nick_render_to_html($result, $options = false) { |
59
|
|
|
$result = player_nick_uncompact($result); |
60
|
|
|
|
61
|
|
|
if (is_array($result)) { |
62
|
|
|
if (isset($result['id'])) { |
63
|
|
|
$result = player_nick_render_current_to_array($result, $options); |
64
|
|
|
} |
65
|
|
|
if (!isset($result[NICK_HTML])) { |
66
|
|
|
$result = player_nick_render_array_to_html($result); |
67
|
|
|
} |
68
|
|
|
unset($result[NICK_HTML]); |
69
|
|
|
$result = implode('', playerNickOrder($result)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Pack nick parts to string |
77
|
|
|
* |
78
|
|
|
* @param array $nick_array |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
function player_nick_compact($nick_array) { |
83
|
|
|
return json_encode(playerNickOrder($nick_array)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Unpacks nick parts from string - if necessary |
88
|
|
|
* |
89
|
|
|
* @param array|string $nick_string |
90
|
|
|
* |
91
|
|
|
* @return array|string |
92
|
|
|
*/ |
93
|
|
|
function player_nick_uncompact($nick_string) { |
94
|
|
|
$result = $nick_string; |
95
|
|
|
if (is_string($nick_string) && strpos($nick_string, '{"') === 0) { |
96
|
|
|
$result = json_decode($nick_string, true); |
97
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) { |
98
|
|
|
$result = $nick_string; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $result; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
function player_nick_render_array_to_html($nick_array) { |
106
|
|
|
$result = null; |
107
|
|
|
|
108
|
|
|
return sn_function_call('player_nick_render_array_to_html', array($nick_array, &$result)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $nick_array |
113
|
|
|
* @param array $result |
114
|
|
|
* |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
|
|
function sn_player_nick_render_array_to_html($nick_array, &$result) { |
118
|
|
|
static $iconCache = array(); |
119
|
|
|
|
120
|
|
|
if (empty($iconCache['gender_' . $nick_array[NICK_GENDER]])) { |
121
|
|
|
$iconCache['gender_' . $nick_array[NICK_GENDER]] = classSupernova::$gc->skinModel->getImageCurrent("gender_{$nick_array[NICK_GENDER]}|html"); |
122
|
|
|
$iconCache['icon_vacation'] = classSupernova::$gc->skinModel->getImageCurrent('icon_vacation|html'); |
123
|
|
|
$iconCache['icon_birthday'] = classSupernova::$gc->skinModel->getImageCurrent('icon_birthday|html'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// ALL STRING ARE UNSAFE!!! |
127
|
|
|
if (isset($nick_array[NICK_BIRTHSDAY])) { |
128
|
|
|
$result[NICK_BIRTHSDAY] = $iconCache['icon_birthday']; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if (isset($nick_array[NICK_VACATION])) { |
132
|
|
|
$result[NICK_VACATION] = $iconCache['icon_vacation']; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if (isset($nick_array[NICK_GENDER])) { |
136
|
|
|
$result[NICK_GENDER] = $iconCache['gender_' . $nick_array[NICK_GENDER]]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$highlight = null; |
140
|
|
|
if (isset($nick_array[NICK_PREMIUM])) { |
141
|
|
|
$highlight = classSupernova::$config->chat_highlight_premium; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if (isset($nick_array[NICK_AUTH_LEVEL])) { |
145
|
|
|
switch ($nick_array[NICK_AUTH_LEVEL]) { |
146
|
|
|
case 4: |
147
|
|
|
$highlight = classSupernova::$config->chat_highlight_developer; |
|
|
|
|
148
|
|
|
break; |
149
|
|
|
|
150
|
|
|
case 3: |
151
|
|
|
$highlight = classSupernova::$config->chat_highlight_admin; |
|
|
|
|
152
|
|
|
break; |
153
|
|
|
|
154
|
|
|
case 2: |
155
|
|
|
$highlight = classSupernova::$config->chat_highlight_operator; |
|
|
|
|
156
|
|
|
break; |
157
|
|
|
|
158
|
|
|
case 1: |
159
|
|
|
$highlight = classSupernova::$config->chat_highlight_moderator; |
|
|
|
|
160
|
|
|
break; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
if ($highlight) { |
166
|
|
|
list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
if (isset($nick_array[NICK_CLASS])) { |
170
|
|
|
$result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] . '>'; |
171
|
|
|
$result[NICK_CLASS_END] = '</span>'; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]); |
175
|
|
|
|
176
|
|
|
if (isset($nick_array[NICK_ALLY])) { |
177
|
|
|
$result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']'; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$result[NICK_HTML] = true; |
181
|
|
|
|
182
|
|
|
return $result; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param array $render_user |
187
|
|
|
* @param array|bool $options - [ |
188
|
|
|
* 'color' => true, |
189
|
|
|
* 'icons' => true, |
190
|
|
|
* 'gender' => true, |
191
|
|
|
* 'birthday' => true, |
192
|
|
|
* 'ally' => true, |
193
|
|
|
* ] |
194
|
|
|
* |
195
|
|
|
* @return mixed |
196
|
|
|
*/ |
197
|
|
|
function player_nick_render_current_to_array($render_user, $options = false) { |
198
|
|
|
$result = null; |
199
|
|
|
|
200
|
|
|
return sn_function_call('player_nick_render_current_to_array', array($render_user, $options, &$result)); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param array $render_user |
205
|
|
|
* @param array|bool $options - [ |
206
|
|
|
* 'color' => true, |
207
|
|
|
* 'icons' => true, |
208
|
|
|
* 'gender' => true, |
209
|
|
|
* 'birthday' => true, |
210
|
|
|
* 'ally' => true, |
211
|
|
|
* ] |
212
|
|
|
* @param array $result |
213
|
|
|
* |
214
|
|
|
* @return mixed |
215
|
|
|
*/ |
216
|
|
|
function sn_player_nick_render_current_to_array($render_user, $options = false, &$result) { |
217
|
|
|
/* |
|
|
|
|
218
|
|
|
$options = $options !== true ? $options : |
219
|
|
|
array( |
220
|
|
|
'color' => true, |
221
|
|
|
'icons' => true, |
222
|
|
|
'gender' => true, |
223
|
|
|
'birthday' => true, |
224
|
|
|
'ally' => true, |
225
|
|
|
); |
226
|
|
|
*/ |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
if ($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
230
|
|
|
$result[NICK_BIRTHSDAY] = ''; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
if ($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
234
|
|
|
$result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
if (($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
|
|
|
238
|
|
|
$result[NICK_VACATION] = $render_user['vacation']; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
if ($options === true || (isset($options['color']) && $options['color'])) { |
242
|
|
|
if ($user_auth_level = $render_user['authlevel']) { |
243
|
|
|
$result[NICK_AUTH_LEVEL] = $user_auth_level; |
244
|
|
|
} |
245
|
|
|
if ($user_premium = mrc_get_level($render_user, false, UNIT_PREMIUM)) { |
|
|
|
|
246
|
|
|
$result[NICK_PREMIUM] = $user_premium; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if ((isset($options['class']) && $options['class'])) { |
251
|
|
|
$result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class']; |
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
if ($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
255
|
|
|
$result[NICK_ALLY] = $render_user['ally_tag']; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
$result[NICK_NICK] = $render_user['username']; |
259
|
|
|
|
260
|
|
|
return $result; |
261
|
|
|
} |
262
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.