aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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 /src
parentb5d7eb148c4cd62ff187b08765f0c13c7d330fcf (diff)
downloadwallabag-47e2d609bcac6de4893cc04559c0794642c30a80.tar.gz
wallabag-47e2d609bcac6de4893cc04559c0794642c30a80.tar.zst
wallabag-47e2d609bcac6de4893cc04559c0794642c30a80.zip
Changed RSS to Atom feed and improve paging
Diffstat (limited to 'src')
-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
3 files changed, 74 insertions, 52 deletions
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 *