]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | declare(strict_types=1); | |
4 | ||
5 | namespace Shaarli\Front\Controller\Visitor; | |
6 | ||
7 | use Shaarli\Feed\FeedBuilder; | |
8 | use Slim\Http\Request; | |
9 | use Slim\Http\Response; | |
10 | ||
11 | /** | |
12 | * Class FeedController | |
13 | * | |
14 | * Slim controller handling ATOM and RSS feed. | |
15 | */ | |
16 | class FeedController extends ShaarliVisitorController | |
17 | { | |
18 | public function atom(Request $request, Response $response): Response | |
19 | { | |
20 | return $this->processRequest(FeedBuilder::$FEED_ATOM, $request, $response); | |
21 | } | |
22 | ||
23 | public function rss(Request $request, Response $response): Response | |
24 | { | |
25 | return $this->processRequest(FeedBuilder::$FEED_RSS, $request, $response); | |
26 | } | |
27 | ||
28 | protected function processRequest(string $feedType, Request $request, Response $response): Response | |
29 | { | |
30 | $response = $response->withHeader('Content-Type', 'application/'. $feedType .'+xml; charset=utf-8'); | |
31 | ||
32 | $pageUrl = page_url($this->container->environment); | |
33 | $cache = $this->container->pageCacheManager->getCachePage($pageUrl); | |
34 | ||
35 | $cached = $cache->cachedVersion(); | |
36 | if (!empty($cached)) { | |
37 | return $response->write($cached); | |
38 | } | |
39 | ||
40 | // Generate data. | |
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') | |
45 | ); | |
46 | ||
47 | $data = $this->container->feedBuilder->buildData($feedType, $request->getParams()); | |
48 | ||
49 | $this->executePageHooks('render_feed', $data, 'feed.' . $feedType); | |
50 | $this->assignAllView($data); | |
51 | ||
52 | $content = $this->render('feed.' . $feedType); | |
53 | ||
54 | $cache->cache($content); | |
55 | ||
56 | return $response->write($content); | |
57 | } | |
58 | } |