diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 100 |
1 files changed, 96 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ccdf9406..624576b5 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,6 +12,7 @@ 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 | { |
@@ -226,6 +226,10 @@ class EntryController extends Controller | |||
226 | $repository = $this->get('wallabag_core.entry_repository'); | 226 | $repository = $this->get('wallabag_core.entry_repository'); |
227 | 227 | ||
228 | switch ($type) { | 228 | switch ($type) { |
229 | case 'untagged': | ||
230 | $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); | ||
231 | |||
232 | break; | ||
229 | case 'starred': | 233 | case 'starred': |
230 | $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); | 234 | $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); |
231 | break; | 235 | break; |
@@ -257,9 +261,10 @@ class EntryController extends Controller | |||
257 | } | 261 | } |
258 | 262 | ||
259 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); | 263 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); |
260 | $entries = new Pagerfanta($pagerAdapter); | ||
261 | 264 | ||
262 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); | 265 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') |
266 | ->prepare($pagerAdapter, $page); | ||
267 | |||
263 | try { | 268 | try { |
264 | $entries->setCurrentPage($page); | 269 | $entries->setCurrentPage($page); |
265 | } catch (OutOfRangeCurrentPageException $e) { | 270 | } catch (OutOfRangeCurrentPageException $e) { |
@@ -434,7 +439,7 @@ class EntryController extends Controller | |||
434 | */ | 439 | */ |
435 | private function checkUserAction(Entry $entry) | 440 | private function checkUserAction(Entry $entry) |
436 | { | 441 | { |
437 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { | 442 | if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) { |
438 | throw $this->createAccessDeniedException('You can not access this entry.'); | 443 | throw $this->createAccessDeniedException('You can not access this entry.'); |
439 | } | 444 | } |
440 | } | 445 | } |
@@ -450,4 +455,91 @@ class EntryController extends Controller | |||
450 | { | 455 | { |
451 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); | 456 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); |
452 | } | 457 | } |
458 | |||
459 | /** | ||
460 | * Get public URL for entry (and generate it if necessary). | ||
461 | * | ||
462 | * @param Entry $entry | ||
463 | * | ||
464 | * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share") | ||
465 | * | ||
466 | * @return \Symfony\Component\HttpFoundation\Response | ||
467 | */ | ||
468 | public function shareAction(Entry $entry) | ||
469 | { | ||
470 | $this->checkUserAction($entry); | ||
471 | |||
472 | if (null === $entry->getUuid()) { | ||
473 | $entry->generateUuid(); | ||
474 | |||
475 | $em = $this->getDoctrine()->getManager(); | ||
476 | $em->persist($entry); | ||
477 | $em->flush(); | ||
478 | } | ||
479 | |||
480 | return $this->redirect($this->generateUrl('share_entry', [ | ||
481 | 'uuid' => $entry->getUuid(), | ||
482 | ])); | ||
483 | } | ||
484 | |||
485 | /** | ||
486 | * Disable public sharing for an entry. | ||
487 | * | ||
488 | * @param Entry $entry | ||
489 | * | ||
490 | * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share") | ||
491 | * | ||
492 | * @return \Symfony\Component\HttpFoundation\Response | ||
493 | */ | ||
494 | public function deleteShareAction(Entry $entry) | ||
495 | { | ||
496 | $this->checkUserAction($entry); | ||
497 | |||
498 | $entry->cleanUuid(); | ||
499 | |||
500 | $em = $this->getDoctrine()->getManager(); | ||
501 | $em->persist($entry); | ||
502 | $em->flush(); | ||
503 | |||
504 | return $this->redirect($this->generateUrl('view', [ | ||
505 | 'id' => $entry->getId(), | ||
506 | ])); | ||
507 | } | ||
508 | |||
509 | /** | ||
510 | * Ability to view a content publicly. | ||
511 | * | ||
512 | * @param Entry $entry | ||
513 | * | ||
514 | * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") | ||
515 | * @Cache(maxage="25200", smaxage="25200", public=true) | ||
516 | * | ||
517 | * @return \Symfony\Component\HttpFoundation\Response | ||
518 | */ | ||
519 | public function shareEntryAction(Entry $entry) | ||
520 | { | ||
521 | if (!$this->get('craue_config')->get('share_public')) { | ||
522 | throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.'); | ||
523 | } | ||
524 | |||
525 | return $this->render( | ||
526 | '@WallabagCore/themes/share.html.twig', | ||
527 | ['entry' => $entry] | ||
528 | ); | ||
529 | } | ||
530 | |||
531 | /** | ||
532 | * Shows untagged articles for current user. | ||
533 | * | ||
534 | * @param Request $request | ||
535 | * @param int $page | ||
536 | * | ||
537 | * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"}) | ||
538 | * | ||
539 | * @return \Symfony\Component\HttpFoundation\Response | ||
540 | */ | ||
541 | public function showUntaggedEntriesAction(Request $request, $page) | ||
542 | { | ||
543 | return $this->showEntries('untagged', $request, $page); | ||
544 | } | ||
453 | } | 545 | } |