summaryrefslogtreecommitdiff
path: root/includes/jobs
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-27 22:22:53 +0200
committerRaindropsSys <contact@minteck.org>2023-03-27 22:22:53 +0200
commite98e95d89939cdc1252d02df04ae8d91c6aa8c92 (patch)
treea5d5535f8058f1a7b45a31a1caf36ab7e24ff19d /includes/jobs
parent6ab243c12f2514cd0f40e80504223664755a6da4 (diff)
downloadpluralconnect-e98e95d89939cdc1252d02df04ae8d91c6aa8c92.tar.gz
pluralconnect-e98e95d89939cdc1252d02df04ae8d91c6aa8c92.tar.bz2
pluralconnect-e98e95d89939cdc1252d02df04ae8d91c6aa8c92.zip
Updated 9 files, added 9 files, deleted 3 files and renamed includes/refresh/logo.inc (automated)
Diffstat (limited to 'includes/jobs')
-rw-r--r--includes/jobs/CleanupDocs.php25
-rw-r--r--includes/jobs/FrontersNotification.php101
-rw-r--r--includes/jobs/PKFronters.php31
-rw-r--r--includes/jobs/PKMembers.php48
-rw-r--r--includes/jobs/PKSwitches.php77
-rw-r--r--includes/jobs/PKSystem.php31
-rw-r--r--includes/jobs/UpdateAssets.php99
-rw-r--r--includes/jobs/UpdateLogo.php327
8 files changed, 739 insertions, 0 deletions
diff --git a/includes/jobs/CleanupDocs.php b/includes/jobs/CleanupDocs.php
new file mode 100644
index 0000000..70f37b9
--- /dev/null
+++ b/includes/jobs/CleanupDocs.php
@@ -0,0 +1,25 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$documents = array_map(function ($i) {
+ return [
+ "id" => substr($i, 0, -5),
+ ...(json_decode(file_get_contents("./data/docs/" . $i), true) ?? [])
+ ];
+}, array_filter(scandir("./data/docs"), function ($i) {
+ return !str_starts_with($i, ".") && str_ends_with($i, ".json");
+}));
+
+$deletable = array_values(array_filter($documents, function ($i) {
+ return str_starts_with(strip_tags($i["contents"]), "/delete");
+}));
+
+foreach ($deletable as $item) {
+ if (time() - $item["last"]["date"] > 86400) {
+ unlink("./data/docs/" . $item["id"] . ".json");
+ }
+} \ No newline at end of file
diff --git a/includes/jobs/FrontersNotification.php b/includes/jobs/FrontersNotification.php
new file mode 100644
index 0000000..d95f273
--- /dev/null
+++ b/includes/jobs/FrontersNotification.php
@@ -0,0 +1,101 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+$system = $options["system"];
+
+if ($system === "gdapd") {
+ $name = "Raindrops System";
+} elseif ($system === "ynmuc") {
+ $name = "Cloudburst System";
+} elseif (isset($app["other"]) && $system === $app["other"]["id"]) {
+ $name = $app["other"]["name"];
+} else {
+ die();
+}
+
+$fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true);
+$currentFronter = $fronters["members"][0]["id"];
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/last.json", json_encode($currentFronter));
+
+$ntfy = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["ntfy"];
+
+if (count($fronters["members"]) > 0 && ($system !== $app["other"]["id"] || !isset($app["other"]))) {
+ foreach ($fronters["members"] as $member) {
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json")) {
+ $metadata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true);
+
+ if (!isset($metadata["birth"])) {
+ showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
+ } else if (isset($metadata['birth']["age"]) && $metadata["birth"]["age"] === 0 && (!isset($metadata['birth']["year"]) || $metadata["birth"]["year"] < 1900)) {
+ showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
+ } else if (isset($metadata['birth']["year"]) && $metadata["birth"]["year"] < 1900) {
+ showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
+ } else if (!isset($metadata['birth']["year"]) && !isset($metadata['birth']["age"])) {
+ showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
+ }
+ }
+ }
+}
+
+if (count($fronters["members"]) > 1) {
+ $context = stream_context_create([
+ 'http' => [
+ 'method' => 'POST',
+ 'header' =>
+ "Content-Type: text/plain\r\n" .
+ "Title: 🐴 Switch occurred in $name\r\n" .
+ "Priority: default\r\n" .
+ "Tags: switch\r\n" .
+ "Actions: view, Open " . $fronters["members"][0]["display_name"] . " on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true;view, Open " . $fronters["members"][1]["display_name"] . " on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][1]["name"] . "/, clear=true\r\n" .
+ "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]),
+ 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " and " . ($fronters["members"][1]["display_name"] ?? $fronters["members"][1]["name"]) . " switched in just now"
+ ]
+ ]);
+} else if (count($fronters["members"]) > 0) {
+ $context = stream_context_create([
+ 'http' => [
+ 'method' => 'POST',
+ 'header' =>
+ "Content-Type: text/plain\r\n" .
+ "Title: 🐴 Switch occurred in $name\r\n" .
+ "Priority: default\r\n" .
+ "Tags: switch\r\n" .
+ "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/" . $fronters["members"][0]["name"] . "/, clear=true\r\n" .
+ "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]),
+ 'content' => ($fronters["members"][0]["display_name"] ?? $fronters["members"][0]["name"]) . " switched in just now"
+ ]
+ ]);
+} else {
+ $context = stream_context_create([
+ 'http' => [
+ 'method' => 'POST',
+ 'header' =>
+ "Content-Type: text/plain\r\n" .
+ "Title: 🐴 Switch occurred in $name\r\n" .
+ "Priority: default\r\n" .
+ "Tags: switch\r\n" .
+ "Actions: view, Open on Cold Haze, https://ponies.equestria.horse/, clear=true\r\n" .
+ "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]),
+ 'content' => "The fallback pony switched in just now"
+ ]
+ ]);
+}
+
+if ($system !== $app["other"]["id"] || !isset($app["other"])) {
+ file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, $context);
+}
+
+if ($system === "gdapd") {
+ $topic = "public-switches-raindrops";
+} else if ($system === "ynmuc") {
+ $topic = "public-switches-cloudburst";
+} else {
+ $topic = "main";
+}
+
+file_get_contents('https://' . $ntfy["server"] . '/' . $topic, false, $context); \ No newline at end of file
diff --git a/includes/jobs/PKFronters.php b/includes/jobs/PKFronters.php
new file mode 100644
index 0000000..2649b7d
--- /dev/null
+++ b/includes/jobs/PKFronters.php
@@ -0,0 +1,31 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+$system = $options["system"];
+
+if ($app["other"]["id"] === $system) {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET',
+ 'header' =>
+ "Authorization: " . $app["other"]["token"] . "\r\n"
+ ]
+ ]);
+} else {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET'
+ ]
+ ]);
+}
+
+$data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/fronters", false, $ctx);
+
+if (trim($data) !== "" && $data !== false) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", $data);
+} \ No newline at end of file
diff --git a/includes/jobs/PKMembers.php b/includes/jobs/PKMembers.php
new file mode 100644
index 0000000..529a820
--- /dev/null
+++ b/includes/jobs/PKMembers.php
@@ -0,0 +1,48 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+$system = $options["system"];
+
+if ($app["other"]["id"] === $system) {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET',
+ 'header' =>
+ "Authorization: " . $app["other"]["token"] . "\r\n"
+ ]
+ ]);
+} else {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET'
+ ]
+ ]);
+}
+
+$data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/members", false, $ctx);
+
+if (trim($data) !== "" && $data !== false) {
+ $parsed = json_decode($data, true);
+
+ foreach ($parsed as $index => $member) {
+ if (isset($member["avatar_url"])) {
+ $dominantColor = substr(ColorThief::getColor($member["avatar_url"], outputFormat: "hex"), 1);
+ } else {
+ $dominantColor = "ffffff";
+ }
+
+ $parsed[$index]["dominant_color"] = $dominantColor;
+
+ if (!isset($member["color"])) {
+ $parsed[$index]["color"] = $dominantColor;
+ }
+ }
+
+ $data = json_encode($parsed, JSON_PRETTY_PRINT);
+ file_put_contents("./data/$system/members.json", $data);
+} \ No newline at end of file
diff --git a/includes/jobs/PKSwitches.php b/includes/jobs/PKSwitches.php
new file mode 100644
index 0000000..eb7d897
--- /dev/null
+++ b/includes/jobs/PKSwitches.php
@@ -0,0 +1,77 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+$system = $options["system"];
+
+if ($app["other"]["id"] === $system) {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET',
+ 'header' =>
+ "Authorization: " . $app["other"]["token"] . "\r\n"
+ ]
+ ]);
+} else {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET'
+ ]
+ ]);
+}
+
+echo(" Part 1/6\n");
+$switches1 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/switches", false, $ctx), true);
+
+if (count($switches1) > 0) {
+ $oldest = $switches1[count($switches1) - 1]["timestamp"];
+
+ echo(" Part 2/6\n");
+ $switches2 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/switches?before=$oldest", false, $ctx), true);
+
+ if (count($switches2) > 0) {
+ $oldest = $switches2[count($switches2) - 1]["timestamp"];
+
+ echo(" Part 3/6\n");
+ $switches3 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/switches?before=$oldest", false, $ctx), true);
+
+ if (count($switches3) > 0) {
+ $oldest = $switches3[count($switches3) - 1]["timestamp"];
+
+ echo(" Part 4/6\n");
+ $switches4 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/switches?before=$oldest", false, $ctx), true);
+
+ if (count($switches4) > 0) {
+ $oldest = $switches4[count($switches4) - 1]["timestamp"];
+
+ echo(" Part 5/6\n");
+ $switches5 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/switches?before=$oldest", false, $ctx), true);
+
+ if (count($switches5) > 0) {
+ $oldest = $switches5[count($switches5) - 1]["timestamp"];
+
+ echo(" Part 6/6\n");
+ $switches6 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/switches?before=$oldest", false, $ctx), true);
+ } else {
+ $switches6 = [];
+ }
+ } else {
+ $switches5 = $switches6 = [];
+ }
+ } else {
+ $switches4 = $switches5 = $switches6 = [];
+ }
+ } else {
+ $switches3 = $switches4 = $switches5 = $switches6 = [];
+ }
+} else {
+ $switches2 = $switches3 = $switches4 = $switches5 = $switches6 = [];
+}
+
+if ($switches1 !== null && $switches2 !== null && $switches3 !== null && $switches4 !== null && $switches5 !== null && $switches6 !== null) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", json_encode([...$switches1, ...$switches2, ...$switches3, ...$switches4, ...$switches5, ...$switches6], JSON_PRETTY_PRINT));
+} \ No newline at end of file
diff --git a/includes/jobs/PKSystem.php b/includes/jobs/PKSystem.php
new file mode 100644
index 0000000..c3fce1b
--- /dev/null
+++ b/includes/jobs/PKSystem.php
@@ -0,0 +1,31 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+$system = $options["system"];
+
+if ($app["other"]["id"] === $system) {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET',
+ 'header' =>
+ "Authorization: " . $app["other"]["token"] . "\r\n"
+ ]
+ ]);
+} else {
+ $ctx = stream_context_create([
+ 'http' => [
+ 'method' => 'GET'
+ ]
+ ]);
+}
+
+$data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system", false, $ctx);
+
+if (trim($data) !== "" && $data !== false) {
+ file_put_contents("./data/$system/general.json", $data);
+} \ No newline at end of file
diff --git a/includes/jobs/UpdateAssets.php b/includes/jobs/UpdateAssets.php
new file mode 100644
index 0000000..8898b94
--- /dev/null
+++ b/includes/jobs/UpdateAssets.php
@@ -0,0 +1,99 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+
+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) {
+ global $options;
+
+ if (!isset($path)) {
+ $path = $system;
+ }
+
+ $general = json_decode(file_get_contents("./data/$path/general.json"), true);
+
+ if ($options["type"] === "system") {
+ 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 ($options["type"] === "members") {
+ 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 ($options["type"] === "ponytown") {
+ 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/jobs/UpdateLogo.php b/includes/jobs/UpdateLogo.php
new file mode 100644
index 0000000..add1fa9
--- /dev/null
+++ b/includes/jobs/UpdateLogo.php
@@ -0,0 +1,327 @@
+<?php
+
+$options = json_decode($argv[1], true);
+$_SERVER['DOCUMENT_ROOT'] = "../..";
+require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
+use ColorThief\ColorThief;
+
+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