summaryrefslogtreecommitdiff
path: root/includes/refresh
diff options
context:
space:
mode:
Diffstat (limited to 'includes/refresh')
-rw-r--r--includes/refresh/assets.inc86
-rw-r--r--includes/refresh/cleanup.inc24
-rw-r--r--includes/refresh/logo.inc322
3 files changed, 432 insertions, 0 deletions
diff --git a/includes/refresh/assets.inc b/includes/refresh/assets.inc
new file mode 100644
index 0000000..b27840a
--- /dev/null
+++ b/includes/refresh/assets.inc
@@ -0,0 +1,86 @@
+<?php
+
+global $app;
+
+if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars");
+if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners");
+if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads");
+if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies");
+
+function downloadAssets($system, $path = null) {
+ if (!isset($path)) {
+ $path = $system;
+ }
+
+ $general = json_decode(file_get_contents("./data/$path/general.json"), true);
+
+ if (isset($general["avatar_url"])) {
+ $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]);
+ echo(" /avatars/$id.webp\n");
+ file_put_contents("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION), file_get_contents($general['avatar_url']));
+ exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars/" . $id . ".webp");
+ unlink("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION));
+ }
+
+ if (isset($general["banner"])) {
+ $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]);
+ echo(" /banners/$id.webp\n");
+ file_put_contents("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION), file_get_contents($general['banner']));
+ exec("convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION) ."\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp");
+ unlink("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION));
+ }
+
+ $members = json_decode(file_get_contents("./data/$path/members.json"), true);
+
+ foreach ($members as $member) {
+ $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]) . preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $member["uuid"]);
+
+ if (isset($member["avatar_url"])) {
+ echo(" /avatars/$id.webp\n");
+ file_put_contents("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION), file_get_contents($member['avatar_url']));
+ exec("convert -resize 512x512 \"" . "/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars/" . $id . ".webp");
+ unlink("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION));
+ }
+
+ echo(" /banners/$id.webp\n");
+
+ if (isset($member["banner"])) {
+ file_put_contents("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION), file_get_contents($member['banner']));
+ exec("convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp");
+ unlink("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION));
+ } else {
+ $img = imagecreate(2048, 1024);
+
+ if (isset($member["color"])) {
+ imagecolorallocate($img, hexdec(substr($member["color"], 0, 2)) / 2, hexdec(substr($member["color"], 2, 2)) / 2, hexdec(substr($member["color"], 4, 2)) / 2);
+ } else {
+ imagecolorallocate($img, 0, 0, 0);
+ }
+
+ imagejpeg($img, "/tmp/img.jpeg", 100);
+ imagedestroy($img);
+ exec("convert -resize 2048x2048 \"/tmp/img.jpeg\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp");
+ unlink("/tmp/img.jpeg");
+ }
+
+ if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png")) {
+ $url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png";
+ } else {
+ $url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt.png";
+ }
+ echo(" /heads/$id.png\n");
+ exec("convert \"" . $url . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads/" . $id . ".png");
+
+ if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png")) {
+ echo(" /bodies/$id.png\n");
+ exec("convert \"" . "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png" . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies/" . $id . ".png");
+ }
+ }
+}
+
+downloadAssets("gdapd");
+downloadAssets("ynmuc");
+
+if (isset($app["other"]) && isset($app["other"]["id"]) && isset($app["other"]["token"])) {
+ downloadAssets($app["other"]["id"], "other");
+} \ No newline at end of file
diff --git a/includes/refresh/cleanup.inc b/includes/refresh/cleanup.inc
new file mode 100644
index 0000000..39ec41a
--- /dev/null
+++ b/includes/refresh/cleanup.inc
@@ -0,0 +1,24 @@
+<?php
+
+$screens = array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens"), function ($i) {
+ return !str_starts_with($i, ".");
+}));
+
+$computers = array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata"), function ($i) {
+ return !str_starts_with($i, ".");
+}));
+
+foreach ($screens as $screen) {
+ $delete = true;
+ $id = explode(".", explode("-", $screen)[2])[0];
+
+ foreach ($computers as $file) {
+ $computer = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $file), true);
+
+ foreach ($computer["screens"] as $sel) {
+ if ($sel["id"] === $id) $delete = false;
+ }
+ }
+
+ if ($delete) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens/" . $screen);
+} \ No newline at end of file
diff --git a/includes/refresh/logo.inc b/includes/refresh/logo.inc
new file mode 100644
index 0000000..3e88140
--- /dev/null
+++ b/includes/refresh/logo.inc
@@ -0,0 +1,322 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.inc";
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/score.inc";
+
+$columns = ceil(sqrt(count(scoreOrderGlobal())));
+echo(" Using " . $columns . " columns\n");
+
+$members = scoreOrderGlobal();
+
+usort($members, function ($a, $b) {
+ $vr = hexdec(substr($a["color"], 0, 2));
+ $vg = hexdec(substr($a["color"], 2, 2));
+ $vb = hexdec(substr($a["color"], 4, 2));
+
+ $hsl = rgbToHsl($vr, $vg, $vb);
+ if ($hsl[0] == 0) $hsl[0] = 360;
+ $ra = $hsl[0];
+
+ $vr = hexdec(substr($b["color"], 0, 2));
+ $vg = hexdec(substr($b["color"], 2, 2));
+ $vb = hexdec(substr($b["color"], 4, 2));
+
+ $hsl = rgbToHsl($vr, $vg, $vb);
+ if ($hsl[0] == 0) $hsl[0] = 360;
+ $rb = $hsl[0];
+
+ return $ra - $rb;
+});
+
+echo(" " . count($members) . " members\n");
+
+$packs = [];
+$currentPack = [];
+
+foreach ($members as $member) {
+ if (count($currentPack) >= $columns) {
+ $packs[] = $currentPack;
+ $currentPack = [];
+ }
+
+ $currentPack[] = $member["color"];
+}
+
+if (count($currentPack) > 0) $packs[] = $currentPack;
+
+$newPacks = [];
+foreach ($packs as $pack) {
+ usort($pack, function ($a, $b) {
+ $vra = hexdec(substr($a, 0, 2));
+ $vga = hexdec(substr($a, 2, 2));
+ $vba = hexdec(substr($a, 4, 2));
+
+ $hsla = rgbToHsl($vra, $vga, $vba);
+ $ra = $hsla[2] * $hsla[1];
+
+ $vrb = hexdec(substr($b, 0, 2));
+ $vgb = hexdec(substr($b, 2, 2));
+ $vbb = hexdec(substr($b, 4, 2));
+
+ $hslb = rgbToHsl($vrb, $vgb, $vbb);
+ $rb = $hslb[2] * $hslb[1];
+
+ return $rb < $ra;
+ });
+
+ while (count($pack) < $columns) $pack[] = "ffffff";
+
+ $newPacks[] = $pack;
+}
+
+$img = imagecreatetruecolor($columns, $columns);
+$factor = 64;
+
+for ($y = 0; $y < $columns; ++$y) {
+ for ($x = 0; $x < $columns; ++$x) {
+ if (isset($newPacks[$y][$x])) {
+ imagesetpixel($img, $x, $y, imagecolorallocate($img, hexdec(substr($newPacks[$y][$x], 0, 2)), hexdec(substr($newPacks[$y][$x], 2, 2)), hexdec(substr($newPacks[$y][$x], 4, 2))));
+ } else {
+ imagesetpixel($img, $x, $y, imagecolorallocate($img, 255, 255, 255));
+ }
+ }
+}
+
+$img2 = imagecreatetruecolor($columns * $factor, $columns * $factor);
+imagecopyresampled($img2, $img, 0, 0, 0, 0, $columns * $factor, $columns * $factor, $columns, $columns);
+
+imagepng($img2, "/tmp/image.png");
+$img3 = imageCreateCorners("/tmp/image.png", $columns * 10);
+unlink("/tmp/image.png");
+
+imagepng($img3, $_SERVER['DOCUMENT_ROOT'] . "/assets/logo/newlogo.png");
+imagepng($img3, "/tmp/ponieslogo1.png");
+
+for ($x = 1; $x <= 120; $x++) {
+ imagefilter($img2, IMG_FILTER_GAUSSIAN_BLUR);
+}
+
+imagefilter($img2, IMG_FILTER_BRIGHTNESS, -100);
+
+imagepng($img2, "/tmp/image.png");
+$img3 = imageCreateCorners("/tmp/image.png", $columns * 10);
+unlink("/tmp/image.png");
+
+imagepng($img3, $_SERVER['DOCUMENT_ROOT'] . "/assets/logo/newlogo-template.png");
+imagepng($img3, "/tmp/ponieslogo2.png");
+
+// --------------------------
+
+/*$columns = ceil(sqrt(count(array_filter(scoreOrderGlobal(), function ($i) {
+ return $i["_system"] === "gdapd";
+}))));
+echo(" Using " . $columns . " columns\n");
+
+$members = array_values(array_filter(scoreOrderGlobal(), function ($i) {
+ return $i["_system"] === "gdapd";
+}));
+
+usort($members, function ($a, $b) {
+ $vr = hexdec(substr($a["color"], 0, 2));
+ $vg = hexdec(substr($a["color"], 2, 2));
+ $vb = hexdec(substr($a["color"], 4, 2));
+
+ $hsl = rgbToHsl($vr, $vg, $vb);
+ if ($hsl[0] == 0) $hsl[0] = 360;
+ $ra = $hsl[0];
+
+ $vr = hexdec(substr($b["color"], 0, 2));
+ $vg = hexdec(substr($b["color"], 2, 2));
+ $vb = hexdec(substr($b["color"], 4, 2));
+
+ $hsl = rgbToHsl($vr, $vg, $vb);
+ if ($hsl[0] == 0) $hsl[0] = 360;
+ $rb = $hsl[0];
+
+ return $ra - $rb;
+});
+
+echo(" " . count($members) . " members\n");
+
+$packs = [];
+$currentPack = [];
+
+foreach ($members as $member) {
+ if (count($currentPack) >= $columns) {
+ $packs[] = $currentPack;
+ $currentPack = [];
+ }
+
+ $currentPack[] = $member["color"];
+}
+
+if (count($currentPack) > 0) $packs[] = $currentPack;
+
+$newPacks = [];
+foreach ($packs as $pack) {
+ usort($pack, function ($a, $b) {
+ $vra = hexdec(substr($a, 0, 2));
+ $vga = hexdec(substr($a, 2, 2));
+ $vba = hexdec(substr($a, 4, 2));
+
+ $hsla = rgbToHsl($vra, $vga, $vba);
+ $ra = $hsla[2] * $hsla[1];
+
+ $vrb = hexdec(substr($b, 0, 2));
+ $vgb = hexdec(substr($b, 2, 2));
+ $vbb = hexdec(substr($b, 4, 2));
+
+ $hslb = rgbToHsl($vrb, $vgb, $vbb);
+ $rb = $hslb[2] * $hslb[1];
+
+ return $rb < $ra;
+ });
+
+ while (count($pack) < $columns) $pack[] = "ffffff";
+
+ $newPacks[] = $pack;
+}
+
+$img = imagecreatetruecolor($columns, $columns);
+$factor = 64;
+
+for ($y = 0; $y < $columns; ++$y) {
+ for ($x = 0; $x < $columns; ++$x) {
+ if (isset($newPacks[$y][$x])) {
+ imagesetpixel($img, $x, $y, imagecolorallocate($img, hexdec(substr($newPacks[$y][$x], 0, 2)), hexdec(substr($newPacks[$y][$x], 2, 2)), hexdec(substr($newPacks[$y][$x], 4, 2))));
+ } else {
+ imagesetpixel($img, $x, $y, imagecolorallocate($img, 255, 255, 255));
+ }
+ }
+}
+
+$img2 = imagecreatetruecolor($columns * $factor, $columns * $factor);
+imagecopyresampled($img2, $img, 0, 0, 0, 0, $columns * $factor, $columns * $factor, $columns, $columns);
+
+imagepng($img2, "/tmp/image.png");
+$img3 = imageCreateCorners("/tmp/image.png", $columns * 10);
+unlink("/tmp/image.png");
+
+imagepng($img3, $_SERVER['DOCUMENT_ROOT'] . "/assets/logo/newlogo2.png");
+imagepng($img3, "/tmp/ponieslogo1a.png");
+
+for ($x = 1; $x <= 120; $x++) {
+ imagefilter($img2, IMG_FILTER_GAUSSIAN_BLUR);
+}
+
+imagefilter($img2, IMG_FILTER_BRIGHTNESS, -100);
+
+imagepng($img2, "/tmp/image.png");
+$img3 = imageCreateCorners("/tmp/image.png", $columns * 10);
+unlink("/tmp/image.png");
+
+imagepng($img3, $_SERVER['DOCUMENT_ROOT'] . "/assets/logo/newlogo2-template.png");
+imagepng($img3, "/tmp/ponieslogo2a.png");*/
+
+// --------------------------
+
+$isLoggedIn = true;
+$isLowerLoggedIn = false;
+
+$columns = ceil(sqrt(count(array_filter(scoreOrderGlobal()))));
+echo(" Using " . $columns . " columns\n");
+
+$members = array_values(array_filter(scoreOrderGlobal()));
+
+usort($members, function ($a, $b) {
+ $vr = hexdec(substr($a["color"], 0, 2));
+ $vg = hexdec(substr($a["color"], 2, 2));
+ $vb = hexdec(substr($a["color"], 4, 2));
+
+ $hsl = rgbToHsl($vr, $vg, $vb);
+ if ($hsl[0] == 0) $hsl[0] = 360;
+ $ra = $hsl[0];
+
+ $vr = hexdec(substr($b["color"], 0, 2));
+ $vg = hexdec(substr($b["color"], 2, 2));
+ $vb = hexdec(substr($b["color"], 4, 2));
+
+ $hsl = rgbToHsl($vr, $vg, $vb);
+ if ($hsl[0] == 0) $hsl[0] = 360;
+ $rb = $hsl[0];
+
+ return $ra - $rb;
+});
+
+echo(" " . count($members) . " members\n");
+
+$packs = [];
+$currentPack = [];
+
+foreach ($members as $member) {
+ if (count($currentPack) >= $columns) {
+ $packs[] = $currentPack;
+ $currentPack = [];
+ }
+
+ $currentPack[] = $member["color"];
+}
+
+if (count($currentPack) > 0) $packs[] = $currentPack;
+
+$newPacks = [];
+foreach ($packs as $pack) {
+ usort($pack, function ($a, $b) {
+ $vra = hexdec(substr($a, 0, 2));
+ $vga = hexdec(substr($a, 2, 2));
+ $vba = hexdec(substr($a, 4, 2));
+
+ $hsla = rgbToHsl($vra, $vga, $vba);
+ $ra = $hsla[2] * $hsla[1];
+
+ $vrb = hexdec(substr($b, 0, 2));
+ $vgb = hexdec(substr($b, 2, 2));
+ $vbb = hexdec(substr($b, 4, 2));
+
+ $hslb = rgbToHsl($vrb, $vgb, $vbb);
+ $rb = $hslb[2] * $hslb[1];
+
+ return $rb < $ra;
+ });
+
+ while (count($pack) < $columns) $pack[] = "ffffff";
+
+ $newPacks[] = $pack;
+}
+
+$img = imagecreatetruecolor($columns, $columns);
+$factor = 64;
+
+for ($y = 0; $y < $columns; ++$y) {
+ for ($x = 0; $x < $columns; ++$x) {
+ if (isset($newPacks[$y][$x])) {
+ imagesetpixel($img, $x, $y, imagecolorallocate($img, hexdec(substr($newPacks[$y][$x], 0, 2)), hexdec(substr($newPacks[$y][$x], 2, 2)), hexdec(substr($newPacks[$y][$x], 4, 2))));
+ } else {
+ imagesetpixel($img, $x, $y, imagecolorallocate($img, 255, 255, 255));
+ }
+ }
+}
+
+$img2 = imagecreatetruecolor($columns * $factor, $columns * $factor);
+imagecopyresampled($img2, $img, 0, 0, 0, 0, $columns * $factor, $columns * $factor, $columns, $columns);
+
+imagepng($img2, "/tmp/image.png");
+$img3 = imageCreateCorners("/tmp/image.png", $columns * 10);
+unlink("/tmp/image.png");
+
+imagepng($img3, $_SERVER['DOCUMENT_ROOT'] . "/assets/logo/newlogo3.png");
+imagepng($img3, "/tmp/ponieslogo1b.png");
+
+for ($x = 1; $x <= 120; $x++) {
+ imagefilter($img2, IMG_FILTER_GAUSSIAN_BLUR);
+}
+
+imagefilter($img2, IMG_FILTER_BRIGHTNESS, -100);
+
+imagepng($img2, "/tmp/image.png");
+$img3 = imageCreateCorners("/tmp/image.png", $columns * 10);
+unlink("/tmp/image.png");
+
+imagepng($img3, $_SERVER['DOCUMENT_ROOT'] . "/assets/logo/newlogo3-template.png");
+imagepng($img3, "/tmp/ponieslogo2b.png"); \ No newline at end of file