summaryrefslogtreecommitdiff
path: root/app.php
blob: 521ce2ff09fdcccef3bb8a7c55c7f7d559e786ad (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php

$enable2024Mode = isset($_GET["2024"]) || time() >= 1711929600;
$defaultMember = <<<EOF
{
  "regression": null,
  "median": false,
  "marefriends": [],
  "sisters": [],
  "caretakers": [],
  "heat": null,
  "birth": {
    "date": "01-01",
    "year": null,
    "age": 0
  },
  "code": "",
  "interest": "",
  "food": 0,
  "shared_memory": 0,
  "species": [
    "earth"
  ],
  "alignment": {
    "sexual": "homo",
    "romantic": "homo"
  },
  "sexfriends": [],
  "age_regressor": false,
  "age_spells": false,
  "host": false,
  "not_talking": false,
  "protector": false,
  "leader": false,
  "fictive": false,
  "sexual_features": false,
  "sexually_active": false,
  "robot": false,
  "plush": false,
  "polyamorous": {
    "romantic": false,
    "sexual": false
  },
  "non_verbal": false,
  "less_frequent": false,
  "persecutor": false,
  "pacifier": false,
  "not_fronting": false,
  "friends": []
}
EOF;

ob_start();

if (!str_starts_with($_SERVER['REQUEST_URI'], "/api")) {
    require_once $_SERVER['DOCUMENT_ROOT'] . "/error.php";
    set_error_handler("ch_error");
}

$start = microtime(true);
$GLOBALS["ColdHazeStart"] = microtime(true);
$GLOBALS["ColdHazePerformance"] = [];

if (!function_exists("formatPonypush")) {
    function formatPonypush($message) {
        return "Update to Ponypush 3.1.0 or later — (\$PA1$\$" . base64_encode($message) . "\$\$)";
    }
}

$lang = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/i18n/en.json"), true); global $lang; global $pages;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $isLowerLoggedIn;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";

global $app;
$app = $GLOBALS["ColdHazeApp"] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);

if (str_ends_with($_GET['_'], "/")) {
    $pagename = substr($_GET['_'], 0, strlen($_GET['_']) - 1);
} else {
    $pagename = $_GET['_'];
}

$toplevel = explode("/", $pagename)[0];

if ($enable2024Mode) {
    if ($toplevel === "api") {
        require_once $_SERVER['DOCUMENT_ROOT'] . "/api/_main.php";
    } else {
        require_once $_SERVER['DOCUMENT_ROOT'] . "/eol.php";
    }
} else {
    if (in_array($toplevel, ["editor", "icons", "species", "uploads"])) {
        $filename = explode("/", $pagename)[1];
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/" . $toplevel . "/" . $filename)) {
            header("Location: /assets/" . $toplevel . "/" . $filename) and die();
        } else {
            peh_error("File not found", 404);
        }
    } elseif ($toplevel === "") {
        $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/home.inc";
        $GLOBALS["ColdHazePerformance"]["router"] = (microtime(true) - $start) * 1000;
        require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/home.inc";
    } else {
        if ($toplevel === "-") {
            $pagename = substr($pagename, 2);
            $toplevel = explode("/", $pagename)[0];

            if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc")) {
                $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
                $GLOBALS["ColdHazePerformance"]["router"] = (microtime(true) - $start) * 1000;
                require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
            } else {
                peh_error("Page not found: " . strip_tags($pagename), 404);
            }
        } else if ($toplevel === "api") {
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc")) {
                $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
                $GLOBALS["ColdHazePerformance"]["router"] = (microtime(true) - $start) * 1000;
                require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
            }
        } else if ($toplevel === "raindrops" || $toplevel === "moonglow" || (($isLoggedIn || $isLowerLoggedIn) && $toplevel === $app["other"]["slug"])) {
            $parts = explode("/", $_GET['_']);

            if (isset($parts[1]) && $parts[1] !== "-") {
                if ($parts[1] === "unknown") {
                    header("Location: /unknown-rd");
                } else {
                    header("Location: /" . $parts[1]);
                }

                die();
            }

            $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
            $GLOBALS["ColdHazePerformance"]["router"] = (microtime(true) - $start) * 1000;
            require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
        } else {
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc")) {
                header("Location: /-/" . $toplevel);
            } else {
                $namesRaindrops = [...array_map(function ($i) {
                    return $i['name'];
                }, array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true), function ($i) {
                    return true;
                })), "unknown-rd"];
                $namesMoonglow = array_map(function ($i) {
                    return $i['name'];
                }, array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/hrbom/members.json"), true), function ($i) {
                    return true;
                }));
                $namesOther = [];

                if ($isLoggedIn || $isLowerLoggedIn) {
                    $namesOther = [...array_map(function ($i) {
                        return $i['name'];
                    }, array_filter(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true), function ($i) {
                        return true;
                    })), $app["other"]["unknown"]];
                }

                if ((in_array($toplevel, $namesRaindrops) || in_array($toplevel, $namesOther) || in_array($toplevel, $namesMoonglow)) && $toplevel !== "unknown") {
                    $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
                    $GLOBALS["ColdHazePerformance"]["router"] = (microtime(true) - $start) * 1000;
                    require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
                }
            }
        }
    }
}

$output = ob_get_contents();
ob_end_clean();
echo($output);