aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
authorJeremy <jeremy.benoist@gmail.com>2015-03-28 14:27:45 +0100
committerJeremy <jeremy.benoist@gmail.com>2015-03-31 22:47:43 +0200
commit0c83fd5994861efa728097dd151c994796c39ae1 (patch)
tree925520c0bb62d2b9ba7270020fc2ebcebb520f8c /src/Wallabag/CoreBundle/Controller
parentf98a2a0fc3ae8a5955bb811f083c3d2535f96791 (diff)
downloadwallabag-0c83fd5994861efa728097dd151c994796c39ae1.tar.gz
wallabag-0c83fd5994861efa728097dd151c994796c39ae1.tar.zst
wallabag-0c83fd5994861efa728097dd151c994796c39ae1.zip
Add rss for entries
will fix #1000
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php58
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php84
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..1622f348 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -5,11 +5,14 @@ namespace Wallabag\CoreBundle\Controller;
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\JsonResponse;
8use Wallabag\CoreBundle\Entity\Config; 9use Wallabag\CoreBundle\Entity\Config;
9use Wallabag\CoreBundle\Entity\User; 10use Wallabag\CoreBundle\Entity\User;
10use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 11use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
11use Wallabag\CoreBundle\Form\Type\UserType; 12use Wallabag\CoreBundle\Form\Type\UserType;
12use Wallabag\CoreBundle\Form\Type\NewUserType; 13use Wallabag\CoreBundle\Form\Type\NewUserType;
14use Wallabag\CoreBundle\Form\Type\RssType;
15use Wallabag\CoreBundle\Tools\Utils;
13 16
14class ConfigController extends Controller 17class 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->getContainer()->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..f2f8dd65
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Controller/RssController.php
@@ -0,0 +1,84 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
7use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8use Wallabag\CoreBundle\Entity\User;
9use Wallabag\CoreBundle\Entity\Entry;
10
11class 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->getContainer()->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->getContainer()->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->getContainer()->getParameter('rss_limit')
77 );
78
79 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
80 'type' => 'starred',
81 'entries' => $entries,
82 ));
83 }
84}