Merge branch 'main' of https://git.0xa0.dev/0xA0/0xa0.dev
Deploy / deploy (push) Successful in 4s
Deploy / deploy (push) Successful in 4s
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user