summaryrefslogtreecommitdiff
path: root/api/docs.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-09-21 22:42:33 +0200
committerMinteck <contact@minteck.org>2022-09-21 22:42:33 +0200
commite95b208af90cc386a7d8d1bcab426727cf4f0121 (patch)
treeb293e0c644513fbeb6e9ad29be97fa6347a55e9f /api/docs.php
parentb5f589c323f415bb42ea7069cb4d1a8a2233dd69 (diff)
downloadpluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.tar.gz
pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.tar.bz2
pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.zip
Update time
Diffstat (limited to 'api/docs.php')
-rw-r--r--api/docs.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/api/docs.php b/api/docs.php
new file mode 100644
index 0000000..edcd4fb
--- /dev/null
+++ b/api/docs.php
@@ -0,0 +1,31 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; 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 {
+ header("Location: /-/docs");
+ die();
+ }
+} else {
+ header("Location: /-/docs");
+ die();
+}
+
+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