From 99650613591cdf7da5ecd683c1590d17d0f27fca Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Mar 2017 21:20:33 +0000 Subject: [PATCH] Better detection for Hubzilla --- include/socgraph.php | 50 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 6968704bf2..407a3074da 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -680,7 +680,13 @@ function poco_to_boolean($val) { return ($val); } -function poco_detect_friendica_server($body) { +/** + * @brief Detect server type (Hubzilla or Friendica) via the front page body + * + * @param string $body Front page of the server + * @return array Server data + */ +function poco_detect_server_type($body) { $server = false; $doc = new \DOMDocument(); @@ -709,6 +715,27 @@ function poco_detect_friendica_server($body) { } } + if (!$server) { + $list = $xpath->query("//meta[@property]"); + + foreach ($list as $node) { + $attr = array(); + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { + $attr[$attribute->name] = $attribute->value; + } + } + if ($attr['property'] == 'generator') { + if (in_array($attr['content'], array("hubzilla"))) { + $server = array(); + $server["platform"] = $attr['content']; + $server["version"] = ""; + $server["network"] = NETWORK_DIASPORA; + } + } + } + } + if (!$server) { return false; } @@ -794,13 +821,22 @@ function poco_check_server($server_url, $network = "", $force = false) { $last_contact = datetime_convert(); if (!$failure) { - // Test for Diaspora + // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers $serverret = z_fetch_url($server_url); if (!$serverret["success"] OR ($serverret["body"] == "")) { $last_failure = datetime_convert(); $failure = true; } else { + $server = poco_detect_server_type($serverret["body"]); + if ($server) { + $platform = $server['platform']; + $network = $server['network']; + $version = $server['version']; + $site_name = $server['site_name']; + $last_contact = datetime_convert(); + } + $lines = explode("\n",$serverret["header"]); if(count($lines)) { foreach($lines as $line) { @@ -824,15 +860,6 @@ function poco_check_server($server_url, $network = "", $force = false) { } } } - - $friendica_server = poco_detect_friendica_server($serverret["body"]); - if ($friendica_server) { - $platform = $friendica_server['platform']; - $network = $friendica_server['network']; - $version = $friendica_server['version']; - $site_name = $friendica_server['site_name']; - $last_contact = datetime_convert(); - } } } @@ -859,6 +886,7 @@ function poco_check_server($server_url, $network = "", $force = false) { $last_contact = datetime_convert(); } + // Test for Hubzilla, Redmatrix or Friendica $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]);