diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Twig')
-rw-r--r-- | src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 00b1e595..02f17f50 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php | |||
@@ -4,10 +4,14 @@ namespace Wallabag\CoreBundle\Twig; | |||
4 | 4 | ||
5 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | 5 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
6 | use Symfony\Component\Translation\TranslatorInterface; | 6 | use Symfony\Component\Translation\TranslatorInterface; |
7 | use Twig\Extension\AbstractExtension; | ||
8 | use Twig\Extension\GlobalsInterface; | ||
9 | use Twig\TwigFilter; | ||
10 | use Twig\TwigFunction; | ||
7 | use Wallabag\CoreBundle\Repository\EntryRepository; | 11 | use Wallabag\CoreBundle\Repository\EntryRepository; |
8 | use Wallabag\CoreBundle\Repository\TagRepository; | 12 | use Wallabag\CoreBundle\Repository\TagRepository; |
9 | 13 | ||
10 | class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface | 14 | class WallabagExtension extends AbstractExtension implements GlobalsInterface |
11 | { | 15 | { |
12 | private $tokenStorage; | 16 | private $tokenStorage; |
13 | private $entryRepository; | 17 | private $entryRepository; |
@@ -24,20 +28,26 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa | |||
24 | $this->translator = $translator; | 28 | $this->translator = $translator; |
25 | } | 29 | } |
26 | 30 | ||
31 | public function getGlobals() | ||
32 | { | ||
33 | return []; | ||
34 | } | ||
35 | |||
27 | public function getFilters() | 36 | public function getFilters() |
28 | { | 37 | { |
29 | return [ | 38 | return [ |
30 | new \Twig_SimpleFilter('removeWww', [$this, 'removeWww']), | 39 | new TwigFilter('removeWww', [$this, 'removeWww']), |
31 | new \Twig_SimpleFilter('removeSchemeAndWww', [$this, 'removeSchemeAndWww']), | 40 | new TwigFilter('removeScheme', [$this, 'removeScheme']), |
41 | new TwigFilter('removeSchemeAndWww', [$this, 'removeSchemeAndWww']), | ||
32 | ]; | 42 | ]; |
33 | } | 43 | } |
34 | 44 | ||
35 | public function getFunctions() | 45 | public function getFunctions() |
36 | { | 46 | { |
37 | return [ | 47 | return [ |
38 | new \Twig_SimpleFunction('count_entries', [$this, 'countEntries']), | 48 | new TwigFunction('count_entries', [$this, 'countEntries']), |
39 | new \Twig_SimpleFunction('count_tags', [$this, 'countTags']), | 49 | new TwigFunction('count_tags', [$this, 'countTags']), |
40 | new \Twig_SimpleFunction('display_stats', [$this, 'displayStats']), | 50 | new TwigFunction('display_stats', [$this, 'displayStats']), |
41 | ]; | 51 | ]; |
42 | } | 52 | } |
43 | 53 | ||
@@ -46,11 +56,14 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa | |||
46 | return preg_replace('/^www\./i', '', $url); | 56 | return preg_replace('/^www\./i', '', $url); |
47 | } | 57 | } |
48 | 58 | ||
59 | public function removeScheme($url) | ||
60 | { | ||
61 | return preg_replace('#^https?://#i', '', $url); | ||
62 | } | ||
63 | |||
49 | public function removeSchemeAndWww($url) | 64 | public function removeSchemeAndWww($url) |
50 | { | 65 | { |
51 | return $this->removeWww( | 66 | return $this->removeWww($this->removeScheme($url)); |
52 | preg_replace('@^https?://@i', '', $url) | ||
53 | ); | ||
54 | } | 67 | } |
55 | 68 | ||
56 | /** | 69 | /** |