2015-03-28 13:27:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Controller;
|
|
|
|
|
2015-12-22 09:16:34 +00:00
|
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
2016-11-19 13:53:28 +00:00
|
|
|
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Pagerfanta\Pagerfanta;
|
2015-03-28 13:27:45 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
2016-11-19 13:53:28 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2015-03-28 13:27:45 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Wallabag\CoreBundle\Entity\Entry;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Wallabag\UserBundle\Entity\User;
|
2016-11-19 13:53:28 +00:00
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
2015-03-28 13:27:45 +00:00
|
|
|
|
|
|
|
class RssController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows unread entries for current user.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"})
|
2015-10-02 12:51:41 +00:00
|
|
|
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2016-11-19 13:53:28 +00:00
|
|
|
public function showUnreadAction(Request $request, User $user)
|
2015-03-28 13:27:45 +00:00
|
|
|
{
|
2016-11-19 13:53:28 +00:00
|
|
|
return $this->showEntries('unread', $user, $request->query->get('page', 1));
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows read entries for current user.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @Route("/{username}/{token}/archive.xml", name="archive_rss")
|
2015-10-02 12:51:41 +00:00
|
|
|
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2016-11-19 13:53:28 +00:00
|
|
|
public function showArchiveAction(Request $request, User $user)
|
2015-03-28 13:27:45 +00:00
|
|
|
{
|
2016-11-19 13:53:28 +00:00
|
|
|
return $this->showEntries('archive', $user, $request->query->get('page', 1));
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows starred entries for current user.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @Route("/{username}/{token}/starred.xml", name="starred_rss")
|
2015-10-02 12:51:41 +00:00
|
|
|
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2016-11-19 13:53:28 +00:00
|
|
|
public function showStarredAction(Request $request, User $user)
|
2015-03-28 13:27:45 +00:00
|
|
|
{
|
2016-11-19 13:53:28 +00:00
|
|
|
return $this->showEntries('starred', $user, $request->query->get('page', 1));
|
2015-08-20 18:10:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global method to retrieve entries depending on the given type
|
|
|
|
* It returns the response to be send.
|
|
|
|
*
|
|
|
|
* @param string $type Entries type: unread, starred or archive
|
|
|
|
* @param User $user
|
2016-11-19 13:53:28 +00:00
|
|
|
* @param int $page
|
2015-08-20 18:10:06 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2016-11-19 13:53:28 +00:00
|
|
|
private function showEntries($type, User $user, $page = 1)
|
2015-08-20 18:10:06 +00:00
|
|
|
{
|
2017-06-10 10:33:58 +00:00
|
|
|
$repository = $this->get('wallabag_core.entry_repository');
|
2015-08-20 18:10:06 +00:00
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'starred':
|
|
|
|
$qb = $repository->getBuilderForStarredByUser($user->getId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'archive':
|
|
|
|
$qb = $repository->getBuilderForArchiveByUser($user->getId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unread':
|
|
|
|
$qb = $repository->getBuilderForUnreadByUser($user->getId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
|
|
|
|
}
|
2015-03-28 13:27:45 +00:00
|
|
|
|
2016-12-14 08:00:14 +00:00
|
|
|
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
|
2015-08-07 20:20:30 +00:00
|
|
|
$entries = new Pagerfanta($pagerAdapter);
|
|
|
|
|
2016-01-21 11:24:27 +00:00
|
|
|
$perPage = $user->getConfig()->getRssLimit() ?: $this->getParameter('wallabag_core.rss_limit');
|
2015-07-27 21:20:32 +00:00
|
|
|
$entries->setMaxPerPage($perPage);
|
|
|
|
|
2016-11-19 13:53:28 +00:00
|
|
|
$url = $this->generateUrl(
|
|
|
|
$type.'_rss',
|
|
|
|
[
|
|
|
|
'username' => $user->getUsername(),
|
|
|
|
'token' => $user->getConfig()->getRssToken(),
|
|
|
|
],
|
|
|
|
UrlGeneratorInterface::ABSOLUTE_URL
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$entries->setCurrentPage((int) $page);
|
|
|
|
} catch (OutOfRangeCurrentPageException $e) {
|
|
|
|
if ($page > 1) {
|
|
|
|
return $this->redirect($url.'?page='.$entries->getNbPages(), 302);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 07:38:08 +00:00
|
|
|
return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [
|
2015-08-20 18:10:06 +00:00
|
|
|
'type' => $type,
|
2016-11-19 13:53:28 +00:00
|
|
|
'url' => $url,
|
2015-03-28 13:27:45 +00:00
|
|
|
'entries' => $entries,
|
2016-04-12 09:36:01 +00:00
|
|
|
]);
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|
|
|
|
}
|