]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Replace unwarranted uses of $a->data['contact']
[friendica.git] / src / Network / Probe.php
index 0e9219c5a615b8b095f1068b827f060f640d27c4..2c42643b44a07fae9389c4ac738aa3ebac54c82c 100644 (file)
@@ -74,7 +74,7 @@ class Probe
         */
        private static function ownHost($host)
        {
-               $own_host = get_app()->get_hostname();
+               $own_host = get_app()->getHostName();
 
                $parts = parse_url($host);
 
@@ -112,20 +112,20 @@ class Probe
                logger("Probing for ".$host, LOGGER_DEBUG);
                $xrd = null;
 
-               $ret = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
-               if ($ret['success']) {
-                       $xml = $ret['body'];
+               $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+               if ($curlResult->isSuccess()) {
+                       $xml = $curlResult->getBody();
                        $xrd = XML::parseString($xml, false);
                        $host_url = 'https://'.$host;
                }
 
                if (!is_object($xrd)) {
-                       $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
-                       if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
-                               logger("Probing timeout for ".$url, LOGGER_DEBUG);
+                       $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+                       if ($curlResult->isTimeout()) {
+                               logger("Probing timeout for " . $url, LOGGER_DEBUG);
                                return false;
                        }
-                       $xml = $ret['body'];
+                       $xml = $curlResult->getBody();
                        $xrd = XML::parseString($xml, false);
                        $host_url = 'http://'.$host;
                }
@@ -335,11 +335,10 @@ class Probe
                        $data = null;
                }
 
-               if (in_array(defaults($data, 'network', ''), ['', Protocol::PHANTOM])) {
-                       $ap_profile = ActivityPub::fetchProfile($uri);
-                       if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) {
-                               $data = $ap_profile;
-                       }
+               $ap_profile = ActivityPub::probeProfile($uri);
+
+               if (!empty($ap_profile) && (defaults($data, 'network', '') != Protocol::DFRN)) {
+                       $data = $ap_profile;
                }
 
                if (!isset($data["url"])) {
@@ -743,11 +742,11 @@ class Probe
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
                $redirects = 0;
 
-               $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
-               if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
+               $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
+               if ($curlResult->isTimeout()) {
                        return false;
                }
-               $data = $ret['body'];
+               $data = $curlResult->getBody();
 
                $webfinger = json_decode($data, true);
                if (is_array($webfinger)) {
@@ -810,11 +809,11 @@ class Probe
         */
        private static function pollNoscrape($noscrape_url, $data)
        {
-               $ret = Network::curl($noscrape_url);
-               if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
+               $curlResult = Network::curl($noscrape_url);
+               if ($curlResult->isTimeout()) {
                        return false;
                }
-               $content = $ret['body'];
+               $content = $curlResult->getBody();
                if (!$content) {
                        logger("Empty body for ".$noscrape_url, LOGGER_DEBUG);
                        return false;
@@ -1055,11 +1054,11 @@ class Probe
         */
        private static function pollHcard($hcard_url, $data, $dfrn = false)
        {
-               $ret = Network::curl($hcard_url);
-               if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
+               $curlResult = Network::curl($hcard_url);
+               if ($curlResult->isTimeout()) {
                        return false;
                }
-               $content = $ret['body'];
+               $content = $curlResult->getBody();
                if (!$content) {
                        return false;
                }
@@ -1302,11 +1301,11 @@ class Probe
                                                        $pubkey = substr($pubkey, 5);
                                                }
                                        } elseif (normalise_link($pubkey) == 'http://') {
-                                               $ret = Network::curl($pubkey);
-                                               if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
+                                               $curlResult = Network::curl($pubkey);
+                                               if ($curlResult->isTimeout()) {
                                                        return false;
                                                }
-                                               $pubkey = $ret['body'];
+                                               $pubkey = $curlResult['body'];
                                        }
 
                                        $key = explode(".", $pubkey);
@@ -1334,11 +1333,11 @@ class Probe
                }
 
                // Fetch all additional data from the feed
-               $ret = Network::curl($data["poll"]);
-               if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
+               $curlResult = Network::curl($data["poll"]);
+               if ($curlResult->isTimeout()) {
                        return false;
                }
-               $feed = $ret['body'];
+               $feed = $curlResult->getBody();
                $dummy1 = null;
                $dummy2 = null;
                $dummy2 = null;
@@ -1544,11 +1543,11 @@ class Probe
         */
        private static function feed($url, $probe = true)
        {
-               $ret = Network::curl($url);
-               if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
+               $curlResult = Network::curl($url);
+               if ($curlResult->isTimeout()) {
                        return false;
                }
-               $feed = $ret['body'];
+               $feed = $curlResult->getBody();
                $dummy1 = $dummy2 = $dummy3 = null;
                $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);