Compare commits

..

10 Commits

Author SHA1 Message Date
quenousimporte 9d636c7b2c recover local git disaster 2024-03-06 08:33:44 +01:00
quenousimporte c18744c45f change: save before returning home 2024-02-20 16:23:37 +01:00
quenousimporte 6b676c7ba1 refactor: externalize css 2024-02-20 16:23:04 +01:00
quenousimporte c6f5979a87 add: pwa 2024-02-19 17:28:43 +01:00
quenousimporte f8b2ee3942 add: markdown preview 2024-02-19 12:20:20 +01:00
quenousimporte 2ce4cbeef6 fix: links 2024-02-19 10:42:49 +01:00
quenousimporte 9d7d804865 change: style 2024-02-19 10:42:30 +01:00
quenousimporte 62570915eb add: default header on new note 2024-02-19 10:26:10 +01:00
quenousimporte 6e85a1336b refactor
add: show tags list when searching tags
add: show preview when searching in content
change: delete previous upon rename
change: various improvments
2024-02-19 10:18:10 +01:00
quenousimporte ac6c01bd46 change: param empty by default 2024-02-16 18:08:18 +01:00
9 changed files with 1994 additions and 88 deletions

BIN
bbn192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
bbn512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

67
home.php Normal file
View File

@ -0,0 +1,67 @@
<form action="index.php" method="GET">
<div>
<input type="submit" name="home" value="home" accesskey="h">
<input type="submit" name="open" value="open">
<input type="submit" name="filter" value="filter">
<input type="submit" name="search" value="search">
<input type="submit" name="tags" value="tags">
<input type="submit" name="clip" value="clip">
<br>
<input autocomplete="off" class="title" name="param" value="<?php echo $param; ?>">
</div>
</form>
<div class="editor">
<?php
$files = glob($dir . '/*');
usort($files, function($a, $b)
{
return filemtime($b) - filemtime($a);
});
foreach($files as $path)
{
$tags = '';
$name = basename($path);
if (!str_ends_with($name, '.del') && ($action != 'filter' || str_contains(strtolower($name), strtolower($param))))
{
if ($action == 'search' || $action == 'tags')
{
$content = file_get_contents($path);
if (($action == 'search' && !str_contains(strtolower($content), strtolower($param))) ||
($action == 'tags' && !preg_match('/tags:.*' . $param . '/i', $content)))
{
continue;
}
}
echo '<div><a href=index.php?open=true&param=' . urlencode($name) . '>' . $name .'</a>';
if ($action == 'tags')
{
$tags = array();
$hastags = preg_match_all('/tags:(.*)/i', $content, $tags, PREG_SET_ORDER);
if ($hastags)
{
$tagslist = explode(',', $tags[0][1]);
echo '<span class="grey"> ';
foreach ($tagslist as $tag)
{
$tag = trim($tag);
echo('<a class="grey" href="index.php?tags=true&param=' . $tag . '">' . $tag . '</a> ');
}
echo '</span>';
}
}
else if ($action == 'search')
{
$pos = strpos(strtolower($content), strtolower($param));
echo '<span class="grey"> <b>' . $param . '</b>' . substr($content, $pos + strlen($param), 42) . '</span>';
}
echo'</div>';
}
}
?>
</div>

179
index.php
View File

