use Exception;
use Friendica\Content\Text\HTML;
use Friendica\Core\Config;
+use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\GContact;
$url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation') ;
- logger('load: ' . $url, LOGGER_DEBUG);
+ Logger::log('load: ' . $url, LOGGER_DEBUG);
- $s = Network::fetchUrl($url);
+ $fetchresult = Network::fetchUrlFull($url);
+ $s = $fetchresult->getBody();
- logger('load: returns ' . $s, LOGGER_DATA);
+ Logger::log('load: returns ' . $s, LOGGER_DATA);
- logger('load: return code: ' . $a->get_curl_code(), LOGGER_DEBUG);
+ Logger::log('load: return code: ' . $fetchresult->getReturnCode(), LOGGER_DEBUG);
- if (($a->get_curl_code() > 299) || (! $s)) {
+ if (($fetchresult->getReturnCode() > 299) || (! $s)) {
return;
}
$j = json_decode($s, true);
- logger('load: json: ' . print_r($j, true), LOGGER_DATA);
+ Logger::log('load: json: ' . print_r($j, true), LOGGER_DATA);
if (!isset($j['entry'])) {
return;
$connect_url = '';
$name = '';
$network = '';
- $updated = NULL_DATE;
+ $updated = DBA::NULL_DATETIME;
$location = '';
$about = '';
$keywords = '';
GContact::link($gcid, $uid, $cid, $zcid);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), LOGGER_DEBUG);
}
}
- logger("load: loaded $total entries", LOGGER_DEBUG);
+ Logger::log("load: loaded $total entries", LOGGER_DEBUG);
$condition = ["`cid` = ? AND `uid` = ? AND `zcid` = ? AND `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY", $cid, $uid, $zcid];
DBA::delete('glink', $condition);
$friendica = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $profile);
if ($friendica != $profile) {
$server_url = $friendica;
- $network = NETWORK_DFRN;
+ $network = Protocol::DFRN;
}
}
$diaspora = preg_replace("=(https?://)(.*)/u/(.*)=ism", "$1$2", $profile);
if ($diaspora != $profile) {
$server_url = $diaspora;
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
}
$red = preg_replace("=(https?://)(.*)/channel/(.*)=ism", "$1$2", $profile);
if ($red != $profile) {
$server_url = $red;
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
}
$mastodon = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile);
if ($mastodon != $profile) {
$server_url = $mastodon;
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
}
$ostatus = preg_replace("=(https?://)(.*)/user/(.*)=ism", "$1$2", $profile);
if ($ostatus != $profile) {
$server_url = $ostatus;
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
}
$base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile);
if ($base != $profile) {
$server_url = $base;
- $network = NETWORK_PHANTOM;
+ $network = Protocol::PHANTOM;
}
}
}
// Fetch the host-meta to check if this really is a server
- $serverret = Network::curl($server_url."/.well-known/host-meta");
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($server_url."/.well-known/host-meta");
+ if (!$curlResult->isSuccess()) {
return "";
}
$contact = ["url" => $profile];
- if ($gcontacts[0]["created"] <= NULL_DATE) {
+ if ($gcontacts[0]["created"] <= DBA::NULL_DATETIME) {
$contact['created'] = DateTimeFormat::utcNow();
}
$server_url = normalise_link(self::detectServer($profile));
}
- if (!in_array($gcontacts[0]["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_FEED, NETWORK_OSTATUS, ""])) {
- logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
+ if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
+ Logger::log("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
return false;
}
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
}
- logger("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
return false;
}
$contact['server_url'] = $server_url;
}
- if (in_array($gcontacts[0]["network"], ["", NETWORK_FEED])) {
+ if (in_array($gcontacts[0]["network"], ["", Protocol::FEED])) {
$server = q(
"SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
DBA::escape(normalise_link($server_url))
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", DBA::escape(normalise_link($server_url)));
if ($server) {
- $noscraperet = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
+ $curlResult = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
- if ($noscraperet["success"] && ($noscraperet["body"] != "")) {
- $noscrape = json_decode($noscraperet["body"], true);
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != "")) {
+ $noscrape = json_decode($curlResult->getBody(), true);
if (is_array($noscrape)) {
$contact["network"] = $server[0]["network"];
$fields = ['last_contact' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
- logger("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
return $noscrape["updated"];
}
// If we only can poll the feed, then we only do this once a while
if (!$force && !self::updateNeeded($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
- logger("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
GContact::update($contact);
return $gcontacts[0]["updated"];
// Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
// Then check the other link and delete this one
- if (($data["network"] == NETWORK_OSTATUS) && self::alternateOStatusUrl($profile)
+ if (($data["network"] == Protocol::OSTATUS) && self::alternateOStatusUrl($profile)
&& (normalise_link($profile) == normalise_link($data["alias"]))
&& (normalise_link($profile) != normalise_link($data["url"]))
) {
self::lastUpdated($data["url"], $force);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), LOGGER_DEBUG);
}
- logger("Profile ".$profile." was deleted", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was deleted", LOGGER_DEBUG);
return false;
}
- if (($data["poll"] == "") || (in_array($data["network"], [NETWORK_FEED, NETWORK_PHANTOM]))) {
+ if (($data["poll"] == "") || (in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM]))) {
$fields = ['last_failure' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
- logger("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
return false;
}
GContact::update($contact);
- $feedret = Network::curl($data["poll"]);
+ $curlResult = Network::curl($data["poll"]);
- if (!$feedret["success"]) {
+ if (!$curlResult->isSuccess()) {
$fields = ['last_failure' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
- logger("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
return false;
}
$doc = new DOMDocument();
/// @TODO Avoid error supression here
- @$doc->loadXML($feedret["body"]);
+ @$doc->loadXML($curlResult->getBody());
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
// Maybe there aren't any entries. Then check if it is a valid feed
if ($last_updated == "") {
if ($xpath->query('/atom:feed')->length > 0) {
- $last_updated = NULL_DATE;
+ $last_updated = DBA::NULL_DATETIME;
}
}
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
}
- logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
return $last_updated;
}
if ($url['type'] == 'zot') {
$server = [];
$server["platform"] = 'Hubzilla';
- $server["network"] = NETWORK_DIASPORA;
+ $server["network"] = Protocol::DIASPORA;
return $server;
}
}
*/
private static function fetchNodeinfo($server_url)
{
- $serverret = Network::curl($server_url."/.well-known/nodeinfo");
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($server_url."/.well-known/nodeinfo");
+ if (!$curlResult->isSuccess()) {
return false;
}
- $nodeinfo = json_decode($serverret['body'], true);
+ $nodeinfo = json_decode($curlResult->getBody(), true);
if (!is_array($nodeinfo) || !isset($nodeinfo['links'])) {
return false;
$nodeinfo2_url = '';
foreach ($nodeinfo['links'] as $link) {
+ if (!is_array($link) || empty($link['rel'])) {
+ Logger::log('Invalid nodeinfo format for ' . $server_url, LOGGER_DEBUG);
+ continue;
+ }
if ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
$nodeinfo1_url = $link['href'];
} elseif ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0') {
*/
private static function parseNodeinfo1($nodeinfo_url)
{
- $serverret = Network::curl($nodeinfo_url);
+ $curlResult = Network::curl($nodeinfo_url);
- if (!$serverret["success"]) {
+ if (!$curlResult->isSuccess()) {
return false;
}
- $nodeinfo = json_decode($serverret['body'], true);
+ $nodeinfo = json_decode($curlResult->getBody(), true);
if (!is_array($nodeinfo)) {
return false;
}
if ($gnusocial) {
- $server['network'] = NETWORK_OSTATUS;
+ $server['network'] = Protocol::OSTATUS;
}
if ($diaspora) {
- $server['network'] = NETWORK_DIASPORA;
+ $server['network'] = Protocol::DIASPORA;
}
if ($friendica) {
- $server['network'] = NETWORK_DFRN;
+ $server['network'] = Protocol::DFRN;
}
if (!$server) {
*/
private static function parseNodeinfo2($nodeinfo_url)
{
- $serverret = Network::curl($nodeinfo_url);
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($nodeinfo_url);
+ if (!$curlResult->isSuccess()) {
return false;
}
- $nodeinfo = json_decode($serverret['body'], true);
+ $nodeinfo = json_decode($curlResult->getBody(), true);
if (!is_array($nodeinfo)) {
return false;
}
if ($gnusocial) {
- $server['network'] = NETWORK_OSTATUS;
+ $server['network'] = Protocol::OSTATUS;
} elseif ($diaspora) {
- $server['network'] = NETWORK_DIASPORA;
+ $server['network'] = Protocol::DIASPORA;
} elseif ($friendica) {
- $server['network'] = NETWORK_DFRN;
+ $server['network'] = Protocol::DFRN;
}
if (empty($server)) {
$server = [];
$server["platform"] = $version_part[0];
$server["version"] = $version_part[1];
- $server["network"] = NETWORK_DFRN;
+ $server["network"] = Protocol::DFRN;
}
}
}
$server = [];
$server["platform"] = $attr['content'];
$server["version"] = "";
- $server["network"] = NETWORK_DIASPORA;
+ $server["network"] = Protocol::DIASPORA;
}
}
}
$gserver = DBA::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
if (DBA::isResult($gserver)) {
- if ($gserver["created"] <= NULL_DATE) {
+ if ($gserver["created"] <= DBA::NULL_DATETIME) {
$fields = ['created' => DateTimeFormat::utcNow()];
$condition = ['nurl' => normalise_link($server_url)];
DBA::update('gserver', $fields, $condition);
// See discussion under https://forum.friendi.ca/display/0b6b25a8135aabc37a5a0f5684081633
// It can happen that a zero date is in the database, but storing it again is forbidden.
- if ($last_contact < NULL_DATE) {
- $last_contact = NULL_DATE;
+ if ($last_contact < DBA::NULL_DATETIME) {
+ $last_contact = DBA::NULL_DATETIME;
}
- if ($last_failure < NULL_DATE) {
- $last_failure = NULL_DATE;
+ if ($last_failure < DBA::NULL_DATETIME) {
+ $last_failure = DBA::NULL_DATETIME;
}
if (!$force && !self::updateNeeded($gserver["created"], "", $last_failure, $last_contact)) {
- logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
+ Logger::log("Use cached data for server ".$server_url, LOGGER_DEBUG);
return ($last_contact >= $last_failure);
}
} else {
$register_policy = -1;
$registered_users = 0;
- $last_contact = NULL_DATE;
- $last_failure = NULL_DATE;
+ $last_contact = DBA::NULL_DATETIME;
+ $last_failure = DBA::NULL_DATETIME;
}
- logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
$failure = false;
$possible_failure = false;
$server_url = str_replace("http://", "https://", $server_url);
// We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
- $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+ $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
// Quit if there is a timeout.
// But we want to make sure to only quit if we are mostly sure that this server url fits.
if (DBA::isResult($gserver) && ($orig_server_url == $server_url) &&
- (!empty($serverret["errno"]) && ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT))) {
- logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
+ ($curlResult->isTimeout())) {
+ Logger::log("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
return false;
}
// Maybe the page is unencrypted only?
- $xmlobj = @simplexml_load_string($serverret["body"], 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
- if (!$serverret["success"] || ($serverret["body"] == "") || empty($xmlobj) || !is_object($xmlobj)) {
+ $xmlobj = @simplexml_load_string($curlResult->getBody(), 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == "") || empty($xmlobj) || !is_object($xmlobj)) {
$server_url = str_replace("https://", "http://", $server_url);
// We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
- $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+ $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
// Quit if there is a timeout
- if (!empty($serverret["errno"]) && ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
- logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
+ if ($curlResult->isTimeout()) {
+ Logger::log("Connection to server " . $server_url . " timed out.", LOGGER_DEBUG);
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
return false;
}
- $xmlobj = @simplexml_load_string($serverret["body"], 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
+ $xmlobj = @simplexml_load_string($curlResult->getBody(), 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
}
- if (!$serverret["success"] || ($serverret["body"] == "") || empty($xmlobj) || !is_object($xmlobj)) {
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == "") || empty($xmlobj) || !is_object($xmlobj)) {
// Workaround for bad configured servers (known nginx problem)
- if (!empty($serverret["debug"]) && !in_array($serverret["debug"]["http_code"], ["403", "404"])) {
+ if (!empty($curlResult->getInfo()) && !in_array($curlResult->getInfo()["http_code"], ["403", "404"])) {
$failure = true;
}
// Look for poco
if (!$failure) {
- $serverret = Network::curl($server_url."/poco");
+ $curlResult = Network::curl($server_url."/poco");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"], true);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
if (isset($data['totalResults'])) {
$registered_users = $data['totalResults'];
if (!$failure) {
// Test for Diaspora, Hubzilla, Mastodon or older Friendica servers
- $serverret = Network::curl($server_url);
+ $curlResult = Network::curl($server_url);
- if (!$serverret["success"] || ($serverret["body"] == "")) {
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == "")) {
$failure = true;
} else {
- $server = self::detectServerType($serverret["body"]);
+ $server = self::detectServerType($curlResult->getBody());
if (!empty($server)) {
$platform = $server['platform'];
$site_name = $server['site_name'];
}
- $lines = explode("\n", $serverret["header"]);
+ $lines = explode("\n", $curlResult->getHeader());
if (count($lines)) {
foreach ($lines as $line) {
$platform = "Diaspora";
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
$version = trim(str_replace("x-diaspora-version:", "", $version));
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
$versionparts = explode("-", $version);
$version = $versionparts[0];
}
if (stristr($line, 'Server: Mastodon')) {
$platform = "Mastodon";
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
}
}
// Test for Statusnet
// Will also return data for Friendica and GNU Social - but it will be overwritten later
// The "not implemented" is a special treatment for really, really old Friendica versions
- $serverret = Network::curl($server_url."/api/statusnet/version.json");
+ $curlResult = Network::curl($server_url."/api/statusnet/version.json");
- if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') &&
- ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) {
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
+ ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$platform = "StatusNet";
// Remove junk that some GNU Social servers return
- $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
+ $version = str_replace(chr(239).chr(187).chr(191), "", $curlResult->getBody());
$version = trim($version, '"');
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
// Test for GNU Social
- $serverret = Network::curl($server_url."/api/gnusocial/version.json");
+ $curlResult = Network::curl($server_url."/api/gnusocial/version.json");
- if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') &&
- ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) {
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
+ ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$platform = "GNU Social";
// Remove junk that some GNU Social servers return
- $version = str_replace(chr(239) . chr(187) . chr(191), "", $serverret["body"]);
+ $version = str_replace(chr(239) . chr(187) . chr(191), "", $curlResult->getBody());
$version = trim($version, '"');
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
// Test for Mastodon
$orig_version = $version;
- $serverret = Network::curl($server_url . "/api/v1/instance");
+ $curlResult = Network::curl($server_url . "/api/v1/instance");
- if ($serverret["success"] && ($serverret["body"] != '')) {
- $data = json_decode($serverret["body"], true);
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != '')) {
+ $data = json_decode($curlResult->getBody(), true);
if (isset($data['version'])) {
$platform = "Mastodon";
- $version = $data['version'];
- $site_name = $data['title'];
- $info = $data['description'];
- $network = NETWORK_OSTATUS;
+ $version = defaults($data, 'version', '');
+ $site_name = defaults($data, 'title', '');
+ $info = defaults($data, 'description', '');
+ $network = Protocol::OSTATUS;
}
if (!empty($data['stats']['user_count'])) {
if (!$failure) {
// Test for Hubzilla and Red
- $serverret = Network::curl($server_url . "/siteinfo.json");
+ $curlResult = Network::curl($server_url . "/siteinfo.json");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"], true);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
if (isset($data['url'])) {
$platform = $data['platform'];
$version = $data['version'];
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
if (!empty($data['site_name'])) {
}
} else {
// Test for Hubzilla, Redmatrix or Friendica
- $serverret = Network::curl($server_url."/api/statusnet/config.json");
+ $curlResult = Network::curl($server_url."/api/statusnet/config.json");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"], true);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
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;
+ $network = Protocol::DIASPORA;
}
if (isset($data['site']['BlaBlaNet'])) {
$platform = $data['site']['BlaBlaNet']['PLATFORM_NAME'];
$version = $data['site']['BlaBlaNet']['STD_VERSION'];
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
if (isset($data['site']['hubzilla'])) {
$platform = $data['site']['hubzilla']['PLATFORM_NAME'];
$version = $data['site']['hubzilla']['RED_VERSION'];
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
if (isset($data['site']['redmatrix'])) {
}
$version = $data['site']['redmatrix']['RED_VERSION'];
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
if (isset($data['site']['friendica'])) {
$platform = $data['site']['friendica']['FRIENDICA_PLATFORM'];
$version = $data['site']['friendica']['FRIENDICA_VERSION'];
- $network = NETWORK_DFRN;
+ $network = Protocol::DFRN;
}
$site_name = $data['site']['name'];
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) {
- $serverret = Network::curl($server_url . "/statistics.json");
+ $curlResult = Network::curl($server_url . "/statistics.json");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"], true);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
if (isset($data['version'])) {
$version = $data['version'];
}
if ($platform == "Diaspora") {
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
if (!empty($data['registrations_open']) && $data['registrations_open']) {
// Check for noscrape
// Friendica servers could be detected as OStatus servers
- if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) {
- $serverret = Network::curl($server_url . "/friendica/json");
+ if (!$failure && in_array($network, [Protocol::DFRN, Protocol::OSTATUS])) {
+ $curlResult = Network::curl($server_url . "/friendica/json");
- if (!$serverret["success"]) {
- $serverret = Network::curl($server_url . "/friendika/json");
+ if (!$curlResult->isSuccess()) {
+ $curlResult = Network::curl($server_url . "/friendika/json");
}
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"], true);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
if (isset($data['version'])) {
- $network = NETWORK_DFRN;
+ $network = Protocol::DFRN;
if (!empty($data['no_scrape_url'])) {
$noscrape = $data['no_scrape_url'];
}
if (($last_contact <= $last_failure) && !$failure) {
- logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
} elseif (($last_contact >= $last_failure) && $failure) {
- logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
}
// Check again if the server exists
DBA::insert('gserver', $fields);
}
- if (!$failure && in_array($fields['network'], [NETWORK_DFRN, NETWORK_DIASPORA])) {
+ if (!$failure && in_array($fields['network'], [Protocol::DFRN, Protocol::DIASPORA])) {
self::discoverRelay($server_url);
}
- logger("End discovery for server " . $server_url, LOGGER_DEBUG);
+ Logger::log("End discovery for server " . $server_url, LOGGER_DEBUG);
return !$failure;
}
*/
private static function discoverRelay($server_url)
{
- logger("Discover relay data for server " . $server_url, LOGGER_DEBUG);
+ Logger::log("Discover relay data for server " . $server_url, LOGGER_DEBUG);
- $serverret = Network::curl($server_url . "/.well-known/x-social-relay");
+ $curlResult = Network::curl($server_url . "/.well-known/x-social-relay");
- if (!$serverret["success"]) {
+ if (!$curlResult->isSuccess()) {
return;
}
- $data = json_decode($serverret['body'], true);
+ $data = json_decode($curlResult->getBody(), true);
if (!is_array($data)) {
return;
$tags = [];
foreach ($data['tags'] as $tag) {
$tag = mb_strtolower($tag);
- $tags[$tag] = $tag;
+ if (strlen($tag) < 100) {
+ $tags[$tag] = $tag;
+ }
}
foreach ($tags as $tag) {
$fields = [];
if (isset($data['protocols'])) {
if (isset($data['protocols']['diaspora'])) {
- $fields['network'] = NETWORK_DIASPORA;
+ $fields['network'] = Protocol::DIASPORA;
if (isset($data['protocols']['diaspora']['receive'])) {
$fields['batch'] = $data['protocols']['diaspora']['receive'];
}
if (isset($data['protocols']['dfrn'])) {
- $fields['network'] = NETWORK_DFRN;
+ $fields['network'] = Protocol::DFRN;
if (isset($data['protocols']['dfrn']['receive'])) {
$fields['batch'] = $data['protocols']['dfrn']['receive'];
WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure`
ORDER BY `last_contact`
LIMIT 1000",
- DBA::escape(NETWORK_DFRN),
- DBA::escape(NETWORK_DIASPORA),
- DBA::escape(NETWORK_OSTATUS)
+ DBA::escape(Protocol::DFRN),
+ DBA::escape(Protocol::DIASPORA),
+ DBA::escape(Protocol::OSTATUS)
);
if (!DBA::isResult($r)) {
*/
private static function fetchServerlist($poco)
{
- $serverret = Network::curl($poco . "/@server");
+ $curlResult = Network::curl($poco . "/@server");
- if (!$serverret["success"]) {
+ if (!$curlResult->isSuccess()) {
return;
}
- $serverlist = json_decode($serverret['body'], true);
+ $serverlist = json_decode($curlResult->getBody(), true);
if (!is_array($serverlist)) {
return;
$r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(normalise_link($server_url)));
if (!DBA::isResult($r)) {
- logger("Call server check for server ".$server_url, LOGGER_DEBUG);
+ Logger::log("Call server check for server ".$server_url, LOGGER_DEBUG);
Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $server_url);
}
}
}
// Discover Friendica, Hubzilla and Diaspora servers
- $serverdata = Network::fetchUrl("http://the-federation.info/pods.json");
+ $curlResult = Network::fetchUrl("http://the-federation.info/pods.json");
- if (!empty($serverdata)) {
- $servers = json_decode($serverdata, true);
+ if (!empty($curlResult)) {
+ $servers = json_decode($curlResult, true);
if (!empty($servers['pods'])) {
foreach ($servers['pods'] as $server) {
if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0';
$header = ['Authorization: Bearer '.$accesstoken];
- $serverdata = Network::curl($api, false, $redirects, ['headers' => $header]);
+ $curlResult = Network::curl($api, false, $redirects, ['headers' => $header]);
- if ($serverdata['success']) {
- $servers = json_decode($serverdata['body'], true);
+ if ($curlResult->isSuccess()) {
+ $servers = json_decode($curlResult->getBody(), true);
foreach ($servers['instances'] as $server) {
$url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name'];
//if (!Config::get('system','ostatus_disabled')) {
// $serverdata = "http://gstools.org/api/get_open_instances/";
- // $result = Network::curl($serverdata);
- // if ($result["success"]) {
- // $servers = json_decode($result["body"], true);
+ // $curlResult = Network::curl($serverdata);
+ // if ($curlResult->isSuccess()) {
+ // $servers = json_decode($result->getBody(), true);
// foreach($servers['data'] as $server)
// self::checkServer($server['instance_address']);
// Fetch all users from the other server
$url = $server["poco"] . "/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
- logger("Fetch all users from the server " . $server["url"], LOGGER_DEBUG);
+ Logger::log("Fetch all users from the server " . $server["url"], LOGGER_DEBUG);
- $retdata = Network::curl($url);
+ $curlResult = Network::curl($url);
- if ($retdata["success"] && !empty($retdata["body"])) {
- $data = json_decode($retdata["body"], true);
+ if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
+ $data = json_decode($curlResult->getBody(), true);
- self::discoverServer($data, 2);
+ if (!empty($data)) {
+ self::discoverServer($data, 2);
+ }
if (Config::get('system', 'poco_discovery') > 1) {
$timeframe = Config::get('system', 'poco_discovery_since');
$success = false;
- $retdata = Network::curl($url);
+ $curlResult = Network::curl($url);
- if ($retdata["success"] && !empty($retdata["body"])) {
- logger("Fetch all global contacts from the server " . $server["nurl"], LOGGER_DEBUG);
- $success = self::discoverServer(json_decode($retdata["body"], true));
+ if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
+ Logger::log("Fetch all global contacts from the server " . $server["nurl"], LOGGER_DEBUG);
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (!empty($data)) {
+ $success = self::discoverServer($data);
+ }
}
if (!$success && (Config::get('system', 'poco_discovery') > 2)) {
- logger("Fetch contacts from users of the server " . $server["nurl"], LOGGER_DEBUG);
+ Logger::log("Fetch contacts from users of the server " . $server["nurl"], LOGGER_DEBUG);
self::discoverServerUsers($data, $server);
}
}
continue;
}
- logger('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], LOGGER_DEBUG);
+ Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], LOGGER_DEBUG);
Worker::add(PRIORITY_LOW, 'DiscoverPoCo', 'update_server_directory', (int) $gserver['id']);
if (!$complete && ( --$no_of_queries == 0)) {
}
if ($username != '') {
- logger('Fetch contacts for the user ' . $username . ' from the server ' . $server['nurl'], LOGGER_DEBUG);
+ Logger::log('Fetch contacts for the user ' . $username . ' from the server ' . $server['nurl'], LOGGER_DEBUG);
// Fetch all contacts from a given user from the other server
$url = $server['poco'] . '/' . $username . '/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation';
- $retdata = Network::curl($url);
+ $curlResult = Network::curl($url);
- if (!empty($retdata['success'])) {
- self::discoverServer(json_decode($retdata['body'], true), 3);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult["body"], true);
+
+ if (!empty($data)) {
+ self::discoverServer($data, 3);
+ }
}
}
}
$connect_url = '';
$name = '';
$network = '';
- $updated = NULL_DATE;
+ $updated = DBA::NULL_DATETIME;
$location = '';
$about = '';
$keywords = '';
if ($generation > 0) {
$success = true;
- logger("Store profile ".$profile_url, LOGGER_DEBUG);
+ Logger::log("Store profile ".$profile_url, LOGGER_DEBUG);
$gcontact = ["url" => $profile_url,
"name" => $name,
$gcontact = GContact::sanitize($gcontact);
GContact::update($gcontact);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), LOGGER_DEBUG);
}
- logger("Done for profile ".$profile_url, LOGGER_DEBUG);
+ Logger::log("Done for profile ".$profile_url, LOGGER_DEBUG);
}
}
return $success;