* @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]);
}
/**
$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);