]> git.mxchange.org Git - friendica-addons.git/blobdiff - nsfw/nsfw.php
[rendertime] Adapt ignored_modules
[friendica-addons.git] / nsfw / nsfw.php
index ae98d1064bbbea9c0147a8be0b9f78a39e765f7b..31d17f74a8fbf59c0e7a2881dc50683ce3bdc431 100644 (file)
@@ -53,18 +53,18 @@ function nsfw_extract_photos($body)
 
 function nsfw_addon_settings(App &$a, array &$data)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       $enabled = !DI::pConfig()->get(local_user(), 'nsfw', 'disable');
-       $words   = DI::pConfig()->get(local_user(), 'nsfw', 'words', 'nsfw,');
+       $enabled = !DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'nsfw', 'disable');
+       $words   = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'nsfw', 'words', 'nsfw,');
 
        $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/nsfw/');
        $html = Renderer::replaceMacros($t, [
                '$info'    => DI::l10n()->t('This addon searches for specified words/text in posts and collapses them. It can be used to filter content tagged with for instance #NSFW that may be deemed inappropriate at certain times or places, such as being at work. It is also useful for hiding irrelevant or annoying content from direct view.'),
                '$enabled' => ['nsfw-enable', DI::l10n()->t('Enable Content filter'), $enabled],
-               '$words'   => ['nsfw-words', DI::l10n()->t('Comma separated list of keywords to hide'), $words, DI::l10n()->t('Use /expression/ to provide regular expressions')],
+               '$words'   => ['nsfw-words', DI::l10n()->t('Comma separated list of keywords to hide'), $words, DI::l10n()->t('Use /expression/ to provide regular expressions, #tag to specfically match hashtags (case-insensitive), or regular words (case-sensitive)')],
        ]);
 
        $data = [
@@ -76,27 +76,27 @@ function nsfw_addon_settings(App &$a, array &$data)
 
 function nsfw_addon_settings_post(App $a, array &$b)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
        if (!empty($_POST['nsfw-submit'])) {
-               DI::pConfig()->set(local_user(), 'nsfw', 'words', trim($_POST['nsfw-words']));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'nsfw', 'words', trim($_POST['nsfw-words']));
                $enable = (!empty($_POST['nsfw-enable']) ? intval($_POST['nsfw-enable']) : 0);
                $disable = 1 - $enable;
-               DI::pConfig()->set(local_user(), 'nsfw', 'disable', $disable);
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'nsfw', 'disable', $disable);
        }
 }
 
 function nsfw_prepare_body_content_filter(App $a, &$hook_data)
 {
        $words = null;
-       if (DI::pConfig()->get(local_user(), 'nsfw', 'disable')) {
+       if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'nsfw', 'disable')) {
                return;
        }
 
-       if (local_user()) {
-               $words = DI::pConfig()->get(local_user(), 'nsfw', 'words');
+       if (DI::userSession()->getLocalUserId()) {
+               $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'nsfw', 'words');
        }
 
        if ($words) {
@@ -125,7 +125,7 @@ function nsfw_prepare_body_content_filter(App $a, &$hook_data)
                                        $found = nsfw_find_word_in_item_tags($hook_data['item']['hashtags'], substr($word, 1));
                                        break;
                                default:
-                                       $found = stripos($body, $word) !== false || nsfw_find_word_in_item_tags($hook_data['item']['tags'], $word);
+                                       $found = strpos($body, $word) !== false || nsfw_find_word_in_item_tags($hook_data['item']['tags'], $word);
                                        break;
                        }