diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-12 20:41:49 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-12 20:41:49 +0100 |
| commit | 2ab5661583d74b03c86bb4f437616bb634d9c4fc (patch) | |
| tree | 2e09a8386148e8994def741f5fffdd733d297e38 /public | |
| parent | 523a84dd4b7cb611955e949fd6debc4a3c037b91 (diff) | |
Add delete
Diffstat (limited to 'public')
| -rw-r--r-- | public/delete/index.php | 27 | ||||
| -rw-r--r-- | public/edit/index.php | 2 | ||||
| -rw-r--r-- | public/index.php | 2 |
3 files changed, 27 insertions, 4 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); diff --git a/public/edit/index.php b/public/edit/index.php index 0cc1c27..65b3fa5 100644 --- a/public/edit/index.php +++ b/public/edit/index.php @@ -16,8 +16,6 @@ $template = new Template($config['path_to_templates']); $id = filter_input(INPUT_GET, 'id') ?? filter_input(INPUT_POST, 'id') ?? null; -$bookmarks->load(); - $bookmark = $bookmarks->find($id); if ('POST' === filter_input(INPUT_SERVER, 'REQUEST_METHOD')) { diff --git a/public/index.php b/public/index.php index 2a9ccb7..7453506 100644 --- a/public/index.php +++ b/public/index.php @@ -18,8 +18,6 @@ $sort = $_GET['sort'] ?? null; $tag = $_GET['tag'] ?? null; -$bookmarks->load(); - if ($tag !== null) { $bookmarks->filter($tag); } |
