From f3d0cb91063840f2b05c63954d3fef3e5b8943fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 10 Apr 2016 17:33:15 +0200 Subject: Share entry with a public URL --- .../CoreBundle/Controller/EntryController.php | 31 +++++++++++++++++ src/Wallabag/CoreBundle/Entity/Entry.php | 38 +++++++++++++++++++++ .../views/themes/material/Entry/entry.html.twig | 8 ++++- .../Resources/views/themes/share.html.twig | 39 ++++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/share.html.twig (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 93db0d6c..a78dd00c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -291,6 +291,8 @@ class EntryController extends Controller { $this->checkUserAction($entry); + $this->generateEntryUuid($entry); + return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] @@ -449,5 +451,34 @@ class EntryController extends Controller private function checkIfEntryAlreadyExists(Entry $entry) { return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); + + } + + /* + * Share entry content. + * + * @param Entry $entry + * + * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function shareEntry(Entry $entry) + { + return $this->render( + '@WallabagCore/themes/share.html.twig', + array('entry' => $entry) + ); + } + + /** + * @param Entry $entry + */ + private function generateEntryUuid(Entry $entry) + { + $entry->generateUuid(); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); } } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index ceae78b0..3c742828 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -37,6 +37,15 @@ class Entry */ private $id; + /** + * @var int + * + * @ORM\Column(name="uuid", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $uuid; + /** * @var string * @@ -427,6 +436,8 @@ class Entry } $this->updatedAt = new \DateTime(); + + $this->generateUuid(); } /** @@ -595,4 +606,31 @@ class Entry { return $this->language; } + + /** + * @return int + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * @param int $uuid + * + * @return Entry + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + + return $this; + } + + public function generateUuid() + { + if (empty($this->uuid) || is_null($this->uuid)) { + $this->uuid = uniqid(); + } + } } diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 5dd2afb3..b634dd40 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig @@ -99,6 +99,13 @@