X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=f35808f050c9843986cabf3be7f3f25d6bf0c1b7;hb=bbb5440144a6a8421350ef6c0176be9c05df5527;hp=e847ce034666cf458ce7121363127af7f5d8eac1;hpb=79d15066945d58709ffc9b8fd1f8eac9b96695ee;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index e847ce0346..f35808f050 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -243,15 +243,13 @@ class Contact * @throws \Exception * @todo Let's get rid of boolean type of $old_fields */ - public static function update(array $fields, array $condition, $old_fields = []) + public static function update(array $fields, array $condition, $old_fields = []): bool { - $fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields); - $ret = DBA::update('contact', $fields, $condition, $old_fields); - // Apply changes to the "user-contact" table on dedicated fields Contact\User::updateByContactUpdate($fields, $condition); - return $ret; + $fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields); + return DBA::update('contact', $fields, $condition, $old_fields); } /** @@ -572,7 +570,7 @@ class Contact { if (!parse_url($url, PHP_URL_SCHEME)) { $addr_parts = explode('@', $url); - return (count($addr_parts) == 2) && ($addr_parts[1] == DI::baseUrl()->getHostname()); + return (count($addr_parts) == 2) && ($addr_parts[1] == DI::baseUrl()->getHost()); } return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl()); @@ -2206,20 +2204,38 @@ class Contact return; } + if (!Network::isValidHttpUrl($avatar)) { + Logger::warning('Invalid avatar', ['cid' => $cid, 'avatar' => $avatar]); + $avatar = ''; + } + $uid = $contact['uid']; // Only update the cached photo links of public contacts when they already are cached if (($uid == 0) && !$force && empty($contact['thumb']) && empty($contact['micro']) && !$create_cache) { if (($contact['avatar'] != $avatar) || empty($contact['blurhash'])) { $update_fields = ['avatar' => $avatar]; - $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); - - $img_str = $fetchResult->getBody(); - if (!empty($img_str)) { - $image = new Image($img_str, Images::getMimeTypeByData($img_str)); - if ($image->isValid()) { - $update_fields['blurhash'] = $image->getBlurHash(); + if (!Network::isLocalLink($avatar)) { + try { + $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); + + $img_str = $fetchResult->getBody(); + if (!empty($img_str)) { + $image = new Image($img_str, Images::getMimeTypeByData($img_str)); + if ($image->isValid()) { + $update_fields['blurhash'] = $image->getBlurHash(); + } else { + return; + } + } + } catch (\Exception $exception) { + Logger::notice('Error fetching avatar', ['avatar' => $avatar, 'exception' => $exception]); + return; } + } elseif (!empty($contact['blurhash'])) { + $update_fields['blurhash'] = null; + } else { + return; } self::update($update_fields, ['id' => $cid]); @@ -2970,7 +2986,7 @@ class Contact } // check if we already have a contact - $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url'])]; + $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url']), 'deleted' => false]; $contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition); $protocol = self::getProtocol($ret['url'], $ret['network']); @@ -3293,7 +3309,7 @@ class Contact if ($contact['rel'] == self::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) { self::remove($contact['id']); } else { - self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]); + self::update(['rel' => self::FOLLOWER, 'pending' => false], ['id' => $contact['id']]); } Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $contact['uid']);