aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/visitor/FeedController.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-22 13:20:31 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit2899ebb5b5e82890c877151f5c02045266ac9973 (patch)
tree0c4e2684c7f6d161f92a21181bfa4b2f78d6a82f /application/front/controller/visitor/FeedController.php
parentaf290059d10319e76d1e7d78b592cab99c26d91a (diff)
downloadShaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.gz
Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.zst
Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.zip
Initialize admin Slim controllers
- Reorganize visitor controllers - Fix redirection with Slim's requests base path - Fix daily links
Diffstat (limited to 'application/front/controller/visitor/FeedController.php')
-rw-r--r--application/front/controller/visitor/FeedController.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/application/front/controller/visitor/FeedController.php b/application/front/controller/visitor/FeedController.php
new file mode 100644
index 00000000..70664635
--- /dev/null
+++ b/application/front/controller/visitor/FeedController.php
@@ -0,0 +1,77 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Visitor;
6
7use Shaarli\Feed\FeedBuilder;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class FeedController
13 *
14 * Slim controller handling ATOM and RSS feed.
15 */
16class 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->executeHooks($data, $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
59 /**
60 * @param mixed[] $data Template data
61 *
62 * @return mixed[] Template data after active plugins hook execution.
63 */
64 protected function executeHooks(array $data, string $feedType): array
65 {
66 $this->container->pluginManager->executeHooks(
67 'render_feed',
68 $data,
69 [
70 'loggedin' => $this->container->loginManager->isLoggedIn(),
71 'target' => $feedType,
72 ]
73 );
74
75 return $data;
76 }
77}