117 lines
3.1 KiB
PHP
117 lines
3.1 KiB
PHP
<?php
|
|
require('common.php');
|
|
|
|
// handle save actions
|
|
$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=1&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;
|
|
}
|
|
|
|
// main
|
|
|
|
$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;
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title><? echo $title; ?></title>
|
|
<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>
|
|
<form action="note.php" method="POST" <? if(isset($_GET['preview'])) echo 'hidden'; ?>>
|
|
<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" formtarget="_bbn_preview">
|
|
<input type="submit" name="download" value="download" accesskey="d">
|
|
<input type="submit" name="delete" value="delete">
|
|
<input hidden name="lastchanged" value="<? echo $lastchanged; ?>">
|
|
<div><input autocomplete="off" class="title" name="title" value="<? echo $title; ?>"></div>
|
|
</div>
|
|
<div class="editor">
|
|
<textarea rows="<? echo $rows; ?>" autofocus name="content" spellcheck="false"><? echo $content; ?></textarea>
|
|
</div>
|
|
<input hidden name="previoustitle" value="<? echo $title; ?>">
|
|
<?php
|
|
echo '<div class="grey">' . $lines . ' ' . $words . ' ' . $chars . ' ' . $title . '.md</div>';
|
|
echo linksdiv($content);
|
|
?>
|
|
</form>
|
|
<div <? if(!isset($_GET['preview'])) echo 'hidden'; ?>>
|
|
<?
|
|
echo computepreview($title, $content);
|
|
?>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|