diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index ca01dec8..c6fa0d98 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -54,7 +54,11 @@ class ContentProxy | |||
54 | 54 | ||
55 | if ((empty($content) || false === $this->validateContent($content)) && false === $disableContentUpdate) { | 55 | if ((empty($content) || false === $this->validateContent($content)) && false === $disableContentUpdate) { |
56 | $fetchedContent = $this->graby->fetchContent($url); | 56 | $fetchedContent = $this->graby->fetchContent($url); |
57 | $fetchedContent['title'] = $this->sanitizeContentTitle($fetchedContent['title'], $fetchedContent['content_type']); | 57 | |
58 | $fetchedContent['title'] = $this->sanitizeContentTitle( | ||
59 | $fetchedContent['title'], | ||
60 | isset($fetchedContent['headers']['content-type']) ? $fetchedContent['headers']['content-type'] : '' | ||
61 | ); | ||
58 | 62 | ||
59 | // when content is imported, we have information in $content | 63 | // when content is imported, we have information in $content |
60 | // in case fetching content goes bad, we'll keep the imported information instead of overriding them | 64 | // in case fetching content goes bad, we'll keep the imported information instead of overriding them |
@@ -188,8 +192,8 @@ class ContentProxy | |||
188 | /** | 192 | /** |
189 | * Try to sanitize the title of the fetched content from wrong character encodings and invalid UTF-8 character. | 193 | * Try to sanitize the title of the fetched content from wrong character encodings and invalid UTF-8 character. |
190 | * | 194 | * |
191 | * @param $title | 195 | * @param string $title |
192 | * @param $contentType | 196 | * @param string $contentType |
193 | * | 197 | * |
194 | * @return string | 198 | * @return string |
195 | */ | 199 | */ |
@@ -253,16 +257,14 @@ class ContentProxy | |||
253 | 257 | ||
254 | if (!empty($content['title'])) { | 258 | if (!empty($content['title'])) { |
255 | $entry->setTitle($content['title']); | 259 | $entry->setTitle($content['title']); |
256 | } elseif (!empty($content['open_graph']['og_title'])) { | ||
257 | $entry->setTitle($content['open_graph']['og_title']); | ||
258 | } | 260 | } |
259 | 261 | ||
260 | if (empty($content['html'])) { | 262 | if (empty($content['html'])) { |
261 | $content['html'] = $this->fetchingErrorMessage; | 263 | $content['html'] = $this->fetchingErrorMessage; |
262 | 264 | ||
263 | if (!empty($content['open_graph']['og_description'])) { | 265 | if (!empty($content['description'])) { |
264 | $content['html'] .= '<p><i>But we found a short description: </i></p>'; | 266 | $content['html'] .= '<p><i>But we found a short description: </i></p>'; |
265 | $content['html'] .= $content['open_graph']['og_description']; | 267 | $content['html'] .= $content['description']; |
266 | } | 268 | } |
267 | } | 269 | } |
268 | 270 | ||
@@ -277,8 +279,8 @@ class ContentProxy | |||
277 | $entry->setPublishedBy($content['authors']); | 279 | $entry->setPublishedBy($content['authors']); |
278 | } | 280 | } |
279 | 281 | ||
280 | if (!empty($content['all_headers']) && $this->storeArticleHeaders) { | 282 | if (!empty($content['headers'])) { |
281 | $entry->setHeaders($content['all_headers']); | 283 | $entry->setHeaders($content['headers']); |
282 | } | 284 | } |
283 | 285 | ||
284 | if (!empty($content['date'])) { | 286 | if (!empty($content['date'])) { |
@@ -290,28 +292,29 @@ class ContentProxy | |||
290 | } | 292 | } |
291 | 293 | ||
292 | $previewPictureUrl = ''; | 294 | $previewPictureUrl = ''; |
293 | if (!empty($content['open_graph']['og_image'])) { | 295 | if (!empty($content['image'])) { |
294 | $previewPictureUrl = $content['open_graph']['og_image']; | 296 | $previewPictureUrl = $content['image']; |
295 | } | 297 | } |
296 | 298 | ||
297 | // if content is an image, define it as a preview too | 299 | // if content is an image, define it as a preview too |
298 | if (!empty($content['content_type']) && \in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { | 300 | if (!empty($content['headers']['content-type']) && \in_array($this->mimeGuesser->guess($content['headers']['content-type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { |
299 | $previewPictureUrl = $content['url']; | 301 | $previewPictureUrl = $content['url']; |
300 | } elseif (empty($previewPictureUrl)) { | 302 | } elseif (empty($previewPictureUrl)) { |
301 | $this->logger->debug('Extracting images from content to provide a default preview picture'); | 303 | $this->logger->debug('Extracting images from content to provide a default preview picture'); |
302 | $imagesUrls = DownloadImages::extractImagesUrlsFromHtml($content['html']); | 304 | $imagesUrls = DownloadImages::extractImagesUrlsFromHtml($content['html']); |
303 | $this->logger->debug(\count($imagesUrls) . ' pictures found'); | 305 | $this->logger->debug(\count($imagesUrls) . ' pictures found'); |
306 | |||
304 | if (!empty($imagesUrls)) { | 307 | if (!empty($imagesUrls)) { |
305 | $previewPictureUrl = $imagesUrls[0]; | 308 | $previewPictureUrl = $imagesUrls[0]; |
306 | } | 309 | } |
307 | } | 310 | } |
308 | 311 | ||
309 | if (!empty($previewPictureUrl)) { | 312 | if (!empty($content['headers']['content-type'])) { |
310 | $this->updatePreviewPicture($entry, $previewPictureUrl); | 313 | $entry->setMimetype($content['headers']['content-type']); |
311 | } | 314 | } |
312 | 315 | ||
313 | if (!empty($content['content_type'])) { | 316 | if (!empty($previewPictureUrl)) { |
314 | $entry->setMimetype($content['content_type']); | 317 | $this->updatePreviewPicture($entry, $previewPictureUrl); |
315 | } | 318 | } |
316 | 319 | ||
317 | try { | 320 | try { |