aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controllers
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-18 17:17:36 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit7b2ba6ef820335df682fbe3dcfaceef3a62cf4a5 (patch)
treeb9d4b744f514fb3d1b45a40f81323983ca31f7ad /application/front/controllers
parentf4929b1188b4bc5e92b925ebc44f5ad40bb1a4ed (diff)
downloadShaarli-7b2ba6ef820335df682fbe3dcfaceef3a62cf4a5.tar.gz
Shaarli-7b2ba6ef820335df682fbe3dcfaceef3a62cf4a5.tar.zst
Shaarli-7b2ba6ef820335df682fbe3dcfaceef3a62cf4a5.zip
RSS/ATOM feeds: process through Slim controller
Diffstat (limited to 'application/front/controllers')
-rw-r--r--application/front/controllers/FeedController.php79
-rw-r--r--application/front/controllers/ShaarliController.php14
2 files changed, 93 insertions, 0 deletions
diff --git a/application/front/controllers/FeedController.php b/application/front/controllers/FeedController.php
new file mode 100644
index 00000000..78d826d9
--- /dev/null
+++ b/application/front/controllers/FeedController.php
@@ -0,0 +1,79 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller;
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 *
16 * @package Front\Controller
17 */
18class FeedController extends ShaarliController
19{
20 public function atom(Request $request, Response $response): Response
21 {
22 return $this->processRequest(FeedBuilder::$FEED_ATOM, $request, $response);
23 }
24
25 public function rss(Request $request, Response $response): Response
26 {
27 return $this->processRequest(FeedBuilder::$FEED_RSS, $request, $response);
28 }
29
30 protected function processRequest(string $feedType, Request $request, Response $response): Response
31 {
32 $response = $response->withHeader('Content-Type', 'application/'. $feedType .'+xml; charset=utf-8');
33
34 $pageUrl = page_url($this->container->environment);
35 $cache = $this->container->pageCacheManager->getCachePage($pageUrl);
36
37 $cached = $cache->cachedVersion();
38 if (!empty($cached)) {
39 return $response->write($cached);
40 }
41
42 // Generate data.
43 $this->container->feedBuilder->setLocale(strtolower(setlocale(LC_COLLATE, 0)));
44 $this->container->feedBuilder->setHideDates($this->container->conf->get('privacy.hide_timestamps', false));
45 $this->container->feedBuilder->setUsePermalinks(
46 null !== $request->getParam('permalinks') || !$this->container->conf->get('feed.rss_permalinks')
47 );
48
49 $data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
50
51 $this->executeHooks($data, $feedType);
52 $this->assignAllView($data);
53
54 $content = $this->render('feed.'. $feedType);
55
56 $cache->cache($content);
57
58 return $response->write($content);
59 }
60
61 /**
62 * @param mixed[] $data Template data
63 *
64 * @return mixed[] Template data after active plugins hook execution.
65 */
66 protected function executeHooks(array $data, string $feedType): array
67 {
68 $this->container->pluginManager->executeHooks(
69 'render_feed',
70 $data,
71 [
72 'loggedin' => $this->container->loginManager->isLoggedIn(),
73 'target' => $feedType,
74 ]
75 );
76
77 return $data;
78 }
79}
diff --git a/application/front/controllers/ShaarliController.php b/application/front/controllers/ShaarliController.php
index 2b828588..0c5d363e 100644
--- a/application/front/controllers/ShaarliController.php
+++ b/application/front/controllers/ShaarliController.php
@@ -30,6 +30,20 @@ abstract class ShaarliController
30 return $this; 30 return $this;
31 } 31 }
32 32
33 /**
34 * Assign variables to RainTPL template through the PageBuilder.
35 *
36 * @param mixed $data Values to assign to the template and their keys
37 */
38 protected function assignAllView(array $data): self
39 {
40 foreach ($data as $key => $value) {
41 $this->assignView($key, $value);
42 }
43
44 return $this;
45 }
46
33 protected function render(string $template): string 47 protected function render(string $template): string
34 { 48 {
35 $this->assignView('linkcount', $this->container->bookmarkService->count(BookmarkFilter::$ALL)); 49 $this->assignView('linkcount', $this->container->bookmarkService->count(BookmarkFilter::$ALL));