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
->getBuilderForUnreadByUser($user->getId())->getQuery()->getResult();
40 $starredEntries = $this->repository
->getBuilderForStarredByUser($user->getId())->getQuery()->getResult();
41 $archivedEntries = $this->repository
->getBuilderForArchiveByUser($user->getId())->getQuery()->getResult();
42 $allEntries = $this->repository
->getBuilderForAllByUser($user->getId())->getQuery()->getResult();
45 'unreadEntries' => count($unreadEntries),
46 'starredEntries' => count($starredEntries),
47 'archivedEntries' => count($archivedEntries),
48 'allEntries' => count($allEntries),
52 public function getName()
54 return 'wallabag_extension';