summaryrefslogtreecommitdiff
path: root/public/delete/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/delete/index.php')
-rw-r--r--public/delete/index.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/public/delete/index.php b/public/delete/index.php
new file mode 100644
index 0000000..1b2484d
--- /dev/null
+++ b/public/delete/index.php
@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+use DTS\BookmarkRepository;
+use DTS\Template;
+use function DTS\Functions\respondAndExit;
+
+require_once(__DIR__.'/../../autoload.php');
+
+$config = require_once(__DIR__.'/../../config.php');
+
+$bookmarks = new BookmarkRepository($config['path_to_repository']);
+
+$template = new Template($config['path_to_templates']);
+
+$id = filter_input(INPUT_GET, 'id') ?? filter_input(INPUT_POST, 'id') ?? null;
+
+$bookmark = $bookmarks->find($id);
+
+if ('POST' === filter_input(INPUT_SERVER, 'REQUEST_METHOD')) {
+ $bookmarks->delete($bookmark);
+}
+
+$html = $template->render('delete', compact('bookmark'));
+
+respondAndExit(200, 'OK', $html);