X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=index.php;h=7ae8e478efa5eac7432ab39c0d68dd2e4b524cd4;hb=f60062deb36b708d1b28b0e264957562b06964f3;hp=b2109846572cbf8c414f5117b29a4a39ddc5c8ba;hpb=333f749f9ae65fecd6b52b06fde3dceda1579470;p=mdref%2Fmdref diff --git a/index.php b/index.php index b210984..7ae8e47 100644 --- a/index.php +++ b/index.php @@ -54,15 +54,33 @@ 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, "/."))); } @@ -73,16 +91,17 @@ function urlpath($dir, $file) { function ls($dir) { $dir = rtrim(is_dir($dir) ? $dir : dirname($dir) ."/". basename($dir, ".md"), "/"); printf("\n"); @@ -118,17 +142,45 @@ function ls($dir) { function ml($file) { $pi = pathinfo($file); - if (ctype_upper($pi["filename"][0])) { - printf("

Methods:

\n"); + if (!isset($pi["extension"])) { + return; + } + if ($pi["extension"] !== "md") { + return; + } + if (!ctype_upper($pi["filename"][0])) { + // namespaced functions $dir = $pi["dirname"] . "/" . $pi["filename"]; if (is_dir($dir)) { + printf("

Functions:

\n"); printf("\n"); + } + } else { + // methods + $dir = $pi["dirname"] . "/" . $pi["filename"]; + if (is_dir($dir)) { + printf("

Methods:

\n"); + printf("