3 namespace Wallabag\CoreBundle\Helper
;
6 use Psr\Log\LoggerInterface
as Logger
;
7 use Wallabag\CoreBundle\Entity\Entry
;
8 use Wallabag\CoreBundle\Tools\Utils
;
11 * This kind of proxy class take care of getting the content from an url
12 * and update the entry with what it found.
20 public function __construct(Graby
$graby, RuleBasedTagger
$tagger, Logger
$logger)
22 $this->graby
= $graby;
23 $this->tagger
= $tagger;
24 $this->logger
= $logger;
28 * Fetch content using graby and hydrate given entry with results information.
29 * In case we couldn't find content, we'll try to use Open Graph data.
31 * @param Entry $entry Entry to update
32 * @param string $url Url to grab content for
36 public function updateEntry(Entry
$entry, $url)
38 $content = $this->graby
->fetchContent($url);
40 $title = $content['title'];
41 if (!$title && isset($content['open_graph']['og_title'])) {
42 $title = $content['open_graph']['og_title'];
45 $html = $content['html'];
46 if (false === $html) {
47 $html = '<p>Unable to retrieve readable content.</p>';
49 if (isset($content['open_graph']['og_description'])) {
50 $html .= '<p><i>But we found a short description: </i></p>';
51 $html .= $content['open_graph']['og_description'];
55 $entry->setUrl($content['url'] ?: $url);
56 $entry->setTitle($title);
57 $entry->setContent($html);
58 $entry->setLanguage($content['language']);
59 $entry->setMimetype($content['content_type']);
60 $entry->setReadingTime(Utils
::getReadingTime($html));
61 $entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST
));
63 if (isset($content['open_graph']['og_image'])) {
64 $entry->setPreviewPicture($content['open_graph']['og_image']);
68 $this->tagger
->tag($entry);
69 } catch (\Exception
$e) {
70 $this->logger
->error('Error while trying to automatically tag an entry.', array(
72 'error_msg' => $e->getMessage(),