reduce the number of network fetches for server detection of hubzilla/red systems from around 10 to maybe 5. Kind of wasteful to get hit on 10 non-existent endpoints every couple of minutes.

This commit is contained in:
zotlabs 2017-07-19 17:56:40 -07:00
parent 6f661d50dc
commit a583bda5fc

View file

@ -1160,53 +1160,77 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (!$failure) { if (!$failure) {
// Test for Hubzilla, Redmatrix or Friendica // Test for Hubzilla, Redmatrix or Friendica
$serverret = z_fetch_url($server_url."/api/statusnet/config.json"); $serverret = z_fetch_url($server_url."/siteinfo.json");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->site->server)) { if(isset($data->url)) {
if (isset($data->site->platform)) { $platform = $data->platform;
$platform = $data->site->platform->PLATFORM_NAME; $version = $data->version;
$version = $data->site->platform->STD_VERSION; $network = NETWORK_DIASPORA;
$network = NETWORK_DIASPORA; }
} $site_name = $data->site_name;
if (isset($data->site->BlaBlaNet)) { switch ($data->register_policy) {
$platform = $data->site->BlaBlaNet->PLATFORM_NAME; case "REGISTER_OPEN":
$version = $data->site->BlaBlaNet->STD_VERSION; $register_policy = REGISTER_OPEN;
$network = NETWORK_DIASPORA; break;
} case "REGISTER_APPROVE":
if (isset($data->site->hubzilla)) { $register_policy = REGISTER_APPROVE;
$platform = $data->site->hubzilla->PLATFORM_NAME; break;
$version = $data->site->hubzilla->RED_VERSION; case "REGISTER_CLOSED":
$network = NETWORK_DIASPORA; default:
} $register_policy = REGISTER_CLOSED;
if (isset($data->site->redmatrix)) { break;
if (isset($data->site->redmatrix->PLATFORM_NAME)) { }
$platform = $data->site->redmatrix->PLATFORM_NAME; }
} elseif (isset($data->site->redmatrix->RED_PLATFORM)) { else {
$platform = $data->site->redmatrix->RED_PLATFORM; $serverret = z_fetch_url($server_url."/api/statusnet/config.json");
if ($serverret["success"]) {
$data = json_decode($serverret["body"]);
if (isset($data->site->server)) {
if (isset($data->site->platform)) {
$platform = $data->site->platform->PLATFORM_NAME;
$version = $data->site->platform->STD_VERSION;
$network = NETWORK_DIASPORA;
}
if (isset($data->site->BlaBlaNet)) {
$platform = $data->site->BlaBlaNet->PLATFORM_NAME;
$version = $data->site->BlaBlaNet->STD_VERSION;
$network = NETWORK_DIASPORA;
}
if (isset($data->site->hubzilla)) {
$platform = $data->site->hubzilla->PLATFORM_NAME;
$version = $data->site->hubzilla->RED_VERSION;
$network = NETWORK_DIASPORA;
}
if (isset($data->site->redmatrix)) {
if (isset($data->site->redmatrix->PLATFORM_NAME)) {
$platform = $data->site->redmatrix->PLATFORM_NAME;
} elseif (isset($data->site->redmatrix->RED_PLATFORM)) {
$platform = $data->site->redmatrix->RED_PLATFORM;
}
$version = $data->site->redmatrix->RED_VERSION;
$network = NETWORK_DIASPORA;
}
if (isset($data->site->friendica)) {
$platform = $data->site->friendica->FRIENDICA_PLATFORM;
$version = $data->site->friendica->FRIENDICA_VERSION;
$network = NETWORK_DFRN;
} }
$version = $data->site->redmatrix->RED_VERSION; $site_name = $data->site->name;
$network = NETWORK_DIASPORA;
}
if (isset($data->site->friendica)) {
$platform = $data->site->friendica->FRIENDICA_PLATFORM;
$version = $data->site->friendica->FRIENDICA_VERSION;
$network = NETWORK_DFRN;
}
$site_name = $data->site->name; $data->site->closed = poco_to_boolean($data->site->closed);
$data->site->private = poco_to_boolean($data->site->private);
$data->site->inviteonly = poco_to_boolean($data->site->inviteonly);
$data->site->closed = poco_to_boolean($data->site->closed); if (!$data->site->closed && !$data->site->private and $data->site->inviteonly) {
$data->site->private = poco_to_boolean($data->site->private); $register_policy = REGISTER_APPROVE;
$data->site->inviteonly = poco_to_boolean($data->site->inviteonly); } elseif (!$data->site->closed && !$data->site->private) {
$register_policy = REGISTER_OPEN;
if (!$data->site->closed && !$data->site->private and $data->site->inviteonly) { } else {
$register_policy = REGISTER_APPROVE; $register_policy = REGISTER_CLOSED;
} elseif (!$data->site->closed && !$data->site->private) { }
$register_policy = REGISTER_OPEN;
} else {
$register_policy = REGISTER_CLOSED;
} }
} }
} }