]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Update function / rearrange tab order
[friendica.git] / src / Network / Probe.php
index 041e227a4dbaff4ee6c10f70c32c73d020a0ceba..a0887d5cba877cb5187acccdf6c09017c261b1a6 100644 (file)
@@ -341,7 +341,6 @@ class Probe
         * @param string  $uri     Address that should be probed
         * @param string  $network Test for this specific network
         * @param integer $uid     User ID for the probe (only used for mails)
-        * @param boolean $cache   Use cached values?
         *
         * @return array uri data
         * @throws HTTPException\InternalServerErrorException
@@ -416,14 +415,19 @@ class Probe
                        }
                }
 
-               if (!empty($data['baseurl']) && empty($data['gsid'])) {
-                       $data['gsid'] = GServer::getID($data['baseurl']);
-               }
-
                if (empty($data['network'])) {
                        $data['network'] = Protocol::PHANTOM;
                }
 
+               $baseurl = parse_url($data['url'], PHP_URL_SCHEME) . '://' . parse_url($data['url'], PHP_URL_HOST);
+               if (empty($data['baseurl']) && ($data['network'] == Protocol::ACTIVITYPUB) && (rtrim($data['url'], '/') == $baseurl)) {
+                       $data['baseurl'] = $baseurl;
+               }
+
+               if (!empty($data['baseurl']) && empty($data['gsid'])) {
+                       $data['gsid'] = GServer::getID($data['baseurl']);
+               }       
+
                // Ensure that local connections always are DFRN
                if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) {
                        $data['network'] = Protocol::DFRN;
@@ -769,7 +773,7 @@ class Probe
                if (empty($result['network']) && empty($ap_profile['network']) || ($network == Protocol::FEED)) {
                        $result = self::feed($uri);
                } else {
-                       // We overwrite the detected nick with our try if the previois routines hadn't detected it.
+                       // We overwrite the detected nick with our try if the previous routines hadn't detected it.
                        // Additionally, it is overwritten when the nickname doesn't make sense (contains spaces).
                        if ((empty($result['nick']) || (strstr($result['nick'], ' '))) && ($nick != '')) {
                                $result['nick'] = $nick;
@@ -952,9 +956,17 @@ class Probe
         */
        public static function webfinger(string $url, string $type): array
        {
-               $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
+               try {
+                       $curlResult = DI::httpClient()->get(
+                               $url,
+                               $type,
+                               [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout', 20)]
+                       );
+               } catch (\Throwable $e) {
+                       Logger::notice($e->getMessage(), ['url' => $url, 'type' => $type, 'class' => get_class($e)]);
+                       return [];
+               }
 
-               $curlResult = DI::httpClient()->get($url, $type, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
                if ($curlResult->isTimeout()) {
                        self::$isTimeout = true;
                        return [];
@@ -1173,7 +1185,6 @@ class Probe
                        $data = self::pollHcard($profile_link, $data, true);
                }
 
-               $prof_data = [];
 
                if (empty($data['addr']) || empty($data['nick'])) {
                        $probe_data = self::uri($profile_link);
@@ -1181,15 +1192,17 @@ class Probe
                        $data['nick'] = ($data['nick'] ?? '') ?: $probe_data['nick'];
                }
 
-               $prof_data['addr']         = $data['addr'];
-               $prof_data['nick']         = $data['nick'];
-               $prof_data['dfrn-request'] = $data['request'] ?? null;
-               $prof_data['dfrn-confirm'] = $data['confirm'] ?? null;
-               $prof_data['dfrn-notify']  = $data['notify']  ?? null;
-               $prof_data['dfrn-poll']    = $data['poll']    ?? null;
-               $prof_data['photo']        = $data['photo']   ?? null;
-               $prof_data['fn']           = $data['name']    ?? null;
-               $prof_data['key']          = $data['pubkey']  ?? null;
+               $prof_data = [
+                       'addr'         => $data['addr'],
+                       'nick'         => $data['nick'],
+                       'dfrn-request' => $data['request'] ?? null,
+                       'dfrn-confirm' => $data['confirm'] ?? null,
+                       'dfrn-notify'  => $data['notify']  ?? null,
+                       'dfrn-poll'    => $data['poll']    ?? null,
+                       'photo'        => $data['photo']   ?? null,
+                       'fn'           => $data['name']    ?? null,
+                       'key'          => $data['pubkey']  ?? null,
+               ];
 
                Logger::debug('Result', ['link' => $profile_link, 'data' => $prof_data]);
 
@@ -1623,7 +1636,7 @@ class Probe
                if (!empty($feed_data['header']['author-about'])) {
                        $data['about'] = $feed_data['header']['author-about'];
                }
-               // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
+               // OStatus has serious issues when the url doesn't fit (ssl vs. non ssl)
                // So we take the value that we just fetched, although the other one worked as well
                if (!empty($feed_data['header']['author-link'])) {
                        $data['url'] = $feed_data['header']['author-link'];