From 186d730468c156440922e525424161aaa7f066c8 Mon Sep 17 00:00:00 2001 From: nee Date: Wed, 2 Nov 2016 04:56:29 +0100 Subject: [PATCH 1/2] SensitiveContentPlugin: don't crash in GNU/Social Classic, when an attachment has no thumbnail (for example when it is a video) --- SensitiveContentPlugin.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SensitiveContentPlugin.php b/SensitiveContentPlugin.php index 8eb7c4a..69315d1 100644 --- a/SensitiveContentPlugin.php +++ b/SensitiveContentPlugin.php @@ -160,14 +160,23 @@ EOB; $classes = "sensitive-blocker"; //'sensitive-blocker'; + $thumbnail = null; + try { + $thumbnail = $file->getThumbnail(); + } catch (Exception $e) { + $thumbnail = null; + } + $thumbWidth = $thumbnail ? $thumbnail->width : 'auto'; + $thumbHeight = $thumbnail ? $thumbnail->height : 'auto'; + $out->elementStart('div', array( 'class'=>'attachment-wrapper', - 'style'=>'height: ' . $file->getThumbnail()->height . 'px; width: ' . $file->getThumbnail()->width . 'px;' + 'style'=>'height: ' . $thumbHeight . 'px; width: ' . $thumbWidth . 'px;' )); /*needs height of thumb*/ $out->elementStart('div', array( 'class'=>$classes, 'onclick'=>'toggleSpoiler(event)', - 'style'=>'height: ' . $file->getThumbnail()->height . 'px; width: ' . $file->getThumbnail()->width . 'px;' + 'style'=>'height: ' . $thumbHeight . 'px; width: ' . $thumbWidth . 'px;' )); $out->raw(' '); $out->elementEnd('div'); From 79eb6c2025d65ad6459e886cd4917e8a2dff5565 Mon Sep 17 00:00:00 2001 From: nee Date: Wed, 2 Nov 2016 06:33:59 +0100 Subject: [PATCH 2/2] fix: don't append 'auto px', thats invalid css. Append just 'auto' instead. --- SensitiveContentPlugin.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SensitiveContentPlugin.php b/SensitiveContentPlugin.php index 69315d1..5054d5a 100644 --- a/SensitiveContentPlugin.php +++ b/SensitiveContentPlugin.php @@ -166,17 +166,17 @@ EOB; } catch (Exception $e) { $thumbnail = null; } - $thumbWidth = $thumbnail ? $thumbnail->width : 'auto'; - $thumbHeight = $thumbnail ? $thumbnail->height : 'auto'; + $thumbWidthCss = $thumbnail ? $thumbnail->width.'px' : 'auto'; + $thumbHeightCss = $thumbnail ? $thumbnail->height.'px' : 'auto'; $out->elementStart('div', array( 'class'=>'attachment-wrapper', - 'style'=>'height: ' . $thumbHeight . 'px; width: ' . $thumbWidth . 'px;' + 'style'=>'height: ' . $thumbHeightCss . '; width: ' . $thumbWidthCss . ';' )); /*needs height of thumb*/ $out->elementStart('div', array( 'class'=>$classes, 'onclick'=>'toggleSpoiler(event)', - 'style'=>'height: ' . $thumbHeight . 'px; width: ' . $thumbWidth . 'px;' + 'style'=>'height: ' . $thumbHeightCss . '; width: ' . $thumbWidthCss . ';' )); $out->raw(' '); $out->elementEnd('div');