]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
Class file relocations
[friendica.git] / src / Network / Probe.php
index 431ff5bf75be3ae9dd4957a395721333781d1801..84a0344f32b9978faa1c09e395f88ef2267d8250 100644 (file)
@@ -11,9 +11,9 @@ namespace Friendica\Network;
 use Friendica\App;
 use Friendica\Core\System;
 use Friendica\Core\Config;
+use Friendica\Database\DBM;
 
 use dba;
-use dbm;
 use Cache;
 use xml;
 
@@ -306,16 +306,16 @@ class Probe {
         *
         * @return array uri data
         */
-       public static function uri($uri, $network = "", $uid = 0, $cache = true) {
+       public static function uri($uri, $network = "", $uid = -1, $cache = true) {
 
                if ($cache) {
-                       $result = Cache::get("probe_url:".$network.":".$uri);
+                       $result = Cache::get("Probe::uri:".$network.":".$uri);
                        if (!is_null($result)) {
                                return $result;
                        }
                }
 
-               if ($uid == 0) {
+               if ($uid == -1) {
                        $uid = local_user();
                }
 
@@ -361,7 +361,7 @@ class Probe {
 
                // Only store into the cache if the value seems to be valid
                if (!in_array($data['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
-                       Cache::set("probe_url:".$network.":".$uri, $data, CACHE_DAY);
+                       Cache::set("Probe::uri:".$network.":".$uri, $data, CACHE_DAY);
 
                        /// @todo temporary fix - we need a real contact update function that updates only changing fields
                        /// The biggest problem is the avatar picture that could have a reduced image size.
@@ -397,7 +397,7 @@ class Probe {
                                        }
                                }
 
-                               $fields['updated'] = dbm::date();
+                               $fields['updated'] = DBM::date();
 
                                $condition = array('nurl' => normalise_link($data["url"]));
 
@@ -420,7 +420,7 @@ class Probe {
                                                'confirm' => $data['confirm'],
                                                'poco' => $data['poco'],
                                                'network' => $data['network'],
-                                               'success_update' => dbm::date());
+                                               'success_update' => DBM::date());
 
                                $fieldnames = array();
 
@@ -778,6 +778,10 @@ class Probe {
                        $data["nick"] = $json["nick"];
                }
 
+               if (!empty($json["guid"])) {
+                       $data["guid"] = $json["guid"];
+               }
+
                if (!empty($json["comm"])) {
                        $data["community"] = $json["comm"];
                }
@@ -905,7 +909,6 @@ class Probe {
         * @return array DFRN data
         */
        private static function dfrn($webfinger) {
-
                $hcard_url = "";
                $data = array();
                foreach ($webfinger["links"] as $link) {
@@ -937,7 +940,9 @@ class Probe {
 
                if (is_array($webfinger["aliases"])) {
                        foreach ($webfinger["aliases"] as $alias) {
-                               if (substr($alias, 0, 5) == 'acct:') {
+                               if (normalise_link($alias) != normalise_link($data["url"]) && ! strstr($alias, "@")) {
+                                       $data["alias"] = $alias;
+                               } elseif (substr($alias, 0, 5) == 'acct:') {
                                        $data["addr"] = substr($alias, 5);
                                }
                        }
@@ -1093,7 +1098,6 @@ class Probe {
         * @return array Diaspora data
         */
        private static function diaspora($webfinger) {
-
                $hcard_url = "";
                $data = array();
                foreach ($webfinger["links"] as $link) {
@@ -1129,10 +1133,16 @@ class Probe {
                        foreach ($webfinger["aliases"] as $alias) {
                                if (normalise_link($alias) != normalise_link($data["url"]) && ! strstr($alias, "@")) {
                                        $data["alias"] = $alias;
+                               } elseif (substr($alias, 0, 5) == 'acct:') {
+                                       $data["addr"] = substr($alias, 5);
                                }
                        }
                }
 
+               if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == 'acct:')) {
+                       $data["addr"] = substr($webfinger["subject"], 5);
+               }
+
                // Fetch further information from the hcard
                $data = self::pollHcard($hcard_url, $data);
 
@@ -1171,17 +1181,20 @@ class Probe {
         */
        private static function ostatus($webfinger, $short = false) {
                $data = array();
+
                if (is_array($webfinger["aliases"])) {
                        foreach ($webfinger["aliases"] as $alias) {
-                               if (strstr($alias, "@")) {
+                               if (strstr($alias, "@") && !strstr(normalise_link($alias), "http://")) {
                                        $data["addr"] = str_replace('acct:', '', $alias);
                                }
                        }
                }
 
-               if (is_string($webfinger["subject"]) && strstr($webfinger["subject"], "@")) {
+               if (is_string($webfinger["subject"]) && strstr($webfinger["subject"], "@") &&
+                       !strstr(normalise_link($webfinger["subject"]), "http://")) {
                        $data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
                }
+
                $pubkey = "";
                if (is_array($webfinger["links"])) {
                        foreach ($webfinger["links"] as $link) {
@@ -1483,25 +1496,27 @@ class Probe {
                        return false;
                }
 
-               $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
+               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));
+                       $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
 
-               if (dbm::is_result($x) && dbm::is_result($r)) {
-                       $mailbox = construct_mailbox_name($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;
+                       if (DBM::is_result($x) && DBM::is_result($r)) {
+                               $mailbox = construct_mailbox_name($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);
+                       $msgs = email_poll($mbox, $uri);
+                       logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
 
-               if (!count($msgs)) {
-                       return false;
+                       if (!count($msgs)) {
+                               return false;
+                       }
                }
 
                $phost = substr($uri, strpos($uri, '@') + 1);
@@ -1512,7 +1527,7 @@ class Probe {
                $data["name"]    = substr($uri, 0, strpos($uri, '@'));
                $data["nick"]    = $data["name"];
                $data["photo"]   = avatar_img($uri);
-               $data["url"]     = 'http://'.$phost."/".$data["nick"];
+               $data["url"]     = 'mailto:'.$uri;
                $data["notify"]  = 'smtp '.random_string();
                $data["poll"]    = 'email '.random_string();
 
@@ -1542,7 +1557,9 @@ class Probe {
                                }
                        }
                }
-               imap_close($mbox);
+               if (!empty($mbox)) {
+                       imap_close($mbox);
+               }
 
                return $data;
        }