Skip to content

Commit

Permalink
Wordfilter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedEnchilada committed Aug 21, 2014
1 parent 878d734 commit 10ecb7e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions plugins/NoSwear/NoSwearPlugin.php
Expand Up @@ -22,7 +22,6 @@ class NoSwearPlugin extends Plugin {
private function _getWordlist($skipLinks = false) {
$s = '\!\@\#\$\%\^\&\*';
$wordlist = <<<ENDFILTER
h[o0$s]m[e3]?.?[s5][t7][u$s](ck?|k)
d[i$s][c$s]?khead
\bdik
c[u$s]nt
Expand Down Expand Up @@ -59,18 +58,31 @@ private function _getWordlist($skipLinks = false) {
ENDFILTER;
$wordlist = '/'.($skipLinks ?
'((^[^<]*)|(>[^<]*)|(<a[^>]*title="[^"]*))\\K' // Keep filter from affecting link hrefs
: '').'((' . str_replace("\n", ")|(", str_replace("\r\n", "\n", $wordlist)) . '))/i';
: '').'((' . str_replace("\n", ")|(", str_replace("\r\n", "\n", $wordlist)) . '))/is';
return $wordlist;
}

public function _filter($content, $skipLinks = false) {
$wordlist = $this->_getWordlist($skipLinks);
$choice = $this->filterTo;

while(preg_match($wordlist, $content))
$content = preg_replace_callback($wordlist, function($choice) use ($choice) {
return $choice[array_rand($choice)];
}, $content);
while(preg_match($wordlist, $content))
$content = preg_replace_callback($wordlist, function($choice) use ($choice) {
return $choice[array_rand($choice)];
}, $content);

// bleh
$stripped_content = $content;
if($skipLinks)
$stripped_content = preg_replace('/((<.*?>)|(\\[\\/?([buist]|m[^\\]]*)\\]))/im', '', $stripped_content);

while(preg_match($wordlist, $stripped_content)) {
$stripped_content = preg_replace_callback($wordlist, function($choice) use ($choice) {
return $choice[array_rand($choice)];
}, $stripped_content);
$content = $stripped_content;
}

return $content;
}

Expand Down

0 comments on commit 10ecb7e

Please sign in to comment.