]> git.mxchange.org Git - friendica.git/commitdiff
Issue 9305: Relay deny tags are added
authorMichael <heluecht@pirati.ca>
Tue, 29 Sep 2020 19:48:26 +0000 (19:48 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 29 Sep 2020 19:48:26 +0000 (19:48 +0000)
src/Module/Admin/Site.php
src/Protocol/ActivityPub/Processor.php
view/templates/admin/site.tpl
view/theme/frio/templates/admin/site.tpl

index 3c5688977a36b850ee7896f455e73294c67510d5..ea2b5604e33a087b70de24b93a86e0744157d748 100644 (file)
@@ -214,6 +214,7 @@ class Site extends BaseAdmin
                $relay_subscribe   = !empty($_POST['relay_subscribe']);
                $relay_scope       = (!empty($_POST['relay_scope'])       ? Strings::escapeTags(trim($_POST['relay_scope']))        : '');
                $relay_server_tags = (!empty($_POST['relay_server_tags']) ? Strings::escapeTags(trim($_POST['relay_server_tags']))  : '');
+               $relay_deny_tags   = (!empty($_POST['relay_deny_tags'])   ? Strings::escapeTags(trim($_POST['relay_deny_tags']))    : '');
                $relay_user_tags   = !empty($_POST['relay_user_tags']);
                $active_panel      = (!empty($_POST['active_panel'])      ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
 
@@ -425,6 +426,7 @@ class Site extends BaseAdmin
                DI::config()->set('system', 'relay_subscribe'  , $relay_subscribe);
                DI::config()->set('system', 'relay_scope'      , $relay_scope);
                DI::config()->set('system', 'relay_server_tags', $relay_server_tags);
+               DI::config()->set('system', 'relay_deny_tags'  , $relay_deny_tags);
                DI::config()->set('system', 'relay_user_tags'  , $relay_user_tags);
 
                DI::config()->set('system', 'rino_encrypt'     , $rino);
@@ -696,6 +698,7 @@ class Site extends BaseAdmin
                        '$relay_directly'         => ['relay_directly', DI::l10n()->t('Direct relay transfer'), DI::config()->get('system', 'relay_directly'), DI::l10n()->t('Enables the direct transfer to other servers without using the relay servers')],
                        '$relay_scope'            => ['relay_scope', DI::l10n()->t('Relay scope'), DI::config()->get('system', 'relay_scope'), DI::l10n()->t('Can be "all" or "tags". "all" means that every public post should be received. "tags" means that only posts with selected tags should be received.'), ['' => DI::l10n()->t('Disabled'), 'all' => DI::l10n()->t('all'), 'tags' => DI::l10n()->t('tags')]],
                        '$relay_server_tags'      => ['relay_server_tags', DI::l10n()->t('Server tags'), DI::config()->get('system', 'relay_server_tags'), DI::l10n()->t('Comma separated list of tags for the "tags" subscription.')],
+                       '$relay_deny_tags'        => ['relay_deny_tags', DI::l10n()->t('Deny Server tags'), DI::config()->get('system', 'relay_deny_tags'), DI::l10n()->t('Comma separated list of tags that are rejected.')],
                        '$relay_user_tags'        => ['relay_user_tags', DI::l10n()->t('Allow user tags'), DI::config()->get('system', 'relay_user_tags'), DI::l10n()->t('If enabled, the tags from the saved searches will used for the "tags" subscription in addition to the "relay_server_tags".')],
 
                        '$form_security_token'    => self::getFormSecurityToken('admin_site'),
index 26d953985a5634196a4f97a5ac057df54739f490..75d47090b542be5a313d0a5d4be40bed1baff47c 100644 (file)
@@ -810,11 +810,6 @@ class Processor
                        $scope = SR_SCOPE_NONE;
                }
 
-               if ($scope == SR_SCOPE_ALL) {
-                       Logger::info('Server accept all posts - accepted', ['id' => $id]);
-                       return true;
-               }
-
                $replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id');
                if (Item::exists(['uri' => $replyto])) {
                        Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]);
@@ -839,11 +834,11 @@ class Processor
 
                $systemTags = [];
                $userTags = [];
