Add manual NSFW tagging, refactor icon safety

dev
gravel 1 year ago
parent a6841ab9c5
commit 99194864aa
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -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);
?>

@ -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 = [

@ -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",

@ -78,7 +78,7 @@
data-staff='<?=$staff_json?>'
data-tags='<?=$tags_json?>'
data-icon='<?=room_icon($room, '64x64')?>'
data-icon-safe='<?=room_icon_safety($room)?>'
data-icon-safe='<?=$room->icon_safety()?>'
data-created='<?=html_sanitize($room->created)?>'
>
<td class="td_language" title="Language flag for '<?=$name?>'"><?=$language?></td>

Loading…
Cancel
Save