summaryrefslogtreecommitdiff
path: root/pages/api/wear/schedule.php
blob: cf053d84e150762fb678447616e0e504f2a5bec3 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
if (!$isLoggedIn) header("Location: /-/login") and die();

header("Content-Type: application/json");

$obj = [
    "today" => [],
    "tomorrow" => []
];

$raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/gdapd.json"), true);
$cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/ynmuc.json"), true);

if (isset($raindrops[date('Y-m-d', time())]) || isset($cloudburst[date('Y-m-d', time())])) {
    $rd = $raindrops[date('Y-m-d', time())];
    $cb = $cloudburst[date('Y-m-d', time())];
    $longest = max(count($rd), count($cb));

    for ($x = 0; $x < $longest; $x++) {
        $item = [];
        $item["raindrops"] = null;
        $item["cloudburst"] = null;

        if (isset($rd[$x])) {
            $item["raindrops"] = array_map(function ($i) use ($x, $longest) {
                $member = getMemberWithoutSystem($i);

                return [
                    "id" => $member["id"],
                    "name" => $member["display_name"] ?? $member["name"],
                    "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]),
                    "flags" => [
                        "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)),
                        "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)),
                    ]
                ];
            }, array_filter($rd[$x], function ($i) { return isset($i); }));
        } else if (isset($obj["today"][$x - 1]["raindrops"])) {
            $item["raindrops"] = $obj["today"][$x - 1]["raindrops"];
        }

        if (isset($cb[$x])) {
            $item["cloudburst"] = array_map(function ($i) use ($x, $longest) {
                $member = getMemberWithoutSystem($i);

                return [
                    "id" => $member["id"],
                    "name" => $member["display_name"] ?? $member["name"],
                    "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]),
                    "flags" => [
                        "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)),
                        "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)),
                    ]
                ];
            }, array_filter($cb[$x], function ($i) { return isset($i); }));
        } else if (isset($obj["today"][$x - 1]["cloudburst"])) {
            $item["cloudburst"] = $obj["today"][$x - 1]["cloudburst"];
        }

        $obj["today"][] = $item;
    }
}

if (isset($raindrops[date('Y-m-d', time() + 86400)]) || isset($cloudburst[date('Y-m-d', time() + 86400)])) {
    $rd = $raindrops[date('Y-m-d', time() + 86400)];
    $cb = $cloudburst[date('Y-m-d', time() + 86400)];
    $longest = max(count($rd), count($cb));

    for ($x = 0; $x < $longest; $x++) {
        $item = [];
        $item["raindrops"] = null;
        $item["cloudburst"] = null;

        if (isset($rd[$x])) {
            $item["raindrops"] = array_map(function ($i) use ($x, $longest) {
                $member = getMemberWithoutSystem($i);

                return [
                    "id" => $member["id"],
                    "name" => $member["display_name"] ?? $member["name"],
                    "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]),
                    "flags" => [
                        "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)),
                        "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)),
                    ]
                ];
            }, array_filter($rd[$x], function ($i) { return isset($i); }));
        } else if (isset($obj["tomorrow"][$x - 1]["raindrops"])) {
            $item["raindrops"] = $obj["tomorrow"][$x - 1]["raindrops"];
        }

        if (isset($cb[$x])) {
            $item["cloudburst"] = array_map(function ($i) use ($x, $longest) {
                $member = getMemberWithoutSystem($i);

                return [
                    "id" => $member["id"],
                    "name" => $member["display_name"] ?? $member["name"],
                    "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]),
                    "flags" => [
                        "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)),
                        "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)),
                    ]
                ];
            }, array_filter($cb[$x], function ($i) { return isset($i); }));
        } else if (isset($obj["tomorrow"][$x - 1]["cloudburst"])) {
            $item["cloudburst"] = $obj["tomorrow"][$x - 1]["cloudburst"];
        }

        $obj["tomorrow"][] = $item;
    }
}

die(json_encode($obj, JSON_PRETTY_PRINT));