diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
5 files changed, 176 insertions, 56 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php index d85ba5ee..63386db0 100644 --- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php +++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php | |||
@@ -49,12 +49,13 @@ class DeveloperController extends Controller | |||
49 | 49 | ||
50 | $this->get('session')->getFlashBag()->add( | 50 | $this->get('session')->getFlashBag()->add( |
51 | 'notice', | 51 | 'notice', |
52 | 'flashes.developer.notice.client_created' | 52 | $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()]) |
53 | ); | 53 | ); |
54 | 54 | ||
55 | return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', [ | 55 | return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', [ |
56 | 'client_id' => $client->getPublicId(), | 56 | 'client_id' => $client->getPublicId(), |
57 | 'client_secret' => $client->getSecret(), | 57 | 'client_secret' => $client->getSecret(), |
58 | 'client_name' => $client->getName(), | ||
58 | ]); | 59 | ]); |
59 | } | 60 | } |
60 | 61 | ||
@@ -80,7 +81,7 @@ class DeveloperController extends Controller | |||
80 | 81 | ||
81 | $this->get('session')->getFlashBag()->add( | 82 | $this->get('session')->getFlashBag()->add( |
82 | 'notice', | 83 | 'notice', |
83 | 'flashes.developer.notice.client_deleted' | 84 | $this->get('translator')->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()]) |
84 | ); | 85 | ); |
85 | 86 | ||
86 | return $this->redirect($this->generateUrl('developer')); | 87 | return $this->redirect($this->generateUrl('developer')); |
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ccdf9406..40111af0 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\Controller; | |||
4 | 4 | ||
5 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 5 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Pagerfanta\Pagerfanta; | ||
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
@@ -13,30 +12,40 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
13 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; | 12 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; |
14 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
15 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
15 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | ||
16 | 16 | ||
17 | class EntryController extends Controller | 17 | class EntryController extends Controller |
18 | { | 18 | { |
19 | /** | 19 | /** |
20 | * @param Entry $entry | 20 | * Fetch content and update entry. |
21 | * In case it fails, entry will return to avod loosing the data. | ||
22 | * | ||
23 | * @param Entry $entry | ||
24 | * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded | ||
25 | * | ||
26 | * @return Entry | ||
21 | */ | 27 | */ |
22 | private function updateEntry(Entry $entry) | 28 | private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved') |
23 | { | 29 | { |
30 | // put default title in case of fetching content failed | ||
31 | $entry->setTitle('No title found'); | ||
32 | |||
33 | $message = 'flashes.entry.notice.'.$prefixMessage; | ||
34 | |||
24 | try { | 35 | try { |
25 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | 36 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); |
26 | |||
27 | $em = $this->getDoctrine()->getManager(); | ||
28 | $em->persist($entry); | ||
29 | $em->flush(); | ||
30 | } catch (\Exception $e) { | 37 | } catch (\Exception $e) { |
31 | $this->get('logger')->error('Error while saving an entry', [ | 38 | $this->get('logger')->error('Error while saving an entry', [ |
32 | 'exception' => $e, | 39 | 'exception' => $e, |
33 | 'entry' => $entry, | 40 | 'entry' => $entry, |
34 | ]); | 41 | ]); |
35 | 42 | ||
36 | return false; | 43 | $message = 'flashes.entry.notice.'.$prefixMessage.'_failed'; |
37 | } | 44 | } |
38 | 45 | ||
39 | return true; | 46 | $this->get('session')->getFlashBag()->add('notice', $message); |
47 | |||
48 | return $entry; | ||
40 | } | 49 | } |
41 | 50 | ||
42 | /** | 51 | /** |
@@ -66,12 +75,11 @@ class EntryController extends Controller | |||
66 | return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()])); | 75 | return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()])); |
67 | } | 76 | } |
68 | 77 | ||
69 | $message = 'flashes.entry.notice.entry_saved'; | 78 | $this->updateEntry($entry); |
70 | if (false === $this->updateEntry($entry)) { | ||
71 | $message = 'flashes.entry.notice.entry_saved_failed'; | ||
72 | } | ||
73 | 79 | ||
74 | $this->get('session')->getFlashBag()->add('notice', $message); | 80 | $em = $this->getDoctrine()->getManager(); |
81 | $em->persist($entry); | ||
82 | $em->flush(); | ||
75 | 83 | ||
76 | return $this->redirect($this->generateUrl('homepage')); | 84 | return $this->redirect($this->generateUrl('homepage')); |
77 | } | 85 | } |
@@ -95,6 +103,10 @@ class EntryController extends Controller | |||
95 | 103 | ||
96 | if (false === $this->checkIfEntryAlreadyExists($entry)) { | 104 | if (false === $this->checkIfEntryAlreadyExists($entry)) { |
97 | $this->updateEntry($entry); | 105 | $this->updateEntry($entry); |
106 | |||
107 | $em = $this->getDoctrine()->getManager(); | ||
108 | $em->persist($entry); | ||
109 | $em->flush(); | ||
98 | } | 110 | } |
99 | 111 | ||
100 | return $this->redirect($this->generateUrl('homepage')); | 112 | return $this->redirect($this->generateUrl('homepage')); |
@@ -226,6 +238,10 @@ class EntryController extends Controller | |||
226 | $repository = $this->get('wallabag_core.entry_repository'); | 238 | $repository = $this->get('wallabag_core.entry_repository'); |
227 | 239 | ||
228 | switch ($type) { | 240 | switch ($type) { |
241 | case 'untagged': | ||
242 | $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); | ||
243 | |||
244 | break; | ||
229 | case 'starred': | 245 | case 'starred': |
230 | $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); | 246 | $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); |
231 | break; | 247 | break; |
@@ -257,9 +273,10 @@ class EntryController extends Controller | |||
257 | } | 273 | } |
258 | 274 | ||
259 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); | 275 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); |
260 | $entries = new Pagerfanta($pagerAdapter); | ||
261 | 276 | ||
262 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); | 277 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') |
278 | ->prepare($pagerAdapter, $page); | ||
279 | |||
263 | try { | 280 | try { |
264 | $entries->setCurrentPage($page); | 281 | $entries->setCurrentPage($page); |
265 | } catch (OutOfRangeCurrentPageException $e) { | 282 | } catch (OutOfRangeCurrentPageException $e) { |
@@ -311,15 +328,11 @@ class EntryController extends Controller | |||
311 | { | 328 | { |
312 | $this->checkUserAction($entry); | 329 | $this->checkUserAction($entry); |
313 | 330 | ||
314 | $message = 'flashes.entry.notice.entry_reloaded'; | 331 | $this->updateEntry($entry, 'entry_reloaded'); |
315 | if (false === $this->updateEntry($entry)) { | ||
316 | $message = 'flashes.entry.notice.entry_reload_failed'; | ||
317 | } | ||
318 | 332 | ||
319 | $this->get('session')->getFlashBag()->add( | 333 | $em = $this->getDoctrine()->getManager(); |
320 | 'notice', | 334 | $em->persist($entry); |
321 | $message | 335 | $em->flush(); |
322 | ); | ||
323 | 336 | ||
324 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); | 337 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); |
325 | } | 338 | } |
@@ -434,7 +447,7 @@ class EntryController extends Controller | |||
434 | */ | 447 | */ |
435 | private function checkUserAction(Entry $entry) | 448 | private function checkUserAction(Entry $entry) |
436 | { | 449 | { |
437 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { | 450 | if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) { |
438 | throw $this->createAccessDeniedException('You can not access this entry.'); | 451 | throw $this->createAccessDeniedException('You can not access this entry.'); |
439 | } | 452 | } |
440 | } | 453 | } |
@@ -450,4 +463,91 @@ class EntryController extends Controller | |||
450 | { | 463 | { |
451 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); | 464 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); |
452 | } | 465 | } |
466 | |||
467 | /** | ||
468 | * Get public URL for entry (and generate it if necessary). | ||
469 | * | ||
470 | * @param Entry $entry | ||
471 | * | ||
472 | * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share") | ||
473 | * | ||
474 | * @return \Symfony\Component\HttpFoundation\Response | ||
475 | */ | ||
476 | public function shareAction(Entry $entry) | ||
477 | { | ||
478 | $this->checkUserAction($entry); | ||
479 | |||
480 | if (null === $entry->getUuid()) { | ||
481 | $entry->generateUuid(); | ||
482 | |||
483 | $em = $this->getDoctrine()->getManager(); | ||
484 | $em->persist($entry); | ||
485 | $em->flush(); | ||
486 | } | ||
487 | |||
488 | return $this->redirect($this->generateUrl('share_entry', [ | ||
489 | 'uuid' => $entry->getUuid(), | ||
490 | ])); | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * Disable public sharing for an entry. | ||
495 | * | ||
496 | * @param Entry $entry | ||
497 | * | ||
498 | * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share") | ||
499 | * | ||
500 | * @return \Symfony\Component\HttpFoundation\Response | ||
501 | */ | ||
502 | public function deleteShareAction(Entry $entry) | ||
503 | { | ||
504 | $this->checkUserAction($entry); | ||
505 | |||
506 | $entry->cleanUuid(); | ||
507 | |||
508 | $em = $this->getDoctrine()->getManager(); | ||
509 | $em->persist($entry); | ||
510 | $em->flush(); | ||
511 | |||
512 | return $this->redirect($this->generateUrl('view', [ | ||
513 | 'id' => $entry->getId(), | ||
514 | ])); | ||
515 | } | ||
516 | |||
517 | /** | ||
518 | * Ability to view a content publicly. | ||
519 | * | ||
520 | * @param Entry $entry | ||
521 | * | ||
522 | * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") | ||
523 | * @Cache(maxage="25200", smaxage="25200", public=true) | ||
524 | * | ||
525 | * @return \Symfony\Component\HttpFoundation\Response | ||
526 | */ | ||
527 | public function shareEntryAction(Entry $entry) | ||
528 | { | ||
529 | if (!$this->get('craue_config')->get('share_public')) { | ||
530 | throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.'); | ||
531 | } | ||
532 | |||
533 | return $this->render( | ||
534 | '@WallabagCore/themes/share.html.twig', | ||
535 | ['entry' => $entry] | ||
536 | ); | ||
537 | } | ||
538 | |||
539 | /** | ||
540 | * Shows untagged articles for current user. | ||
541 | * | ||
542 | * @param Request $request | ||
543 | * @param int $page | ||
544 | * | ||
545 | * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"}) | ||
546 | * | ||
547 | * @return \Symfony\Component\HttpFoundation\Response | ||
548 | */ | ||
549 | public function showUntaggedEntriesAction(Request $request, $page) | ||
550 | { | ||
551 | return $this->showEntries('untagged', $request, $page); | ||
552 | } | ||
453 | } | 553 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index 944c755d..6191d5d7 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php | |||
@@ -46,7 +46,7 @@ class ExportController extends Controller | |||
46 | * | 46 | * |
47 | * @Route("/export/{category}.{format}", name="export_entries", requirements={ | 47 | * @Route("/export/{category}.{format}", name="export_entries", requirements={ |
48 | * "format": "epub|mobi|pdf|json|xml|txt|csv", | 48 | * "format": "epub|mobi|pdf|json|xml|txt|csv", |
49 | * "category": "all|unread|starred|archive" | 49 | * "category": "all|unread|starred|archive|tag_entries|untagged" |
50 | * }) | 50 | * }) |
51 | * | 51 | * |
52 | * @return \Symfony\Component\HttpFoundation\Response | 52 | * @return \Symfony\Component\HttpFoundation\Response |
diff --git a/src/Wallabag/CoreBundle/Controller/FooterController.php b/src/Wallabag/CoreBundle/Controller/FooterController.php deleted file mode 100644 index fd93c436..00000000 --- a/src/Wallabag/CoreBundle/Controller/FooterController.php +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
6 | |||
7 | class FooterController extends Controller | ||
8 | { | ||
9 | /** | ||
10 | * Display the footer. | ||
11 | * | ||
12 | * @return \Symfony\Component\HttpFoundation\Response | ||
13 | */ | ||
14 | public function indexAction() | ||
15 | { | ||
16 | $addonsUrl = $this->container->getParameter('addons_url'); | ||
17 | $socialsUrl = $this->container->getParameter('socials_url'); | ||
18 | |||
19 | return $this->render( | ||
20 | 'WallabagCoreBundle::footer.html.twig', | ||
21 | [ | ||
22 | 'addonsUrl' => $addonsUrl, | ||
23 | 'socialsUrl' => $socialsUrl, | ||
24 | ] | ||
25 | ); | ||
26 | } | ||
27 | } | ||
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 8645fb44..bc95a4d3 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -2,12 +2,15 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Pagerfanta\Adapter\ArrayAdapter; | ||
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\CoreBundle\Entity\Entry; | 10 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Entity\Tag; | 11 | use Wallabag\CoreBundle\Entity\Tag; |
10 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 12 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
13 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
11 | 14 | ||
12 | class TagController extends Controller | 15 | class TagController extends Controller |
13 | { | 16 | { |
@@ -81,7 +84,9 @@ class TagController extends Controller | |||
81 | { | 84 | { |
82 | $tags = $this->getDoctrine() | 85 | $tags = $this->getDoctrine() |
83 | ->getRepository('WallabagCoreBundle:Tag') | 86 | ->getRepository('WallabagCoreBundle:Tag') |
84 | ->findAllTags($this->getUser()->getId()); | 87 | ->findAllTags($this->getUser()->getId()) |
88 | ->getQuery() | ||
89 | ->getResult(); | ||
85 | 90 | ||
86 | return $this->render( | 91 | return $this->render( |
87 | 'WallabagCoreBundle:Tag:tags.html.twig', | 92 | 'WallabagCoreBundle:Tag:tags.html.twig', |
@@ -90,4 +95,45 @@ class TagController extends Controller | |||
90 | ] | 95 | ] |
91 | ); | 96 | ); |
92 | } | 97 | } |
98 | |||
99 | /** | ||
100 | * @param Tag $tag | ||
101 | * @param int $page | ||
102 | * | ||
103 | * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) | ||
104 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
105 | * | ||
106 | * @return \Symfony\Component\HttpFoundation\Response | ||
107 | */ | ||
108 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) | ||
109 | { | ||
110 | $entriesByTag = $this->getDoctrine() | ||
111 | ->getRepository('WallabagCoreBundle:Entry') | ||
112 | ->findAllByTagId($this->getUser()->getId(), $tag->getId()); | ||
113 | |||
114 | $pagerAdapter = new ArrayAdapter($entriesByTag); | ||
115 | |||
116 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') | ||
117 | ->prepare($pagerAdapter, $page); | ||
118 | |||
119 | try { | ||
120 | $entries->setCurrentPage($page); | ||
121 | } catch (OutOfRangeCurrentPageException $e) { | ||
122 | if ($page > 1) { | ||
123 | return $this->redirect($this->generateUrl($request->get('_route'), [ | ||
124 | 'slug' => $tag->getSlug(), | ||
125 | 'page' => $entries->getNbPages(), | ||
126 | ]), 302); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return $this->render( | ||
131 | 'WallabagCoreBundle:Entry:entries.html.twig', | ||
132 | [ | ||
133 | 'form' => null, | ||
134 | 'entries' => $entries, | ||
135 | 'currentPage' => $page, | ||
136 | ] | ||
137 | ); | ||
138 | } | ||
93 | } | 139 | } |