]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/ContentProxy.php
CS
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / ContentProxy.php
index 4565d8e7a7adc93ad7a6993197c98fab46be1267..bd8b993a1c56b1b73078a5f0e1666f65a26c7b93 100644 (file)
@@ -3,7 +3,9 @@
 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
@@ -12,10 +14,14 @@ use Wallabag\CoreBundle\Entity\Entry;
 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;
     }
 
     /**
@@ -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;
     }
 }