summaryrefslogtreecommitdiff
path: root/includes/util/functions.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/util/functions.inc')
-rw-r--r--includes/util/functions.inc102
1 files changed, 63 insertions, 39 deletions
diff --git a/includes/util/functions.inc b/includes/util/functions.inc
index 0cf15d2..67b1786 100644
--- a/includes/util/functions.inc
+++ b/includes/util/functions.inc
@@ -1,10 +1,54 @@
<?php
+use JetBrains\PhpStorm\NoReturn;
+
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/score.inc";
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.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("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);
@@ -30,7 +74,7 @@ if (!function_exists("getLastFronted")) {
}
if (!function_exists("createJob")) {
- function createJob($title, $options) {
+ function createJob($title, $options): void {
$job = [
"name" => $title,
"options" => $options,
@@ -42,7 +86,7 @@ if (!function_exists("createJob")) {
}
if (!function_exists("formatPonypush")) {
- function formatPonypush($message) {
+ function formatPonypush($message): string {
return "Update to Ponypush 3.1.0 or later — (\$PA1$\$" . base64_encode($message) . "\$\$)";
}
}
@@ -54,14 +98,14 @@ if (!function_exists("generateToken")) {
}
if (!function_exists("peh_error")) {
- function peh_error($message, $code = 500): void {
+ #[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") {
+ function getAsset($systemID, $memberID = null, $type = "avatars"): string {
$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;
@@ -132,11 +176,7 @@ if (!function_exists("getAsset")) {
}
if (!function_exists("rgbToHsl")) {
- function rgbToHsl($r, $g, $b) {
- $oldR = $r;
- $oldG = $g;
- $oldB = $b;
-
+ function rgbToHsl($r, $g, $b): array {
$r /= 255;
$g /= 255;
$b /= 255;
@@ -176,13 +216,11 @@ if (!function_exists("rgbToHsl")) {
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];
@@ -198,13 +236,11 @@ if (!function_exists("imageCreateCorners")) {
}
}
- # create corners
if ($res) {
- $q = 10; # change this if you want
+ $q = 10;
$radius *= $q;
- # find unique color
do {
$r = rand(0, 255);
$g = rand(0, 255);
@@ -235,14 +271,12 @@ if (!function_exists("imageCreateCorners")) {
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);
@@ -253,22 +287,8 @@ if (!function_exists("imageCreateCorners")) {
}
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;
- }
+ function getMiniName(string $name): string {
+ return $name;
}
}
@@ -339,7 +359,7 @@ if (!function_exists("getMemberWithoutSystem")) {
}
if (!function_exists("showMembersFromList")) {
- function showMembersFromList(array $list) {
+ 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;">
@@ -351,7 +371,7 @@ if (!function_exists("showMembersFromList")) {
}
if (!function_exists("prettySize")) {
- function prettySize($bytes) {
+ function prettySize($bytes): string {
if ($bytes > 1024) {
if ($bytes > 1024**2) {
if ($bytes > 1024**3) {
@@ -369,7 +389,7 @@ if (!function_exists("prettySize")) {
}
if (!function_exists("showSystem")) {
- function showSystem(string $id, string $name, string $color, bool $hideTitle) {
+ 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;
@@ -401,7 +421,7 @@ if (!function_exists("showSystem")) {
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'];
+ if (isset($travelling[$i['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']));
@@ -549,7 +569,7 @@ if (!function_exists("timeIn")) {
}
if (!function_exists("duration")) {
- function duration($seconds) {
+ function duration($seconds): string {
global $lang; global $pages;
if ($seconds >= 60) {
@@ -586,7 +606,7 @@ if (!function_exists("duration")) {
}
if (!function_exists("relativeDate")) {
- function relativeDate($date, $showTime = true) {
+ function relativeDate($date, $showTime = true): string {
if (!is_numeric($date)) $date = strtotime($date);
if (!$showTime) {
@@ -620,6 +640,8 @@ if (!function_exists("getMemberSystem")) {
foreach ($list as $item) {
if ($item["id"] === $id) return $item["_system"];
}
+
+ return null;
}
}
@@ -630,6 +652,8 @@ if (!function_exists("getMemberFromName")) {
foreach ($list as $item) {
if ($item["name"] === $name) return getMemberWithoutSystem($item["id"]);
}
+
+ return null;
}
}