3 namespace Wallabag\CoreBundle\Helper
;
6 use Wallabag\CoreBundle\Entity\Entry
;
7 use Wallabag\CoreBundle\Tools\Utils
;
10 * This kind of proxy class take care of getting the content from an url
11 * and update the entry with what it found.
18 public function __construct(Graby
$graby, RuleBasedTagger
$tagger)
20 $this->graby
= $graby;
21 $this->tagger
= $tagger;
25 * Fetch content using graby and hydrate given entry with results information.
26 * In case we couldn't find content, we'll try to use Open Graph data.
28 * @param Entry $entry Entry to update
29 * @param string $url Url to grab content for
33 public function updateEntry(Entry
$entry, $url)
35 $content = $this->graby
->fetchContent($url);
37 $title = $content['title'];
38 if (!$title && isset($content['open_graph']['og_title'])) {
39 $title = $content['open_graph']['og_title'];
42 $html = $content['html'];
43 if (false === $html) {
44 $html = '<p>Unable to retrieve readable content.</p>';
46 if (isset($content['open_graph']['og_description'])) {
47 $html .= '<p><i>But we found a short description: </i></p>';
48 $html .= $content['open_graph']['og_description'];
52 $entry->setUrl($content['url'] ?: $url);
53 $entry->setTitle($title);
54 $entry->setContent($html);
55 $entry->setLanguage($content['language']);
56 $entry->setMimetype($content['content_type']);
57 $entry->setReadingTime(Utils
::getReadingTime($html));
58 $entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST
));
60 if (isset($content['open_graph']['og_image'])) {
61 $entry->setPreviewPicture($content['open_graph']['og_image']);
64 $this->tagger
->tag($entry);