From: Hypolite Petovan Date: Sun, 25 Mar 2018 04:20:16 +0000 (-0400) Subject: Add hashtag-only search X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=567028f1bdf77df50581a3d7f49e60df752c62e5;p=friendica-addons.git Add hashtag-only search --- diff --git a/nsfw/nsfw.php b/nsfw/nsfw.php index 646665e9..08107151 100644 --- a/nsfw/nsfw.php +++ b/nsfw/nsfw.php @@ -140,24 +140,21 @@ function nsfw_prepare_body(Friendica\App $a, &$b) if (!strlen($word)) { continue; } - if (strpos($word,'/') === 0) { - if (preg_match($word, $body)) { - $found = true; + + switch ($word[0]) { + case '/'; // Regular expression + $found = preg_match($word, $body); + break; + case '#': // Hashtag-only search + $found = nsfw_find_word_in_item_tags($b['item']['hashtags'], substr($word, 1)); break; - } - } else { - if (stristr($body, $word)) { - $found = true; + default: + $found = stripos($body, $word) !== false || nsfw_find_word_in_item_tags($b['item']['tags'], $word); break; - } - if (is_array($b['item']['tags']) && count($b['item']['tags'])) { - foreach ($b['item']['tags'] as $t) { - if (stristr($t, '>' . $word . '<')) { - $found = true; - break; - } - } - } + } + + if ($found) { + break; } } } @@ -169,3 +166,16 @@ function nsfw_prepare_body(Friendica\App $a, &$b) ''; } } + +function nsfw_find_word_in_item_tags($item_tags, $word) +{ + if (is_array($item_tags)) { + foreach ($item_tags as $tag) { + if (stripos($tag, '>' . $word . '<') !== false) { + return true; + } + } + } + + return false; +}