throw new Exception('URL is empty');
}
- $gcontact['server_url'] = defaults($gcontact, 'server_url', '');
+ $gcontact['server_url'] = $gcontact['server_url'] ?? '';
$urlparts = parse_url($gcontact['url']);
if (empty($urlparts['scheme'])) {
public static function getId($contact)
{
$gcontact_id = 0;
- $doprobing = false;
- $last_failure_str = '';
- $last_contact_str = '';
if (empty($contact['network'])) {
Logger::notice('Empty network', ['url' => $contact['url'], 'callstack' => System::callstack()]);
$gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]);
if (DBA::isResult($gcnt)) {
$gcontact_id = $gcnt['id'];
-
- // Update every 90 days
- if (empty($gcnt['network']) || in_array($gcnt['network'], Protocol::FEDERATED)) {
- $last_failure_str = $gcnt['last_failure'];
- $last_failure = strtotime($gcnt['last_failure']);
- $last_contact_str = $gcnt['last_contact'];
- $last_contact = strtotime($gcnt['last_contact']);
- $doprobing = (((time() - $last_contact) > (90 * 86400)) && ((time() - $last_failure) > (90 * 86400)));
- }
} else {
$contact['location'] = $contact['location'] ?? '';
$contact['about'] = $contact['about'] ?? '';
$contact['generation'] = $contact['generation'] ?? 0;
- $fields = ['name' => $contact['name'], 'nick' => $contact['nick'], 'addr' => $contact['addr'], 'network' => $contact['network'],
+ $fields = ['name' => $contact['name'], 'nick' => $contact['nick'] ?? '', 'addr' => $contact['addr'] ?? '', 'network' => $contact['network'],
'url' => $contact['url'], 'nurl' => Strings::normaliseLink($contact['url']), 'photo' => $contact['photo'],
'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(), 'location' => $contact['location'],
'about' => $contact['about'], 'hide' => $contact['hide'], 'generation' => $contact['generation']];
+
DBA::insert('gcontact', $fields);
$condition = ['nurl' => Strings::normaliseLink($contact['url'])];
$cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]);
if (DBA::isResult($cnt)) {
$gcontact_id = $cnt['id'];
- $doprobing = (empty($cnt['network']) || in_array($cnt['network'], Protocol::FEDERATED));
}
}
DBA::unlock();
- if ($doprobing) {
- Logger::notice('Probing', ['contact' => $last_contact_str, "failure" => $last_failure_str, "checking" => $contact['url']]);
- Worker::add(PRIORITY_LOW, 'GProbe', $contact['url']);
- }
-
return $gcontact_id;
}
return;
}
- if (!$force && !PortableContact::updateNeeded($gcontact['created'], $gcontact['updated'], $gcontact['last_failure'], $gcontact['last_contact'])) {
+ if (!$force && !GServer::updateNeeded($gcontact['created'], $gcontact['updated'], $gcontact['last_failure'], $gcontact['last_contact'])) {
Logger::info("Don't update profile", ['url' => $data['url'], 'updated' => $gcontact['updated']]);
return;
}
return;
}
- // When the profile doesn't have got a feed, then we exit here
- if (empty($data['poll'])) {
- return;
- }
-
- if ($data['network'] == Protocol::ACTIVITYPUB) {
+ if (!empty($data['outbox'])) {
+ self::updateFromOutbox($data['outbox'], $data);
+ } elseif (!empty($data['poll']) && ($data['network'] == Protocol::ACTIVITYPUB)) {
self::updateFromOutbox($data['poll'], $data);
- } else {
+ } elseif (!empty($data['poll'])) {
self::updateFromFeed($data);
}
}
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
$noscrape = json_decode($curlResult->getBody(), true);
- if (!empty($noscrape)) {
+ if (!empty($noscrape) && !empty($noscrape['updated'])) {
$noscrape['updated'] = DateTimeFormat::utc($noscrape['updated'], DateTimeFormat::MYSQL);
$fields = ['last_contact' => DateTimeFormat::utcNow(), 'updated' => $noscrape['updated']];
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
/**
* Update a global contact via an ActivityPub Outbox
*
- * @param string $data Probing result
+ * @param string $feed
+ * @param array $data Probing result
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function updateFromOutbox(string $feed, array $data)
{
$items = $outbox['orderedItems'];
} elseif (!empty($outbox['first']['orderedItems'])) {
$items = $outbox['first']['orderedItems'];
+ } elseif (!empty($outbox['first']['href'])) {
+ self::updateFromOutbox($outbox['first']['href'], $data);
+ return;
} elseif (!empty($outbox['first'])) {
- self::updateFromOutbox($outbox['first'], $data);
+ if (is_string($outbox['first'])) {
+ self::updateFromOutbox($outbox['first'], $data);
+ } else {
+ Logger::warning('Unexpected data', ['outbox' => $outbox]);
+ }
return;
} else {
$items = [];
}
$last_updated = '';
-
foreach ($items as $activity) {
- if ($last_updated < $activity['published']) {
- $last_updated = $activity['published'];
+ if (!empty($activity['published'])) {
+ $published = DateTimeFormat::utc($activity['published']);
+ } elseif (!empty($activity['object']['published'])) {
+ $published = DateTimeFormat::utc($activity['object']['published']);
+ } else {
+ continue;
+ }
+
+ if ($last_updated < $published) {
+ $last_updated = $published;
}
}
'birthday' => $userdata['dob'], 'photo' => $userdata['photo'],
"notify" => $userdata['notify'], 'url' => $userdata['url'],
"hide" => ($userdata['hidewall'] || !$userdata['net-publish']),
- 'nick' => $userdata['nickname'], 'addr' => $addr,
- "connect" => $addr, "server_url" => System::baseUrl(),
+ 'nick' => $userdata['nickname'], 'addr' => $userdata['addr'],
+ "connect" => $userdata['addr'], "server_url" => System::baseUrl(),
"generation" => 1, 'network' => Protocol::DFRN];
self::update($gcontact);