From 03b7fcd09c7446104df53f5ca0d7dce25980032e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 Mar 2023 09:55:39 -0400 Subject: [PATCH] Filter contact search by blocked remote domains - Add filter explanation --- src/Module/BaseSearch.php | 16 ++++++++++++++-- view/templates/contact/list.tpl | 4 ++++ view/theme/frio/templates/contact/list.tpl | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index cc8fab8f7e..675deb8fb2 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -97,6 +97,8 @@ class BaseSearch extends BaseModule } elseif (Search::getGlobalDirectory() && empty($results)) { $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage()); $pager->setItemsPerPage($results->getItemsPage()); + } else { + $results = new ResultList(); } return self::printResult($results, $pager, $header); @@ -120,11 +122,17 @@ class BaseSearch extends BaseModule return ''; } + $filtered = 0; + $entries = []; foreach ($results->getResults() as $result) { - // in case the result is a contact result, add a contact-specific entry if ($result instanceof ContactResult) { + if (Network::isUriBlocked($result->getUrl())) { + $filtered++; + continue; + } + $contact = Model\Contact::getByURLForUser($result->getUrl(), DI::userSession()->getLocalUserId()); if (!empty($contact)) { $entries[] = Contact::getContactTemplateVars($contact); @@ -134,7 +142,11 @@ class BaseSearch extends BaseModule $tpl = Renderer::getMarkupTemplate('contact/list.tpl'); return Renderer::replaceMacros($tpl, [ - 'title' => $header, + '$title' => $header, + '$filtered' => $filtered ? DI::l10n()->tt( + '%d result was filtered out because your node blocks the domain it is registered on. You can review the list of domains your node is currently blocking in the About page.', + '%d results were filtered out because your node blocks the domain they are registered on. You can review the list of domains your node is currently blocking in the About page.', + $filtered) : '', '$contacts' => $entries, '$paginate' => $pager->renderFull($results->getTotal()), ]); diff --git a/view/templates/contact/list.tpl b/view/templates/contact/list.tpl index ec77fd521b..b3ed7df7bb 100644 --- a/view/templates/contact/list.tpl +++ b/view/templates/contact/list.tpl @@ -12,3 +12,7 @@
{{$paginate nofilter}} + +{{if $filtered}} +

{{$filtered nofilter}}

+{{/if}} diff --git a/view/theme/frio/templates/contact/list.tpl b/view/theme/frio/templates/contact/list.tpl index 1925f7ec4d..1258ded36b 100644 --- a/view/theme/frio/templates/contact/list.tpl +++ b/view/theme/frio/templates/contact/list.tpl @@ -14,4 +14,8 @@ at the suggest page and also at many other places *}}
{{$paginate nofilter}} - \ No newline at end of file + +{{if $filtered}} +

{{$filtered nofilter}}

+{{/if}} +