@ -3,35 +3,17 @@
<head> <head>
<title> <title>
<?php <?php
if (isset($_GET['openaction'])) if (isset($_GET['action']) && $_GET['action'] == 'open')
{ {
echo $_GET['userdata']; echo $_GET['param'];
} }
?> ?>
</title> </title>
<link rel="manifest" href="manifest.json" />
<meta name="theme-color" content="white" /> <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 name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta charset="UTF-8"> <meta charset="UTF-8">
<style type="text/css"> <link rel="stylesheet" type="text/css" href="style.css">
body {
font-family: helvetica;
}
textarea {
width: 100%;
border: none;
outline: none;
font-family: inherit;
font-size: inherit;
}
.title {
width: 100%;
border: none;
outline: none;
font-family: inherit;
font-size: inherit;
font-weight: bold;
}
</style>
</head> </head>
<body> <body>
<?php <?php
@ -44,22 +26,75 @@
exit; exit;
} }
echo '<div><a accesskey="h" href="' . $root . '">home</a></div><br>';
$action = ''; $action = '';
if (isset($_POST['action'])) $action = $_POST['action'];
else if (isset($_GET['action'])) $action = $_GET['action'];
$param = ''; if (isset($_GET['open']))
if (isset($_GET['param'])) $param = $_GET['param']; {
$action = 'open';
}
else if (isset($_GET['filter']))
{
$action = 'filter';
}
else if (isset($_GET['search']))
{
$action = 'search';
}
else if (isset($_GET['tags']))
{
$action = 'tags';
}
else if (isset($_GET['clip']))
{
$action = 'clip';
}
else if (isset($_POST['save']))
{
$action = 'save';
}
else if (isset($_POST['delete']))
{
$action = 'delete';
}
else if (isset($_POST['home']))
{
$action = 'save';
}
else if(isset($_GET['home']))
{
$action = '';
}
else if (isset($_POST['preview']))
{
$action = 'preview';
}
$content = '';
if ($action == 'clip' && $_GET['param'])
{
$content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/clip');
file_put_contents($dir . '/clip', $content);
$_GET['param'] = '';
}
if ($action == 'save') if ($action == 'save')
{ {
$title = $_POST['title']; $title = $_POST['title'];
$content = $_POST['content']; $content = $_POST['content'];
file_put_contents($dir . '/' . $title, $content); file_put_contents($dir . '/' . $title, $content);
$previoustitle = $_POST['previoustitle'];
if ($title != $previoustitle)
{
rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del');
}
$action = 'open'; $action = 'open';
$param = $title; $_GET['param'] = $title;
if (isset($_POST['home']))
{
header('Location: index.php');
}
} }
else if ($action == 'delete') else if ($action == 'delete')
{ {
@ -67,79 +102,47 @@
rename($dir . '/' . $title, $dir . '/' . $title . '.del'); rename($dir . '/' . $title, $dir . '/' . $title . '.del');
} }
if ($action == 'open') if ($action == 'preview')
{ {
$title = $param; require 'libs/Parsedown.php';
$title = $_POST['title'];
$content = $_POST['content'];
$pos = 0;
if (str_starts_with($content, '---'))
{
$pos = strpos($content, '---', 3);
}
$Parsedown = new Parsedown();
$Parsedown->setBreaksEnabled(true);
echo $Parsedown->text('# ' . $title . "\r\n" . substr($content, $pos + 3));
}
else if ($action == 'open')
{
$title = $_GET['param'];
$now = date("Y-m-d H.i.s", time());
if (!$title)
{
$title = $now;
}
$content = '';
if (!file_exists($dir . '/' . $title)) if (!file_exists($dir . '/' . $title))
{ {
$content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n";
file_put_contents($dir . '/' . $title, $content); file_put_contents($dir . '/' . $title, $content);
} }
else else if (!$content)
{ {
$content = file_get_contents($dir . '/' . $title); $content = file_get_contents($dir . '/' . $title);
} }
require('note.php');
$nblines = max(20, substr_count($content, "\r\n") + 1) * 2;
echo '<form action="index.php" method="POST">
<div>
<select name="action">
<option value="save">save</option>
<option value="delete">delete</option>
</select>
<input type="submit" name="go" value="go" accesskey="s">
</div>
<br>
<div><input class="title" name="title" value="' . $title . '"></div><br>
<div>
<textarea rows="' . $nblines. '" autofocus name="content" spellcheck="false">' . $content . '</textarea>
</div>
</form>';
} }
else else
{ {
$defaulttitle = date("Y-m-d H.i.s", time()); if (isset($_GET['param']))
if ($param)
{ {
$defaulttitle = $param; $param = $_GET['param'];
} }
echo '<form action="index.php" method="GET"> require('home.php');
<input name="param" value="' . $defaulttitle . '">
<select name="action">
<option value="open">open</option>
<option value="filter">filter</option>
<option value="search">search</option>
</select>
<input accesskey="s" type="submit" value="go">
</form>';
echo '<br>';
$files = glob($dir . '/*');
usort($files, function($a, $b)
{
return filemtime($b) - filemtime($a);
});
foreach($files as $path)
{
$name = basename($path);
if (!str_ends_with($name, '.del')
&& ($action != 'filter' || str_contains($name, $param)))
{
if ($action == 'search')
{
$content = file_get_contents($path);
if (!str_contains($content, $param))
{
continue;
}
}
echo '<div><a href=index.php?action=open&param=' . urlencode($name) . '>' . $name .'</a></div>';
}
}
echo '<br>';
} }
?> ?>
</body> </body>

1712
libs/Parsedown.php Normal file

File diff suppressed because it is too large Load Diff

23
manifest.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "bbn",
"start_url": ".",
"display": "standalone",
"icons": [
{
"src": "favicon.ico",
"type": "image/vnd.microsoft.icon",
"sizes": "48x48"
},
{
"src": "bbn192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "bbn512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}

51
note.php Normal file
View File

@ -0,0 +1,51 @@
<?
$lines = substr_count($content, "\r\n") + 1;
$words = $lines + substr_count($content, " ");
$rows = max(20, $lines) * 2;
$length = strlen($content);
?>
<form action="index.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="delete" value="delete">
<input type="submit" name="preview" value="preview">
<br>
<input autocomplete="off" class="title" name="title" value="<? echo $title; ?>">
</div>
<div class="editor">
<textarea rows="<? echo $rows; ?>" autofocus name="content" spellcheck="false"><? echo $content; ?></textarea>
</div>
<input hidden name="previoustitle" value="<? echo $title; ?>">
</form>
<?
$links = array();
if (preg_match_all('/\[\[(.*)\]\]/', $content, $links, PREG_SET_ORDER))
{
echo '<div>Internal links:</div>';
foreach($links as $link)
{
echo '<div>
<a href="index.php?open=true&param=' . urlencode($link[1]) . '">' . $link[1] . '</a>
</div>';
}
echo '<br>';
}
$links = array();
if (preg_match_all('/https:(.*)[ \r]/', $content, $links, PREG_SET_ORDER))
{
echo '<div>External links:</div>';
foreach($links as $link)
{
echo '<div>
<a target="_blank" href="https:' . $link[1] . '">https:' . $link[1] . '</a>
</div>';
}
echo '<br>';
}
echo '<span class="grey">' . $title . ' - ' . $now . ' - ' . $length . 'c - ' . $words . 'w - ' . $lines . 'l </span>';
?>

50
style.css Normal file
View File

@ -0,0 +1,50 @@
body {
color: rgb(55, 53, 47);
font-family: helvetica;
line-height: 24px;
font-size: 16px;
margin-left: 7%;
margin-right: 7%;
margin-top: 10px;
}
textarea {
width: 100%;
border: none;
outline: none;
font-family: inherit;
font-size: inherit;
line-height: inherit;
color: inherit;
}
.grey {
color: lightgrey;
}
a {
color: inherit;
}
.editor {
margin-top: 10px;
}
.title {
font: inherit;
border: none;
outline: none;
font-weight: bold;
margin-top: 10px;
color: inherit;
}
form input[type="submit"] {
background: none;
border: none;
color: lightgrey;
font: inherit;
text-decoration: underline;
cursor: pointer;
padding: 0;
border: 0;
}