From 19718ab4e1d0dfd6d787e5a078131c8f19eae8e7 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 13 Feb 2024 03:47:28 +0200 Subject: [PATCH] implement rss feeds --- src/Controller/MainController.php | 28 +++++++++++++++++----- templates/default/main/index.html.twig | 5 ++++ templates/default/main/index.rss.twig | 17 +++++++++++++ templates/default/main/namespace.html.twig | 5 ++++ templates/default/main/namespace.rss.twig | 17 +++++++++++++ 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 templates/default/main/index.rss.twig create mode 100644 templates/default/main/namespace.rss.twig diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index b3927fe..8110156 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -28,13 +28,20 @@ class MainController extends AbstractController ] )] public function index( - ?Request $request + ?Request $request, + ?Response $response ): Response { $index = new \Kvazar\Index\Manticore(); + if ($rss = ('rss' == $request->get('feed'))) + { + $response = new Response(); + $response->headers->set('Content-Type', 'text/xml'); + } + return $this->render( - 'default/main/index.html.twig', + $rss ? 'default/main/index.rss.twig' : 'default/main/index.html.twig', [ 'request' => $request, 'records' => $index->get( @@ -46,7 +53,8 @@ class MainController extends AbstractController $request->get('part') > 1 ? (int) $request->get('part') * $this->getParameter('app.main.index.limit') : 0, $this->getParameter('app.main.index.limit') ) - ] + ], + $response ); } @@ -68,13 +76,20 @@ class MainController extends AbstractController ] )] public function namespace( - ?Request $request + ?Request $request, + ?Response $response ): Response { $index = new \Kvazar\Index\Manticore(); + if ($rss = ('rss' == $request->get('feed'))) + { + $response = new Response(); + $response->headers->set('Content-Type', 'text/xml'); + } + return $this->render( - 'default/main/namespace.html.twig', + $rss ? 'default/main/namespace.rss.twig' : 'default/main/namespace.html.twig', [ 'request' => $request, 'records' => $index->get( @@ -93,7 +108,8 @@ class MainController extends AbstractController 'title' => $this->_title( $request->get('namespace') ) - ] + ], + $response ); } diff --git a/templates/default/main/index.html.twig b/templates/default/main/index.html.twig index 968dd34..419e1e3 100644 --- a/templates/default/main/index.html.twig +++ b/templates/default/main/index.html.twig @@ -60,4 +60,9 @@ } ) }}">{{ 'newer' | trans }} +
+ +
{% endblock %} \ No newline at end of file diff --git a/templates/default/main/index.rss.twig b/templates/default/main/index.rss.twig new file mode 100644 index 0000000..e7c0e16 --- /dev/null +++ b/templates/default/main/index.rss.twig @@ -0,0 +1,17 @@ + + + + + {{ app.name }} + {{ url('main_index') }} + {% for record in records %} + + {{ record.key }} + {{ record.namespace }} + {{ record.time | date('D, d M Y h:i:s O') }} + {{ url('main_transaction',{'transaction':record.transaction}) }} + {{ url('main_transaction',{'transaction':record.transaction}) }} + + {% endfor %} + + \ No newline at end of file diff --git a/templates/default/main/namespace.html.twig b/templates/default/main/namespace.html.twig index 83a034a..1b83d11 100644 --- a/templates/default/main/namespace.html.twig +++ b/templates/default/main/namespace.html.twig @@ -63,4 +63,9 @@ } ) }}">{{ 'newer' | trans }} +
+ +
{% endblock %} \ No newline at end of file diff --git a/templates/default/main/namespace.rss.twig b/templates/default/main/namespace.rss.twig new file mode 100644 index 0000000..0b0ae3c --- /dev/null +++ b/templates/default/main/namespace.rss.twig @@ -0,0 +1,17 @@ + + + + + {{ app.name }} + {{ url('main_namespace',{'namespace':request.get('namespace')}) }} + {% for record in records %} + + {{ record.key }} + {{ record.namespace }} + {{ record.time | date('D, d M Y h:i:s O') }} + {{ url('main_transaction',{'transaction':record.transaction}) }} + {{ url('main_transaction',{'transaction':record.transaction}) }} + + {% endfor %} + + \ No newline at end of file