6 * Description: Collapse posts with inappropriate content
8 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
12 function nsfw_install() {
13 register_hook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body');
14 register_hook('plugin_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings');
15 register_hook('plugin_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post');
20 function nsfw_uninstall() {
21 unregister_hook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body');
22 unregister_hook('plugin_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings');
23 unregister_hook('plugin_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post');
31 function nsfw_addon_settings(&$a,&$s) {
37 /* Add our stylesheet to the page so we can make our settings look nice */
39 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/nsfw/nsfw.css' . '" media="all" />' . "\r\n";
41 $enable_checked = (intval(get_pconfig(local_user(),'nsfw','disable')) ? '' : ' checked="checked" ');
42 $words = get_pconfig(local_user(),'nsfw','words');
46 $s .= '<div class="settings-block">';
47 $s .= '<h3>' . t('Not Safe For Work (General Purpose Content Filter) settings') . '</h3>';
48 $s .= '<div id="nsfw-wrapper">';
49 $s .= '<p>' . t ('This plugin looks in posts for the words/text you specify below, and collapses any content containing those keywords so it is not displayed at inappropriate times, such as sexual innuendo that may be improper in a work setting. It is polite and recommended to tag any content containing nudity with #NSFW. This filter can also match any other word/text you specify, and can thereby be used as a general purpose content filter.') . '</p>';
50 $s .= '<label id="nsfw-enable-label" for="nsfw-enable">' . t('Enable Content filter') . ' </label>';
51 $s .= '<input id="nsfw-enable" type="checkbox" name="nsfw-enable" value="1"' . $enable_checked . ' />';
52 $s .= '<div class="clear"></div>';
53 $s .= '<label id="nsfw-label" for="nsfw-words">' . t('Comma separated list of keywords to hide') . ' </label>';
54 $s .= '<input id="nsfw-words" type="text" name="nsfw-words" value="' . $words .'" />';
55 $s .= '</div><div class="clear"></div>';
57 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="nsfw-submit" name="nsfw-submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
58 $s .= '<div class="nsfw-desc">' . t('Use /expression/ to provide regular expressions') . '</div></div>';
64 function nsfw_addon_settings_post(&$a,&$b) {
69 if($_POST['nsfw-submit']) {
70 set_pconfig(local_user(),'nsfw','words',trim($_POST['nsfw-words']));
71 $enable = ((x($_POST,'nsfw-enable')) ? intval($_POST['nsfw-enable']) : 0);
73 set_pconfig(local_user(),'nsfw','disable', $disable);
74 info( t('NSFW Settings saved.') . EOL);
78 function nsfw_prepare_body(&$a,&$b) {
81 if(get_pconfig(local_user(),'nsfw','disable'))
85 $words = get_pconfig(local_user(),'nsfw','words');
88 $arr = explode(',',$words);
96 foreach($arr as $word) {
97 if(! strlen(trim($word))) {
100 if(strpos($word,'/') === 0) {
101 if(preg_match($word,$b['html'])) {
107 if(stristr($b['html'],$word)) {
111 if(stristr($b['item']['tag'], ']' . $word . '[' )) {
119 $rnd = random_string(8);
120 $b['html'] = '<div id="nsfw-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'nsfw-' . $rnd . '\'); >' . sprintf( t('%s - Click to open/close'),$word ) . '</div><div id="nsfw-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';