return DBA::selectFirst('contact', $fields, ['id' => $id]);
}
+ /**
+ * Fetches a contact by a given url
+ *
+ * @param string $url profile url
+ * @param integer $uid User ID of the contact
+ * @param array $fields Field list
+ * @param boolean $update true = always update, false = never update, null = update when not found or outdated
+ * @return array contact array
+ */
+ public static function getByURL(string $url, int $uid = 0, array $fields = [], $update = null)
+ {
+ if ($update || is_null($update)) {
+ $cid = self::getIdForURL($url, $uid, !($update ?? false));
+ if (empty($cid)) {
+ return [];
+ }
+ return self::getById($cid, $fields);
+ }
+
+ // We first try the nurl (http://server.tld/nick), most common case
+ $options = ['order' => ['id']];
+ $contact = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false], $options);
+
+ // Then the addr (nick@server.tld)
+ if (!DBA::isResult($contact)) {
+ $contact = DBA::selectFirst('contact', $fields, ['addr' => str_replace('acct:', '', $url), 'uid' => $uid, 'deleted' => false], $options);
+ }
+
+ // Then the alias (which could be anything)
+ if (!DBA::isResult($contact)) {
+ // The link could be provided as http although we stored it as https
+ $ssl_url = str_replace('http://', 'https://', $url);
+ $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
+ $contact = DBA::selectFirst('contact', $fields, $condition, $options);
+ }
+ return $contact;
+ }
+
/**
* Tests if the given contact is a follower
*
// create an unfollow slap
$item = [];
$item['verb'] = Activity::O_UNFOLLOW;
+ $item['gravity'] = GRAVITY_ACTIVITY;
$item['follow'] = $contact["url"];
$item['body'] = '';
$item['title'] = '';
return;
}
} elseif (!isset($contact['url'])) {
- Logger::log('Empty contact: ' . json_encode($contact) . ' - ' . System::callstack(20), Logger::DEBUG);
+ Logger::info('Empty contact', ['contact' => $contact, 'callstack' => System::callstack(20)]);
}
- Logger::log('Contact '.$contact['id'].' is marked for archival', Logger::DEBUG);
+ Logger::info('Contact is marked for archival', ['id' => $contact['id']]);
// Contact already archived or "self" contact? => nothing to do
if ($contact['archive'] || $contact['self']) {
return;
}
- Logger::log('Contact '.$contact['id'].' is marked as vital again', Logger::DEBUG);
+ Logger::info('Contact is marked as vital again', ['id' => $contact['id']]);
if (!isset($contact['url']) && !empty($contact['id'])) {
$fields = ['id', 'url', 'batch'];
if (!DBA::isResult($r)) {
$data = Probe::uri($addr);
- $profile = self::getDetailsByURL($data['url'], $uid);
+ $profile = self::getDetailsByURL($data['url'], $uid, $data);
} else {
$profile = $r[0];
}
*/
public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [], $in_loop = false)
{
- Logger::log("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), Logger::DEBUG);
+ Logger::info('Get contact data', ['url' => $url, 'user' => $uid]);
$contact_id = 0;
return 0;
}
- /// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following
- // We first try the nurl (http://server.tld/nick), most common case
- $fields = ['id', 'avatar', 'updated', 'network'];
- $options = ['order' => ['id']];
- $contact = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false], $options);
-
- // Then the addr (nick@server.tld)
- if (!DBA::isResult($contact)) {
- $contact = DBA::selectFirst('contact', $fields, ['addr' => str_replace('acct:', '', $url), 'uid' => $uid, 'deleted' => false], $options);
- }
-
- // Then the alias (which could be anything)
- if (!DBA::isResult($contact)) {
- // The link could be provided as http although we stored it as https
- $ssl_url = str_replace('http://', 'https://', $url);
- $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
- $contact = DBA::selectFirst('contact', $fields, $condition, $options);
- }
+ $contact = self::getByURL($url, $uid, ['id', 'avatar', 'updated', 'network'], false);
- if (DBA::isResult($contact)) {
+ if (!empty($contact)) {
$contact_id = $contact["id"];
$update_contact = false;
$data['gsid'] = GServer::getID($data['baseurl']);
}
- if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $url) && !$in_loop) {
+ if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $data['url']) && !$in_loop) {
$contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
}
$condition = ['uid' => $user['uid'], 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
if (!DBA::isResult($contact)) {
- $condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false];
+ $condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($ret['url']), 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
}
- $protocol = self::getProtocol($url, $ret['network']);
+ $protocol = self::getProtocol($ret['url'], $ret['network']);
if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
if ($interactive) {
if (empty($ret['url'])) {
$result['message'] .= DI::l10n()->t('No browser URL could be matched to this address.') . EOL;
}
- if (strpos($url, '@') !== false) {
+ if (strpos($ret['url'], '@') !== false) {
$result['message'] .= DI::l10n()->t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL;
$result['message'] .= DI::l10n()->t('Use mailto: in front of address to force email check.') . EOL;
}
$pending = false;
if ($protocol == Protocol::ACTIVITYPUB) {
- $apcontact = APContact::getByURL($url, false);
+ $apcontact = APContact::getByURL($ret['url'], false);
if (isset($apcontact['manually-approve'])) {
$pending = (bool)$apcontact['manually-approve'];
}
// create a follow slap
$item = [];
$item['verb'] = Activity::FOLLOW;
+ $item['gravity'] = GRAVITY_ACTIVITY;
$item['follow'] = $contact["url"];
$item['body'] = '';
$item['title'] = '';