blob: 0cc1c2780ac819b603599ad48c918ac982c6cbac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
|