]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
make errormessages modular and better
[friendica.git] / src / Network / Probe.php
index e1bedf5e5358e1fa51bf9e26aa2d6d4c455a7d9b..88c256fe08d9975046423a67887672424b95bee9 100644 (file)
@@ -120,9 +120,13 @@ class Probe
 
                $numeric_fields = ['gsid', 'hide', 'account-type', 'manually-approve'];
 
-               if (!empty($data['photo']) && !Network::isValidHttpUrl($data['photo'])) {
-                       Logger::info('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]);
-                       unset($data['photo']);
+               if (!empty($data['photo'])) {
+                       $data['photo'] = Network::addBasePath($data['photo'], $data['url']);
+
+                       if (!Network::isValidHttpUrl($data['photo'])) {
+                               Logger::warning('Invalid URL for photo', ['url' => $data['url'], 'photo' => $data['photo']]);
+                               unset($data['photo']);
+                       }
                }
 
                $newdata = [];
@@ -174,7 +178,7 @@ class Probe
         */
        private static function ownHost(string $host): bool
        {
-               $own_host = DI::baseUrl()->getHostname();
+               $own_host = DI::baseUrl()->getHost();
 
                $parts = parse_url($host);
 
@@ -524,7 +528,7 @@ class Probe
         * @return array Webfinger data
         * @throws HTTPException\InternalServerErrorException
         */
-       private static function getWebfingerArray(string $uri): array
+       public static function getWebfingerArray(string $uri): array
        {
                $parts = parse_url($uri);
 
@@ -766,7 +770,7 @@ class Probe
                        $result = self::feed($uri);
                } else {
                        // We overwrite the detected nick with our try if the previois routines hadn't detected it.
-                       // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
+                       // Additionally, it is overwritten when the nickname doesn't make sense (contains spaces).
                        if ((empty($result['nick']) || (strstr($result['nick'], ' '))) && ($nick != '')) {
                                $result['nick'] = $nick;
                        }
@@ -1684,11 +1688,8 @@ class Probe
                }
                if ($avatar) {
                        foreach ($avatar->attributes as $attribute) {
-                               if ($attribute->name == 'src') {
-                                       $data['photo'] = trim($attribute->value);
-                                       if (!empty($data['photo']) && !parse_url($data['photo'], PHP_URL_SCHEME) && !parse_url($data['photo'], PHP_URL_HOST)) {
-                                               $data['photo'] = $baseurl . $data['photo'];
-                                       }
+                               if (($attribute->name == 'src') && !empty($attribute->value)) {
+                                       $data['photo'] = Network::addBasePath($attribute->value, $baseurl);
                                }
                        }
                }
@@ -1861,11 +1862,18 @@ class Probe
         */
        private static function feed(string $url, bool $probe = true): array
        {
-               $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML);
+               try {
+                       $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML);
+               } catch(\Throwable $e) {
+                       DI::logger()->info('Error requesting feed URL', ['url' => $url, 'exception' => $e]);
+                       return [];
+               }
+
                if ($curlResult->isTimeout()) {
                        self::$isTimeout = true;
                        return [];
                }
+
                $feed = $curlResult->getBody();
                $feed_data = Feed::import($feed);