Add hashtag-only search

pull/560/head
Hypolite Petovan 2018-03-25 00:20:16 -04:00
parent b9c38e9ac3
commit 567028f1bd
1 changed files with 26 additions and 16 deletions

View File

@ -140,24 +140,21 @@ function nsfw_prepare_body(Friendica\App $a, &$b)
if (!strlen($word)) { if (!strlen($word)) {
continue; continue;
} }
if (strpos($word,'/') === 0) {
if (preg_match($word, $body)) { switch ($word[0]) {
$found = true; case '/'; // Regular expression
$found = preg_match($word, $body);
break; break;
} case '#': // Hashtag-only search
} else { $found = nsfw_find_word_in_item_tags($b['item']['hashtags'], substr($word, 1));
if (stristr($body, $word)) {
$found = true;
break; break;
} default:
if (is_array($b['item']['tags']) && count($b['item']['tags'])) { $found = stripos($body, $word) !== false || nsfw_find_word_in_item_tags($b['item']['tags'], $word);
foreach ($b['item']['tags'] as $t) { break;
if (stristr($t, '>' . $word . '<')) { }
$found = true;
break; if ($found) {
} break;
}
}
} }
} }
} }
@ -169,3 +166,16 @@ function nsfw_prepare_body(Friendica\App $a, &$b)
'</div><div id="nsfw-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>'; '</div><div id="nsfw-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';
} }
} }
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;
}