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.
17 public function __construct(Graby
$graby)
19 $this->graby
= $graby;
23 * Fetch content using graby and hydrate given entry with results information.
24 * In case we couldn't find content, we'll try to use Open Graph data.
26 * @param Entry $entry Entry to update
27 * @param string $url Url to grab content for
31 public function updateEntry(Entry
$entry, $url)
33 $content = $this->graby
->fetchContent($url);
35 $title = $content['title'];
36 if (!$title && isset($content['open_graph']['og_title'])) {
37 $title = $content['open_graph']['og_title'];
40 $html = $content['html'];
41 if (false === $html) {
42 $html = '<p>Unable to retrieve readable content.</p>';
44 if (isset($content['open_graph']['og_description'])) {
45 $html .= '<p><i>But we found a short description: </i></p>';
46 $html .= $content['open_graph']['og_description'];
50 $entry->setUrl($content['url'] ?: $url);
51 $entry->setTitle($title);
52 $entry->setContent($html);
53 $entry->setLanguage($content['language']);
54 $entry->setMimetype($content['content_type']);
55 $entry->setReadingTime(Utils
::getReadingTime($html));
56 $entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST
));
58 if (isset($content['open_graph']['og_image'])) {
59 $entry->setPreviewPicture($content['open_graph']['og_image']);