getMessage();
exit(1);
}
set_exception_handler('exception_handler');
define("EDITABLE_EXTENSIONS", ["gmi", "md"]);
// patch up PATH_INFO in case it is unset
if(!array_key_exists('PATH_INFO', $_SERVER) || $_SERVER['PATH_INFO'] == "") {
$_SERVER['PATH_INFO'] = "/";
}
if(substr($_SERVER['PATH_INFO'],-1,1) === "/") {
$_SERVER['PATH_INFO'] .= "index.md";
}
?>
" class="link--editable">
>
0): ?>
$value): ?>
$max_width) {
$img = imagescale($img, $max_width);
}
// replace extension with new format
$public_path = dirname($_SERVER['PATH_INFO'])."/".basename($new_basename, ".".$extension).".".$dest_format;
$_dest = fopen("..".$public_path, "x");
if(!$_dest) {
http_response_code(400);
header('Content-Type: text/plain');
echo 'File already exists in this directory. Delete it to overwrite.';
exit(1);
}
switch($dest_format) {
case "png":
imagepng($img, $_dest, intval(getenv('IMG_RESIZE_PNG_COMPRESSION') ?: -1));
break;
case "jpg":
case "jpeg":
imagejpeg($img, $_dest, intval(getenv('IMG_RESIZE_JPEG_QUALITY') ?: -1));
break;
case "webp":
imagewebp($img, $_dest, intval(getenv('IMG_RESIZE_WEBP_QUALITY') ?: -1));
break;
case "avif":
imageavif($img, $_dest, intval(getenv('IMG_RESIZE_AVIF_QUALITY') ?: -1), intval(getenv('IMG_RESIZE_AVIF_SPEED') ?: -1));
break;
case "gif":
imagegif($img, $_dest);
break;
case "bmp":
imagewbmp($img, $_dest);
break;
default:
http_response_code(400);
header('Content-Type: text/plain');
echo "Unknown image format: ".$dest_format;
exit(1);
}
fclose($_dest);
} else {
$public_path = dirname($_SERVER['PATH_INFO'])."/".$new_basename;
$_dest = fopen("..".$public_path, "x");
if(!$_dest) {
http_response_code(400);
header('Content-Type: text/plain');
echo 'File already exists in this directory. Delete it to overwrite.';
exit(1);
}
$_src = fopen("php://input", "r");
stream_copy_to_stream($_src, $_dest);
fclose($_dest);
fclose($_src);
}
$base = dirname($public_path);
if(substr($base,-1,1) !== "/") {
$base .= "/";
}
http_response_code(200);
header('Content-Type: text/html');
render_file(basename($public_path), $base);
exit(0);
} elseif($_SERVER['REQUEST_METHOD'] === 'DELETE') {
if($_SERVER['PATH_INFO'] === "" || $_SERVER['PATH_INFO'] === "." || $_SERVER['PATH_INFO'] === "/") {
http_response_code(400);
exit(1);
}
if(is_dir("..".$_SERVER['PATH_INFO'])) {
delTree("..".$_SERVER['PATH_INFO']);
} else {
unlink("..".$_SERVER['PATH_INFO']);
}
http_response_code(204);
exit(0);
} elseif($_SERVER['REQUEST_METHOD'] === 'PATCH') {
mkdir("..".$_SERVER['PATH_INFO']);
http_response_code(200);
header('Content-Type: text/html');
$dir = dirname($_SERVER['PATH_INFO']);
render_directory(basename($_SERVER['PATH_INFO']), $dir, count(explode("/", $dir)), array());
exit(0);
}
?>
Lichen
# heading
## subhead
### sub-subhead
* bulleted
* list
* items
=> https://abc.xyz external link
=> /page.gmi internal link
=> /image.jpg image alt
```
preformatted```