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

@ -365,14 +365,8 @@ if (!$ranks = $datastore->get('ranks')) {
$ranks = $datastore->get('ranks');
}
// Define censored word matches
$orig_word = $replacement_word = [];
obtain_word_list($orig_word, $replacement_word);
// Censor topic title
if (count($orig_word)) {
$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
}
$topic_title = $wordCensor->censorString($topic_title);
// Post, reply and other URL generation for templating vars
$new_topic_url = POSTING_URL . "?mode=newtopic&f=" . $forum_id;
@ -627,28 +621,26 @@ for ($i = 0; $i < $total_posts; $i++) {
}
// Replace naughty words
if (count($orig_word)) {
if ($user_sig) {
$user_sig = str_replace(
'\"', '"',
substr(
preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($orig_word, $replacement_word) {
return preg_replace($orig_word, $replacement_word, reset($matches));
}, '>' . $user_sig . '<'), 1, -1
)
);
}
$message = str_replace(
if ($user_sig) {
$user_sig = str_replace(
'\"', '"',
substr(
preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($orig_word, $replacement_word) {
return preg_replace($orig_word, $replacement_word, reset($matches));
}, '>' . $message . '<'), 1, -1
preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($wordCensor) {
return $wordCensor->censorString(reset($matches));
}, '>' . $user_sig . '<'), 1, -1
)
);
}
$message = str_replace(
'\"', '"',
substr(
preg_replace_callback('#(\>(((?>([^><]+|(?R)))*)\<))#s', function ($matches) use ($wordCensor) {
return $wordCensor->censorString(reset($matches));
}, '>' . $message . '<'), 1, -1
)
);
// Replace newlines (we use this rather than nl2br because till recently it wasn't XHTML compliant)
if ($user_sig) {
$user_sig = $bb_cfg['user_signature_start'] . $user_sig . $bb_cfg['user_signature_end'];