+               $denyTags = [];
 
                if ($scope == SR_SCOPE_TAGS) {
-                       $server_tags = $config->get('system', 'relay_server_tags', []);
+                       $server_tags = $config->get('system', 'relay_server_tags');
                        $tagitems = explode(',', mb_strtolower($server_tags));
-
                        foreach ($tagitems AS $tag) {
                                $systemTags[] = trim($tag, '# ');
                        }
@@ -853,22 +848,43 @@ class Processor
                        }
                }
 
-               $content = mb_strtolower(BBCode::toPlaintext(HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value')), false));
-
                $tagList = array_unique(array_merge($systemTags, $userTags));
-               foreach ($messageTags as $tag) {
-                       if (in_array($tag, $tagList)) {
-                               Logger::info('Subscribed hashtag found - accepted', ['id' => $id, 'hashtag' => $tag]);
-                               return true;
-                       }
-                       // We check with "strpos" for performance issues. Only when this is true, the regular expression check is used
-                       // RegExp is taken from here: https://medium.com/@shiba1014/regex-word-boundaries-with-unicode-207794f6e7ed
-                       if ((strpos($content, $tag) !== false) && preg_match('/(?<=[\s,.:;"\']|^)' . preg_quote($tag, '/') . '(?=[\s,.:;"\']|$)/', $content)) {
-                               Logger::info('Subscribed hashtag found in content - accepted', ['id' => $id, 'hashtag' => $tag]);
-                               return true;
+
+               $deny_tags = $config->get('system', 'relay_deny_tags');
+               $tagitems = explode(',', mb_strtolower($deny_tags));
+               foreach ($tagitems AS $tag) {
+                       $tag = trim($tag, '# ');
+                       $denyTags[] = $tag;
+               }
+
+               if (!empty($tagList) || !empty($denyTags)) {
+                       $content = mb_strtolower(BBCode::toPlaintext(HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value')), false));
+
+                       foreach ($messageTags as $tag) {
+                               if (in_array($tag, $denyTags)) {
+                                       Logger::info('Unwanted hashtag found - rejected', ['id' => $id, 'hashtag' => $tag]);
+                                       return false;
+                               }
+
+                               if (in_array($tag, $tagList)) {
+                                       Logger::info('Subscribed hashtag found - accepted', ['id' => $id, 'hashtag' => $tag]);
+                                       return true;
+                               }
+
+                               // We check with "strpos" for performance issues. Only when this is true, the regular expression check is used
+                               // RegExp is taken from here: https://medium.com/@shiba1014/regex-word-boundaries-with-unicode-207794f6e7ed
+                               if ((strpos($content, $tag) !== false) && preg_match('/(?<=[\s,.:;"\']|^)' . preg_quote($tag, '/') . '(?=[\s,.:;"\']|$)/', $content)) {
+                                       Logger::info('Subscribed hashtag found in content - accepted', ['id' => $id, 'hashtag' => $tag]);
+                                       return true;
+                               }
                        }
                }
 
+               if ($scope == SR_SCOPE_ALL) {
+                       Logger::info('Server accept all posts - accepted', ['id' => $id]);
+                       return true;
+               }
+
                Logger::info('No matching hashtags found - rejected', ['id' => $id]);
                return false;
        }
index 0c097413433927fe82091071e17243fc52aa9113..7f72b4386ab1d9e924beafb20344868dd3d022e9 100644 (file)
                {{include file="field_checkbox.tpl" field=$relay_directly}}
                {{include file="field_select.tpl" field=$relay_scope}}
                {{include file="field_input.tpl" field=$relay_server_tags}}
+               {{include file="field_input.tpl" field=$relay_deny_tags}}
                {{include file="field_checkbox.tpl" field=$relay_user_tags}}
 
                <div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
index a60cb06b63c9bb551e9e6c473bc0e35dfc781237..2a0cb3f48baf8684cfb1a2eb1df8d2b274d98e19 100644 (file)
                                                {{include file="field_checkbox.tpl" field=$relay_directly}}
                                                {{include file="field_select.tpl" field=$relay_scope}}
                                                {{include file="field_input.tpl" field=$relay_server_tags}}
+                                               {{include file="field_input.tpl" field=$relay_deny_tags}}
                                                {{include file="field_checkbox.tpl" field=$relay_user_tags}}
                                        </div>
                                        <div class="panel-footer">