X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=d5f63554fb3636c620472156e6108fc1ef873fca;hb=c3a532a9f682d0ceea70e65379018c59cf59efc4;hp=60dec8b2891f9b9a532892ecb790355b138ce59c;hpb=c9f02d534e2016acf18d7fa18db193d056495841;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 60dec8b289..d5f63554fb 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -220,6 +220,11 @@ class Contact extends BaseObject // 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]); } } @@ -306,7 +311,9 @@ class Contact extends BaseObject */ /// @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 @@ -343,9 +350,14 @@ class Contact extends BaseObject $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); + } } /** @@ -411,7 +423,7 @@ class Contact extends BaseObject // 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); } @@ -740,10 +752,11 @@ class Contact extends BaseObject * @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); @@ -792,18 +805,48 @@ class Contact extends BaseObject $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)]); } - $data = array_merge($data, $gcontact); + 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); + } + + 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)) { @@ -1251,7 +1294,7 @@ class Contact extends BaseObject 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 @@ -1470,6 +1513,11 @@ class Contact extends BaseObject } // 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`)