summaryrefslogtreecommitdiff
path: root/public/store/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/store/index.php')
-rw-r--r--public/store/index.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/public/store/index.php b/public/store/index.php
new file mode 100644
index 0000000..2a84c59
--- /dev/null
+++ b/public/store/index.php
@@ -0,0 +1,33 @@
+<?php
+
+declare(strict_types=1);
+
+use DTS\Bookmark;
+use DTS\BookmarkRepository;
+use function DTS\Functions\respondAndExit;
+use function DTS\Functions\redirectAndExit;
+
+require_once(__DIR__.'/../../autoload.php');
+
+$config = require_once(__DIR__.'/../../config.php');
+
+if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') {
+ respondAndExit(405, 'Method Not Allowed');
+}
+
+$bookmarks = new BookmarkRepository($config['path_to_repository']);
+
+$bookmark = new Bookmark();
+
+$bookmark->id = bin2hex(random_bytes(32));
+$bookmark->url = $_POST['url'];
+$bookmark->title = $_POST['title'];
+$bookmark->tag = $_POST['tag'];
+$bookmark->addedAt = date('Y-m-d H:i:s');
+$bookmark->unread = true;
+
+if (!$bookmarks->add($bookmark)) {
+ respondAndExit(500, 'Internal Server Error');
+}
+
+redirectAndExit('/');