3 namespace Wallabag\CoreBundle\Twig
;
5 use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
;
6 use Wallabag\CoreBundle\Repository\EntryRepository
;
8 class WallabagExtension
extends \Twig_Extension
implements \Twig_Extension_GlobalsInterface
10 private $tokenStorage;
13 public function __construct(EntryRepository
$repository = null, TokenStorageInterface
$tokenStorage = null)
15 $this->repository
= $repository;
16 $this->tokenStorage
= $tokenStorage;
19 public function getFilters()
22 new \
Twig_SimpleFilter('removeWww', [$this, 'removeWww']),
26 public function removeWww($url)
28 return preg_replace('/^www\./i', '', $url);
31 public function getGlobals()
33 $user = $this->tokenStorage
->getToken() ? $this->tokenStorage
->getToken()->getUser() : null;
35 if (null === $user || !is_object($user)) {
39 $unreadEntries = $this->repository
->enableCache(
40 $this->repository
->getBuilderForUnreadByUser($user->getId())->getQuery()
43 $starredEntries = $this->repository
->enableCache(
44 $this->repository
->getBuilderForStarredByUser($user->getId())->getQuery()
47 $archivedEntries = $this->repository
->enableCache(
48 $this->repository
->getBuilderForArchiveByUser($user->getId())->getQuery()
51 $allEntries = $this->repository
->enableCache(
52 $this->repository
->getBuilderForAllByUser($user->getId())->getQuery()
56 'unreadEntries' => count($unreadEntries->getResult()),
57 'starredEntries' => count($starredEntries->getResult()),
58 'archivedEntries' => count($archivedEntries->getResult()),
59 'allEntries' => count($allEntries->getResult()),
63 public function getName()
65 return 'wallabag_extension';