$fields['forum'] = $user['page-flags'] == PAGE_COMMUNITY;
$fields['prv'] = $user['page-flags'] == PAGE_PRVGROUP;
+ // it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
+ $fields['url'] = System::baseUrl() . '/profile/' . $user['nickname'];
+ $fields['nurl'] = normalise_link($fields['url']);
+ $fields['addr'] = $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
+ $fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname'];
+ $fields['notify'] = System::baseUrl() . '/dfrn_notify/' . $user['nickname'];
+ $fields['poll'] = System::baseUrl() . '/dfrn_poll/' . $user['nickname'];
+ $fields['confirm'] = System::baseUrl() . '/dfrn_confirm/' . $user['nickname'];
+ $fields['poco'] = System::baseUrl() . '/poco/' . $user['nickname'];
+
$update = false;
foreach ($fields as $field => $content) {
// Update the public contact as well
dba::update('contact', $fields, ['uid' => 0, 'nurl' => $self['nurl']]);
+
+ // Update the profile
+ $fields = ['photo' => System::baseUrl() . '/photo/profile/' .$uid . '.jpg',
+ 'thumb' => System::baseUrl() . '/photo/avatar/' . $uid .'.jpg'];
+ dba::update('profile', $fields, ['uid' => $uid, 'is-default' => true]);
}
}
*/
/// @todo Check for contact vitality via probing
- $expiry = $contact['term-date'] . ' + 32 days ';
+ $archival_days = Config::get('system', 'archival_days', 32);
+
+ $expiry = $contact['term-date'] . ' + ' . $archival_days . ' days ';
if (DateTimeFormat::utcNow() > DateTimeFormat::utc($expiry)) {
/* Relationship is really truly dead. archive them rather than
* delete, though if the owner tries to unarchive them we'll start
$fields = ['term-date' => NULL_DATE, 'archive' => false];
dba::update('contact', $fields, ['id' => $contact['id']]);
- if ($contact['url'] != '') {
+ if (!empty($contact['url'])) {
dba::update('contact', $fields, ['nurl' => normalise_link($contact['url'])]);
}
+
+ if (!empty($contact['batch'])) {
+ $condition = ['batch' => $contact['batch'], 'contact-type' => ACCOUNT_TYPE_RELAY];
+ dba::update('contact', $fields, $condition);
+ }
}
/**
// Fetch the data from the gcontact table
if (!DBM::is_result($r)) {
$s = dba::p("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
- `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
+ `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, 0 AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
FROM `gcontact` WHERE `nurl` = ?", normalise_link($url));
$r = dba::inArray($s);
}
* @param string $url Contact URL
* @param integer $uid The user id for the contact (0 = public contact)
* @param boolean $no_update Don't update the contact
+ * @param array $default Default value for creating the contact when every else fails
*
* @return integer Contact ID
*/
- public static function getIdForURL($url, $uid = 0, $no_update = false)
+ public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [])
{
logger("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), LOGGER_DEBUG);
$data = Probe::uri($url, "", $uid);
// Last try in gcontact for unsupported networks
- if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO, NETWORK_MAIL])) {
+ if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO, NETWORK_MAIL, NETWORK_FEED])) {
if ($uid != 0) {
return 0;
}
// Get data from the gcontact table
- $gcontact = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
- if (!DBM::is_result($gcontact)) {
- return 0;
+ $fields = ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'];
+ $contact = dba::selectFirst('gcontact', $fields, ['nurl' => normalise_link($url)]);
+ if (!DBM::is_result($contact)) {
+ $contact = dba::selectFirst('contact', $fields, ['nurl' => normalise_link($url)]);
+ }
+
+ if (!DBM::is_result($contact)) {
+ $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
+ 'photo', 'keywords', 'location', 'about', 'network',
+ 'priority', 'batch', 'request', 'confirm', 'poco'];
+ $contact = dba::selectFirst('contact', $fields, ['addr' => $url]);
+ }
+
+ if (!DBM::is_result($contact)) {
+ // The link could be provided as http although we stored it as https
+ $ssl_url = str_replace('http://', 'https://', $url);
+ $condition = ['alias' => [$url, normalise_link($url), $ssl_url]];
+ $contact = dba::selectFirst('contact', $fields, $condition);
}
- $data = array_merge($data, $gcontact);
+ if (!DBM::is_result($contact)) {
+ $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
+ 'photo', 'network', 'priority', 'batch', 'request', 'confirm'];
+ $condition = ['url' => [$url, normalise_link($url), $ssl_url]];
+ $contact = dba::selectFirst('fcontact', $fields, $condition);
+ }
+
+ if (!empty($default)) {
+ $contact = $default;
+ }
+
+ if (!DBM::is_result($contact)) {
+ return 0;
+ } else {
+ $data = array_merge($data, $contact);
+ }
}
if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
$contact = ($r[0]["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
- $r = q(item_query() . " AND `item`.`" . $contact . "` = %d AND " . $sql .
+ $r = q(item_query(local_user()) . " AND `item`.`" . $contact . "` = %d AND " . $sql .
" AND `item`.`verb` = '%s' ORDER BY `item`.`created` DESC LIMIT %d, %d",
intval($author_id), intval(local_user()), dbesc(ACTIVITY_POST),
intval($a->pager['start']), intval($a->pager['itemspage'])
if (($network != '') && ($ret['network'] != $network)) {
logger('Expected network ' . $network . ' does not match actual network ' . $ret['network']);
- return result;
+ return $result;
}
// check if we already have a contact
}
// send email notification to owner?
} else {
+ if (dba::exists('contact', ['nurl' => normalise_link($url), 'uid' => $importer['uid'], 'pending' => true])) {
+ logger('ignoring duplicated connection request from pending contact ' . $url);
+ return;
+ }
+
// create contact record
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
`blocked`, `readonly`, `pending`, `writable`)