aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-04-10 17:33:15 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-08-23 16:49:21 +0200
commitf3d0cb91063840f2b05c63954d3fef3e5b8943fd (patch)
tree5ee9a0c73e7a3e4c8d6da1761a8ce23110f8125a
parent1bee9e0760c89756ebab0b67f9ab7efc5c6a709b (diff)
downloadwallabag-f3d0cb91063840f2b05c63954d3fef3e5b8943fd.tar.gz
wallabag-f3d0cb91063840f2b05c63954d3fef3e5b8943fd.tar.zst
wallabag-f3d0cb91063840f2b05c63954d3fef3e5b8943fd.zip
Share entry with a public URL
-rw-r--r--app/config/security.yml1
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php31
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php38
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig8
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/share.html.twig39
5 files changed, 116 insertions, 1 deletions
diff --git a/app/config/security.yml b/app/config/security.yml
index e24e03df..1f30e58b 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -60,6 +60,7 @@ security:
60 - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 60 - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
61 - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 61 - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
62 - { path: /(unread|starred|archive).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } 62 - { path: /(unread|starred|archive).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
63 - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY }
63 - { path: ^/settings, roles: ROLE_SUPER_ADMIN } 64 - { path: ^/settings, roles: ROLE_SUPER_ADMIN }
64 - { path: ^/annotations, roles: ROLE_USER } 65 - { path: ^/annotations, roles: ROLE_USER }
65 - { path: ^/, roles: ROLE_USER } 66 - { path: ^/, roles: ROLE_USER }
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
291 { 291 {
292 $this->checkUserAction($entry); 292 $this->checkUserAction($entry);
293 293
294 $this->generateEntryUuid($entry);
295
294 return $this->render( 296 return $this->render(
295 'WallabagCoreBundle:Entry:entry.html.twig', 297 'WallabagCoreBundle:Entry:entry.html.twig',
296 ['entry' => $entry] 298 ['entry' => $entry]
@@ -449,5 +451,34 @@ class EntryController extends Controller
449 private function checkIfEntryAlreadyExists(Entry $entry) 451 private function checkIfEntryAlreadyExists(Entry $entry)
450 { 452 {
451 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); 453 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
454
455 }
456
457 /*
458 * Share entry content.
459 *
460 * @param Entry $entry
461 *
462 * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share")
463 *
464 * @return \Symfony\Component\HttpFoundation\Response
465 */
466 public function shareEntry(Entry $entry)
467 {
468 return $this->render(
469 '@WallabagCore/themes/share.html.twig',
470 array('entry' => $entry)
471 );
472 }
473
474 /**
475 * @param Entry $entry
476 */
477 private function generateEntryUuid(Entry $entry)
478 {
479 $entry->generateUuid();
480 $em = $this->getDoctrine()->getManager();
481 $em->persist($entry);
482 $em->flush();
452 } 483 }
453} 484}
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
@@ -38,6 +38,15 @@ class Entry
38 private $id; 38 private $id;
39 39
40 /** 40 /**
41 * @var int
42 *
43 * @ORM\Column(name="uuid", type="text", nullable=true)
44 *
45 * @Groups({"entries_for_user", "export_all"})
46 */
47 private $uuid;
48
49 /**
41 * @var string 50 * @var string
42 * 51 *
43 * @ORM\Column(name="title", type="text", nullable=true) 52 * @ORM\Column(name="title", type="text", nullable=true)
@@ -427,6 +436,8 @@ class Entry
427 } 436 }
428 437
429 $this->updatedAt = new \DateTime(); 438 $this->updatedAt = new \DateTime();
439
440 $this->generateUuid();
430 } 441 }
431 442
432 /** 443 /**
@@ -595,4 +606,31 @@ class Entry
595 { 606 {
596 return $this->language; 607 return $this->language;
597 } 608 }
609
610 /**
611 * @return int
612 */
613 public function getUuid()
614 {
615 return $this->uuid;
616 }
617
618 /**
619 * @param int $uuid
620 *
621 * @return Entry
622 */
623 public function setUuid($uuid)
624 {
625 $this->uuid = $uuid;
626
627 return $this;
628 }
629
630 public function generateUuid()
631 {
632 if (empty($this->uuid) || is_null($this->uuid)) {
633 $this->uuid = uniqid();
634 }
635 }
598} 636}
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
@@ -101,6 +101,13 @@
101 <ul> 101 <ul>
102 {% if craue_setting('share_twitter') %} 102 {% if craue_setting('share_twitter') %}
103 <li> 103 <li>
104 <a href="{{ path('share', {'uuid': entry.uuid }) }}" target="_blank" class="tool public" title="public">
105 <span>public</span>
106 </a>
107 </li>
108 {% endif %}
109 {% if craue_setting('share_twitter') %}
110 <li>
104 <a href="https://twitter.com/home?status={{entry.title|url_encode}}%20{{ entry.url|url_encode }}%20via%20@wallabagapp" target="_blank" class="tool twitter icon icon-twitter" title="twitter"> 111 <a href="https://twitter.com/home?status={{entry.title|url_encode}}%20{{ entry.url|url_encode }}%20via%20@wallabagapp" target="_blank" class="tool twitter icon icon-twitter" title="twitter">
105 <span>twitter</span> 112 <span>twitter</span>
106 </a> 113 </a>
@@ -149,7 +156,6 @@
149 </li> 156 </li>
150 {% endif %} 157 {% endif %}
151 158
152
153 <li class="bold"> 159 <li class="bold">
154 <a class="waves-effect collapsible-header"> 160 <a class="waves-effect collapsible-header">
155 <i class="material-icons small">file_download</i> 161 <i class="material-icons small">file_download</i>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/share.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/share.html.twig
new file mode 100644
index 00000000..37ca14f1
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/share.html.twig
@@ -0,0 +1,39 @@
1<html>
2 <head>
3 <title>{{ entry.title | raw }}</title>
4 <style>
5 body {
6 margin: 10px;
7 font-family: 'Roboto',Verdana,Geneva,sans-serif;
8 font-size: 16px;
9 color: #000;
10 }
11 header {
12 text-align: center;
13 }
14
15 header h1 {
16 font-size: 1.3em;
17 }
18
19 a,
20 a:hover,
21 a:visited {
22 color: #000;
23 }
24
25 article {
26 margin: 0 auto;
27 width: 600px;
28 }
29 </style>
30 </head>
31 <body>
32 <header>
33 <h1>{{ entry.title | raw }}</h1>
34 </header>
35 <article>
36 {{ entry.content | raw }}
37 </article>
38 </body>
39</html>