From d017568a77d677e449e66d689450532a760d6f11 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 13 Nov 2023 13:37:26 +0100 Subject: initial commit --- index.php | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 index.php (limited to 'index.php') diff --git a/index.php b/index.php new file mode 100644 index 0000000..23c314f --- /dev/null +++ b/index.php @@ -0,0 +1,83 @@ +request("$url[path]$url[query]"); + +ob_start(); +$mime = explode(';', $response->getMeta())[0]; +if (strpos($mime, 'text/gemini') === 0) { + $parser = new Gemtext($response->getBody()); + $lines = $parser->parse(); + + $wasListItem = false; + $currentListItems = []; + foreach ($lines as $line) { + if ($wasListItem && $line['type'] !== 'listitem') { + echo ""; + $wasListItem = false; + $currentListItems = []; + } + + if ($line['type'] === 'preformatted_on') { + echo "
$line[alt]
";
+    }
+    else if ($line['type'] === 'preformatted') {
+      echo htmlentities($line['raw']);
+    }
+    else if ($line['type'] === 'preformatted_off') {
+      echo "
"; + } + else if ($line['type'] === 'heading') { + echo "$line[text]"; + } + else if ($line['type'] === 'listitem') { + $currentListItems[] = $line; + $wasListItem = true; + } + else if ($line['type'] === 'quote') { + echo "
$line[text]
"; + } + else if ($line['type'] === 'link') { + $line['link'] = str_replace(["gemini://$geminiHost", $geminiHost], "https://$geminiHost", $line['link']); + $line['text'] = $line['text'] ?: $line['link']; + echo "$line[text]"; + } + else if ($line['type'] === 'text') { + echo "

$line[text]

"; + } + } +} + +else if (strpos($mime, 'image') === 0) { + echo "getBody()) . "\">"; +} + +echo "
"; +echo "Proxied from gemini://$geminiHost$url[path]$url[query]"; +$content = ob_get_clean(); + +?> + + + + + + + + -- cgit v1.2.3