From 99194864aa35570dbedbfe15cd2a90403672b075 Mon Sep 17 00:00:00 2001 From: gravel Date: Tue, 6 Jun 2023 10:44:26 +0000 Subject: [PATCH] Add manual NSFW tagging, refactor icon safety --- php/assets/room-icons.php | 19 +-------------- php/servers/known-servers.php | 19 ++++++++++++++- php/servers/servers-rooms.php | 33 +++++++++++++++++++++++++-- sites/+components/tbl-communities.php | 2 +- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/php/assets/room-icons.php b/php/assets/room-icons.php index 940e23a..934b29f 100644 --- a/php/assets/room-icons.php +++ b/php/assets/room-icons.php @@ -69,7 +69,7 @@ $height = intval($height); assert(!empty($width) && !empty($height)); - if (room_icon_safety($room) < 0) { + if ($room->icon_safety() < 0) { return null; } @@ -101,23 +101,6 @@ return room_icon_path_relative($room_id, $size); } - function room_icon_safety(\CommunityRoom $room): int { - global $ICON_ALLOWLIST, $ICON_BLOCKLIST; - if (in_array($room->get_room_identifier(), $ICON_BLOCKLIST)) { - return -1; - } - if (in_array($room->server->get_hostname(), $ICON_ALLOWLIST)) { - return 1; - } - if (in_array($room->server->get_hostname(), $ICON_BLOCKLIST)) { - return -1; - } - if ($room->has_nsfw_keywords()) { - return -1; - } - return 0; - } - file_exists($ROOM_ICONS_CACHE) or mkdir($ROOM_ICONS_CACHE, 0755, true); file_exists($ROOM_ICONS) or mkdir($ROOM_ICONS, 0755, true); ?> diff --git a/php/servers/known-servers.php b/php/servers/known-servers.php index 8467c38..7ec92a3 100644 --- a/php/servers/known-servers.php +++ b/php/servers/known-servers.php @@ -70,9 +70,26 @@ * These hostnames or rooms are considered to have unsafe room icons. */ $ICON_BLOCKLIST = [ + + ]; + + /** + * @var string[] $NSFW_INCLUDE + * These hostnames or rooms are considered to host NSFW content. + */ + $NSFW_INCLUDE = [ "gaohuangse.work", "46.101.253.18", - "womanbodybeauty+13f6" + "womanbodybeauty+13f6", + "88.212.53.198:4080", + ]; + + /** + * @var string[] $NSFW_EXCLDUE + * These hostnames or rooms are considered to host SFW-only content. + */ + $NSFW_EXCLUDE = [ + "AISFW+fc30", ]; $SERVER_ICON_MAPPING = [ diff --git a/php/servers/servers-rooms.php b/php/servers/servers-rooms.php index b6bc705..26ce46f 100644 --- a/php/servers/servers-rooms.php +++ b/php/servers/servers-rooms.php @@ -294,7 +294,7 @@ $this->tags = [...$this->tags, ...$tags]; } - public function has_nsfw_keywords(): bool { + private function has_nsfw_keywords(): bool { // Description not included due to false positives. $blob = strtolower($this->name) . " " . @@ -309,6 +309,35 @@ return false; } + public function matched_by_list(array $filter): bool { + return in_array($this->get_room_identifier(), $filter) || + in_array($this->server->get_pubkey(), $filter) || + in_array($this->server->get_hostname(), $filter); + } + + public function rated_nsfw(): bool { + global $NSFW_INCLUDE, $NSFW_EXCLUDE; + + if ($this->matched_by_list($NSFW_EXCLUDE)) { + return false; + } + + return $this->has_nsfw_keywords() || $this->matched_by_list($NSFW_INCLUDE); + } + + public function icon_safety(): int { + global $ICON_ALLOWLIST, $ICON_BLOCKLIST; + + if ($this->matched_by_list($ICON_ALLOWLIST)) { + return 1; + } + if ($this->rated_nsfw() || $this->matched_by_list($ICON_BLOCKLIST)) { + return -1; + } + + return 0; + } + public const USERS_PER_STAFF = 50; public const USERS_PER_STAFF_WARNING = 200; @@ -359,7 +388,7 @@ ); } - if ($this->has_nsfw_keywords()) { + if ($this->rated_nsfw()) { $derived_tags[] = new CommunityTag( "nsfw", diff --git a/sites/+components/tbl-communities.php b/sites/+components/tbl-communities.php index 087c133..35b7105 100644 --- a/sites/+components/tbl-communities.php +++ b/sites/+components/tbl-communities.php @@ -78,7 +78,7 @@ data-staff='' data-tags='' data-icon='' - data-icon-safe='' + data-icon-safe='icon_safety()?>' data-created='created)?>' >