From 5795a7fc0ddacc8bef56d8351764892986f68e35 Mon Sep 17 00:00:00 2001 From: Bofh Date: Mon, 19 Dec 2022 16:13:20 +0100 Subject: [PATCH] Support !(negation) of any instance in "instances" field of accounts search --- .../database/mastodon/accounts/search/mod.php | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/api/v1/database/mastodon/accounts/search/mod.php b/api/v1/database/mastodon/accounts/search/mod.php index 495168a..80f9824 100644 --- a/api/v1/database/mastodon/accounts/search/mod.php +++ b/api/v1/database/mastodon/accounts/search/mod.php @@ -59,20 +59,36 @@ $sql_all = ' '; $instances = null; +$ninstances = null; if (isset($_GET['instances'])) { $instances = []; + $ninstances = []; foreach (explode(',',$_GET['instances']) as $instance) { $instance = trim($instance); - if (valid_domain_name($instance)) - $instances []= "'".$instance."'"; + $not_bool = $instance[0] === '!'; + if ($not_bool) + $instance = substr($instance, 1); + if (valid_domain_name($instance)) { + if ($not_bool) + $ninstances []= "'".$instance."'"; + else $instances []= "'".$instance."'"; + } } if (count($instances) > 0) $instances = implode(',', $instances); else $instances = null; + if (count($ninstances) > 0) + $ninstances = implode(',', $ninstances); + else $ninstances = null; } +$_ = ''; if ($instances !== null) - $sql_all = str_replace('{instanceFilter}', "a.domain IN ($instances) AND", $sql_all); -else $sql_all = str_replace('{instanceFilter}', '', $sql_all); + $_ .= "a.domain IN ($instances) AND "; +if ($ninstances !== null) + $_ .= "NOT a.domain IN ($ninstances) AND "; +$_ = trim($_); +$sql_all = str_replace('{instanceFilter}', $_, $sql_all); +unset($_); $user_filter = 'local'; if (isset($_GET['user_filter'])) {