]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GContact.php
Remove unused `use` statements & remove PConfig class
[friendica.git] / src / Model / GContact.php
index 61e44b4106dff1f1cc5147e817c34c8e4ed8925e..6dac33bfb14e4a5656ebda787ddbb91f1c66a3ab 100644 (file)
@@ -12,8 +12,9 @@ use Friendica\Core\Config;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
-use Friendica\Core\Worker;
+use Friendica\Core\Search;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Network\Probe;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\PortableContact;
@@ -149,7 +150,7 @@ class GContact
                }
 
                // The global contacts should contain the original picture, not the cached one
-               if (($gcontact['generation'] != 1) && stristr(Strings::normaliseLink($gcontact['photo']), Strings::normaliseLink(System::baseUrl() . '/photo/'))) {
+               if (($gcontact['generation'] != 1) && stristr(Strings::normaliseLink($gcontact['photo']), Strings::normaliseLink(DI::baseUrl() . '/photo/'))) {
                        $gcontact['photo'] = '';
                }
 
@@ -216,7 +217,7 @@ class GContact
 
                if (empty($gcontact['server_url'])) {
                        // We check the server url to be sure that it is a real one
-                       $server_url = Contact::getBasepath($gcontact['url']);
+                       $server_url = self::getBasepath($gcontact['url']);
 
                        // We are now sure that it is a correct URL. So we use it in the future
                        if ($server_url != '') {
@@ -503,12 +504,12 @@ class GContact
                $done = [];
 
                /// @TODO Check if it is really neccessary to poll the own server
-               PortableContact::loadWorker(0, 0, 0, System::baseUrl() . '/poco');
+               PortableContact::loadWorker(0, 0, 0, DI::baseUrl() . '/poco');
 
-               $done[] = System::baseUrl() . '/poco';
+               $done[] = DI::baseUrl() . '/poco';
 
                if (strlen(Config::get('system', 'directory'))) {
-                       $x = Network::fetchUrl(get_server() . '/pubsites');
+                       $x = Network::fetchUrl(Search::getGlobalDirectory() . '/pubsites');
                        if (!empty($x)) {
                                $j = json_decode($x);
                                if (!empty($j->entries)) {
@@ -1122,12 +1123,44 @@ class GContact
                                "notify" => $userdata['notify'], 'url' => $userdata['url'],
                                "hide" => ($userdata['hidewall'] || !$userdata['net-publish']),
                                'nick' => $userdata['nickname'], 'addr' => $userdata['addr'],
-                               "connect" => $userdata['addr'], "server_url" => System::baseUrl(),
+                               "connect" => $userdata['addr'], "server_url" => DI::baseUrl(),
                                "generation" => 1, 'network' => Protocol::DFRN];
 
                self::update($gcontact);
        }
 
+       /**
+        * @brief Get the basepath for a given contact link
+        *
+        * @param string $url The gcontact link
+        * @param boolean $dont_update Don't update the contact
+        *
+        * @return string basepath
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function getBasepath($url, $dont_update = false)
+       {
+               $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($url)]);
+               if (!empty($gcontact['server_url'])) {
+                       return $gcontact['server_url'];
+               } elseif ($dont_update) {
+                       return '';
+               }
+
+               self::updateFromProbe($url, true);
+
+               // Fetch the result
+               $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($url)]);
+               if (empty($gcontact['server_url'])) {
+                       Logger::info('No baseurl for gcontact', ['url' => $url]);
+                       return '';
+               }
+
+               Logger::info('Found baseurl for gcontact', ['url' => $url, 'baseurl' => $gcontact['server_url']]);
+               return $gcontact['server_url'];
+       }
+
        /**
         * @brief Fetches users of given GNU Social server
         *
@@ -1182,7 +1215,7 @@ class GContact
                                                'addr' => $user->nickname . '@' . $hostname,
                                                'nick' => $user->nickname,
                                                "network" => Protocol::OSTATUS,
-                                               'photo' => System::baseUrl() . '/images/person-300.jpg'];
+                                               'photo' => DI::baseUrl() . '/images/person-300.jpg'];
 
                                if (isset($user->bio)) {
                                        $contact['about'] = $user->bio;