X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=index.php;h=5c4b909b5057fe201b23b09978d73c0a785222dd;hb=a5291ff36193869a65db4cbf30acf1febe29b15d;hp=160fed53b3418e5a0a30fb4f80e4e594c5fbf86d;hpb=13943464c255c79c2038c4c63ad5af34331af088;p=mdref%2Fmdref diff --git a/index.php b/index.php index 160fed5..5c4b909 100644 --- a/index.php +++ b/index.php @@ -2,8 +2,6 @@ error_reporting(E_ALL &~ E_DEPRECATED); -define("OUTPUT", fopen("php://memory", "w+")); - function cut(array $lines, array $specs) { $delim = "[[:space:]]+"; $bytes = []; @@ -56,111 +54,195 @@ function cut(array $lines, array $specs) { function head($file, $lines = 1) { $ld = []; - if (($fd = fopen($file, "r"))) { + if (is_resource($file) || ($file = fopen($file, "r"))) { while ($lines--) { - $ld[] = fgets($fd); + $ld[] = fgets($file); } } return $ld; } -function ns($file) { +function ns($path) { + $ns = ""; + $parts = explode("/", $path); + $upper = ctype_upper($path[0]); + for ($i = 0; $i < count($parts); ++$i) { + if (!strlen($parts[$i]) || $parts[$i] === ".") { + continue; + } + if (strlen($ns)) { + if ($upper && !ctype_upper($parts[$i][0])) { + $ns .= "::"; + } else { + $ns .= "\\"; + } + } + $ns .= $parts[$i]; + $upper = ctype_upper($parts[$i][0]); + } + return $ns; return str_replace("/", "\\", str_replace("//", "/", trim($file, "/."))); } function urlpath($dir, $file) { - return (strlen($dir) ? $dir . "/" : "") . urlencode($file); + return (strlen($dir) ? $dir . "/" : "") . basename($file, ".md"); } -function ls($dir, $invert = false) { - fprintf(OUTPUT, "
".join(" ", cut(head("./$dir/$file"), ["f"=>"1-"]))."
"; + printf("%s
%s
%s\n", htmlspecialchars(file_get_contents($file))); + break; + } + } else { + $res->setResponseCode(404); + printf("
", dirname($file), basename($file, ".md")); + } } +chdir(__DIR__); +$t = ["css"=>"text/css", "js"=>"application/javascript"]; $r = new http\Env\Request; $u = new http\Url($r->getRequestUrl()); -$t = ["css"=>"text/css", "js"=>"application/javascript"]; +$s = new http\Env\Response; +$b = dirname($_SERVER["SCRIPT_NAME"]); +$p = ".". substr($u->path, strlen($b)); -switch($u->path) { -case "/index.js": -case "/index.css": - $s = new http\Env\Response; - $s->setHeader("Content-type", $t[pathinfo($u->path, PATHINFO_EXTENSION)]); - $s->setBody(new http\Message\Body(fopen(basename($u->path), "r"))); +switch($p) { +case "./index.php": + exit; +case "./index.js": +case "./index.css": + $s->setHeader("Content-type", $t[pathinfo($p, PATHINFO_EXTENSION)]); + $s->setBody(new http\Message\Body(fopen($p, "r"))); $s->send(); exit; } -if (is_dir(".".$u->path)) { - ls(".".$u->path); -} else { - md(".".$u->path); -} +ob_start($s); ?> - -Sorry, I could not find
%s/%s
.
v
+ + + + + + + + + + + + +send();