summaryrefslogtreecommitdiff
path: root/pages/api.inc
blob: 418df7679cdf56d19d3d20075b6eb5cc0f8981e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

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

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

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