X-Git-Url: https://git.mxchange.org/?p=friendica-addons.git;a=blobdiff_plain;f=nsfw%2Fnsfw.php;h=6592738de2daf5055641c4defceac6ac404c0456;hp=af383d20b7cfb6d9f45ebe0e47a704b1bacaa17c;hb=27b60e003f92dd9f3aebbeddb34ebb905488ca82;hpb=4aea294776e524cf498a19b49c69bdc0a929dab7 diff --git a/nsfw/nsfw.php b/nsfw/nsfw.php old mode 100755 new mode 100644 index af383d20..6592738d --- a/nsfw/nsfw.php +++ b/nsfw/nsfw.php @@ -6,9 +6,11 @@ * Description: Collapse posts with inappropriate content * Version: 1.0 * Author: Mike Macgirvin - * + * */ +use Friendica\Core\PConfig; + function nsfw_install() { register_hook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body', 10); register_hook('plugin_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings'); @@ -24,15 +26,15 @@ function nsfw_uninstall() { } -// This function isn't perfect and isn't trying to preserve the html structure - it's just a -// quick and dirty filter to pull out embedded photo blobs because 'nsfw' seems to come up +// This function isn't perfect and isn't trying to preserve the html structure - it's just a +// quick and dirty filter to pull out embedded photo blobs because 'nsfw' seems to come up // inside them quite often. We don't need anything fancy, just pull out the data blob so we can -// check against the rest of the body. - +// check against the rest of the body. + function nsfw_extract_photos($body) { $new_body = ''; - + $img_start = strpos($body,'src="data:'); $img_end = (($img_start !== false) ? strpos(substr($body,$img_start),'>') : false); @@ -41,7 +43,7 @@ function nsfw_extract_photos($body) { while($img_end !== false) { $img_end += $img_start; $new_body = $new_body . substr($body,0,$img_start); - + $cnt ++; $body = substr($body,0,$img_end); @@ -69,8 +71,8 @@ function nsfw_addon_settings(&$a,&$s) { $a->page['htmlhead'] .= '' . "\r\n"; - $enable_checked = (intval(get_pconfig(local_user(),'nsfw','disable')) ? '' : ' checked="checked" '); - $words = get_pconfig(local_user(),'nsfw','words'); + $enable_checked = (intval(PConfig::get(local_user(),'nsfw','disable')) ? '' : ' checked="checked" '); + $words = PConfig::get(local_user(),'nsfw','words'); if(! $words) $words = 'nsfw,'; @@ -104,10 +106,10 @@ function nsfw_addon_settings_post(&$a,&$b) { return; if($_POST['nsfw-submit']) { - set_pconfig(local_user(),'nsfw','words',trim($_POST['nsfw-words'])); + PConfig::set(local_user(),'nsfw','words',trim($_POST['nsfw-words'])); $enable = ((x($_POST,'nsfw-enable')) ? intval($_POST['nsfw-enable']) : 0); $disable = 1-$enable; - set_pconfig(local_user(),'nsfw','disable', $disable); + PConfig::set(local_user(),'nsfw','disable', $disable); info( t('NSFW Settings saved.') . EOL); } } @@ -116,17 +118,17 @@ function nsfw_prepare_body(&$a,&$b) { $words = null; - if(get_pconfig(local_user(),'nsfw','disable')) + if(PConfig::get(local_user(),'nsfw','disable')) return; if(local_user()) { - $words = get_pconfig(local_user(),'nsfw','words'); + $words = PConfig::get(local_user(),'nsfw','words'); } if($words) { $arr = explode(',',$words); } else { - $arr = array('nsfw'); + $arr = ['nsfw']; } $found = false; @@ -158,11 +160,11 @@ function nsfw_prepare_body(&$a,&$b) { } } } - } - } + } + } } if($found) { $rnd = random_string(8); - $b['html'] = ''; + $b['html'] = ''; } }