From 8d7b4f0eff9d07f8d6d354e09fd926abf26aa4ce Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 8 Nov 2016 22:17:46 +0100 Subject: Display a bigger image in case of image content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the content is only an image, we can display a bigger preview image because we won’t have text to display. Also, split different card view to avoid too much complexity in the entries.html.twig --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 8 +++ .../themes/material/Entry/_card_actions.html.twig | 14 ++++ .../material/Entry/_card_full_image.html.twig | 28 ++++++++ .../material/Entry/_card_no_preview.html.twig | 26 ++++++++ .../themes/material/Entry/_card_preview.html.twig | 47 ++++++++++++++ .../views/themes/material/Entry/entries.html.twig | 75 ++-------------------- 6 files changed, 130 insertions(+), 68 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_actions.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_full_image.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_no_preview.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_preview.html.twig (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 8019df42..bbd5db5d 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -8,6 +8,7 @@ use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Tools\Utils; use Wallabag\CoreBundle\Repository\TagRepository; +use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser; /** * This kind of proxy class take care of getting the content from an url @@ -19,6 +20,7 @@ class ContentProxy protected $tagger; protected $logger; protected $tagRepository; + protected $mimeGuesser; public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, Logger $logger) { @@ -26,6 +28,7 @@ class ContentProxy $this->tagger = $tagger; $this->logger = $logger; $this->tagRepository = $tagRepository; + $this->mimeGuesser = new MimeTypeExtensionGuesser(); } /** @@ -79,6 +82,11 @@ class ContentProxy $entry->setPreviewPicture($content['open_graph']['og_image']); } + // if content is an image define as a preview too + if (in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { + $entry->setPreviewPicture($content['url']); + } + try { $this->tagger->tag($entry); } catch (\Exception $e) { diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_actions.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_actions.html.twig new file mode 100644 index 00000000..9f696d06 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_actions.html.twig @@ -0,0 +1,14 @@ +
+ + timer + {{ entry.readingTime / app.user.config.readingSpeed|round }} min + + + +
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_full_image.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_full_image.html.twig new file mode 100644 index 00000000..0fdd5996 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_full_image.html.twig @@ -0,0 +1,28 @@ +
+
+
+ +
+
+ + +
+ + {% include "@WallabagCore/themes/material/Entry/_card_actions.html.twig" with {'entry': entry} only %} +
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_no_preview.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_no_preview.html.twig new file mode 100644 index 00000000..19a400b4 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_no_preview.html.twig @@ -0,0 +1,26 @@ +
+
+
+ + + {{ entry.title | raw | striptags | truncate(80, true, '…') }} + + + + + +

{{ entry.content|striptags|slice(0, 250)|raw }}…

+ +
+
+ + {% include "@WallabagCore/themes/material/Entry/_card_actions.html.twig" with {'entry': entry} only %} +
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_preview.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_preview.html.twig new file mode 100644 index 00000000..b0e3c06d --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/_card_preview.html.twig @@ -0,0 +1,47 @@ +
+
+
+ +
+
+ + +
+ +
+ clear + + + {{ entry.title | raw | striptags | truncate(80, true, '…') }} + + + +

{{ entry.content|striptags|slice(0, 250)|raw }}…

+ + +
+ + {% include "@WallabagCore/themes/material/Entry/_card_actions.html.twig" with {'entry': entry} only %} +
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index 498234b9..c610c8d2 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -22,74 +22,13 @@ -- cgit v1.2.3