X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSearch.php;h=9f8375da12f66e539a25d1da0954a3c14b34ca1a;hb=f70271aa5d40ce48ec92f1c6ec652c6a977e588c;hp=3a97a700d77bbde3f55d1f1af64d4bb7f84df8c9;hpb=2bb2bb19fd1c348ee18b0de6a67b032eea326a89;p=friendica.git diff --git a/src/Core/Search.php b/src/Core/Search.php index 3a97a700d7..9f8375da12 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -33,26 +33,28 @@ class Search extends BaseObject * * @param string $user The user to search for * - * @return ResultList|null + * @return ResultList * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ public static function getContactsFromProbe($user) { + $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 = Probe::uri($user); if (empty($user_data)) { - return null; + return $emptyResultList; } - if (!(in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]))) { - return null; + if (!(in_array($user_data["network"], Protocol::FEDERATED))) { + return $emptyResultList; } $contactDetails = Contact::getDetailsByURL(defaults($user_data, 'url', ''), local_user()); - $itemUrl = (($contactDetails["addr"] != "") ? $contactDetails["addr"] : defaults($user_data, 'url', '')); + $itemUrl = defaults($contactDetails, 'addr', defaults($user_data, 'url', '')); $result = new ContactResult( defaults($user_data, 'name', ''), @@ -67,21 +69,21 @@ class Search extends BaseObject ); return new ResultList(1, 1, 1, [$result]); - } else { - return null; + return $emptyResultList; } } /** * Search in the global directory for occurrences of the search string + * * @see https://github.com/friendica/friendica-directory/blob/master/docs/Protocol.md#search * * @param string $search * @param int $type specific type of searching * @param int $page * - * @return ResultList|null + * @return ResultList * @throws HTTPException\InternalServerErrorException */ public static function getContactsFromGlobalDirectory($search, $type = self::TYPE_ALL, $page = 1) @@ -105,22 +107,21 @@ class Search extends BaseObject $searchUrl .= '&page=' . $page; } - $red = 0; - $resultJson = Network::fetchUrl($searchUrl, false,$red, 0, 'application/json'); + $resultJson = Network::fetchUrl($searchUrl, false, 0, 'application/json'); - $results = json_decode($resultJson, true); + $results = json_decode($resultJson, true); $resultList = new ResultList( defaults($results, 'page', 1), - defaults($results, 'count', 1), - defaults($results, 'itemsperpage', 1) + defaults($results, 'count', 0), + defaults($results, 'itemsperpage', 30) ); $profiles = defaults($results, 'profiles', []); foreach ($profiles as $profile) { $contactDetails = Contact::getDetailsByURL(defaults($profile, 'profile_url', ''), local_user()); - $itemUrl = (!empty($contactDetails['addr']) ? $contactDetails['addr'] : defaults($profile, 'profile_url', '')); + $itemUrl = defaults($contactDetails, 'addr', defaults($profile, 'profile_url', '')); $result = new ContactResult( defaults($profile, 'name', ''), @@ -147,7 +148,7 @@ class Search extends BaseObject * @param int $start * @param int $itemPage * - * @return ResultList|null + * @return ResultList * @throws HTTPException\InternalServerErrorException */ public static function getContactsFromLocalDirectory($search, $type = self::TYPE_ALL, $start = 0, $itemPage = 80) @@ -172,8 +173,10 @@ class Search extends BaseObject ($type === self::TYPE_FORUM), ]); + $resultList = new ResultList($start, $itemPage, $count); + if (empty($count)) { - return null; + return $resultList; } $data = DBA::select('gcontact', ['nurl'], [ @@ -189,16 +192,14 @@ class Search extends BaseObject ($type === self::TYPE_FORUM), ], [ 'group_by' => ['nurl', 'updated'], - 'limit' => [$start, $itemPage], - 'order' => ['updated' => 'DESC'] + 'limit' => [$start, $itemPage], + 'order' => ['updated' => 'DESC'] ]); if (!DBA::isResult($data)) { - return null; + return $resultList; } - $resultList = new ResultList($start, $itemPage, $count); - while ($row = DBA::fetch($data)) { if (PortableContact::alternateOStatusUrl($row["nurl"])) { continue;