X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=fe373ae94a737923b3bc21be033e99a231b4ceaf;hb=0c8c97171affb924b1153264474664925ec8acba;hp=2d6bc716bb11338fdbffcc2af290b66ff1fa090c;hpb=d6a82c6c2d7befde9914fce3bd4e3e07b97ca036;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 2d6bc716bb..fe373ae94a 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -109,6 +109,16 @@ class Contact extends BaseObject * @} */ + /** + * @param integer $id + * @return array|boolean Contact record if it exists, false otherwise + * @throws \Exception + */ + public static function getById($id) + { + return DBA::selectFirst('contact', [], ['id' => $id]); + } + /** * @brief Tests if the given contact is a follower * @@ -232,6 +242,11 @@ class Contact extends BaseObject } DBA::update('user-contact', ['blocked' => $blocked], ['cid' => $cdata['public'], 'uid' => $uid], true); + + if ($blocked) { + // Blocked contact can't be in any group + self::removeFromGroups($cid); + } } /** @@ -616,7 +631,7 @@ class Contact extends BaseObject DBA::update('contact', ['archive' => true, 'network' => Protocol::PHANTOM, 'deleted' => true], ['id' => $id]); // Delete it in the background - Worker::add(PRIORITY_LOW, 'RemoveContact', $id); + Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $id); } /** @@ -1001,7 +1016,7 @@ class Contact extends BaseObject $sparkle = false; if (($contact['network'] === Protocol::DFRN) && !$contact['self']) { $sparkle = true; - $profile_link = System::baseUrl() . '/redir/' . $contact['id']; + $profile_link = System::baseUrl() . '/redir/' . $contact['id'] . '?url=' . $contact['url']; } else { $profile_link = $contact['url']; } @@ -1011,9 +1026,9 @@ class Contact extends BaseObject } if ($sparkle) { - $status_link = $profile_link . '?url=status'; - $photos_link = $profile_link . '?url=photos'; - $profile_link = $profile_link . '?url=profile'; + $status_link = $profile_link . '?tab=status'; + $photos_link = str_replace('/profile/', '/photos/', $profile_link); + $profile_link = $profile_link . '?tab=profile'; } if (in_array($contact['network'], [Protocol::DFRN, Protocol::DIASPORA]) && !$contact['self']) { @@ -1619,27 +1634,35 @@ class Contact extends BaseObject /** * @param integer $id contact id * @param string $network Optional network we are probing for + * @param boolean $force Optional forcing of network probing (otherwise we use the cached data) * @return boolean * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function updateFromProbe($id, $network = '') + public static function updateFromProbe($id, $network = '', $force = false) { /* Warning: Never ever fetch the public key via Probe::uri and write it into the contacts. This will reliably kill your communication with Friendica contacts. */ - $fields = ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network']; + $fields = ['avatar', 'uid', 'name', 'nick', 'url', 'addr', 'batch', 'notify', + 'poll', 'request', 'confirm', 'poco', 'network', 'alias']; $contact = DBA::selectFirst('contact', $fields, ['id' => $id]); if (!DBA::isResult($contact)) { return false; } - $ret = Probe::uri($contact["url"], $network); + $uid = $contact['uid']; + unset($contact['uid']); + + $contact['photo'] = $contact['avatar']; + unset($contact['avatar']); + + $ret = Probe::uri($contact['url'], $network, $uid, !$force); // If Probe::uri fails the network code will be different (mostly "feed" or "unkn") - if (($ret["network"] != $contact["network"]) && !in_array($ret["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, $network])) { + if ((in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($ret['network'] != $contact['network'])) { return false; } @@ -1647,11 +1670,11 @@ class Contact extends BaseObject // make sure to not overwrite existing values with blank entries foreach ($ret as $key => $val) { - if (isset($contact[$key]) && ($contact[$key] != "") && ($val == "")) { + if (!isset($contact[$key])) { + unset($ret[$key]); + } elseif (($contact[$key] != '') && ($val == '')) { $ret[$key] = $contact[$key]; - } - - if (isset($contact[$key]) && ($ret[$key] != $contact[$key])) { + } elseif ($ret[$key] != $contact[$key]) { $update = true; } } @@ -1660,20 +1683,12 @@ class Contact extends BaseObject return true; } - DBA::update( - 'contact', [ - 'url' => $ret['url'], - 'nurl' => Strings::normaliseLink($ret['url']), - 'network' => $ret['network'], - 'addr' => $ret['addr'], - 'alias' => $ret['alias'], - 'batch' => $ret['batch'], - 'notify' => $ret['notify'], - 'poll' => $ret['poll'], - 'poco' => $ret['poco'] - ], - ['id' => $id] - ); + $ret['nurl'] = Strings::normaliseLink($ret['url']); + + self::updateAvatar($ret['photo'], $uid, $id, true); + + unset($ret['photo']); + DBA::update('contact', $ret, ['id' => $id]); // Update the corresponding gcontact entry PortableContact::lastUpdated($ret["url"]); @@ -2184,7 +2199,7 @@ class Contact extends BaseObject { $contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], ['id' => $cid]); - return self::magicLinkbyContact($contact, $url); + return self::magicLinkByContact($contact, $url); } /** @@ -2197,7 +2212,7 @@ class Contact extends BaseObject * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function magicLinkbyContact($contact, $url = '') + public static function magicLinkByContact($contact, $url = '') { if ((!local_user() && !remote_user()) || ($contact['network'] != Protocol::DFRN)) { return $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url']; @@ -2220,4 +2235,36 @@ class Contact extends BaseObject return $redirect; } + + /** + * Remove a contact from all groups + * + * @param integer $contact_id + * + * @return boolean Success + */ + public static function removeFromGroups($contact_id) + { + return DBA::delete('group_member', ['contact-id' => $contact_id]); + } + + /** + * Is the contact a forum? + * + * @param integer $contactid ID of the contact + * + * @return boolean "true" if it is a forum + */ + public static function isForum($contactid) + { + $fields = ['forum', 'prv']; + $condition = ['id' => $contactid]; + $contact = DBA::selectFirst('contact', $fields, $condition); + if (!DBA::isResult($contact)) { + return false; + } + + // Is it a forum? + return ($contact['forum'] || $contact['prv']); + } }