aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-10-02 11:04:49 +0200
committerGitHub <noreply@github.com>2016-10-02 11:04:49 +0200
commitbfb3ae01dafa921505384c5db1cd6625ecdd0bb8 (patch)
tree1e8fec40282a204c6ba24a0f0c2eefb245391518
parentae394b407831b45755d084328cd440e0bdcf453f (diff)
parent1264029cd413a4e29642a219e2647d886f0de0d6 (diff)
downloadwallabag-bfb3ae01dafa921505384c5db1cd6625ecdd0bb8.tar.gz
wallabag-bfb3ae01dafa921505384c5db1cd6625ecdd0bb8.tar.zst
wallabag-bfb3ae01dafa921505384c5db1cd6625ecdd0bb8.zip
Merge pull request #2323 from wallabag/footer-stats
Add simple stats in footer
-rw-r--r--app/config/services.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.it.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml3
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig15
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php40
-rw-r--r--tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php18
15 files changed, 82 insertions, 5 deletions
diff --git a/app/config/services.yml b/app/config/services.yml
index 76bbce27..a57ef0f3 100644
--- a/app/config/services.yml
+++ b/app/config/services.yml
@@ -21,6 +21,7 @@ services:
21 - "@wallabag_core.tag_repository" 21 - "@wallabag_core.tag_repository"
22 - "@security.token_storage" 22 - "@security.token_storage"
23 - "%wallabag_core.cache_lifetime%" 23 - "%wallabag_core.cache_lifetime%"
24 - "@translator"
24 tags: 25 tags:
25 - { name: twig.extension } 26 - { name: twig.extension }
26 27
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index e5d10870..72374a4a 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -45,6 +45,7 @@ footer:
45 # social: 'Social' 45 # social: 'Social'
46 # powered_by: 'powered by' 46 # powered_by: 'powered by'
47 about: 'Om' 47 about: 'Om'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Opsætning' 51 page_title: 'Opsætning'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index c6482dfe..3013e780 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Soziales' 45 social: 'Soziales'
46 powered_by: 'angetrieben von' 46 powered_by: 'angetrieben von'
47 about: 'Über' 47 about: 'Über'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Einstellungen' 51 page_title: 'Einstellungen'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index 1a160321..7bd85cd6 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Social' 45 social: 'Social'
46 powered_by: 'powered by' 46 powered_by: 'powered by'
47 about: 'About' 47 about: 'About'
48 stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Config' 51 page_title: 'Config'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index 47fbcf6c..cab0f302 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Social' 45 social: 'Social'
46 powered_by: 'funciona por' 46 powered_by: 'funciona por'
47 about: 'Acerca de' 47 about: 'Acerca de'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Configuración' 51 page_title: 'Configuración'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index e2447111..202f9d2d 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'شبکه‌های اجتماعی' 45 social: 'شبکه‌های اجتماعی'
46 powered_by: 'توانمند با' 46 powered_by: 'توانمند با'
47 about: 'درباره' 47 about: 'درباره'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'پیکربندی' 51 page_title: 'پیکربندی'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index b43882f0..591b598b 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Social' 45 social: 'Social'
46 powered_by: 'propulsé par' 46 powered_by: 'propulsé par'
47 about: 'À propos' 47 about: 'À propos'
48 stats: Depuis le %user_creation% vous avez lu %nb_archives% articles. Ce qui fait %per_day% par jour !
48 49
49config: 50config:
50 page_title: 'Configuration' 51 page_title: 'Configuration'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
index 2ccd5634..b767e580 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Social' 45 social: 'Social'
46 powered_by: 'powered by' 46 powered_by: 'powered by'
47 about: 'About' 47 about: 'About'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Configurazione' 51 page_title: 'Configurazione'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index 8ead3f8d..39eac642 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -45,9 +45,10 @@ footer:
45 social: 'Social' 45 social: 'Social'
46 powered_by: 'propulsat per' 46 powered_by: 'propulsat per'
47 about: 'A prepaus' 47 about: 'A prepaus'
48 page_title: 'Configuracion' 48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
49 49
50config: 50config:
51 page_title: 'Configuracion'
51 tab_menu: 52 tab_menu:
52 settings: 'Paramètres' 53 settings: 'Paramètres'
53 rss: 'RSS' 54 rss: 'RSS'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index cb4ba675..50da9ff2 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Społeczność' 45 social: 'Społeczność'
46 powered_by: 'Kontrolowany przez' 46 powered_by: 'Kontrolowany przez'
47 about: 'O nas' 47 about: 'O nas'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Konfiguracja' 51 page_title: 'Konfiguracja'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index 6cd7770d..315d6aa0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -45,6 +45,7 @@ footer:
45 # social: 'Social' 45 # social: 'Social'
46 # powered_by: 'powered by' 46 # powered_by: 'powered by'
47 about: 'Despre' 47 about: 'Despre'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Configurație' 51 page_title: 'Configurație'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
index de60b1ae..e46c17c8 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
@@ -45,6 +45,7 @@ footer:
45 social: 'Sosyal' 45 social: 'Sosyal'
46 powered_by: 'powered by' 46 powered_by: 'powered by'
47 about: 'Hakkımızda' 47 about: 'Hakkımızda'
48 # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
48 49
49config: 50config:
50 page_title: 'Yapılandırma' 51 page_title: 'Yapılandırma'
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
index df05e2a4..b2d77c2e 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
@@ -122,8 +122,19 @@
122 <footer class="page-footer cyan darken-2"> 122 <footer class="page-footer cyan darken-2">
123 <div class="footer-copyright"> 123 <div class="footer-copyright">
124 <div class="container"> 124 <div class="container">
125 <p>{{ 'footer.wallabag.powered_by'|trans }} <a target="_blank" href="https://wallabag.org" class="grey-text text-lighten-4">wallabag</a></p> 125 <div class="row">
126 <a class="grey-text text-lighten-4 right" href="{{ path('about') }}">{{ 'footer.wallabag.about'|trans }}</a> 126 <div class="col s8">
127 <p>
128 {{ display_stats() }}
129 </p>
130 </div>
131 <div class="col s4">
132 <p>
133 {{ 'footer.wallabag.powered_by'|trans }} <a target="_blank" href="https://wallabag.org" class="grey-text text-lighten-4">wallabag</a> –
134 <a class="grey-text text-lighten-4" href="{{ path('about') }}">{{ 'footer.wallabag.about'|trans|lower }}</a>
135 </p>
136 </div>
137 </div>
127 </div> 138 </div>
128 </div> 139 </div>
129 </footer> 140 </footer>
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
index fb4c7412..783cde3e 100644
--- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
+++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Twig;
5use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; 5use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
6use Wallabag\CoreBundle\Repository\EntryRepository; 6use Wallabag\CoreBundle\Repository\EntryRepository;
7use Wallabag\CoreBundle\Repository\TagRepository; 7use Wallabag\CoreBundle\Repository\TagRepository;
8use Symfony\Component\Translation\TranslatorInterface;
8 9
9class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface 10class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
10{ 11{
@@ -12,13 +13,15 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
12 private $entryRepository; 13 private $entryRepository;
13 private $tagRepository; 14 private $tagRepository;
14 private $lifeTime; 15 private $lifeTime;
16 private $translator;
15 17
16 public function __construct(EntryRepository $entryRepository = null, TagRepository $tagRepository = null, TokenStorageInterface $tokenStorage = null, $lifeTime = 0) 18 public function __construct(EntryRepository $entryRepository, TagRepository $tagRepository, TokenStorageInterface $tokenStorage, $lifeTime, TranslatorInterface $translator)
17 { 19 {
18 $this->entryRepository = $entryRepository; 20 $this->entryRepository = $entryRepository;
19 $this->tagRepository = $tagRepository; 21 $this->tagRepository = $tagRepository;
20 $this->tokenStorage = $tokenStorage; 22 $this->tokenStorage = $tokenStorage;
21 $this->lifeTime = $lifeTime; 23 $this->lifeTime = $lifeTime;
24 $this->translator = $translator;
22 } 25 }
23 26
24 public function getFilters() 27 public function getFilters()
@@ -33,6 +36,7 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
33 return array( 36 return array(
34 new \Twig_SimpleFunction('count_entries', [$this, 'countEntries']), 37 new \Twig_SimpleFunction('count_entries', [$this, 'countEntries']),
35 new \Twig_SimpleFunction('count_tags', [$this, 'countTags']), 38 new \Twig_SimpleFunction('count_tags', [$this, 'countTags']),
39 new \Twig_SimpleFunction('display_stats', [$this, 'displayStats']),
36 ); 40 );
37 } 41 }
38 42
@@ -107,6 +111,40 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
107 return $this->tagRepository->countAllTags($user->getId()); 111 return $this->tagRepository->countAllTags($user->getId());
108 } 112 }
109 113
114 /**
115 * Display a single line about reading stats.
116 *
117 * @return string
118 */
119 public function displayStats()
120 {
121 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
122
123 if (null === $user || !is_object($user)) {
124 return 0;
125 }
126
127 $query = $this->entryRepository->getBuilderForArchiveByUser($user->getId())
128 ->select('e.id')
129 ->groupBy('e.id')
130 ->getQuery();
131
132 $query->useQueryCache(true);
133 $query->useResultCache(true);
134 $query->setResultCacheLifetime($this->lifeTime);
135
136 $nbArchives = count($query->getArrayResult());
137
138 $interval = $user->getCreatedAt()->diff(new \DateTime('now'));
139 $nbDays = (int) $interval->format('%a') ?: 1;
140
141 return $this->translator->trans('footer.stats', [
142 '%user_creation%' => $user->getCreatedAt()->format('F jS, Y'),
143 '%nb_archives%' => $nbArchives,
144 '%per_day%' => round($nbArchives / $nbDays, 2),
145 ]);
146 }
147
110 public function getName() 148 public function getName()
111 { 149 {
112 return 'wallabag_extension'; 150 return 'wallabag_extension';
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
index 8ec2a75a..b1c8c946 100644
--- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
+++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
@@ -8,7 +8,23 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase
8{ 8{
9 public function testRemoveWww() 9 public function testRemoveWww()
10 { 10 {
11 $extension = new WallabagExtension(); 11 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
16 ->disableOriginalConstructor()
17 ->getMock();
18
19 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
20 ->disableOriginalConstructor()
21 ->getMock();
22
23 $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')
24 ->disableOriginalConstructor()
25 ->getMock();
26
27 $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator);
12 28
13 $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); 29 $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr'));
14 $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); 30 $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr'));