X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSearch.php;h=98517361ea34c48a373fcc50380719800a88d9c6;hb=911ed3d6ba98149ed6d400d554e7a0e10bd1c273;hp=605e3fa22918c4beafa37599397c9ae27e58d229;hpb=97456ff20542b2dffabae77a2bab6428c51ac218;p=friendica.git diff --git a/src/Core/Search.php b/src/Core/Search.php index 605e3fa229..98517361ea 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -42,7 +42,7 @@ class Search const DEFAULT_DIRECTORY = 'https://dir.friendica.social'; const TYPE_PEOPLE = 0; - const TYPE_FORUM = 1; + const TYPE_GROUP = 1; const TYPE_ALL = 2; /** @@ -55,19 +55,25 @@ class Search * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function getContactsFromProbe(string $user): ?ResultList + public static function getContactsFromProbe(string $user, $only_group = false): ResultList { + $emptyResultList = new ResultList(); + if (empty(parse_url($user, PHP_URL_SCHEME)) && !(filter_var($user, FILTER_VALIDATE_EMAIL) || Network::isEmailDomainValid($user))) { - return null; + return $emptyResultList; } - + $user_data = Contact::getByURL($user); if (empty($user_data)) { - return null; + return $emptyResultList; + } + + if ($only_group && ($user_data['contact-type'] != Contact::TYPE_COMMUNITY)) { + return $emptyResultList; } if (!Protocol::supportsProbe($user_data['network'])) { - return null; + return $emptyResultList; } $contactDetails = Contact::getByURLForUser($user_data['url'], DI::userSession()->getLocalUserId()); @@ -81,7 +87,7 @@ class Search $user_data['network'], $contactDetails['cid'] ?? 0, $user_data['id'], - $user_data['tags'] + $user_data['keywords'] ); return new ResultList(1, 1, 1, [$result]); @@ -106,8 +112,8 @@ class Search $searchUrl = $server . '/search'; switch ($type) { - case self::TYPE_FORUM: - $searchUrl .= '/forum'; + case self::TYPE_GROUP: + $searchUrl .= '/group'; break; case self::TYPE_PEOPLE: $searchUrl .= '/people'; @@ -125,7 +131,7 @@ class Search $resultList = new ResultList( ($results['page'] ?? 0) ?: 1, - $results['count'] ?? 0, + $results['count'] ?? 0, ($results['itemsperpage'] ?? 0) ?: 30 ); @@ -168,9 +174,9 @@ class Search { Logger::info('Searching', ['search' => $search, 'type' => $type, 'start' => $start, 'itempage' => $itemPage]); - $contacts = Contact::searchByName($search, $type == self::TYPE_FORUM ? 'community' : '', true); + $contacts = Contact::searchByName($search, $type == self::TYPE_GROUP ? 'community' : '', true); - $resultList = new ResultList($start, $itemPage, count($contacts)); + $resultList = new ResultList($start, count($contacts), $itemPage); foreach ($contacts as $contact) { $result = new ContactResult( @@ -234,7 +240,9 @@ class Search $return = array_map(function ($result) { static $contactType = [ 'People' => Contact::TYPE_PERSON, + // Kept for backward compatibility 'Forum' => Contact::TYPE_COMMUNITY, + 'Group' => Contact::TYPE_COMMUNITY, 'Organization' => Contact::TYPE_ORGANISATION, 'News' => Contact::TYPE_NEWS, ];