]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Search.php
Merge pull request #12690 from annando/statistics
[friendica.git] / src / Core / Search.php
index 5ae1dd7ac4a9c0aecc1fcd6b590c161770722a71..3c0ace3db5468d62486f7cfc2d1236a75b9b87c1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -70,7 +70,7 @@ class Search
                                return $emptyResultList;
                        }
 
-                       $contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', local_user());
+                       $contactDetails = Contact::getByURLForUser($user_data['url'] ?? '', DI::userSession()->getLocalUserId());
 
                        $result = new ContactResult(
                                $user_data['name'] ?? '',
@@ -136,7 +136,7 @@ class Search
 
                foreach ($profiles as $profile) {
                        $profile_url = $profile['profile_url'] ?? '';
-                       $contactDetails = Contact::getByURLForUser($profile_url, local_user());
+                       $contactDetails = Contact::getByURLForUser($profile_url, DI::userSession()->getLocalUserId());
 
                        $result = new ContactResult(
                                $profile['name'] ?? '',
@@ -192,7 +192,7 @@ class Search
                }
 
                // Add found profiles from the global directory to the local directory
-               Worker::add(PRIORITY_LOW, 'SearchDirectory', $search);
+               Worker::add(Worker::PRIORITY_LOW, 'SearchDirectory', $search);
 
                return $resultList;
        }
@@ -211,7 +211,7 @@ class Search
        {
                Logger::info('Searching', ['search' => $search, 'mode' => $mode, 'page' => $page]);
 
-               if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
+               if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
                        return [];
                }
 
@@ -233,7 +233,24 @@ class Search
                        if ($curlResult->isSuccess()) {
                                $searchResult = json_decode($curlResult->getBody(), true);
                                if (!empty($searchResult['profiles'])) {
-                                       $return = $searchResult['profiles'];
+                                       // Converting Directory Search results into contact-looking records
+                                       $return = array_map(function ($result) {
+                                               static $contactType = [
+                                                       'People'       => Contact::TYPE_PERSON,
+                                                       'Forum'        => Contact::TYPE_COMMUNITY,
+                                                       'Organization' => Contact::TYPE_ORGANISATION,
+                                                       'News'         => Contact::TYPE_NEWS,
+                                               ];
+
+                                               return [
+                                                       'name'         => $result['name'],
+                                                       'addr'         => $result['addr'],
+                                                       'url'          => $result['profile_url'],
+                                                       'network'      => Protocol::DFRN,
+                                                       'micro'        => $result['photo'],
+                                                       'contact-type' => $contactType[$result['account_type']],
+                                               ];
+                                       }, $searchResult['profiles']);
                                }
                        }
                }