mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Merge pull request #1904 from wallabag/feature-public-mode
Share entry with a public URL
This commit is contained in:
commit
60e7220406
33 changed files with 346 additions and 9 deletions
|
@ -241,6 +241,11 @@ class InstallCommand extends ContainerAwareCommand
|
|||
$em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute();
|
||||
|
||||
$settings = [
|
||||
[
|
||||
'name' => 'share_public',
|
||||
'value' => '1',
|
||||
'section' => 'entry',
|
||||
],
|
||||
[
|
||||
'name' => 'carrot',
|
||||
'value' => '1',
|
||||
|
|
|
@ -12,6 +12,7 @@ use Wallabag\CoreBundle\Entity\Entry;
|
|||
use Wallabag\CoreBundle\Form\Type\EntryFilterType;
|
||||
use Wallabag\CoreBundle\Form\Type\EditEntryType;
|
||||
use Wallabag\CoreBundle\Form\Type\NewEntryType;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
|
||||
class EntryController extends Controller
|
||||
{
|
||||
|
@ -434,7 +435,7 @@ class EntryController extends Controller
|
|||
*/
|
||||
private function checkUserAction(Entry $entry)
|
||||
{
|
||||
if ($this->getUser()->getId() != $entry->getUser()->getId()) {
|
||||
if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) {
|
||||
throw $this->createAccessDeniedException('You can not access this entry.');
|
||||
}
|
||||
}
|
||||
|
@ -450,4 +451,76 @@ class EntryController extends Controller
|
|||
{
|
||||
return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get public URL for entry (and generate it if necessary).
|
||||
*
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @Route("/share/{id}", requirements={"id" = "\d+"}, name="share")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function shareAction(Entry $entry)
|
||||
{
|
||||
$this->checkUserAction($entry);
|
||||
|
||||
if (null === $entry->getUuid()) {
|
||||
$entry->generateUuid();
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entry);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
return $this->redirect($this->generateUrl('share_entry', [
|
||||
'uuid' => $entry->getUuid(),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable public sharing for an entry.
|
||||
*
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function deleteShareAction(Entry $entry)
|
||||
{
|
||||
$this->checkUserAction($entry);
|
||||
|
||||
$entry->cleanUuid();
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entry);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('view', [
|
||||
'id' => $entry->getId(),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ability to view a content publicly.
|
||||
*
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry")
|
||||
* @Cache(maxage="25200", smaxage="25200", public=true)
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function shareEntryAction(Entry $entry)
|
||||
{
|
||||
if (!$this->get('craue_config')->get('share_public')) {
|
||||
throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'@WallabagCore/themes/share.html.twig',
|
||||
['entry' => $entry]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@ class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface
|
|||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$settings = [
|
||||
[
|
||||
'name' => 'share_public',
|
||||
'value' => '1',
|
||||
'section' => 'entry',
|
||||
],
|
||||
[
|
||||
'name' => 'carrot',
|
||||
'value' => '1',
|
||||
|
|
|
@ -37,6 +37,15 @@ class Entry
|
|||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="uuid", type="text", nullable=true)
|
||||
*
|
||||
* @Groups({"entries_for_user", "export_all"})
|
||||
*/
|
||||
private $uuid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
|
@ -595,4 +604,37 @@ class Entry
|
|||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUuid()
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uuid
|
||||
*
|
||||
* @return Entry
|
||||
*/
|
||||
public function setUuid($uuid)
|
||||
{
|
||||
$this->uuid = $uuid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function generateUuid()
|
||||
{
|
||||
if (null === $this->uuid) {
|
||||
// @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
|
||||
$this->uuid = uniqid('', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function cleanUuid()
|
||||
{
|
||||
$this->uuid = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Tliføj et tag'
|
||||
share_content: 'Deling'
|
||||
# share_email_label: 'Email'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Download'
|
||||
# print: 'Print'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Tag hinzufügen'
|
||||
share_content: 'Teilen'
|
||||
share_email_label: 'E-Mail'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Herunterladen'
|
||||
print: 'Drucken'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Add a tag'
|
||||
share_content: 'Share'
|
||||
share_email_label: 'Email'
|
||||
public_link: 'public link'
|
||||
delete_public_link: 'delete public link'
|
||||
download: 'Download'
|
||||
print: 'Print'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Añadir una etiqueta'
|
||||
share_content: 'Compartir'
|
||||
share_email_label: 'Dirección e-mail'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Descargar'
|
||||
print: 'Imprimir'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'افزودن برچسب'
|
||||
share_content: 'همرسانی'
|
||||
share_email_label: 'نشانی ایمیل'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'بارگیری'
|
||||
print: 'چاپ'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Ajouter un tag'
|
||||
share_content: 'Partager'
|
||||
share_email_label: 'Email'
|
||||
public_link: 'Lien public'
|
||||
delete_public_link: 'Supprimer lien public'
|
||||
download: 'Télécharger'
|
||||
print: 'Imprimer'
|
||||
problem:
|
||||
|
|
|
@ -185,6 +185,8 @@ entry:
|
|||
add_a_tag: 'Aggiungi un tag'
|
||||
share_content: 'Condividi'
|
||||
share_email_label: 'E-mail'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Download'
|
||||
print: 'Stampa'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Ajustar una etiqueta'
|
||||
share_content: 'Partatjar'
|
||||
share_email_label: 'Corrièl'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Telecargar'
|
||||
print: 'Imprimir'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Dodaj tag'
|
||||
share_content: 'Udostępnij'
|
||||
share_email_label: 'Adres email'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Pobierz'
|
||||
print: 'Drukuj'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Adaugă un tag'
|
||||
share_content: 'Dă mai departe'
|
||||
share_email_label: 'E-mail'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'Descarcă'
|
||||
# print: 'Print'
|
||||
problem:
|
||||
|
|
|
@ -187,6 +187,8 @@ entry:
|
|||
add_a_tag: 'Bir etiket ekle'
|
||||
share_content: 'Paylaş'
|
||||
share_email_label: 'E-posta'
|
||||
# public_link: 'public link'
|
||||
# delete_public_link: 'delete public link'
|
||||
download: 'İndir'
|
||||
# print: 'Print'
|
||||
problem:
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
<li><a title="{{ 'entry.view.left_menu.set_as_starred'|trans }}" class="tool icon icon-star {% if entry.isStarred == 0 %}fav-off{% else %}fav{% endif %}" href="{{ path('star_entry', { 'id': entry.id }) }}"><span>{{ 'entry.view.left_menu.set_as_starred'|trans }}</span></a></li>
|
||||
<li><a id="nav-btn-add-tag" title="{{ 'entry.view.left_menu.add_a_tag'|trans }}"><span>{{ 'entry.view.left_menu.add_a_tag'|trans }}</span></a></li>
|
||||
<li><a title="{{ 'entry.view.left_menu.delete'|trans }}" class="tool delete icon icon-trash" href="{{ path('delete_entry', { 'id': entry.id }) }}"><span>{{ 'entry.view.left_menu.delete'|trans }}</span></a></li>
|
||||
{% if craue_setting('share_public') %}<li><a href="{{ path('share', {'id': entry.id }) }}" target="_blank" class="tool public" title="{{ 'entry.view.left_menu.public_link'|trans }}"><span>{{ 'entry.view.left_menu.public_link'|trans }}</span></a></li> <li><a href="{{ path('delete_share', {'id': entry.id }) }}" class="tool public" title="{{ 'entry.view.left_menu.delete_public_link'|trans }}"><span>{{ 'entry.view.left_menu.delete_public_link'|trans }}</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="Tweet"><span>Tweet</span></a></li>{% endif %}
|
||||
{% if craue_setting('share_mail') %}<li><a href="mailto:?subject={{ entry.title|url_encode }}&body={{ entry.url|url_encode }}%20via%20@wallabagapp" class="tool email icon icon-mail" title="Email"><span>Email</span></a></li>{% endif %}
|
||||
{% if craue_setting('share_shaarli') %}<li><a href="{{ craue_setting('shaarli_url') }}/index.php?post={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="shaarli"><span>shaarli</span></a></li>{% endif %}
|
||||
|
|
|
@ -99,6 +99,18 @@
|
|||
</a>
|
||||
<div class="collapsible-body">
|
||||
<ul>
|
||||
{% if craue_setting('share_public') %}
|
||||
<li>
|
||||
<a href="{{ path('share', {'id': entry.id }) }}" target="_blank" class="tool public" title="{{ 'entry.view.left_menu.public_link'|trans }}">
|
||||
<span>{{ 'entry.view.left_menu.public_link'|trans }}</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ path('delete_share', {'id': entry.id }) }}" class="tool public" title="{{ 'entry.view.left_menu.delete_public_link'|trans }}">
|
||||
<span>{{ 'entry.view.left_menu.delete_public_link'|trans }}</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 +161,6 @@
|
|||
</li>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<li class="bold">
|
||||
<a class="waves-effect collapsible-header">
|
||||
<i class="material-icons small">file_download</i>
|
||||
|
|
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue