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";
42 $words = get_pconfig(local_user(),'nsfw','words');
46 $s .= '<div class="settings-block">';
47 $s .= '<h3>' . t('"Not Safe For Work" Settings') . '</h3>';
48 $s .= '<div id="nsfw-wrapper">';
49 $s .= '<label id="nsfw-label" for="nsfw-words">' . t('Comma separated words to treat as NSFW') . ' </label>';
50 $s .= '<input id="nsfw-words" type="text" name="nsfw-words" value="' . $words .'" />';
51 $s .= '</div><div class="clear"></div>';
53 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="nsfw-submit" name="nsfw-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
59 function nsfw_addon_settings_post(&$a,&$b) {
64 if($_POST['nsfw-submit']) {
65 set_pconfig(local_user(),'nsfw','words',trim($_POST['nsfw-words']));
66 info( t('NSFW Settings saved.') . EOL);
70 function nsfw_prepare_body(&$a,&$b) {
74 $words = get_pconfig(local_user(),'nsfw','words');
77 $arr = explode(',',$words);
85 foreach($arr as $word) {
86 if(! strlen(trim($word))) {
90 if(stristr($b['html'],$word)) {
94 if(stristr($b['item']['tag'], ']' . $word . '[' )) {
101 $rnd = random_string(8);
102 $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>';