diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 8 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php | 16 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 178910ab..fd059325 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -8,6 +8,7 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
8 | use Wallabag\CoreBundle\Entity\Tag; | 8 | use Wallabag\CoreBundle\Entity\Tag; |
9 | use Wallabag\CoreBundle\Tools\Utils; | 9 | use Wallabag\CoreBundle\Tools\Utils; |
10 | use Wallabag\CoreBundle\Repository\TagRepository; | 10 | use Wallabag\CoreBundle\Repository\TagRepository; |
11 | use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser; | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * This kind of proxy class take care of getting the content from an url | 14 | * This kind of proxy class take care of getting the content from an url |
@@ -19,6 +20,7 @@ class ContentProxy | |||
19 | protected $tagger; | 20 | protected $tagger; |
20 | protected $logger; | 21 | protected $logger; |
21 | protected $tagRepository; | 22 | protected $tagRepository; |
23 | protected $mimeGuesser; | ||
22 | 24 | ||
23 | public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger) | 25 | public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger) |
24 | { | 26 | { |
@@ -26,6 +28,7 @@ class ContentProxy | |||
26 | $this->tagger = $tagger; | 28 | $this->tagger = $tagger; |
27 | $this->logger = $logger; | 29 | $this->logger = $logger; |
28 | $this->tagRepository = $tagRepository; | 30 | $this->tagRepository = $tagRepository; |
31 | $this->mimeGuesser = new MimeTypeExtensionGuesser(); | ||
29 | } | 32 | } |
30 | 33 | ||
31 | /** | 34 | /** |
@@ -81,6 +84,11 @@ class ContentProxy | |||
81 | $entry->setPreviewPicture($content['open_graph']['og_image']); | 84 | $entry->setPreviewPicture($content['open_graph']['og_image']); |
82 | } | 85 | } |
83 | 86 | ||
87 | // if content is an image define as a preview too | ||
88 | if (in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { | ||
89 | $entry->setPreviewPicture($content['url']); | ||
90 | } | ||
91 | |||
84 | try { | 92 | try { |
85 | $this->tagger->tag($entry); | 93 | $this->tagger->tag($entry); |
86 | } catch (\Exception $e) { | 94 | } catch (\Exception $e) { |
diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php index f9066bee..7d3798b9 100644 --- a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php +++ b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php | |||
@@ -5,16 +5,16 @@ namespace Wallabag\CoreBundle\Helper; | |||
5 | use Pagerfanta\Adapter\AdapterInterface; | 5 | use Pagerfanta\Adapter\AdapterInterface; |
6 | use Pagerfanta\Pagerfanta; | 6 | use Pagerfanta\Pagerfanta; |
7 | use Symfony\Component\Routing\Router; | 7 | use Symfony\Component\Routing\Router; |
8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | 8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
9 | 9 | ||
10 | class PreparePagerForEntries | 10 | class PreparePagerForEntries |
11 | { | 11 | { |
12 | private $user; | ||
13 | private $router; | 12 | private $router; |
13 | private $tokenStorage; | ||
14 | 14 | ||
15 | public function __construct(TokenStorage $token, Router $router) | 15 | public function __construct(TokenStorageInterface $tokenStorage, Router $router) |
16 | { | 16 | { |
17 | $this->user = $token->getToken()->getUser(); | 17 | $this->tokenStorage = $tokenStorage; |
18 | $this->router = $router; | 18 | $this->router = $router; |
19 | } | 19 | } |
20 | 20 | ||
@@ -26,8 +26,14 @@ class PreparePagerForEntries | |||
26 | */ | 26 | */ |
27 | public function prepare(AdapterInterface $adapter, $page = 1) | 27 | public function prepare(AdapterInterface $adapter, $page = 1) |
28 | { | 28 | { |
29 | $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; | ||
30 | |||
31 | if (null === $user || !is_object($user)) { | ||
32 | return null; | ||
33 | } | ||
34 | |||
29 | $entries = new Pagerfanta($adapter); | 35 | $entries = new Pagerfanta($adapter); |
30 | $entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage()); | 36 | $entries->setMaxPerPage($user->getConfig()->getItemsPerPage()); |
31 | 37 | ||
32 | return $entries; | 38 | return $entries; |
33 | } | 39 | } |