diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 93db0d6c..d71ba6cd 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -12,6 +12,7 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
12 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; | 12 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; |
13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
15 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | ||
15 | 16 | ||
16 | class EntryController extends Controller | 17 | class EntryController extends Controller |
17 | { | 18 | { |
@@ -434,7 +435,7 @@ class EntryController extends Controller | |||
434 | */ | 435 | */ |
435 | private function checkUserAction(Entry $entry) | 436 | private function checkUserAction(Entry $entry) |
436 | { | 437 | { |
437 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { | 438 | if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) { |
438 | throw $this->createAccessDeniedException('You can not access this entry.'); | 439 | throw $this->createAccessDeniedException('You can not access this entry.'); |
439 | } | 440 | } |
440 | } | 441 | } |
@@ -450,4 +451,76 @@ class EntryController extends Controller | |||
450 | { | 451 | { |
451 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); | 452 | return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); |
452 | } | 453 | } |
454 | |||
455 | /** | ||
456 | * Get public URL for entry (and generate it if necessary). | ||
457 | * | ||
458 | * @param Entry $entry | ||
459 | * | ||
460 | * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share") | ||
461 | * | ||
462 | * @return \Symfony\Component\HttpFoundation\Response | ||
463 | */ | ||
464 | public function shareAction(Entry $entry) | ||
465 | { | ||
466 | $this->checkUserAction($entry); | ||
467 | |||
468 | if (null === $entry->getUuid()) { | ||
469 | $entry->generateUuid(); | ||
470 | |||
471 | $em = $this->getDoctrine()->getManager(); | ||
472 | $em->persist($entry); | ||
473 | $em->flush(); | ||
474 | } | ||
475 | |||
476 | return $this->redirect($this->generateUrl('share_entry', [ | ||
477 | 'uuid' => $entry->getUuid(), | ||
478 | ])); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Disable public sharing for an entry. | ||
483 | * | ||
484 | * @param Entry $entry | ||
485 | * | ||
486 | * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share") | ||
487 | * | ||
488 | * @return \Symfony\Component\HttpFoundation\Response | ||
489 | */ | ||
490 | public function deleteShareAction(Entry $entry) | ||
491 | { | ||
492 | $this->checkUserAction($entry); | ||
493 | |||
494 | $entry->cleanUuid(); | ||
495 | |||
496 | $em = $this->getDoctrine()->getManager(); | ||
497 | $em->persist($entry); | ||
498 | $em->flush(); | ||
499 | |||
500 | return $this->redirect($this->generateUrl('view', [ | ||
501 | 'id' => $entry->getId(), | ||
502 | ])); | ||
503 | } | ||
504 | |||
505 | /** | ||
506 | * Ability to view a content publicly. | ||
507 | * | ||
508 | * @param Entry $entry | ||
509 | * | ||
510 | * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") | ||
511 | * @Cache(maxage="25200", smaxage="25200", public=true) | ||
512 | * | ||
513 | * @return \Symfony\Component\HttpFoundation\Response | ||
514 | */ | ||
515 | public function shareEntryAction(Entry $entry) | ||
516 | { | ||
517 | if (!$this->get('craue_config')->get('share_public')) { | ||
518 | throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.'); | ||
519 | } | ||
520 | |||
521 | return $this->render( | ||
522 | '@WallabagCore/themes/share.html.twig', | ||
523 | ['entry' => $entry] | ||
524 | ); | ||
525 | } | ||
453 | } | 526 | } |