From: Friendika Date: Fri, 14 Oct 2011 03:53:24 +0000 (-0700) Subject: nsfw custom wordlist X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1d33565385a33926551aeda762f9626e00d2cf40;p=friendica-addons.git nsfw custom wordlist --- diff --git a/nsfw.tgz b/nsfw.tgz index 294f9ec8..e7c959e8 100644 Binary files a/nsfw.tgz and b/nsfw.tgz differ diff --git a/nsfw/nsfw.css b/nsfw/nsfw.css new file mode 100644 index 00000000..548b63ae --- /dev/null +++ b/nsfw/nsfw.css @@ -0,0 +1,16 @@ + +#nsfw-label { + float: left; + width: 300px; + margin-top: 10px; +} + +#nsfw-words { + float: left; + margin-top: 10px; +} + +#nsfw-submit { + margin-top: 15px; +} + diff --git a/nsfw/nsfw.php b/nsfw/nsfw.php index 776df194..dba9f1e8 100644 --- a/nsfw/nsfw.php +++ b/nsfw/nsfw.php @@ -11,16 +11,90 @@ function nsfw_install() { register_hook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body'); + register_hook('plugin_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings'); + register_hook('plugin_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post'); + } function nsfw_uninstall() { unregister_hook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body'); + unregister_hook('plugin_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings'); + unregister_hook('plugin_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post'); + +} + + + + + +function nsfw_addon_settings(&$a,&$s) { + + + if(! local_user()) + return; + + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= '' . "\r\n"; + + + $words = get_pconfig(local_user(),'nsfw','words'); + if(! $words) + $words = 'nsfw,'; + + $s .= '
'; + $s .= '

' . t('"Not Safe For Work" Settings') . '

'; + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + $s .= '
'; + + return; + +} + +function nsfw_addon_settings_post(&$a,&$b) { + + if(! local_user()) + return; + + if($_POST['nsfw-submit']) { + set_pconfig(local_user(),'nsfw','words',trim($_POST['nsfw-words'])); + info( t('NSFW Settings saved.') . EOL); + } } function nsfw_prepare_body(&$a,&$b) { - if(stristr($b,'nsfw')) { + + $words = null; + if(local_user()) { + $words = get_pconfig(local_user(),'nsfw','words'); + } + if($words) { + $arr = explode(',',$words); + } + else { + $arr = array('nsfw'); + } + + $found = false; + if(count($arr)) { + foreach($arr as $word) { + if(! strlen(trim($word))) { + continue; + } + + if(stristr($b,$word)) { + $found = true; + break; + } + } + } + if($found) { $rnd = random_string(8); $b = ''; } -} \ No newline at end of file +}