mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
108 lines
3.5 KiB
PHP
108 lines
3.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2015 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\ControllerProvider\Root;
|
|
|
|
use Alchemy\Phrasea\Feed\Aggregate;
|
|
use Silex\Application;
|
|
use Silex\ControllerProviderInterface;
|
|
|
|
class RSSFeeds implements ControllerProviderInterface
|
|
{
|
|
public function connect(Application $app)
|
|
{
|
|
$app['controller.rss-feeds'] = $this;
|
|
|
|
$controllers = $app['controllers_factory'];
|
|
|
|
$controllers->get('/feed/{id}/{format}/', function (Application $app, $id, $format) {
|
|
$feed = $app['repo.feeds']->find($id);
|
|
|
|
if (null === $feed) {
|
|
$app->abort(404, 'Feed not found');
|
|
}
|
|
|
|
if (!$feed->isPublic()) {
|
|
$app->abort(403, 'Forbidden');
|
|
}
|
|
|
|
$request = $app['request'];
|
|
|
|
$page = (int) $request->query->get('page');
|
|
$page = $page < 1 ? 1 : $page;
|
|
|
|
return $app['feed.formatter-strategy']($format)->createResponse($app, $feed, $page);
|
|
})
|
|
->bind('feed_public')
|
|
->assert('id', '\d+')
|
|
->assert('format', '(rss|atom)');
|
|
|
|
$controllers->get('/userfeed/{token}/{id}/{format}/', function (Application $app, $token, $id, $format) {
|
|
$token = $app["repo.feed-tokens"]->find($id);
|
|
|
|
$request = $app['request'];
|
|
|
|
$page = (int) $request->query->get('page');
|
|
$page = $page < 1 ? 1 : $page;
|
|
|
|
return $app['feed.formatter-strategy']($format)
|
|
->createResponse($app, $token->getFeed(), $page, $token->getUser());
|
|
})
|
|
->bind('feed_user')
|
|
->assert('id', '\d+')
|
|
->assert('format', '(rss|atom)');
|
|
|
|
$controllers->get('/userfeed/aggregated/{token}/{format}/', function (Application $app, $token, $format) {
|
|
$token = $app['repo.aggregate-tokens']->findOneBy(["value" => $token]);
|
|
|
|
$user = $token->getUser();
|
|
|
|
$feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($user));
|
|
|
|
$aggregate = new Aggregate($app['orm.em'], $feeds, $token);
|
|
|
|
$request = $app['request'];
|
|
|
|
$page = (int) $request->query->get('page');
|
|
$page = $page < 1 ? 1 : $page;
|
|
|
|
return $app['feed.formatter-strategy']($format)->createResponse($app, $aggregate, $page, $user);
|
|
})
|
|
->bind('feed_user_aggregated')
|
|
->assert('format', '(rss|atom)');
|
|
|
|
$controllers->get('/aggregated/{format}/', function (Application $app, $format) {
|
|
$feed = Aggregate::getPublic($app);
|
|
|
|
$request = $app['request'];
|
|
$page = (int) $request->query->get('page');
|
|
$page = $page < 1 ? 1 : $page;
|
|
|
|
return $app['feed.formatter-strategy']($format)->createResponse($app, $feed, $page);
|
|
})
|
|
->bind('feed_public_aggregated')
|
|
->assert('format', '(rss|atom)');
|
|
|
|
$controllers->get('/cooliris/', function (Application $app) {
|
|
$feed = Aggregate::getPublic($app);
|
|
|
|
$request = $app['request'];
|
|
$page = (int) $request->query->get('page');
|
|
$page = $page < 1 ? 1 : $page;
|
|
|
|
return $app['feed.formatter-strategy']('cooliris')->createResponse($app, $feed, $page, null, 'Phraseanet', $app);
|
|
})
|
|
->bind('feed_public_cooliris');
|
|
|
|
return $controllers;
|
|
}
|
|
}
|