From 07b4cfaeae3b4b429ab4cc1091f9c0478acb2983 Mon Sep 17 00:00:00 2001 From: Miguel Dantas Date: Sat, 13 Jul 2019 02:56:47 +0100 Subject: [PATCH] [Embed] Hide error from the UI and just don't display an image if the remote image is not valid --- lib/imagefile.php | 2 +- plugins/Embed/EmbedPlugin.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/imagefile.php b/lib/imagefile.php index 590f95a739..2d7e85e28c 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -115,7 +115,7 @@ class ImageFile extends MediaFile $media = common_get_mime_media($file->mimetype); if (Event::handle('CreateFileImageThumbnailSource', array($file, &$imgPath, $media))) { if (empty($file->filename) && !file_exists($imgPath)) { - throw new UnsupportedMediaException(_m('File without filename could not get a thumbnail source.')); + throw new FileNotFoundException($imgPath); } // First some mimetype specific exceptions diff --git a/plugins/Embed/EmbedPlugin.php b/plugins/Embed/EmbedPlugin.php index c7cf4d228c..d623e10ae9 100644 --- a/plugins/Embed/EmbedPlugin.php +++ b/plugins/Embed/EmbedPlugin.php @@ -175,12 +175,12 @@ class EmbedPlugin extends Plugin if (isset($url)) { foreach (['xml', 'json'] as $format) { $action->element('link', - array('rel' =>'alternate', - 'type' => "application/{$format}+oembed", - 'href' => common_local_url('oembed', - array(), - array('format' => $format, 'url' => $url)), - 'title' => 'oEmbed')); + ['rel' =>'alternate', + 'type' => "application/{$format}+oembed", + 'href' => common_local_url('oembed', + [], + ['format' => $format, 'url' => $url]), + 'title' => 'oEmbed']); } } return true; @@ -291,6 +291,8 @@ class EmbedPlugin extends Plugin $thumb = $file->getThumbnail(128, 128); $out->element('img', $thumb->getHtmlAttrs(['class'=>'u-photo embed'])); unset($thumb); + } catch (FileNotFoundException $e){ + // Nothing to show } catch (Exception $e) { $out->element('div', ['class'=>'error'], $e->getMessage()); } @@ -411,7 +413,7 @@ class EmbedPlugin extends Plugin // Out $imgPath = $thumbnail->getPath(); - return false; + return !file_exists($imgPath); } /**