From 0eccccfab33bbad8d5731700c1ed959debe98bbd Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 23 Jul 2025 18:45:43 +0200 Subject: display blob based on mime type --- index.php | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 148 insertions(+), 30 deletions(-) diff --git a/index.php b/index.php index d45341a..1dddf72 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,11 @@ urlencode($value), + explode("/", $url) + ) + ); +} + + +## +# Template +## + + /** * Template root */ @@ -180,12 +257,17 @@ function template_root(string $content, array $meta = []): string <?php echo $meta["title"]; ?> + @@ -198,6 +280,34 @@ function template_root(string $content, array $meta = []): string } +/** + * build breadcrumbs + */ +function breadcrumbs(string $root, string $path): string +{ + ob_start(); + + $breadcrumbs = explode("/", trim(str_replace($root, "", $path), "/")); + echo "root"; + $crumb_parts = ""; + foreach ($breadcrumbs as $idx => $crumb) { + $crumb_parts .= "/$crumb"; + if ($idx < count($breadcrumbs) - 1) { + echo "/$crumb"; + } else { + echo "/$crumb"; + } + } + + return ob_get_clean(); +} + + +## +# Output +## + + $projects_path = realpath($_ENV["PHPGIT_PROJECTS_PATH"]); $url = parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); @@ -251,7 +361,7 @@ if ($url["path"] == "/") { ?>root"; - $crumb_parts = ""; - foreach ($breadcrumbs as $idx => $crumb) { - $crumb_parts .= "/$crumb"; - echo "/$crumb"; - } + echo breadcrumbs("/$project/tree", "/$project/tree/$file_path"); // build list ?> @@ -306,7 +410,7 @@ elseif (preg_match("#(.*)/tree/?(.*)#", $url["path"], $matches)) { ">">">">root"; - $crumb_parts = ""; - foreach ($breadcrumbs as $idx => $crumb) { - $crumb_parts .= "/$crumb"; - if ($idx != count($breadcrumbs) - 1) { - echo "/$crumb"; - } else { - echo "/$crumb"; - } - } + echo breadcrumbs("/$project/tree", "/$project/tree/$file_path"); + + // get file info + $info = get_file_info("$projects_path/$project", $file_path); + $contents = read_object_file("$projects_path/$project", $info["name"]); + $mime_type = (new finfo(FILEINFO_MIME_TYPE))->buffer($contents); + + $memory_limit = (int)ini_get("memory_limit") * 1024 ** ["k" => 1, "m" => 2, "g" => 3][strtolower(ini_get("memory_limit")[-1])]; ?> -
-
+
+ Mime Type: +
+ + + + +