2024-10-07 16:06:35 +02:00
|
|
|
<?php
|
|
|
|
require('common.php');
|
|
|
|
|
2024-10-15 12:05:46 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-10-07 16:06:35 +02:00
|
|
|
// handle save actions
|
2024-10-15 11:38:15 +02:00
|
|
|
if (count($_POST) > 0)
|
2024-10-07 16:06:35 +02:00
|
|
|
{
|
2024-10-15 11:38:15 +02:00
|
|
|
$title = $_POST['title'];
|
|
|
|
$content = $_POST['content'];
|
|
|
|
if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['download']) || isset($_POST['preview']))
|
2024-10-07 16:06:35 +02:00
|
|
|
{
|
2024-10-15 11:38:15 +02:00
|
|
|
savenote($title, $content);
|
2024-10-07 16:06:35 +02:00
|
|
|
|
2024-10-15 11:38:15 +02:00
|
|
|
$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;
|
|
|
|
}
|
2024-10-07 16:06:35 +02:00
|
|
|
}
|
2024-10-15 11:38:15 +02:00
|
|
|
else if (isset($_POST['delete']))
|
2024-10-07 16:06:35 +02:00
|
|
|
{
|
2024-10-15 11:38:15 +02:00
|
|
|
rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del');
|
|
|
|
removefromindex($title);
|
|
|
|
|
2024-10-07 16:06:35 +02:00
|
|
|
header("Location: index.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// main
|
|
|
|
$title = '';
|
2024-10-07 16:45:49 +02:00
|
|
|
$content = false;
|
2024-10-07 16:06:35 +02:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2024-10-07 16:45:49 +02:00
|
|
|
if (!$content)
|
|
|
|
{
|
|
|
|
http_response_code(404);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2024-10-07 16:06:35 +02:00
|
|
|
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;
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2024-10-08 17:52:02 +02:00
|
|
|
<title><?php echo $title; ?></title>
|
2024-10-07 16:06:35 +02:00
|
|
|
<link rel="manifest" href="manifest.json" />
|
|
|
|
<meta name="theme-color" content="white" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<link rel="stylesheet" type="text/css" href="style.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
2024-10-07 17:57:18 +02:00
|
|
|
<!-- editor -->
|
2024-10-08 17:52:02 +02:00
|
|
|
<div <?php if(isset($_GET['preview'])) echo 'hidden'; ?>>
|
2024-10-07 17:57:18 +02:00
|
|
|
<form action="note.php" method="POST">
|
|
|
|
<div>
|
|
|
|
<input type="submit" name="home" value="home" accesskey="h">
|
|
|
|
<input type="submit" name="save" value="save" accesskey="s">
|
|
|
|
<input type="submit" name="preview" value="preview" accesskey="p">
|
|
|
|
<input type="submit" name="download" value="download" accesskey="d">
|
|
|
|
<input type="submit" name="delete" value="delete">
|
2024-10-08 17:52:02 +02:00
|
|
|
<input hidden name="lastchanged" value="<?php echo $lastchanged; ?>">
|
|
|
|
<div><input autocomplete="off" class="title" name="title" value="<?php echo $title; ?>"></div>
|
2024-10-07 17:57:18 +02:00
|
|
|
</div>
|
|
|
|
<div class="editor">
|
2024-10-08 17:52:02 +02:00
|
|
|
<textarea rows="<?php echo $rows; ?>" autofocus name="content" spellcheck="false"><?php echo $content; ?></textarea>
|
2024-10-07 17:57:18 +02:00
|
|
|
</div>
|
2024-10-08 17:52:02 +02:00
|
|
|
<input hidden name="previoustitle" value="<?php echo $title; ?>">
|
2024-10-10 10:22:32 +02:00
|
|
|
<div class="grey">
|
|
|
|
<?php echo '' . $lines . ' ' . $words . ' ' . $chars . ' ' . $title . '.md ' . date('Y-m-d H.i.s', $lastchanged); ?>
|
|
|
|
</div>
|
|
|
|
<?php echo linksdiv($content); ?>
|
2024-10-07 17:57:18 +02:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- preview -->
|
2024-10-08 17:52:02 +02:00
|
|
|
<div <?php if(!isset($_GET['preview'])) echo 'hidden'; ?>>
|
|
|
|
<div><a class="grey" href="note.php?title=<?php echo $title; ?>">back</a></div>
|
|
|
|
<?php
|
2024-10-07 16:06:35 +02:00
|
|
|
echo computepreview($title, $content);
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|