]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Share entry with a public URL
authorNicolas Lœuillet <nicolas@loeuillet.org>
Sun, 10 Apr 2016 15:33:15 +0000 (17:33 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 23 Aug 2016 14:49:21 +0000 (16:49 +0200)
app/config/security.yml
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/share.html.twig [new file with mode: 0644]

index e24e03df2e921d98eff8325b86a1ae2733a8ea6d..1f30e58b845abceb50011a28ed32b0f7ab57daca 100644 (file)
@@ -60,6 +60,7 @@ security:
         - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: /(unread|starred|archive).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
+        - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/settings, roles: ROLE_SUPER_ADMIN }
         - { path: ^/annotations, roles: ROLE_USER }
         - { path: ^/, roles: ROLE_USER }
index 93db0d6caa117d1d0ba9442c8b4a3ea66ace11c8..a78dd00cf7676926ee1399a80703045d69589ebc 100644 (file)
@@ -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();
     }
 }
index ceae78b05556e4005f0c51e35e1eb93a5bf6c57a..3c742828522935830b11bc90c426946ef63acbdb 100644 (file)
@@ -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();
+        }
+    }
 }
index 5dd2afb3e32d58d52b953067086da402ea844557..b634dd40b7280de3e54da76e504f926f7909d348 100644 (file)
             </a>
             <div class="collapsible-body">
                 <ul>
+                    {% if craue_setting('share_twitter') %}
+                        <li>
+                            <a href="{{ path('share', {'uuid': entry.uuid }) }}" target="_blank" class="tool public" title="public">
+                                <span>public</span>
+                            </a>
+                        </li>
+                    {% endif %}
                     {% if craue_setting('share_twitter') %}
                         <li>
                             <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">
         </li>
         {% endif %}
 
-
         <li class="bold">
             <a class="waves-effect collapsible-header">
                 <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 (file)
index 0000000..37ca14f
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+    <head>
+        <title>{{ entry.title | raw }}</title>
+        <style>
+            body {
+                margin: 10px;
+                font-family: 'Roboto',Verdana,Geneva,sans-serif;
+                font-size: 16px;
+                color: #000;
+            }
+            header {
+                text-align: center;
+            }
+
+            header h1 {
+                font-size: 1.3em;
+            }
+
+            a,
+            a:hover,
+            a:visited {
+                color: #000;
+            }
+
+            article {
+                margin: 0 auto;
+                width: 600px;
+            }
+        </style>
+    </head>
+    <body>
+        <header>
+            <h1>{{ entry.title | raw }}</h1>
+        </header>
+        <article>
+            {{ entry.content | raw }}
+        </article>
+    </body>
+</html>