use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1310);
+ define('DB_UPDATE_VERSION', 1311);
}
return [
"alias" => ["type" => "varchar(255)", "comment" => ""],
"pubkey" => ["type" => "text", "comment" => ""],
"baseurl" => ["type" => "varchar(255)", "comment" => "baseurl of the ap contact"],
+ "generator" => ["type" => "varchar(255)", "comment" => "Name of the contact's system"],
"updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""]
],
"indexes" => [
"remote_self" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"rel" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "The kind of the relation between the user and the contact"],
"duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
- "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network protocol of the contact"],
+ "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network of the contact"],
+ "protocol" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Protocol of the contact"],
"name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
"nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
"location" => ["type" => "varchar(255)", "default" => "", "comment" => ""],
-- ------------------------------------------
-- Friendica 2019.06-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1310
+-- DB_UPDATE_VERSION 1311
-- ------------------------------------------
`alias` varchar(255) COMMENT '',
`pubkey` text COMMENT '',
`baseurl` varchar(255) COMMENT 'baseurl of the ap contact',
+ `generator` varchar(255) COMMENT 'Name of the contact\'s system',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
PRIMARY KEY(`url`),
INDEX `addr` (`addr`(32)),
`remote_self` boolean NOT NULL DEFAULT '0' COMMENT '',
`rel` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'The kind of the relation between the user and the contact',
`duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
- `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network protocol of the contact',
+ `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network of the contact',
+ `protocol` char(4) NOT NULL DEFAULT '' COMMENT 'Protocol of the contact',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
`nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
`location` varchar(255) DEFAULT '' COMMENT '',
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
-use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\User;
$dfrn_confirm = $contact['confirm'];
$aes_allow = $contact['aes_allow'];
- $network = ((strlen($contact['issued-id'])) ? Protocol::DFRN : Protocol::OSTATUS);
-
- if ($contact['network']) {
- $network = $contact['network'];
- }
-
// an empty DFRN-ID tells us that it had been a request via AP from a Friendica contact
- if (($network === Protocol::DFRN) && empty($dfrn_id) && !empty($contact['hub-verify'])) {
- $apcontact = APContact::getByURL($contact['url']);
- if (!empty($apcontact)) {
- $network = Protocol::ACTIVITYPUB;
- }
+ if (!empty($contact['protocol'])) {
+ $protocol = $contact['protocol'];
+ } elseif (($contact['network'] === Protocol::DFRN) && empty($dfrn_id)) {
+ $protocol = Contact::getProtocol($contact['url'], $contact['network']);
+ } else {
+ $protocol = $contact['network'];
}
- if ($network === Protocol::DFRN) {
+ if ($protocol === Protocol::DFRN) {
/*
* Generate a key pair for all further communications with this person.
* We have a keypair for every contact, and a site key for unknown people.
$public_key = $res['pubkey'];
// Save the private key. Send them the public key.
- q("UPDATE `contact` SET `prvkey` = '%s' WHERE `id` = %d AND `uid` = %d",
- DBA::escape($private_key),
- intval($contact_id),
- intval($uid)
- );
+ $fields = ['prvkey' => $private_key, 'protocol' => Protocol::DFRN];
+ DBA::update('contact', $fields, ['id' => $contact_id]);
$params = [];
if ($status != 0) {
return;
}
+ } else {
+ DBA::update('contact', ['protocol' => $protocol], ['id' => $contact_id]);
}
/*
Logger::log('dfrn_confirm: confirm - imported photos');
- if ($network === Protocol::DFRN) {
+ if ($protocol === Protocol::DFRN) {
$new_relation = Contact::FOLLOWER;
if (($relation == Contact::SHARING) || ($duplex)) {
intval($contact_id)
);
} else {
- if ($network == Protocol::ACTIVITYPUB) {
+ if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
// Setting "pending" to true on a bidirectional contact request could create a problem when it isn't accepted on the other side
// Then we have got a situation where - although one direction is accepted - the contact still appears as pending.
$pending = false;
}
- // $network !== Protocol::DFRN
- $network = defaults($contact, 'network', Protocol::OSTATUS);
-
- $arr = Probe::uri($contact['url'], $network);
+ $arr = Probe::uri($contact['url'], $protocol);
$notify = defaults($contact, 'notify' , $arr['notify']);
$poll = defaults($contact, 'poll' , $arr['poll']);
$new_relation = $contact['rel'];
$writable = $contact['writable'];
- if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
+ if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
if ($duplex) {
$new_relation = Contact::FRIEND;
} else {
$fields = ['name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
'notify' => $notify, 'poll' => $poll, 'blocked' => false,
- 'pending' => $pending, 'network' => $network,
+ 'pending' => $pending, 'protocol' => $protocol,
'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
DBA::update('contact', $fields, ['id' => $contact_id]);
}
// reload contact info
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
- if ((isset($new_relation) && $new_relation == Contact::FRIEND)) {
+ if (isset($new_relation) && ($new_relation == Contact::FRIEND)) {
if (DBA::isResult($contact) && ($contact['network'] === Protocol::DIASPORA)) {
$ret = Diaspora::sendShare($user, $contact);
Logger::log('share returns: ' . $ret);
Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
- if ($network == Protocol::ACTIVITYPUB && $duplex) {
+ if (($protocol == Protocol::ACTIVITYPUB) && $duplex) {
ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
}
$ret = Probe::uri($url);
- if (($ret['network'] == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
+ $protocol = Contact::getProtocol($ret['url'], $ret['network']);
+
+ if (($protocol == Protocol::DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
$submit = '';
//$a->internalRedirect($_SESSION['return_path']);
// NOTREACHED
}
- if (($ret['network'] == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
+ if (($protocol == Protocol::OSTATUS) && Config::get('system', 'ostatus_disabled')) {
notice(L10n::t("OStatus support is disabled. Contact can't be added."));
$submit = '';
//$a->internalRedirect($_SESSION['return_path']);
// NOTREACHED
}
- if ($ret['network'] == Protocol::PHANTOM) {
+ if ($protocol == Protocol::PHANTOM) {
notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
$submit = '';
//$a->internalRedirect($_SESSION['return_path']);
// NOTREACHED
}
- if ($ret['network'] == Protocol::MAIL) {
+ if ($protocol == Protocol::MAIL) {
$ret['url'] = $ret['addr'];
}
- if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($r)) {
+ if (($protocol === Protocol::DFRN) && !DBA::isResult($r)) {
$request = $ret['request'];
$tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
} else {
$gcontact_id = $r[0]['id'];
}
- if ($ret['network'] === Protocol::DIASPORA) {
+ if ($protocol === Protocol::DIASPORA) {
$r[0]['location'] = '';
$r[0]['about'] = '';
}
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
+ if (!empty($compacted['as:generator'])) {
+ $apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
+ $apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
+ }
+
// To-Do
// Unhandled
- // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked
+ // tag, attachment, image, nomadicLocations, signature, featured, movedTo, liked
// Unhandled from Misskey
// sharedInbox, isCat
$apcontact['baseurl'] = Network::unparseURL($parts);
} else {
$apcontact['addr'] = null;
+ }
+
+ if (empty($apcontact['baseurl'])) {
$apcontact['baseurl'] = null;
}
if (empty($contact['network'])) {
return;
}
- if (($contact['network'] == Protocol::DFRN) && $dissolve) {
+
+ $protocol = $contact['network'];
+ if (($protocol == Protocol::DFRN) && !self::isLegacyDFRNContact($contact)) {
+ $protocol = Protocol::ACTIVITYPUB;
+ }
+
+ if (($protocol == Protocol::DFRN) && $dissolve) {
DFRN::deliver($user, $contact, 'placeholder', true);
- } elseif (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DFRN])) {
+ } elseif (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create an unfollow slap
$item = [];
$item['verb'] = NAMESPACE_OSTATUS . "/unfollow";
if (!empty($contact['notify'])) {
Salmon::slapper($user, $contact['notify'], $slap);
}
- } elseif ($contact['network'] == Protocol::DIASPORA) {
+ } elseif ($protocol == Protocol::DIASPORA) {
Diaspora::sendUnshare($user, $contact);
- } elseif ($contact['network'] == Protocol::ACTIVITYPUB) {
+ } elseif ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactUndo($contact['url'], $contact['id'], $user['uid']);
if ($dissolve) {
return true;
}
+ /**
+ * Detects if a given contact array belongs to a legacy DFRN connection
+ *
+ * @param array $contact
+ * @return boolean
+ */
+ public static function isLegacyDFRNContact($contact)
+ {
+ // Newer Friendica contacts are connected via AP, then these fields aren't set
+ return !empty($contact['dfrn-id']) || !empty($contact['issued-id']);
+ }
+
+ /**
+ * Detects the communication protocol for a given contact url.
+ * This is used to detect Friendica contacts that we can communicate via AP.
+ *
+ * @param string $url contact url
+ * @param string $network Network of that contact
+ * @return string with protocol
+ */
+ public static function getProtocol($url, $network)
+ {
+ if ($network != Protocol::DFRN) {
+ return $network;
+ }
+
+ $apcontact = APContact::getByURL($url);
+ if (!empty($apcontact) && !empty($apcontact['generator'])) {
+ return Protocol::ACTIVITYPUB;
+ } else {
+ return $network;
+ }
+ }
+
/**
* Takes a $uid and a url/handle and adds a new contact
* Currently if the contact is DFRN, interactive needs to be true, to redirect to the
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
}
- if (($ret['network'] === Protocol::DFRN) && !DBA::isResult($contact)) {
+ $protocol = self::getProtocol($url, $ret['network']);
+
+ if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
if ($interactive) {
if (strlen($a->getURLPath())) {
$myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']);
}
// This extra param just confuses things, remove it
- if ($ret['network'] === Protocol::DIASPORA) {
+ if ($protocol === Protocol::DIASPORA) {
$ret['url'] = str_replace('?absolute=true', '', $ret['url']);
}
return $result;
}
- if ($ret['network'] === Protocol::OSTATUS && Config::get('system', 'ostatus_disabled')) {
+ if ($protocol === Protocol::OSTATUS && Config::get('system', 'ostatus_disabled')) {
$result['message'] .= L10n::t('The profile address specified belongs to a network which has been disabled on this site.') . EOL;
$ret['notify'] = '';
}
$result['message'] .= L10n::t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL;
}
- $writeable = ((($ret['network'] === Protocol::OSTATUS) && ($ret['notify'])) ? 1 : 0);
+ $writeable = ((($protocol === Protocol::OSTATUS) && ($ret['notify'])) ? 1 : 0);
- $subhub = (($ret['network'] === Protocol::OSTATUS) ? true : false);
+ $subhub = (($protocol === Protocol::OSTATUS) ? true : false);
- $hidden = (($ret['network'] === Protocol::MAIL) ? 1 : 0);
+ $hidden = (($protocol === Protocol::MAIL) ? 1 : 0);
- $pending = in_array($ret['network'], [Protocol::ACTIVITYPUB]);
+ $pending = in_array($protocol, [Protocol::ACTIVITYPUB]);
- if (in_array($ret['network'], [Protocol::MAIL, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
+ if (in_array($protocol, [Protocol::MAIL, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
$writeable = 1;
}
$fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false];
DBA::update('contact', $fields, ['id' => $contact['id']]);
} else {
- $new_relation = (in_array($ret['network'], [Protocol::MAIL]) ? self::FRIEND : self::SHARING);
+ $new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING);
// create contact record
DBA::insert('contact', [
'name' => $ret['name'],
'nick' => $ret['nick'],
'network' => $ret['network'],
+ 'protocol' => $protocol,
'pubkey' => $ret['pubkey'],
'rel' => $new_relation,
'priority'=> $ret['priority'],
$owner = User::getOwnerDataById($uid);
if (DBA::isResult($owner)) {
- if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DFRN])) {
+ if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create a follow slap
$item = [];
$item['verb'] = ACTIVITY_FOLLOW;
if (!empty($contact['notify'])) {
Salmon::slapper($owner, $contact['notify'], $slap);
}
- } elseif ($contact['network'] == Protocol::DIASPORA) {
+ } elseif ($protocol == Protocol::DIASPORA) {
$ret = Diaspora::sendShare($a->user, $contact);
Logger::log('share returns: ' . $ret);
- } elseif ($contact['network'] == Protocol::ACTIVITYPUB) {
+ } elseif ($protocol == Protocol::ACTIVITYPUB) {
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
if (empty($activity_id)) {
// This really should never happen
return $contact;
}
- public static function addRelationship($importer, $contact, $datarray, $item = '', $sharing = false) {
+ public static function addRelationship($importer, $contact, $datarray, $item = '', $sharing = false, $note = '') {
// Should always be set
if (empty($datarray['author-id'])) {
return;
$network = $pub_contact['network'];
if (is_array($contact)) {
+ // Make sure that the existing contact isn't archived
+ self::unmarkForArchival($contact);
+
+ $protocol = self::getProtocol($url, $contact['network']);
+
if (($contact['rel'] == self::SHARING)
|| ($sharing && $contact['rel'] == self::FOLLOWER)) {
- DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true],
+ DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
['id' => $contact['id'], 'uid' => $importer['uid']]);
}
- if ($contact['network'] == Protocol::ACTIVITYPUB) {
+ if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']);
}
// send email notification to owner?
} else {
+ $protocol = self::getProtocol($url, $network);
+
if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($url), 'uid' => $importer['uid'], 'pending' => true])) {
Logger::log('ignoring duplicated connection request from pending contact ' . $url);
return;
if (is_array($contact_record)) {
DBA::insert('intro', ['uid' => $importer['uid'], 'contact-id' => $contact_record['id'],
- 'blocked' => false, 'knowyou' => false,
+ 'blocked' => false, 'knowyou' => false, 'note' => $note,
'hash' => $hash, 'datetime' => DateTimeFormat::utcNow()]);
}
DBA::update('contact', ['pending' => false], $condition);
$contact = DBA::selectFirst('contact', ['url', 'network', 'hub-verify'], ['id' => $contact_record['id']]);
+ $protocol = self::getProtocol($contact['url'], $contact['network']);
- if ($contact['network'] == Protocol::ACTIVITYPUB) {
+ if ($protocol == Protocol::ACTIVITYPUB) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']);
}
}
$cid = Contact::getIdForURL($activity['actor'], $uid);
if (!empty($cid)) {
self::switchContact($cid);
- DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]);
+ DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
$contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
} else {
$contact = false;
$item = ['author-id' => Contact::getIdForURL($activity['actor']),
'author-link' => $activity['actor']];
+ $note = Strings::escapeTags(trim(defaults($activity, 'content', '')));
+
// Ensure that the contact has got the right network type
self::switchContact($item['author-id']);
- Contact::addRelationship($owner, $contact, $item);
+ Contact::addRelationship($owner, $contact, $item, '', false, $note);
$cid = Contact::getIdForURL($activity['actor'], $uid);
if (empty($cid)) {
return;
}
if (empty($contact)) {
- DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]);
+ DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
}
Logger::log('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
self::switchContact($cid);
- if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) {
+ if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING])) {
Contact::remove($cid);
Logger::log('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', Logger::DEBUG);
} else {
private static function switchContact($cid)
{
$contact = DBA::selectFirst('contact', ['network'], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
- if (!DBA::isResult($contact) || ($contact['network'] == Protocol::ACTIVITYPUB)) {
+ if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
return;
}
return;
}
+ if (($contact['network'] == Protocol::DFRN) && !Contact::isLegacyDFRNContact($contact)) {
+ $protocol = Protocol::ACTIVITYPUB;
+ } else {
+ $protocol = $contact['network'];
+ }
+
$importer_uid = $contact['uid'];
// Possibly switch the remote contact to AP
- if ($contact['network'] === Protocol::OSTATUS) {
+ if ($protocol === Protocol::OSTATUS) {
ActivityPub\Receiver::switchContact($contact['id'], $importer_uid, $contact['url']);
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
}
+ $updated = DateTimeFormat::utcNow();
+
// These three networks can be able to speak AP, so we are trying to fetch AP profile data here
- if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN])) {
+ if (in_array($protocol, [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN])) {
$apcontact = APContact::getByURL($contact['url'], true);
- $updated = DateTimeFormat::utcNow();
- if (($contact['network'] === Protocol::ACTIVITYPUB) && empty($apcontact)) {
+ if (($protocol === Protocol::ACTIVITYPUB) && empty($apcontact)) {
self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
Contact::markForArchival($contact);
Logger::log('Contact archived');
}
// Diaspora users, archived users and followers are only checked if they still exist.
- if (($contact['network'] != Protocol::ACTIVITYPUB) && ($contact['archive'] || ($contact["network"] == Protocol::DIASPORA) || ($contact["rel"] == Contact::FOLLOWER))) {
+ if (($protocol != Protocol::ACTIVITYPUB) && ($contact['archive'] || ($contact["network"] == Protocol::DIASPORA) || ($contact["rel"] == Contact::FOLLOWER))) {
$last_updated = PortableContact::lastUpdated($contact["url"], true);
- $updated = DateTimeFormat::utcNow();
if ($last_updated) {
Logger::log('Contact '.$contact['id'].' had last update on '.$last_updated, Logger::DEBUG);
}
// Update the contact entry
- if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
- $updated = DateTimeFormat::utcNow();
+ if (in_array($protocol, [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
// Currently we can't check every AP implementation, so we don't do it at all
- if (($contact['network'] != Protocol::ACTIVITYPUB) && !PortableContact::reachable($contact['url'])) {
+ if (($protocol != Protocol::ACTIVITYPUB) && !PortableContact::reachable($contact['url'])) {
Logger::log("Skipping probably dead contact ".$contact['url']);
// set the last-update so we don't keep polling
Logger::log("Don't poll follower");
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return;
}
// Don't poll if polling is deactivated (But we poll feeds and mails anyway)
- if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) {
+ if (!in_array($protocol, [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) {
Logger::log('Polling is disabled');
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return;
}
// We don't poll AP contacts by now
- if ($contact['network'] === Protocol::ACTIVITYPUB) {
+ if ($protocol === Protocol::ACTIVITYPUB) {
Logger::log("Don't poll AP contact");
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return;
}
Logger::log('Ignore public contacts');
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return;
}
Logger::log('No self contact for user '.$importer_uid);
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
return;
}
: DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM)
);
- Logger::log("poll: ({$contact['network']}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
+ Logger::log("poll: ({$protocol}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
- if ($contact['network'] === Protocol::DFRN) {
+ if ($protocol === Protocol::DFRN) {
$idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
if (intval($contact['duplex']) && $contact['dfrn-id']) {
$idtosend = '0:' . $orig_id;
if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) {
// set the last-update so we don't keep polling
- self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
+ self::updateContact($contact, ['last-update' => $updated]);
Contact::markForArchival($contact);
Logger::log('Contact archived');
return;
Logger::log("$url appears to be dead - marking for death ");
// set the last-update so we don't keep polling
- $fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()];
+ $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields);
Contact::markForArchival($contact);
return;
if (!strstr($handshake_xml, '<')) {
Logger::log('response from ' . $url . ' did not contain XML.');
- $fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()];
+ $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields);
Contact::markForArchival($contact);
return;
Logger::log("$url replied status 1 - marking for death ");
// set the last-update so we don't keep polling
- $fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()];
+ $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields);
Contact::markForArchival($contact);
} elseif ($contact['term-date'] > DBA::NULL_DATETIME) {
if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
Logger::log('Contact status is ' . $res->status);
return;
}
Logger::log('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
Contact::markForArchival($contact);
return;
}
$xml = Network::post($contact['poll'], $postvars)->getBody();
- } elseif (($contact['network'] === Protocol::OSTATUS)
- || ($contact['network'] === Protocol::DIASPORA)
- || ($contact['network'] === Protocol::FEED)) {
+ } elseif (($protocol === Protocol::OSTATUS)
+ || ($protocol === Protocol::DIASPORA)
+ || ($protocol === Protocol::FEED)) {
// Upgrading DB fields from an older Friendica version
// Will only do this once per notify-enabled OStatus contact
$stat_writeable = ((($contact['notify']) && ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND)) ? 1 : 0);
// Contacts from OStatus are always writable
- if ($contact['network'] === Protocol::OSTATUS) {
+ if ($protocol === Protocol::OSTATUS) {
$stat_writeable = 1;
}
// Are we allowed to import from this person?
if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) {
// set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
Logger::log('Contact is blocked or only a follower');
return;
}
if ($curlResult->isTimeout()) {
// set the last-update so we don't keep polling
- self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
+ self::updateContact($contact, ['last-update' => $updated]);
Contact::markForArchival($contact);
Logger::log('Contact archived');
return;
$xml = $curlResult->getBody();
- } elseif ($contact['network'] === Protocol::MAIL) {
+ } elseif ($protocol === Protocol::MAIL) {
Logger::log("Mail: Fetching for ".$contact['addr'], Logger::DEBUG);
$mail_disabled = ((function_exists('imap_open') && !Config::get('system', 'imap_disabled')) ? 0 : 1);
if ($mail_disabled) {
// set the last-update so we don't keep polling
- self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
+ self::updateContact($contact, ['last-update' => $updated]);
Contact::markForArchival($contact);
Logger::log('Contact archived');
return;
unset($password);
Logger::log("Mail: Connect to " . $mailconf['user']);
if ($mbox) {
- $fields = ['last_check' => DateTimeFormat::utcNow()];
+ $fields = ['last_check' => $updated];
DBA::update('mailacct', $fields, ['id' => $mailconf['id']]);
Logger::log("Mail: Connected to " . $mailconf['user']);
} else {
// Only delete when mails aren't automatically moved or deleted
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
if ($meta->deleted && ! $item['deleted']) {
- $fields = ['deleted' => true, 'changed' => DateTimeFormat::utcNow()];
+ $fields = ['deleted' => true, 'changed' => $updated];
Item::update($fields, ['id' => $item['id']]);
}
if ($datarray['parent-uri'] === $datarray['uri']) {
$datarray['private'] = 1;
}
- if (($contact['network'] === Protocol::MAIL) && !PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) {
+ if (($protocol === Protocol::MAIL) && !PConfig::get($importer_uid, 'system', 'allow_public_email_replies')) {
$datarray['private'] = 1;
$datarray['allow_cid'] = '<' . $contact['id'] . '>';
}
if (!strstr($xml, '<')) {
Logger::log('post_handshake: response from ' . $url . ' did not contain XML.');
- $fields = ['last-update' => DateTimeFormat::utcNow(), 'failure_update' => DateTimeFormat::utcNow()];
+ $fields = ['last-update' => $updated, 'failure_update' => $updated];
self::updateContact($contact, $fields);
Contact::markForArchival($contact);
return;
consume_feed($xml, $importer, $contact, $hub);
// do it a second time for DFRN so that any children find their parents.
- if ($contact['network'] === Protocol::DFRN) {
+ if ($protocol === Protocol::DFRN) {
consume_feed($xml, $importer, $contact, $hub);
}
$hubmode = 'subscribe';
- if ($contact['network'] === Protocol::DFRN || $contact['blocked']) {
+ if ($protocol === Protocol::DFRN || $contact['blocked']) {
$hubmode = 'unsubscribe';
}
- if (($contact['network'] === Protocol::OSTATUS || $contact['network'] == Protocol::FEED) && (! $contact['hub-verify'])) {
+ if (($protocol === Protocol::OSTATUS || $protocol == Protocol::FEED) && (! $contact['hub-verify'])) {
$hub_update = true;
}
$hub_update = true;
}
- Logger::log("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update);
+ Logger::log("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$protocol." Relation: ".$contact['rel']." Update: ".$hub_update);
- if (strlen($hub) && $hub_update && (($contact['rel'] != Contact::FOLLOWER) || $contact['network'] == Protocol::FEED)) {
+ if (strlen($hub) && $hub_update && (($contact['rel'] != Contact::FOLLOWER) || $protocol == Protocol::FEED)) {
Logger::log('hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
$hubs = explode(',', $hub);
}
}
- $updated = DateTimeFormat::utcNow();
-
self::updateContact($contact, ['last-update' => $updated, 'success_update' => $updated]);
DBA::update('gcontact', ['last_contact' => $updated], ['nurl' => $contact['nurl']]);
Contact::unmarkForArchival($contact);
} elseif (in_array($contact["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED])) {
- $updated = DateTimeFormat::utcNow();
-
self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
DBA::update('gcontact', ['last_failure' => $updated], ['nurl' => $contact['nurl']]);
Contact::markForArchival($contact);
} else {
- self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
+ self::updateContact($contact, ['last-update' => $updated]);
}
Logger::log('End');