From 7af4edc1370db79d7611fc023352adb6405c8d00 Mon Sep 17 00:00:00 2001 From: nobody Date: Fri, 12 Mar 2021 14:20:57 -0800 Subject: [PATCH 1/3] Some pleroma servers sending back photos as application/octet-stream --- include/photo_factory.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/photo_factory.php b/include/photo_factory.php index 56e569ee5..aa3d36316 100644 --- a/include/photo_factory.php +++ b/include/photo_factory.php @@ -367,7 +367,14 @@ function import_remote_xchan_photo($photo, $xchan, $thing = false) { if ($result['success']) { $type = guess_image_type($photo, $result['header']); - + if ((! $type) || strpos($type,'image') === false) { + @file_put_contents('cache/' . $hash, $result['body']); + $info = getimagesize('cache/' . $hash); + @unlink('cache/' . $hash); + if (isset($info) && array_key_exists('mime',$info)) { + $type = $info['mime']; + } + } if ($type) { $failed = false; } From 073db32fe1f67d13d62aba4e276c543e251ceba9 Mon Sep 17 00:00:00 2001 From: nobody Date: Fri, 12 Mar 2021 14:26:56 -0800 Subject: [PATCH 2/3] minor tweaks (php8 cont.) --- Zotlabs/Lib/Activity.php | 5 +++-- Zotlabs/Lib/ActivityPub.php | 2 +- Zotlabs/Module/Connedit.php | 29 ++++++++++++----------------- Zotlabs/Web/HTTPHeaders.php | 1 - 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 04377123b..91fe6cf7d 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1796,10 +1796,11 @@ class Activity { } } } - else + else ( $icon = $person_obj['icon']; + } } - if (! $icon) { + if (! (isset($icon) && $icon)) { $icon = z_root() . '/' . get_default_profile_photo(); } diff --git a/Zotlabs/Lib/ActivityPub.php b/Zotlabs/Lib/ActivityPub.php index 05acb067b..5cc2fb6d3 100644 --- a/Zotlabs/Lib/ActivityPub.php +++ b/Zotlabs/Lib/ActivityPub.php @@ -481,7 +481,7 @@ class ActivityPub { } } } - if ($person_obj) { + if (isset($person_obj)) { Activity::actor_store($person_obj['id'],$person_obj, $force); return $person_obj['id']; } diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index efa930879..6c546c86b 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -361,7 +361,7 @@ class Connedit extends Controller { intval(local_channel()) ); - if(! $orig_record) { + if (! $orig_record) { notice( t('Could not access address book record.') . EOL); goaway(z_root() . '/connections'); } @@ -374,25 +374,21 @@ class Connedit extends Controller { goaway(z_root() . '/connedit/' . $contact_id); } - if($cmd === 'fetchvc') { + if ($cmd === 'fetchvc') { $url = str_replace('/channel/','/profile/',$orig_record['xchan_url']) . '/vcard'; $recurse = 0; $x = z_fetch_url(zid($url),false,$recurse,['session' => true]); if ($x['success']) { $h = new HTTPHeaders($x['header']); - $fields = $h->fetch(); - if ($fields) { - foreach ($fields as $y) { - if (array_key_exists('content-type',$y)) { - $type = explode(';',trim($y['content-type'])); - if ($type && $type[0] === 'text/vcard' && $x['body']) { - $vc = Reader::read($x['body']); - $vcard = $vc->serialize(); - if ($vcard) { - set_abconfig(local_channel(),$orig_record['abook_xchan'],'system','vcard',$vcard); - $this->connedit_clone($a); - } - } + $fields = $h->fetcharr(); + if ($fields && array_key_exists('content-type',$fields)) { + $type = explode(';',trim($fields['content-type'])); + if ($type && $type[0] === 'text/vcard' && $x['body']) { + $vc = Reader::read($x['body']); + $vcard = $vc->serialize(); + if ($vcard) { + set_abconfig(local_channel(),$orig_record['abook_xchan'],'system','vcard',$vcard); + $this->connedit_clone($a); } } } @@ -493,7 +489,7 @@ class Connedit extends Controller { Libsync::build_sync_packet(0, [ 'abook' => [ 'abook_xchan' => $orig_record['abook_xchan'], 'entry_deleted' => true ] ] ); info( t('Connection has been removed.') . EOL ); - if (x($_SESSION,'return_url')) { + if (isset($_SESSION['return_url']) && $_SESSION['return_url']) { goaway(z_root() . '/' . $_SESSION['return_url']); } goaway(z_root() . '/contacts'); @@ -623,7 +619,6 @@ class Connedit extends Controller { ]; } - $sections = []; $sections['perms'] = [ diff --git a/Zotlabs/Web/HTTPHeaders.php b/Zotlabs/Web/HTTPHeaders.php index 551ae94d0..832e82dfa 100644 --- a/Zotlabs/Web/HTTPHeaders.php +++ b/Zotlabs/Web/HTTPHeaders.php @@ -51,7 +51,6 @@ class HTTPHeaders { } } } - logger('fetcharr: ' . print_r($ret,true)); return $ret; } From 169dae482a2ba54aa5c3099e29d6ecc0dc4e2c3a Mon Sep 17 00:00:00 2001 From: nobody Date: Fri, 12 Mar 2021 14:37:18 -0800 Subject: [PATCH 3/3] typo --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 91fe6cf7d..6f6859476 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1796,7 +1796,7 @@ class Activity { } } } - else ( + else { $icon = $person_obj['icon']; } }