diff --git a/common.php b/common.php index be007e8..6fd248c 100644 --- a/common.php +++ b/common.php @@ -3,63 +3,6 @@ date_default_timezone_set('Europe/Paris'); require 'settings.php'; - function cleanstring($string) - { - return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', strtolower($string)); - } - - function downloadall() - { - $zip = new ZipArchive(); - $zip_name = 'bbn.zip'; - $zip->open($zip_name, ZipArchive::CREATE); - foreach($_SESSION['index'] as $path) - { - if (!str_ends_with($path, '.del')) - { - $path = $path . '.md'; - if (file_exists($path)) - { - $zip->addFile($path, basename($path)); - } - } - } - $zip->close(); - - header('Content-disposition: attachment; filename=' . $zip_name); - header('Content-type: application/zip'); - readfile($zip_name); - - unlink($zip_name); - } - - function savenote($title, $content) - { - global $dir; - $path = $dir . '/' . $title; - $filename = $path . '.md'; - - if (file_exists($filename)) - { - $lastchanged = filemtime($filename); - $previous = $_POST['lastchanged']; - if ((int)$lastchanged > (int)$previous) - { - $tempcontent = file_get_contents($filename); - if ($tempcontent != $content) - { - $temptitle = $title . '_conflict_' . $lastchanged; - file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); - array_unshift($_SESSION['index'], $dir . '/' . $temptitle); - } - } - } - - file_put_contents($filename, $content); - removefromindex($title); - array_unshift($_SESSION['index'], $path); - } - function removefromindex($title) { global $dir; diff --git a/index.php b/index.php index 002308e..d8a512b 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,36 @@ open($zip_name, ZipArchive::CREATE); + foreach($_SESSION['index'] as $path) + { + if (!str_ends_with($path, '.del')) + { + $path = $path . '.md'; + if (file_exists($path)) + { + $zip->addFile($path, basename($path)); + } + } + } + $zip->close(); + + header('Content-disposition: attachment; filename=' . $zip_name); + header('Content-type: application/zip'); + readfile($zip_name); + + unlink($zip_name); + } + if (isset($_GET['download'])) { downloadall(); diff --git a/note.php b/note.php index 938af67..50662e5 100644 --- a/note.php +++ b/note.php @@ -1,6 +1,33 @@ (int)$previous) + { + $tempcontent = file_get_contents($filename); + if ($tempcontent != $content) + { + $temptitle = $title . '_conflict_' . $lastchanged; + file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); + array_unshift($_SESSION['index'], $dir . '/' . $temptitle); + } + } + } + + file_put_contents($filename, $content); + removefromindex($title); + array_unshift($_SESSION['index'], $path); + } + // handle save actions if (count($_POST) > 0) {