X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fsocgraph.php;h=7a39e388be8bba407ef3ba73fe11a39c1ea070ce;hb=34815de99c548b61c94b6e6939edd485eca728d6;hp=642d03d8911a6bf8b204f40ce9915bd092fbacbc;hpb=632d77cfb1ffce8aaddc0134ee232df29f267162;p=friendica.git diff --git a/include/socgraph.php b/include/socgraph.php index 642d03d891..7a39e388be 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1,18 +1,22 @@ loadHTML($body); - $xpath = new \DomXPath($doc); + $xpath = new DomXPath($doc); $list = $xpath->query("//meta[@name]"); @@ -1006,6 +1010,7 @@ function poco_check_server($server_url, $network = "", $force = false) { if (dbm::is_result($servers) AND ($orig_server_url == $server_url) AND ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) { logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); + dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url)); return false; } @@ -1020,6 +1025,7 @@ function poco_check_server($server_url, $network = "", $force = false) { // Quit if there is a timeout if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); + dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url)); return false; } @@ -1029,12 +1035,10 @@ function poco_check_server($server_url, $network = "", $force = false) { if (!$serverret["success"] OR ($serverret["body"] == "") OR (sizeof($xmlobj) == 0) OR !is_object($xmlobj)) { // Workaround for bad configured servers (known nginx problem) if (!in_array($serverret["debug"]["http_code"], array("403", "404"))) { - $last_failure = datetime_convert(); $failure = true; } $possible_failure = true; - } elseif ($network == NETWORK_DIASPORA) - $last_contact = datetime_convert(); + } // If the server has no possible failure we reset the cached data if (!$possible_failure) { @@ -1052,8 +1056,6 @@ function poco_check_server($server_url, $network = "", $force = false) { $data = json_decode($serverret["body"]); if (isset($data->totalResults)) { $poco = $server_url."/poco"; - $last_contact = datetime_convert(); - $server = poco_detect_poco_data($data); if ($server) { $platform = $server['platform']; @@ -1070,7 +1072,6 @@ function poco_check_server($server_url, $network = "", $force = false) { $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"]); @@ -1079,7 +1080,6 @@ function poco_check_server($server_url, $network = "", $force = false) { $network = $server['network']; $version = $server['version']; $site_name = $server['site_name']; - $last_contact = datetime_convert(); } $lines = explode("\n",$serverret["header"]); @@ -1093,15 +1093,11 @@ function poco_check_server($server_url, $network = "", $force = false) { $network = NETWORK_DIASPORA; $versionparts = explode("-", $version); $version = $versionparts[0]; - $last_contact = datetime_convert(); } if(stristr($line,'Server: Mastodon')) { $platform = "Mastodon"; $network = NETWORK_OSTATUS; - // Mastodon doesn't reveal version numbers - $version = ""; - $last_contact = datetime_convert(); } } } @@ -1120,7 +1116,6 @@ function poco_check_server($server_url, $network = "", $force = false) { $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]); $version = trim($version, '"'); $network = NETWORK_OSTATUS; - $last_contact = datetime_convert(); } // Test for GNU Social @@ -1132,7 +1127,19 @@ function poco_check_server($server_url, $network = "", $force = false) { $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]); $version = trim($version, '"'); $network = NETWORK_OSTATUS; - $last_contact = datetime_convert(); + } + + // Test for Mastodon + $serverret = z_fetch_url($server_url."/api/v1/instance"); + if ($serverret["success"] AND ($serverret["body"] != '')) { + $data = json_decode($serverret["body"]); + if (isset($data->version)) { + $platform = "Mastodon"; + $version = $data->version; + $site_name = $data->title; + $info = $data->description; + $network = NETWORK_OSTATUS; + } } } @@ -1142,8 +1149,6 @@ function poco_check_server($server_url, $network = "", $force = false) { if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->site->server)) { - $last_contact = datetime_convert(); - if (isset($data->site->platform)) { $platform = $data->site->platform->PLATFORM_NAME; $version = $data->site->platform->STD_VERSION; @@ -1190,7 +1195,6 @@ function poco_check_server($server_url, $network = "", $force = false) { } } - // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix if (!$failure) { $serverret = z_fetch_url($server_url."/statistics.json"); @@ -1218,9 +1222,6 @@ function poco_check_server($server_url, $network = "", $force = false) { } else { $register_policy = REGISTER_CLOSED; } - - if (isset($data->version)) - $last_contact = datetime_convert(); } } @@ -1245,8 +1246,6 @@ function poco_check_server($server_url, $network = "", $force = false) { if (isset($server['site_name'])) { $site_name = $server['site_name']; } - - $last_contact = datetime_convert(); } } @@ -1262,7 +1261,6 @@ function poco_check_server($server_url, $network = "", $force = false) { $data = json_decode($serverret["body"]); if (isset($data->version)) { - $last_contact = datetime_convert(); $network = NETWORK_DFRN; $noscrape = $data->no_scrape_url; @@ -1288,13 +1286,14 @@ function poco_check_server($server_url, $network = "", $force = false) { } if ($possible_failure AND !$failure) { - $last_failure = datetime_convert(); $failure = true; } if ($failure) { $last_contact = $orig_last_contact; + $last_failure = datetime_convert(); } else { + $last_contact = datetime_convert(); $last_failure = $orig_last_failure; } @@ -1428,7 +1427,7 @@ function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = fal $r = q("SELECT `gcontact`.* FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`zcid` = %d - and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) + and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) $sql_extra limit %d, %d", intval($zcid), intval($uid), @@ -1656,6 +1655,20 @@ function poco_discover_federation() { } } + // Disvover Mastodon servers + if (!Config::get('system','ostatus_disabled')) { + $serverdata = fetch_url("https://instances.mastodon.xyz/instances.json"); + + if ($serverdata) { + $servers = json_decode($serverdata); + + foreach ($servers AS $server) { + $url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name; + proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($url)); + } + } + } + // Currently disabled, since the service isn't available anymore. // It is not removed since I hope that there will be a successor. // Discover GNU Social Servers. @@ -1982,10 +1995,11 @@ function get_gcontact_id($contact) { if (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) $contact["url"] = clean_contact_url($contact["url"]); - $r = q("SELECT `id`, `last_contact`, `last_failure`, `network` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 2", + dba::lock('gcontact'); + $r = q("SELECT `id`, `last_contact`, `last_failure`, `network` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($contact["url"]))); - if ($r) { + if (dbm::is_result($r)) { $gcontact_id = $r[0]["id"]; // Update every 90 days @@ -2023,17 +2037,13 @@ function get_gcontact_id($contact) { $doprobing = in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")); } } + dba::unlock(); if ($doprobing) { logger("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], LOGGER_DEBUG); proc_run(PRIORITY_LOW, 'include/gprobe.php', bin2hex($contact["url"])); } - if ((dbm::is_result($r)) AND (count($r) > 1) AND ($gcontact_id > 0) AND ($contact["url"] != "")) - q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d", - dbesc(normalise_link($contact["url"])), - intval($gcontact_id)); - return $gcontact_id; } @@ -2096,7 +2106,7 @@ function update_gcontact($contact) { fix_alternate_contact_address($contact); if (!isset($contact["updated"])) - $contact["updated"] = datetime_convert(); + $contact["updated"] = dbm::date(); if ($contact["server_url"] == "") { $server_url = $contact["url"]; @@ -2151,7 +2161,7 @@ function update_gcontact($contact) { dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]), intval($contact["nsfw"]), intval($contact["contact-type"]), dbesc($contact["alias"]), dbesc($contact["notify"]), dbesc($contact["url"]), dbesc($contact["location"]), - dbesc($contact["about"]), intval($contact["generation"]), dbesc($contact["updated"]), + dbesc($contact["about"]), intval($contact["generation"]), dbesc(dbm::date($contact["updated"])), dbesc($contact["server_url"]), dbesc($contact["connect"]), dbesc(normalise_link($contact["url"])), intval($contact["generation"])); @@ -2329,4 +2339,3 @@ function poco_serverlist() { } return $r; } -?>