aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/MessageFilter.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2022-07-26 18:00:00 +0000
committerMario <mario@mariovavti.com>2022-07-26 18:00:00 +0000
commit40377796edd8c612ce9d68f52fc146ad32302f9e (patch)
tree92cce4a3ee3627ed28f45ce8f0bb3598be87c8c9 /Zotlabs/Lib/MessageFilter.php
parentc452a621fe7db5405d929ebc5f5433c9670fc367 (diff)
parentfedad7f31a1b9133bfd63de7fc19de6916485254 (diff)
downloadvolse-hubzilla-7.6.tar.gz
volse-hubzilla-7.6.tar.bz2
volse-hubzilla-7.6.zip
Merge branch '7.6RC'7.6
Diffstat (limited to 'Zotlabs/Lib/MessageFilter.php')
-rw-r--r--Zotlabs/Lib/MessageFilter.php48
1 files changed, 37 insertions, 11 deletions
diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php
index 70b0188c4..7d6dcbe8e 100644
--- a/Zotlabs/Lib/MessageFilter.php
+++ b/Zotlabs/Lib/MessageFilter.php
@@ -29,7 +29,19 @@ class MessageFilter {
if (! $word) {
continue;
}
- if (substr($word, 0, 1) === '#' && $tags) {
+ if (isset($lang) && ((strpos($word, 'lang=') === 0) || (strpos($word, 'lang!=') === 0))) {
+ if (!strlen($lang)) {
+ // Result is ambiguous. As we are matching deny rules only at this time, continue tests.
+ // Any matching deny rule concludes testing.
+ continue;
+ }
+ if (strpos($word, 'lang=') === 0 && strcasecmp($lang, trim(substr($word, 5))) == 0) {
+ return false;
+ } elseif (strpos($word, 'lang!=') === 0 && strcasecmp($lang, trim(substr($word, 6))) != 0) {
+ return false;
+ }
+ }
+ elseif (substr($word, 0, 1) === '#' && $tags) {
foreach ($tags as $t) {
if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
return false;
@@ -51,10 +63,6 @@ class MessageFilter {
}
} elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) {
return false;
- } elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) {
- return false;
- } elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) {
- return false;
} elseif (stristr($text, $word) !== false) {
return false;
}
@@ -69,7 +77,19 @@ class MessageFilter {
if (! $word) {
continue;
}
- if (substr($word, 0, 1) === '#' && $tags) {
+ if (isset($lang) && ((strpos($word, 'lang=') === 0) || (strpos($word, 'lang!=') === 0))) {
+ if (!strlen($lang)) {
+ // Result is ambiguous. However we are checking allow rules
+ // and an ambiguous language is always permitted.
+ return true;
+ }
+ if (strpos($word, 'lang=') === 0 && strcasecmp($lang, trim(substr($word, 5))) == 0) {
+ return true;
+ } elseif (strpos($word, 'lang!=') === 0 && strcasecmp($lang, trim(substr($word, 6))) != 0) {
+ return true;
+ }
+ }
+ elseif (substr($word, 0, 1) === '#' && $tags) {
foreach ($tags as $t) {
if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
return true;
@@ -91,10 +111,6 @@ class MessageFilter {
}
} elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) {
return true;
- } elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) {
- return true;
- } elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) {
- return true;
} elseif (stristr($text, $word) !== false) {
return true;
}
@@ -123,7 +139,8 @@ class MessageFilter {
* - ?foo {} baz which will check if 'baz' is an array element in item.foo
* - ?foo {*} baz which will check if 'baz' is an array key in item.foo
* - ?foo which will check for a return of a true condition for item.foo;
- *
+ * - ?!foo which will check for a return of a false condition for item.foo;
+ *
* The values 0, '', an empty array, and an unset value will all evaluate to false.
*
* @param string $s
@@ -205,6 +222,15 @@ class MessageFilter {
return false;
}
+ // Ordering of this check (for falsiness) with relation to the following one (check for truthiness) is important.
+ if (preg_match('/\!(.*?)$/', $s, $matches)) {
+ $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR);
+ if (!$x) {
+ return true;
+ }
+ return false;
+ }
+
if (preg_match('/(.*?)$/', $s, $matches)) {
$x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR);
if ($x) {