aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r--src/Wallabag/CoreBundle/Helper/Content.php34
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php60
-rw-r--r--src/Wallabag/CoreBundle/Helper/Url.php28
3 files changed, 60 insertions, 62 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/Content.php b/src/Wallabag/CoreBundle/Helper/Content.php
deleted file mode 100644
index 1cc5e4cf..00000000
--- a/src/Wallabag/CoreBundle/Helper/Content.php
+++ /dev/null
@@ -1,34 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5class Content
6{
7 private $title;
8
9 private $body;
10
11 public function __constructor()
12 {
13 }
14
15 public function getTitle()
16 {
17 return $this->title;
18 }
19
20 public function setTitle($title)
21 {
22 $this->title = $title;
23 }
24
25 public function getBody()
26 {
27 return $this->body;
28 }
29
30 public function setBody($body)
31 {
32 $this->body = $body;
33 }
34}
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
new file mode 100644
index 00000000..4565d8e7
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -0,0 +1,60 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Graby\Graby;
6use Wallabag\CoreBundle\Entity\Entry;
7
8/**
9 * This kind of proxy class take care of getting the content from an url
10 * and update the entry with what it found.
11 */
12class ContentProxy
13{
14 protected $graby;
15
16 public function __construct(Graby $graby)
17 {
18 $this->graby = $graby;
19 }
20
21 /**
22 * Fetch content using graby and hydrate given entry with results information.
23 * In case we couldn't find content, we'll try to use Open Graph data.
24 *
25 * @param Entry $entry Entry to update
26 * @param string $url Url to grab content for
27 *
28 * @return Entry
29 */
30 public function updateEntry(Entry $entry, $url)
31 {
32 $content = $this->graby->fetchContent($url);
33
34 $title = $content['title'];
35 if (!$title && isset($content['open_graph']['og_title'])) {
36 $title = $content['open_graph']['og_title'];
37 }
38
39 $html = $content['html'];
40 if (false === $html) {
41 $html = '<p>Unable to retrieve readable content.</p>';
42
43 if (isset($content['open_graph']['og_description'])) {
44 $html .= '<p><i>But we found a short description: </i></p>';
45 $html .= $content['open_graph']['og_description'];
46 }
47 }
48
49 $entry->setUrl($content['url'] ?: $url);
50 $entry->setTitle($title);
51 $entry->setContent($html);
52 $entry->setMimetype($content['content_type']);
53
54 if (isset($content['open_graph']['og_image'])) {
55 $entry->setPreviewPicture($content['open_graph']['og_image']);
56 }
57
58 return $entry;
59 }
60}
diff --git a/src/Wallabag/CoreBundle/Helper/Url.php b/src/Wallabag/CoreBundle/Helper/Url.php
deleted file mode 100644
index 35eb260d..00000000
--- a/src/Wallabag/CoreBundle/Helper/Url.php
+++ /dev/null
@@ -1,28 +0,0 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5class Url
6{
7 public $url;
8
9 public function __construct($url)
10 {
11 $this->url = base64_decode($url);
12 }
13
14 public function getUrl()
15 {
16 return $this->url;
17 }
18
19 public function setUrl($url)
20 {
21 $this->url = $url;
22 }
23
24 public function isCorrect()
25 {
26 return filter_var($this->url, FILTER_VALIDATE_URL) !== false;
27 }
28}