/ wordfilters / test.php
test.php
  1  <?php
  2  function word_filter_callback($m) {
  3    static $vals = array(
  4      'smh' => 'baka',
  5      'SMH' => 'BAKA',
  6      'tbh' => 'desu',
  7      'TBH' => 'DESU',
  8      'fam' => 'senpai',
  9      'FAM' => 'SENPAI',
 10      'Fam' => 'Senpai',
 11      'fams' => 'senpaitachi',
 12      'FAMS' => 'SENPAITACHI',
 13      'FAMs' => 'SENPAITACHI',
 14      'Fams' => 'Senpaitachi'
 15    );
 16    
 17    if (!isset($vals[$m[2]])) {
 18      return $m[0];
 19    }
 20    
 21    return "{$m[1]}{$vals[$m[2]]}{$m[3]}";
 22  }
 23  
 24  function word_filter_callback_soy($m) {
 25    $is_uc = $m[2] === strtoupper($m[2]);
 26    
 27    $lc = strtolower($m[4]);
 28    
 29    if ($lc === 'uz') {
 30      return $m[0];
 31    }
 32    
 33    if ($lc === 'im' || $lc === 'lent') {
 34      $m[4] = '';
 35    }
 36    
 37    if (!isset($m[4][1])) {
 38      if ($is_uc) {
 39        $onions = 'ONIONS';
 40      }
 41      else {
 42        if ($m[2][0] === 's') {
 43          $onions = 'onions';
 44        }
 45        else {
 46          $onions = 'Onions';
 47        }
 48      }
 49      
 50      return "{$m[1]}{$onions}{$m[4]}";
 51    }
 52    
 53    if ($m[2][0] === 's') {
 54      $b = 'b';
 55    }
 56    else {
 57      $b = 'B';
 58    }
 59    
 60    $ac = mb_strlen($m[3]);
 61    
 62    if ($ac == 1) {
 63      $a = 'a';
 64    }
 65    else {
 66      if ($ac < 35) {
 67        $a = str_repeat('a', $ac);
 68      }
 69      else {
 70        $a = 'a';
 71      }
 72    }
 73    
 74    $based = "{$b}{$a}sed";
 75    
 76    if ($is_uc) {
 77      $based = strtoupper($based);
 78    }
 79    
 80    return $m[1] . $based . $m[4];
 81  }
 82  
 83  function april_leet_filter($text) {
 84    $pairs = [
 85      [
 86        'a' => '4',
 87        'A' => '4'
 88      ],
 89      [
 90        'e' => '3',
 91        'E' => '3'
 92      ],
 93      [
 94        'i' => '1',
 95        'I' => '1'
 96      ],
 97      [
 98        'o' => '0',
 99        'O' => '0'
100      ],
101      [
102        's' => '5',
103        'S' => '5'
104      ],
105      [
106        'T' => '7',
107        't' => '7'
108      ]
109    ];
110    
111    $roll1 = mt_rand(0, 5);
112    $roll2 = mt_rand(0, 5);
113    
114    
115    if ($roll1 === 5) {
116      $text = preg_replace('/([^gl])[tT]/', '${1}7', $text);
117    }
118    else {
119      $repl = $pairs[$roll1];
120      $text = strtr($text, $repl);
121    }
122    
123    if ($roll2 != $roll1) {
124      if ($roll2 === 5) {
125        $text = preg_replace('/([^gl])[tT]/', '${1}7', $text);
126      }
127      else {
128        $repl = $pairs[$roll2];
129        $text = strtr($text, $repl);
130      }
131    }
132    
133    return $text;
134  }
135  
136  // $text contents of a field
137  // $type name of the field
138  function word_filter($text, $type) {
139    if ($type !== 'com') {
140      return $text;
141    }
142    
143  //  $text = str_replace('Cuck', 'Kek', $text);
144  //  $text = str_replace('cuck', 'kek', $text);
145    $text = str_replace('CUCK', 'KEK', $text);
146    
147    $text = preg_replace_callback('/(\b)(sjw|sjws|smh|tbh|fams|fam)(\b)/i', 'word_filter_callback', $text);
148    
149    $text = preg_replace_callback('/(\b)(s([o0οоօჿ]+)[yуΥ])(\b|[[:alpha:]]{2,4})/iu', 'word_filter_callback_soy', $text);
150    
151    $text = april_leet_filter($text);
152    
153    return $text;
154  }