(.*?)<\/title>/i', $html, $matches); return isset($matches[1]) ? $matches[1] : $url;*/ return $url; } 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); } // main // handle save actions if (count($_POST) > 0) { $title = $_POST['title']; $content = $_POST['content']; if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['download']) || isset($_POST['preview'])) { savenote($title, $content); $previoustitle = $_POST['previoustitle']; if ($title != $previoustitle) { rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del'); removefromindex($previoustitle); } if (isset($_POST['download'])) { downloadnote($dir . '/' . $title . '.md'); exit; } else if (isset($_POST['home'])) { header("Location: index.php"); exit; } else if (isset($_POST['preview'])) { header("Location: note.php?preview=true&title=" . $title); exit; } else { header("Location: note.php?title=" . $title); exit; } } else if (isset($_POST['delete'])) { rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del'); removefromindex($title); header("Location: index.php"); exit; } } $title = ''; $content = false; if (isset($_GET['new'])) { $now = date("Y-m-d H.i.s", time()); $title = $now; $content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n"; savenote($title, $content); } else if (isset($_GET['title'])) { $title = $_GET['title']; $content = file_get_contents($dir . '/' . $title . '.md'); } if (!$content) { http_response_code(404); die(); } clearstatcache(); $lastchanged = filemtime($dir . '/' . $title . '.md'); $lines = substr_count($content, "\r\n"); $words = substr_count($content, " ") + $lines; $chars = strlen($content); $rows = max(20, $lines) * 2; ?> <?php echo $title; ?>
>
>
back