diff --git a/index.php b/index.php index c518315..2dce2a0 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,7 @@ { return filemtime($b) - filemtime($a); }); - $_SESSION['index'] = $files; + $_SESSION['index'] = array_map(fn($value): string => str_replace('.md', '', $value), $files); } function removefromindex($title) @@ -50,16 +50,16 @@ $previous = $_POST['lastchanged']; if (!isset($_GET['clip']) && (int)$lastchanged > (int)$previous) { - $tempcontent = file_get_contents($path); + $tempcontent = file_get_contents($path . '.md'); if ($tempcontent != $content) { $temptitle = $title . '_' . $lastchanged; - file_put_contents($dir . '/' . $temptitle, $tempcontent); + file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); array_unshift($_SESSION['index'], $dir . '/' . $temptitle); echo '
Conflict detected. See backup: ' . $temptitle . '
'; } } - file_put_contents($path, $content); + file_put_contents($path . '.md', $content); removefromindex($title); array_unshift($_SESSION['index'], $path); } @@ -95,7 +95,7 @@ if (isset($_GET['clip']) && $_GET['param']) { - $content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo'); + $content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo.md'); savenote('todo', $content); $_GET['param'] = ''; } @@ -108,7 +108,7 @@ $previoustitle = $_POST['previoustitle']; if ($title != $previoustitle) { - rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del'); + rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del'); removefromindex($previoustitle); } @@ -120,7 +120,7 @@ else if (isset($_POST['delete'])) { $title = $_POST['title']; - rename($dir . '/' . $title, $dir . '/' . $title . '.del'); + rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del'); removefromindex($title); } else if (isset($_POST['preview'])) @@ -152,18 +152,18 @@ $title = $now; } - if (!file_exists($dir . '/' . $title)) + if (!file_exists($dir . '/' . $title . '.md')) { $content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n"; savenote($title, $content); } else if (!$content) { - $content = file_get_contents($dir . '/' . $title); + $content = file_get_contents($dir . '/' . $title . '.md'); } clearstatcache(); - $lastchanged = filemtime($dir . '/' . $title); + $lastchanged = filemtime($dir . '/' . $title . '.md'); $lines = substr_count($content, "\r\n"); $words = substr_count($content, " ") + $lines; $chars = strlen($content); @@ -191,7 +191,7 @@ { if (($_GET['param'] && isset($_GET['search'])) || isset($_GET['tags'])) { - $content = file_get_contents($path); + $content = file_get_contents($path . '.md'); if ((isset($_GET['search']) && !str_contains(strtolower($content), strtolower($param)) && !str_contains(strtolower($name), strtolower($param))) || (isset($_GET['tags']) && !preg_match('/tags:.*' . $param . '/i', $content)))