Better detection for Hubzilla

This commit is contained in:
Michael 2017-03-02 21:20:33 +00:00
parent 324d8bfe8e
commit 9965061359

View File

@ -680,7 +680,13 @@ function poco_to_boolean($val) {
return ($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; $server = false;
$doc = new \DOMDocument(); $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) { if (!$server) {
return false; return false;
} }
@ -794,13 +821,22 @@ function poco_check_server($server_url, $network = "", $force = false) {
$last_contact = datetime_convert(); $last_contact = datetime_convert();
if (!$failure) { if (!$failure) {
// Test for Diaspora // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers
$serverret = z_fetch_url($server_url); $serverret = z_fetch_url($server_url);
if (!$serverret["success"] OR ($serverret["body"] == "")) { if (!$serverret["success"] OR ($serverret["body"] == "")) {
$last_failure = datetime_convert(); $last_failure = datetime_convert();
$failure = true; $failure = true;
} else { } 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"]); $lines = explode("\n",$serverret["header"]);
if(count($lines)) { if(count($lines)) {
foreach($lines as $line) { 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(); $last_contact = datetime_convert();
} }
// Test for Hubzilla, Redmatrix or Friendica
$serverret = z_fetch_url($server_url."/api/statusnet/config.json"); $serverret = z_fetch_url($server_url."/api/statusnet/config.json");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);