38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Moderation\Rules;
|
|
|
|
use App\Contracts\Moderation\ModerationRuleInterface;
|
|
use App\Services\Moderation\ModerationRuleRegistryService;
|
|
|
|
class RegexPatternRule implements ModerationRuleInterface
|
|
{
|
|
public function analyze(string $content, string $normalized, array $context = []): array
|
|
{
|
|
$registry = \app(ModerationRuleRegistryService::class);
|
|
$findings = [];
|
|
|
|
foreach ($registry->regexRules() as $rule) {
|
|
$pattern = (string) ($rule['pattern'] ?? '');
|
|
if ($pattern === '') {
|
|
continue;
|
|
}
|
|
|
|
$matched = @preg_match($pattern, $content) === 1 || @preg_match($pattern, $normalized) === 1;
|
|
if (! $matched) {
|
|
continue;
|
|
}
|
|
|
|
$findings[] = [
|
|
'rule' => 'regex_pattern',
|
|
'score' => (int) ($rule['weight'] ?? \app('config')->get('content_moderation.weights.regex_pattern', 30)),
|
|
'reason' => 'Matched custom moderation regex rule',
|
|
'links' => [],
|
|
'domains' => [],
|
|
'keywords' => [$pattern],
|
|
];
|
|
}
|
|
|
|
return $findings;
|
|
}
|
|
} |