]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Fix update password rehash
[friendica.git] / src / Network / Probe.php
index f7c3b84fdd46803c35eb334a505366189595004f..d14c623e864b7f6df93407f1fc52f21bbbd86ab5 100644 (file)
@@ -90,6 +90,9 @@ class Probe
        /**
         * @brief Probes for webfinger path via "host-meta"
         *
+        * We have to check if the servers in the future still will offer this.
+        * It seems as if it was dropped from the standard.
+        *
         * @param string $host The host part of an url
         *
         * @return array with template and type of the webfinger template for JSON or XML
@@ -649,7 +652,7 @@ class Probe
                        $result = self::ostatus($webfinger);
                }
                if ((!$result && ($network == "")) || ($network == NETWORK_PUMPIO)) {
-                       $result = self::pumpio($webfinger);
+                       $result = self::pumpio($webfinger, $addr);
                }
                if ((!$result && ($network == "")) || ($network == NETWORK_FEED)) {
                        $result = self::feed($uri);
@@ -673,7 +676,6 @@ class Probe
                                $result["baseurl"] = substr($result["url"], 0, $pos).$host;
                        }
                }
-
                return $result;
        }
 
@@ -959,6 +961,10 @@ class Probe
                        }
                }
 
+               if (substr($webfinger["subject"], 0, 5) == "acct:") {
+                       $data["addr"] = substr($webfinger["subject"], 5);
+               }
+
                if (!isset($data["network"]) || ($hcard_url == "")) {
                        return false;
                }
@@ -1325,14 +1331,33 @@ class Probe
 
                $data = [];
 
-               // This is ugly - but pump.io doesn't seem to know a better way for it
-               $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
-               $pos = strpos($data["name"], chr(10));
-               if ($pos) {
-                       $data["name"] = trim(substr($data["name"], 0, $pos));
+               $data["name"] = $xpath->query("//span[contains(@class, 'p-name')]")->item(0)->nodeValue;
+
+               if ($data["name"] == '') {
+                       // This is ugly - but pump.io doesn't seem to know a better way for it
+                       $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
+                       $pos = strpos($data["name"], chr(10));
+                       if ($pos) {
+                               $data["name"] = trim(substr($data["name"], 0, $pos));
+                       }
+               }
+
+               $data["location"] = $xpath->query("//p[contains(@class, 'p-locality')]")->item(0)->nodeValue;
+
+               if ($data["location"] == '') {
+                       $data["location"] = $xpath->query("//p[contains(@class, 'location')]")->item(0)->nodeValue;
+               }
+
+               $data["about"] = $xpath->query("//p[contains(@class, 'p-note')]")->item(0)->nodeValue;
+
+               if ($data["about"] == '') {
+                       $data["about"] = $xpath->query("//p[contains(@class, 'summary')]")->item(0)->nodeValue;
                }
 
-               $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
+               $avatar = $xpath->query("//img[contains(@class, 'u-photo')]")->item(0);
+               if (!$avatar) {
+                       $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
+               }
                if ($avatar) {
                        foreach ($avatar->attributes as $attribute) {
                                if ($attribute->name == "src") {
@@ -1341,9 +1366,6 @@ class Probe
                        }
                }
 
-               $data["location"] = $xpath->query("//p[@class='location']")->item(0)->nodeValue;
-               $data["about"] = $xpath->query("//p[@class='summary']")->item(0)->nodeValue;
-
                return $data;
        }
 
@@ -1354,7 +1376,7 @@ class Probe
         *
         * @return array pump.io data
         */
-       private static function pumpio($webfinger)
+       private static function pumpio($webfinger, $addr)
        {
                $data = [];
                foreach ($webfinger["links"] as $link) {
@@ -1392,6 +1414,13 @@ class Probe
 
                $data = array_merge($data, $profile_data);
 
+               if (($addr != '') && ($data['name'] != '')) {
+                       $name = trim(str_replace($addr, '', $data['name']));
+                       if ($name != '') {
+                               $data['name'] = $name;
+                       }
+               }
+
                return $data;
        }
 
@@ -1513,29 +1542,31 @@ class Probe
                        return false;
                }
 
-               if ($uid != 0) {
-                       $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
-
-                       $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
+               if ($uid == 0) {
+                       return false;
+               }
 
-                       if (DBM::is_result($x) && DBM::is_result($r)) {
-                               $mailbox = Email::constructMailboxName($r[0]);
-                               $password = '';
-                               openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
-                               $mbox = Email::connect($mailbox, $r[0]['user'], $password);
-                               if (!mbox) {
-                                       return false;
-                               }
-                       }
+               $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
 
-                       $msgs = Email::poll($mbox, $uri);
-                       logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+               $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
 
-                       if (!count($msgs)) {
+               if (DBM::is_result($x) && DBM::is_result($r)) {
+                       $mailbox = Email::constructMailboxName($r[0]);
+                       $password = '';
+                       openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
+                       $mbox = Email::connect($mailbox, $r[0]['user'], $password);
+                       if (!$mbox) {
                                return false;
                        }
                }
 
+               $msgs = Email::poll($mbox, $uri);
+               logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+
+               if (!count($msgs)) {
+                       return false;
+               }
+
                $phost = substr($uri, strpos($uri, '@') + 1);
 
                $data = [];