summaryrefslogtreecommitdiff
path: root/includes/util
diff options
context:
space:
mode:
Diffstat (limited to 'includes/util')
-rw-r--r--includes/util/banner.inc401
-rw-r--r--includes/util/functions.inc691
-rw-r--r--includes/util/homepage.inc29
-rw-r--r--includes/util/rainbow.inc56
-rw-r--r--includes/util/random.inc15
-rw-r--r--includes/util/score.inc147
-rw-r--r--includes/util/session.inc109
7 files changed, 0 insertions, 1448 deletions
diff --git a/includes/util/banner.inc b/includes/util/banner.inc
deleted file mode 100644
index 72656ca..0000000
--- a/includes/util/banner.inc
+++ /dev/null
@@ -1,401 +0,0 @@
-<?php
-
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $lang; global $pages; global $isLowerLoggedIn;
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
-
-$travelling = [];
-
-function _header_getMember(string $id, $system) {
- $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/members.json"), true);
- $member = null;
-
- foreach ($members as $m) {
- if ($m["id"] === $id) $member = $m;
- }
-
- return $member;
-}
-
-function getMemberBannerData(string $id, string $system, bool $french = false) {
- global $travelling;
- global $isLoggedIn;
- global $isLowerLoggedIn;
- global $lang;
- global $use2023UI;
-
- $french = $lang["_french"];
-
- $member = getSystemMember($system, $id);
- $metadata = file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$id.json") ? parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$id.json"), true)) : parseMetadata([
- // FIXME: This doesn't work now that bitset functionality is removed
- "bitset" => 4196352,
- "regression" => null,
- "median" => null,
- "marefriends" => [],
- "sexfriends" => [],
- "sisters" => [],
- "caretakers" => []
- ]);
-
- $prefixes = [];
- foreach ($member['proxy_tags'] as $proxy) {
- if (isset($travelling[$member['id']]) && $travelling[$member['id']]["travelling"]) {
- if (isset($travelling[$member['id']]['equestria']) && $travelling[$member['id']]['equestria']) {
- $prefixes[] = null;
- } else {
- $prefixes[] = "+" . $proxy["prefix"] . ($proxy["suffix"] !== "" && $proxy["suffix"] !== null ? "..." . $proxy["suffix"] : "");
- }
- } else {
- $prefixes[] = $proxy["prefix"] . ($proxy["suffix"] !== "" && $proxy["suffix"] !== null ? "..." . $proxy["suffix"] : "");
- }
- }
-
- $lastFronted = null;
- if (!$metadata["median"]) {
- $fronters = array_map(function ($item) {
- return $item["id"];
- }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);
-
- if (in_array($id, $fronters)) {
- $lastFronted = [
- 'now' => true,
- 'relative' => timeAgo(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["timestamp"]),
- 'absolute' => date("D j M Y, G:i:s (e)", strtotime(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["timestamp"])),
- 'timestamp' => strtotime(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["timestamp"]),
- 'duration' => [
- 'seconds' => null,
- 'pretty' => null
- ]
- ];
- } else {
- $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);
-
- $thisMember = array_filter($switches, function ($item) {
- global $memberData;
- return in_array($memberData["id"], $item["members"]);
- });
-
- $thisMember = array_values($thisMember);
- $frontingEnd = null;
-
- if (count($thisMember) > 0) {
- $thisIndex = array_search($thisMember[0], $switches);
-
- $frontingStart = $thisMember[0];
- $frontingEnd = $switches[$thisIndex - 1];
- }
-
- if ($frontingEnd !== null && isset($frontingStart)) {
- $seconds = (strtotime($frontingEnd["timestamp"]) - strtotime($frontingStart["timestamp"]));
-
- $lastFronted = [
- 'now' => false,
- 'relative' => timeAgo($frontingEnd["timestamp"]),
- 'absolute' => date("D j M Y, G:i:s (e)", strtotime($frontingEnd["timestamp"])),
- 'timestamp' => strtotime($frontingEnd["timestamp"]),
- 'duration' => [
- 'seconds' => $seconds,
- 'pretty' => $seconds . ($french ? " secondes" : " seconds")
- ]
- ];
- if ($french) {
- if ($seconds > 60) {
- if ($seconds > 3600) {
- $lastFronted['duration']['pretty'] = round($seconds / 3600) . " heures";
- } else {
- $lastFronted['duration']['pretty'] = round($seconds / 60) . " minutes";
- }
- }
- } else {
- if ($seconds > 60) {
- if ($seconds > 3600) {
- $lastFronted['duration']['pretty'] = round($seconds / 3600) . " hours";
- } else {
- $lastFronted['duration']['pretty'] = round($seconds / 60) . " minutes";
- }
- }
- }
- }
- }
- }
-
- $speciesList = [];
- foreach ($metadata["species"] ?? [] as $species) {
- if ($french) {
- $name = match ($species) {
- "earth" => $metadata["robot"] ? "Robot poney terrestre" : (!$metadata["plush"] ? "Poney terrestre" : "Poney terrestre en peluche"),
- "alicorn" => $metadata["robot"] ? "Robot alicorne" : (!$metadata["plush"] ? "Alicorne" : "Alicorne en peluche"),
- "crystal" => $metadata["robot"] ? "Robot poney de crystal" : (!$metadata["plush"] ? "Poney de crystal" : "Poney de crystal en peluche"),
- "pegasus" => $metadata["robot"] ? "Robot pégase" : (!$metadata["plush"] ? "Pégase" : "Pégase en peluche"),
- "batpony" => $metadata["robot"] ? "Robot Poney chauve souris" : (!$metadata["plush"] ? "Poney chauve souris" : "Poney chauve souris en peluche"),
- "unicorn" => $metadata["robot"] ? "Robot licorne" : (!$metadata["plush"] ? "Licorne" : "Licorne en peluche"),
- "changeling" => "Changelin",
- "merpony" => "Poney sirène",
- "kirin" => "Kirin",
- "deer" => "Deer",
- default => $species . "_" . $metadata["robot"]
- };
- } else {
- $name = match ($species) {
- "earth" => $metadata["robot"] ? "Robot earth pony" : (!$metadata["plush"] ? "Earth pony" : "Earth pony plush"),
- "alicorn" => $metadata["robot"] ? "Robot alicorn" : (!$metadata["plush"] ? "Alicorn" : "Alicorn plush"),
- "crystal" => $metadata["robot"] ? "Robot crystal pony" : (!$metadata["plush"] ? "Crystal pony" : "Crystal pony plush"),
- "pegasus" => $metadata["robot"] ? "Robot pegasus" : (!$metadata["plush"] ? "Pegasus" : "Pegasus plush"),
- "batpony" => $metadata["robot"] ? "Robot bat pony" : (!$metadata["plush"] ? "Bat pony" : "Bat pony plush"),
- "unicorn" => $metadata["robot"] ? "Robot unicorn" : (!$metadata["plush"] ? "Unicorn" : "Unicorn plush"),
- "changeling" => "Changeling",
- "human" => "Human",
- "merpony" => "Merpony",
- "kirin" => "Kirin",
- "deer" => "Deer",
- default => $species . "_" . $metadata["robot"]
- };
- }
-
- $speciesList[] = [
- "id" => $species,
- "name" => $name,
- "robot" => $metadata["robot"],
- "plush" => $metadata["plush"],
- "icon" => $species . ($metadata["robot"] ? "-robot" : ($metadata["plush"] ? "-plush" : "")) . ".png"
- ];
- }
-
- $app = $GLOBALS["ColdHazeApp"];
-
- $systemData = [];
- $systemData['page'] = "/" . ($system === "gdapd" ? "raindrops" : ($system === $app["other"]["id"] ? $app["other"]["slug"] : "moonglow"));
- $systemData['icon'] = getAsset($system);
- $systemData['name'] = $system === "gdapd" ? "Raindrops" : ($system === $app["other"]["id"] ? $app["other"]["short"] : "Moonglow");
- $systemData['full_name'] = $system === "gdapd" ? "Raindrops System" : ($system === $app["other"]["id"] ? $app["other"]["name"] : "Moonglow");
- $systemData['temporary'] = false;
-
- $marefriends = [];
- foreach ($metadata["marefriends"] as $marefriend) {
- $mfSystem = explode("/", $marefriend)[0];
- $mfMemberID = explode("/", $marefriend)[1];
- $mfMember = array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$mfSystem/members.json"), true), function ($item) use ($mfMemberID) {
- return $item["id"] === $mfMemberID;
- });
- sort($mfMember);
- $mfMember = $mfMember[0];
-
- if (!($mfSystem === $app["other"]["id"] && !$isLoggedIn && !$isLowerLoggedIn)) $marefriends[] = [
- "id" => $marefriend,
- "link" => "/" . ($mfMember["name"]),
- "icon" => getAsset($mfSystem, $mfMemberID, "heads"),
- "name" => $mfMember["display_name"] ?? $mfMember["name"],
- "full_name" => $mfMember["display_name"] ?? $mfMember["name"]
- ];
- }
-
- $sexfriends = null;
-
- if ($isLoggedIn) {
- $sexfriends = [];
- foreach ($metadata["sexfriends"] as $marefriend) {
- $mfSystem = explode("/", $marefriend)[0];
- $mfMemberID = explode("/", $marefriend)[1];
- $mfMember = array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$mfSystem/members.json"), true), function ($item) use ($mfMemberID) {
- return $item["id"] === $mfMemberID;
- });
- sort($mfMember);
- $mfMember = $mfMember[0];
-
- if (!($mfSystem === $app["other"]["id"] && !$isLoggedIn && !$isLowerLoggedIn)) $sexfriends[] = [
- "id" => $marefriend,
- "link" => "/" . ($mfMember["name"]),
- "icon" => getAsset($mfSystem, $mfMemberID, "heads"),
- "name" => $mfMember["display_name"] ?? $mfMember["name"],
- "full_name" => $mfMember["display_name"] ?? $mfMember["name"]
- ];
- }
- }
-
- $sisters = [];
- foreach ($metadata["sisters"] as $marefriend) {
- $mfSystem = explode("/", $marefriend)[0];
- $mfMemberID = explode("/", $marefriend)[1];
- $mfMember = array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$mfSystem/members.json"), true), function ($item) use ($mfMemberID) {
- return $item["id"] === $mfMemberID;
- });
- sort($mfMember);
- $mfMember = $mfMember[0];
-
- if (!($mfSystem === $app["other"]["id"] && !$isLoggedIn && !$isLowerLoggedIn)) $sisters[] = [
- "id" => $marefriend,
- "link" => "/" . ($mfMember["name"]),
- "icon" => getAsset($mfSystem, $mfMemberID, "heads"),
- "name" => $mfMember["display_name"] ?? $mfMember["name"],
- "full_name" => $mfMember["display_name"] ?? $mfMember["name"]
- ];
- }
-
- $friends = [];
- foreach ($metadata["friends"] ?? [] as $marefriend) {
- $mfSystem = explode("/", $marefriend)[0];
- $mfMemberID = explode("/", $marefriend)[1];
- $mfMember = array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$mfSystem/members.json"), true), function ($item) use ($mfMemberID) {
- return $item["id"] === $mfMemberID;
- });
- sort($mfMember);
- $mfMember = $mfMember[0];
-
- if (!($mfSystem === $app["other"]["id"] && !$isLoggedIn && !$isLowerLoggedIn)) $friends[] = [
- "id" => $marefriend,
- "link" => "/" . ($mfMember["name"]),
- "icon" => getAsset($mfSystem, $mfMemberID, "heads"),
- "name" => $mfMember["display_name"] ?? $mfMember["name"],
- "full_name" => $mfMember["display_name"] ?? $mfMember["name"]
- ];
- }
-
- $caretakers = null;
-
- if ($metadata["little"] >= 2) {
- $caretakers = [];
- foreach ($metadata["caretakers"] as $marefriend) {
- $mfSystem = explode("/", $marefriend)[0];
- $mfMemberID = explode("/", $marefriend)[1];
- $mfMember = array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$mfSystem/members.json"), true), function ($item) use ($mfMemberID) {
- return $item["id"] === $mfMemberID;
- });
- sort($mfMember);
- $mfMember = $mfMember[0];
-
- if (!($mfSystem === $app["other"]["id"] && !$isLoggedIn && !$isLowerLoggedIn)) $caretakers[] = [
- "id" => $marefriend,
- "link" => "/" . ($mfMember["name"]),
- "icon" => getAsset($mfSystem, $mfMemberID, "heads"),
- "name" => $mfMember["display_name"] ?? $mfMember["name"],
- "full_name" => $mfMember["display_name"] ?? $mfMember["name"]
- ];
- }
- }
-
- $badges = [];
-
- if ($metadata["fictive"] ?? false) {
- $badges[] = [
- "id" => "fictive",
- "color" => "info",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Equestrian</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' based on the personality, look and behavior of a character that is from Equestria." class="badge rounded-pill bg-' . ($use2023UI ? "success" : "info") . '" style="height: 24px;"><img style="width: 16px;" src="/assets/logo/equestria.png"><span style="vertical-align: middle;">&nbsp;Equestrian</span></span>'
- ];
- }
-
- if ($metadata["fictive2"] ?? false) {
- $badges[] = [
- "id" => "fictive2",
- "color" => "d63384",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Fictive</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' based on the personality, look and behavior of a character that is from Celeste." class="badge rounded-pill ' . ($use2023UI ? "bg-success" : "") . '" style="height: 24px;' . (!$use2023UI ? "background-color: #d63384;" : "") . '"><img style="width: 16px;" src="/assets/logo/celeste.png"><span style="vertical-align: middle;">&nbsp;Fictive</span></span>'
- ];
- }
-
- if ($metadata["persecutor"] ?? false) {
- $badges[] = [
- "id" => "persecutor",
- "color" => "danger",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Persecutor</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "acts" : "act") . ' harmfully towards other system members and/or others, potentially as a misguided attempt to protect the system." class="badge rounded-pill bg-' . ($use2023UI ? "success" : "danger") . '" style="height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;"><span>Persecutor</span></span>'
- ];
- }
-
- if ($metadata["less_frequent"] ?? false) {
- $badges[] = [
- "id" => "nonverbal",
- "color" => "#6610f2",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Fronts less often</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "front" : "fronts") . ' less often than ' . getMemberPronouns($member['pronouns'])["possessive_det"] . ' headmates, this can be due to various reasons." class="badge rounded-pill ' . ($use2023UI ? "bg-success" : "") . '" style="' . (!$use2023UI ? "background-color:#6610f2;" : "") . 'height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;"><span>Fronts less often</span></span>'
- ];
- }
-
- if ($metadata["nonverbal"] ?? false) {
- $badges[] = [
- "id" => "nonverbal",
- "color" => "#20c997",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Non verbal IRL</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' non verbal in real life, although text communication is still possible." class="badge rounded-pill ' . ($use2023UI ? "bg-success" : "") . '" style="' . (!$use2023UI ? "background-color:#20c997;" : "") . 'height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;"><span>Non verbal IRL</span></span>'
- ];
- }
-
- if ($member["name"] === "fusion") {
- $badges[] = [
- "id" => "fusion",
- "color" => "333333",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Fusion</b><br>She is the result of multiple ponies purposefully merging in a way that makes them impossible to tell apart." class="badge rounded-pill ' . ($use2023UI ? "bg-success" : "") . '" style="' . (!$use2023UI ? "background-color:#333333;" : "") . 'height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;"><span>Fusion</span></span>'
- ];
- }
-
- if (($metadata["host"] ?? false)) {
- $badges[] = [
- "id" => "host",
- "color" => "fc6735",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Host</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' the host in ' . getMemberPronouns($member['pronouns'])["possessive_det"] . ' system." class="badge rounded-pill ' . ($use2023UI ? "bg-success" : "") . '" style="' . (!$use2023UI ? "background-color:#fc6735;" : "") . 'height:24px;display:inline-flex;align-items:center;position:relative;top:1px;"><span>Host</span></span>'
- ];
- }
-
- if (($metadata["leader"] ?? false)) {
- $badges[] = [
- "id" => "leader",
- "color" => "d6a833",
- "html" => '<span data-bs-toggle="tooltip" data-bs-html="true" title="<b>Leader</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' a leader in ' . getMemberPronouns($member['pronouns'])["possessive_det"] . ' system." class="badge rounded-pill ' . ($use2023UI ? "bg-success" : "") . '" style="' . (!$use2023UI ? "background-color:#fd7e14;" : "") . 'height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;"><span>Leader</span></span>'
- ];
- }
-
- if ($metadata["protector"] ?? false) {
- $badges[] = [
- "id" => "protector",
- "color" => "black",
- "html" => '<span style="height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;" data-bs-toggle="tooltip" data-bs-html="true" title="<b>Protector</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' a protector in the system and will front when somepony cannot handle it anymore." class="badge rounded-pill bg-' . ($use2023UI ? "success" : "black") . '"><span>Protector</span></span>'
- ];
- }
-
- if (($metadata["little"] ?? 0) === 2) {
- $badges[] = [
- "id" => "little",
- "color" => "success",
- "html" => '<span style="height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;" data-bs-toggle="tooltip" data-bs-html="true" title="<b>Little</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' mentally younger, and therefore behaves and feels younger than the body is." class="badge rounded-pill bg-success"><span>Little</span></span>'
- ];
- }
-
- if (($metadata["little"] ?? 0) === 3) {
- $badges[] = [
- "id" => "younger",
- "color" => "dark",
- "html" => '<span style="height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;" data-bs-toggle="tooltip" data-bs-html="true" title="<b>Younger</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' ' . (getMemberPronouns($member['pronouns'])["third"] ? "is" : "are") . ' younger than the body, but not young enough to be classified as a little." class="badge rounded-pill bg-' . ($use2023UI ? "success" : "dark") . '"><span>Younger</span></span>'
- ];
- }
-
- if (($isLoggedIn || $isLowerLoggedIn) && isset($metadata["alcohol"]) && $metadata["alcohol"] !== false) {
- $badges[] = [
- "id" => "alcohol",
- "color" => "secondary",
- "html" => '<span style="height:24px;display: inline-flex;align-items: center;position: relative;top: 1px;" data-bs-toggle="tooltip" data-bs-html="true" title="<b>Alcohol</b><br>' . ucfirst(getMemberPronouns($member['pronouns'])["subjective"]) . ' drinks alcohol, and thus may be drunk or hungover at times." class="badge rounded-pill bg-' . ($use2023UI ? "success" : "secondary") . '"><span>Alcohol</span></span>'
- ];
- }
-
- return [
- 'id' => $member['name'],
- 'color' => $member["color"] ?? "000000",
- 'icon' => [
- "online" => getAsset($system, $member["id"]),
- "offline" => "pf-$system-$id.webp"
- ],
- 'median' => $metadata["median"],
- 'little' => $metadata["little"] >= 2,
- 'name' => $member["display_name"] ?? $member["name"],
- 'gender' => "Agender",
- 'badges' => $badges,
- 'prefixes' => $prefixes,
- 'pronouns' => isset($member["pronouns"]) && trim($member["pronouns"]) !== "" ? $member["pronouns"] : "<i>they/them</i>",
- 'pronouns_usage' => getMemberPronouns($member['pronouns']),
- 'last_fronted' => $lastFronted,
- 'species' => $speciesList,
- 'system' => $systemData,
- 'age' => -1,
- 'relations' => [
- 'marefriends' => $marefriends ?? [],
- 'sexfriends' => $sexfriends ?? null,
- 'sisters' => $sisters ?? [],
- 'caretakers' => $caretakers ?? [],
- 'friends' => $friends ?? []
- ]
- ];
-}
diff --git a/includes/util/functions.inc b/includes/util/functions.inc
deleted file mode 100644
index b01476f..0000000
--- a/includes/util/functions.inc
+++ /dev/null
@@ -1,691 +0,0 @@
-<?php
-
-use JetBrains\PhpStorm\NoReturn;
-
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/score.inc";
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/homepage.inc";
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc";
-
-if (!function_exists("getMemberPronouns")) {
- function getMemberPronouns(?string $pronouns): ?array {
- return [
- "gender" => "invalid",
- "gender:fr" => "invalide",
- "object" => "this pony",
- "person" => "pony",
- "possessive_det" => "this pony's",
- "possessive_pro" => "this pony's",
- "reflexive" => "this pony",
- "subjective" => "this pony",
- "third" => true,
- "color" => "success"
- ];
- }
-}
-
-if (!function_exists("file_get_contents_or_defaults")) {
- function file_get_contents_or_defaults($file, $default) {
- if (file_exists($file)) {
- return file_get_contents($file);
- } else {
- return $default;
- }
- }
-}
-
-if (!function_exists("parseMetadata")) {
- function parseMetadata ($metadata) {
- $metadata["little"] = 0;
-
- $age = -1;
-
- if (isset($metadata["birth"]["age"]) && $metadata["birth"]["age"] !== 0) {
- $age = $metadata["birth"]["age"];
- } else if (isset($metadata["birth"]["year"]) && $metadata["birth"]["year"] > 1990) {
- $age = (int)date('Y') - $metadata["birth"]["year"] + (strtotime(date('Y') . "-" . $metadata["birth"]["date"]) <= time() ? 0 : -1);
- }
-
- if (is_string($age) && isset(explode("-", $age)[1]) && is_numeric(explode("-", $age)[1])) {
- $age = (int)explode("-", $age)[1];
- }
-
- if ($age > 0 && $age <= 10) {
- $metadata["little"] = 2;
- } else if ($age > 0 && $age <= 15) {
- $metadata["little"] = 3;
- }
-
- return $metadata;
- }
-}
-
-if (!function_exists("pf_utf8_decode")) {
- function pf_utf8_decode(string $string): string {
- return iconv("UTF-8", "ISO-8859-1", $string);
- }
-}
-
-if (!function_exists("pf_utf8_encode")) {
- function pf_utf8_encode(string $string): string {
- return iconv("ISO-8859-1", "UTF-8", $string);
- }
-}
-
-if (!function_exists("getLastFronted")) {
- function getLastFronted($members, $id) {
- foreach ($members as $member) {
- if ($member["id"] === $id) {
- return $member["_lastFronted"];
- }
- }
-
- return -1;
- }
-}
-
-if (!function_exists("createJob")) {
- function createJob($title, $options): void {
- $job = [
- "name" => $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): string {
- 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")) {
- #[NoReturn] 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"): string {
- if ($systemID === "gdapd") {
- if (isset($memberID)) {
- if ($type === "avatars" || $type === "heads") {
- return getSystemMember($systemID, $memberID)["avatar_url"];
- } else {
- return getSystemMember($systemID, $memberID)["banner"];
- }
- } else {
- $system = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $systemID . "/general.json"), true);
-
- if ($type === "avatars" || $type === "heads") {
- return $system["avatar_url"];
- } else {
- return $system["banner"];
- }
- }
- }
-
- $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" ? "hrbom" : "gdapd") . "/general.json"), true)["uuid"]);
-
- $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($systemID === "gdapd" ? "hrbom" : "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): array {
- $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) {
- if (file_exists($sourceImageFile)) {
- $res = is_array($info = getimagesize($sourceImageFile));
- }
- else $res = false;
-
- 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;
- }
- }
-
- if ($res) {
-
- $q = 10;
- $radius *= $q;
-
- 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);
-
- $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);
-
- $res = $dest;
- imagedestroy($src);
- imagedestroy($img);
- }
-
- return $res;
- }
-}
-
-if (!function_exists("getMiniName")) {
- function getMiniName(string $name): string {
- 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;
-
- $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;
- }
-
- $members3 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/members.json"), true);
- foreach ($members3 as $m) {
- $m["_system"] = "hrbom";
- $m["system"] = "hrbom";
- if ($m["id"] === $id) $member = $m;
- }
-
- if ($isLowerLoggedIn || $isLoggedIn) {
- $app = $GLOBALS["ColdHazeApp"] ?? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
- $members4 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true);
-
- foreach ($members4 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): void {
- foreach ($list as $member) { if ($member['name'] !== "unknown" && $member['name'] !== "fusion") {
- echo('<a href="/' . $member['name'] . '" style="text-decoration:none !important;filter:none !important;"><div class="hpd-item-card" style="background-color:rgba(255, 255, 255, .1);border:1px solid ' . (isset($member['color']) ? "#" . $member['color'] . "55" : "transparent") . ';outline-color:' . (isset($member['color']) ? "#" . $member['color'] . "55" : "transparent") . ';border-radius:10px;text-align:center;display:flex;align-items:center;justify-content:center;padding:5px;' . (isset($member["equestria"]) && $member["equestria"] ? 'opacity:.5;' : '') . '"><div>
-<img alt="" src="' . getAsset($member["system"], $member["id"]) . '" style="border-radius:999px;background-color:rgba(0, 0, 0, .25);height:48px;width:48px;display:block;margin-left:auto;margin-right:auto;">
-<div style="text-decoration:none;color:white;margin-top:5px;" class="member-card-name">' . ($member['display_name'] ?? $member['name']) . '</div>
-<div style="text-decoration:none !important;color:black !important;" class="member-card-prefix"><code style="text-decoration:none !important;color:white;">' . (isset($member['travelling']) && $member['travelling'] ? "+" . ($member['proxy_tags'][0]['prefix'] ?? "&nbsp;") : ($member['proxy_tags'][0]['prefix'] ?? "&nbsp;")) . '</code></div>
-</div></div></a>');
- }}
- }
-}
-
-if (!function_exists("prettySize")) {
- function prettySize($bytes): string {
- if ($bytes > 1024) {
- if ($bytes > 1024**2) {
- if ($bytes > 1024**3) {
- return round($bytes / 1024**3, 1) . " GB";
- } else {
- return round($bytes / 1024**2, 1) . " MB";
- }
- } else {
- return round($bytes / 1024, 1) . " KB";
- }
- } else {
- return $bytes . " B";
- }
- }
-}
-
-if (!function_exists("showSystem")) {
- function showSystem(string $id, string $name, string $color, bool $hideTitle): void {
- $app = $GLOBALS["ColdHazeApp"] ?? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
- global $travelling;
-
- $global = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . (isset($app["other"]) && $id === $app["other"]["id"] ? "other" : $id) . "/general.json"), true);
-
- if ($hideTitle) {
- echo('<div id="hpd-' . ($id === "gdapd" ? "raindrops" : ($id === "hrbom" ? "moonglow" : "other")) . '" style="background:rgba(255, 255, 255, .1);border-radius:10px;padding:10px;display:grid;grid-template-columns: 1fr;margin-bottom:10px;">');
- } else {
- echo('<div id="hpd-' . ($id === "gdapd" ? "raindrops" : ($id === "hrbom" ? "moonglow" : "other")) . '" style="background:rgba(255, 255, 255, .1);border-radius:10px;padding:10px 10px 10px 20px;display:grid;grid-template-columns: 128px 1fr;margin-bottom:10px;">');
- }
- if (!$hideTitle) echo('<a style="display:flex;margin: -10px -20px;align-items:center;justify-content:center;text-align:center;padding: 10px 20px;border-radius: 10px;background: #' . $global['color'] . '55;width: 148px;text-decoration:none;color:white;filter:none !important;" href="/' . ($id === "gdapd" ? "raindrops" : ($id === $app["other"]["id"] ? $app["other"]["slug"] : "moonglow")) . '" class="hpd-system">
-<div style="text-align:center;"><img src="' . getAsset($id) . '" style="width:64px;"><br>' . $name . '</div>
-</a>');
-
- if ($hideTitle) {
- echo(' <div style="display:grid;grid-template-columns:repeat(6, 1fr);grid-gap:10px;">');
- } else {
- echo(' <div style="display:grid;grid-template-columns:repeat(6, 1fr);padding-left:10px;grid-gap:10px;">');
- }
-
- showMembersFromList(scoreOrder([...array_map(function ($i) use ($id, $travelling) {
- $i["travelling"] = false;
- $i["system"] = $id;
- $i["equestria"] = false;
- return $i;
- }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . (isset($app["other"]) && $id === $app["other"]["id"] ? "other" : $id) . "/members.json"), true))], $id));
-
- echo('</div>
-
-</div>');
- }
-}
-
-if (!function_exists("raindrops")) {
- function raindrops(bool $hideTitle): void {
- showSystem("gdapd", "Raindrops System", "#a95f08a6", $hideTitle);
- }
-}
-
-if (!function_exists("moonglow")) {
- function moonglow(bool $hideTitle): void {
- showSystem("hrbom", "Moonglow", "#9064cca6", $hideTitle);
- }
-}
-
-if (!function_exists("other")) {
- function other(bool $hideTitle): void {
- $app = $GLOBALS["ColdHazeApp"] ?? 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;
-
- $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID/members.json"), true);
- $member = null;
-
- foreach ($members as $m) {
- if ($m["id"] === $id) $member = $m;
- }
-
- return $member;
- }
-}
-
-if (!function_exists("timeAgo")) {
- function timeAgo($time, $french = false, $isDifference = false, $long = false, $showTense = true): string {
- $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
-
- if ($long) {
- $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"];
- } else {
- $periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"];
- }
-
- if ($isDifference) {
- $difference = $time;
- } else {
- if (!is_numeric($time)) {
- $time = strtotime($time);
- }
-
- $now = time();
- $difference = $now - $time;
- }
-
- if ($difference <= 10 && $difference >= 0) {
- return $tense = "now";
- } elseif ($difference > 0) {
- $tense = "ago";
- } else {
- $tense = "later";
- }
-
- for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
- $difference /= $lengths[$j];
- }
-
- $difference = round($difference);
-
- $period = $periods[$j];
-
- if ($showTense) {
- if ($long) {
- return "{$difference} {$period}" . ($difference > 1 ? "s" : "") . " {$tense}";
- } else {
- return "{$difference} {$period} {$tense}";
- }
- } else {
- if ($long) {
- return "{$difference} {$period}" . ($difference > 1 ? "s" : "");
- } else {
- return "{$difference} {$period}";
- }
- }
- }
-}
-
-if (!function_exists("timeIn")) {
- function timeIn($time, $isDifference = false): string {
- $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"];
- $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
-
- if ($isDifference) {
- $difference = $time;
- } else {
- if (!is_numeric($time)) {
- $time = strtotime($time);
- }
-
- $now = time();
- $difference = $time - $now;
- }
-
- if ($difference <= 10 && $difference >= 0) {
- return $tense = "now";
- } elseif ($difference > 0) {
- $tense = "in";
- } else {
- $tense = "ago";
- }
-
- for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
- $difference /= $lengths[$j];
- }
-
- $difference = round($difference);
-
- $period = $periods[$j] . ($difference >1 ? "s" :'');
- return "{$tense} {$difference} {$period}";
- }
-}
-
-if (!function_exists("duration")) {
- function duration($seconds): string {
- global $lang; global $pages;
-
- if ($seconds >= 60) {
- if (floor($seconds / 60) >= 60) {
- if (floor($seconds / 3600) >= 24) {
- $days = floor($seconds / 86400);
-
- if ($lang["_french"]) {
- return $days . " jour" . ($days > 1 ? "s" : "");
- } else {
- return $days . " day" . ($days > 1 ? "s" : "");
- }
- } else {
- $hours = floor($seconds / 3600);
-
- if ($lang["_french"]) {
- return $hours . " heure" . ($hours > 1 ? "s" : "");
- } else {
- return $hours . " hour" . ($hours > 1 ? "s" : "");
- }
- }
- } else {
- $minutes = floor($seconds / 60);
- return $minutes . " minute" . ($minutes > 1 ? "s" : "");
- }
- } else {
- if ($lang["_french"]) {
- return $seconds . " secondes";
- } else {
- return $seconds . " seconds";
- }
- }
- }
-}
-
-if (!function_exists("relativeDate")) {
- function relativeDate($date, $showTime = true): string {
- if (!is_numeric($date)) $date = strtotime($date);
-
- if (!$showTime) {
- if (date('Y-m-d', $date) === date('Y-m-d')) {
- return "today";
- } elseif (date('Y-m-d', $date) === date('Y-m-d', time() + 86400)) {
- return "tomorrow";
- } elseif ($date < time() + 518400) {
- return date('l', $date);
- } else {
- return date('D j M', $date);
- }
- } else {
- if (date('Y-m-d', $date) === date('Y-m-d')) {
- return "today, <span class='time-adjust'>" . date('H:i', $date) . "</span>";
- } elseif (date('Y-m-d', $date) === date('Y-m-d', time() + 86400)) {
- return "tomorrow, <span class='time-adjust'>" . date('H:i', $date) . "</span>";
- } elseif ($date < time() + 518400) {
- return date('l', $date) . ", <span class='time-adjust'>" . date('H:i', $date) . "</span>";
- } else {
- return date('D j M', $date) . ", <span class='time-adjust'>" . date('H:i', $date) . "</span>";
- }
- }
- }
-}
-
-if (!function_exists("getMemberSystem")) {
- function getMemberSystem(string $id) {
- $list = scoreOrderGlobal();
-
- foreach ($list as $item) {
- if ($item["id"] === $id) return $item["_system"];
- }
-
- return null;
- }
-}
-
-if (!function_exists("getMemberFromName")) {
- function getMemberFromName(string $name) {
- $list = [...json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true), ...json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/members.json"), true), ...json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true)];
-
- foreach ($list as $item) {
- if ($item["name"] === $name) return getMemberWithoutSystem($item["id"]);
- }
-
- return null;
- }
-}
-
-if (!function_exists("resolveMember")) {
- function resolveMember(mixed $name) {
- if (is_string($name)) {
- if (str_ends_with($name, "-travelling")) {
- return substr($name, 0, strlen($name) - 11);
- } else {
- return $name;
- }
- } else {
- return $name;
- }
- }
-}
-
-if (!function_exists("calculateFullAmount")) {
- function calculateFullAmount($account, $asNumber = false, $gbpOnly = false): string|float|int {
- global $rate;
- $total = 0;
-
- foreach ($account["transactions"] as $transaction) {
- $total += $transaction["amount"];
- }
-
- if ($asNumber) {
- if ($gbpOnly && $account["currency"] === "eur") {
- return $total * $rate;
- } else {
- return $total;
- }
- } else {
- return number_format($total, 2, '.', ',');
- }
- }
-}
diff --git a/includes/util/homepage.inc b/includes/util/homepage.inc
deleted file mode 100644
index df6679f..0000000
--- a/includes/util/homepage.inc
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-
-global $app;
-global $travelling;
-
-function newHomepage($id, $page, $title) {
- global $travelling;
- $system = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $id . "/general.json"), true);
-
- ?>
- <div class="new-homepage-system" id="new-homepage-system-<?= $id ?>">
- <?php if ($title): ?>
- <a href="/<?= $page ?>" style="height: 48px; display: flex; align-items: center; justify-content: center; border-top-left-radius: 10px; border-top-right-radius: 10px; text-align: center; text-decoration: none; color: white; background-color: #<?= $system["color"] ?? "000000" ?>55; box-shadow: 0 20px 20px 0 #<?= $system["color"] ?? "000000" ?>55;" class="new-homepage-system-title" id="new-homepage-system-<?= $id ?>-title">
- <div>
- <img src="<?= getAsset($id) ?>" style="border-radius: 5px;width: 48px; vertical-align: middle;"><b style="vertical-align: middle; margin-left: 5px;"><?= $system["name"] ?></b>
- </div>
- </a>
- <?php endif; ?>
-
- <div class="new-homepage-system-list" id="new-homepage-system-<?= $id ?>-list">
- <?php $list = array_values(scoreOrder(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $id . "/members.json"), true), $id)); foreach ($list as $index => $member): ?>
- <a href="/<?= $member["name"] ?>" class="new-homepage-link <?= $index === count($list) - 1 ? "new-homepage-link-last" : "" ?>" style="color: white; text-decoration: none !important; display: block; background-color: #<?= $member["color"] ?>22; padding: 5px 10px;">
- <img src="<?= getAsset($id, $member["id"]) ?>" style="width: 32px; height: 32px; vertical-align: middle; background-color: rgba(0, 0, 0, .25); border-radius: 999px;">
- <span style="width: calc(100% - 37px); vertical-align: middle; margin-left: 5px;text-overflow: ellipsis;white-space: nowrap;overflow: hidden;"><?= $member["display_name"] ?? $member["name"] ?></span>
- </a>
- <?php endforeach; ?>
- </div>
- </div>
-<?php }
diff --git a/includes/util/rainbow.inc b/includes/util/rainbow.inc
deleted file mode 100644
index 027c771..0000000
--- a/includes/util/rainbow.inc
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/score.inc";
-
-function rainbow(): array {
- $members = scoreOrderGlobal();
-
- $data = [];
-
- foreach ($members as $member) {
- $data[$member["name"]] = [
- "_data" => $member
- ];
-
- if (isset($member["color"])) {
- $data[$member["name"]]["rgb"] = [
- hexdec(substr($member["color"], 0, 2)),
- hexdec(substr($member["color"], 2, 2)),
- hexdec(substr($member["color"], 4, 2))
- ];
- $data[$member["name"]]["hsl"] = rgbToHsl(
- $data[$member["name"]]["rgb"][0],
- $data[$member["name"]]["rgb"][1],
- $data[$member["name"]]["rgb"][2]
- );
- } else {
- $data[$member["name"]]["rgb"] = [255, 255, 255];
- $data[$member["name"]]["hsl"] = rgbToHsl(255, 255, 255);
- }
- }
-
- return $data;
-}
-
-function getMembersByColor($_ = false, $ignoreHumans = false): array {
- $members = rainbow();
-
- uasort($members, function ($a, $b) {
- return $a['hsl'][0] - $b['hsl'][0];
- });
-
- $sorted = [];
- foreach ($members as $data) {
- $data["_data"]["hue"] = $data["hsl"][0];
- $sorted[] = $data["_data"];
- }
-
- if ($ignoreHumans) {
- return array_filter($sorted, function ($i) {
- return !in_array("human", $i["_metadata"]["species"]);
- });
- } else {
- return $sorted;
- }
-} \ No newline at end of file
diff --git a/includes/util/random.inc b/includes/util/random.inc
deleted file mode 100644
index b6e7905..0000000
--- a/includes/util/random.inc
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-/**
- * @throws Exception
- */
-function random($length = 13): string {
- if (function_exists("random_bytes")) {
- $bytes = random_bytes(ceil($length / 2));
- } elseif (function_exists("openssl_random_pseudo_bytes")) {
- $bytes = openssl_random_pseudo_bytes(ceil($length / 2));
- } else {
- throw new Exception("No cryptographically secure random function available");
- }
- return substr(bin2hex($bytes), 0, $length);
-} \ No newline at end of file
diff --git a/includes/util/score.inc b/includes/util/score.inc
deleted file mode 100644
index c7d47de..0000000
--- a/includes/util/score.inc
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-
-function scoreOrder($members, $system, $useDominant = false) {
- global $defaultMember;
- global $isLowerLoggedIn;
- global $isLoggedIn;
-
- $ordered = [];
- foreach ($members as $member) {
- if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling")) {
- if (isset($member["color"])) {
- if ($useDominant) {
- $rgb = [
- hexdec(substr($member["dominant_color"] ?? $member["color"], 0, 2)),
- hexdec(substr($member["dominant_color"] ?? $member["color"], 2, 2)),
- hexdec(substr($member["dominant_color"] ?? $member["color"], 4, 2))
- ];
- } else {
- $rgb = [
- hexdec(substr($member["color"], 0, 2)),
- hexdec(substr($member["color"], 2, 2)),
- hexdec(substr($member["color"], 4, 2))
- ];
- }
-
- $hsl = rgbToHsl(
- $rgb[0],
- $rgb[1],
- $rgb[2]
- );
- } else {
- $hsl = rgbToHsl(255, 255, 255);
- }
-
- $systemID = $member["system"] ?? $system;
-
- $member["_system"] = $member["system"] = $systemID;
- $member["_metadata"] = parseMetadata(json_decode(file_get_contents_or_defaults($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json", $defaultMember), true));
- $member["_score"] = $hsl[0];
-
- if (!isset($member["_metadata"]["private"]) || !$member["_metadata"]["private"] || $isLoggedIn || $isLowerLoggedIn) {
- $ordered[] = $member;
- }
- }
- }
-
- uasort($ordered, function($a, $b) {
- return $a["_score"] - $b["_score"];
- });
-
- return $ordered;
-}
-
-function scoreOrderGlobal() {
- global $defaultMember;
- global $isLowerLoggedIn;
- global $isLoggedIn;
-
- $ordered = [];
-
- foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/members.json"), true) as $member) {
- if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling")) {
- if (isset($member["color"])) {
- $rgb = [
- hexdec(substr($member["color"], 0, 2)),
- hexdec(substr($member["color"], 2, 2)),
- hexdec(substr($member["color"], 4, 2))
- ];
- $hsl = rgbToHsl(
- $rgb[0],
- $rgb[1],
- $rgb[2]
- );
- } else {
- $hsl = rgbToHsl(255, 255, 255);
- }
- $member["_score"] = $hsl[0];
- $member["_system"] = "hrbom";
- $member["system"] = "hrbom";
- $member["_metadata"] = parseMetadata(json_decode(file_get_contents_or_defaults($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json", $defaultMember), true));
-
- if (!isset($member["_metadata"]["private"]) || !$member["_metadata"]["private"] || $isLoggedIn || $isLowerLoggedIn) {
- $ordered[] = $member;
- }
- }
- }
-
- foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true) as $member) {
- if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling")) {
- if (isset($member["color"])) {
- $rgb = [
- hexdec(substr($member["color"], 0, 2)),
- hexdec(substr($member["color"], 2, 2)),
- hexdec(substr($member["color"], 4, 2))
- ];
- $hsl = rgbToHsl(
- $rgb[0],
- $rgb[1],
- $rgb[2]
- );
- } else {
- $hsl = rgbToHsl(255, 255, 255);
- }
- $member["_score"] = $hsl[0];
- $member["_system"] = "gdapd";
- $member["system"] = "gdapd";
- $member["_metadata"] = parseMetadata(json_decode(file_get_contents_or_defaults($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json", $defaultMember), true));
-
- if (!isset($member["_metadata"]["private"]) || !$member["_metadata"]["private"] || $isLoggedIn || $isLowerLoggedIn) {
- $ordered[] = $member;
- }
- }
- }
-
- if ($isLowerLoggedIn || $isLoggedIn) {
- $app = $GLOBALS["ColdHazeApp"] ?? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
- foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true) as $member) {
- if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling")) {
- if (isset($member["color"])) {
- $rgb = [
- hexdec(substr($member["color"], 0, 2)),
- hexdec(substr($member["color"], 2, 2)),
- hexdec(substr($member["color"], 4, 2))
- ];
- $hsl = rgbToHsl(
- $rgb[0],
- $rgb[1],
- $rgb[2]
- );
- } else {
- $hsl = rgbToHsl(255, 255, 255);
- }
- $member["_score"] = $hsl[0];
- $member["_system"] = $app["other"]["id"];
- $member["system"] = $app["other"]["id"];
- $member["_metadata"] = parseMetadata(json_decode(file_get_contents_or_defaults($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json", $defaultMember), true));
- $ordered[] = $member;
- }
- }
- }
-
- uasort($ordered, function($a, $b) {
- return $a["_score"] - $b["_score"];
- });
-
- return array_values($ordered);
-}
diff --git a/includes/util/session.inc b/includes/util/session.inc
deleted file mode 100644
index 867b306..0000000
--- a/includes/util/session.inc
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
-
-global $isLoggedIn;
-global $isLowerLoggedIn;
-global $_PROFILE;
-
-$isLoggedIn = false;
-$isLowerLoggedIn = false;
-
-if (!function_exists("formatPonypush")) {
- function formatPonypush($message) {
- return "Update to Ponypush 3.1.0 or later — (\$PA1$\$" . base64_encode($message) . "\$\$)";
- }
-}
-
-$authorization = null;
-$post = null;
-
-if ($_SERVER['REQUEST_METHOD'] === "POST") {
- $request_raw = file_get_contents('php://input');
- $json_object = $data = json_decode($request_raw, true);
-
- if (json_last_error() === JSON_ERROR_NONE) {
- $post = $data["_session"] ?? null;
- }
-}
-
-if (isset($_SERVER['HTTP_AUTHORIZATION']) && str_starts_with(trim($_SERVER['HTTP_AUTHORIZATION']), "Bearer ")) {
- $authorization = trim(substr($_SERVER['HTTP_AUTHORIZATION'], 7));
-}
-
-$token = $authorization ?? $post ?? $_POST["_session"] ?? $_GET["_session"] ?? $_COOKIE['PEH2_SESSION_TOKEN'] ?? null;
-
-if (isset($token)) {
- if (!(str_contains($token, "/") || trim($token) === "" || trim($token) === "." || trim($token) === "..")) {
- if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token))) {
- $data = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token))), true);
-
- if (isset($data["profile"])) {
- $_PROFILE = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token)), true);
-
- if (time() - $data["last"] > 86400 * 30) {
- unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token));
- unset($_PROFILE);
- $isLoggedIn = false;
- $isLowerLoggedIn = false;
- }
-
- $data["last"] = time();
- if (!isset($data["addresses"])) $data["addresses"] = [];
- $data["addresses"][$_SERVER["HTTP_X_FORWARDED_FOR"] ?? $_SERVER["REMOTE_ADDR"]] = time();
-
- copy($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token), $_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token) . ".old");
-
- file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token), pf_utf8_encode(json_encode($data)));
-
- if (trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token)) === "")) {
- unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token));
- copy($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token) . ".old", $_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token));
- }
-
- unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token) . ".old");
- } else {
- $_PROFILE = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token)), true);
- }
-
- $isLoggedIn = true;
- } elseif (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/lowertokens/" . str_replace("/", "", $token))) {
- $data = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token))), true);
-
- if (isset($data["profile"])) {
- $_PROFILE = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/lowertokens/" . str_replace("/", "", $token)), true);
-
- if (time() - $data["last"] > 86400 * 30) {
- unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token));
- unset($_PROFILE);
- $isLoggedIn = false;
- $isLowerLoggedIn = false;
- }
-
- $data["last"] = time();
- if (!isset($data["addresses"])) $data["addresses"] = [];
- $data["addresses"][$_SERVER["HTTP_X_FORWARDED_FOR"] ?? $_SERVER["REMOTE_ADDR"]] = time();
-
- copy($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token), $_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token) . ".old");
-
- file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token), pf_utf8_encode(json_encode($data)));
-
- if (trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token)) === "")) {
- unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token));
- copy($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token) . ".old", $_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token));
- }
-
- unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/sessions/" . str_replace("/", "", $token) . ".old");
- } else {
- $_PROFILE = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/lowertokens/" . str_replace("/", "", $token)), true);
- }
-
- $isLowerLoggedIn = true;
- }
- }
-} else if ($_SERVER["REMOTE_ADDR"] === "127.0.0.1") {
- $isLowerLoggedIn = false;
- $isLoggedIn = true;
-}
-
-unset($data); \ No newline at end of file