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
|
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; global $isLowerLoggedIn; global $app;
$parts = explode("/", $_GET["_"]);
if (!isset($parts[2])) {
peh_error("System member not found", 404);
return;
}
if (getMemberWithoutSystem($parts[2]) === null) {
peh_error("System member not found", 404);
return;
}
$member = getMemberWithoutSystem($parts[2]);
if ($isLowerLoggedIn && $member["_system"] !== $app["other"]["id"] && $member["_system"] !== "hrbom") {
peh_error("System member not found", 404);
return;
}
$title = ($member["display_name"] ?? $member["name"]) . " · " . $title;
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';
$member = getMemberWithoutSystem($parts[2]);
?>
<br>
<div class="container">
<div id="page-content">
<h2>Pony Town uploader for <?= $member["display_name"] ?? $member["name"] ?></h2>
<?php if (isset($_GET["updated"])): ?>
<div class="alert alert-success">Successfully uploaded a new Pony Town character for this member, it may take a few minutes to update across the website.</div>
<?php endif; ?>
<div style="display: grid; grid-template-columns: repeat(2, 1fr); grid-gap: 20px; margin-top: 15px;">
<div class="card">
<div class="card-body">
<h3>Current version</h3>
<div style="display: grid; grid-template-columns: repeat(2, 1fr); grid-gap: 10px;">
<div style="display: flex; align-items: center; justify-content: center;">
<img src="data:image/png;base64,<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png") ? base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png")) : "" ?>" style="width: 100%; border: 1px dashed rgba(255, 255, 255, .5); border-radius: 10px;">
</div>
<div style="display: flex; align-items: center; justify-content: center;">
<img src="data:image/png;base64,<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png") ? base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png")) : (file_exists($_SERVER['DOCUMENT_ROOT'] . getAsset($member["_system"], $member["id"], "heads")) ? base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . getAsset($member["_system"], $member["id"], "heads"))) : "") ?>" style="width: 100%; border: 1px dashed rgba(255, 255, 255, .5); border-radius: 10px;">
</div>
</div>
<?php
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png")) {
$info = getimagesize($_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png");
} else {
$info = [null, 61];
}
if ($info[1] > 60): ?>
<p class="text-warning" style="margin-top: 15px; margin-bottom: 0; text-align: center;"><b>This Pony Town character needs to be updated.</b><br>Ponycule now relies on pixel-perfect versions of one's Pony Town character to work properly, and the current character for this member is not compliant or non-existant.</p>
<?php endif; ?>
</div>
</div>
<div class="card">
<div class="card-body">
<h3>Upload a new version</h3>
<div id="uploader">
<ol>
<li>Open Pony Town [<a href="https://pony.town/" target="_blank">main</a>, <a href="https://event.pony.town/" target="_blank">event</a>, <a href="https://eventblue.pony.town/" target="_blank">eventblue</a>, <a href="https://eventgreen.pony.town/" target="_blank">eventgreen</a>, <a href="https://breezy.pony.town/" target="_blank">breezy</a>, <a href="https://building.pony.town/" target="_blank">building</a>], login if needed, and select the right pony</li>
<li>Click on <img class="antialias" alt="edit" src="/assets/editor/ponytown/step1.png" style="height: 2rem;"></li>
<li>Focus on <img class="antialias" alt="Export" src="/assets/editor/ponytown/step2.png" style="height: 2rem;"> and click on <img class="antialias" alt="Image export zoom" src="/assets/editor/ponytown/step2b.png" style="height: 2rem;"></li>
<li>In the menu, select <img class="antialias" alt="1x" src="/assets/editor/ponytown/step3.png" style="height: 2rem;"></li>
<li>Click on <img class="antialias" alt="Image export settings" src="/assets/editor/ponytown/step4.png" style="height: 2rem;"> and uncheck everything, like this:<br><img class="antialias" alt="[all settings unchecked]" src="/assets/editor/ponytown/step4b.png" style="width: 25%;"></li>
<li>Click on <img class="antialias" alt="PNG" src="/assets/editor/ponytown/step5.png" style="height: 2rem;"> and download the file to your device</li>
<li>Upload this file here (yes this is a button):<br><input type="file" id="file-uploader"></li>
<li>Go back to Pony Town, click on <img class="antialias" alt="Image export settings" src="/assets/editor/ponytown/step4.png" style="height: 2rem;"> again</li>
<li>Check "Head only", and nothing else, like this:<br><img class="antialias" alt="[Head only checked]" src="/assets/editor/ponytown/step9.png" style="width: 25%;"></li>
<li>Click on <img class="antialias" alt="PNG" src="/assets/editor/ponytown/step5.png" style="height: 2rem;"> once again and download the file to your device</li>
<li>Upload this file (the second one) here (yes this is also a button):<br><input type="file" id="file-uploader2"></li>
<li>We will check if you used the correct settings and save it if everything is good.</li>
</ol>
</div>
<div id="checker" style="display: none;">
<img src="/assets/editor/load.svg" style="width: 36px;"><span style="vertical-align: middle;" id="checker-message">Reading files...</span>
</div>
<div id="error" style="display: none;">
<p>Hmm, I don't think this is working! Check the errors below and try again:</p>
<ul id="errors"></ul>
<span class="btn btn-primary" onclick="upload();">Back</span>
</div>
<div id="confirm" style="display: none;">
<div style="display: grid; grid-template-columns: repeat(2, 1fr); grid-gap: 10px;">
<div style="display: flex; align-items: center; justify-content: center;">
<img id="confirm-preview-1" style="width: 100%; border: 1px dashed rgba(255, 255, 255, .5); border-radius: 10px;">
</div>
<div style="display: flex; align-items: center; justify-content: center;">
<img id="confirm-preview-2" style="width: 100%; border: 1px dashed rgba(255, 255, 255, .5); border-radius: 10px;">
</div>
</div>
<div style="margin-top: 10px;">
<span class="btn btn-primary" onclick="uploadActual();">Upload</span>
<span class="btn btn-outline-primary" onclick='document.getElementById("file-uploader").value = "";document.getElementById("file-uploader2").value = "";upload();'>Cancel</span>
</div>
</div>
</div>
</div>
<script>
function errors(list) {
document.getElementById("file-uploader").value = "";
document.getElementById("file-uploader2").value = "";
document.getElementById("uploader").style.display = "none";
document.getElementById("error").style.display = "";
document.getElementById("checker").style.display = "none";
document.getElementById("confirm").style.display = "none";
document.getElementById("errors").innerHTML = `<li>${list.map(i => i.replaceAll("<", "<").replaceAll(">", ">")).join("</li><li>")}</li>`;
}
let files = [
null,
null
];
function uploadCandidate() {
if (files[0] && files[1]) {
document.getElementById("checker-message").innerText = "Uploading files for review...";
let data = JSON.stringify(files);
if (data.length > 1024 ** 2) {
errors(["0xFF000001: The data being sent to the server is too large, your images are huge!"]);
return;
}
window.fetch("/api/ponytown/?id=<?= $member["id"] ?>", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: data
}).then((res) => {
res.json().then((data) => {
document.getElementById("checker-message").innerText = "Processing response...";
console.log(data);
if (data.success) {
document.getElementById("confirm-preview-1").src = files[0];
document.getElementById("confirm-preview-2").src = files[1];
document.getElementById("uploader").style.display = "none";
document.getElementById("checker").style.display = "none";
document.getElementById("confirm").style.display = "";
document.getElementById("error").style.display = "none";
} else {
errors(data.errors);
}
})
})
}
}
function uploadActual() {
if (files[0] && files[1]) {
document.getElementById("checker-message").innerText = "Uploading final files...";
let data = JSON.stringify(files);
if (data.length > 1024 ** 2) {
errors(["0xFF000001: The data being sent to the server is too large, your images are huge!"]);
return;
}
window.fetch("/api/ponytown/?id=<?= $member["id"] ?>&real", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: data
}).then((res) => {
res.json().then((data) => {
document.getElementById("checker-message").innerText = "Processing response...";
console.log(data);
if (data.success) {
document.getElementById("checker-message").innerText = "Reloading...";
location.href = "/-/ponytown/<?= $member["id"] ?>/?updated";
} else {
errors(data.errors);
}
})
})
}
}
document.getElementById("file-uploader").onchange = document.getElementById("file-uploader2").onchange = upload = () => {
files = [
null,
null
];
if (document.getElementById("file-uploader").files.length >= 1 && document.getElementById("file-uploader2").files.length >= 1) {
document.getElementById("errors").innerHTML = "";
document.getElementById("uploader").style.display = "none";
document.getElementById("checker").style.display = "";
document.getElementById("confirm").style.display = "none";
document.getElementById("error").style.display = "none";
let file1 = document.getElementById("file-uploader").files[0];
let file2 = document.getElementById("file-uploader2").files[0];
let reader1 = new FileReader();
let reader2 = new FileReader();
reader1.readAsDataURL(file1);
reader2.readAsDataURL(file2);
reader1.onerror = () => {
errors(["Unable to read file #1, an internal error occurred"]);
}
reader2.onerror = () => {
errors(["Unable to read file #2, an internal error occurred"]);
}
reader1.onload = () => {
files[0] = reader1.result;
uploadCandidate();
}
reader2.onload = () => {
files[1] = reader2.result;
uploadCandidate();
}
} else {
document.getElementById("uploader").style.display = "";
document.getElementById("checker").style.display = "none";
document.getElementById("confirm").style.display = "none";
document.getElementById("error").style.display = "none";
}
}
</script>
</div>
</div>
</div>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>
|