-if (!file_put_contents($filename, $prepend . $upload . $append))
- abort('500 save error', "fout bij schrijven van $filename");
+ abort("Bestand verwijderd");
+}
+
+if (!file_exists(dirname($filename)) and !mkdir(dirname($filename), 0777, TRUE))
+ abort("fout bij aanmaken van map voor $filename", '500 save error');
+
+if (!file_put_contents($filename, $upload))
+ abort("fout bij schrijven van $filename", '500 save error');
+
+if (is_writable('../.git')) {
+ $gitmsg = preg_replace('/\.html$/', '', $filename).": edit from {$_SERVER['REMOTE_ADDR']}";
+ $gitcmd = 'git';
+ $gitcmd .= ' -c user.name='.escapeshellarg($User['name']);
+ $gitcmd .= ' -c user.email='.escapeshellarg("{$User['name']}@lijtweg.nl");
+ $gitcmd .= ' commit -q';
+ $gitcmd .= ' -m '.escapeshellarg($gitmsg);
+ $gitcmd .= ' -- '.escapeshellarg($filename);
+ exec("$gitcmd 2>&1", $gitlog, $gitstatus);
+ if ($gitstatus) {
+ trigger_error("git commit failure $gitstatus: ".implode("\n", $gitlog), E_USER_WARNING);
+ }
+}