|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AbuseKeywordPurifier\src\Services; |
|
4
|
|
|
|
|
5
|
|
|
class ProfanityWordPurifier { |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @param string $content |
|
9
|
|
|
* @param array $whiteList |
|
10
|
|
|
* @param string $replaceWith |
|
11
|
|
|
* |
|
12
|
|
|
* @return string |
|
13
|
|
|
*/ |
|
14
|
|
|
public static function contentFilter($content, $whiteList, $replaceWith) { |
|
15
|
|
|
$replace = array(); |
|
16
|
|
|
$replace['a'] = '(a|a\.|a\-|4|@|Á|á|À|Â|à|Â|â|Ä|ä|Ã|ã|Å|å|α|Δ|Λ|λ)'; |
|
17
|
|
|
$replace['b'] = '(b|b\.|b\-|8|\|3|ß|Β|β)'; |
|
18
|
|
|
$replace['c'] = '(c|c\.|c\-|Ç|ç|¢|€|<|\(|{|©)'; |
|
19
|
|
|
$replace['d'] = '(d|d\.|d\-|∂|\|\)|Þ|þ|Ð|ð)'; |
|
20
|
|
|
$replace['e'] = '(e|e\.|e\-|3|€|È|è|É|é|Ê|ê|∑)'; |
|
21
|
|
|
$replace['f'] = '(f|f\.|f\-|ƒ)'; |
|
22
|
|
|
$replace['g'] = '(g|g\.|g\-|6|9)'; |
|
23
|
|
|
$replace['h'] = '(h|h\.|h\-|Η)'; |
|
24
|
|
|
$replace['i'] = '(i|i\.|i\-|!|\||\]\[|]|1|∫|Ì|Í|Î|Ï|ì|í|î|ï)'; |
|
25
|
|
|
$replace['j'] = '(j|j\.|j\-)'; |
|
26
|
|
|
$replace['k'] = '(k|k\.|k\-|Κ|κ)'; |
|
27
|
|
|
$replace['l'] = '(l|1\.|l\-|!|\||\]\[|]|£|∫|Ì|Í|Î|Ï)'; |
|
28
|
|
|
$replace['m'] = '(m|m\.|m\-)'; |
|
29
|
|
|
$replace['n'] = '(n|n\.|n\-|η|Ν|Π)'; |
|
30
|
|
|
$replace['o'] = '(o|o\.|o\-|0|Ο|ο|Φ|¤|°|ø)'; |
|
31
|
|
|
$replace['p'] = '(p|p\.|p\-|ρ|Ρ|¶|þ)'; |
|
32
|
|
|
$replace['q'] = '(q|q\.|q\-)'; |
|
33
|
|
|
$replace['r'] = '(r|r\.|r\-|®)'; |
|
34
|
|
|
$replace['s'] = '(s|s\.|s\-|5|\$|§)'; |
|
35
|
|
|
$replace['t'] = '(t|t\.|t\-|Τ|τ)'; |
|
36
|
|
|
$replace['u'] = '(u|u\.|u\-|υ|µ)'; |
|
37
|
|
|
$replace['v'] = '(v|v\.|v\-|υ|ν)'; |
|
38
|
|
|
$replace['w'] = '(w|w\.|w\-|ω|ψ|Ψ)'; |
|
39
|
|
|
$replace['x'] = '(x|x\.|x\-|Χ|χ)'; |
|
40
|
|
|
$replace['y'] = '(y|y\.|y\-|¥|γ|ÿ|ý|Ÿ|Ý)'; |
|
41
|
|
|
$replace['z'] = '(z|z\.|z\-|Ζ)'; |
|
42
|
|
|
|
|
43
|
|
|
$replacement = array(); |
|
44
|
|
|
$whiteListCount = count($whiteList); |
|
45
|
|
|
|
|
46
|
|
|
for ($x = 0; $x < $whiteListCount; $x++) { |
|
47
|
|
|
$replacement[$x] = str_repeat($replaceWith, strlen($whiteList[$x])); |
|
48
|
|
|
$whiteList[$x] = '/' . str_ireplace(array_keys($replace), array_values($replace), $whiteList[$x]) . '/i'; |
|
49
|
|
|
} |
|
50
|
|
|
$cleanContent = preg_replace($whiteList, $replacement, $content); |
|
51
|
|
|
|
|
52
|
|
|
return $cleanContent; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|