summaryrefslogtreecommitdiff
path: root/app.php
blob: a6e17d93978a59412923c1f741612641f98194e4 (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
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/language.inc"; global $lang; global $pages;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLoggedIn; global $isLowerLoggedIn;

$app = 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 (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 {
        header("Location: /?error=" . $lang["app"]["file"]) and die();
    }
} elseif ($toplevel === "") {
    $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/home.inc";
    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";
            require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
        } else {
            header("Location: /?error=" . $lang["app"]["page"] . " " . strip_tags($pagename)) and die();
        }
    } else if ($toplevel === "api") {
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc")) {
            $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
            require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc";
        }
    } else if ($toplevel === "cloudburst" || $toplevel === "raindrops" || (($isLoggedIn || $isLowerLoggedIn) && $toplevel === $app["other"]["slug"])) {
        $parts = explode("/", $_GET['_']);

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

            die();
        }

        $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
        require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
    } else {
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/" . $toplevel . ".inc")) {
            header("Location: /-/" . $toplevel);
        } else {
            $namesCloudburst = [...array_map(function ($i) {
                return $i['name'];
            }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true)), "unknown-cb"];
            $namesRaindrops = [...array_map(function ($i) {
                return $i['name'];
            }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true)), "unknown-rd"];
            $namesOther = [];

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

            if ((in_array($toplevel, $namesCloudburst) || in_array($toplevel, $namesRaindrops) || in_array($toplevel, $namesOther)) && $toplevel !== "unknown") {
                $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
                require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/page.inc";
            } else {
                global $toplevel;
                $pageFile = $_SERVER['DOCUMENT_ROOT'] . "/includes/short.inc";
                require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/short.inc";
            }
        }
    }
}