Entire thing works now
This commit is contained in:
parent
e1eaf1a672
commit
59af0602f3
1995
parsedown.php
Normal file
1995
parsedown.php
Normal file
File diff suppressed because it is too large
Load diff
153
router.php
153
router.php
|
@ -1,65 +1,136 @@
|
|||
<?php
|
||||
require "parsedown.php";
|
||||
|
||||
// router.php
|
||||
|
||||
$site = json_decode(file_get_contents("site.json");
|
||||
echo json_last_error();
|
||||
echo $site["title"];
|
||||
|
||||
/* Overwrite these with the specific content */
|
||||
$title = $site['title'];
|
||||
$desc = $site['desc'];
|
||||
$author = "";
|
||||
|
||||
class menu_link {
|
||||
public $name;
|
||||
public $url;
|
||||
if (file_exists("site.json")) {
|
||||
$site = json_decode(file_get_contents("site.json"), true);
|
||||
}
|
||||
|
||||
$menu[0] = new menu_link();
|
||||
$menu[1] = new menu_link();
|
||||
$menu[2] = new menu_link();
|
||||
|
||||
$menu[0]->name = "Circus of the Stranded";
|
||||
$menu[0]->url = "/rooms/circus";
|
||||
$menu[1]->name = "Swan Song";
|
||||
$menu[1]->url = "/rooms/swan";
|
||||
$menu[2]->name = "Abstract Larceny";
|
||||
$menu[2]->url = "/rooms/abstract-larceny";
|
||||
|
||||
$mainphp = "";
|
||||
|
||||
if (preg_match('/\.(?:jpg|png|css|ico|scss|js|ttf|woff)/', $_SERVER["REQUEST_URI"])) {
|
||||
if (preg_match('/\.(?:jpg|png|css|ico|scss|js|ttf|woff|txt)/', $_SERVER["REQUEST_URI"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$obj = NULL;
|
||||
$tryuri = ltrim("$_SERVER[REQUEST_URI]", '/');
|
||||
$tryuri = strtok($tryuri, "?");
|
||||
|
||||
$jsonf = "index.json";
|
||||
$mainphp = "index.php";
|
||||
load_page($tryuri);
|
||||
|
||||
do {
|
||||
$tryf = "$tryuri/index";
|
||||
|
||||
if (file_exists("$tryf.json") && $jsonf == "index.json") {
|
||||
$jsonf = "$tryf.json";
|
||||
/* HELPER FUNCTIONS START */
|
||||
|
||||
function get_path_content($path) {
|
||||
$fs = scandir($path);
|
||||
$titles;
|
||||
|
||||
for ($i = 2; $i < count($fs); $i++) {
|
||||
$f = "$path/$fs[$i]";
|
||||
if (!is_dir($f)) {
|
||||
if (pathinfo($f, PATHINFO_EXTENSION) == "json") {
|
||||
$titles[] = ["c" => json_decode(file_get_contents($f), true), "link" => uri_from_file($f)];
|
||||
}
|
||||
} else {
|
||||
$fy = "$f/index.json";
|
||||
if (file_exists($fy)) $titles[] = ["c" => json_decode(file_get_contents($fy), true), "link" => uri_from_file($fy)];
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists("$tryf.php") && $mainphp == "index.php") {
|
||||
$mainphp = "$tryf.php";
|
||||
return $titles;
|
||||
}
|
||||
|
||||
function uri_from_file($file) {
|
||||
$name = substr($file, strrpos($file, '/')+1);
|
||||
if ($name == "index.json") {
|
||||
return substr($file, 0, -strlen($name)-1);
|
||||
}
|
||||
|
||||
$tryuri = substr($tryuri, 0, strrpos($tryuri, '/'));
|
||||
if (!strcmp(substr($file, strrpos($file, '.')+1), "json")) {
|
||||
|
||||
} while ($tryuri != "" && (!$obj || $mainphp == ""));
|
||||
return substr($file, 0, -5);
|
||||
}
|
||||
}
|
||||
|
||||
function load_page($tryuri) {
|
||||
global $site;
|
||||
|
||||
$mainphp = "";
|
||||
$jsonf = "";
|
||||
$parsef = "";
|
||||
|
||||
/* Looking for 3 things: a base, a content, and a template */
|
||||
|
||||
$tryf = "$tryuri/index";
|
||||
$tryf = ltrim($tryf, '/');
|
||||
|
||||
if (file_exists("$tryf.json")) {
|
||||
$jsonf = "$tryf.json";
|
||||
} else if (file_exists("$tryuri.json")) {
|
||||
$jsonf = "$tryuri.json";
|
||||
}
|
||||
|
||||
if (file_exists("$tryf.php")) {
|
||||
$mainphp = "$tryf.php";
|
||||
}
|
||||
else if (file_exists("$tryuri.php")) {
|
||||
$mainphp = "$tryuri.php";
|
||||
}
|
||||
|
||||
if (file_exists("$tryf.md")) {
|
||||
$parsef = "$tryf.md";
|
||||
} else if (file_exists("$tryuri.md")) {
|
||||
$parsef = "$tryuri.md";
|
||||
}
|
||||
|
||||
if (empty($mainphp) && empty($jsonf) && empty($parsef)) {
|
||||
load_page("404");
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($mainphp)) {
|
||||
|
||||
while ($tryuri != "") {
|
||||
if (file_exists("$tryuri/temp.php")) {
|
||||
$mainphp = "$tryuri/temp.php";
|
||||
goto endmain;
|
||||
}
|
||||
|
||||
$tryuri = substr($tryuri, 0, strrpos($tryuri, '/'));
|
||||
}
|
||||
|
||||
$mainphp = "temp.php";
|
||||
}
|
||||
|
||||
endmain:
|
||||
|
||||
|
||||
if (!empty($jsonf)) {
|
||||
$file = file_get_contents($jsonf);
|
||||
$obj = json_decode($file);
|
||||
}
|
||||
|
||||
if (!empty($parsef)) {
|
||||
$pd = new Parsedown();
|
||||
$parse = $pd->text(file_get_contents($parsef));
|
||||
}
|
||||
|
||||
$page['title'] = $obj->title;
|
||||
$page['desc'] = $obj->desc;
|
||||
|
||||
if (empty($page['title'])) $page['title'] = $site['title'];
|
||||
if (empty($page['desc'])) $page['desc'] = $site['desc'];
|
||||
|
||||
include "base.php";
|
||||
|
||||
}
|
||||
|
||||
function img_src($src, $root = "" ) {
|
||||
if (empty($root)) $root = $_SERVER['REQUEST_URI'];
|
||||
if ($src[0] != '/') {
|
||||
$write = "$root/$src";
|
||||
} else $write = $src;
|
||||
|
||||
return $write;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
?>
|
Loading…
Reference in a new issue