diff options
author | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
commit | 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch) | |
tree | 75be5fba4368472fb11c8015aee026b2b9a71888 /includes/refresh.php | |
parent | 8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff) | |
download | pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2 pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip |
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'includes/refresh.php')
-rw-r--r-- | includes/refresh.php | 65 |
1 files changed, 24 insertions, 41 deletions
diff --git a/includes/refresh.php b/includes/refresh.php index 922e708..3f3e7f4 100644 --- a/includes/refresh.php +++ b/includes/refresh.php @@ -1,22 +1,24 @@ <?php +require_once './composer/vendor/autoload.php'; $_SERVER['DOCUMENT_ROOT'] = ".."; +use ColorThief\ColorThief; + $app = json_decode(file_get_contents("./app.json"), true); $start = microtime(true); @mkdir("./data"); -@mkdir("./data/backup"); $files = []; $restored = []; $times = []; $currentOpStart = microtime(true); -file_put_contents("./data/actions/" . date('Y-m-d_H-i-s') . ".json", @file_get_contents("./data/actions/actions.json")); -file_put_contents("./data/toys/" . date('Y-m-d_H-i-s') . ".json", @file_get_contents("./data/toys/toys.json")); +//file_put_contents("./data/actions/" . date('Y-m-d_H-i-s') . ".json", @file_get_contents("./data/actions/actions.json")); +//file_put_contents("./data/toys/" . date('Y-m-d_H-i-s') . ".json", @file_get_contents("./data/toys/toys.json")); -exec('bash -c "cd /nas/web/ponies.equestria.horse/includes/data; ls -tp toys/20* | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"'); -exec('bash -c "cd /nas/web/ponies.equestria.horse/includes/data; ls -tp actions/20* | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"'); +//exec('bash -c "cd /nas/web/ponies.equestria.horse/includes/data; ls -tp toys/20* | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"'); +//exec('bash -c "cd /nas/web/ponies.equestria.horse/includes/data; ls -tp actions/20* | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"'); $times["important_backup"] = microtime(true) - $currentOpStart; @@ -107,27 +109,6 @@ if ($versionHash[0] !== $version["hash"]) { file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/version.json", json_encode($version)); $times["version"] = microtime(true) - $currentOpStart; -$currentOpStart = microtime(true); -foreach (array_filter(scandir("./data"), function ($i) { - return !str_starts_with($i, ".") && $i !== "backup" && (is_file("./data/" . $i) || is_dir("./data/" . $i)); -}) as $file) { - if (is_dir("./data/" . $file)) { - foreach (array_filter(scandir("./data"), function ($i) use ($file) { - return !str_starts_with($i, ".") && $i !== "backup" && is_file("./data/" . $file . "/" . $i); - }) as $file2) { - @mkdir("./data/backup/" . $file); - $files[] = $file . "/" . $file2; - } - } else { - $files[] = $file; - } -} - -@mkdir("./data/backup"); -foreach ($files as $file) { - copy("./data/" . $file, "./data/backup/" . $file); -} - function getSystem(string $id, string $fileName = null, string $token = null) { global $times; @@ -167,6 +148,21 @@ function getSystem(string $id, string $fileName = null, string $token = null) { $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/members", false, $ctx); if (trim($data) !== "" && $data !== false) { + $parsed = json_decode($data, true); + + foreach ($parsed as $index => $member) { + if (!isset($member["color"])) { + if (isset($member["avatar_url"])) { + $dominantColor = substr(ColorThief::getColor($member["avatar_url"], outputFormat: "hex"), 1); + } else { + $dominantColor = "ffffff"; + } + + $parsed[$index]["color"] = $dominantColor; + } + } + + $data = json_encode($parsed, JSON_PRETTY_PRINT); file_put_contents("./data/$fileName/members.json", $data); } $times["system-members-" . md5($id)] = microtime(true) - $currentOpStart; @@ -247,11 +243,6 @@ if (!is_link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"] link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other", $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"]); } -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")); @@ -272,21 +263,13 @@ $times["logo"] = microtime(true) - $currentOpStart; echo("Generated logo\n"); -echo("Generating favicons...\n"); - -$currentOpStart = microtime(true); -require_once "./icons.inc"; -$times["favicons"] = microtime(true) - $currentOpStart; - -echo("Generated favicons\n"); - echo("Fetching school information...\n"); file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/school.json", "{}"); $currentOpStart = microtime(true); -chdir("../school"); +chdir("./external/school"); exec("node index.js"); -chdir("../includes"); +chdir("../.."); $times["school"] = microtime(true) - $currentOpStart; echo("Fetched school information\n"); |