diff options
author | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
commit | 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch) | |
tree | 75be5fba4368472fb11c8015aee026b2b9a71888 /pages/api/docs.php | |
parent | 8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff) | |
download | pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2 pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip |
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'pages/api/docs.php')
-rw-r--r-- | pages/api/docs.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/pages/api/docs.php b/pages/api/docs.php new file mode 100644 index 0000000..89e9216 --- /dev/null +++ b/pages/api/docs.php @@ -0,0 +1,29 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $_PROFILE; +if (!$isLoggedIn) header("Location: /-/login") and die(); + +$request_raw = file_get_contents('php://input'); +$json_object = json_decode($request_raw, true); + +$select = $_GET['id'] ?? null; + +if (isset($select)) { + if (ctype_alnum($select) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $select . ".json")) { + $id = $select; + $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $select . ".json"), true); + } else { + die("Not found"); + } +} else { + die("Not set"); +} + +if ($json_object["content"]) $data["contents"] = $json_object["content"]; +if ($json_object["name"]) $data["name"] = $json_object["name"]; +if ($json_object["category"]) $data["category"] = trim($json_object["category"]) !== "" && trim($json_object["category"]) !== "Unsorted" && trim($json_object["category"]) !== "unsorted" && trim($json_object["category"]) !== "/no" && trim($json_object["category"]) !== "Unsort" && trim($json_object["category"]) !== "unsort" ? $json_object["category"] : null; + +$data["last"]["date"] = time(); +$data["last"]["author"] = $_PROFILE['login']; + +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $select . ".json", utf8_encode(json_encode($data)));
\ No newline at end of file |