aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php4
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php20
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php4
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php70
4 files changed, 50 insertions, 48 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index aff0534a..d9d99c85 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -369,9 +369,7 @@ class EntryRestController extends WallabagRestController
369 'language' => !empty($data['language']) ? $data['language'] : $entry->getLanguage(), 369 'language' => !empty($data['language']) ? $data['language'] : $entry->getLanguage(),
370 'date' => !empty($data['publishedAt']) ? $data['publishedAt'] : $entry->getPublishedAt(), 370 'date' => !empty($data['publishedAt']) ? $data['publishedAt'] : $entry->getPublishedAt(),
371 // faking the open graph preview picture 371 // faking the open graph preview picture
372 'open_graph' => [ 372 'image' => !empty($data['picture']) ? $data['picture'] : $entry->getPreviewPicture(),
373 'og_image' => !empty($data['picture']) ? $data['picture'] : $entry->getPreviewPicture(),
374 ],
375 'authors' => \is_string($data['authors']) ? explode(',', $data['authors']) : $entry->getPublishedBy(), 373 'authors' => \is_string($data['authors']) ? explode(',', $data['authors']) : $entry->getPublishedBy(),
376 ] 374 ]
377 ); 375 );
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index ca01dec8..ac27e50a 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -253,16 +253,14 @@ class ContentProxy
253 253
254 if (!empty($content['title'])) { 254 if (!empty($content['title'])) {
255 $entry->setTitle($content['title']); 255 $entry->setTitle($content['title']);
256 } elseif (!empty($content['open_graph']['og_title'])) {
257 $entry->setTitle($content['open_graph']['og_title']);
258 } 256 }
259 257
260 if (empty($content['html'])) { 258 if (empty($content['html'])) {
261 $content['html'] = $this->fetchingErrorMessage; 259 $content['html'] = $this->fetchingErrorMessage;
262 260
263 if (!empty($content['open_graph']['og_description'])) { 261 if (!empty($content['description'])) {
264 $content['html'] .= '<p><i>But we found a short description: </i></p>'; 262 $content['html'] .= '<p><i>But we found a short description: </i></p>';
265 $content['html'] .= $content['open_graph']['og_description']; 263 $content['html'] .= $content['description'];
266 } 264 }
267 } 265 }
268 266
@@ -277,8 +275,8 @@ class ContentProxy
277 $entry->setPublishedBy($content['authors']); 275 $entry->setPublishedBy($content['authors']);
278 } 276 }
279 277
280 if (!empty($content['all_headers']) && $this->storeArticleHeaders) { 278 if (!empty($content['headers'])) {
281 $entry->setHeaders($content['all_headers']); 279 $entry->setHeaders($content['headers']);
282 } 280 }
283 281
284 if (!empty($content['date'])) { 282 if (!empty($content['date'])) {
@@ -290,12 +288,12 @@ class ContentProxy
290 } 288 }
291 289
292 $previewPictureUrl = ''; 290 $previewPictureUrl = '';
293 if (!empty($content['open_graph']['og_image'])) { 291 if (!empty($content['image'])) {
294 $previewPictureUrl = $content['open_graph']['og_image']; 292 $previewPictureUrl = $content['image'];
295 } 293 }
296 294
297 // if content is an image, define it as a preview too 295 // 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)) { 296 if (!empty($content['headers']['content_type']) && \in_array($this->mimeGuesser->guess($content['headers']['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) {
299 $previewPictureUrl = $content['url']; 297 $previewPictureUrl = $content['url'];
300 } elseif (empty($previewPictureUrl)) { 298 } elseif (empty($previewPictureUrl)) {
301 $this->logger->debug('Extracting images from content to provide a default preview picture'); 299 $this->logger->debug('Extracting images from content to provide a default preview picture');
@@ -310,8 +308,8 @@ class ContentProxy
310 $this->updatePreviewPicture($entry, $previewPictureUrl); 308 $this->updatePreviewPicture($entry, $previewPictureUrl);
311 } 309 }
312 310
313 if (!empty($content['content_type'])) { 311 if (!empty($content['headers']['content-type'])) {
314 $entry->setMimetype($content['content_type']); 312 $entry->setMimetype($content['headers']['content-type']);
315 } 313 }
316 314
317 try { 315 try {
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
index 3e085ecf..2ba26003 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
@@ -35,7 +35,9 @@ class WallabagV2Import extends WallabagImport
35 { 35 {
36 return [ 36 return [
37 'html' => $entry['content'], 37 'html' => $entry['content'],
38 'content_type' => $entry['mimetype'], 38 'headers' => [
39 'content-type' => $entry['mimetype'],
40 ],
39 'is_archived' => (bool) ($entry['is_archived'] || $this->markAsRead), 41 'is_archived' => (bool) ($entry['is_archived'] || $this->markAsRead),
40 'is_starred' => (bool) $entry['is_starred'], 42 'is_starred' => (bool) $entry['is_starred'],
41 ] + $entry; 43 ] + $entry;
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index c7caac1d..40a6cc80 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -104,15 +104,12 @@ class ContentProxyTest extends TestCase
104 ->method('fetchContent') 104 ->method('fetchContent')
105 ->willReturn([ 105 ->willReturn([
106 'html' => false, 106 'html' => false,
107 'title' => '', 107 'title' => 'my title',
108 'url' => '', 108 'url' => '',
109 'content_type' => '', 109 'content_type' => '',
110 'language' => '', 110 'language' => '',
111 'status' => '', 111 'status' => '',
112 'open_graph' => [ 112 'description' => 'desc',
113 'og_title' => 'my title',
114 'og_description' => 'desc',
115 ],
116 ]); 113 ]);
117 114
118 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 115 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
@@ -147,13 +144,12 @@ class ContentProxyTest extends TestCase
147 'html' => str_repeat('this is my content', 325), 144 'html' => str_repeat('this is my content', 325),
148 'title' => 'this is my title', 145 'title' => 'this is my title',
149 'url' => 'http://1.1.1.1', 146 'url' => 'http://1.1.1.1',
150 'content_type' => 'text/html',
151 'language' => 'fr', 147 'language' => 'fr',
152 'status' => '200', 148 'status' => '200',
153 'open_graph' => [ 149 'description' => 'OG desc',
154 'og_title' => 'my OG title', 150 'image' => 'http://3.3.3.3/cover.jpg',
155 'og_description' => 'OG desc', 151 'headers' => [
156 'og_image' => 'http://3.3.3.3/cover.jpg', 152 'content-type' => 'text/html',
157 ], 153 ],
158 ]); 154 ]);
159 155
@@ -189,13 +185,12 @@ class ContentProxyTest extends TestCase
189 'html' => str_repeat('this is my content', 325), 185 'html' => str_repeat('this is my content', 325),
190 'title' => 'this is my title', 186 'title' => 'this is my title',
191 'url' => 'http://1.1.1.1', 187 'url' => 'http://1.1.1.1',
192 'content_type' => 'text/html',
193 'language' => 'fr', 188 'language' => 'fr',
194 'status' => '200', 189 'status' => '200',
195 'open_graph' => [ 190 'description' => 'OG desc',
196 'og_title' => 'my OG title', 191 'image' => null,
197 'og_description' => 'OG desc', 192 'headers' => [
198 'og_image' => null, 193 'content-type' => 'text/html',
199 ], 194 ],
200 ]); 195 ]);
201 196
@@ -320,9 +315,11 @@ class ContentProxyTest extends TestCase
320 'html' => str_repeat('this is my content', 325), 315 'html' => str_repeat('this is my content', 325),
321 'title' => 'this is my title', 316 'title' => 'this is my title',
322 'url' => 'http://1.1.1.1', 317 'url' => 'http://1.1.1.1',
323 'content_type' => 'text/html',
324 'language' => 'dontexist', 318 'language' => 'dontexist',
325 'status' => '200', 319 'status' => '200',
320 'headers' => [
321 'content-type' => 'text/html',
322 ],
326 ]); 323 ]);
327 324
328 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); 325 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage);
@@ -367,10 +364,10 @@ class ContentProxyTest extends TestCase
367 'content_type' => 'text/html', 364 'content_type' => 'text/html',
368 'language' => 'fr', 365 'language' => 'fr',
369 'status' => '200', 366 'status' => '200',
370 'open_graph' => [ 367 'description' => 'OG desc',
371 'og_title' => 'my OG title', 368 'image' => 'https://',
372 'og_description' => 'OG desc', 369 'headers' => [
373 'og_image' => 'https://', 370 'content-type' => 'text/html',
374 ], 371 ],
375 ]); 372 ]);
376 373
@@ -404,12 +401,12 @@ class ContentProxyTest extends TestCase
404 'html' => str_repeat('this is my content', 325), 401 'html' => str_repeat('this is my content', 325),
405 'title' => 'this is my title', 402 'title' => 'this is my title',
406 'url' => 'http://1.1.1.1', 403 'url' => 'http://1.1.1.1',
407 'content_type' => 'text/html',
408 'language' => 'fr', 404 'language' => 'fr',
409 'date' => '1395635872', 405 'date' => '1395635872',
410 'authors' => ['Jeremy', 'Nico', 'Thomas'], 406 'authors' => ['Jeremy', 'Nico', 'Thomas'],
411 'all_headers' => [ 407 'headers' => [
412 'Cache-Control' => 'no-cache', 408 'cache-control' => 'no-cache',
409 'content-type' => 'text/html',
413 ], 410 ],
414 ] 411 ]
415 ); 412 );
@@ -447,9 +444,11 @@ class ContentProxyTest extends TestCase
447 'html' => str_repeat('this is my content', 325), 444 'html' => str_repeat('this is my content', 325),
448 'title' => 'this is my title', 445 'title' => 'this is my title',
449 'url' => 'http://1.1.1.1', 446 'url' => 'http://1.1.1.1',
450 'content_type' => 'text/html',
451 'language' => 'fr', 447 'language' => 'fr',
452 'date' => '2016-09-08T11:55:58+0200', 448 'date' => '2016-09-08T11:55:58+0200',
449 'headers' => [
450 'content-type' => 'text/html',
451 ],
453 ] 452 ]
454 ); 453 );
455 454
@@ -482,9 +481,11 @@ class ContentProxyTest extends TestCase
482 'html' => str_repeat('this is my content', 325), 481 'html' => str_repeat('this is my content', 325),
483 'title' => 'this is my title', 482 'title' => 'this is my title',
484 'url' => 'http://1.1.1.1', 483 'url' => 'http://1.1.1.1',
485 'content_type' => 'text/html',
486 'language' => 'fr', 484 'language' => 'fr',
487 'date' => '01 02 2012', 485 'date' => '01 02 2012',
486 'headers' => [
487 'content-type' => 'text/html',
488 ],
488 ] 489 ]
489 ); 490 );
490 491
@@ -519,8 +520,10 @@ class ContentProxyTest extends TestCase
519 'html' => str_repeat('this is my content', 325), 520 'html' => str_repeat('this is my content', 325),
520 'title' => 'this is my title', 521 'title' => 'this is my title',
521 'url' => 'http://1.1.1.1', 522 'url' => 'http://1.1.1.1',
522 'content_type' => 'text/html',
523 'language' => 'fr', 523 'language' => 'fr',
524 'headers' => [
525 'content-type' => 'text/html',
526 ],
524 ] 527 ]
525 ); 528 );
526 529
@@ -559,13 +562,13 @@ class ContentProxyTest extends TestCase
559 'html' => $html, 562 'html' => $html,
560 'title' => 'this is my title', 563 'title' => 'this is my title',
561 'url' => 'http://1.1.1.1', 564 'url' => 'http://1.1.1.1',
562 'content_type' => 'text/html',
563 'language' => 'fr', 565 'language' => 'fr',
564 'status' => '200', 566 'status' => '200',
565 'open_graph' => [ 567 //'og_title' => 'my OG title',
566 'og_title' => 'my OG title', 568 'description' => 'OG desc',
567 'og_description' => 'OG desc', 569 'image' => 'http://3.3.3.3/cover.jpg',
568 'og_image' => 'http://3.3.3.3/cover.jpg', 570 'headers' => [
571 'content-type' => 'text/html',
569 ], 572 ],
570 ] 573 ]
571 ); 574 );
@@ -597,9 +600,10 @@ class ContentProxyTest extends TestCase
597 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', 600 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>',
598 'title' => 'this is my title', 601 'title' => 'this is my title',
599 'url' => 'http://1.1.1.1/image.jpg', 602 'url' => 'http://1.1.1.1/image.jpg',
600 'content_type' => 'image/jpeg',
601 'status' => '200', 603 'status' => '200',
602 'open_graph' => [], 604 'headers' => [
605 'content-type' => 'image/jpeg',
606 ],
603 ]); 607 ]);
604 608
605 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 609 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);