404: convert error pages to php code
[minimedit.git] / edit.php
index 657c2790e570a841011790204097be7170ab2e4d..57906963d9c1db85338d1c8782b66ef7d81a434e 100644 (file)
--- a/edit.php
+++ b/edit.php
@@ -7,19 +7,28 @@ function abort($status, $body) {
 
 if (!$_POST)
        abort('405 post error', "niets te doen");
-if (!isset($_POST['page']))
+if (!isset($_SERVER['PATH_INFO']) or strlen($_SERVER['PATH_INFO']) <= 1)
        abort('409 input error', "geen bestand aangeleverd");
 
-$filename = preg_replace('/(?:\.html)?$/', '.html', ltrim($_POST['page'], '/'), 1);
+$filename = preg_replace('/(?:\.html)?$/', '.html', ltrim($_SERVER['PATH_INFO'], '/'), 1);
 if (file_exists($filename) and !is_writable($filename))
        abort('403 input error', "ongeldige bestandsnaam: $filename");
 
-$prepend = '<!--#include virtual="/common.html" -->'."\n\n";
-$append  = "\n".'<!--#include virtual="/footer.html" -->'."\n";
+if (!isset($_POST['body']))
+       abort('409 input error', "geen inhoud aangeleverd");
+
 $upload = $_POST['body'];
 
-if (!$upload)
-       abort('409 input error', "leeg bestand aangeleverd");
+if (!strlen($upload)) {
+       if (file_exists($filename) and !unlink($filename))
+               abort('500 delete error', "fout bij het verwijderen van $filename");
+
+       print "Bestand verwijderd";
+       exit;
+}
+
+$prepend = '<!--#include virtual="/head.inc.html" -->'."\n\n";
+$append  = "\n".'<!--#include virtual="/foot.inc.html" -->'."\n";
 
 if (!file_put_contents($filename, $prepend . $upload . $append))
        abort('500 save error', "fout bij schrijven van $filename");