Skip to content

Commit

Permalink
Ajustes no regex do getSpamTerms Ref.: #1
Browse files Browse the repository at this point in the history
  • Loading branch information
israelmelo committed Sep 3, 2024
1 parent 6f0d841 commit 8ef3d1e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit 8ef3d1e

Please sign in to comment.