aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/ContentProxy.php
diff options
context:
space:
mode:
authornicofrand <mail@nicofrand.eu>2019-05-10 23:01:07 +0200
committernicofrand <mail@nicofrand.eu>2019-05-21 20:38:22 +0200
commit423efadefc2459c7b4a2eabc32edaed918e1075d (patch)
treea30cddc2fa567c7b9ca10c515eccd965d8d4ae03 /src/Wallabag/CoreBundle/Helper/ContentProxy.php
parenta2b5d67560341011e791b678422578ab8d6b1e3f (diff)
downloadwallabag-423efadefc2459c7b4a2eabc32edaed918e1075d.tar.gz
wallabag-423efadefc2459c7b4a2eabc32edaed918e1075d.tar.zst
wallabag-423efadefc2459c7b4a2eabc32edaed918e1075d.zip
Set first picture as preview picture
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index bc257ffb..ca01dec8 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -12,8 +12,8 @@ use Wallabag\CoreBundle\Entity\Entry;
12use Wallabag\CoreBundle\Tools\Utils; 12use Wallabag\CoreBundle\Tools\Utils;
13 13
14/** 14/**
15 * This kind of proxy class take care of getting the content from an url 15 * This kind of proxy class takes care of getting the content from an url
16 * and update the entry with what it found. 16 * and updates the entry with what it found.
17 */ 17 */
18class ContentProxy 18class ContentProxy
19{ 19{
@@ -289,13 +289,25 @@ class ContentProxy
289 $this->updateLanguage($entry, $content['language']); 289 $this->updateLanguage($entry, $content['language']);
290 } 290 }
291 291
292 $previewPictureUrl = '';
292 if (!empty($content['open_graph']['og_image'])) { 293 if (!empty($content['open_graph']['og_image'])) {
293 $this->updatePreviewPicture($entry, $content['open_graph']['og_image']); 294 $previewPictureUrl = $content['open_graph']['og_image'];
294 } 295 }
295 296
296 // if content is an image, define it as a preview too 297 // if content is an image, define it as a preview too
297 if (!empty($content['content_type']) && \in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { 298 if (!empty($content['content_type']) && \in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) {
298 $this->updatePreviewPicture($entry, $content['url']); 299 $previewPictureUrl = $content['url'];
300 } elseif (empty($previewPictureUrl)) {
301 $this->logger->debug('Extracting images from content to provide a default preview picture');
302 $imagesUrls = DownloadImages::extractImagesUrlsFromHtml($content['html']);
303 $this->logger->debug(\count($imagesUrls) . ' pictures found');
304 if (!empty($imagesUrls)) {
305 $previewPictureUrl = $imagesUrls[0];
306 }
307 }
308
309 if (!empty($previewPictureUrl)) {
310 $this->updatePreviewPicture($entry, $previewPictureUrl);
299 } 311 }
300 312
301 if (!empty($content['content_type'])) { 313 if (!empty($content['content_type'])) {