diff options
Diffstat (limited to 'Zotlabs/Lib/MessageFilter.php')
-rw-r--r-- | Zotlabs/Lib/MessageFilter.php | 48 |
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) { |