Improved word censor 🤐 (#1393)

* Improved default word censor

* Updated

* Updated

* Updated

* Update Censor.php

* Update CHANGELOG.md

* Updated
This commit is contained in:
Roman Kelesidis 2024-02-08 23:17:09 +07:00 committed by GitHub
commit d5390132ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 116 additions and 168 deletions

View file

@ -1606,36 +1606,6 @@ function bb_preg_quote($str, $delimiter)
return $text;
}
//
// Obtain list of naughty words and build preg style replacement arrays for use by the
// calling script, note that the vars are passed as references this just makes it easier
// to return both sets of arrays
//
function obtain_word_list(&$orig_word, &$replacement_word)
{
global $bb_cfg;
if (!$bb_cfg['use_word_censor']) {
return false;
}
if (!$sql = CACHE('bb_cache')->get('censored')) {
$sql = DB()->fetch_rowset("SELECT word, replacement FROM " . BB_WORDS);
if (!$sql) {
$sql = [['word' => 1, 'replacement' => 1]];
}
CACHE('bb_cache')->set('censored', $sql, 7200);
}
foreach ($sql as $row) {
//$orig_word[] = '#(?<!\S)(' . str_replace('\*', '\S*?', preg_quote($row['word'], '#')) . ')(?!\S)#iu';
$orig_word[] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($row['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';
$replacement_word[] = $row['replacement'];
}
return true;
}
function bb_die($msg_text, $status_code = null)
{
global $ajax, $bb_cfg, $lang, $template, $theme, $userdata, $user;