mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
Move source files directly under src/ directory
This commit is contained in:
parent
804261bc26
commit
a37b385c23
190 changed files with 19 additions and 21 deletions
122
src/Controller/ExportController.php
Normal file
122
src/Controller/ExportController.php
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Wallabag\CoreBundle\Helper\EntriesExport;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\CoreBundle\Repository\TagRepository;
|
||||
|
||||
/**
|
||||
* The try/catch can be removed once all formats will be implemented.
|
||||
* Still need implementation: txt.
|
||||
*/
|
||||
class ExportController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Gets one entry content.
|
||||
*
|
||||
* @Route("/export/{id}.{format}", name="export_entry", requirements={
|
||||
* "format": "epub|pdf|json|xml|txt|csv",
|
||||
* "id": "\d+"
|
||||
* })
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function downloadEntryAction(Request $request, EntryRepository $entryRepository, EntriesExport $entriesExport, string $format, int $id)
|
||||
{
|
||||
try {
|
||||
$entry = $entryRepository->find($id);
|
||||
|
||||
/*
|
||||
* We duplicate EntryController::checkUserAction here as a quick fix for an improper authorization vulnerability
|
||||
*
|
||||
* This should be eventually rewritten
|
||||
*/
|
||||
if (null === $entry || null === $this->getUser() || $this->getUser()->getId() !== $entry->getUser()->getId()) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
return $entriesExport
|
||||
->setEntries($entry)
|
||||
->updateTitle('entry')
|
||||
->updateAuthor('entry')
|
||||
->exportAs($format);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all entries for current user.
|
||||
*
|
||||
* @Route("/export/{category}.{format}", name="export_entries", requirements={
|
||||
* "format": "epub|pdf|json|xml|txt|csv",
|
||||
* "category": "all|unread|starred|archive|tag_entries|untagged|search|annotated|same_domain"
|
||||
* })
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function downloadEntriesAction(Request $request, EntryRepository $entryRepository, TagRepository $tagRepository, EntriesExport $entriesExport, string $format, string $category, int $entry = 0)
|
||||
{
|
||||
$method = ucfirst($category);
|
||||
$methodBuilder = 'getBuilderFor' . $method . 'ByUser';
|
||||
$title = $method;
|
||||
|
||||
if ('same_domain' === $category) {
|
||||
$entries = $entryRepository->getBuilderForSameDomainByUser(
|
||||
$this->getUser()->getId(),
|
||||
$request->get('entry')
|
||||
)->getQuery()
|
||||
->getResult();
|
||||
|
||||
$title = 'Same domain';
|
||||
} elseif ('tag_entries' === $category) {
|
||||
$tag = $tagRepository->findOneBySlug($request->query->get('tag'));
|
||||
|
||||
$entries = $entryRepository->findAllByTagId(
|
||||
$this->getUser()->getId(),
|
||||
$tag->getId()
|
||||
);
|
||||
|
||||
$title = 'Tag ' . $tag->getLabel();
|
||||
} elseif ('search' === $category) {
|
||||
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
|
||||
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
|
||||
|
||||
$entries = $entryRepository->getBuilderForSearchByUser(
|
||||
$this->getUser()->getId(),
|
||||
$searchTerm,
|
||||
$currentRoute
|
||||
)->getQuery()
|
||||
->getResult();
|
||||
|
||||
$title = 'Search ' . $searchTerm;
|
||||
} elseif ('annotated' === $category) {
|
||||
$entries = $entryRepository->getBuilderForAnnotationsByUser(
|
||||
$this->getUser()->getId()
|
||||
)->getQuery()
|
||||
->getResult();
|
||||
|
||||
$title = 'With annotations';
|
||||
} else {
|
||||
$entries = $entryRepository
|
||||
->$methodBuilder($this->getUser()->getId())
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
try {
|
||||
return $entriesExport
|
||||
->setEntries($entries)
|
||||
->updateTitle($title)
|
||||
->updateAuthor($method)
|
||||
->exportAs($format);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue