diff options
author | Minteck <contact@minteck.org> | 2022-08-26 22:29:23 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-26 22:29:23 +0200 |
commit | 09bd0164ebc020a54b944b7326dcba496fb5d82c (patch) | |
tree | 0c5e765e627ecc94e534ccb6e2bc83917d58dc4c /includes/functions.php | |
parent | a2df9a69dcc14cb70118cda2ded499055e7ee358 (diff) | |
download | pluralconnect-09bd0164ebc020a54b944b7326dcba496fb5d82c.tar.gz pluralconnect-09bd0164ebc020a54b944b7326dcba496fb5d82c.tar.bz2 pluralconnect-09bd0164ebc020a54b944b7326dcba496fb5d82c.zip |
idk when was the last commit so I'm making a new one - Violet Dawn
Diffstat (limited to 'includes/functions.php')
-rw-r--r-- | includes/functions.php | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/includes/functions.php b/includes/functions.php new file mode 100644 index 0000000..51317ca --- /dev/null +++ b/includes/functions.php @@ -0,0 +1,202 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/score.php"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php"; + +if (!function_exists("getMiniName")) { + function getMiniName(string $name) { + $parts = explode(" ", $name); + + if (strlen($parts[0]) > 3 && !str_ends_with($parts[0], "e") && $parts[0] !== "Filly") { + if (str_contains($parts[0], "/")) { + return explode("/", $parts[0])[0]; + } else { + return $parts[0]; + } + } else { + return $name; + } + } +} + +if (!function_exists("getSystemMember")) { + function getSystemMember(string $system, string $id) { + $systemID = $system; + + $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("showMembersFromList")) { + function showMembersFromList(array $list) { + foreach ($list as $member) { if ($member['name'] !== "unknown" && $member['name'] !== "fusion") { + echo('<!-- ' . ($member['display_name'] ?? $member['name']) . ' --> +<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;"><div> +<img alt="" src="' . $member['avatar_url'] . '" style="border-radius:999px;background-color:rgba(0, 0, 0, .25);height:48px;display:block;margin-left:auto;margin-right:auto;"> +<div style="text-decoration:none;color:white;margin-top:5px;">' . ($member['display_name'] ?? $member['name']) . '</div> +<div style="text-decoration:none !important;color:black !important;"><code style="text-decoration:none !important;color:white !important;">' . ($member['travelling'] ? "+" . ($member['proxy_tags'][0]['prefix'] ?? " ") : ($member['proxy_tags'][0]['prefix'] ?? " ")) . '</code></div> +</div></div></a>'); + }} + } +} + +if (!function_exists("showSubsystem")) { + function showSubsystem(array $data, string $parentSystem) { + $subsystemData = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$parentSystem-subsystem-$data[source].json"), true); + + echo('<!-- ' . $subsystemData["name"] . ' --> +<div id="hpd-cloudburst" style="background:rgba(255, 255, 255, .1);border-radius:10px;padding:10px;display:grid;grid-template-columns: 1fr;margin-bottom:10px;">'); + echo(' <div style="display:grid;grid-template-columns:repeat(6, 1fr);grid-gap:10px;">'); + + showMembersFromList(scoreOrder(array_map(function ($i) use ($parentSystem) { + return getSystemMember($parentSystem, $i); + }, $data["members"]), $parentSystem)); + + echo('</div> + +</div>'); + } +} + +if (!function_exists("showSystem")) { + function showSystem(string $id, string $name, string $color, bool $hideTitle) { + global $travelling; + + $global = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$id-general.json"), true); + + if ($hideTitle) { + echo('<!-- ' . $name . ' --> +<div id="hpd-' . ($id === "gdapd" ? "raindrops" : "cloudburst") . '" style="background:rgba(255, 255, 255, .1);border-radius:10px;padding:10px;display:grid;grid-template-columns: 1fr;margin-bottom:10px;">'); + } else { + echo('<!-- ' . $name . ' --> +<div id="hpd-' . ($id === "gdapd" ? "raindrops" : "cloudburst") . '" 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('<!-- System Name --> +<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" : "cloudburst") . '" class="hpd-system"> +<div style="text-align:center;"><img src="/assets/uploads/' . ($id === "gdapd" ? "raindrops" : "cloudburst") . '.png" 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) { + $i["travelling"] = false; + $i["system"] = $id; + return $i; + }, array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$id-members.json"), true), function ($i) use ($travelling) { + return !$travelling[$i['id']]['travelling']; + })), ...array_map(function ($i) use ($id) { + $i["travelling"] = true; + $i["system"] = ($id === "gdapd" ? "ynmuc" : "gdapd"); + return $i; + }, array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($id === "gdapd" ? "ynmuc" : "gdapd") . "-members.json"), true), function ($i) use ($travelling) { + return $travelling[$i['id']]['travelling']; + }))], $id)); + + echo('</div> + +</div>'); + } +} + +if (!function_exists("cloudburst")) { + function cloudburst(bool $hideTitle): void { + showSystem("ynmuc", "Cloudburst System", "#5f08a9a6", $hideTitle); + } +} + +if (!function_exists("raindrops")) { + function raindrops(bool $hideTitle): void { + showSystem("gdapd", "Raindrops System", "#a95f08a6", $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): string { + if (!is_numeric($time)) { + $time = strtotime($time); + } + + $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"]; + $lengths = array("60", "60", "24", "7", "4.35", "12", "100"); + + $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] . ($difference >1 ? "s" :''); + return "{$difference} {$period} {$tense}"; + } +} + +if (!function_exists("getMemberSystem")) { + function getMemberSystem(string $id) { + $list = scoreOrderGlobal(); + + foreach ($list as $item) { + if ($item["id"] === $id) return $item["_system"]; + } + } +} + +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/ynmuc-members.json"), true)]; + + foreach ($list as $item) { + if ($item["name"] === $name) return $item; + } + } +} + +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; + } + } +}
\ No newline at end of file |