* @todo Detect if it is a forum
*/
+use \Friendica\Core\Config;
+
require_once('include/datetime.php');
require_once("include/Scrape.php");
require_once("include/network.php");
"contact-type" => $contact_type,
"generation" => $generation);
- if (sanitized_gcontact($gcontact)) {
+ try {
+ $gcontact = sanitize_gcontact($gcontact);
$gcid = update_gcontact($gcontact);
link_gcontact($gcid, $uid, $cid, $zcid);
+ } catch (Exception $e) {
+ logger($e->getMessage(), LOGGER_DEBUG);
}
}
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
* @brief Sanitize the given gcontact data
*
* @param array $gcontact array with gcontact data
+ * @throw Exception
*
* Generation:
* 0: No definition
* 4: ...
*
*/
-function sanitized_gcontact(&$gcontact) {
+function sanitize_gcontact($gcontact) {
if ($gcontact['url'] == "") {
- return false;
+ throw new Exception('URL is empty');
}
$urlparts = parse_url($gcontact['url']);
if (!isset($urlparts["scheme"])) {
- return false;
+ throw new Exception("This (".$gcontact['url'].") doesn't seem to be an url.");
}
if (in_array($urlparts["host"], array("www.facebook.com", "facebook.com", "twitter.com",
"identi.ca", "alpha.app.net"))) {
- return false;
+ throw new Exception('Contact from a non federated network ignored. ('.$gcontact['url'].')');
}
// Don't store the statusnet connector as network
$data = Probe::uri($gcontact['url']);
if ($data["network"] == NETWORK_PHANTOM) {
- return false;
+ throw new Exception('Probing for URL '.$gcontact['url'].' failed');
}
$orig_profile = $gcontact['url'];
}
if (!isset($gcontact['name']) OR !isset($gcontact['photo'])) {
- return false;
+ throw new Exception('No name and photo for URL '.$gcontact['url']);
}
if (!in_array($gcontact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
- return false;
+ throw new Exception('No federated network ('.$gcontact['network'].') detected for URL '.$gcontact['url']);
}
if (!isset($gcontact['server_url'])) {
$gcontact['server_url'] = "";
}
- return true;
+ return $gcontact;
}
/**
$gcontact["server_url"] = $data["baseurl"];
- if (sanitized_gcontact($gcontact)) {
+ try {
+ $gcontact = sanitize_gcontact($gcontact);
update_gcontact($gcontact);
poco_last_updated($data["url"], $force);
+ } catch (Exception $e) {
+ logger($e->getMessage(), LOGGER_DEBUG);
}
logger("Profile ".$profile." was deleted", LOGGER_DEBUG);
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;
}
// 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;
}
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) {
$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'];
$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"]);
$network = $server['network'];
$version = $server['version'];
$site_name = $server['site_name'];
- $last_contact = datetime_convert();
}
$lines = explode("\n",$serverret["header"]);
$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();
}
}
}
$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
$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;
+ }
}
}
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;
}
}
-
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) {
$serverret = z_fetch_url($server_url."/statistics.json");
} else {
$register_policy = REGISTER_CLOSED;
}
-
- if (isset($data->version))
- $last_contact = datetime_convert();
}
}
if (isset($server['site_name'])) {
$site_name = $server['site_name'];
}
-
- $last_contact = datetime_convert();
}
}
$data = json_decode($serverret["body"]);
if (isset($data->version)) {
- $last_contact = datetime_convert();
$network = NETWORK_DFRN;
$noscrape = $data->no_scrape_url;
}
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;
}
}
}
+ // 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.
"contact-type" => $contact_type,
"generation" => $generation);
- if (sanitized_gcontact($gcontact)) {
+ try {
+ $gcontact = sanitize_gcontact($gcontact);
update_gcontact($gcontact);
+ } catch (Exception $e) {
+ logger($e->getMessage(), LOGGER_DEBUG);
}
logger("Done for profile ".$profile_url, LOGGER_DEBUG);
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"];
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"]));