]> git.mxchange.org Git - friendica.git/commitdiff
Querying via nodeinfo
authorMichael <heluecht@pirati.ca>
Mon, 13 Mar 2017 00:03:27 +0000 (00:03 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 13 Mar 2017 00:03:27 +0000 (00:03 +0000)
include/socgraph.php

index dee3bfc198ff14c48c0dd2d0f816e427b6a83c95..e3e5773b7f954bf208787f47e3dc6c6db73cfccc 100644 (file)
@@ -763,6 +763,110 @@ function poco_detect_poco_data($data) {
        return false;
 }
 
+/**
+ * @brief Detect server type by using the nodeinfo data
+ *
+ * @param string $server_url address of the server
+ * @return array Server data
+ */
+function poco_fetch_nodeinfo($server_url) {
+       $serverret = z_fetch_url($server_url."/.well-known/nodeinfo");
+       if (!$serverret["success"]) {
+               return false;
+       }
+
+       $nodeinfo = json_decode($serverret['body']);
+
+       if (!is_object($nodeinfo)) {
+               return false;
+       }
+
+       if (!is_array($nodeinfo->links)) {
+               return false;
+       }
+
+       $nodeinfo_url = '';
+
+       foreach ($nodeinfo->links AS $link) {
+               if ($link->rel == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
+                       $nodeinfo_url = $link->href;
+               }
+       }
+
+       if ($nodeinfo_url == '') {
+               return false;
+       }
+
+       $serverret = z_fetch_url($nodeinfo_url);
+       if (!$serverret["success"]) {
+               return false;
+       }
+
+       $nodeinfo = json_decode($serverret['body']);
+
+       if (!is_object($nodeinfo)) {
+               return false;
+       }
+
+       $server = array();
+
+       $server['register_policy'] = REGISTER_CLOSED;
+
+       if (is_bool($nodeinfo->openRegistrations) AND $nodeinfo->openRegistrations) {
+               $server['register_policy'] = REGISTER_OPEN;
+       }
+
+       if (is_object($nodeinfo->software)) {
+               if (isset($nodeinfo->software->name)) {
+                       $server['platform'] = $nodeinfo->software->name;
+               }
+
+               if (isset($nodeinfo->software->version)) {
+                       $server['version'] = $nodeinfo->software->version;
+               }
+       }
+
+       if (is_object($nodeinfo->metadata)) {
+               if (isset($nodeinfo->metadata->nodeName)) {
+                       $server['site_name'] = $nodeinfo->metadata->nodeName;
+               }
+       }
+
+       $diaspora = false;
+       $friendica = false;
+       $gnusocial = false;
+
+       if (is_array($nodeinfo->protocols->inbound)) {
+               foreach ($nodeinfo->protocols->inbound AS $inbound) {
+                       if ($inbound == 'diaspora') {
+                               $diaspora = true;
+                       }
+                       if ($inbound == 'friendica') {
+                               $friendica = true;
+                       }
+                       if ($inbound == 'gnusocial') {
+                               $gnusocial = true;
+                       }
+               }
+       }
+
+       if ($gnusocial) {
+               $server['network'] = NETWORK_OSTATUS;
+       }
+       if ($diaspora) {
+               $server['network'] = NETWORK_DIASPORA;
+       }
+       if ($friendica) {
+               $server['network'] = NETWORK_DFRN;
+       }
+
+       if (!$server) {
+               return false;
+       }
+
+       return $server;
+}
+
 /**
  * @brief Detect server type (Hubzilla or Friendica) via the front page body
  *
@@ -1103,6 +1207,24 @@ function poco_check_server($server_url, $network = "", $force = false) {
                }
        }
 
+       // Query nodeinfo. Working for (at least) Diaspora and Friendica.
+       if (!$failure) {
+               $server = poco_fetch_nodeinfo($server_url);
+               if ($server) {
+                       $register_policy = $server['register_policy'];
+                       $platform = $server['platform'];
+                       $network = $server['network'];
+
+                       if ($version == "") {
+                               $version = $server['version'];
+                       }
+
+                       $site_name = $server['site_name'];
+
+                       $last_contact = datetime_convert();
+               }
+       }
+
        // Check for noscrape
        // Friendica servers could be detected as OStatus servers
        if (!$failure AND in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS))) {