]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/Probe.php
add some spaces for better readability
[friendica.git] / src / Network / Probe.php
index 30d7ef898c9c433759b6c4d1fcbc6dc847e49b5e..fb4c4f66dd0609ca35c22b7bb4e7f3304e67c2fa 100644 (file)
@@ -109,11 +109,13 @@ class Probe {
                                continue;
                        }
 
-                       if (($attributes["rel"] == "lrdd") AND
-                               ($attributes["type"] == "application/xrd+xml")) {
+                       if (($attributes["rel"] == "lrdd")
+                               AND ($attributes["type"] == "application/xrd+xml")
+                       ) {
                                $xrd_data["lrdd-xml"] = $attributes["template"];
-                       } elseif (($attributes["rel"] == "lrdd") AND
-                               ($attributes["type"] == "application/json")) {
+                       } elseif (($attributes["rel"] == "lrdd")
+                               AND ($attributes["type"] == "application/json")
+                       ) {
                                $xrd_data["lrdd-json"] = $attributes["template"];
                        } elseif ($attributes["rel"] == "lrdd") {
                                $xrd_data["lrdd"] = $attributes["template"];
@@ -141,12 +143,12 @@ class Probe {
         * a lengthy content page to scrape dfrn attributes
         *
         * @param string $webbie Address that should be probed
-        * @param string $hcard Link to the hcard - is returned by reference
+        * @param string $hcard_url Link to the hcard - is returned by reference
         *
         * @return string profile link
         */
 
-       public static function webfingerDfrn($webbie, &$hcard) {
+       public static function webfingerDfrn($webbie, &$hcard_url) {
 
                $profile_link = '';
 
@@ -161,7 +163,7 @@ class Probe {
                                        $profile_link = 'stat:'.$link['@attributes']['template'];
                                }
                                if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
-                                       $hcard = $link['@attributes']['href'];
+                                       $hcard_url = $link['@attributes']['href'];
                                }
                        }
                }
@@ -330,8 +332,14 @@ class Probe {
                        /// @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.
                        /// It should only be updated if the existing picture isn't existing anymore.
-                       if (($data['network'] != NETWORK_FEED) AND ($mode == PROBE_NORMAL) AND
-                               $data["name"] AND $data["nick"] AND $data["url"] AND $data["addr"] AND $data["poll"]) {
+                       if (($data['network'] != NETWORK_FEED)
+                               AND ($mode == PROBE_NORMAL)
+                               AND $data["name"]
+                               AND $data["nick"]
+                               AND $data["url"]
+                               AND $data["addr"]
+                               AND $data["poll"]
+                       ) {
                                q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `addr` = '%s',
                                                `notify` = '%s', `poll` = '%s', `alias` = '%s', `success_update` = '%s'
                                        WHERE `nurl` = '%s' AND NOT `self` AND `uid` = 0",
@@ -571,13 +579,13 @@ class Probe {
         * "noscrape" is a faster alternative to fetch the data from the hcard.
         * This functionality was originally created for the directory.
         *
-        * @param string $noscrape Link to the noscrape page
+        * @param string $noscrape_url Link to the noscrape page
         * @param array $data The already fetched data
         *
         * @return array noscrape data
         */
-       private function pollNoscrape($noscrape, $data) {
-               $ret = z_fetch_url($noscrape);
+       private function pollNoscrape($noscrape_url, $data) {
+               $ret = z_fetch_url($noscrape_url);
                if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
                        return false;
                }
@@ -680,40 +688,44 @@ class Probe {
        /**
         * @brief Fetch data from a DFRN profile page and via "noscrape"
         *
-        * @param string $profile Link to the profile page
+        * @param string $profile_link Link to the profile page
         *
         * @return array profile data
         */
-       public static function profile($profile) {
+       public static function profile($profile_link) {
 
                $data = array();
 
-               logger("Check profile ".$profile, LOGGER_DEBUG);
+               logger("Check profile ".$profile_link, LOGGER_DEBUG);
 
                // Fetch data via noscrape - this is faster
-               $noscrape = str_replace(array("/hcard/", "/profile/"), "/noscrape/", $profile);
-               $data = self::pollNoscrape($noscrape, $data);
+               $noscrape_url = str_replace(array("/hcard/", "/profile/"), "/noscrape/", $profile_link);
+               $data = self::pollNoscrape($noscrape_url, $data);
 
-               if (!isset($data["notify"]) OR !isset($data["confirm"]) OR
-                       !isset($data["request"]) OR !isset($data["poll"]) OR
-                       !isset($data["poco"]) OR !isset($data["name"]) OR
-                       !isset($data["photo"])) {
-                       $data = self::pollHcard($profile, $data, true);
+               if (!isset($data["notify"])
+                       OR !isset($data["confirm"])
+                       OR !isset($data["request"])
+                       OR !isset($data["poll"])
+                       OR !isset($data["poco"])
+                       OR !isset($data["name"])
+                       OR !isset($data["photo"])
+               ) {
+                       $data = self::pollHcard($profile_link, $data, true);
                }
 
                $prof_data = array();
-               $prof_data["addr"] = $data["addr"];
-               $prof_data["nick"] = $data["nick"];
+               $prof_data["addr"]         = $data["addr"];
+               $prof_data["nick"]         = $data["nick"];
                $prof_data["dfrn-request"] = $data["request"];
                $prof_data["dfrn-confirm"] = $data["confirm"];
-               $prof_data["dfrn-notify"] = $data["notify"];
-               $prof_data["dfrn-poll"] = $data["poll"];
-               $prof_data["dfrn-poco"] = $data["poco"];
-               $prof_data["photo"] = $data["photo"];
-               $prof_data["fn"] = $data["name"];
-               $prof_data["key"] = $data["pubkey"];
+               $prof_data["dfrn-notify"]  = $data["notify"];
+               $prof_data["dfrn-poll"]    = $data["poll"];
+               $prof_data["dfrn-poco"]    = $data["poco"];
+               $prof_data["photo"]        = $data["photo"];
+               $prof_data["fn"]           = $data["name"];
+               $prof_data["key"]          = $data["pubkey"];
 
-               logger("Result for profile ".$profile.": ".print_r($prof_data, true), LOGGER_DEBUG);
+               logger("Result for profile ".$profile_link.": ".print_r($prof_data, true), LOGGER_DEBUG);
 
                return $prof_data;
        }
@@ -727,7 +739,7 @@ class Probe {
         */
        private function dfrn($webfinger) {
 
-               $hcard = "";
+               $hcard_url = "";
                $data = array();
                foreach ($webfinger["links"] as $link) {
                        if (($link["rel"] == NAMESPACE_DFRN) AND ($link["href"] != "")) {
@@ -737,7 +749,7 @@ class Probe {
                        } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") AND ($link["type"] == "text/html") AND ($link["href"] != "")) {
                                $data["url"] = $link["href"];
                        } elseif (($link["rel"] == "http://microformats.org/profile/hcard") AND ($link["href"] != "")) {
-                               $hcard = $link["href"];
+                               $hcard_url = $link["href"];
                        } elseif (($link["rel"] == NAMESPACE_POCO) AND ($link["href"] != "")) {
                                $data["poco"] = $link["href"];
                        } elseif (($link["rel"] == "http://webfinger.net/rel/avatar") AND ($link["href"] != "")) {
@@ -756,20 +768,25 @@ class Probe {
                        }
                }
 
-               if (!isset($data["network"]) OR ($hcard == "")) {
+               if (!isset($data["network"]) OR ($hcard_url == "")) {
                        return false;
                }
 
                // Fetch data via noscrape - this is faster
-               $noscrape = str_replace("/hcard/", "/noscrape/", $hcard);
-               $data = self::pollNoscrape($noscrape, $data);
-
-               if (isset($data["notify"]) AND isset($data["confirm"]) AND isset($data["request"]) AND
-                       isset($data["poll"]) AND isset($data["name"]) AND isset($data["photo"])) {
+               $noscrape_url = str_replace("/hcard/", "/noscrape/", $hcard_url);
+               $data = self::pollNoscrape($noscrape_url, $data);
+
+               if (isset($data["notify"])
+                       AND isset($data["confirm"])
+                       AND isset($data["request"])
+                       AND isset($data["poll"])
+                       AND isset($data["name"])
+                       AND isset($data["photo"])
+               ) {
                        return $data;
                }
 
-               $data = self::pollHcard($hcard, $data, true);
+               $data = self::pollHcard($hcard_url, $data, true);
 
                return $data;
        }
@@ -777,14 +794,14 @@ class Probe {
        /**
         * @brief Poll the hcard page (Diaspora and Friendica specific)
         *
-        * @param string $hcard Link to the hcard page
+        * @param string $hcard_url Link to the hcard page
         * @param array $data The already fetched data
         * @param boolean $dfrn Poll DFRN specific data
         *
         * @return array hcard data
         */
-       private function pollHcard($hcard, $data, $dfrn = false) {
-               $ret = z_fetch_url($hcard);
+       private function pollHcard($hcard_url, $data, $dfrn = false) {
+               $ret = z_fetch_url($hcard_url);
                if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
                        return false;
                }
@@ -902,11 +919,11 @@ class Probe {
         */
        private function diaspora($webfinger) {
 
-               $hcard = "";
+               $hcard_url = "";
                $data = array();
                foreach ($webfinger["links"] as $link) {
                        if (($link["rel"] == "http://microformats.org/profile/hcard") AND ($link["href"] != "")) {
-                               $hcard = $link["href"];
+                               $hcard_url = $link["href"];
                        } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") AND ($link["href"] != "")) {
                                $data["baseurl"] = trim($link["href"], '/');
                        } elseif (($link["rel"] == "http://joindiaspora.com/guid") AND ($link["href"] != "")) {
@@ -929,7 +946,7 @@ class Probe {
                        }
                }
 
-               if (!isset($data["url"]) OR ($hcard == "")) {
+               if (!isset($data["url"]) OR ($hcard_url == "")) {
                        return false;
                }
 
@@ -942,14 +959,18 @@ class Probe {
                }
 
                // Fetch further information from the hcard
-               $data = self::pollHcard($hcard, $data);
+               $data = self::pollHcard($hcard_url, $data);
 
                if (!$data) {
                        return false;
                }
 
-               if (isset($data["url"]) AND isset($data["guid"]) AND isset($data["baseurl"]) AND
-                       isset($data["pubkey"]) AND ($hcard != "")) {
+               if (isset($data["url"])
+                       AND isset($data["guid"])
+                       AND isset($data["baseurl"])
+                       AND isset($data["pubkey"])
+                       AND ($hcard_url != "")
+               ) {
                        $data["network"] = NETWORK_DIASPORA;
 
                        // The Diaspora handle must always be lowercase
@@ -957,7 +978,7 @@ class Probe {
 
                        // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
                        $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"];
-                       $data["batch"] = $data["baseurl"] . "/receive/public";
+                       $data["batch"]  = $data["baseurl"] . "/receive/public";
                } else {
                        return false;
                }
@@ -987,8 +1008,10 @@ class Probe {
                }
                $pubkey = "";
                foreach ($webfinger["links"] as $link) {
-                       if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
-                               ($link["type"] == "text/html") AND ($link["href"] != "")) {
+                       if (($link["rel"] == "http://webfinger.net/rel/profile-page")
+                               AND ($link["type"] == "text/html")
+                               AND ($link["href"] != "")
+                       ) {
                                $data["url"] = $link["href"];
                        } elseif (($link["rel"] == "salmon") AND ($link["href"] != "")) {
                                $data["notify"] = $link["href"];
@@ -1021,8 +1044,10 @@ class Probe {
                        }
                }
 
-               if (isset($data["notify"]) AND isset($data["pubkey"]) AND
-                       isset($data["poll"]) AND isset($data["url"])) {
+               if (isset($data["notify"]) AND isset($data["pubkey"])
+                       AND isset($data["poll"])
+                       AND isset($data["url"])
+               ) {
                        $data["network"] = NETWORK_OSTATUS;
                } else {
                        return false;
@@ -1067,14 +1092,14 @@ class Probe {
        /**
         * @brief Fetch data from a pump.io profile page
         *
-        * @param string $profile Link to the profile page
+        * @param string $profile_link Link to the profile page
         *
         * @return array profile data
         */
-       private function pumpioProfileData($profile) {
+       private function pumpioProfileData($profile_link) {
 
                $doc = new \DOMDocument();
-               if (!@$doc->loadHTMLFile($profile)) {
+               if (!@$doc->loadHTMLFile($profile_link)) {
                        return false;
                }
 
@@ -1115,8 +1140,10 @@ class Probe {
 
                $data = array();
                foreach ($webfinger["links"] as $link) {
-                       if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
-                               ($link["type"] == "text/html") AND ($link["href"] != "")) {
+                       if (($link["rel"] == "http://webfinger.net/rel/profile-page")
+                               AND ($link["type"] == "text/html")
+                               AND ($link["href"] != "")
+                       ) {
                                $data["url"] = $link["href"];
                        } elseif (($link["rel"] == "activity-inbox") AND ($link["href"] != "")) {
                                $data["notify"] = $link["href"];
@@ -1126,8 +1153,10 @@ class Probe {
                                $data["dialback"] = $link["href"];
                        }
                }
-               if (isset($data["poll"]) AND isset($data["notify"]) AND
-                       isset($data["dialback"]) AND isset($data["url"])) {
+               if (isset($data["poll"]) AND isset($data["notify"])
+                       AND isset($data["dialback"])
+                       AND isset($data["url"])
+               ) {
                        // by now we use these fields only for the network type detection
                        // So we unset all data that isn't used at the moment
                        unset($data["dialback"]);
@@ -1285,18 +1314,17 @@ class Probe {
                        return false;
                }
 
-               $data = array();
+               $phost = substr($uri, strpos($uri, '@') + 1);
 
-               $data["addr"] = $uri;
+               $data = array();
+               $data["addr"]    = $uri;
                $data["network"] = NETWORK_MAIL;
-               $data["name"] = substr($uri, 0, strpos($uri, '@'));
-               $data["nick"] = $data["name"];
-               $data["photo"] = avatar_img($uri);
-
-               $phost = substr($uri, strpos($uri, '@') + 1);
-               $data["url"] = 'http://'.$phost."/".$data["nick"];
-               $data["notify"] = 'smtp '.random_string();
-               $data["poll"] = 'email '.random_string();
+               $data["name"]    = substr($uri, 0, strpos($uri, '@'));
+               $data["nick"]    = $data["name"];
+               $data["photo"]   = avatar_img($uri);
+               $data["url"]     = 'http://'.$phost."/".$data["nick"];
+               $data["notify"]  = 'smtp '.random_string();
+               $data["poll"]    = 'email '.random_string();
 
                $x = email_msg_meta($mbox, $msgs[0]);
                if (stristr($x[0]->from, $uri)) {
@@ -1308,8 +1336,8 @@ class Probe {
                        foreach ($adr as $feadr) {
                                if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)
                                        &&(strcasecmp($feadr->host, $phost) == 0)
-                                       && (strlen($feadr->personal))) {
-
+                                       && (strlen($feadr->personal))
+                               ) {
                                        $personal = imap_mime_header_decode($feadr->personal);
                                        $data["name"] = "";
                                        foreach ($personal as $perspart) {
@@ -1351,11 +1379,11 @@ class Probe {
                $parts = array_merge($base_parts, $avatar_parts);
 
                // And put them together again
-               $scheme   = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
-               $host     = isset($parts['host']) ? $parts['host'] : '';
-               $port     = isset($parts['port']) ? ':' . $parts['port'] : '';
-               $path     = isset($parts['path']) ? $parts['path'] : '';
-               $query    = isset($parts['query']) ? '?' . $parts['query'] : '';
+               $scheme   = isset($parts['scheme'])   ? $parts['scheme'] . '://' : '';
+               $host     = isset($parts['host'])     ? $parts['host']           : '';
+               $port     = isset($parts['port'])     ? ':' . $parts['port']     : '';
+               $path     = isset($parts['path'])     ? $parts['path']           : '';
+               $query    = isset($parts['query'])    ? '?' . $parts['query']    : '';
                $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
 
                $fixed = $scheme.$host.$port.$path.$query.$fragment;