summaryrefslogtreecommitdiff
path: root/api/cloudburst-data.php
blob: edddd2da30531afc64b5c556aa600ddb8414c186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.inc";
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, "/content.html") || 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));