Skip to content

Commit

Permalink
Ajustada condição para verificar os termos Ref.: #1
Browse files Browse the repository at this point in the history
  • Loading branch information
israelmelo committed Sep 2, 2024
1 parent fa52428 commit 2c67c78
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,28 @@ public function __construct($config = [])
'instalador',
];

$default_fields = [
'name',
'shortDescription',
'longDescription',
'nomeSocial',
'nomeCompleto',
'comunidadesTradicionalOutros',
'facebook',
'twitter',
'instagram',
'linkedin',
'vimeo',
'spotify',
'youtube',
'pinterest',
'tiktok'
];

$config += [
'terms' => env('SPAM_DETECTOR_TERMS', $default_terms),
'entities' => env('SPAM_DETECTOR_ENTITIES', ['Agent', 'Opportunity', 'Project', 'Space', 'Event']),
'fields' => env('SPAM_DETECTOR_FIELDS', ['name', 'shortDescription', 'longDescription', 'nomeSocial', 'nomeCompleto', 'comunidadesTradicionalOutros']),
'fields' => env('SPAM_DETECTOR_FIELDS', $default_fields),
'termsBlock' => env('SPAM_DETECTOR_TERMS_BLOCK', $terms_block)
];

Expand Down Expand Up @@ -223,9 +241,8 @@ public function formatText($text)
{
$text = trim($text);
$text = strip_tags($text);
$text = str_replace(["\n", "\t"], "", $text);
$text = mb_strtolower($text);
$text = preg_replace("/[^a-z0-9]/", "", $text);
$text = preg_replace("/[^a-z0-9_\s]/", "", $text);

return $text;
}
Expand Down Expand Up @@ -269,17 +286,22 @@ public function getSpamTerms($entity, $terms): array {
foreach ($terms as $term) {
$lowercase_term = $this->formatText($term);

if (strpos($lowercase_value, $lowercase_term) !== false && !in_array($lowercase_term, $found_terms)) {
$found_terms[] = $term;
$pattern = '/\b' . preg_quote($lowercase_term, '/') . '\b/';

if (preg_match($pattern, $lowercase_value) && !in_array($term, $found_terms)) {

$found_terms[$field][] = $term;
}
}

if ($found_terms) {
$spam_detector[] = [
'terms' => $found_terms,
'field' => $field,
];
}
}
}

if ($found_terms) {
foreach($found_terms as $key => $value) {
$spam_detector[] = [
'field' => $key,
'terms' => $value
];
}
}

Expand Down

0 comments on commit 2c67c78

Please sign in to comment.