From 108525534c28013cfe1897c30e4565f9893f3766 Mon Sep 17 00:00:00 2001 From: Minteck Date: Mon, 10 Oct 2022 20:51:39 +0200 Subject: Update --- pages/docs.inc | 361 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 pages/docs.inc (limited to 'pages/docs.inc') diff --git a/pages/docs.inc b/pages/docs.inc new file mode 100644 index 0000000..f893e95 --- /dev/null +++ b/pages/docs.inc @@ -0,0 +1,361 @@ + "Untitled document ($id)", + "category" => null, + "contents" => "
This is a new document you just created.
", + "last" => [ + "author" => $_PROFILE["login"], + "date" => time() + ] + ])); + + header("Location: /-/docs/$id"); + die(); +} elseif (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); + $titleBase = " · " . $title . " · Cold Haze"; + $title = $data["name"] . " · " . $title; + } else { + header("Location: /-/docs"); + die(); + } +} + +require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc'; + +?> + +
+
+
+
+

+ + Back +

+

Category:

+

+ + Last modified never + + Last modified "> + + by + + + · Saved +

+ + + + + + + + +
+

Documents

+
+ substr($i, 0, -5), + ...(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $i), true) ?? []) + ]; + }, array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs"), function ($i) { + return !str_starts_with($i, ".") && str_ends_with($i, ".json"); + })); + + $deletable = array_values(array_filter($documents, function ($i) { + return strip_tags($i["contents"]) === "/delete"; + })); + $unsorted_pre = array_values(array_filter($documents, function ($i) { + return strip_tags($i["contents"]) !== "/delete"; + })); + + $unsorted = []; + $categories = []; + foreach ($unsorted_pre as $item) { + if (isset($item["category"])) { + $existing_categories = array_keys($categories); + $matched_category = null; + + foreach ($existing_categories as $existing_category) { + if (levenshtein($item["category"], $existing_category) < 3) { + $matched_category = $existing_category; + } + } + + $selected_category = $matched_category ?? $item["category"]; + if (!isset($categories[$selected_category])) $categories[$selected_category] = []; + $categories[$selected_category][] = $item; + } else { + $unsorted[] = $item; + } + } + + uasort($unsorted, function ($a, $b) { + return $b["last"]["date"] - $a["last"]["date"]; + }); + + uasort($deletable, function ($a, $b) { + return $b["last"]["date"] - $a["last"]["date"]; + }); + + ?> + + $items): ?> +

+
+ + +

Unsorted

+ +
+

Marked for deletion

+
+ +
+ + +
+
+ + + + + -- cgit