]> git.mxchange.org Git - friendica.git/commitdiff
Avoid fatal error when AP contact has no photo
authorMichael <heluecht@pirati.ca>
Tue, 11 Jun 2019 05:26:16 +0000 (05:26 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 11 Jun 2019 05:26:16 +0000 (05:26 +0000)
src/Model/APContact.php
src/Model/Photo.php

index 67c714f9afd29d00a211295a0ec5f78c0a0a6838..c308da3889cec771e62cb66516a45d3c3fafc350 100644 (file)
@@ -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
index 8ad7f3145f3d8c30d593c3b1b34c24999774171a..2d740e137858c9e4d47059eb8d75818d3be032ad 100644 (file)
@@ -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;