X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FPortableContact.php;h=def8f1b628bc3b667636843c9d701f2bf331c5fb;hb=a80a6bec74dc35b90697dfde6260206bfb128827;hp=0bc17d3dce17000b33dbf5e799ca84a6f60292f0;hpb=6e7ca479d63d9740c83074cd95b454da0c686885;p=friendica.git diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 0bc17d3dce..def8f1b628 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -29,6 +29,11 @@ use Friendica\Util\XML; class PortableContact { + const DISABLED = 0; + const USERS = 1; + const USERS_GCONTACTS = 2; + const USERS_GCONTACTS_FALLBACK = 3; + /** * @brief Fetch POCO data * @@ -500,8 +505,15 @@ class PortableContact $last_updated = ""; foreach ($entries as $entry) { - $published = DateTimeFormat::utc($xpath->query('atom:published/text()', $entry)->item(0)->nodeValue); - $updated = DateTimeFormat::utc($xpath->query('atom:updated/text()' , $entry)->item(0)->nodeValue); + $published_item = $xpath->query('atom:published/text()', $entry)->item(0); + $updated_item = $xpath->query('atom:updated/text()' , $entry)->item(0); + $published = isset($published_item->nodeValue) ? DateTimeFormat::utc($published_item->nodeValue) : null; + $updated = isset($updated_item->nodeValue) ? DateTimeFormat::utc($updated_item->nodeValue) : null; + + if (!isset($published) || !isset($updated)) { + Logger::notice('Invalid entry for XPath.', ['entry' => $entry, 'profile' => $profile]); + continue; + } if ($last_updated < $published) { $last_updated = $published; @@ -653,7 +665,7 @@ class PortableContact $nodeinfo2_url = ''; foreach ($nodeinfo['links'] as $link) { - if (!is_array($link) || empty($link['rel'])) { + if (!is_array($link) || empty($link['rel']) || empty($link['href'])) { Logger::log('Invalid nodeinfo format for ' . $server_url, Logger::DEBUG); continue; } @@ -737,7 +749,7 @@ class PortableContact $friendica = false; $gnusocial = false; - if (is_array($nodeinfo['protocols']['inbound'])) { + if (!empty($nodeinfo['protocols']['inbound']) && is_array($nodeinfo['protocols']['inbound'])) { foreach ($nodeinfo['protocols']['inbound'] as $inbound) { if ($inbound == 'diaspora') { $diaspora = true; @@ -992,7 +1004,7 @@ class PortableContact $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 - $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['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. @@ -1009,7 +1021,7 @@ class PortableContact $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 - $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]); // Quit if there is a timeout if ($curlResult->isTimeout()) { @@ -1612,7 +1624,7 @@ class PortableContact if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $curlResult = Network::curl($api, false, $redirects, ['headers' => $header]); + $curlResult = Network::curl($api, false, ['headers' => $header]); if ($curlResult->isSuccess()) { $servers = json_decode($curlResult->getBody(), true); @@ -1645,21 +1657,19 @@ class PortableContact public static function discoverSingleServer($id) { - $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id)); + $server = DBA::selectFirst('gserver', ['poco', 'nurl', 'url', 'network'], ['id' => $id]); - if (!DBA::isResult($r)) { + if (!DBA::isResult($server)) { return false; } - $server = $r[0]; - // Discover new servers out there (Works from Friendica version 3.5.2) self::fetchServerlist($server["poco"]); // Fetch all users from the other server $url = $server["poco"] . "/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - Logger::log("Fetch all users from the server " . $server["url"], Logger::DEBUG); + Logger::info("Fetch all users from the server " . $server["url"]); $curlResult = Network::curl($url); @@ -1670,7 +1680,7 @@ class PortableContact self::discoverServer($data, 2); } - if (Config::get('system', 'poco_discovery') > 1) { + if (Config::get('system', 'poco_discovery') >= self::USERS_GCONTACTS) { $timeframe = Config::get('system', 'poco_discovery_since'); if ($timeframe == 0) { @@ -1687,7 +1697,7 @@ class PortableContact $curlResult = Network::curl($url); if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { - Logger::log("Fetch all global contacts from the server " . $server["nurl"], Logger::DEBUG); + Logger::info("Fetch all global contacts from the server " . $server["nurl"]); $data = json_decode($curlResult->getBody(), true); if (!empty($data)) { @@ -1695,8 +1705,8 @@ class PortableContact } } - if (!$success && (Config::get('system', 'poco_discovery') > 2)) { - Logger::log("Fetch contacts from users of the server " . $server["nurl"], Logger::DEBUG); + if (!$success && !empty($data) && Config::get('system', 'poco_discovery') >= self::USERS_GCONTACTS_FALLBACK) { + Logger::info("Fetch contacts from users of the server " . $server["nurl"]); self::discoverServerUsers($data, $server); } }