From 76a420fbe95915d94ffba310be664fa05a4c49a9 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Jun 2019 05:26:16 +0000 Subject: [PATCH 1/2] Avoid fatal error when AP contact has no photo --- src/Model/APContact.php | 18 +++++++++++++----- src/Model/Photo.php | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 67c714f9af..c308da3889 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -152,7 +152,13 @@ class APContact extends BaseObject $apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id'); } - if (empty($apcontact['url']) || empty($apcontact['inbox'])) { + // Quit if none of the basic values are set + if (empty($apcontact['url']) || empty($apcontact['inbox']) || empty($apcontact['type'])) { + return false; + } + + // Quit if this doesn't seem to be an account at all + if (!in_array($apcontact['type'], ActivityPub::ACCOUNT_TYPES)) { return false; } @@ -228,11 +234,13 @@ class APContact extends BaseObject DBA::update('contact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]); - $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]); - while ($contact = DBA::fetch($contacts)) { - Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); + if (!empty($apcontact['photo'])) { + $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]); + while ($contact = DBA::fetch($contacts)) { + Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); + } + DBA::close($contacts); } - DBA::close($contacts); // Update the gcontact table // These two fields don't exist in the gcontact table diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 8ad7f3145f..2d740e1378 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -413,7 +413,11 @@ class Photo extends BaseObject $photo_failure = false; $filename = basename($image_url); - $img_str = Network::fetchUrl($image_url, true); + if (!empty($image_url)) { + $img_str = Network::fetchUrl($image_url, true); + } else { + $img_str = ''; + } if ($quit_on_error && ($img_str == "")) { return false; From 9d8f01c49c12de4cba6515781d150ce1123206e3 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Jun 2019 06:02:18 +0000 Subject: [PATCH 2/2] Fix another fatal error --- src/Protocol/ActivityPub/Transmitter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 06dbaee71f..5f33257113 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -436,7 +436,7 @@ class Transmitter $data['to'][] = $profile['url']; } else { $data['cc'][] = $profile['url']; - if (!$item['private']) { + if (!$item['private'] && !empty($actor_profile['followers'])) { $data['cc'][] = $actor_profile['followers']; } }