$title,
"options" => $options,
"date" => date('c')
];
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs/" . round(microtime(true) * 1000000) . "-" . random() . ".json", json_encode($job));
}
}
if (!function_exists("formatPonypush")) {
function formatPonypush($message) {
return "Update to Ponypush 3.1.0 or later — (\$PA1$\$" . base64_encode($message) . "\$\$)";
}
}
if (!function_exists("generateToken")) {
function generateToken(): string {
return "peh" . str_replace("/", ".", base64_encode(random_bytes(96)));
}
}
if (!function_exists("peh_error")) {
function peh_error($message, $code = 500): void {
header("Location: /?em=" . urlencode(base64_encode($message)) . "&ec=" . $code);
die();
}
}
if (!function_exists("getAsset")) {
function getAsset($systemID, $memberID = null, $type = "avatars") {
$app = $GLOBALS["ColdHazeApp"] ?? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$systemFile = (isset($app["other"]) && $systemID === $app["other"]["id"]) ? "other" : $systemID;
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemFile/general.json")) {
$id1 = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemFile/general.json"), true)["uuid"]);
if (isset($memberID)) {
$members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemFile/members.json"), true);
$list = array_map(function ($i) {
return $i["id"];
}, $members);
if (in_array($memberID, $list)) {
$id2 = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", (getMemberWithoutSystem($memberID) ?? ['uuid' => ''])["uuid"]);
} else {
return "/error/nomember/?s=$systemID&m=$memberID&t=$type";
}
$id = $id1 . $id2;
if (str_ends_with((getMemberWithoutSystem($memberID) ?? ['name' => ''])["name"], "-travelling")) {
$id1 = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($systemID === "gdapd" ? "ynmuc" : "gdapd") . "/general.json"), true)["uuid"]);
$members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($systemID === "gdapd" ? "ynmuc" : "gdapd") . "/members.json"), true);
$list = array_map(function ($i) {
return $i["name"];
}, $members);
if (in_array(substr(getMemberWithoutSystem($memberID)["name"], 0, -11), $list)) {
$id2 = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", getMemberFromName(substr(getMemberWithoutSystem($memberID)["name"], 0, -11))["uuid"]);
} else {
return "/error/nomember/?s=$systemID&m=$memberID&t=$type";
}
$id = $id1 . $id2;
}
} else {
$id = $id1;
}
if ($type === "bodies" || $type === "heads") {
if (getSystemMember($systemID, $memberID) !== null && getSystemMember($systemID, $memberID)["_metadata"] !== null && getSystemMember($systemID, $memberID)["_metadata"]["species"] !== null && in_array("human", getSystemMember($systemID, $memberID)["_metadata"]["species"])) {
$type = "avatars";
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/" . $type . "/" . $id . ".webp")) {
return "/assets/" . $type . "/" . $id . ".webp";
} else {
return "/error/nofile/?s=$systemID&m=$memberID&t=$type";
}
} else {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/" . $type . "/" . $id . ".png")) {
return "/assets/" . $type . "/" . $id . ".png";
} else {
return "/error/nofile/?s=$systemID&m=$memberID&t=$type";
}
}
} else {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/" . $type . "/" . $id . ".webp")) {
return "/assets/" . $type . "/" . $id . ".webp";
} else {
return "/error/nofile/?s=$systemID&m=$memberID&t=$type";
}
}
} else {
return "/error/nosys/?s=$systemID&m=$memberID&t=$type";
}
}
}
if (!function_exists("rgbToHsl")) {
function rgbToHsl($r, $g, $b) {
$oldR = $r;
$oldG = $g;
$oldB = $b;
$r /= 255;
$g /= 255;
$b /= 255;
$max = max($r, $g, $b);
$min = min($r, $g, $b);
$l = ($max + $min) / 2;
$d = $max - $min;
if ($d == 0) {
$h = $s = 0;
} else {
$s = $d / (1 - abs(2 * $l - 1));
switch ($max) {
case $r:
$h = 60 * fmod((($g - $b) / $d), 6);
if ($b > $g) {
$h += 360;
}
break;
case $g:
$h = 60 * (($b - $r) / $d + 2);
break;
case $b:
$h = 60 * (($r - $g) / $d + 4);
break;
}
}
return array(round($h, 2), round($s, 2), round($l, 2));
}
}
if (!function_exists("imageCreateCorners")) {
function imageCreateCorners($sourceImageFile, $radius) {
# test source image
if (file_exists($sourceImageFile)) {
$res = is_array($info = getimagesize($sourceImageFile));
}
else $res = false;
# open image
if ($res) {
$w = $info[0];
$h = $info[1];
switch ($info['mime']) {
case 'image/jpeg': $src = imagecreatefromjpeg($sourceImageFile);
break;
case 'image/gif': $src = imagecreatefromgif($sourceImageFile);
break;
case 'image/png': $src = imagecreatefrompng($sourceImageFile);
break;
default:
$res = false;
}
}
# create corners
if ($res) {
$q = 10; # change this if you want
$radius *= $q;
# find unique color
do {
$r = rand(0, 255);
$g = rand(0, 255);
$b = rand(0, 255);
}
while (imagecolorexact($src, $r, $g, $b) < 0);
$nw = $w*$q;
$nh = $h*$q;
$img = imagecreatetruecolor($nw, $nh);
$alphacolor = imagecolorallocatealpha($img, $r, $g, $b, 127);
imagealphablending($img, false);
imagesavealpha($img, true);
imagefilledrectangle($img, 0, 0, $nw, $nh, $alphacolor);
imagefill($img, 0, 0, $alphacolor);
imagecopyresampled($img, $src, 0, 0, 0, 0, $nw, $nh, $w, $h);
imagearc($img, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $alphacolor);
imagefilltoborder($img, 0, 0, $alphacolor, $alphacolor);
imagearc($img, $nw-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $alphacolor);
imagefilltoborder($img, $nw-1, 0, $alphacolor, $alphacolor);
imagearc($img, $radius-1, $nh-$radius, $radius*2, $radius*2, 90, 180, $alphacolor);
imagefilltoborder($img, 0, $nh-1, $alphacolor, $alphacolor);
imagearc($img, $nw-$radius, $nh-$radius, $radius*2, $radius*2, 0, 90, $alphacolor);
imagefilltoborder($img, $nw-1, $nh-1, $alphacolor, $alphacolor);
imagealphablending($img, true);
imagecolortransparent($img, $alphacolor);
# resize image down
$dest = imagecreatetruecolor($w, $h);
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagefilledrectangle($dest, 0, 0, $w, $h, $alphacolor);
imagecopyresampled($dest, $img, 0, 0, 0, 0, $w, $h, $nw, $nh);
# output image
$res = $dest;
imagedestroy($src);
imagedestroy($img);
}
return $res;
}
}
if (!function_exists("getMiniName")) {
function getMiniName(string $name) {
$parts = explode(" ", $name);
if (strlen($parts[0]) > 3 && $parts[0] !== "Sweetie" && $parts[0] !== "Filly" && $parts[0] !== "Windy" && (isset($parts[1]) && $parts[1] !== "Brightdawn" && $parts[1] !== "Fizz")) {
if ($parts[0] === "Princess") {
array_shift($parts);
}
if (str_contains($parts[0], "/")) {
return explode("/", $parts[0])[0];
} else {
return $parts[0];
}
} else {
return $name;
}
}
}
if (!function_exists("withCaretakersDown")) {
function withCaretakersDown(array $ordered): array {
return $ordered;
}
}
if (!function_exists("getSystemMember")) {
function getSystemMember(string $system, string $id) {
$app = $GLOBALS["ColdHazeApp"] ?? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$systemID = $system;
$members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($systemID === $app["other"]["id"] ? "other" : $systemID) . "/members.json"), true);
$member = null;
foreach ($members as $m) {
if ($m["id"] === $id) $member = $m;
}
$member["system"] = $member["_system"] = $system;
$member["_metadata"] = file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $id . ".json") ? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $id . ".json"), true) : null;
return $member;
}
}
if (!function_exists("getMemberWithoutSystem")) {
function getMemberWithoutSystem(string $id) {
global $isLowerLoggedIn; global $isLoggedIn;
$member = null;
$members1 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true);
foreach ($members1 as $m) {
$m["_system"] = "ynmuc";
$m["system"] = "ynmuc";
if ($m["id"] === $id) $member = $m;
}
$members2 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true);
foreach ($members2 as $m) {
$m["_system"] = "gdapd";
$m["system"] = "gdapd";
if ($m["id"] === $id) $member = $m;
}
if ($isLowerLoggedIn || $isLoggedIn) {
$app = $GLOBALS["ColdHazeApp"] ?? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
$members3 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true);
foreach ($members3 as $m) {
$m["_system"] = $app["other"]["id"];
$m["system"] = $app["other"]["id"];
if ($m["id"] === $id) $member = $m;
}
}
return $member;
}
}
if (!function_exists("showMembersFromList")) {
function showMembersFromList(array $list) {
foreach ($list as $member) { if ($member['name'] !== "unknown" && $member['name'] !== "fusion") {
echo('' . (isset($member['travelling']) && $member['travelling'] ? "+" . ($member['proxy_tags'][0]['prefix'] ?? " ") : ($member['proxy_tags'][0]['prefix'] ?? " ")) . '