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) --- includes/assets.inc | 18 ++++-- includes/flags.json | 20 +++---- includes/functions.inc | 23 ++++++-- includes/metadata.inc | 4 +- includes/navigation.inc | 8 +++ includes/refresh.php | 149 +++++++++++++++++++++++++----------------------- 6 files changed, 129 insertions(+), 93 deletions(-) (limited to 'includes') 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")); -- cgit