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())->select('COUNT(e.id)')->getQuery()
43 $starredEntries = $this->repository
->enableCache(
44 $this->repository
->getBuilderForStarredByUser($user->getId())->select('COUNT(e.id)')->getQuery()
47 $archivedEntries = $this->repository
->enableCache(
48 $this->repository
->getBuilderForArchiveByUser($user->getId())->select('COUNT(e.id)')->getQuery()
51 $allEntries = $this->repository
->enableCache(
52 $this->repository
->getBuilderForAllByUser($user->getId())->select('COUNT(e.id)')->getQuery()
56 'unreadEntries' => $unreadEntries->getSingleScalarResult(),
57 'starredEntries' => $starredEntries->getSingleScalarResult(),
58 'archivedEntries' => $archivedEntries->getSingleScalarResult(),
59 'allEntries' => $allEntries->getSingleScalarResult(),
63 public function getName()
65 return 'wallabag_extension';