summaryrefslogtreecommitdiff
path: root/includes/jobs
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-03 22:22:48 +0200
committerRaindropsSys <contact@minteck.org>2023-04-03 22:22:48 +0200
commit704e1c22efe6056b0fc2f59b2766f47e1c8d71cc (patch)
tree25c3c3980c115e7bcbc60e62f4b3d3f7fc184c71 /includes/jobs
parentbbf20f987bb6a7561be3d98518ddaa41b71eaf67 (diff)
downloadpluralconnect-704e1c22efe6056b0fc2f59b2766f47e1c8d71cc.tar.gz
pluralconnect-704e1c22efe6056b0fc2f59b2766f47e1c8d71cc.tar.bz2
pluralconnect-704e1c22efe6056b0fc2f59b2766f47e1c8d71cc.zip
Updated 19 files and added 12 files (automated)
Diffstat (limited to 'includes/jobs')
-rw-r--r--includes/jobs/FrontersNotification.php13
-rw-r--r--includes/jobs/PKFronters.php8
-rw-r--r--includes/jobs/PKMembers.php9
-rw-r--r--includes/jobs/PKSwitches.php20
-rw-r--r--includes/jobs/PKSystem.php8
-rw-r--r--includes/jobs/UpdateAssets.php9
-rw-r--r--includes/jobs/UpdateLogo.php116
7 files changed, 67 insertions, 116 deletions
diff --git a/includes/jobs/FrontersNotification.php b/includes/jobs/FrontersNotification.php
index f29a1e5..d342303 100644
--- a/includes/jobs/FrontersNotification.php
+++ b/includes/jobs/FrontersNotification.php
@@ -5,6 +5,8 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
if (!function_exists("formatPonypush")) {
function formatPonypush($message) {
return "Update to Ponypush 3.1.0 or later — (\$PA1$\$" . base64_encode($message) . "\$\$)";
@@ -14,6 +16,8 @@ if (!function_exists("formatPonypush")) {
$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$system = $options["system"];
+echo("Processing for system $system\n");
+
if ($system === "gdapd") {
$name = "Raindrops System";
} elseif ($system === "ynmuc") {
@@ -36,12 +40,16 @@ if (count($fronters["members"]) > 0 && ($system !== $app["other"]["id"] || !isse
$metadata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true);
if (!isset($metadata["birth"])) {
+ echo("Showing age warning\n");
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)) {
+ echo("Showing age warning\n");
showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
} else if (isset($metadata['birth']["year"]) && $metadata["birth"]["year"] < 1900) {
+ echo("Showing age warning\n");
showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
} else if (!isset($metadata['birth']["year"]) && !isset($metadata['birth']["age"])) {
+ echo("Showing age warning\n");
showWarning($member["display_name"] ?? $member["name"], $member["name"], $system);
}
}
@@ -49,6 +57,7 @@ if (count($fronters["members"]) > 0 && ($system !== $app["other"]["id"] || !isse
}
if (count($fronters["members"]) > 1) {
+ echo("Creating context for 2 members\n");
$context = stream_context_create([
'http' => [
'method' => 'POST',
@@ -63,6 +72,7 @@ if (count($fronters["members"]) > 1) {
]
]);
} else if (count($fronters["members"]) > 0) {
+ echo("Creating context for 1 member\n");
$context = stream_context_create([
'http' => [
'method' => 'POST',
@@ -77,6 +87,7 @@ if (count($fronters["members"]) > 1) {
]
]);
} else {
+ echo("Creating context for no member (fallback pony)\n");
$context = stream_context_create([
'http' => [
'method' => 'POST',
@@ -93,6 +104,7 @@ if (count($fronters["members"]) > 1) {
}
if ($system !== $app["other"]["id"] || !isset($app["other"])) {
+ echo("Sending to general public channel\n");
file_get_contents('https://' . $ntfy["server"] . '/public-switches', false, $context);
}
@@ -104,4 +116,5 @@ if ($system === "gdapd") {
$topic = "main";
}
+echo("Sending to specific channel ($topic)\n");
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
index 2649b7d..feb7fd3 100644
--- a/includes/jobs/PKFronters.php
+++ b/includes/jobs/PKFronters.php
@@ -5,10 +5,13 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$system = $options["system"];
if ($app["other"]["id"] === $system) {
+ echo("Using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET',
@@ -17,6 +20,7 @@ if ($app["other"]["id"] === $system) {
]
]);
} else {
+ echo("Not using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET'
@@ -24,8 +28,12 @@ if ($app["other"]["id"] === $system) {
]);
}
+echo("Fetching...\n");
$data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/fronters", false, $ctx);
if (trim($data) !== "" && $data !== false) {
+ echo("Data is valid, saved it\n");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json", $data);
+} else {
+ echo("Data is invalid\n");
} \ No newline at end of file
diff --git a/includes/jobs/PKMembers.php b/includes/jobs/PKMembers.php
index 536853d..7bcb242 100644
--- a/includes/jobs/PKMembers.php
+++ b/includes/jobs/PKMembers.php
@@ -5,10 +5,13 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$system = $options["system"];
if ($app["other"]["id"] === $system) {
+ echo("Using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET',
@@ -17,6 +20,7 @@ if ($app["other"]["id"] === $system) {
]
]);
} else {
+ echo("Not using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET'
@@ -24,9 +28,11 @@ if ($app["other"]["id"] === $system) {
]);
}
+echo("Fetching...\n");
$data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system/members", false, $ctx);
if (trim($data) !== "" && $data !== false) {
+ echo("Data is valid, saved it\n");
$parsed = json_decode($data, true);
foreach ($parsed as $index => $member) {
@@ -47,7 +53,10 @@ if (trim($data) !== "" && $data !== false) {
$data = json_encode($parsed, JSON_PRETTY_PRINT);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/members.json", $data);
+} else {
+ echo("Data is invalid\n");
}
+echo("Cleared cache\n");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/navigation.json", "{}");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/home.json", "{}"); \ No newline at end of file
diff --git a/includes/jobs/PKSwitches.php b/includes/jobs/PKSwitches.php
index eb7d897..b7a755d 100644
--- a/includes/jobs/PKSwitches.php
+++ b/includes/jobs/PKSwitches.php
@@ -5,10 +5,13 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$system = $options["system"];
if ($app["other"]["id"] === $system) {
+ echo("Using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET',
@@ -17,6 +20,7 @@ if ($app["other"]["id"] === $system) {
]
]);
} else {
+ echo("Not using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET'
@@ -24,37 +28,38 @@ if ($app["other"]["id"] === $system) {
]);
}
-echo(" Part 1/6\n");
+echo("Fetching...\n");
+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");
+ 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");
+ 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");
+ 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");
+ 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");
+ 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 = [];
@@ -73,5 +78,8 @@ if (count($switches1) > 0) {
}
if ($switches1 !== null && $switches2 !== null && $switches3 !== null && $switches4 !== null && $switches5 !== null && $switches6 !== null) {
+ echo("Data is valid, saved it\n");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json", json_encode([...$switches1, ...$switches2, ...$switches3, ...$switches4, ...$switches5, ...$switches6], JSON_PRETTY_PRINT));
+} else {
+ echo("Data is invalid\n");
} \ No newline at end of file
diff --git a/includes/jobs/PKSystem.php b/includes/jobs/PKSystem.php
index 045eb67..6583e4f 100644
--- a/includes/jobs/PKSystem.php
+++ b/includes/jobs/PKSystem.php
@@ -5,10 +5,13 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$system = $options["system"];
if ($app["other"]["id"] === $system) {
+ echo("Using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET',
@@ -17,6 +20,7 @@ if ($app["other"]["id"] === $system) {
]
]);
} else {
+ echo("Not using authentication\n");
$ctx = stream_context_create([
'http' => [
'method' => 'GET'
@@ -24,8 +28,12 @@ if ($app["other"]["id"] === $system) {
]);
}
+echo("Fetching...\n");
$data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$system", false, $ctx);
if (trim($data) !== "" && $data !== false) {
+ echo("Data is valid, saved it\n");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/general.json", $data);
+} else {
+ echo("Data is invalid\n");
} \ No newline at end of file
diff --git a/includes/jobs/UpdateAssets.php b/includes/jobs/UpdateAssets.php
index e52a6fa..0c05686 100644
--- a/includes/jobs/UpdateAssets.php
+++ b/includes/jobs/UpdateAssets.php
@@ -5,6 +5,8 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
$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");
@@ -22,6 +24,7 @@ function downloadAssets($system, $path = null) {
$general = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$path/general.json"), true);
if ($options["type"] === "system") {
+ echo("Download system assets\n");
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");
@@ -45,6 +48,7 @@ function downloadAssets($system, $path = null) {
$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") {
+ echo("Downloading member assets\n");
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']));
@@ -75,6 +79,7 @@ function downloadAssets($system, $path = null) {
}
if ($options["type"] === "ponytown") {
+ echo("Downloading Pony Town assets\n");
if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png")) {
$url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png";
} else {
@@ -91,9 +96,13 @@ function downloadAssets($system, $path = null) {
}
}
+echo("Downloading for gdapd\n");
downloadAssets("gdapd");
+
+echo("Downloading for ynmuc\n");
downloadAssets("ynmuc");
if (isset($app["other"]) && isset($app["other"]["id"]) && isset($app["other"]["token"])) {
+ echo("Downloading for other\n");
downloadAssets($app["other"]["id"], "other");
} \ No newline at end of file
diff --git a/includes/jobs/UpdateLogo.php b/includes/jobs/UpdateLogo.php
index add1fa9..9d669fc 100644
--- a/includes/jobs/UpdateLogo.php
+++ b/includes/jobs/UpdateLogo.php
@@ -5,10 +5,14 @@ $_SERVER['DOCUMENT_ROOT'] = "../..";
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php';
use ColorThief\ColorThief;
+echo("Loading...\n");
+
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";
+echo("Generating public logo\n");
+
$columns = ceil(sqrt(count(scoreOrderGlobal())));
echo(" Using " . $columns . " columns\n");
@@ -111,119 +115,11 @@ 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;
+echo("Generating private logo\n");
+
$columns = ceil(sqrt(count(array_filter(scoreOrderGlobal()))));
echo(" Using " . $columns . " columns\n");