3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Visitor
;
7 use Shaarli\Feed\FeedBuilder
;
9 use Slim\Http\Response
;
12 * Class FeedController
14 * Slim controller handling ATOM and RSS feed.
16 class FeedController
extends ShaarliVisitorController
18 public function atom(Request
$request, Response
$response): Response
20 return $this->processRequest(FeedBuilder
::$FEED_ATOM, $request, $response);
23 public function rss(Request
$request, Response
$response): Response
25 return $this->processRequest(FeedBuilder
::$FEED_RSS, $request, $response);
28 protected function processRequest(string $feedType, Request
$request, Response
$response): Response
30 $response = $response->withHeader('Content-Type', 'application/'. $feedType .'+xml; charset=utf-8');
32 $pageUrl = page_url($this->container
->environment
);
33 $cache = $this->container
->pageCacheManager
->getCachePage($pageUrl);
35 $cached = $cache->cachedVersion();
36 if (!empty($cached)) {
37 return $response->write($cached);
41 $this->container
->feedBuilder
->setLocale(strtolower(setlocale(LC_COLLATE
, 0)));
42 $this->container
->feedBuilder
->setHideDates($this->container
->conf
->get('privacy.hide_timestamps', false));
43 $this->container
->feedBuilder
->setUsePermalinks(
44 null !== $request->getParam('permalinks') || !$this->container
->conf
->get('feed.rss_permalinks')
47 $data = $this->container
->feedBuilder
->buildData($feedType, $request->getParams());
49 $this->executePageHooks('render_feed', $data, 'feed.' . $feedType);
50 $this->assignAllView($data);
52 $content = $this->render('feed.' . $feedType);
54 $cache->cache($content);
56 return $response->write($content);