mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-12 16:58:37 +00:00
Add RSS tags feeds
This commit is contained in:
parent
25203e5081
commit
18c38dffc6
5 changed files with 117 additions and 20 deletions
|
@ -3,13 +3,16 @@
|
|||
namespace Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||
use Pagerfanta\Adapter\ArrayAdapter;
|
||||
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Entity\Tag;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
|
@ -31,7 +34,7 @@ class RssController extends Controller
|
|||
/**
|
||||
* Shows read entries for current user.
|
||||
*
|
||||
* @Route("/{username}/{token}/archive.xml", name="archive_rss")
|
||||
* @Route("/{username}/{token}/archive.xml", name="archive_rss", defaults={"_format"="xml"})
|
||||
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
|
@ -44,7 +47,7 @@ class RssController extends Controller
|
|||
/**
|
||||
* Shows starred entries for current user.
|
||||
*
|
||||
* @Route("/{username}/{token}/starred.xml", name="starred_rss")
|
||||
* @Route("/{username}/{token}/starred.xml", name="starred_rss", defaults={"_format"="xml"})
|
||||
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
|
@ -54,6 +57,65 @@ class RssController extends Controller
|
|||
return $this->showEntries('starred', $user, $request->query->get('page', 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows entries associated to a tag for current user.
|
||||
*
|
||||
* @Route("/{username}/{token}/tags/{slug}.xml", name="tag_rss", defaults={"_format"="xml"})
|
||||
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
||||
* @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function showTagsAction(Request $request, User $user, Tag $tag)
|
||||
{
|
||||
$page = $request->query->get('page', 1);
|
||||
|
||||
$url = $this->generateUrl(
|
||||
'tag_rss',
|
||||
[
|
||||
'username' => $user->getUsername(),
|
||||
'token' => $user->getConfig()->getRssToken(),
|
||||
'slug' => $tag->getSlug(),
|
||||
],
|
||||
UrlGeneratorInterface::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
|
||||
$user->getId(),
|
||||
$tag->getId()
|
||||
);
|
||||
|
||||
$pagerAdapter = new ArrayAdapter($entriesByTag);
|
||||
|
||||
$entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare(
|
||||
$pagerAdapter,
|
||||
$user
|
||||
);
|
||||
|
||||
if (null === $entries) {
|
||||
throw $this->createNotFoundException('No entries found?');
|
||||
}
|
||||
|
||||
try {
|
||||
$entries->setCurrentPage($page);
|
||||
} catch (OutOfRangeCurrentPageException $e) {
|
||||
if ($page > 1) {
|
||||
return $this->redirect($url.'?page='.$entries->getNbPages(), 302);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'@WallabagCore/themes/common/Entry/entries.xml.twig',
|
||||
[
|
||||
'url_html' => $this->generateUrl('tag_entries', ['slug' => $tag->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
|
||||
'type' => 'tag ('.$tag->getLabel().')',
|
||||
'url' => $url,
|
||||
'entries' => $entries,
|
||||
],
|
||||
new Response('', 200, ['Content-Type' => 'application/rss+xml'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global method to retrieve entries depending on the given type
|
||||
* It returns the response to be send.
|
||||
|
@ -108,10 +170,15 @@ class RssController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [
|
||||
'type' => $type,
|
||||
'url' => $url,
|
||||
'entries' => $entries,
|
||||
]);
|
||||
return $this->render(
|
||||
'@WallabagCore/themes/common/Entry/entries.xml.twig',
|
||||
[
|
||||
'url_html' => $this->generateUrl($type, [], UrlGeneratorInterface::ABSOLUTE_URL),
|
||||
'type' => $type,
|
||||
'url' => $url,
|
||||
'entries' => $entries,
|
||||
],
|
||||
new Response('', 200, ['Content-Type' => 'application/rss+xml'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Helper;
|
|||
|
||||
use Pagerfanta\Adapter\AdapterInterface;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
|
@ -20,12 +21,15 @@ class PreparePagerForEntries
|
|||
|
||||
/**
|
||||
* @param AdapterInterface $adapter
|
||||
* @param User $user If user isn't logged in, we can force it (like for rss)
|
||||
*
|
||||
* @return null|Pagerfanta
|
||||
*/
|
||||
public function prepare(AdapterInterface $adapter)
|
||||
public function prepare(AdapterInterface $adapter, User $user = null)
|
||||
{
|
||||
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
|
||||
if (null === $user) {
|
||||
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
|
||||
}
|
||||
|
||||
if (null === $user || !is_object($user)) {
|
||||
return;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
|
||||
<channel>
|
||||
<title>wallabag — {{type}} feed</title>
|
||||
<link>{{ url(type) }}</link>
|
||||
<title>wallabag - {{ type }} feed</title>
|
||||
<link>{{ url_html }}</link>
|
||||
<link rel="self" href="{{ app.request.uri }}"/>
|
||||
{% if entries.hasPreviousPage -%}
|
||||
<link rel="previous" href="{{ url }}?page={{ entries.previousPage }}"/>
|
||||
|
@ -13,7 +13,7 @@
|
|||
<link rel="last" href="{{ url }}?page={{ entries.nbPages }}"/>
|
||||
<pubDate>{{ "now"|date('D, d M Y H:i:s') }}</pubDate>
|
||||
<generator>wallabag</generator>
|
||||
<description>wallabag {{type}} elements</description>
|
||||
<description>wallabag {{ type }} elements</description>
|
||||
|
||||
{% for entry in entries %}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue