summaryrefslogtreecommitdiff
path: root/includes/refresh.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-02-22 20:45:15 +0100
committerMinteck <contact@minteck.org>2023-02-22 20:45:15 +0100
commit737f5008f8a4a011c832e83f6b2019d3dc27dbd0 (patch)
tree1039c5acc74159587f48fe1c513b796b9c6abbfb /includes/refresh.php
parent1ff917767cca089a87f4e06a676c48ed132c2a73 (diff)
downloadpluralconnect-737f5008f8a4a011c832e83f6b2019d3dc27dbd0.tar.gz
pluralconnect-737f5008f8a4a011c832e83f6b2019d3dc27dbd0.tar.bz2
pluralconnect-737f5008f8a4a011c832e83f6b2019d3dc27dbd0.zip
Updated 8 files (automated)
Diffstat (limited to 'includes/refresh.php')
-rw-r--r--includes/refresh.php149
1 files changed, 78 insertions, 71 deletions
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"));