aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-06-13 18:48:10 +0200
committerThomas Citharel <tcit@tcit.fr>2017-07-09 16:18:12 +0200
commit47e2d609bcac6de4893cc04559c0794642c30a80 (patch)
tree47ff46760b8d2a9c4a57e9b734395d283afd7f76
parentb5d7eb148c4cd62ff187b08765f0c13c7d330fcf (diff)
downloadwallabag-47e2d609bcac6de4893cc04559c0794642c30a80.tar.gz
wallabag-47e2d609bcac6de4893cc04559c0794642c30a80.tar.zst
wallabag-47e2d609bcac6de4893cc04559c0794642c30a80.zip
Changed RSS to Atom feed and improve paging
-rw-r--r--app/config/security.yml1
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php44
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/common/Entry/entries.xml.twig76
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php6
-rw-r--r--tests/Wallabag/CoreBundle/Controller/RssControllerTest.php71
-rw-r--r--tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php25
6 files changed, 135 insertions, 88 deletions
diff --git a/app/config/security.yml b/app/config/security.yml
index e14a0bd1..5f3bf0b6 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -62,6 +62,7 @@ security:
62 - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 62 - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
63 - { path: /(unread|starred|archive).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } 63 - { path: /(unread|starred|archive).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
64 - { path: /tags/(.*).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } 64 - { path: /tags/(.*).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
65 - { path: ^/feed, roles: IS_AUTHENTICATED_ANONYMOUSLY }
65 - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY } 66 - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY }
66 - { path: ^/settings, roles: ROLE_SUPER_ADMIN } 67 - { path: ^/settings, roles: ROLE_SUPER_ADMIN }
67 - { path: ^/annotations, roles: ROLE_USER } 68 - { path: ^/annotations, roles: ROLE_USER }
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php
index e84044b1..db0a8f9a 100644
--- a/src/Wallabag/CoreBundle/Controller/RssController.php
+++ b/src/Wallabag/CoreBundle/Controller/RssController.php
@@ -21,40 +21,46 @@ class RssController extends Controller
21 /** 21 /**
22 * Shows unread entries for current user. 22 * Shows unread entries for current user.
23 * 23 *
24 * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"}) 24 * @Route("/feed/{username}/{token}/unread/{page}", name="unread_rss", defaults={"page": 1})
25 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") 25 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
26 * 26 *
27 * @param User $user
28 * @param $page
27 * @return \Symfony\Component\HttpFoundation\Response 29 * @return \Symfony\Component\HttpFoundation\Response
28 */ 30 */
29 public function showUnreadRSSAction(Request $request, User $user) 31 public function showUnreadRSSAction(User $user, $page)
30 { 32 {
31 return $this->showEntries('unread', $user, $request->query->get('page', 1)); 33 return $this->showEntries('unread', $user, $page);
32 } 34 }
33 35
34 /** 36 /**
35 * Shows read entries for current user. 37 * Shows read entries for current user.
36 * 38 *
37 * @Route("/{username}/{token}/archive.xml", name="archive_rss", defaults={"_format"="xml"}) 39 * @Route("/feed/{username}/{token}/archive/{page}", name="archive_rss", defaults={"page": 1})
38 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") 40 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
39 * 41 *
42 * @param User $user
43 * @param $page
40 * @return \Symfony\Component\HttpFoundation\Response 44 * @return \Symfony\Component\HttpFoundation\Response
41 */ 45 */
42 public function showArchiveRSSAction(Request $request, User $user) 46 public function showArchiveRSSAction(User $user, $page)
43 { 47 {
44 return $this->showEntries('archive', $user, $request->query->get('page', 1)); 48 return $this->showEntries('archive', $user, $page);
45 } 49 }
46 50
47 /** 51 /**
48 * Shows starred entries for current user. 52 * Shows starred entries for current user.
49 * 53 *
50 * @Route("/{username}/{token}/starred.xml", name="starred_rss", defaults={"_format"="xml"}) 54 * @Route("/feed/{username}/{token}/starred/{page}", name="starred_rss", defaults={"page": 1})
51 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") 55 * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
52 * 56 *
57 * @param User $user
58 * @param $page
53 * @return \Symfony\Component\HttpFoundation\Response 59 * @return \Symfony\Component\HttpFoundation\Response
54 */ 60 */
55 public function showStarredRSSAction(Request $request, User $user) 61 public function showStarredRSSAction(User $user, $page)
56 { 62 {
57 return $this->showEntries('starred', $user, $request->query->get('page', 1)); 63 return $this->showEntries('starred', $user, $page);
58 } 64 }
59 65
60 /** 66 /**
@@ -179,19 +185,17 @@ class RssController extends Controller
179 $entries->setCurrentPage((int) $page); 185 $entries->setCurrentPage((int) $page);
180 } catch (OutOfRangeCurrentPageException $e) { 186 } catch (OutOfRangeCurrentPageException $e) {
181 if ($page > 1) { 187 if ($page > 1) {
182 return $this->redirect($url . '?page=' . $entries->getNbPages(), 302); 188 return $this->redirect($url.'/'.$entries->getNbPages());
183 } 189 }
184 } 190 }
185 191
186 return $this->render( 192 return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [
187 '@WallabagCore/themes/common/Entry/entries.xml.twig', 193 'type' => $type,
188 [ 194 'url' => $url,
189 'url_html' => $this->generateUrl($type, [], UrlGeneratorInterface::ABSOLUTE_URL), 195 'entries' => $entries,
190 'type' => $type, 196 'user' => $user->getUsername(),
191 'url' => $url, 197 'domainName' => $this->getParameter('domain_name'),
192 'entries' => $entries, 198 'version' => $this->getParameter('wallabag_core.version'),
193 ], 199 ]);
194 new Response('', 200, ['Content-Type' => 'application/rss+xml'])
195 );
196 } 200 }
197} 201}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/common/Entry/entries.xml.twig b/src/Wallabag/CoreBundle/Resources/views/themes/common/Entry/entries.xml.twig
index d70aa5dc..0a0131cd 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/common/Entry/entries.xml.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/common/Entry/entries.xml.twig
@@ -1,34 +1,46 @@
1<?xml version="1.0" encoding="utf-8"?> 1<?xml version="1.0" encoding="utf-8"?>
2<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"> 2<feed xmlns="http://www.w3.org/2005/Atom">
3 <channel> 3 <title>wallabag — {{type}} feed</title>
4 <title>wallabag - {{ type }} feed</title> 4 <subtitle type="html">RSS feed for {{ type }} entries</subtitle>
5 <link>{{ url_html }}</link> 5 {% if entries | length > 0 %}
6 <link rel="self" href="{{ app.request.uri }}"/> 6 <updated>{{ (entries | first).createdAt | date('c') }}</updated> {# Indicates the last time the feed was modified in a significant way. #}
7 {% if entries.hasPreviousPage -%} 7 {% endif %}
8 <link rel="previous" href="{{ url }}?page={{ entries.previousPage }}"/> 8 <id>wallabag:{{ domainName | removeScheme | removeWww }}:{{ user }}:{{ type }}</id>
9 {% endif -%} 9 <link rel="alternate" type="text/html" href="{{ url(type) }}"/>
10 {% if entries.hasNextPage -%} 10 <link rel="self" type="application/atom+xml" href="{{ app.request.uri }}"/>
11 <link rel="next" href="{{ url }}?page={{ entries.nextPage }}"/> 11 {% if entries.hasPreviousPage %}
12 {% endif -%} 12 <link rel="previous" href="{{ url }}/{{ entries.previousPage }}"/>
13 <link rel="last" href="{{ url }}?page={{ entries.nbPages }}"/> 13 {% endif -%}
14 <pubDate>{{ "now"|date('D, d M Y H:i:s') }}</pubDate> 14 {% if entries.hasNextPage %}
15 <generator>wallabag</generator> 15 <link rel="next" href="{{ url }}/{{ entries.nextPage }}"/>
16 <description>wallabag {{ type }} elements</description> 16 {% endif -%}
17 17 <link rel="last" href="{{ url }}/{{ entries.nbPages }}"/>
18 {% for entry in entries %} 18 <generator uri="http://wallabag.org" version="{{ version }}">wallabag</generator>
19 19 <author>
20 <item> 20 <name>{{ user }}</name>
21 <title><![CDATA[{{ entry.title|e }}]]></title> 21 </author>
22 <source url="{{ url('view', { 'id': entry.id }) }}">wallabag</source> 22 <icon>{{ asset('favicon.ico') }}</icon>
23 <link>{{ entry.url }}</link> 23 <logo>{{ asset('bundles/wallabagcore/themes/_global/img/logo-square.png') }}</logo>
24 <guid>{{ entry.url }}</guid> 24 {% for entry in entries %}
25 <pubDate>{{ entry.createdAt|date('D, d M Y H:i:s') }}</pubDate> 25 <entry>
26 <description> 26 <title><![CDATA[{{ entry.title|e }}]]></title>
27 <![CDATA[{%- if entry.readingTime > 0 -%}{{ 'entry.list.reading_time_minutes'|trans({'%readingTime%': entry.readingTime}) }}{%- else -%}{{ 'entry.list.reading_time_less_one_minute'|trans|raw }}{%- endif %}{{ entry.content|raw -}}]]> 27 <link rel="alternate" type="text/html"
28 </description> 28 href="{{ url('view', {'id': entry.id}) }}"/>
29 </item> 29 <link rel="via">{{ entry.url }}</link>
30 30 <id>wallabag:{{ domainName | removeScheme | removeWww }}:{{ user }}:entry:{{ entry.id }}</id>
31 <updated>{{ entry.updatedAt|date('c') }}</updated>
32 <published>{{ entry.createdAt|date('c') }}</published>
33 {% for tag in entry.tags %}
34 <category term="{{ tag.slug }}" label="{{ tag.label }}" />
31 {% endfor %} 35 {% endfor %}
32 36 {% for author in entry.publishedBy %}
33 </channel> 37 <author>
34</rss> 38 <name>{{ author }}</name>
39 </author>
40 {% endfor %}
41 <content type="html" {% if entry.language %}xml:lang="{{ entry.language[:2] }}"{% endif %}>
42 <![CDATA[{%- if entry.readingTime > 0 -%}{{ 'entry.list.reading_time_minutes'|trans({'%readingTime%': entry.readingTime}) }}{%- else -%}{{ 'entry.list.reading_time_less_one_minute'|trans|raw }}{%- endif %}{{ entry.content|raw -}}]]>
43 </content>
44 </entry>
45 {% endfor %}
46</feed>
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
index 351172c4..530e0492 100644
--- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
+++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
@@ -28,6 +28,7 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
28 { 28 {
29 return [ 29 return [
30 new \Twig_SimpleFilter('removeWww', [$this, 'removeWww']), 30 new \Twig_SimpleFilter('removeWww', [$this, 'removeWww']),
31 new \Twig_SimpleFilter('removeScheme', [$this, 'removeScheme']),
31 ]; 32 ];
32 } 33 }
33 34
@@ -45,6 +46,11 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
45 return preg_replace('/^www\./i', '', $url); 46 return preg_replace('/^www\./i', '', $url);
46 } 47 }
47 48
49 public function removeScheme($url)
50 {
51 return preg_replace('#^https?://#', '', $url);
52 }
53
48 /** 54 /**
49 * Return number of entries depending of the type (unread, archive, starred or all). 55 * Return number of entries depending of the type (unread, archive, starred or all).
50 * 56 *
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
index 6167fe2d..0e4a5afa 100644
--- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
@@ -12,40 +12,39 @@ class RssControllerTest extends WallabagCoreTestCase
12 $doc->loadXML($xml); 12 $doc->loadXML($xml);
13 13
14 $xpath = new \DOMXpath($doc); 14 $xpath = new \DOMXpath($doc);
15 $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom');
15 16
16 if (null === $nb) { 17 if (null === $nb) {
17 $this->assertGreaterThan(0, $xpath->query('//item')->length); 18 $this->assertGreaterThan(0, $xpath->query('//a:entry')->length);
18 } else { 19 } else {
19 $this->assertSame($nb, $xpath->query('//item')->length); 20 $this->assertEquals($nb, $xpath->query('//a:entry')->length);
20 } 21 }
21 22
22 $this->assertSame(1, $xpath->query('/rss')->length); 23 $this->assertEquals(1, $xpath->query('/a:feed')->length);
23 $this->assertSame(1, $xpath->query('/rss/channel')->length);
24 24
25 $this->assertSame(1, $xpath->query('/rss/channel/title')->length); 25 $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length);
26 $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); 26 $this->assertEquals('wallabag '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue);
27 27
28 $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); 28 $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length);
29 29
30 $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); 30 $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length);
31 $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); 31 $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue);
32 32
33 $this->assertSame(1, $xpath->query('/rss/channel/description')->length); 33 $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length);
34 $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); 34 $this->assertEquals('RSS feed for '.$type.' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue);
35 35
36 $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); 36 $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length);
37 $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); 37 $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href'));
38 38
39 $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); 39 $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length);
40 $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
41 40
42 foreach ($xpath->query('//item') as $item) { 41 foreach ($xpath->query('//a:entry') as $item) {
43 $this->assertSame(1, $xpath->query('title', $item)->length); 42 $this->assertEquals(1, $xpath->query('a:title', $item)->length);
44 $this->assertSame(1, $xpath->query('source', $item)->length); 43 $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length);
45 $this->assertSame(1, $xpath->query('link', $item)->length); 44 $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length);
46 $this->assertSame(1, $xpath->query('guid', $item)->length); 45 $this->assertEquals(1, $xpath->query('a:id', $item)->length);
47 $this->assertSame(1, $xpath->query('pubDate', $item)->length); 46 $this->assertEquals(1, $xpath->query('a:published', $item)->length);
48 $this->assertSame(1, $xpath->query('description', $item)->length); 47 $this->assertEquals(1, $xpath->query('a:content', $item)->length);
49 } 48 }
50 } 49 }
51 50
@@ -53,13 +52,13 @@ class RssControllerTest extends WallabagCoreTestCase
53 { 52 {
54 return [ 53 return [
55 [ 54 [
56 '/admin/YZIOAUZIAO/unread.xml', 55 '/feed/admin/YZIOAUZIAO/unread',
57 ], 56 ],
58 [ 57 [
59 '/wallace/YZIOAUZIAO/starred.xml', 58 '/feed/wallace/YZIOAUZIAO/starred',
60 ], 59 ],
61 [ 60 [
62 '/wallace/YZIOAUZIAO/archives.xml', 61 '/feed/wallace/YZIOAUZIAO/archives',
63 ], 62 ],
64 ]; 63 ];
65 } 64 }
@@ -90,7 +89,7 @@ class RssControllerTest extends WallabagCoreTestCase
90 $em->persist($config); 89 $em->persist($config);
91 $em->flush(); 90 $em->flush();
92 91
93 $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); 92 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
94 93
95 $this->assertSame(200, $client->getResponse()->getStatusCode()); 94 $this->assertSame(200, $client->getResponse()->getStatusCode());
96 95
@@ -112,7 +111,7 @@ class RssControllerTest extends WallabagCoreTestCase
112 $em->flush(); 111 $em->flush();
113 112
114 $client = $this->getClient(); 113 $client = $this->getClient();
115 $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); 114 $client->request('GET', '/feed/admin/SUPERTOKEN/starred');
116 115
117 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); 116 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
118 117
@@ -134,7 +133,7 @@ class RssControllerTest extends WallabagCoreTestCase
134 $em->flush(); 133 $em->flush();
135 134
136 $client = $this->getClient(); 135 $client = $this->getClient();
137 $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); 136 $client->request('GET', '/feed/admin/SUPERTOKEN/archive');
138 137
139 $this->assertSame(200, $client->getResponse()->getStatusCode()); 138 $this->assertSame(200, $client->getResponse()->getStatusCode());
140 139
@@ -157,16 +156,16 @@ class RssControllerTest extends WallabagCoreTestCase
157 156
158 $client = $this->getClient(); 157 $client = $this->getClient();
159 158
160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); 159 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
161 $this->assertSame(200, $client->getResponse()->getStatusCode()); 160 $this->assertEquals(200, $client->getResponse()->getStatusCode());
162 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); 161 $this->validateDom($client->getResponse()->getContent(), 'unread');
163 162
164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); 163 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2');
165 $this->assertSame(200, $client->getResponse()->getStatusCode()); 164 $this->assertEquals(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); 165 $this->validateDom($client->getResponse()->getContent(), 'unread');
167 166
168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); 167 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000');
169 $this->assertSame(302, $client->getResponse()->getStatusCode()); 168 $this->assertEquals(302, $client->getResponse()->getStatusCode());
170 } 169 }
171 170
172 public function testTags() 171 public function testTags()
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
index ceec4b37..4cb84ef1 100644
--- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
+++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
@@ -30,4 +30,29 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase
30 $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); 30 $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr'));
31 $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); 31 $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com'));
32 } 32 }
33
34 public function testRemoveScheme()
35 {
36 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
37 ->disableOriginalConstructor()
38 ->getMock();
39
40 $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
41 ->disableOriginalConstructor()
42 ->getMock();
43
44 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
45 ->disableOriginalConstructor()
46 ->getMock();
47
48 $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')
49 ->disableOriginalConstructor()
50 ->getMock();
51
52 $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator);
53
54 $this->assertEquals('lemonde.fr', $extension->removeScheme('lemonde.fr'));
55 $this->assertEquals('gist.github.com', $extension->removeScheme('gist.github.com'));
56 $this->assertEquals('gist.github.com', $extension->removeScheme('https://gist.github.com'));
57 }
33} 58}