]> git.mxchange.org Git - friendica.git/blobdiff - include/Probe.php
Only fetch the rows when needed
[friendica.git] / include / Probe.php
index d0b799bfbafdf756abd76b2d6436d87bcedfdcc9..f67a821f9dc04b3854570b881189ca98aa527ea8 100644 (file)
@@ -364,9 +364,9 @@ class Probe {
                                return self::mail($uri, $uid);
                        }
 
-                       if ($network == NETWORK_MAIL)
+                       if ($network == NETWORK_MAIL) {
                                return self::mail($uri, $uid);
-
+                       }
                        // Remove "acct:" from the URI
                        $uri = str_replace('acct:', '', $uri);
 
@@ -391,37 +391,37 @@ class Probe {
                /// @todo Do we need the prefix "acct:" or "acct://"?
 
                foreach ($lrdd AS $key => $link) {
-                       if ($webfinger)
+                       if ($webfinger) {
                                continue;
-
-                       if (!in_array($key, array("lrdd", "lrdd-xml", "lrdd-json")))
+                       }
+                       if (!in_array($key, array("lrdd", "lrdd-xml", "lrdd-json"))) {
                                continue;
-
-                       // Try webfinger with the address (user@domain.tld)
-                       $path = str_replace('{uri}', urlencode($addr), $link);
+                       }
+                       // At first try it with the given uri
+                       $path = str_replace('{uri}', urlencode($uri), $link);
                        $webfinger = self::webfinger($path);
 
-                       // Mastodon needs to have it with "acct:"
+                       // We cannot be sure that the detected address was correct, so we don't use the values
+                       if ($webfinger AND ($uri != $addr)) {
+                               $nick = "";
+                               $addr = "";
+                       }
+
+                       // Try webfinger with the address (user@domain.tld)
                        if (!$webfinger) {
-                               $path = str_replace('{uri}', urlencode("acct:".$addr), $link);
+                               $path = str_replace('{uri}', urlencode($addr), $link);
                                $webfinger = self::webfinger($path);
                        }
 
-                       // If webfinger wasn't successful then try it with the URL - possibly in the format https://...
-                       if (!$webfinger AND ($uri != $addr)) {
-                               $path = str_replace('{uri}', urlencode($uri), $link);
+                       // Mastodon needs to have it with "acct:"
+                       if (!$webfinger) {
+                               $path = str_replace('{uri}', urlencode("acct:".$addr), $link);
                                $webfinger = self::webfinger($path);
-
-                               // Since the detection with the address wasn't successful, we delete it.
-                               if ($webfinger) {
-                                       $nick = "";
-                                       $addr = "";
-                               }
                        }
-
                }
-               if (!$webfinger)
+               if (!$webfinger) {
                        return self::feed($uri);
+               }
 
                $result = false;
 
@@ -888,33 +888,36 @@ class Probe {
         * @return array OStatus data
         */
        private function ostatus($webfinger) {
-
                $data = array();
-               if (is_array($webfinger["aliases"]))
-                       foreach($webfinger["aliases"] AS $alias)
-                               if (strstr($alias, "@"))
+               if (is_array($webfinger["aliases"])) {
+                       foreach ($webfinger["aliases"] AS $alias) {
+                               if (strstr($alias, "@")) {
                                        $data["addr"] = str_replace('acct:', '', $alias);
+                               }
+                       }
+               }
 
-               if (is_string($webfinger["subject"]) AND strstr($webfinger["subject"], "@"))
+               if (is_string($webfinger["subject"]) AND strstr($webfinger["subject"], "@")) {
                        $data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
-
+               }
                $pubkey = "";
                foreach ($webfinger["links"] AS $link) {
                        if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
-                               ($link["type"] == "text/html") AND ($link["href"] != ""))
+                               ($link["type"] == "text/html") AND ($link["href"] != "")) {
                                $data["url"] = $link["href"];
-                       elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
+                       } elseif (($link["rel"] == "salmon") AND ($link["href"] != "")) {
                                $data["notify"] = $link["href"];
-                       elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
+                       } elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != "")) {
                                $data["poll"] = $link["href"];
-                       elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
+                       elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
                                $pubkey = $link["href"];
 
                                if (substr($pubkey, 0, 5) === 'data:') {
-                                       if (strstr($pubkey, ','))
+                                       if (strstr($pubkey, ',')) {
                                                $pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
-                                       else
+                                       } else {
                                                $pubkey = substr($pubkey, 5);
+                                       }
                                } elseif (normalise_link($pubkey) == 'http://') {
                                        $ret = z_fetch_url($pubkey);
                                        if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
@@ -930,16 +933,15 @@ class Probe {
                                        $e = base64url_decode($key[2]);
                                        $data["pubkey"] = metopem($m,$e);
                                }
-
                        }
                }
 
                if (isset($data["notify"]) AND isset($data["pubkey"]) AND
                        isset($data["poll"]) AND isset($data["url"])) {
                        $data["network"] = NETWORK_OSTATUS;
-               } else
+               } else {
                        return false;
-
+               }
                // Fetch all additional data from the feed
                $ret = z_fetch_url($data["poll"]);
                if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
@@ -947,32 +949,32 @@ class Probe {
                }
                $feed = $ret['body'];
                $feed_data = feed_import($feed,$dummy1,$dummy2, $dummy3, true);
-               if (!$feed_data)
+               if (!$feed_data) {
                        return false;
-
-               if ($feed_data["header"]["author-name"] != "")
+               }
+               if ($feed_data["header"]["author-name"] != "") {
                        $data["name"] = $feed_data["header"]["author-name"];
-
-               if ($feed_data["header"]["author-nick"] != "")
+               }
+               if ($feed_data["header"]["author-nick"] != "") {
                        $data["nick"] = $feed_data["header"]["author-nick"];
-
-               if ($feed_data["header"]["author-avatar"] != "")
-                       $data["photo"] = $feed_data["header"]["author-avatar"];
-
-               if ($feed_data["header"]["author-id"] != "")
+               }
+               if ($feed_data["header"]["author-avatar"] != "") {
+                       $data["photo"] = ostatus::fix_avatar($feed_data["header"]["author-avatar"], $data["url"]);
+               }
+               if ($feed_data["header"]["author-id"] != "") {
                        $data["alias"] = $feed_data["header"]["author-id"];
-
-               if ($feed_data["header"]["author-location"] != "")
+               }
+               if ($feed_data["header"]["author-location"] != "") {
                        $data["location"] = $feed_data["header"]["author-location"];
-
-               if ($feed_data["header"]["author-about"] != "")
+               }
+               if ($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)
                // So we take the value that we just fetched, although the other one worked as well
-               if ($feed_data["header"]["author-link"] != "")
+               if ($feed_data["header"]["author-link"] != "") {
                        $data["url"] = $feed_data["header"]["author-link"];
-
+               }
                /// @todo Fetch location and "about" from the feed as well
                return $data;
        }