nieuws: port excelsior toc and year filtering
[minimedit.git] / edit.php
index ca9639c3da44f2049cf14bb2318ec1be0b919b34..25f9f1be5454506c137cdc85a698357380810159 100644 (file)
--- a/edit.php
+++ b/edit.php
@@ -1,13 +1,7 @@
 <?php
 ob_clean();
 
-function abort($body, $status = NULL) {
-       if ($status) header("HTTP/1.1 $status");
-       print "$body\n";
-       exit;
-}
-
-if (!@$User['admin'])
+if (empty($User['admin']))
        abort("geen beheersrechten", '401 unauthorised');
 
 if ($_FILES) {
@@ -54,11 +48,25 @@ if (!strlen($upload)) {
        abort("Bestand verwijderd");
 }
 
-if (!file_exists(dirname($filename)) and !mkdir(dirname($filename)))
+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);
+       }
+}
+
 abort("Bestand opgeslagen");