2015-01-22 16:18:56 +00:00
|
|
|
<?php
|
|
|
|
|
2015-01-23 15:28:37 +00:00
|
|
|
namespace Wallabag\CoreBundle\Controller;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
use Craue\ConfigBundle\Util\Config;
|
2017-12-22 14:44:00 +00:00
|
|
|
use Doctrine\ORM\NoResultException;
|
2022-08-28 00:01:46 +00:00
|
|
|
use Lexik\Bundle\FormFilterBundle\Filter\FilterBuilderUpdaterInterface;
|
2020-07-29 04:36:43 +00:00
|
|
|
use Pagerfanta\Doctrine\ORM\QueryAdapter as DoctrineORMAdapter;
|
2016-02-19 13:22:27 +00:00
|
|
|
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
2015-01-22 16:18:56 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2022-08-28 00:01:46 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2022-08-28 14:59:43 +00:00
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2015-01-23 11:45:24 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2022-08-28 14:59:43 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2022-08-28 00:01:46 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
2018-10-04 12:07:20 +00:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2015-12-27 20:28:48 +00:00
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
2022-08-28 00:01:46 +00:00
|
|
|
use Symfony\Component\Translation\TranslatorInterface;
|
2015-02-06 06:45:32 +00:00
|
|
|
use Wallabag\CoreBundle\Entity\Entry;
|
2021-04-27 21:11:03 +00:00
|
|
|
use Wallabag\CoreBundle\Entity\Tag;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Wallabag\CoreBundle\Event\EntryDeletedEvent;
|
|
|
|
use Wallabag\CoreBundle\Event\EntrySavedEvent;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Wallabag\CoreBundle\Form\Type\EditEntryType;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Wallabag\CoreBundle\Form\Type\EntryFilterType;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Wallabag\CoreBundle\Form\Type\NewEntryType;
|
2016-11-04 22:24:43 +00:00
|
|
|
use Wallabag\CoreBundle\Form\Type\SearchEntryType;
|
2022-04-24 15:48:59 +00:00
|
|
|
use Wallabag\CoreBundle\Helper\ContentProxy;
|
|
|
|
use Wallabag\CoreBundle\Helper\PreparePagerForEntries;
|
|
|
|
use Wallabag\CoreBundle\Helper\Redirect;
|
2022-04-24 15:58:57 +00:00
|
|
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
|
|
|
use Wallabag\CoreBundle\Repository\TagRepository;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
class EntryController extends Controller
|
|
|
|
{
|
2020-04-12 14:31:12 +00:00
|
|
|
/**
|
|
|
|
* @Route("/mass", name="mass_action")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2020-04-12 14:31:12 +00:00
|
|
|
*/
|
|
|
|
public function massAction(Request $request)
|
|
|
|
{
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$values = $request->request->all();
|
|
|
|
|
2021-04-27 21:11:03 +00:00
|
|
|
$tagsToAdd = [];
|
|
|
|
$tagsToRemove = [];
|
|
|
|
|
2020-04-12 14:31:12 +00:00
|
|
|
$action = 'toggle-read';
|
|
|
|
if (isset($values['toggle-star'])) {
|
|
|
|
$action = 'toggle-star';
|
|
|
|
} elseif (isset($values['delete'])) {
|
|
|
|
$action = 'delete';
|
2021-04-27 21:11:03 +00:00
|
|
|
} elseif (isset($values['tag'])) {
|
|
|
|
$action = 'tag';
|
|
|
|
|
|
|
|
if (isset($values['tags'])) {
|
|
|
|
$labels = array_filter(explode(',', $values['tags']),
|
|
|
|
function ($v) {
|
|
|
|
$v = trim($v);
|
|
|
|
|
|
|
|
return '' !== $v;
|
|
|
|
});
|
|
|
|
foreach ($labels as $label) {
|
|
|
|
$remove = false;
|
|
|
|
if (0 === strpos($label, '-')) {
|
|
|
|
$label = substr($label, 1);
|
|
|
|
$remove = true;
|
|
|
|
}
|
2022-04-24 15:58:57 +00:00
|
|
|
$tag = $this->get(TagRepository::class)->findOneByLabel($label);
|
2021-04-27 21:11:03 +00:00
|
|
|
if ($remove) {
|
|
|
|
if (null !== $tag) {
|
|
|
|
$tagsToRemove[] = $tag;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (null === $tag) {
|
|
|
|
$tag = new Tag();
|
|
|
|
$tag->setLabel($label);
|
|
|
|
}
|
|
|
|
$tagsToAdd[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 14:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($values['entry-checkbox'])) {
|
|
|
|
foreach ($values['entry-checkbox'] as $id) {
|
|
|
|
/** @var Entry * */
|
2022-04-24 15:58:57 +00:00
|
|
|
$entry = $this->get(EntryRepository::class)->findById((int) $id)[0];
|
2020-04-12 14:31:12 +00:00
|
|
|
|
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
|
|
|
if ('toggle-read' === $action) {
|
|
|
|
$entry->toggleArchive();
|
|
|
|
} elseif ('toggle-star' === $action) {
|
|
|
|
$entry->toggleStar();
|
2021-04-27 21:11:03 +00:00
|
|
|
} elseif ('tag' === $action) {
|
|
|
|
foreach ($tagsToAdd as $tag) {
|
|
|
|
$entry->addTag($tag);
|
|
|
|
}
|
|
|
|
foreach ($tagsToRemove as $tag) {
|
|
|
|
$entry->removeTag($tag);
|
|
|
|
}
|
2020-04-12 14:31:12 +00:00
|
|
|
} elseif ('delete' === $action) {
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
|
2020-04-12 14:31:12 +00:00
|
|
|
$em->remove($entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$em->flush();
|
|
|
|
}
|
|
|
|
|
2022-04-24 15:48:59 +00:00
|
|
|
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'));
|
2020-04-12 14:31:12 +00:00
|
|
|
|
|
|
|
return $this->redirect($redirectUrl);
|
|
|
|
}
|
|
|
|
|
2016-11-04 22:24:43 +00:00
|
|
|
/**
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param int $page
|
2016-11-04 22:24:43 +00:00
|
|
|
*
|
2016-12-14 10:54:30 +00:00
|
|
|
* @Route("/search/{page}", name="search", defaults={"page" = 1})
|
|
|
|
*
|
|
|
|
* Default parameter for page is hardcoded (in duplication of the defaults from the Route)
|
|
|
|
* because this controller is also called inside the layout template without any page as argument
|
2016-11-04 22:24:43 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2016-11-04 22:24:43 +00:00
|
|
|
*/
|
2016-12-14 10:54:30 +00:00
|
|
|
public function searchFormAction(Request $request, $page = 1, $currentRoute = null)
|
2016-11-04 22:24:43 +00:00
|
|
|
{
|
2016-12-14 10:54:30 +00:00
|
|
|
// fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template)
|
|
|
|
if (null === $currentRoute && $request->query->has('currentRoute')) {
|
|
|
|
$currentRoute = $request->query->get('currentRoute');
|
|
|
|
}
|
|
|
|
|
2016-11-04 22:24:43 +00:00
|
|
|
$form = $this->createForm(SearchEntryType::class);
|
|
|
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
2016-12-14 10:54:30 +00:00
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
2016-11-04 22:24:43 +00:00
|
|
|
return $this->showEntries('search', $request, $page);
|
|
|
|
}
|
|
|
|
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagCore/Entry/search_form.html.twig', [
|
2016-11-04 22:24:43 +00:00
|
|
|
'form' => $form->createView(),
|
2016-11-10 14:23:53 +00:00
|
|
|
'currentRoute' => $currentRoute,
|
2016-11-04 22:24:43 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:58:17 +00:00
|
|
|
/**
|
2015-08-12 06:22:30 +00:00
|
|
|
* @Route("/new-entry", name="new_entry")
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-01-23 13:58:17 +00:00
|
|
|
*/
|
2015-08-12 06:22:30 +00:00
|
|
|
public function addEntryFormAction(Request $request)
|
2015-01-23 13:58:17 +00:00
|
|
|
{
|
2015-02-08 22:05:51 +00:00
|
|
|
$entry = new Entry($this->getUser());
|
2015-01-23 13:58:17 +00:00
|
|
|
|
2015-12-22 12:00:37 +00:00
|
|
|
$form = $this->createForm(NewEntryType::class, $entry);
|
2015-01-23 13:58:17 +00:00
|
|
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
2016-12-14 10:54:30 +00:00
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
2016-04-09 11:44:54 +00:00
|
|
|
$existingEntry = $this->checkIfEntryAlreadyExists($entry);
|
2015-10-26 13:38:24 +00:00
|
|
|
|
2015-12-24 14:19:50 +00:00
|
|
|
if (false !== $existingEntry) {
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(SessionInterface::class)->getFlashBag()->add(
|
2015-10-26 13:38:24 +00:00
|
|
|
'notice',
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(TranslatorInterface::class)->trans('flashes.entry.notice.entry_already_saved', ['%date%' => $existingEntry->getCreatedAt()->format('d-m-Y')])
|
2015-10-26 13:38:24 +00:00
|
|
|
);
|
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()]));
|
2015-10-26 13:38:24 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 05:40:56 +00:00
|
|
|
$this->updateEntry($entry);
|
2016-05-30 12:32:41 +00:00
|
|
|
|
2016-09-17 05:40:56 +00:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
2015-01-23 13:58:17 +00:00
|
|
|
|
2016-11-01 13:49:02 +00:00
|
|
|
// entry saved, dispatch event about it!
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
|
2016-11-01 13:49:02 +00:00
|
|
|
|
2015-01-23 13:58:17 +00:00
|
|
|
return $this->redirect($this->generateUrl('homepage'));
|
|
|
|
}
|
|
|
|
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagCore/Entry/new_form.html.twig', [
|
2015-01-23 13:58:17 +00:00
|
|
|
'form' => $form->createView(),
|
2016-04-12 09:36:01 +00:00
|
|
|
]);
|
2015-01-23 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-07 16:08:51 +00:00
|
|
|
/**
|
|
|
|
* @Route("/bookmarklet", name="bookmarklet")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-10-07 16:08:51 +00:00
|
|
|
*/
|
2016-01-20 16:16:17 +00:00
|
|
|
public function addEntryViaBookmarkletAction(Request $request)
|
2015-10-07 16:08:51 +00:00
|
|
|
{
|
|
|
|
$entry = new Entry($this->getUser());
|
|
|
|
$entry->setUrl($request->get('url'));
|
2016-04-08 13:41:05 +00:00
|
|
|
|
2016-04-09 11:44:54 +00:00
|
|
|
if (false === $this->checkIfEntryAlreadyExists($entry)) {
|
2016-04-08 13:41:05 +00:00
|
|
|
$this->updateEntry($entry);
|
2016-09-17 05:40:56 +00:00
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
2016-11-01 13:49:02 +00:00
|
|
|
|
|
|
|
// entry saved, dispatch event about it!
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
|
2016-04-08 13:41:05 +00:00
|
|
|
}
|
2015-10-07 16:08:51 +00:00
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('homepage'));
|
|
|
|
}
|
|
|
|
|
2015-08-12 06:22:30 +00:00
|
|
|
/**
|
|
|
|
* @Route("/new", name="new")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-08-12 06:22:30 +00:00
|
|
|
*/
|
2016-03-27 18:35:56 +00:00
|
|
|
public function addEntryAction()
|
2015-08-12 06:22:30 +00:00
|
|
|
{
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagCore/Entry/new.html.twig');
|
2015-08-12 06:22:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 16:54:34 +00:00
|
|
|
/**
|
|
|
|
* Edit an entry content.
|
|
|
|
*
|
|
|
|
* @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-06-02 16:54:34 +00:00
|
|
|
*/
|
|
|
|
public function editEntryAction(Request $request, Entry $entry)
|
|
|
|
{
|
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2015-12-22 12:00:37 +00:00
|
|
|
$form = $this->createForm(EditEntryType::class, $entry);
|
2015-06-02 16:54:34 +00:00
|
|
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
2016-12-14 10:54:30 +00:00
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
2015-06-02 16:54:34 +00:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(SessionInterface::class)->getFlashBag()->add(
|
2015-06-02 16:54:34 +00:00
|
|
|
'notice',
|
2016-03-11 13:48:46 +00:00
|
|
|
'flashes.entry.notice.entry_updated'
|
2015-06-02 16:54:34 +00:00
|
|
|
);
|
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
|
2015-06-02 16:54:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagCore/Entry/edit.html.twig', [
|
2015-06-02 16:54:34 +00:00
|
|
|
'form' => $form->createView(),
|
2016-04-12 09:36:01 +00:00
|
|
|
]);
|
2015-06-02 16:54:34 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 13:59:47 +00:00
|
|
|
/**
|
|
|
|
* Shows all entries for current user.
|
|
|
|
*
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param int $page
|
2015-08-20 13:59:47 +00:00
|
|
|
*
|
|
|
|
* @Route("/all/list/{page}", name="all", defaults={"page" = "1"})
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-08-20 13:59:47 +00:00
|
|
|
*/
|
|
|
|
public function showAllAction(Request $request, $page)
|
|
|
|
{
|
2015-08-21 05:38:18 +00:00
|
|
|
return $this->showEntries('all', $request, $page);
|
2015-08-20 13:59:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 16:18:56 +00:00
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows unread entries for current user.
|
2015-01-23 11:45:24 +00:00
|
|
|
*
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param int $page
|
2015-08-07 20:20:30 +00:00
|
|
|
*
|
2015-07-27 21:20:32 +00:00
|
|
|
* @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"})
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-08-07 20:20:30 +00:00
|
|
|
public function showUnreadAction(Request $request, $page)
|
2015-01-22 16:18:56 +00:00
|
|
|
{
|
2016-01-09 13:34:49 +00:00
|
|
|
// load the quickstart if no entry in database
|
2022-04-24 15:58:57 +00:00
|
|
|
if (1 === (int) $page && 0 === $this->get(EntryRepository::class)->countAllEntriesByUser($this->getUser()->getId())) {
|
2016-01-09 13:34:49 +00:00
|
|
|
return $this->redirect($this->generateUrl('quickstart'));
|
|
|
|
}
|
|
|
|
|
2015-08-20 18:10:06 +00:00
|
|
|
return $this->showEntries('unread', $request, $page);
|
2015-01-22 16:18:56 +00:00
|
|
|
}
|
2015-01-22 20:11:22 +00:00
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows read entries for current user.
|
2015-01-23 11:45:24 +00:00
|
|
|
*
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param int $page
|
2015-08-07 20:20:30 +00:00
|
|
|
*
|
2015-07-27 21:20:32 +00:00
|
|
|
* @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"})
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-01-22 20:11:22 +00:00
|
|
|
*/
|
2015-08-07 20:20:30 +00:00
|
|
|
public function showArchiveAction(Request $request, $page)
|
2015-01-22 20:11:22 +00:00
|
|
|
{
|
2015-08-20 18:10:06 +00:00
|
|
|
return $this->showEntries('archive', $request, $page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows starred entries for current user.
|
|
|
|
*
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param int $page
|
2015-08-20 18:10:06 +00:00
|
|
|
*
|
|
|
|
* @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"})
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-08-20 18:10:06 +00:00
|
|
|
*/
|
|
|
|
public function showStarredAction(Request $request, $page)
|
|
|
|
{
|
|
|
|
return $this->showEntries('starred', $request, $page);
|
|
|
|
}
|
2015-08-07 20:20:30 +00:00
|
|
|
|
2018-10-12 13:01:19 +00:00
|
|
|
/**
|
|
|
|
* Shows untagged articles for current user.
|
|
|
|
*
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param int $page
|
2018-10-12 13:01:19 +00:00
|
|
|
*
|
|
|
|
* @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2018-10-12 13:01:19 +00:00
|
|
|
*/
|
|
|
|
public function showUntaggedEntriesAction(Request $request, $page)
|
|
|
|
{
|
|
|
|
return $this->showEntries('untagged', $request, $page);
|
|
|
|
}
|
|
|
|
|
2020-04-20 17:00:58 +00:00
|
|
|
/**
|
|
|
|
* Shows entries with annotations for current user.
|
|
|
|
*
|
|
|
|
* @param int $page
|
|
|
|
*
|
2020-04-26 12:09:16 +00:00
|
|
|
* @Route("/annotated/list/{page}", name="annotated", defaults={"page" = "1"})
|
2020-04-20 17:00:58 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2020-04-20 17:00:58 +00:00
|
|
|
*/
|
|
|
|
public function showWithAnnotationsEntriesAction(Request $request, $page)
|
|
|
|
{
|
2020-04-26 12:09:16 +00:00
|
|
|
return $this->showEntries('annotated', $request, $page);
|
2020-04-20 17:00:58 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 14:44:00 +00:00
|
|
|
/**
|
2018-10-12 19:41:05 +00:00
|
|
|
* Shows random entry depending on the given type.
|
2017-12-22 14:44:00 +00:00
|
|
|
*
|
2018-10-12 20:13:33 +00:00
|
|
|
* @param string $type
|
2017-12-22 14:44:00 +00:00
|
|
|
*
|
2020-04-26 12:09:16 +00:00
|
|
|
* @Route("/{type}/random", name="random_entry", requirements={"type": "unread|starred|archive|untagged|annotated|all"})
|
2017-12-22 14:44:00 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return RedirectResponse
|
2017-12-22 14:44:00 +00:00
|
|
|
*/
|
2018-10-12 19:41:05 +00:00
|
|
|
public function redirectRandomEntryAction($type = 'all')
|
2017-12-22 14:44:00 +00:00
|
|
|
{
|
2018-10-12 19:41:05 +00:00
|
|
|
try {
|
2022-04-24 15:58:57 +00:00
|
|
|
$entry = $this->get(EntryRepository::class)
|
2018-10-12 19:41:05 +00:00
|
|
|
->getRandomEntry($this->getUser()->getId(), $type);
|
|
|
|
} catch (NoResultException $e) {
|
2022-08-28 00:01:46 +00:00
|
|
|
$bag = $this->get(SessionInterface::class)->getFlashBag();
|
2018-10-12 19:41:05 +00:00
|
|
|
$bag->clear();
|
|
|
|
$bag->add('notice', 'flashes.entry.notice.no_random_entry');
|
2017-12-22 14:44:00 +00:00
|
|
|
|
2018-10-12 20:13:33 +00:00
|
|
|
return $this->redirect($this->generateUrl($type));
|
2018-10-12 19:41:05 +00:00
|
|
|
}
|
2017-12-22 14:44:00 +00:00
|
|
|
|
2018-10-12 19:41:05 +00:00
|
|
|
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
|
2017-12-22 14:44:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 20:11:22 +00:00
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows entry content.
|
2015-01-23 11:45:24 +00:00
|
|
|
*
|
2015-01-22 20:11:22 +00:00
|
|
|
* @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2015-01-22 20:11:22 +00:00
|
|
|
*/
|
2015-02-06 06:45:32 +00:00
|
|
|
public function viewAction(Entry $entry)
|
2015-01-22 20:11:22 +00:00
|
|
|
{
|
2015-02-10 21:33:18 +00:00
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2015-01-22 20:11:22 +00:00
|
|
|
return $this->render(
|
2022-04-28 22:47:22 +00:00
|
|
|
'@WallabagCore/Entry/entry.html.twig',
|
2016-04-12 09:36:01 +00:00
|
|
|
['entry' => $entry]
|
2015-01-22 20:11:22 +00:00
|
|
|
);
|
2015-01-23 11:45:24 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 08:41:17 +00:00
|
|
|
/**
|
|
|
|
* Reload an entry.
|
|
|
|
* Refetch content from the website and make it readable again.
|
|
|
|
*
|
|
|
|
* @Route("/reload/{id}", requirements={"id" = "\d+"}, name="reload_entry")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return RedirectResponse
|
2015-12-30 08:41:17 +00:00
|
|
|
*/
|
|
|
|
public function reloadAction(Entry $entry)
|
|
|
|
{
|
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2016-09-17 05:40:56 +00:00
|
|
|
$this->updateEntry($entry, 'entry_reloaded');
|
2015-12-30 08:41:17 +00:00
|
|
|
|
2016-10-20 20:49:46 +00:00
|
|
|
// if refreshing entry failed, don't save it
|
|
|
|
if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
|
2022-08-28 00:01:46 +00:00
|
|
|
$bag = $this->get(SessionInterface::class)->getFlashBag();
|
2016-10-20 20:49:46 +00:00
|
|
|
$bag->clear();
|
|
|
|
$bag->add('notice', 'flashes.entry.notice.entry_reloaded_failed');
|
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
|
|
|
|
}
|
|
|
|
|
2016-09-17 05:40:56 +00:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
2015-12-30 08:41:17 +00:00
|
|
|
|
2016-11-01 13:49:02 +00:00
|
|
|
// entry saved, dispatch event about it!
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
|
2016-11-01 13:49:02 +00:00
|
|
|
|
2016-04-12 09:36:01 +00:00
|
|
|
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
|
2015-12-30 08:41:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 11:45:24 +00:00
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Changes read status for an entry.
|
2015-01-23 11:45:24 +00:00
|
|
|
*
|
|
|
|
* @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return RedirectResponse
|
2015-01-23 11:45:24 +00:00
|
|
|
*/
|
2015-02-06 06:45:32 +00:00
|
|
|
public function toggleArchiveAction(Request $request, Entry $entry)
|
2015-01-23 11:45:24 +00:00
|
|
|
{
|
2015-02-10 21:33:18 +00:00
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2015-01-23 11:45:24 +00:00
|
|
|
$entry->toggleArchive();
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
2016-03-11 13:48:46 +00:00
|
|
|
$message = 'flashes.entry.notice.entry_unarchived';
|
|
|
|
if ($entry->isArchived()) {
|
|
|
|
$message = 'flashes.entry.notice.entry_archived';
|
|
|
|
}
|
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(SessionInterface::class)->getFlashBag()->add(
|
2015-01-23 11:45:24 +00:00
|
|
|
'notice',
|
2016-03-11 13:48:46 +00:00
|
|
|
$message
|
2015-01-23 11:45:24 +00:00
|
|
|
);
|
|
|
|
|
2022-04-24 15:48:59 +00:00
|
|
|
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'));
|
2016-04-15 05:58:01 +00:00
|
|
|
|
|
|
|
return $this->redirect($redirectUrl);
|
2015-01-23 11:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-18 13:30:28 +00:00
|
|
|
* Changes starred status for an entry.
|
2015-01-23 11:45:24 +00:00
|
|
|
*
|
|
|
|
* @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return RedirectResponse
|
2015-01-23 11:45:24 +00:00
|
|
|
*/
|
2015-02-06 06:45:32 +00:00
|
|
|
public function toggleStarAction(Request $request, Entry $entry)
|
2015-01-23 11:45:24 +00:00
|
|
|
{
|
2015-02-10 21:33:18 +00:00
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2015-01-23 11:45:24 +00:00
|
|
|
$entry->toggleStar();
|
2017-08-23 21:06:40 +00:00
|
|
|
$entry->updateStar($entry->isStarred());
|
2015-01-23 11:45:24 +00:00
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
2016-03-11 13:48:46 +00:00
|
|
|
$message = 'flashes.entry.notice.entry_unstarred';
|
|
|
|
if ($entry->isStarred()) {
|
|
|
|
$message = 'flashes.entry.notice.entry_starred';
|
|
|
|
}
|
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(SessionInterface::class)->getFlashBag()->add(
|
2015-01-23 11:45:24 +00:00
|
|
|
'notice',
|
2016-03-11 13:48:46 +00:00
|
|
|
$message
|
2015-01-23 11:45:24 +00:00
|
|
|
);
|
|
|
|
|
2022-04-24 15:48:59 +00:00
|
|
|
$redirectUrl = $this->get(Redirect::class)->to($request->headers->get('referer'));
|
2016-04-15 05:58:01 +00:00
|
|
|
|
|
|
|
return $this->redirect($redirectUrl);
|
2015-01-23 11:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-27 20:28:48 +00:00
|
|
|
* Deletes entry and redirect to the homepage or the last viewed page.
|
2015-01-23 11:45:24 +00:00
|
|
|
*
|
|
|
|
* @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
|
2015-02-10 21:33:18 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return RedirectResponse
|
2015-01-23 11:45:24 +00:00
|
|
|
*/
|
2015-10-21 13:26:37 +00:00
|
|
|
public function deleteEntryAction(Request $request, Entry $entry)
|
2015-01-23 11:45:24 +00:00
|
|
|
{
|
2015-02-10 21:33:18 +00:00
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2015-12-27 20:28:48 +00:00
|
|
|
// generates the view url for this entry to check for redirection later
|
|
|
|
// to avoid redirecting to the deleted entry. Ugh.
|
|
|
|
$url = $this->generateUrl(
|
|
|
|
'view',
|
2016-04-12 09:36:01 +00:00
|
|
|
['id' => $entry->getId()],
|
2016-06-17 20:18:48 +00:00
|
|
|
UrlGeneratorInterface::ABSOLUTE_PATH
|
2015-12-27 20:28:48 +00:00
|
|
|
);
|
|
|
|
|
2016-11-01 13:49:02 +00:00
|
|
|
// entry deleted, dispatch event about it!
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
|
2016-11-01 13:49:02 +00:00
|
|
|
|
2015-02-20 14:36:25 +00:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->remove($entry);
|
|
|
|
$em->flush();
|
2015-01-23 11:45:24 +00:00
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(SessionInterface::class)->getFlashBag()->add(
|
2015-01-23 11:45:24 +00:00
|
|
|
'notice',
|
2016-03-11 13:48:46 +00:00
|
|
|
'flashes.entry.notice.entry_deleted'
|
2015-01-23 11:45:24 +00:00
|
|
|
);
|
2015-01-22 20:11:22 +00:00
|
|
|
|
2016-06-17 20:18:48 +00:00
|
|
|
// don't redirect user to the deleted entry (check that the referer doesn't end with the same url)
|
|
|
|
$referer = $request->headers->get('referer');
|
2017-07-01 07:52:38 +00:00
|
|
|
$to = (1 !== preg_match('#' . $url . '$#i', $referer) ? $referer : null);
|
2016-04-15 05:58:01 +00:00
|
|
|
|
2022-04-24 15:48:59 +00:00
|
|
|
$redirectUrl = $this->get(Redirect::class)->to($to);
|
2016-04-15 05:58:01 +00:00
|
|
|
|
|
|
|
return $this->redirect($redirectUrl);
|
2015-01-22 20:11:22 +00:00
|
|
|
}
|
2015-02-10 21:33:18 +00:00
|
|
|
|
2016-08-23 14:49:12 +00:00
|
|
|
/**
|
|
|
|
* Get public URL for entry (and generate it if necessary).
|
|
|
|
*
|
|
|
|
* @Route("/share/{id}", requirements={"id" = "\d+"}, name="share")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2016-08-23 14:49:12 +00:00
|
|
|
*/
|
|
|
|
public function shareAction(Entry $entry)
|
|
|
|
{
|
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2016-12-29 09:09:44 +00:00
|
|
|
if (null === $entry->getUid()) {
|
|
|
|
$entry->generateUid();
|
2016-08-24 20:29:36 +00:00
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
2016-08-23 14:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('share_entry', [
|
2016-12-29 09:09:44 +00:00
|
|
|
'uid' => $entry->getUid(),
|
2016-08-23 14:49:12 +00:00
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable public sharing for an entry.
|
|
|
|
*
|
|
|
|
* @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2016-08-23 14:49:12 +00:00
|
|
|
*/
|
|
|
|
public function deleteShareAction(Entry $entry)
|
|
|
|
{
|
|
|
|
$this->checkUserAction($entry);
|
|
|
|
|
2016-12-29 09:09:44 +00:00
|
|
|
$entry->cleanUid();
|
2016-08-24 20:29:36 +00:00
|
|
|
|
2016-08-23 14:49:12 +00:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entry);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('view', [
|
|
|
|
'id' => $entry->getId(),
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
2016-04-10 19:48:11 +00:00
|
|
|
/**
|
2016-08-24 20:29:36 +00:00
|
|
|
* Ability to view a content publicly.
|
2016-04-10 15:33:15 +00:00
|
|
|
*
|
2016-12-29 09:09:44 +00:00
|
|
|
* @Route("/share/{uid}", requirements={"uid" = ".+"}, name="share_entry")
|
2016-08-24 20:29:36 +00:00
|
|
|
* @Cache(maxage="25200", smaxage="25200", public=true)
|
2016-04-10 15:33:15 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2016-04-10 15:33:15 +00:00
|
|
|
*/
|
2016-04-10 19:48:11 +00:00
|
|
|
public function shareEntryAction(Entry $entry)
|
2016-04-10 15:33:15 +00:00
|
|
|
{
|
2022-08-28 00:01:46 +00:00
|
|
|
if (!$this->get(Config::class)->get('share_public')) {
|
2016-08-24 20:29:36 +00:00
|
|
|
throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
|
|
|
|
}
|
|
|
|
|
2016-04-10 15:33:15 +00:00
|
|
|
return $this->render(
|
2016-09-30 07:38:08 +00:00
|
|
|
'@WallabagCore/themes/common/Entry/share.html.twig',
|
2016-08-24 20:29:36 +00:00
|
|
|
['entry' => $entry]
|
2016-04-10 15:33:15 +00:00
|
|
|
);
|
|
|
|
}
|
2016-08-26 14:55:41 +00:00
|
|
|
|
2021-01-04 08:28:56 +00:00
|
|
|
/**
|
|
|
|
* List the entries with the same domain as the current one.
|
|
|
|
*
|
|
|
|
* @param int $page
|
|
|
|
*
|
|
|
|
* @Route("/domain/{id}/{page}", requirements={"id" = ".+"}, defaults={"page" = 1}, name="same_domain")
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2021-01-04 08:28:56 +00:00
|
|
|
*/
|
|
|
|
public function getSameDomainEntries(Request $request, $page = 1)
|
|
|
|
{
|
|
|
|
return $this->showEntries('same-domain', $request, $page);
|
|
|
|
}
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
/**
|
|
|
|
* Global method to retrieve entries depending on the given type
|
|
|
|
* It returns the response to be send.
|
|
|
|
*
|
2019-11-12 13:18:58 +00:00
|
|
|
* @param string $type Entries type: unread, starred or archive
|
|
|
|
* @param int $page
|
2017-07-01 07:52:38 +00:00
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return Response
|
2017-07-01 07:52:38 +00:00
|
|
|
*/
|
|
|
|
private function showEntries($type, Request $request, $page)
|
|
|
|
{
|
2022-04-24 15:58:57 +00:00
|
|
|
$repository = $this->get(EntryRepository::class);
|
2017-07-01 07:52:38 +00:00
|
|
|
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
|
|
|
|
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
|
|
|
|
|
2021-01-23 20:34:45 +00:00
|
|
|
$formOptions = [];
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
switch ($type) {
|
|
|
|
case 'search':
|
|
|
|
$qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
|
|
|
|
break;
|
|
|
|
case 'untagged':
|
|
|
|
$qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
|
|
|
|
break;
|
|
|
|
case 'starred':
|
|
|
|
$qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
|
2021-01-23 20:34:45 +00:00
|
|
|
$formOptions['filter_starred'] = true;
|
2017-07-01 07:52:38 +00:00
|
|
|
break;
|
|
|
|
case 'archive':
|
|
|
|
$qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
|
2021-01-23 20:34:45 +00:00
|
|
|
$formOptions['filter_archived'] = true;
|
2017-07-01 07:52:38 +00:00
|
|
|
break;
|
2020-04-26 12:09:16 +00:00
|
|
|
case 'annotated':
|
2020-04-20 17:00:58 +00:00
|
|
|
$qb = $repository->getBuilderForAnnotationsByUser($this->getUser()->getId());
|
|
|
|
break;
|
2017-07-01 07:52:38 +00:00
|
|
|
case 'unread':
|
|
|
|
$qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
|
2021-01-23 20:34:45 +00:00
|
|
|
$formOptions['filter_unread'] = true;
|
2017-07-01 07:52:38 +00:00
|
|
|
break;
|
2021-01-04 08:28:56 +00:00
|
|
|
case 'same-domain':
|
|
|
|
$qb = $repository->getBuilderForSameDomainByUser($this->getUser()->getId(), $request->get('id'));
|
|
|
|
break;
|
2017-07-01 07:52:38 +00:00
|
|
|
case 'all':
|
|
|
|
$qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
|
|
|
|
}
|
|
|
|
|
2021-01-23 20:34:45 +00:00
|
|
|
$form = $this->createForm(EntryFilterType::class, [], $formOptions);
|
2017-07-01 07:52:38 +00:00
|
|
|
|
|
|
|
if ($request->query->has($form->getName())) {
|
|
|
|
// manually bind values from the request
|
|
|
|
$form->submit($request->query->get($form->getName()));
|
|
|
|
|
|
|
|
// build the query from the given form object
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(FilterBuilderUpdaterInterface::class)->addFilterConditions($form, $qb);
|
2017-07-01 07:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
|
|
|
|
|
2022-04-24 15:48:59 +00:00
|
|
|
$entries = $this->get(PreparePagerForEntries::class)->prepare($pagerAdapter);
|
2017-07-01 07:52:38 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$entries->setCurrentPage($page);
|
|
|
|
} catch (OutOfRangeCurrentPageException $e) {
|
|
|
|
if ($page > 1) {
|
|
|
|
return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-24 15:58:57 +00:00
|
|
|
$nbEntriesUntagged = $this->get(EntryRepository::class)
|
2019-10-09 15:13:12 +00:00
|
|
|
->countUntaggedEntriesByUser($this->getUser()->getId());
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
return $this->render(
|
2022-04-28 22:47:22 +00:00
|
|
|
'@WallabagCore/Entry/entries.html.twig', [
|
2017-07-01 07:52:38 +00:00
|
|
|
'form' => $form->createView(),
|
|
|
|
'entries' => $entries,
|
|
|
|
'currentPage' => $page,
|
|
|
|
'searchTerm' => $searchTerm,
|
2017-07-27 20:35:59 +00:00
|
|
|
'isFiltered' => $form->isSubmitted(),
|
2019-10-09 15:13:12 +00:00
|
|
|
'nbEntriesUntagged' => $nbEntriesUntagged,
|
2017-07-01 07:52:38 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-12 13:01:19 +00:00
|
|
|
/**
|
|
|
|
* Fetch content and update entry.
|
|
|
|
* In case it fails, $entry->getContent will return an error message.
|
|
|
|
*
|
|
|
|
* @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
|
|
|
|
*/
|
|
|
|
private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
|
|
|
|
{
|
|
|
|
$message = 'flashes.entry.notice.' . $prefixMessage;
|
|
|
|
|
|
|
|
try {
|
2022-04-24 15:48:59 +00:00
|
|
|
$this->get(ContentProxy::class)->updateEntry($entry, $entry->getUrl());
|
2018-10-12 13:01:19 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->get('logger')->error('Error while saving an entry', [
|
|
|
|
'exception' => $e,
|
|
|
|
'entry' => $entry,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($entry->getDomainName())) {
|
2022-04-24 15:48:59 +00:00
|
|
|
$this->get(ContentProxy::class)->setEntryDomainName($entry);
|
2018-10-12 13:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($entry->getTitle())) {
|
2022-04-24 15:48:59 +00:00
|
|
|
$this->get(ContentProxy::class)->setDefaultEntryTitle($entry);
|
2018-10-12 13:01:19 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
$this->get(SessionInterface::class)->getFlashBag()->add('notice', $message);
|
2018-10-12 13:01:19 +00:00
|
|
|
}
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
/**
|
|
|
|
* Check if the logged user can manage the given entry.
|
|
|
|
*/
|
|
|
|
private function checkUserAction(Entry $entry)
|
|
|
|
{
|
|
|
|
if (null === $this->getUser() || $this->getUser()->getId() !== $entry->getUser()->getId()) {
|
|
|
|
throw $this->createAccessDeniedException('You can not access this entry.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for existing entry, if it exists, redirect to it with a message.
|
|
|
|
*
|
|
|
|
* @return Entry|bool
|
|
|
|
*/
|
|
|
|
private function checkIfEntryAlreadyExists(Entry $entry)
|
|
|
|
{
|
2022-04-24 15:58:57 +00:00
|
|
|
return $this->get(EntryRepository::class)->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
|
2017-07-01 07:52:38 +00:00
|
|
|
}
|
2015-01-22 16:18:56 +00:00
|
|
|
}
|