← All changes
|
includes/Services/Products/DescriptionErrorSanitizer.php
+26
-1
1.10.2
→
1.10.23
View file →
| @@ -56,9 +56,19 @@ | ||
| 56 | 56 | if (is_string($snippet) && $snippet !== '') { |
| 57 | 57 | if (preg_match_all('/<em>(.*?)<\/em>/isu', $snippet, $matches)) { |
| 58 | 58 | foreach ($matches[1] as $match) { |
| 59 | 59 | $value = trim(wp_strip_all_tags(html_entity_decode($match, ENT_QUOTES | ENT_HTML5, 'UTF-8'))); |
| 60 | - if ($value !== '') $found[] = $value; | |
| 60 | + if ($value === '') continue; | |
| 61 | + | |
| 62 | + $found[] = $value; | |
| 63 | + | |
| 64 | + // Basalam highlights a whole window of text and returns it normalized | |
| 65 | + // (e.g. "یک" comes back as "1"), so the full phrase often matches nothing | |
| 66 | + // in the original description. The part that actually triggers the | |
| 67 | + // "social id" signal is the handle-like token, so target it separately. | |
| 68 | + foreach (self::handleLikeTokens($value) as $token) { | |
| 69 | + $found[] = $token; | |
| 70 | + } | |
| 61 | 71 | } |
| 62 | 72 | } |
| 63 | 73 | } |
| 64 | 74 | |
| @@ -68,8 +78,23 @@ | ||
| 68 | 78 | if ($value !== '') $found[] = $value; |
| 69 | 79 | } |
| 70 | 80 | |
| 71 | 81 | return $found; |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Pulls out handle/domain-like tokens ("s.exy", "س.کسی", "insta.gram") from a | |
| 86 | + * highlighted snippet. | |
| 87 | + * | |
| 88 | + * @return string[] | |
| 89 | + */ | |
| 90 | + private static function handleLikeTokens(string $text): array | |
| 91 | + { | |
| 92 | + if (!preg_match_all('/[\p{L}\p{N}_]+(?:\.[\p{L}\p{N}_]+)+/u', $text, $matches)) return []; | |
| 93 | + | |
| 94 | + return array_values(array_filter($matches[0], static function ($token) { | |
| 95 | + return mb_strlen($token) >= 3; | |
| 96 | + })); | |
| 72 | 97 | } |
| 73 | 98 | |
| 74 | 99 | public static function sanitize(string $description, array $values): string |
| 75 | 100 | { |