From: Michael Date: Fri, 12 May 2023 07:00:02 +0000 (+0000) Subject: Fix: Contacts can now be searched with a leading @ again. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f45dbf8b01076f3d4d8cd7b9fe55594b21b31bb9;p=friendica.git Fix: Contacts can now be searched with a leading @ again. --- diff --git a/src/Core/Search.php b/src/Core/Search.php index 45b64eb517..605e3fa229 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -55,40 +55,36 @@ class Search * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function getContactsFromProbe(string $user): ResultList + public static function getContactsFromProbe(string $user): ?ResultList { - $emptyResultList = new ResultList(1, 0, 1); - - if ((filter_var($user, FILTER_VALIDATE_EMAIL) && Network::isEmailDomainValid($user)) || - (substr(Strings::normaliseLink($user), 0, 7) == 'http://')) { - - $user_data = Contact::getByURL($user); - if (empty($user_data)) { - return $emptyResultList; - } - - if (!in_array($user_data['network'], Protocol::FEDERATED)) { - return $emptyResultList; - } + if (empty(parse_url($user, PHP_URL_SCHEME)) && !(filter_var($user, FILTER_VALIDATE_EMAIL) || Network::isEmailDomainValid($user))) { + return null; + } + + $user_data = Contact::getByURL($user); + if (empty($user_data)) { + return null; + } - $contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', DI::userSession()->getLocalUserId()); + if (!Protocol::supportsProbe($user_data['network'])) { + return null; + } - $result = new ContactResult( - $user_data['name'] ?? '', - $user_data['addr'] ?? '', - ($contactDetails['addr'] ?? '') ?: ($user_data['url'] ?? ''), - new Uri($user_data['url'] ?? ''), - $user_data['photo'] ?? '', - $user_data['network'] ?? '', - $contactDetails['cid'] ?? 0, - $user_data['id'] ?? 0, - $user_data['tags'] ?? '' - ); + $contactDetails = Contact::getByURLForUser($user_data['url'], DI::userSession()->getLocalUserId()); + + $result = new ContactResult( + $user_data['name'], + $user_data['addr'], + $user_data['addr'] ?: $user_data['url'], + new Uri($user_data['url']), + $user_data['photo'], + $user_data['network'], + $contactDetails['cid'] ?? 0, + $user_data['id'], + $user_data['tags'] + ); - return new ResultList(1, 1, 1, [$result]); - } else { - return $emptyResultList; - } + return new ResultList(1, 1, 1, [$result]); } /** diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index 675deb8fb2..3593e8a632 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -91,14 +91,16 @@ class BaseSearch extends BaseModule $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); - if ($localSearch && empty($results)) { - $pager->setItemsPerPage(80); - $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage()); - } elseif (Search::getGlobalDirectory() && empty($results)) { - $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage()); - $pager->setItemsPerPage($results->getItemsPage()); - } else { - $results = new ResultList(); + if (empty($results)) { + if ($localSearch) { + $pager->setItemsPerPage(80); + $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage()); + } elseif (Search::getGlobalDirectory()) { + $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage()); + $pager->setItemsPerPage($results->getItemsPage()); + } else { + $results = new ResultList(); + } } return self::printResult($results, $pager, $header);