mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 16:15:13 +00:00
Add content filter rule for max number of hashtags
This commit is contained in:
parent
713c9ae361
commit
8ab0e14771
3 changed files with 33 additions and 3 deletions
|
@ -63,6 +63,19 @@ class MessageFilter
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// hashtag count match
|
||||
if (substr($word,1,4) === '>') {
|
||||
$hashtagLimit = (int)substr($word, 5);
|
||||
$hashtagCount = 0;
|
||||
foreach ($tags as $t) {
|
||||
if ($t['ttype'] == TERM_HASHTAG || $t['ttype'] == TERM_COMMUNITYTAG) {
|
||||
$hashtagCount++;
|
||||
}
|
||||
}
|
||||
if ($hashtagLimit && $hashtagCount > $hashtagLimit) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} elseif (str_starts_with($word, '$') && $tags) {
|
||||
foreach ($tags as $t) {
|
||||
if (($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
|
||||
|
@ -116,6 +129,19 @@ class MessageFilter
|
|||
return true;
|
||||
}
|
||||
}
|
||||
// hashtag count match
|
||||
if (substr($word,1,4) === '>') {
|
||||
$hashtagLimit = (int) substr($word,5);
|
||||
$hashtagCount = 0;
|
||||
foreach ($tags as $t) {
|
||||
if ($t['ttype'] == TERM_HASHTAG || $t['ttype'] == TERM_COMMUNITYTAG) {
|
||||
$hashtagCount++;
|
||||
}
|
||||
}
|
||||
if ($hashtagLimit && $hashtagCount > $hashtagLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} elseif (str_starts_with($word, '$') && $tags) {
|
||||
// $category match
|
||||
foreach ($tags as $t) {
|
||||
|
|
|
@ -19,8 +19,8 @@ class Content_filter extends Controller
|
|||
}
|
||||
|
||||
if ($_POST['content_filter-submit']) {
|
||||
$incl = ((x($_POST['message_filter_incl'])) ? htmlspecialchars_decode(trim($_POST['message_filter_incl']), ENT_QUOTES) : '');
|
||||
$excl = ((x($_POST['message_filter_excl'])) ? htmlspecialchars_decode(trim($_POST['message_filter_excl']), ENT_QUOTES) : '');
|
||||
$incl = ((x($_POST['message_filter_incl'])) ? escape_tags(trim($_POST['message_filter_incl'])) : '');
|
||||
$excl = ((x($_POST['message_filter_excl'])) ? escape_tags(trim($_POST['message_filter_excl'])) : '');
|
||||
$filter_moderate = (isset($_POST['filter_moderate']) ? intval($_POST['filter_moderate']) : 0);
|
||||
set_pconfig(local_channel(), 'system', 'message_filter_incl', $incl);
|
||||
set_pconfig(local_channel(), 'system', 'message_filter_excl', $excl);
|
||||
|
@ -43,7 +43,7 @@ class Content_filter extends Controller
|
|||
return $text;
|
||||
}
|
||||
|
||||
$text .= EOL . t('The settings on this page apply to all incoming content. To edit the settings for individual connetions, see the similar settings on the Connection Edit page for that connection.') . EOL . EOL;
|
||||
$text .= EOL . t('The settings on this page apply to all incoming content. To edit the settings for individual connections, see the similar settings on the Connection Edit page for that connection.') . EOL . EOL;
|
||||
|
||||
$setting_fields = $text;
|
||||
|
||||
|
|
|
@ -43,6 +43,10 @@ Example: `lang!=en` (matches non-English content)
|
|||
Match hashtag
|
||||
Example: `#cats`
|
||||
|
||||
**#>n**
|
||||
Match greater than total number of hashtags
|
||||
Example: `#>10`
|
||||
|
||||
|
||||
**CATEGORY**
|
||||
|
||||
|
|
Loading…
Reference in a new issue