diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-04-01 21:08:56 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-04-01 21:08:56 +0200 |
commit | 1a93ee423b072ec3bcb0c437cbf9b488bdea245c (patch) | |
tree | 1466dcb1b465f9ead71c4dcbefe380853c5d846b /src/Wallabag/CoreBundle/Controller | |
parent | f98a2a0fc3ae8a5955bb811f083c3d2535f96791 (diff) | |
parent | 7d74a2f32b55fa9c33f5ecff57785e8d9e4de8ae (diff) | |
download | wallabag-1a93ee423b072ec3bcb0c437cbf9b488bdea245c.tar.gz wallabag-1a93ee423b072ec3bcb0c437cbf9b488bdea245c.tar.zst wallabag-1a93ee423b072ec3bcb0c437cbf9b488bdea245c.zip |
Merge pull request #1166 from wallabag/v2-rss
Add RSS feeds
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 58 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/RssController.php | 84 |
2 files changed, 138 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 4e895875..dbae3ea7 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -5,11 +5,14 @@ namespace Wallabag\CoreBundle\Controller; | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
8 | use Wallabag\CoreBundle\Entity\Config; | 9 | use Wallabag\CoreBundle\Entity\Config; |
9 | use Wallabag\CoreBundle\Entity\User; | 10 | use Wallabag\CoreBundle\Entity\User; |
10 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 11 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
11 | use Wallabag\CoreBundle\Form\Type\UserType; | 12 | use Wallabag\CoreBundle\Form\Type\UserType; |
12 | use Wallabag\CoreBundle\Form\Type\NewUserType; | 13 | use Wallabag\CoreBundle\Form\Type\NewUserType; |
14 | use Wallabag\CoreBundle\Form\Type\RssType; | ||
15 | use Wallabag\CoreBundle\Tools\Utils; | ||
13 | 16 | ||
14 | class ConfigController extends Controller | 17 | class ConfigController extends Controller |
15 | { | 18 | { |
@@ -77,6 +80,22 @@ class ConfigController extends Controller | |||
77 | return $this->redirect($this->generateUrl('config')); | 80 | return $this->redirect($this->generateUrl('config')); |
78 | } | 81 | } |
79 | 82 | ||
83 | // handle rss information | ||
84 | $rssForm = $this->createForm(new RssType(), $config); | ||
85 | $rssForm->handleRequest($request); | ||
86 | |||
87 | if ($rssForm->isValid()) { | ||
88 | $em->persist($config); | ||
89 | $em->flush(); | ||
90 | |||
91 | $this->get('session')->getFlashBag()->add( | ||
92 | 'notice', | ||
93 | 'RSS information updated' | ||
94 | ); | ||
95 | |||
96 | return $this->redirect($this->generateUrl('config')); | ||
97 | } | ||
98 | |||
80 | // handle adding new user | 99 | // handle adding new user |
81 | $newUser = new User(); | 100 | $newUser = new User(); |
82 | $newUserForm = $this->createForm(new NewUserType(), $newUser); | 101 | $newUserForm = $this->createForm(new NewUserType(), $newUser); |
@@ -88,6 +107,7 @@ class ConfigController extends Controller | |||
88 | $config = new Config($newUser); | 107 | $config = new Config($newUser); |
89 | $config->setTheme($this->container->getParameter('theme')); | 108 | $config->setTheme($this->container->getParameter('theme')); |
90 | $config->setItemsPerPage($this->container->getParameter('items_on_page')); | 109 | $config->setItemsPerPage($this->container->getParameter('items_on_page')); |
110 | $config->setRssLimit($this->container->getParameter('rss_limit')); | ||
91 | $config->setLanguage($this->container->getParameter('language')); | 111 | $config->setLanguage($this->container->getParameter('language')); |
92 | 112 | ||
93 | $em->persist($config); | 113 | $em->persist($config); |
@@ -103,14 +123,44 @@ class ConfigController extends Controller | |||
103 | } | 123 | } |
104 | 124 | ||
105 | return $this->render('WallabagCoreBundle:Config:index.html.twig', array( | 125 | return $this->render('WallabagCoreBundle:Config:index.html.twig', array( |
106 | 'configForm' => $configForm->createView(), | 126 | 'form' => array( |
107 | 'pwdForm' => $pwdForm->createView(), | 127 | 'config' => $configForm->createView(), |
108 | 'userForm' => $userForm->createView(), | 128 | 'rss' => $rssForm->createView(), |
109 | 'newUserForm' => $newUserForm->createView(), | 129 | 'pwd' => $pwdForm->createView(), |
130 | 'user' => $userForm->createView(), | ||
131 | 'new_user' => $newUserForm->createView(), | ||
132 | ), | ||
133 | 'rss' => array( | ||
134 | 'username' => $user->getUsername(), | ||
135 | 'token' => $config->getRssToken(), | ||
136 | ) | ||
110 | )); | 137 | )); |
111 | } | 138 | } |
112 | 139 | ||
113 | /** | 140 | /** |
141 | * @param Request $request | ||
142 | * | ||
143 | * @Route("/generate-token", name="generate_token") | ||
144 | * | ||
145 | * @return JsonResponse | ||
146 | */ | ||
147 | public function generateTokenAction(Request $request) | ||
148 | { | ||
149 | $config = $this->getConfig(); | ||
150 | $config->setRssToken(Utils::generateToken()); | ||
151 | |||
152 | $em = $this->getDoctrine()->getManager(); | ||
153 | $em->persist($config); | ||
154 | $em->flush(); | ||
155 | |||
156 | if ($request->isXmlHttpRequest()) { | ||
157 | return new JsonResponse(array('token' => $config->getRssToken())); | ||
158 | } | ||
159 | |||
160 | return $request->headers->get('referer') ? $this->redirect($request->headers->get('referer')) : $this->redirectToRoute('config'); | ||
161 | } | ||
162 | |||
163 | /** | ||
114 | * Retrieve config for the current user. | 164 | * Retrieve config for the current user. |
115 | * If no config were found, create a new one. | 165 | * If no config were found, create a new one. |
116 | * | 166 | * |
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php new file mode 100644 index 00000000..14f1dcb2 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/RssController.php | |||
@@ -0,0 +1,84 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
8 | use Wallabag\CoreBundle\Entity\User; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
10 | |||
11 | class RssController extends Controller | ||
12 | { | ||
13 | /** | ||
14 | * Shows unread entries for current user | ||
15 | * | ||
16 | * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"}) | ||
17 | * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") | ||
18 | * | ||
19 | * @return \Symfony\Component\HttpFoundation\Response | ||
20 | */ | ||
21 | public function showUnreadAction(User $user) | ||
22 | { | ||
23 | $entries = $this->getDoctrine() | ||
24 | ->getRepository('WallabagCoreBundle:Entry') | ||
25 | ->findUnreadByUser( | ||
26 | $user->getId(), | ||
27 | 0, | ||
28 | $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit') | ||
29 | ); | ||
30 | |||
31 | return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( | ||
32 | 'type' => 'unread', | ||
33 | 'entries' => $entries, | ||
34 | )); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * Shows read entries for current user | ||
39 | * | ||
40 | * @Route("/{username}/{token}/archive.xml", name="archive_rss") | ||
41 | * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") | ||
42 | * | ||
43 | * @return \Symfony\Component\HttpFoundation\Response | ||
44 | */ | ||
45 | public function showArchiveAction(User $user) | ||
46 | { | ||
47 | $entries = $this->getDoctrine() | ||
48 | ->getRepository('WallabagCoreBundle:Entry') | ||
49 | ->findArchiveByUser( | ||
50 | $user->getId(), | ||
51 | 0, | ||
52 | $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit') | ||
53 | ); | ||
54 | |||
55 | return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( | ||
56 | 'type' => 'archive', | ||
57 | 'entries' => $entries, | ||
58 | )); | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Shows starred entries for current user | ||
63 | * | ||
64 | * @Route("/{username}/{token}/starred.xml", name="starred_rss") | ||
65 | * @ParamConverter("user", class="WallabagCoreBundle:User", converter="username_rsstoken_converter") | ||
66 | * | ||
67 | * @return \Symfony\Component\HttpFoundation\Response | ||
68 | */ | ||
69 | public function showStarredAction(User $user) | ||
70 | { | ||
71 | $entries = $this->getDoctrine() | ||
72 | ->getRepository('WallabagCoreBundle:Entry') | ||
73 | ->findStarredByUser( | ||
74 | $user->getId(), | ||
75 | 0, | ||
76 | $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit') | ||
77 | ); | ||
78 | |||
79 | return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( | ||
80 | 'type' => 'starred', | ||
81 | 'entries' => $entries, | ||
82 | )); | ||
83 | } | ||
84 | } | ||