3 namespace Wallabag\CoreBundle\Helper
;
6 use Wallabag\CoreBundle\Entity\Entry
;
9 * This kind of proxy class take care of getting the content from an url
10 * and update the entry with what it found.
16 public function __construct(Graby
$graby)
18 $this->graby
= $graby;
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.
25 * @param Entry $entry Entry to update
26 * @param string $url Url to grab content for
30 public function updateEntry(Entry
$entry, $url)
32 $content = $this->graby
->fetchContent($url);
34 $title = $content['title'];
35 if (!$title && isset($content['open_graph']['og_title'])) {
36 $title = $content['open_graph']['og_title'];
39 $html = $content['html'];
40 if (false === $html) {
41 $html = '<p>Unable to retrieve readable content.</p>';
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'];
49 $entry->setUrl($content['url'] ?: $url);
50 $entry->setTitle($title);
51 $entry->setContent($html);
52 $entry->setMimetype($content['content_type']);
54 if (isset($content['open_graph']['og_image'])) {
55 $entry->setPreviewPicture($content['open_graph']['og_image']);