diff -r 000000000000 -r d7eb80b3c6f6 Censorship.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Censorship.php Mon Dec 12 22:51:37 2011 -0500 @@ -0,0 +1,43 @@ +attachHook('render_wikiformat_post', 'anti_sopa_censor($text);'); + +function anti_sopa_censor(&$text) +{ + // save HTML tags + $text = preg_split('/(<(?:[a-z\/].+?|!--.+?--)>|]*>[\w\W]*?<\/script>)/', $text, NULL, PREG_SPLIT_DELIM_CAPTURE); + foreach ( $text as &$block ) + { + if ( $block{0} == '<' ) + continue; + + // split by words + $block = preg_split('/(\s+)/', $block, NULL, PREG_SPLIT_DELIM_CAPTURE); + foreach ( $block as &$word ) + { + if ( preg_match('/^\s+$/', $word) || strlen($word) < 1 || !preg_match('/\w/', $word) ) + continue; + + if ( mt_rand(0, 10) == 0 ) + { + $word = '' . + preg_replace('/[A-z0-9]/', '█', $word) + . '' + ; + } + } + $block = implode('', $block); + } + $text = implode('', $text); +} +