-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskin.php
350 lines (313 loc) · 14.7 KB
/
skin.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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
// Включение кэширования
function fetchJson($url, &$error = null) {
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true
]);
$response = curl_exec($ch);
if ($response === false) {
$error = "Ошибка подключения: " . curl_error($ch);
curl_close($ch);
return null;
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $headerSize);
$body = substr($response, $headerSize);
curl_close($ch);
} else {
$context = stream_context_create(['http' => ['ignore_errors' => true]]);
$response = @file_get_contents($url, false, $context);
if ($response === false) {
$error = "Ошибка подключения к серверу";
return null;
}
preg_match('/HTTP\/\d\.\d (\d{3})/', $http_response_header[0], $matches);
$statusCode = $matches[1];
$body = $response;
}
if ($statusCode != 200) {
$error = $statusCode == 404 ? "Пользователь не найден" : "Ошибка $statusCode";
return null;
}
return json_decode($body, true);
}
function getCache($key) {
$file = __DIR__ . '/cache/' . md5($key) . '.cache';
if (file_exists($file) && time() - filemtime($file) < 3600) {
return json_decode(file_get_contents($file), true);
}
return null;
}
function setCache($key, $data) {
if (!is_dir(__DIR__ . '/cache')) {
mkdir(__DIR__ . '/cache', 0755, true);
}
$file = __DIR__ . '/cache/' . md5($key) . '.cache';
file_put_contents($file, json_encode($data));
}
// Обработка темы
$theme = $_COOKIE['theme'] ?? 'light';
if(isset($_GET['theme'])) {
$theme = in_array($_GET['theme'], ['light', 'dark']) ? $_GET['theme'] : 'light';
setcookie('theme', $theme, time() + 86400 * 30, '/');
}
// Обработка запроса
$username = $_POST['username'] ?? null;
$userData = null;
$error = null;
if ($username) {
$username = trim($username);
if (!preg_match('/^[a-zA-Z0-9_]{3,16}$/u', $username)) {
$error = "Некорректный никнейм";
} else {
$cacheKey = "user_{$username}";
if ($cached = getCache($cacheKey)) {
$userData = $cached;
} else {
$profiles = fetchJson("https://authserver.ely.by/api/users/profiles/minecraft/{$username}", $error);
if ($profiles) {
$userData = [
'id' => $profiles['id'],
'uuid' => preg_replace(
'/(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})/',
'$1-$2-$3-$4-$5',
$profiles['id']
),
'name' => $profiles['name']
];
$skinInfo = fetchJson("https://skinsystem.ely.by/textures/{$username}", $error);
if ($skinInfo && isset($skinInfo['SKIN'])) {
$userData['skin'] = [
'url' => $skinInfo['SKIN']['url'],
'face' => "https://ely.by/services/skins-renderer?url=" .
urlencode($skinInfo['SKIN']['url']) .
"&scale=18.9&renderFace=1",
'render' => "https://ely.by/services/skins-renderer?url=" .
urlencode($skinInfo['SKIN']['url']) .
"&scale=8.65&slim=0"
];
}
if ($userData) setCache($cacheKey, $userData);
}
}
}
}
function esc($value) {
return htmlspecialchars($value ?? '', ENT_QUOTES, 'UTF-8');
}
?>
<!DOCTYPE html>
<html lang="ru" data-bs-theme="<?= $theme ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $userData ? "Скин " . esc($userData['name']) : "Поиск скина" ?> - Ely.by</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
:root {
--gradient-primary: linear-gradient(45deg, #4e73df, #224abe);
--gradient-success: linear-gradient(45deg, #1cc88a, #13855c);
}
a.rollover {
background-image: url("https://ely.by/services/skins-renderer?url=<?=
isset($userData['skin']) ? urlencode($userData['skin']['url']) : '' ?>&scale=8.65&slim=0&v=<?= time() ?>");
display: block;
width: 121px;
height: 276px;
background-position: -8px 0;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
a.rollover:hover {
background-position: -146px 0;
transform: scale(1.02);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}
.theme-switcher {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
.card-hover {
transition: transform 0.3s, box-shadow 0.3s;
}
.card-hover:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15) !important;
}
.gradient-primary {
background: var(--gradient-primary);
}
.gradient-success {
background: var(--gradient-success);
}
.loader {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(var(--bs-body-bg-rgb), 0.9);
z-index: 9999;
}
</style>
</head>
<body class="bg-body-secondary">
<div class="loader">
<div class="spinner-border text-primary" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Загрузка...</span>
</div>
</div>
<div class="theme-switcher">
<div class="btn-group shadow">
<a href="?theme=light" class="btn btn-<?= $theme === 'light' ? 'primary' : 'secondary' ?>">
<i class="fas fa-sun"></i>
</a>
<a href="?theme=dark" class="btn btn-<?= $theme === 'dark' ? 'primary' : 'secondary' ?>">
<i class="fas fa-moon"></i>
</a>
</div>
</div>
<div class="container py-5">
<h1 class="mb-4 text-center gradient-primary bg-clip-text text-transparent">
<i class="fas fa-search me-3"></i>Поиск скинов Ely.by
</h1>
<div class="card shadow-lg card-hover fade-in">
<div class="card-body">
<form method="POST" class="row g-3" id="searchForm">
<div class="col-12 col-md-8">
<div class="input-group input-group-lg">
<span class="input-group-text"><i class="fas fa-user"></i></span>
<input type="text"
name="username"
class="form-control"
placeholder="Введите ник игрока"
value="<?= esc($username) ?>"
pattern="[a-zA-Z0-9_]{3,16}"
title="Только буквы, цифры и подчёркивания (3-16 символов)"
required>
</div>
</div>
<div class="col-12 col-md-4">
<button type="submit" class="btn btn-primary btn-lg w-100">
<i class="fas fa-search me-2"></i> Найти
</button>
</div>
</form>
</div>
</div>
<?php if ($error): ?>
<div class="alert alert-danger fade-in mt-4">
<?= esc($error) ?>
<button onclick="history.back()" class="btn btn-link float-end">
<i class="fas fa-arrow-left me-2"></i>Назад
</button>
</div>
<?php elseif ($userData): ?>
<div class="row g-4 mt-4 fade-in">
<div class="col-12 col-lg-4">
<div class="card shadow-lg h-100 card-hover">
<div class="card-header gradient-primary text-white">
<h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>Основная информация</h5>
</div>
<div class="card-body">
<dl class="mb-0">
<dt>Никнейм</dt>
<dd><?= esc($userData['name']) ?></dd>
<dt class="mt-3">UUID</dt>
<dd><code class="text-break"><?= esc($userData['uuid']) ?></code></dd>
<dt class="mt-3">URL текстуры</dt>
<dd>
<code class="text-break">
<?= isset($userData['skin']) ? esc($userData['skin']['url']) : 'Недоступно' ?>
</code>
</dd>
</dl>
</div>
</div>
</div>
<div class="col-12 col-lg-8">
<div class="card shadow-lg card-hover">
<div class="card-header gradient-success text-white">
<h5 class="mb-0"><i class="fas fa-palette me-2"></i>Внешний вид</h5>
</div>
<div class="card-body">
<div class="row g-4 text-center">
<div class="col-12 col-sm-4">
<h5>Голова</h5>
<img src="<?= isset($userData['skin']) ? esc($userData['skin']['face']) : 'https://ely.by/images/skins/steve-face.png' ?>"
class="img-fluid shadow"
style="width: 150px; height: 150px;">
</div>
<div class="col-12 col-sm-4">
<h5>3D Превью</h5>
<div class="d-inline-block position-relative">
<a href='https://ely.by/skins?uploader=<?= esc($userData['name']) ?>'
target='_blank'
class='rollover'></a>
<div class="position-absolute bottom-0 start-0 end-0 p-2 bg-dark bg-opacity-75 text-white small">
Кликните для просмотра
</div>
</div>
</div>
<div class="col-12 col-sm-4">
<h5>Текстура</h5>
<?php if (isset($userData['skin'])): ?>
<a href="<?= esc($userData['skin']['url']) ?>"
target="_blank"
class="d-block mb-3">
<img src="<?= esc($userData['skin']['url']) ?>"
class="img-fluid rounded shadow">
</a>
<a href="https://ely.by/skins?uploader=<?= urlencode($userData['name']) ?>"
target="_blank"
class="btn btn-sm btn-outline-primary">
<i class="fas fa-history me-2"></i>История скинов
</a>
<?php else: ?>
<div class="text-muted">Скин не найден</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Сохранение положения скролла
const scrollPos = sessionStorage.getItem('scrollPos');
if(scrollPos) window.scrollTo(0, scrollPos);
// Обработка отправки формы
document.getElementById('searchForm').addEventListener('submit', () => {
sessionStorage.setItem('scrollPos', window.pageYOffset);
document.querySelector('.loader').style.display = 'flex';
});
// Инициализация анимаций
document.querySelectorAll('.fade-in').forEach(el => {
el.style.opacity = 0;
setTimeout(() => el.style.opacity = 1, 100);
});
// Предотвращение мерцания темы
const savedTheme = localStorage.getItem('theme');
if(savedTheme) {
document.documentElement.setAttribute('data-bs-theme', savedTheme);
}
});
</script>
</body>
</html>