if ($updated == "0000-00-00 00:00:00")
$updated = $x[0]["updated"];
+ $created = $x[0]["created"];
$last_contact = $x[0]["last_contact"];
$last_failure = $x[0]["last_failure"];
$server_url = $x[0]["server_url"];
+ $nick = $x[0]["nick"];
} else {
+ $created = "0000-00-00 00:00:00";
$last_contact = "0000-00-00 00:00:00";
$last_failure = "0000-00-00 00:00:00";
$server_url = "";
+
+ $urlparts = parse_url($profile_url);
+ $nick = end(explode("/", $urlparts["path"]));
}
if (($network == "") OR ($name == "") OR ($profile_photo == "") OR ($server_url == "")) {
$data = probe_url($profile_url);
$network = $data["network"];
$name = $data["name"];
+ $nick = $data["nick"];
$profile_url = $data["url"];
$profile_photo = $data["photo"];
$server_url = $data["baseurl"];
poco_check_server($server_url, $network);
// Only fetch last update manually if it wasn't provided and enabled in the system
- if (get_config('system','poco_completion') AND ($orig_updated == "0000-00-00 00:00:00") AND poco_do_update($updated, $last_contact, $last_failure)) {
+ if (get_config('system','poco_completion') AND ($orig_updated == "0000-00-00 00:00:00") AND poco_do_update($created, $updated, $last_failure, $last_contact)) {
$last_updated = poco_last_updated($profile_url);
if ($last_updated) {
$updated = $last_updated;
);
}
} else {
- q("INSERT INTO `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `server_url`, `updated`, `last_contact`, `last_failure`, `location`, `about`, `keywords`, `gender`, `generation`)
- VALUES ('%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
+ q("INSERT INTO `gcontact` (`name`, `nick`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `last_contact`, `last_failure`, `location`, `about`, `keywords`, `gender`, `generation`)
+ VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
dbesc($name),
+ dbesc($nick),
dbesc($network),
dbesc($profile_url),
dbesc(normalise_link($profile_url)),
dbesc($profile_photo),
dbesc($connect_url),
dbesc($server_url),
+ dbesc(datetime_convert()),
dbesc($updated),
dbesc($last_contact),
dbesc($last_failure),
$gcontacts = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
dbesc(normalise_link($profile)));
- if ($gcontacts[0]["server_url"] != "") {
- $servers = q("SELECT * FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` < `last_failure`", dbesc(normalise_link($gcontacts[0]["server_url"])));
+ if ($gcontacts[0]["created"] == "0000-00-00 00:00:00")
+ q("UPDATE `gcontact` SET `created` = '%s' WHERE `nurl` = '%s'",
+ dbesc(datetime_convert()), dbesc(normalise_link($profile)));
- if ($servers)
+ if (($gcontacts[0]["server_url"] != "") AND ($gcontacts[0]["network"] != ""))
+ if (!poco_check_server($gcontacts[0]["server_url"], $gcontacts[0]["network"]))
return false;
+
+ // noscrape is really fast so we don't cache the call.
+ if (($gcontacts[0]["server_url"] != "") AND ($gcontacts[0]["nick"] != "")) {
+
+ // Use noscrape if possible
+ $server = q("SELECT `noscrape` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
+
+ if ($server) {
+ $noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
+ if ($noscraperet["success"]) {
+ $noscrape = json_decode($noscraperet["body"], true);
+
+ if (($noscrape["name"] != "") AND ($noscrape["name"] != $gcontacts[0]["name"]))
+ q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'",
+ dbesc($noscrape["name"]), dbesc(normalise_link($profile)));
+
+ if (($noscrape["photo"] != "") AND ($noscrape["photo"] != $gcontacts[0]["photo"]))
+ q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'",
+ dbesc($noscrape["photo"]), dbesc(normalise_link($profile)));
+
+ if (($noscrape["updated"] != "") AND ($noscrape["updated"] != $gcontacts[0]["updated"]))
+ q("UPDATE `gcontact` SET `updated` = '%s' WHERE `nurl` = '%s'",
+ dbesc($noscrape["updated"]), dbesc(normalise_link($profile)));
+
+ if (($noscrape["gender"] != "") AND ($noscrape["gender"] != $gcontacts[0]["gender"]))
+ q("UPDATE `gcontact` SET `gender` = '%s' WHERE `nurl` = '%s'",
+ dbesc($noscrape["gender"]), dbesc(normalise_link($profile)));
+
+ if (($noscrape["about"] != "") AND ($noscrape["about"] != $gcontacts[0]["name"]))
+ q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'",
+ dbesc($noscrape["about"]), dbesc(normalise_link($profile)));
+
+ $keywords = implode(" ", $noscrape["tags"]);
+ if (($keywords != "") AND ($keywords != $gcontacts[0]["keywords"]))
+ q("UPDATE `gcontact` SET `keywords` = '%s' WHERE `nurl` = '%s'",
+ dbesc($keywords), dbesc(normalise_link($profile)));
+
+ $location = $noscrape["locality"];
+
+ if ($noscrape["region"] != "") {
+ if ($location != "")
+ $location .= ", ";
+
+ $location .= $noscrape["region"];
+ }
+
+ if ($noscrape["country-name"] != "") {
+ if ($location != "")
+ $location .= ", ";
+
+ $location .= $noscrape["country-name"];
+ }
+
+ if (($location != "") AND ($location != $gcontacts[0]["location"]))
+ q("UPDATE `gcontact` SET `location` = '%s' WHERE `nurl` = '%s'",
+ dbesc($location), dbesc(normalise_link($profile)));
+
+ return $noscrape["updated"];
+ }
+ }
}
+ // If we only can poll the feed, then we only do this once a while
+ if (!poco_do_update($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"]))
+/ return $gcontacts[0]["updated"];
+
$data = probe_url($profile);
if (($data["poll"] == "") OR ($data["network"] == NETWORK_FEED)) {
q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'",
dbesc($data["name"]), dbesc(normalise_link($profile)));
+ if (($data["nick"] != "") AND ($data["nick"] != $gcontacts[0]["nick"]))
+ q("UPDATE `gcontact` SET `nick` = '%s' WHERE `nurl` = '%s'",
+ dbesc($data["nick"]), dbesc(normalise_link($profile)));
+
if (($data["addr"] != "") AND ($data["addr"] != $gcontacts[0]["connect"]))
q("UPDATE `gcontact` SET `connect` = '%s' WHERE `nurl` = '%s'",
dbesc($data["addr"]), dbesc(normalise_link($profile)));
q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'",
dbesc($data["baseurl"]), dbesc(normalise_link($profile)));
- if ($data["baseurl"] != "")
- poco_check_server($data["baseurl"], $data["network"]);
-
- // To-Do: Use noscrape
-
$feedret = z_fetch_url($data["poll"]);
if (!$feedret["success"]) {
return($last_updated);
}
-function poco_do_update($updated, $last_contact, $last_failure) {
+function poco_do_update($created, $updated, $last_failure, $last_contact) {
$now = strtotime(datetime_convert());
if ($updated > $last_contact)
$contact_time = strtotime($last_contact);
$failure_time = strtotime($last_failure);
+ $created_time = strtotime($created);
+
+ // If there is no "created" time then use the current time
+ if ($created_time <= 0)
+ $created_time = $now;
// If the last contact was less than 24 hours then don't update
if (($now - $contact_time) < (60 * 60 * 24))
if ((($now - $contact_time) < (60 * 60 * 24 * 7)) AND ($contact_time > $failure_time))
return false;
- // If the last contact time was more than a week ago, then only try once a week
- if ((($now - $contact_time) > (60 * 60 * 24 * 7)) AND (($now - $failure_time) < (60 * 60 * 24 * 7)))
+ // If the last contact time was more than a week ago and the contact was created more than a week ago, then only try once a week
+ if ((($now - $contact_time) > (60 * 60 * 24 * 7)) AND (($now - $created_time) > (60 * 60 * 24 * 7)) AND (($now - $failure_time) < (60 * 60 * 24 * 7)))
return false;
- // If the last contact time was more than a month ago, then only try once a month - but only if there ever was a contact time
- if (($contact_time > 0) AND (($now - $contact_time) > (60 * 60 * 24 * 30)) AND (($now - $failure_time) < (60 * 60 * 24 * 30)))
+ // If the last contact time was more than a month ago and the contact was created more than a month ago, then only try once a month
+ if ((($now - $contact_time) > (60 * 60 * 24 * 30)) AND (($now - $created_time) > (60 * 60 * 24 * 30)) AND (($now - $failure_time) < (60 * 60 * 24 * 30)))
return false;
return true;
$servers = q("SELECT * FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
if ($servers) {
+
+ if ($servers[0]["created"] == "0000-00-00 00:00:00")
+ q("UPDATE `gserver` SET `created` = '%s' WHERE `nurl` = '%s'",
+ dbesc(datetime_convert()), dbesc(normalise_link($server_url)));
+
$poco = $servers[0]["poco"];
$noscrape = $servers[0]["noscrape"];
$info = $servers[0]["info"];
$register_policy = $servers[0]["register_policy"];
- if (!poco_do_update("", $last_contact, $last_failure))
+ if (!poco_do_update($servers[0]["created"], "", $last_failure, $last_contact))
return ($last_contact >= $last_failure);
} else {
$poco = "";
if (isset($data->site->hubzilla)) {
$platform = $data->site->hubzilla->PLATFORM_NAME;
$version = $data->site->hubzilla->RED_VERSION;
- $network = NETWORK_DFRN;
+ $network = NETWORK_DIASPORA;
}
if (isset($data->site->redmatrix)) {
if (isset($data->site->redmatrix->PLATFORM_NAME))
dbesc(normalise_link($server_url))
);
else
- q("INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `last_contact`, `last_failure`)
+ q("INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`)
VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s')",
dbesc($server_url),
dbesc(normalise_link($server_url)),
dbesc($noscrape),
dbesc($network),
dbesc($platform),
+ dbesc(datetime_convert()),
dbesc($last_contact),
dbesc($last_failure),
dbesc(datetime_convert())
if (get_config('system','poco_discovery') > 1) {
+ $timeframe = get_config('system','poco_discovery_since');
+ if ($timeframe == 0)
+ $timeframe = 30;
+
+ $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400);
+
// Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3)
- $url = $server["poco"]."/@global?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,generation";
+ $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,generation";
$retdata = z_fetch_url($url);
if ($retdata["success"]) {
$maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
$poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
$poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0);
+ $poco_discovery_since = ((x($_POST,'poco_discovery_since')) ? intval(trim($_POST['poco_discovery_since'])) : 30);
$poco_local_search = ((x($_POST,'poco_local_search')) ? intval(trim($_POST['poco_local_search'])) : false);
$dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
$ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
set_config('system','poco_completion',$poco_completion);
set_config('system','poco_discovery',$poco_discovery);
+ set_config('system','poco_discovery_since',$poco_discovery_since);
set_config('system','poco_local_search',$poco_local_search);
set_config('config','sitename',$sitename);
set_config('config','hostname',$hostname);
"3" => t("Users, Global Contacts/fallback"),
);
+ $poco_discovery_since_choices = array(
+ "30" => t("One month"),
+ "91" => t("Three months"),
+ "182" => t("Half a year"),
+ "365" => t("One year"),
+ );
+
/* get user names to make the install a personal install of X */
$user_names = array();
$user_names['---'] = t('Multi user instance');
'$poco_completion' => array('poco_completion', t("Completion of incoming contacts"), get_config('system','poco_completion'), t("Complete data of incomplete incoming contacts that are provided by the 'portable contacts' functionality. (Useful when communicating with Redmatrix and friendica servers before 3.3)")),
'$poco_discovery' => array('poco_discovery', t("Discover contacts from other servers"), (string) intval(get_config('system','poco_discovery')), t("Periodically query other servers for contacts. You can choose between 'users': the users on the remote system, 'Global Contacts': active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren't available."), $poco_discovery_choices),
+ '$poco_discovery_since' => array('poco_discovery_since', t("Timeframe for fetching global contacts"), (string) intval(get_config('system','poco_discovery_since')), t("When the discovery is activated, this value defines the timeframe for the global contacts that are fetched from other servers."), $poco_discovery_since_choices),
'$poco_local_search' => array('poco_local_search', t("Search the local directory"), get_config('system','poco_local_search'), t("Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.")),
'$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")),