summaryrefslogtreecommitdiff
path: root/api/desktop-app.php
blob: 20b1da933b02d6e8a8cdf76db46c87509a002d9d (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
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.inc";

if (!isset($_GET["id"])) die();

if (isset($_GET["config"])) {
    $data = [];

    $keys = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/permitted.json"), true);
    $proceed = false;

    if (in_array($_GET["id"], array_keys($keys))) {
        $proceed = true;
        $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $keys[$_GET["id"]]["system"] . "/fronters.json"), true)["members"];

        if (count($fronters) > 0) {
            $fronter = $fronters[0];
            $info = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $fronter["id"] . ".json"), true);
            $info = parseMetadata($info);

            if (isset($info["birth"]["age"]) && $info["birth"]["age"] < 16 && $info["birth"]["age"] > 0) {
                $proceed = false;
            } else if (isset($info["birth"]["year"]) && $info["birth"]["year"] > 1900) {
                if (!isset($info["birth"]["date"])) $info["birth"]["date"] = "01-01";

                $age = (int)date('Y') - $info["birth"]["year"] + (strtotime(date('Y') . "-" . $info["birth"]["date"]) <= time() ? 0 : -1);

                if ($age < 16) {
                    $proceed = false;
                }
            }
        }
    }

    if ($proceed) {
        $data = $keys[$_GET["id"]]["config"] ?? [];
    }
} else {
    $data = [
        "success" => true,
        "valid" => false,
        "underage" => false,
        "normal" => false
    ];

    $keys = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/permitted.json"), true);

    if (in_array($_GET["id"], array_keys($keys))) {
        $data["valid"] = true;

        $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $keys[$_GET["id"]]["system"] . "/fronters.json"), true)["members"];

        if (count($fronters) > 0) {
            $fronter = $fronters[0];
            $info = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $fronter["id"] . ".json"), true);
            $info = parseMetadata($info);

            $data["normal"] = $info["sexually_active"];

            if (isset($info["birth"]["age"]) && $info["birth"]["age"] < 16 && $info["birth"]["age"] > 0) {
                $data["underage"] = true;
            } else if (isset($info["birth"]["year"]) && $info["birth"]["year"] > 1900) {
                if (!isset($info["birth"]["date"])) $info["birth"]["date"] = "01-01";

                $age = (int)date('Y') - $info["birth"]["year"] + (strtotime(date('Y') . "-" . $info["birth"]["date"]) <= time() ? 0 : -1);

                if ($age < 16) {
                    $data["underage"] = true;
                }
            }
        }
    }
}

die(json_encode($data));