Share entry with a public URL

This commit is contained in:
Nicolas Lœuillet 2016-04-10 17:33:15 +02:00
parent 1bee9e0760
commit f3d0cb9106
5 changed files with 116 additions and 1 deletions

View 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 }

View 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();
}
}

View 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();
}
}
}

View file

@ -99,6 +99,13 @@
</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">
@ -149,7 +156,6 @@
</li>
{% endif %}
<li class="bold">
<a class="waves-effect collapsible-header">
<i class="material-icons small">file_download</i>

View file

@ -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>