From 737f5008f8a4a011c832e83f6b2019d3dc27dbd0 Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 22 Feb 2023 20:45:15 +0100 Subject: Updated 8 files (automated) --- api/pluralkit-integration.php | 125 +++++++++++++++++++++-------------- includes/assets.inc | 18 +++-- includes/flags.json | 20 +++--- includes/functions.inc | 23 +++++-- includes/metadata.inc | 4 +- includes/navigation.inc | 8 +++ includes/refresh.php | 149 ++++++++++++++++++++++-------------------- pages/home.inc | 3 +- 8 files changed, 207 insertions(+), 143 deletions(-) diff --git a/api/pluralkit-integration.php b/api/pluralkit-integration.php index a0368e4..0793873 100644 --- a/api/pluralkit-integration.php +++ b/api/pluralkit-integration.php @@ -2,6 +2,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/agewarning.inc"; +$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); $user = $_GET['user'] ?? null; $inputJSON = file_get_contents('php://input'); $input = json_decode($inputJSON, true); @@ -28,16 +29,38 @@ if ($input["signing_token"] !== $data[$user]) { if ($input['system_id'] === "7d9f543e-f742-40f6-9d07-86c3f2983124") { $system = "gdapd"; $name = "Raindrops System"; -} else { +} elseif ($input['system_id'] === "ade46823-206b-4b0c-ad3c-caae934a5f3b") { $system = "ynmuc"; $name = "Cloudburst System"; +} elseif (isset($app["other"]) && $input["system_id"] === $app["other"]["uuid"]) { + $system = $app["other"]["id"]; + $name = $app["other"]["name"]; +} else { + die(); } $lastFronter = json_decode(@file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/last.json"), true) ?? ""; if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") { - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/fronters")); - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/switches")); + if ($system === $app["other"]["id"]) { + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/fronters"), false, stream_context_create([ + 'http' => [ + 'method' => 'GET', + 'header' => + "Authorization: " . $app["other"]["token"] . "\r\n" + ] + ])); + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/switches"), false, stream_context_create([ + 'http' => [ + 'method' => 'GET', + 'header' => + "Authorization: " . $app["other"]["token"] . "\r\n" + ] + ])); + } else { + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/fronters")); + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", file_get_contents("https://pluralkit.equestria.dev/v2/systems/$input[system_id]/switches")); + } $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true); $currentFronter = $fronters["members"][0]["id"]; @@ -45,7 +68,7 @@ if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $ntfy = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["ntfy"]; - if (count($fronters["members"]) > 0) { + 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); @@ -63,51 +86,53 @@ if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || } } - if (count($fronters["members"]) > 1) { - $context = stream_context_create([ - 'http' => [ - 'method' => 'POST', - 'header' => - "Content-Type: text/plain\r\n" . - "Title: 🐴 Switch occurred in the $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 the $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 the $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"])) { + if (count($fronters["members"]) > 1) { + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => + "Content-Type: text/plain\r\n" . + "Title: 🐴 Switch occurred in the $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 the $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 the $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" + ] + ]); + } - file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, $context); + file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, $context); + } if ($system === "gdapd") { $topic = "public-switches-raindrops"; @@ -141,8 +166,10 @@ if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || ] ])); } - } else { + } else if ($system === "ynmuc") { $topic = "public-switches-cloudburst"; + } else { + $topic = "main"; } file_get_contents('https://' . $ntfy["server"] . '/' . $topic, false, $context); diff --git a/includes/assets.inc b/includes/assets.inc index 05296ce..4f74a6e 100644 --- a/includes/assets.inc +++ b/includes/assets.inc @@ -1,12 +1,18 @@ -
'); +
'); } else { echo(' -
'); +
'); } if (!$hideTitle) echo(' @@ -327,6 +331,13 @@ if (!function_exists("raindrops")) { } } +if (!function_exists("other")) { + function other(bool $hideTitle): void { + $app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); + showSystem($app["other"]["id"], $app["other"]["name"], "#" . $app["other"]["color"] . "a6", $hideTitle); + } +} + if (!function_exists("getMember")) { function getMember(string $id) { global $systemID; diff --git a/includes/metadata.inc b/includes/metadata.inc index d7875c5..2e009cd 100644 --- a/includes/metadata.inc +++ b/includes/metadata.inc @@ -144,12 +144,12 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member foreach ($flags as $id => $name): if (!is_array($name) && !is_null($name)): ?>
$name2): ?>
diff --git a/includes/navigation.inc b/includes/navigation.inc index 82b6046..ac40ae6 100644 --- a/includes/navigation.inc +++ b/includes/navigation.inc @@ -119,6 +119,14 @@ $navigation_admin = [ "link" => "/-/stats", "stepped" => null, "private" => true + ], + [ + "name" => $pages["logout"]["name"][$lang["_name"]], + "icon" => "/assets/icons/logout.svg", + "invert" => true, + "link" => "/-/logout", + "stepped" => null, + "private" => false ] ] ], diff --git a/includes/refresh.php b/includes/refresh.php index ecf724a..c4eac83 100644 --- a/includes/refresh.php +++ b/includes/refresh.php @@ -128,119 +128,126 @@ foreach ($files as $file) { copy("./data/" . $file, "./data/backup/" . $file); } -function getSystem(string $id) { +function getSystem(string $id, string $fileName = null, string $token = null) { global $times; + + if (!isset($fileName)) { + $fileName = $id; + } + + if (isset($token)) { + $ctx = stream_context_create([ + 'http' => [ + 'method' => 'GET', + 'header' => + "Authorization: " . $token . "\r\n" + ] + ]); + } else { + $ctx = stream_context_create([ + 'http' => [ + 'method' => 'GET' + ] + ]); + } + echo("System: $id\n"); echo(" Base system info\n"); $currentOpStart = microtime(true); - $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id"); + $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id", false, $ctx); if (trim($data) !== "" && $data !== false) { - file_put_contents("./data/$id/general.json", $data); + file_put_contents("./data/$fileName/general.json", $data); } - $times["system-general-$id"] = microtime(true) - $currentOpStart; + $times["system-general-" . md5($id)] = microtime(true) - $currentOpStart; echo(" System members\n"); $currentOpStart = microtime(true); - $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/members"); + $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/members", false, $ctx); if (trim($data) !== "" && $data !== false) { - file_put_contents("./data/$id/members.json", $data); + file_put_contents("./data/$fileName/members.json", $data); } - $times["system-members-$id"] = microtime(true) - $currentOpStart; + $times["system-members-" . md5($id)] = microtime(true) - $currentOpStart; echo(" Fronters\n"); - $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/fronters"); + $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/fronters", false, $ctx); if (trim($data) !== "" && $data !== false) { - file_put_contents("./data/$id/fronters.json", $data); + file_put_contents("./data/$fileName/fronters.json", $data); } - $times["system-fronters-$id"] = microtime(true) - $currentOpStart; + $times["system-fronters-" . md5($id)] = microtime(true) - $currentOpStart; echo(" Switches\n"); $currentOpStart = microtime(true); echo(" Part 1/6\n"); - $switches1 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches"), true); - $oldest = $switches1[count($switches1) - 1]["timestamp"]; + $switches1 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches", false, $ctx), true); - echo(" Part 2/6\n"); - $switches2 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest"), true); - $oldest = $switches2[count($switches2) - 1]["timestamp"]; + if (count($switches1) > 0) { + $oldest = $switches1[count($switches1) - 1]["timestamp"]; - echo(" Part 3/6\n"); - $switches3 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest"), true); - $oldest = $switches3[count($switches3) - 1]["timestamp"]; + echo(" Part 2/6\n"); + $switches2 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true); - echo(" Part 4/6\n"); - $switches4 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest"), true); - $oldest = $switches4[count($switches4) - 1]["timestamp"]; + if (count($switches2) > 0) { + $oldest = $switches2[count($switches2) - 1]["timestamp"]; - echo(" Part 5/6\n"); - $switches5 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest"), true); - $oldest = $switches5[count($switches5) - 1]["timestamp"]; + echo(" Part 3/6\n"); + $switches3 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true); - echo(" Part 6/6\n"); - $switches6 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest"), true); - - if ($switches1 !== null && $switches2 !== null && $switches3 !== null && $switches4 !== null && $switches5 !== null && $switches6 !== null) { - file_put_contents("./data/$id/switches.json", json_encode([...$switches1, ...$switches2, ...$switches3, ...$switches4, ...$switches5, ...$switches6], JSON_PRETTY_PRINT)); - $times["system-switches-$id"] = microtime(true) - $currentOpStart; - } -} + if (count($switches3) > 0) { + $oldest = $switches3[count($switches3) - 1]["timestamp"]; -getSystem("gdapd"); // Raindrops -getSystem("ynmuc"); // Cloudburst + echo(" Part 4/6\n"); + $switches4 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true); -echo("Calendar\n"); -$currentOpStart = microtime(true); -file_put_contents("./data/calendar/calendar.ics", file_get_contents($app["calendar"])); -$times["calendar"] = microtime(true) - $currentOpStart; + if (count($switches4) > 0) { + $oldest = $switches4[count($switches4) - 1]["timestamp"]; -echo("Downloading images.\n"); -if (!file_exists("./data/images")) mkdir("./data/images"); + echo(" Part 5/6\n"); + $switches5 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true); -foreach (json_decode(file_get_contents("./data/gdapd/members.json"), true) as $member) { - $currentOpStart2 = microtime(true); - echo(" " . $member['id'] . "\n"); + if (count($switches5) > 0) { + $oldest = $switches5[count($switches5) - 1]["timestamp"]; - if (isset($member['avatar_url'])) { - echo(" Profile picture\n"); - file_put_contents("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION), file_get_contents($member['avatar_url'])); - exec("convert -resize 128x128 -quality 50 \"" . "/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION) . "\" \"./data/images/pf-gdapd-" . $member['id'] . ".webp\""); - unlink("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION)); + echo(" Part 6/6\n"); + $switches6 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/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 = []; } - echo(" Pony Town character\n"); - if (file_exists("../assets/uploads/pt-" . $member['name'] . ".png")) { - exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt-" . $member['name'] . ".png\" \"./data/images/pt-gdapd-" . $member['id'] . ".png\""); - } else { - exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt.png\" \"./data/images/pt-gdapd-" . $member['id'] . ".png\""); + if ($switches1 !== null && $switches2 !== null && $switches3 !== null && $switches4 !== null && $switches5 !== null && $switches6 !== null) { + file_put_contents("./data/$fileName/switches.json", json_encode([...$switches1, ...$switches2, ...$switches3, ...$switches4, ...$switches5, ...$switches6], JSON_PRETTY_PRINT)); + $times["system-switches-" . md5($id)] = microtime(true) - $currentOpStart; } - $times["images-gdapd-" . $member['id']] = microtime(true) - $currentOpStart2; } -foreach (json_decode(file_get_contents("./data/ynmuc/members.json"), true) as $member) { - $currentOpStart2 = microtime(true); - echo(" " . $member['id'] . "\n"); - - if (isset($member['avatar_url'])) { - echo(" Profile picture\n"); - file_put_contents("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION), file_get_contents($member['avatar_url'])); - exec("convert -resize 128x128 -quality 50 \"" . "/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION) . "\" \"./data/images/pf-ynmuc-" . $member['id'] . ".webp\""); - unlink("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION)); - } +getSystem("gdapd"); // Raindrops +getSystem("ynmuc"); // Cloudburst - echo(" Pony Town character\n"); - if (file_exists("../assets/uploads/pt-" . $member['name'] . ".png")) { - exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt-" . $member['name'] . ".png\" \"./data/images/pt-ynmuc-" . $member['id'] . ".png\""); - } else { - exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt.png\" \"./data/images/pt-ynmuc-" . $member['id'] . ".png\""); - } - $times["images-ynmuc-" . $member['id']] = microtime(true) - $currentOpStart2; +if (isset($app["other"]) && isset($app["other"]["id"]) && isset($app["other"]["token"])) { + getSystem($app["other"]["id"], "other", $app["other"]["token"]); } +echo("Calendar\n"); +$currentOpStart = microtime(true); +file_put_contents("./data/calendar/calendar.ics", file_get_contents($app["calendar"])); +$times["calendar"] = microtime(true) - $currentOpStart; + echo("Backing up...\n"); $lastBackup = (int)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.txt")); diff --git a/pages/home.inc b/pages/home.inc index 464900f..44c8d7e 100644 --- a/pages/home.inc +++ b/pages/home.inc @@ -1,4 +1,4 @@ - +