summaryrefslogtreecommitdiff
path: root/api/cloudburst-data.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
committerMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
commita2df9a69dcc14cb70118cda2ded499055e7ee358 (patch)
tree6dd283e4e9452d38bce81ddaaae49b5335755842 /api/cloudburst-data.php
parent84dd0735820b16b60f600284d35183d76547a71f (diff)
downloadpluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.gz
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.bz2
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.zip
m. update
Diffstat (limited to 'api/cloudburst-data.php')
-rw-r--r--api/cloudburst-data.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/api/cloudburst-data.php b/api/cloudburst-data.php
new file mode 100644
index 0000000..f1bab0b
--- /dev/null
+++ b/api/cloudburst-data.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php";
+if (!$isLoggedIn) header("Location: /login") and die();
+
+$data = [];
+$data["members"] = [];
+
+foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data"), function ($i) { return !str_starts_with($i, "."); }) as $file) {
+ if (str_starts_with($file, "ynmuc-") && !(str_ends_with($file, "-members.json") || str_ends_with($file, "-fronters.json") || str_ends_with($file, "-general.json") || str_ends_with($file, "-switches.json"))) {
+ $name = substr(explode(".", $file)[0], 6);
+ $parts = explode("-", $name);
+
+ if (explode(".", $file)[1] === "json") {
+ if (strlen($parts[0]) === 5) {
+ if (!isset($data["members"][$parts[0]])) $data["members"][$parts[0]] = [
+ "metadata" => null,
+ "content" => null
+ ];
+ if ($parts[1] === "metadata") {
+ $data["members"][$parts[0]][$parts[1]] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true));
+ } else {
+ $data["members"][$parts[0]][$parts[1]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true);
+ }
+ } else {
+ $data[$name] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true);
+ }
+ } else {
+ if (strlen($parts[0]) === 5) {
+ if (!isset($data["members"][$parts[0]])) $data["members"][$parts[0]] = [
+ "metadata" => null,
+ "content" => null
+ ];
+ $data["members"][$parts[0]][$parts[1]] = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file);
+ } else {
+ $data[$name] = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file);
+ }
+ }
+ }
+}
+
+header("Content-Type: application/json");
+die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file