summaryrefslogtreecommitdiff
path: root/includes/functions.inc
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-12 19:16:53 +0100
committerRaindropsSys <contact@minteck.org>2023-03-12 19:16:53 +0100
commiteb89b15c0f044673c1206a418a21d0baba1a675e (patch)
tree39ac31a576d8b8392cbd9baf8d67621bf2cefa86 /includes/functions.inc
parent5385f0ed8fbb4325203a222a75e6700ffb519349 (diff)
downloadpluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.tar.gz
pluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.tar.bz2
pluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.zip
Updated 104 files, added 3 files, deleted 4 files and renamed 36 files (automated)
Diffstat (limited to 'includes/functions.inc')
-rw-r--r--includes/functions.inc551
1 files changed, 0 insertions, 551 deletions
diff --git a/includes/functions.inc b/includes/functions.inc
deleted file mode 100644
index e9024d1..0000000
--- a/includes/functions.inc
+++ /dev/null
@@ -1,551 +0,0 @@
-<?php
-
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/score.inc";
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.inc";
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/homepage.inc";
-
-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 = 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"]);
- } else {
- return "/error/nomember/?s=$systemID&m=$memberID&t=$type";
- }
-
- $id = $id1 . $id2;
-
- if (str_ends_with(getMemberWithoutSystem($memberID)["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 (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 = 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;
-
- 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 = 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('<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;">' . ($member['display_name'] ?? $member['name']) . '</div>
-<div style="text-decoration:none !important;color:black !important;"><code style="text-decoration:none !important;color:white !important;">' . (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) {
- 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) {
- $app = 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 === "ynmuc" ? "cloudburst" : "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 === "ynmuc" ? "cloudburst" : "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"] : "cloudburst")) . '" 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;">');
- }
-
- if ($id === $app["other"]["id"]) {
- 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));
- } else {
- showMembersFromList(scoreOrder([...array_map(function ($i) use ($id, $travelling) {
- $i["travelling"] = false;
- $i["system"] = $id;
- $i["equestria"] = $travelling[$i['id']]['travelling'] && $travelling[$i['id']]['equestria'];
- return $i;
- }, array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . (isset($app["other"]) && $id === $app["other"]["id"] ? "other" : $id) . "/members.json"), true), function ($i) use ($travelling) {
- return !(isset($travelling[$i['id']]) && $travelling[$i['id']]['travelling'] && (!isset($travelling[$i['id']]['equestria']) || !$travelling[$i['id']]['equestria']));
- })), ...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 isset($travelling[$i['id']]) && $travelling[$i['id']]['travelling'] && (!isset($travelling[$i['id']]['equestria']) || !$travelling[$i['id']]['equestria']);
- }))], $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("other")) {
- function other(bool $hideTitle): void {
- $app = 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): string {
- if (!is_numeric($time)) {
- $time = strtotime($time);
- }
-
- $periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"];
- $periods_fr = $periods;
- $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];
- return "{$difference} {$period} {$tense}";
- }
-}
-
-if (!function_exists("timeIn")) {
- function timeIn($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 = $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) {
- 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) {
- 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"];
- }
- }
-}
-
-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), ...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"]);
- }
- }
-}
-
-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