moderation

This commit is contained in:
2026-07-22 11:33:23 +02:00
parent 33f3fafb88
commit da888e085b
2 changed files with 84 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
function gb_badwords(): array {
static $words = null;
if ($words === null) {
$file = DATA_DIR . '/badwords.txt';
$words = is_file($file)
? array_values(array_filter(array_map('trim', file($file))))
: [];
}
return $words;
}
function gb_censor(string $text): string {
foreach (gb_badwords() as $bad) {
if ($bad === '') continue;
$text = preg_replace(
'/\b' . preg_quote($bad, '/') . '\b/iu',
str_repeat('*', mb_strlen($bad)),
$text
);
}
return $text;
}
function gb_has_link(string $text): bool {
return (bool) preg_match('~\b(?:https?://|www\.)\S+~i', $text);
}