aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php31
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php3
-rw-r--r--src/Wallabag/CoreBundle/Helper/DownloadImages.php21
3 files changed, 38 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php b/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
index 654edf31..09f8e911 100644
--- a/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
+++ b/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
@@ -49,22 +49,23 @@ class DownloadImagesSubscriber implements EventSubscriber
49 return; 49 return;
50 } 50 }
51 51
52 $em = $args->getEntityManager(); 52 $config = new $this->configClass();
53 $config->setEntityManager($args->getEntityManager());
53 54
54 // field content has been updated 55 // field content has been updated
55 if ($args->hasChangedField('content')) { 56 if ($args->hasChangedField('content')) {
56 $html = $this->downloadImages($em, $entity); 57 $html = $this->downloadImages($config, $entity);
57 58
58 if (null !== $html) { 59 if (false !== $html) {
59 $args->setNewValue('content', $html); 60 $args->setNewValue('content', $html);
60 } 61 }
61 } 62 }
62 63
63 // field preview picture has been updated 64 // field preview picture has been updated
64 if ($args->hasChangedField('previewPicture')) { 65 if ($args->hasChangedField('previewPicture')) {
65 $previewPicture = $this->downloadPreviewImage($em, $entity); 66 $previewPicture = $this->downloadPreviewImage($config, $entity);
66 67
67 if (null !== $previewPicture) { 68 if (false !== $previewPicture) {
68 $entity->setPreviewPicture($previewPicture); 69 $entity->setPreviewPicture($previewPicture);
69 } 70 }
70 } 71 }
@@ -88,17 +89,25 @@ class DownloadImagesSubscriber implements EventSubscriber
88 89
89 // update all images inside the html 90 // update all images inside the html
90 $html = $this->downloadImages($config, $entity); 91 $html = $this->downloadImages($config, $entity);
91 if (null !== $html) { 92 if (false !== $html) {
92 $entity->setContent($html); 93 $entity->setContent($html);
93 } 94 }
94 95
95 // update preview picture 96 // update preview picture
96 $previewPicture = $this->downloadPreviewImage($config, $entity); 97 $previewPicture = $this->downloadPreviewImage($config, $entity);
97 if (null !== $previewPicture) { 98 if (false !== $previewPicture) {
98 $entity->setPreviewPicture($previewPicture); 99 $entity->setPreviewPicture($previewPicture);
99 } 100 }
100 } 101 }
101 102
103 /**
104 * Download all images from the html.
105 *
106 * @param Config $config
107 * @param Entry $entry
108 *
109 * @return string|false False in case of async
110 */
102 public function downloadImages(Config $config, Entry $entry) 111 public function downloadImages(Config $config, Entry $entry)
103 { 112 {
104 // if ($config->get('download_images_with_rabbitmq')) { 113 // if ($config->get('download_images_with_rabbitmq')) {
@@ -113,6 +122,14 @@ class DownloadImagesSubscriber implements EventSubscriber
113 ); 122 );
114 } 123 }
115 124
125 /**
126 * Download the preview picture.
127 *
128 * @param Config $config
129 * @param Entry $entry
130 *
131 * @return string|false False in case of async
132 */
116 public function downloadPreviewImage(Config $config, Entry $entry) 133 public function downloadPreviewImage(Config $config, Entry $entry)
117 { 134 {
118 // if ($config->get('download_images_with_rabbitmq')) { 135 // if ($config->get('download_images_with_rabbitmq')) {
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index d90d3dc8..1986ab33 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -65,6 +65,7 @@ class ContentProxy
65 65
66 $entry->setUrl($content['url'] ?: $url); 66 $entry->setUrl($content['url'] ?: $url);
67 $entry->setTitle($title); 67 $entry->setTitle($title);
68 $entry->setContent($html);
68 69
69 $entry->setLanguage($content['language']); 70 $entry->setLanguage($content['language']);
70 $entry->setMimetype($content['content_type']); 71 $entry->setMimetype($content['content_type']);
@@ -75,8 +76,6 @@ class ContentProxy
75 $entry->setDomainName($domainName); 76 $entry->setDomainName($domainName);
76 } 77 }
77 78
78 $entry->setContent($html);
79
80 if (isset($content['open_graph']['og_image'])) { 79 if (isset($content['open_graph']['og_image'])) {
81 $entry->setPreviewPicture($content['open_graph']['og_image']); 80 $entry->setPreviewPicture($content['open_graph']['og_image']);
82 } 81 }
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
index 426cbe48..004bb277 100644
--- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php
+++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
@@ -91,20 +91,23 @@ class DownloadImages
91 // build image path 91 // build image path
92 $absolutePath = $this->getAbsoluteLink($url, $imagePath); 92 $absolutePath = $this->getAbsoluteLink($url, $imagePath);
93 if (false === $absolutePath) { 93 if (false === $absolutePath) {
94 $this->logger->log('debug', 'Can not determine the absolute path for that image, skipping.'); 94 $this->logger->log('error', 'Can not determine the absolute path for that image, skipping.');
95 95
96 return false; 96 return false;
97 } 97 }
98 98
99 $res = $this->client->get( 99 try {
100 $absolutePath, 100 $res = $this->client->get($absolutePath);
101 ['exceptions' => false] 101 } catch (\Exception $e) {
102 ); 102 $this->logger->log('error', 'Can not retrieve image, skipping.', ['exception' => $e]);
103
104 return false;
105 }
103 106
104 $ext = $this->mimeGuesser->guess($res->getHeader('content-type')); 107 $ext = $this->mimeGuesser->guess($res->getHeader('content-type'));
105 $this->logger->log('debug', 'Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]); 108 $this->logger->log('debug', 'Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]);
106 if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'])) { 109 if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) {
107 $this->logger->log('debug', 'Processed image with not allowed extension. Skipping '.$imagePath); 110 $this->logger->log('error', 'Processed image with not allowed extension. Skipping '.$imagePath);
108 111
109 return false; 112 return false;
110 } 113 }
@@ -117,7 +120,7 @@ class DownloadImages
117 $im = false; 120 $im = false;
118 } 121 }
119 122
120 if ($im === false) { 123 if (false === $im) {
121 $this->logger->log('error', 'Error while regenerating image', ['path' => $localPath]); 124 $this->logger->log('error', 'Error while regenerating image', ['path' => $localPath]);
122 125
123 return false; 126 return false;
@@ -193,6 +196,8 @@ class DownloadImages
193 return $absolute->get_uri(); 196 return $absolute->get_uri();
194 } 197 }
195 198
199 $this->logger->log('error', 'Can not make an absolute link', ['base' => $base, 'url' => $url]);
200
196 return false; 201 return false;
197 } 202 }
198} 203}