Files
0xa0.dev/inc/moderation.php
T
2026-07-22 11:33:23 +02:00

29 lines
701 B
PHP

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