Просмотр файла engine/functions/censure.php

Размер файла: 6.05Kb
  1. <?php
  2.  
  3. function censure($s, $delta = 3, $continue = "\xe2\x80\xa6")
  4. {
  5.  
  6. static $pretext = array(
  7. '[уyоo]_? (?=[еёeхx])', '[вvbсc]_? (?=[хпбмгжxpmgj])', '[вvbсc]_?[ъь]_? (?=[еёe])', 'ё_? (?=[бb])', '[вvb]_?[ыi]_?', '[зz3]_?[аa]_?', '[нnh]_?[аaеeиi]_?', '[вvb]_?[сc]_? (?=[хпбмгжxpmgj])', '[оo]_?[тtбb]_? (?=[хпбмгжxpmgj])', '[оo]_?[тtбb]_?[ъь]_? (?=[еёe])', '[иiвvb]_?[зz3]_? (?=[хпбмгжxpmgj])', '[иiвvb]_?[зz3]_?[ъь]_? (?=[еёe])', '[иi]_?[сc]_? (?=[хпбмгжxpmgj])', '[пpдdg]_?[оo]_? (?> [бb]_? (?=[хпбмгжxpmgj])
  8. | [бb]_? [ъь]_? (?=[еёe])
  9. | [зz3]_? [аa] _?
  10. )?', '[пp]_?[рr]_?[оoиi]_?', '[зz3]_?[лl]_?[оo]_?', '[нnh]_?[аa]_?[дdg]_? (?=[хпбмгжxpmgj])', '[нnh]_?[аa]_?[дdg]_?[ъь]_? (?=[еёe])', '[пp]_?[оo]_?[дdg]_? (?=[хпбмгжxpmgj])', '[пp]_?[оo]_?[дdg]_?[ъь]_? (?=[еёe])', '[рr]_?[аa]_?[зz3сc]_? (?=[хпбмгжxpmgj])', '[рr]_?[аa]_?[зz3сc]_?[ъь]_? (?=[еёe])', '[вvb]_?[оo]_?[зz3сc]_? (?=[хпбмгжxpmgj])', '[вvb]_?[оo]_?[зz3сc]_?[ъь]_? (?=[еёe])', '[нnh]_?[еe]_?[дdg]_?[оo]_?', '[пp]_?[еe]_?[рr]_?[еe]_?', '[oо]_?[дdg]_?[нnh]_?[оo]_?', '[кk]_?[oо]_?[нnh]_?[оo]_?', '[мm]_?[уy]_?[дdg]_?[оoаa]_?', '[oо]_?[сc]_?[тt]_?[оo]_?', '[дdg]_?[уy]_?[рpr]_?[оoаa]_?', '[хx]_?[уy]_?[дdg]_?[оoаa]_?', '[мm]_?[нnh]_?[оo]_?[гg]_?[оo]_?', '[мm]_?[оo]_?[рpr]_?[дdg]_?[оoаa]_?', '[мm]_?[оo]_?[зz3]_?[гg]_?[оoаa]_?', '[дdg]_?[оo]_?[лl]_?[бb6]_?[оoаa]_?', );
  11.  
  12. static $badwords = array(
  13. '(?<=[_\d]) {RE_PRETEXT}?
  14. [hхx]_?[уyu]_?[йiеeёяюju] #хуй, хуя, хую, хуем, хуёвый
  15. #исключения:
  16. (?<! _hue(?=_) #HUE -- цветовая палитра
  17. | _hue(?=so_) #hueso -- испанское слово
  18. | _хуе(?=дин) #Хуедин -- город в Румынии
  19. )',
  20.  
  21. '(?<=[_\d]) {RE_PRETEXT}?
  22. [пp]_?[иi]_?[зz3]_?[дd]_?[:vowel:]',
  23. '(?<=[_\d]) {RE_PRETEXT}?
  24. [eеё]_? (?<!не[её]_) [бb6]_?(?: [уyиi]_ #ебу, еби
  25. | [ыиiоoaаеeёуy]_?[:consonant:] #ебут, ебать, ебись, ебёт, поеботина, выебываться, ёбарь
  26. | [лl][оoаaыиi] #ебло, ебла, ебливая, еблись, еблысь
  27. | [нn]_?[уy] #ёбнул, ёбнутый
  28. | [кk]_?[аa] #взъёбка
  29. )',
  30. '(?<=[_\d]) {RE_PRETEXT}
  31. (?<=[^_\d][^_\d]|[^_\d]_[^_\d]_) [eеё]_?[бb6] (?:_|_?[аa]_?[^_\d])',
  32. '(?<=[_\d]) {RE_PRETEXT}?
  33. [бb6]_?[лl]_?(?:я|ya)(?: _ #бля
  34. | _?[тд] #блять, бляди
  35. )',
  36.  
  37. '(?<=[_\d]) [пp]_?[иieе]_?[дdg]_?[eеaаoо]_?[rpр]',
  38. '(?<=[_\d]) [мm]_?[уy]_?[дdg]_?[аa]',
  39. '(?<=[_\d]) [zж]_?h?_?[оo]_?[pп]_?[aаyуыiеeoо]',
  40. '(?<=[_\d]) [гg]_?[оo]_?[вvb]_?[нnh]_?[оoаaяеeyу]',
  41. '(?<=[_\d]) f_?u_?[cс]_?k',
  42. );
  43.  
  44. static $re_trans = array(
  45. '_' => '\x20', '[:vowel:]' => '[аеиоуыэюяёaeioyu]', '[:consonant:]' => '[^аеиоуыэюяёaeioyu\x20\d]', );
  46. $re_badwords = str_replace('{RE_PRETEXT}',
  47. '(?>' . implode('|', $pretext) . ')',
  48. '~' . implode('|', $badwords) . '~sxu');
  49. $re_badwords = strtr($re_badwords, $re_trans);
  50.  
  51. static $trans = array(
  52. "\xc2\xad" => '', "\xcc\x81" => '', '/\\' => 'л', '/|' => 'л', "\xd0\xb5\xd0\xb5" => "\xd0\xb5\xd1\x91", );
  53. $s = strtr($s, $trans);
  54.  
  55. preg_match_all('/(?> \xd0[\xb0-\xbf]|\xd1[\x80-\x8f\x91] #[а-я]
  56. | [a-z\d]+
  57. )+
  58. /sx', $s, $m);
  59. $s = ' ' . implode(' ', $m[0]) . ' ';
  60.  
  61. $s = preg_replace('/( [\xd0\xd1][\x80-\xbf] #оптимизированное [а-я]
  62. | [a-z\d]
  63. ) \\1+
  64. /sx', '$1', $s);
  65. if (preg_match($re_badwords, $s, $m, PREG_OFFSET_CAPTURE))
  66. {
  67. list($word, $offset) = $m[0];
  68. $s1 = substr($s, 0, $offset);
  69. $s2 = substr($s, $offset + strlen($word));
  70. $delta = intval($delta);
  71. if ($delta < 1 || $delta > 10) $delta = 3;
  72. preg_match('/ (?> \x20 (?>[\xd0\xd1][\x80-\xbf]|[a-z\d]+)+ ){1,' . $delta . '}
  73. \x20?
  74. $/sx', $s1, $m1);
  75. preg_match('/^ (?>[\xd0\xd1][\x80-\xbf]|[a-z\d]+)* #окончание
  76. \x20?
  77. (?> (?>[\xd0\xd1][\x80-\xbf]|[a-z\d]+)+ \x20 ){1,' . $delta . '}
  78. /sx', $s2, $m2);
  79. $fragment = (ltrim(@$m1[0]) !== ltrim($s1) ? $continue : '') .
  80. trim(@$m1[0] . '[' . trim($word) . ']' . @$m2[0]) .
  81. (rtrim(@$m2[0]) !== rtrim($s2) ? $continue : '');
  82. return $fragment;
  83. }
  84. return false;
  85. }
  86.  
  87. ?>