Censorship.php
changeset 0 d7eb80b3c6f6
child 1 bfc5494ee70c
equal deleted inserted replaced
-1:000000000000 0:d7eb80b3c6f6
       
     1 <?php
       
     2 /**!info**
       
     3 {
       
     4   "Plugin Name"  : "Censorship",
       
     5   "Plugin URI"   : "http://enanocms.org/plugin/censorship",
       
     6   "Description"  : "Protest SOPA",
       
     7   "Author"       : "Dan Fuhry",
       
     8   "Version"      : "1.0",
       
     9   "Author URI"   : "http://enanocms.org/"
       
    10 }
       
    11 **!*/
       
    12 
       
    13 $plugins->attachHook('render_wikiformat_post', 'anti_sopa_censor($text);');
       
    14 
       
    15 function anti_sopa_censor(&$text)
       
    16 {
       
    17 	// save HTML tags
       
    18 	$text = preg_split('/(<(?:[a-z\/].+?|!--.+?--)>|<script[^>]*>[\w\W]*?<\/script>)/', $text, NULL, PREG_SPLIT_DELIM_CAPTURE);
       
    19 	foreach ( $text as &$block )
       
    20 	{
       
    21 		if ( $block{0} == '<' )
       
    22 			continue;
       
    23 		
       
    24 		// split by words
       
    25 		$block = preg_split('/(\s+)/', $block, NULL, PREG_SPLIT_DELIM_CAPTURE);
       
    26 		foreach ( $block as &$word )
       
    27 		{
       
    28 			if ( preg_match('/^\s+$/', $word) || strlen($word) < 1 || !preg_match('/\w/', $word) )
       
    29 				continue;
       
    30 			
       
    31 			if ( mt_rand(0, 10) == 0 )
       
    32 			{
       
    33 				$word = '<a href="http://enanocms.org/activism/stop-sopa" onclick="window.open(this.href); return false;" title="This word redacted by the US Government" style="color: black; background-color: black; background-image: none; padding-right: 0; text-decoration: none;">' .
       
    34 						preg_replace('/[A-z0-9]/', '█', $word)
       
    35 						. '</a>'
       
    36 						;
       
    37 			}
       
    38 		}
       
    39 		$block = implode('', $block);
       
    40 	}
       
    41 	$text = implode('', $text);
       
    42 }
       
    43