$a = get_app();
- if($cid) {
- if((! $url) || (! $uid)) {
+ if ($cid) {
+ if ((! $url) || (! $uid)) {
$r = q("select `poco`, `uid` from `contact` where `id` = %d limit 1",
intval($cid)
);
$uid = $r[0]['uid'];
}
}
- if(! $uid)
+ if (! $uid)
return;
}
- if(! $url)
+ if (! $url)
return;
$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('poco_load: return code: ' . $a->get_curl_code(), LOGGER_DEBUG);
- if(($a->get_curl_code() > 299) || (! $s))
+ if (($a->get_curl_code() > 299) || (! $s))
return;
$j = json_decode($s);
logger('poco_load: json: ' . print_r($j,true),LOGGER_DATA);
- if(! isset($j->entry))
+ if (! isset($j->entry))
return;
$total = 0;
- foreach($j->entry as $entry) {
+ foreach ($j->entry as $entry) {
$total ++;
$profile_url = '';
}
if (isset($entry->tags)) {
- foreach($entry->tags as $tag) {
+ foreach ($entry->tags as $tag) {
$keywords = implode(", ", $tag);
}
}
$gcid = update_gcontact($gcontact);
- if(!$gcid)
+ if (!$gcid)
return $gcid;
$r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1",
// Wild guess
if ($server_url == "") {
$base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile);
- if (base != $profile) {
+ if ($base != $profile) {
$server_url = $base;
$network = NETWORK_PHANTOM;
}
if (isset($nodeinfo->software->version)) {
$server['version'] = $nodeinfo->software->version;
+ // Version numbers on Nodeinfo are presented with additional info, e.g.:
+ // 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
+ $server['version'] = preg_replace("=(.+)-(.{4,})=ism", "$1", $server['version']);
}
}
}
$lines = explode("\n",$serverret["header"]);
- if(count($lines)) {
- foreach($lines as $line) {
+ if (count($lines)) {
+ foreach ($lines as $line) {
$line = trim($line);
- if(stristr($line,'X-Diaspora-Version:')) {
+ if (stristr($line,'X-Diaspora-Version:')) {
$platform = "Diaspora";
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
$version = trim(str_replace("x-diaspora-version:", "", $version));
$last_contact = datetime_convert();
}
- if(stristr($line,'Server: Mastodon')) {
+ if (stristr($line,'Server: Mastodon')) {
$platform = "Mastodon";
$network = NETWORK_OSTATUS;
// Mastodon doesn't reveal version numbers
$serverret = z_fetch_url($server_url."/statistics.json");
if ($serverret["success"]) {
$data = json_decode($serverret["body"]);
- if ($version == "")
+ if (isset($data->version)) {
$version = $data->version;
+ // Version numbers on statistics.json are presented with additional info, e.g.:
+ // 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
+ $version = preg_replace("=(.+)-(.{4,})=ism", "$1", $version);
+ }
$site_name = $data->name;
- if (isset($data->network) AND ($platform == ""))
+ if (isset($data->network)) {
$platform = $data->network;
+ }
- if ($platform == "Diaspora")
+ if ($platform == "Diaspora") {
$network = NETWORK_DIASPORA;
+ }
- if ($data->registrations_open)
+ if ($data->registrations_open) {
$register_policy = REGISTER_OPEN;
- else
+ } else {
$register_policy = REGISTER_CLOSED;
+ }
if (isset($data->version))
$last_contact = datetime_convert();
$server = poco_fetch_nodeinfo($server_url);
if ($server) {
$register_policy = $server['register_policy'];
- $platform = $server['platform'];
- $network = $server['network'];
- if ($version == "") {
+ if (isset($server['platform'])) {
+ $platform = $server['platform'];
+ }
+
+ if (isset($server['network'])) {
+ $network = $server['network'];
+ }
+
+ if (isset($server['version'])) {
$version = $server['version'];
}
- $site_name = $server['site_name'];
+ if (isset($server['site_name'])) {
+ $site_name = $server['site_name'];
+ }
$last_contact = datetime_convert();
}
dbesc($last_failure),
dbesc(normalise_link($server_url))
);
- } elseif (!$failure)
+ } elseif (!$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', '%s')",
dbesc($server_url),
dbesc($last_failure),
dbesc(datetime_convert())
);
-
+ }
logger("End discovery for server ".$server_url, LOGGER_DEBUG);
return !$failure;
function common_friends($uid,$cid,$start = 0,$limit=9999,$shuffle = false) {
- if($shuffle)
+ if ($shuffle)
$sql_extra = " order by rand() ";
else
$sql_extra = " order by `gcontact`.`name` asc ";
function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = false) {
- if($shuffle)
+ if ($shuffle)
$sql_extra = " order by rand() ";
else
$sql_extra = " order by `gcontact`.`name` asc ";
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$base = substr($rr['poco'],0,strrpos($rr['poco'],'/'));
- if(! in_array($base,$done))
+ if (! in_array($base,$done))
poco_load(0,0,0,$base);
}
}
if ($last) {
$next = $last + (24 * 60 * 60);
- if($next > time())
+ if ($next > time())
return;
}
}
}
- // 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.
- //if (!get_config('system','ostatus_disabled')) {
- // $serverdata = "http://gstools.org/api/get_open_instances/";
+ /*
+ * 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.
+ if (!get_config('system','ostatus_disabled')) {
+ $serverdata = "http://gstools.org/api/get_open_instances/";
- // $result = z_fetch_url($serverdata);
- // if ($result["success"]) {
- // $servers = json_decode($result["body"]);
+ $result = z_fetch_url($serverdata);
+ if ($result["success"]) {
+ $servers = json_decode($result["body"]);
- // foreach($servers->data AS $server)
- // poco_check_server($server->instance_address);
- // }
- //}
+ foreach($servers->data AS $server)
+ poco_check_server($server->instance_address);
+ }
+ }
+ */
set_config('poco','last_federation_discovery', time());
}
foreach ($data->entry AS $entry) {
$username = "";
if (isset($entry->urls)) {
- foreach($entry->urls as $url)
+ foreach ($entry->urls as $url)
if ($url->type == 'profile') {
$profile_url = $url->value;
$urlparts = parse_url($profile_url);
$name = $entry->displayName;
if (isset($entry->urls)) {
- foreach($entry->urls as $url) {
+ foreach ($entry->urls as $url) {
if ($url->type == 'profile') {
$profile_url = $url->value;
continue;
$updated = date("Y-m-d H:i:s", strtotime($entry->updated));
}
- if(isset($entry->network)) {
+ if (isset($entry->network)) {
$network = $entry->network;
}
- if(isset($entry->currentLocation)) {
+ if (isset($entry->currentLocation)) {
$location = $entry->currentLocation;
}
- if(isset($entry->aboutMe)) {
+ if (isset($entry->aboutMe)) {
$about = html2bbcode($entry->aboutMe);
}
- if(isset($entry->gender)) {
+ if (isset($entry->gender)) {
$gender = $entry->gender;
}
- if(isset($entry->generation) AND ($entry->generation > 0)) {
+ if (isset($entry->generation) AND ($entry->generation > 0)) {
$generation = ++$entry->generation;
}
- if(isset($entry->contactType) AND ($entry->contactType >= 0)) {
+ if (isset($entry->contactType) AND ($entry->contactType >= 0)) {
$contact_type = $entry->contactType;
}
- if(isset($entry->tags)) {
+ if (isset($entry->tags)) {
foreach ($entry->tags as $tag) {
$keywords = implode(", ", $tag);
}