diff options
author | RaindropsSys <contact@minteck.org> | 2023-03-15 22:40:55 +0100 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-03-15 22:40:55 +0100 |
commit | 940defd2939f52480ed5b548189b549457944995 (patch) | |
tree | 7ca52eca3c3fcafe507dc24b4e2812ab785acc29 /includes/util | |
parent | eb89b15c0f044673c1206a418a21d0baba1a675e (diff) | |
download | pluralconnect-940defd2939f52480ed5b548189b549457944995.tar.gz pluralconnect-940defd2939f52480ed5b548189b549457944995.tar.bz2 pluralconnect-940defd2939f52480ed5b548189b549457944995.zip |
Updated 14 files (automated)
Diffstat (limited to 'includes/util')
-rw-r--r-- | includes/util/banner.inc | 6 | ||||
-rw-r--r-- | includes/util/bitset.inc | 4 | ||||
-rw-r--r-- | includes/util/pronouns.inc | 153 |
3 files changed, 19 insertions, 144 deletions
diff --git a/includes/util/banner.inc b/includes/util/banner.inc index 46d9ce5..1657233 100644 --- a/includes/util/banner.inc +++ b/includes/util/banner.inc @@ -3,6 +3,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $lang; global $pages; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/pronouns.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/Parsedown.php"; $Parsedown = new Parsedown(); $travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling/travelling.json"), true); @@ -21,11 +22,13 @@ function getMemberBannerData(string $id, string $system, bool $french = false) { global $travelling; global $isLoggedIn; global $lang; + global $Parsedown; $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, @@ -463,9 +466,10 @@ function getMemberBannerData(string $id, string $system, bool $french = false) { 'median' => $metadata["median"], 'little' => $metadata["little"] >= 2, 'name' => $member["display_name"] ?? $member["name"], + 'gender' => isset($metadata["gender"]) && trim($metadata["gender"]) !== "" ? $Parsedown->text($metadata["gender"]) : "Agender", 'badges' => $badges, 'prefixes' => $prefixes, - 'pronouns' => getTooltipsFromMark($member["pronouns"], $french) ?? "<span data-bs-toggle='tooltip' title='Pronouns not specified' class='text-muted'>they/them</span>", + 'pronouns' => isset($member["pronouns"]) && trim($member["pronouns"]) !== "" ? $member["pronouns"] : "<i>they/them</i>", 'pronouns_usage' => getMemberPronouns($member['pronouns']), 'last_fronted' => $lastFronted, 'species' => $speciesList, diff --git a/includes/util/bitset.inc b/includes/util/bitset.inc index 131cb39..14f178c 100644 --- a/includes/util/bitset.inc +++ b/includes/util/bitset.inc @@ -11,6 +11,10 @@ function parseMetadata ($metadata) { $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) { diff --git a/includes/util/pronouns.inc b/includes/util/pronouns.inc index 6ab2487..b7c8dd4 100644 --- a/includes/util/pronouns.inc +++ b/includes/util/pronouns.inc @@ -1,149 +1,16 @@ <?php -$pronounsSets = [ - "pony" => [ - "gender" => "ponygender", - "gender:fr" => "poneygenre", - "object" => "pony", +function getMemberPronouns(?string $pronouns): ?array { + return [ + "gender" => "invalid", + "gender:fr" => "invalide", + "object" => "this pony", "person" => "pony", - "possessive_det" => "pony's", - "possessive_pro" => "pony's", - "reflexive" => "ponyself", - "subjective" => "pony", - "third" => true, - "color" => "warning" - ], - "she" => [ - "gender" => "female", - "gender:fr" => "fille", - "object" => "her", - "person" => "girl", - "possessive_det" => "her", - "possessive_pro" => "hers", - "reflexive" => "herself", - "subjective" => "she", + "possessive_det" => "this pony's", + "possessive_pro" => "this pony's", + "reflexive" => "this pony", + "subjective" => "this pony", "third" => true, "color" => "success" - ], - "he" => [ - "gender" => "male", - "gender:fr" => "garçon", - "object" => "him", - "person" => "boy", - "possessive_det" => "his", - "possessive_pro" => "his", - "reflexive" => "himself", - "subjective" => "he", - "third" => true, - "color" => "info" - ], - "it" => [ - "gender" => "agender", - "gender:fr" => "agenre", - "object" => "it", - "person" => "person", - "possessive_det" => "its", - "possessive_pro" => "its", - "reflexive" => "itself", - "subjective" => "it", - "third" => true, - "color" => "light" - ], - "they" => [ - "gender" => "non binary", - "gender:fr" => "non binaire", - "object" => "them", - "person" => "person", - "possessive_det" => "their", - "possessive_pro" => "theirs", - "reflexive" => "themself", - "subjective" => "they", - "third" => false, - "color" => "primary" - ] -]; - -$pronounGetCount = 0; - -$possibilitiesPerSet = []; -foreach ($pronounsSets as $name => $set) { - if (!isset($possibilitiesPerSet[$name])) $possibilitiesPerSet[$name] = []; - $possibilitiesPerSet[$name][] = $name; - - foreach ($set as $category => $value) { - if (is_string($value)) $possibilitiesPerSet[$name][] = $value; - } -} - -function getSetFromValue(string $value) { - global $possibilitiesPerSet; - - foreach ($possibilitiesPerSet as $name => $set) { - if (in_array($value, $set)) { - return $name; - } - } - - return null; -} - -function getPronounsFromMark(?string $mark = null): array { - if (!isset($mark) || trim($mark) === "") { - return ["they"]; - } else { - $parts = array_unique(array_map(function ($i) { - return getSetFromValue($i); - }, explode("/", $mark))); - return $parts; - } -} - -function getMemberPronouns(?string $pronouns): ?array { - global $pronounsSets; - $list = getPronounsFromMark($pronouns); - return $pronounsSets[$list[array_rand($list)]] ?? $pronounsSets["she"]; -} - -function getGenderFromPronoun(string $pronoun, bool $french = false) { - global $pronounsSets; - $set = getPronounsFromMark($pronoun)[0]; - - if ($french) { - return ($pronounsSets[$set] ?? $pronounsSets["they"])["gender:fr"]; - } else { - return ($pronounsSets[$set] ?? $pronounsSets["they"])["gender"]; - } -} - -function pronounInFrench(string $pronoun): string { - return match ($pronoun) { - "she" => "elle", - "her" => "elle", - "he" => "il", - "him" => "lui", - "they" => "iel", - "them" => "iel", - "it" => "iel", - "its" => "iel", - "pony" => "poney", - "pony's" => "à poney", - "ponys" => "à poney", - default => $pronoun, - }; -} - -function getTooltipsFromMark(string $mark = null, bool $french = false): ?string { - if (!isset($mark)) { - return null; - } else { - if ($french) { - return implode("/", array_map(function ($i) { - return "<span title='" . ucfirst(getGenderFromPronoun($i, true)) . "' data-bs-toggle='tooltip'>" . pronounInFrench($i) . "</span>"; - }, explode("/", $mark))); - } else { - return implode("/", array_map(function ($i) { - return "<span title='" . ucfirst(getGenderFromPronoun($i, false)) . "' data-bs-toggle='tooltip'>" . $i . "</span>"; - }, explode("/", $mark))); - } - } + ]; }
\ No newline at end of file |