160fed53b3418e5a0a30fb4f80e4e594c5fbf86d
3 error_reporting(E_ALL
&~ E_DEPRECATED
);
5 define("OUTPUT", fopen("php://memory", "w+"));
7 function cut(array $lines, array $specs) {
8 $delim = "[[:space:]]+";
12 foreach ($specs as $spec => $value) {
30 $func = function($a, $o = 0, $l = 0) {
31 return join(" ", array_slice($a, $o, $l ?
$l+
1 : count($a)-$o));
34 foreach ($lines as $line) {
38 $line = split($delim, $line);
42 if ($spec[0] == "-") {
43 $result[] = $func($line, 0, $spec[1]);
44 } elseif ($spec[1] == "-") {
45 if (empty($spec[2])) {
46 $result[] = $func($line, $spec[0]);
48 $result[] = $func($line, $spec[0], $spec[2]-$spec[0]);
51 $result[] = $line{$spec[0]};
57 function head($file, $lines = 1) {
59 if (($fd = fopen($file, "r"))) {
68 return str_replace("/", "\\", str_replace("//", "/", trim($file, "/.")));
71 function urlpath($dir, $file) {
72 return (strlen($dir) ?
$dir . "/" : "") . urlencode($file);
75 function ls($dir, $invert = false) {
76 fprintf(OUTPUT
, "<ul>\n");
77 foreach (scandir($dir) as $file) {
78 $dir = trim($dir, "./");
82 } elseif ($file === "..") {
83 if ($dir === "" ||
$invert) {
86 $name = sprintf("namespace %s", ns(dirname($dir)));
87 } elseif (!$invert && is_dir("./$dir/$file")) {
88 $name = sprintf("namespace %s", ns("./$dir/$file"));
89 } elseif (!$invert && ctype_upper($file{0})) {
90 $name = join(" ", cut(head("./$dir/$file"), ["f"=>"1-2"]));
91 } elseif (!$invert ||
ctype_upper($file{0})) {
94 $name = ns($dir)."::".basename($file, ".md");
95 $html = "<p>".join(" ", cut(head("./$dir/$file"), ["f"=>"1-"]))."</p>";
98 fprintf(OUTPUT
, "<li><a href=\"/%s\">%s</a>%s</li>\n",
100 htmlspecialchars($name),
103 fprintf(OUTPUT
, "</ul>\n");
107 $pi = pathinfo($file);
108 if (ctype_upper($pi["filename"][0])) {
109 fprintf(OUTPUT
, "<h2>Methods:</h2>\n");
110 $el = $pi["dirname"] . "/" . $pi["filename"];
116 $r = fopen($file, "r");
117 $md = MarkdownDocument
::createFromStream($r);
119 $md->writeHtml(OUTPUT
);
123 // BS Markdown seeks around...
124 fseek(OUTPUT
, 0, SEEK_END
);
129 $r = new http\Env\Request
;
130 $u = new http\
Url($r->getRequestUrl());
131 $t = ["css"=>"text/css", "js"=>"application/javascript"];
136 $s = new http\Env\Response
;
137 $s->setHeader("Content-type", $t[pathinfo($u->path
, PATHINFO_EXTENSION
)]);
138 $s->setBody(new http\Message\
Body(fopen(basename($u->path
), "r")));
143 if (is_dir(".".$u->path
)) {
153 <meta charset
="utf-8">
154 <title
><?
=$u->path?
></title
>
155 <link rel
="stylesheet" href
="/index.css">
163 <script src
="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script
>
164 <script src
="/index.js"></script
>