Merge pull request #9322 from annando/issue-9305
Issue 9305: Relay deny tags are added
This commit is contained in:
commit
c06197377f
|
@ -214,6 +214,7 @@ class Site extends BaseAdmin
|
||||||
$relay_subscribe = !empty($_POST['relay_subscribe']);
|
$relay_subscribe = !empty($_POST['relay_subscribe']);
|
||||||
$relay_scope = (!empty($_POST['relay_scope']) ? Strings::escapeTags(trim($_POST['relay_scope'])) : '');
|
$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_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']);
|
$relay_user_tags = !empty($_POST['relay_user_tags']);
|
||||||
$active_panel = (!empty($_POST['active_panel']) ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
|
$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_subscribe' , $relay_subscribe);
|
||||||
DI::config()->set('system', 'relay_scope' , $relay_scope);
|
DI::config()->set('system', 'relay_scope' , $relay_scope);
|
||||||
DI::config()->set('system', 'relay_server_tags', $relay_server_tags);
|
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', 'relay_user_tags' , $relay_user_tags);
|
||||||
|
|
||||||
DI::config()->set('system', 'rino_encrypt' , $rino);
|
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_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_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_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".')],
|
'$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'),
|
'$form_security_token' => self::getFormSecurityToken('admin_site'),
|
||||||
|
|
|
@ -810,11 +810,6 @@ class Processor
|
||||||
$scope = SR_SCOPE_NONE;
|
$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');
|
$replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id');
|
||||||
if (Item::exists(['uri' => $replyto])) {
|
if (Item::exists(['uri' => $replyto])) {
|
||||||
Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]);
|
Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]);
|
||||||
|
@ -839,11 +834,11 @@ class Processor
|
||||||
|
|
||||||
$systemTags = [];
|
$systemTags = [];
|
||||||
$userTags = [];
|
$userTags = [];
|
||||||
|
$denyTags = [];
|
||||||
|
|
||||||
if ($scope == SR_SCOPE_TAGS) {
|
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));
|
$tagitems = explode(',', mb_strtolower($server_tags));
|
||||||
|
|
||||||
foreach ($tagitems AS $tag) {
|
foreach ($tagitems AS $tag) {
|
||||||
$systemTags[] = trim($tag, '# ');
|
$systemTags[] = trim($tag, '# ');
|
||||||
}
|
}
|
||||||
|
@ -853,14 +848,29 @@ class Processor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tagList = array_unique(array_merge($systemTags, $userTags));
|
||||||
|
|
||||||
|
$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));
|
$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) {
|
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)) {
|
if (in_array($tag, $tagList)) {
|
||||||
Logger::info('Subscribed hashtag found - accepted', ['id' => $id, 'hashtag' => $tag]);
|
Logger::info('Subscribed hashtag found - accepted', ['id' => $id, 'hashtag' => $tag]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We check with "strpos" for performance issues. Only when this is true, the regular expression check is used
|
// 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
|
// 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)) {
|
if ((strpos($content, $tag) !== false) && preg_match('/(?<=[\s,.:;"\']|^)' . preg_quote($tag, '/') . '(?=[\s,.:;"\']|$)/', $content)) {
|
||||||
|
@ -868,6 +878,12 @@ class Processor
|
||||||
return true;
|
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]);
|
Logger::info('No matching hashtags found - rejected', ['id' => $id]);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -133,6 +133,7 @@
|
||||||
{{include file="field_checkbox.tpl" field=$relay_directly}}
|
{{include file="field_checkbox.tpl" field=$relay_directly}}
|
||||||
{{include file="field_select.tpl" field=$relay_scope}}
|
{{include file="field_select.tpl" field=$relay_scope}}
|
||||||
{{include file="field_input.tpl" field=$relay_server_tags}}
|
{{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}}
|
{{include file="field_checkbox.tpl" field=$relay_user_tags}}
|
||||||
|
|
||||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
|
||||||
|
|
|
@ -307,6 +307,7 @@
|
||||||
{{include file="field_checkbox.tpl" field=$relay_directly}}
|
{{include file="field_checkbox.tpl" field=$relay_directly}}
|
||||||
{{include file="field_select.tpl" field=$relay_scope}}
|
{{include file="field_select.tpl" field=$relay_scope}}
|
||||||
{{include file="field_input.tpl" field=$relay_server_tags}}
|
{{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}}
|
{{include file="field_checkbox.tpl" field=$relay_user_tags}}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-footer">
|
<div class="panel-footer">
|
||||||
|
|
Loading…
Reference in a new issue