mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-22 01:23:41 +00:00
Add hashtag-only search
This commit is contained in:
parent
b9c38e9ac3
commit
567028f1bd
1 changed files with 26 additions and 16 deletions
|
@ -140,25 +140,22 @@ 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;
|
||||
default:
|
||||
$found = stripos($body, $word) !== false || nsfw_find_word_in_item_tags($b['item']['tags'], $word);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (stristr($body, $word)) {
|
||||
$found = true;
|
||||
|
||||
if ($found) {
|
||||
break;
|
||||
}
|
||||
if (is_array($b['item']['tags']) && count($b['item']['tags'])) {
|
||||
foreach ($b['item']['tags'] as $t) {
|
||||
if (stristr($t, '>' . $word . '<')) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,3 +166,16 @@ function nsfw_prepare_body(Friendica\App $a, &$b)
|
|||
'</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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue