set_config('poco','last_federation_discovery', time());
}
-function poco_discover($complete = false) {
+function poco_discover_single_server($id) {
+ $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id));
+ if (!dbm::is_result($r)) {
+ return false;
+ }
- // Update the server list
- poco_discover_federation();
+ $server = $r[0];
- $no_of_queries = 5;
+ if (!poco_check_server($server["url"], $server["network"])) {
+ // The server is not reachable? Okay, then we will try it later
+ q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
+ return false;
+ }
- $requery_days = intval(get_config("system", "poco_requery_days"));
++ // Discover new servers out there
++ poco_fetch_serverlist($server["poco"]);
+
- if ($requery_days == 0)
- $requery_days = 7;
+ // Fetch all users from the other server
+ $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
- $last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
+ logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG);
- $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update));
- if ($r)
- foreach ($r AS $server) {
+ $retdata = z_fetch_url($url);
+ if ($retdata["success"]) {
+ $data = json_decode($retdata["body"]);
+
+ poco_discover_server($data, 2);
+
+ if (get_config('system','poco_discovery') > 1) {
- if (!poco_check_server($server["url"], $server["network"])) {
- // The server is not reachable? Okay, then we will try it later
- q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
- continue;
+ $timeframe = get_config('system','poco_discovery_since');
+ if ($timeframe == 0) {
+ $timeframe = 30;
}
- // Discover new servers out there
- poco_fetch_serverlist($server["poco"]);
+ $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400);
- // Fetch all users from the other server
- $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
+ // Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3)
+ $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
- logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG);
+ $success = false;
$retdata = z_fetch_url($url);
if ($retdata["success"]) {