From 8ef3d1ee3a231b05d82bdf30e617c14dfd436ee7 Mon Sep 17 00:00:00 2001 From: israelmelo Date: Tue, 3 Sep 2024 11:34:08 -0300 Subject: [PATCH] Ajustes no regex do getSpamTerms Ref.: #1 --- Plugin.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Plugin.php b/Plugin.php index b353252..6749151 100644 --- a/Plugin.php +++ b/Plugin.php @@ -259,7 +259,7 @@ public function formatText($text) $text = trim($text); $text = strip_tags($text); $text = mb_strtolower($text); - $text = preg_replace("/[^a-z0-9_\s]/", "", $text); + $text = preg_replace("/[^a-z0-9 \s]/", "", $text); return $text; } @@ -295,19 +295,24 @@ public function getSpamTerms($entity, $terms): array { $fields = $this->config['fields']; $spam_detector = []; $found_terms = []; - + $special_chars = ['@', '#', '$', '%', '^', 'ยท', '&', '*', '(', ')', '-', '_', '=', '+', '{', '}', '[', ']', '|', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/', ' ', '']; + foreach ($fields as $field) { if ($value = $entity->$field) { $lowercase_value = $this->formatText($value); foreach ($terms as $term) { $lowercase_term = $this->formatText($term); + + foreach($special_chars as $special_char) { + $_term = implode($special_char, mb_str_split($lowercase_term)); - $pattern = '/\b' . preg_quote($lowercase_term, '/') . '\b/'; - - if (preg_match($pattern, $lowercase_value) && !in_array($term, $found_terms)) { - - $found_terms[$field][] = $term; + $pattern = '/([^\w]|[_0-9]|^)' . preg_quote($_term, '/') . '([^\w]|[_0-9]|$)/'; + + if (preg_match($pattern, $lowercase_value) && !in_array($term, $found_terms)) { + + $found_terms[$field][] = $term; + } } } }