X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FContentProxy.php;h=bd8b993a1c56b1b73078a5f0e1666f65a26c7b93;hb=619cc45359ead519b64129181a07e14160fbbfcb;hp=2dd70e51db50464732c1dbda235dc93b7c442282;hpb=558d9aabab7e01c2e2b506aa362c70a568b953aa;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 2dd70e51..bd8b993a 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -3,27 +3,33 @@ namespace Wallabag\CoreBundle\Helper; use Graby\Graby; +use Psr\Log\LoggerInterface as Logger; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Tools\Utils; /** * This kind of proxy class take care of getting the content from an url - * and update the entry with what it found + * and update the entry with what it found. */ class ContentProxy { protected $graby; + protected $tagger; + protected $logger; - public function __construct(Graby $graby) + public function __construct(Graby $graby, RuleBasedTagger $tagger, Logger $logger) { $this->graby = $graby; + $this->tagger = $tagger; + $this->logger = $logger; } /** * Fetch content using graby and hydrate given entry with results information. - * In case we couldn't find content, we'll try to use Open Graph data + * In case we couldn't find content, we'll try to use Open Graph data. * - * @param Entry $entry Entry to update - * @param string $url Url to grab content for + * @param Entry $entry Entry to update + * @param string $url Url to grab content for * * @return Entry */ @@ -49,12 +55,24 @@ class ContentProxy $entry->setUrl($content['url'] ?: $url); $entry->setTitle($title); $entry->setContent($html); + $entry->setLanguage($content['language']); $entry->setMimetype($content['content_type']); + $entry->setReadingTime(Utils::getReadingTime($html)); + $entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST)); if (isset($content['open_graph']['og_image'])) { $entry->setPreviewPicture($content['open_graph']['og_image']); } + try { + $this->tagger->tag($entry); + } catch (\Exception $e) { + $this->logger->error('Error while trying to automatically tag an entry.', array( + 'entry_url' => $url, + 'error_msg' => $e->getMessage(), + )); + } + return $entry; } }