Contents of this page: \n";
$img_extensions = array("png", "apng", "avif", "bmp", "ico", "tif", "tiff", "jpg", "jpeg", "gif", "svg", "webp");
$aud_extensions = array("mp3", "wav", "ogg");
$vid_extensions = array("mp4", "ogg", "webm");
// == MAIN LOOP
while(!feof($file)) {
$line_no += 1;
$line_untrimmed = fgets($file);
$line = trim($line_untrimmed);
$line_len = strlen($line);
// == POLYGLOT gemtext/pdf
// If this is gemtext/pdf polyglot .gmi skip the first four lines; this only works with files generated by gemdoc from https://github.com/seifferth/gemdoc
if($line_no == 1) {
if ($line == "%PDF-1.7") {
$is_pdf = true;
$body .= "\n";
continue;
} else { // ToDo: rework this: what if the first line of the file begins ">". "=>", "*", or "```"?
$lntype = $line[0] == "#" ? "h1" : "p"; // index.gmi uses "👴 jdcard" as the
level header, in other pages it is a plain line
$body .= "\n";
$title = htmlentities(substr($line, 2, $line_len-2));
$body .= " <$lntype>".htmlentities($lntype == "h1" ? substr($line, 2, $line_len-2) : $line)."$lntype>\n"; // index.gmi
continue;
}
}
// skip past the pdf data that we don't want to see
if($is_pdf == true and $line_no <5) {
continue;
}
// If this is a gemtext/pdf polyglot file, create a link to view it as pdf, then stop processing the file at the end of the gemtext portion
if($is_pdf == true and $line == "endstream") {
$pdf_file = str_replace(".gmi", ".pdf", $fname); // create name for pdf symlink
$pdf_file = substr($pdf_file, 1); // trim the leading "/" path character
$fname = preg_replace("/\/.*\//", "", $fname); // strip path, leave file-name
$fname = preg_replace("/\/?/", "", $fname); // previous line sometimes left an inital "/"
symlink($fname, $pdf_file); // create symlink to this file with a .pdf extension
$pdf_file = preg_replace("/^.*\//", "", $pdf_file); // strip path, leave file-name
$body .= " \n