2020-05-18 17:17:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-05-22 13:20:31 +02:00
|
|
|
namespace Shaarli\Front\Controller\Visitor;
|
2020-05-18 17:17:36 +02:00
|
|
|
|
|
|
|
use Shaarli\Feed\FeedBuilder;
|
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class FeedController
|
|
|
|
*
|
|
|
|
* Slim controller handling ATOM and RSS feed.
|
|
|
|
*/
|
2020-05-22 13:20:31 +02:00
|
|
|
class FeedController extends ShaarliVisitorController
|
2020-05-18 17:17:36 +02:00
|
|
|
{
|
|
|
|
public function atom(Request $request, Response $response): Response
|
|
|
|
{
|
|
|
|
return $this->processRequest(FeedBuilder::$FEED_ATOM, $request, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rss(Request $request, Response $response): Response
|
|
|
|
{
|
|
|
|
return $this->processRequest(FeedBuilder::$FEED_RSS, $request, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function processRequest(string $feedType, Request $request, Response $response): Response
|
|
|
|
{
|
|
|
|
$response = $response->withHeader('Content-Type', 'application/'. $feedType .'+xml; charset=utf-8');
|
|
|
|
|
|
|
|
$pageUrl = page_url($this->container->environment);
|
|
|
|
$cache = $this->container->pageCacheManager->getCachePage($pageUrl);
|
|
|
|
|
|
|
|
$cached = $cache->cachedVersion();
|
|
|
|
if (!empty($cached)) {
|
|
|
|
return $response->write($cached);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate data.
|
|
|
|
$this->container->feedBuilder->setLocale(strtolower(setlocale(LC_COLLATE, 0)));
|
|
|
|
$this->container->feedBuilder->setHideDates($this->container->conf->get('privacy.hide_timestamps', false));
|
|
|
|
$this->container->feedBuilder->setUsePermalinks(
|
|
|
|
null !== $request->getParam('permalinks') || !$this->container->conf->get('feed.rss_permalinks')
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
|
|
|
|
|
2020-09-03 10:09:32 +02:00
|
|
|
$this->executePageHooks('render_feed', $data, 'feed.' . $feedType);
|
2020-05-18 17:17:36 +02:00
|
|
|
$this->assignAllView($data);
|
|
|
|
|
2020-09-03 10:09:32 +02:00
|
|
|
$content = $this->render('feed.' . $feedType);
|
2020-05-18 17:17:36 +02:00
|
|
|
|
|
|
|
$cache->cache($content);
|
|
|
|
|
|
|
|
return $response->write($content);
|
|
|
|
}
|
|
|
|
}
|