diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-11 21:49:47 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-11 21:49:47 +0100 |
| commit | 523a84dd4b7cb611955e949fd6debc4a3c037b91 (patch) | |
| tree | 3ca2999adda1cf3e180390538d91f45f696fe175 /public | |
| parent | 0f273c0a8ead390346571c4be2296fa6e384eff6 (diff) | |
Implement very basic editing
Diffstat (limited to 'public')
| -rw-r--r-- | public/edit/index.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/public/edit/index.php b/public/edit/index.php new file mode 100644 index 0000000..0cc1c27 --- /dev/null +++ b/public/edit/index.php @@ -0,0 +1,33 @@ +<?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; + +$bookmarks->load(); + +$bookmark = $bookmarks->find($id); + +if ('POST' === filter_input(INPUT_SERVER, 'REQUEST_METHOD')) { + $bookmark->url = $_POST['url']; + $bookmark->title = $_POST['title']; + $bookmark->tag = $_POST['tag']; + + $bookmarks->update($bookmark); +} + +$html = $template->render('edit', compact('bookmark')); + +respondAndExit(200, 'OK', $html); |
