author | Dan Fuhry <dan@enanocms.org> |
Mon, 12 Dec 2011 22:51:37 -0500 | |
changeset 0 | d7eb80b3c6f6 |
child 1 | bfc5494ee70c |
permissions | -rwxr-xr-x |
0
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
1 |
<?php |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
2 |
/**!info** |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
3 |
{ |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
4 |
"Plugin Name" : "Censorship", |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
5 |
"Plugin URI" : "http://enanocms.org/plugin/censorship", |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
6 |
"Description" : "Protest SOPA", |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
7 |
"Author" : "Dan Fuhry", |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
8 |
"Version" : "1.0", |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
9 |
"Author URI" : "http://enanocms.org/" |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
10 |
} |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
11 |
**!*/ |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
12 |
|
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
13 |
$plugins->attachHook('render_wikiformat_post', 'anti_sopa_censor($text);'); |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
14 |
|
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
15 |
function anti_sopa_censor(&$text) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
16 |
{ |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
17 |
// save HTML tags |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
18 |
$text = preg_split('/(<(?:[a-z\/].+?|!--.+?--)>|<script[^>]*>[\w\W]*?<\/script>)/', $text, NULL, PREG_SPLIT_DELIM_CAPTURE); |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
19 |
foreach ( $text as &$block ) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
20 |
{ |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
21 |
if ( $block{0} == '<' ) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
22 |
continue; |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
23 |
|
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
24 |
// split by words |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
25 |
$block = preg_split('/(\s+)/', $block, NULL, PREG_SPLIT_DELIM_CAPTURE); |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
26 |
foreach ( $block as &$word ) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
27 |
{ |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
28 |
if ( preg_match('/^\s+$/', $word) || strlen($word) < 1 || !preg_match('/\w/', $word) ) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
29 |
continue; |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
30 |
|
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
31 |
if ( mt_rand(0, 10) == 0 ) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
32 |
{ |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
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;">' . |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
34 |
preg_replace('/[A-z0-9]/', '█', $word) |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
35 |
. '</a>' |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
36 |
; |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
37 |
} |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
38 |
} |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
39 |
$block = implode('', $block); |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
40 |
} |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
41 |
$text = implode('', $text); |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
42 |
} |
d7eb80b3c6f6
First revision... should be the only one
Dan Fuhry <dan@enanocms.org>
parents:
diff
changeset
|
43 |