Merge pull request #12954 from MrPetovan/bug/12555-domain-block-contact-search

Filter contact search by blocked remote domains
This commit is contained in:
Michael Vogel 2023-04-21 21:55:14 +02:00 committed by GitHub
commit bd00287190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 13 deletions

View File

@ -29,6 +29,7 @@ use Friendica\Object\Search\ContactResult;
use Friendica\Object\Search\ResultList;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
/**
* Specific class to perform searches for different systems. Currently:
@ -76,7 +77,7 @@ class Search
$user_data['name'] ?? '',
$user_data['addr'] ?? '',
($contactDetails['addr'] ?? '') ?: ($user_data['url'] ?? ''),
$user_data['url'] ?? '',
new Uri($user_data['url'] ?? ''),
$user_data['photo'] ?? '',
$user_data['network'] ?? '',
$contactDetails['cid'] ?? 0,
@ -142,7 +143,7 @@ class Search
$profile['name'] ?? '',
$profile['addr'] ?? '',
($contactDetails['addr'] ?? '') ?: $profile_url,
$profile_url,
new Uri($profile_url),
$profile['photo'] ?? '',
Protocol::DFRN,
$contactDetails['cid'] ?? 0,
@ -180,7 +181,7 @@ class Search
$contact['name'],
$contact['addr'],
$contact['addr'] ?: $contact['url'],
$contact['url'],
new Uri($contact['url']),
$contact['photo'],
$contact['network'],
0,

View File

@ -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 <a href="/friendica">About page</a>.',
'%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 <a href="/friendica">About page</a>.',
$filtered) : '',
'$contacts' => $entries,
'$paginate' => $pager->renderFull($results->getTotal()),
]);

View File

@ -22,6 +22,7 @@
namespace Friendica\Object\Search;
use Friendica\Model\Search;
use Psr\Http\Message\UriInterface;
/**
* A search result for contact searching
@ -51,7 +52,7 @@ class ContactResult implements IResult
*/
private $item;
/**
* @var string
* @var UriInterface
*/
private $url;
/**
@ -108,9 +109,9 @@ class ContactResult implements IResult
}
/**
* @return string
* @return UriInterface
*/
public function getUrl(): string
public function getUrl(): UriInterface
{
return $this->url;
}
@ -143,14 +144,14 @@ class ContactResult implements IResult
* @param string $name
* @param string $addr
* @param string $item
* @param string $url
* @param UriInterface $url
* @param string $photo
* @param string $network
* @param int $cid
* @param int $pCid
* @param string $tags
*/
public function __construct($name, $addr, $item, $url, $photo, $network, $cid = 0, $pCid = 0, $tags = '')
public function __construct($name, $addr, $item, UriInterface $url, $photo, $network, $cid = 0, $pCid = 0, $tags = '')
{
$this->name = $name;
$this->addr = $addr;

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2023.03-rc\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-04-18 19:28+0000\n"
"POT-Creation-Date: 2023-04-20 07:48-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -5540,10 +5540,23 @@ msgstr ""
msgid "Forum Search - %s"
msgstr ""
#: src/Module/BaseSearch.php:119 src/Module/Contact/MatchInterests.php:139
#: src/Module/BaseSearch.php:121 src/Module/Contact/MatchInterests.php:139
msgid "No matches"
msgstr ""
#: src/Module/BaseSearch.php:147
#, php-format
msgid ""
"%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 <a href=\"/friendica\">About page</a>."
msgid_plural ""
"%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 <a href=\"/friendica\">About page</a>."
msgstr[0] ""
msgstr[1] ""
#: src/Module/BaseSettings.php:80
msgid "Account"
msgstr ""

View File

@ -12,3 +12,7 @@
<div id="view-contact-end"></div>
{{$paginate nofilter}}
{{if $filtered}}
<p>{{$filtered nofilter}}</p>
{{/if}}

View File

@ -14,4 +14,8 @@ at the suggest page and also at many other places *}}
<div id="view-contact-end"></div>
{{$paginate nofilter}}
</div>
{{if $filtered}}
<p>{{$filtered nofilter}}</p>
{{/if}}
</div>