summaryrefslogtreecommitdiff
path: root/api/_main.php
blob: 215c1b255278e8235b40a90cc6ee81233b9d66fe (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
<?php

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

$toplevel = explode("/", $pagename)[1];
$middlelevel = explode("/", $pagename)[2] ?? null;

if ($toplevel === "_main" || $middlelevel === "_main") {
    header("HTTP/1.1 404 Not Found");
    header("Content-Type: text/plain");
    echo("Endpoint not found");
    die();
}

if (isset($middlelevel) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . "/" . $middlelevel . ".php") && is_file($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . "/" . $middlelevel . ".php")) {
    require_once $_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . "/" . $middlelevel . ".php";
} else {
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . ".php") && is_file($_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . ".php")) {
        require_once $_SERVER['DOCUMENT_ROOT'] . "/api/" . $toplevel . ".php";
    } else {
        header("HTTP/1.1 404 Not Found");
        header("Content-Type: text/plain");
        echo("Endpoint not found");
        die();
    }
}