2024-02-13 22:57:28 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
2024-02-14 14:23:25 +01:00
|
|
|
<head>
|
2024-03-08 13:47:29 +01:00
|
|
|
<title>bbn</title>
|
2024-02-19 17:28:43 +01:00
|
|
|
<link rel="manifest" href="manifest.json" />
|
2024-02-14 18:22:26 +01:00
|
|
|
<meta name="theme-color" content="white" />
|
2024-02-14 14:23:25 +01:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
|
|
|
<meta charset="UTF-8">
|
2024-02-20 16:23:04 +01:00
|
|
|
<link rel="stylesheet" type="text/css" href="style.css">
|
2024-02-14 14:23:25 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php
|
2024-03-15 15:11:26 +01:00
|
|
|
error_reporting(E_ALL);
|
2024-02-14 14:23:25 +01:00
|
|
|
require 'settings.php';
|
2024-02-13 23:38:09 +01:00
|
|
|
|
2024-02-14 14:23:25 +01:00
|
|
|
if ($password && (!isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_PW'] != $password)) {
|
|
|
|
header('WWW-Authenticate: Basic realm="bbn"');
|
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
2024-03-15 15:11:26 +01:00
|
|
|
echo '<p>Access denied.</p></body></html>';
|
2024-02-14 14:23:25 +01:00
|
|
|
exit;
|
|
|
|
}
|
2024-02-13 23:38:09 +01:00
|
|
|
|
2024-03-07 10:02:11 +01:00
|
|
|
session_start();
|
|
|
|
|
2024-03-18 17:22:22 +01:00
|
|
|
if (!isset($_SESSION['index']) || isset($_GET['reindex']) || empty($_SESSION['index']))
|
|
|
|
{
|
2024-03-19 17:37:54 +01:00
|
|
|
echo '<div class="grey">reindexed</div>';
|
2024-03-18 17:22:22 +01:00
|
|
|
$files = glob($dir . '/*');
|
|
|
|
usort($files, function($a, $b)
|
|
|
|
{
|
|
|
|
return filemtime($b) - filemtime($a);
|
|
|
|
});
|
|
|
|
$_SESSION['index'] = $files;
|
|
|
|
}
|
|
|
|
|
2024-03-07 12:48:31 +01:00
|
|
|
function removefromindex($title)
|
2024-03-07 10:02:11 +01:00
|
|
|
{
|
|
|
|
global $dir;
|
|
|
|
$key = array_search($dir . '/' . $title, $_SESSION['index']);
|
2024-03-07 12:48:31 +01:00
|
|
|
if ($key !== FALSE)
|
2024-03-07 10:02:11 +01:00
|
|
|
{
|
|
|
|
array_splice($_SESSION['index'], $key, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-07 12:48:31 +01:00
|
|
|
function savenote($title, $content)
|
2024-03-06 08:33:44 +01:00
|
|
|
{
|
2024-03-07 12:48:31 +01:00
|
|
|
global $dir;
|
2024-03-15 15:11:51 +01:00
|
|
|
$path = $dir . '/' . $title;
|
|
|
|
$lastchanged = filemtime($path);
|
|
|
|
$previous = $_POST['lastchanged'];
|
|
|
|
if ( (int)$lastchanged > (int)$previous)
|
|
|
|
{
|
|
|
|
$tempcontent = file_get_contents($path);
|
|
|
|
if ($tempcontent != $content)
|
|
|
|
{
|
|
|
|
$temptitle = $title . '_' . $lastchanged;
|
|
|
|
file_put_contents($dir . '/' . $temptitle, $tempcontent);
|
|
|
|
array_unshift($_SESSION['index'], $dir . '/' . $temptitle);
|
|
|
|
echo '<div class="grey">Conflict detected. See backup: ' . $temptitle . '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file_put_contents($path, $content);
|
2024-03-07 12:48:31 +01:00
|
|
|
removefromindex($title);
|
2024-03-15 15:11:51 +01:00
|
|
|
array_unshift($_SESSION['index'], $path);
|
2024-03-06 08:33:44 +01:00
|
|
|
}
|
2024-02-20 16:23:37 +01:00
|
|
|
|
2024-03-12 12:12:13 +01:00
|
|
|
function linksdiv($content)
|
|
|
|
{
|
|
|
|
$divcontent = '<div class="grey">';
|
|
|
|
$links = array();
|
|
|
|
if (preg_match_all('/\[\[(.*)\]\]/', $content, $links, PREG_SET_ORDER))
|
|
|
|
{
|
|
|
|
foreach($links as $link)
|
|
|
|
{
|
|
|
|
$divcontent .= '<div>
|
|
|
|
<a href="index.php?open=true¶m=' . urlencode($link[1]) . '">' . $link[1] . '</a>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$links = array();
|
|
|
|
if (preg_match_all('/https:(.*)\b/', $content, $links, PREG_SET_ORDER))
|
|
|
|
{
|
|
|
|
foreach($links as $link)
|
|
|
|
{
|
|
|
|
$divcontent .= '<div>
|
|
|
|
<a target="_blank" href="https:' . $link[1] . '">https:' . $link[1] . '</a>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$divcontent .= '</div>';
|
|
|
|
return $divcontent;
|
|
|
|
}
|
|
|
|
|
2024-03-07 12:48:31 +01:00
|
|
|
$nextpage = 'home';
|
|
|
|
|
|
|
|
if (isset($_GET['clip']) && $_GET['param'])
|
2024-03-06 08:33:44 +01:00
|
|
|
{
|
2024-03-06 14:44:52 +01:00
|
|
|
$content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo');
|
2024-03-07 10:02:11 +01:00
|
|
|
savenote('todo', $content);
|
2024-03-06 08:33:44 +01:00
|
|
|
$_GET['param'] = '';
|
|
|
|
}
|
2024-03-12 14:09:49 +01:00
|
|
|
else if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['links']) || isset($_POST['stats']))
|
2024-02-14 14:23:25 +01:00
|
|
|
{
|
|
|
|
$title = $_POST['title'];
|
|
|
|
$content = $_POST['content'];
|
2024-03-07 10:02:11 +01:00
|
|
|
savenote($title, $content);
|
2024-02-19 10:18:10 +01:00
|
|
|
|
|
|
|
$previoustitle = $_POST['previoustitle'];
|
|
|
|
if ($title != $previoustitle)
|
|
|
|
{
|
|
|
|
rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del');
|
2024-03-07 12:48:31 +01:00
|
|
|
removefromindex($previoustitle);
|
2024-02-19 10:18:10 +01:00
|
|
|
}
|
|
|
|
|
2024-03-07 12:48:31 +01:00
|
|
|
if (!isset($_POST['home']))
|
2024-02-20 16:23:37 +01:00
|
|
|
{
|
2024-03-07 12:48:31 +01:00
|
|
|
$nextpage = 'note';
|
2024-02-20 16:23:37 +01:00
|
|
|
}
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
2024-03-07 12:48:31 +01:00
|
|
|
else if (isset($_POST['delete']))
|
2024-02-14 14:23:25 +01:00
|
|
|
{
|
|
|
|
$title = $_POST['title'];
|
|
|
|
rename($dir . '/' . $title, $dir . '/' . $title . '.del');
|
2024-03-07 12:48:31 +01:00
|
|
|
removefromindex($title);
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
2024-03-07 12:48:31 +01:00
|
|
|
else if (isset($_POST['preview']))
|
2024-02-19 12:20:20 +01:00
|
|
|
{
|
2024-02-20 16:23:37 +01:00
|
|
|
require 'libs/Parsedown.php';
|
2024-02-19 12:20:20 +01:00
|
|
|
$title = $_POST['title'];
|
|
|
|
$content = $_POST['content'];
|
2024-03-06 08:33:44 +01:00
|
|
|
$pos = 0;
|
|
|
|
if (str_starts_with($content, '---'))
|
|
|
|
{
|
2024-03-08 16:45:50 +01:00
|
|
|
$pos = strpos($content, '---', 3) + 3;
|
2024-03-06 08:33:44 +01:00
|
|
|
}
|
2024-02-19 12:20:20 +01:00
|
|
|
$Parsedown = new Parsedown();
|
|
|
|
$Parsedown->setBreaksEnabled(true);
|
2024-03-08 16:45:50 +01:00
|
|
|
echo $Parsedown->text('# ' . $title . "\r\n" . substr($content, $pos));
|
2024-03-07 12:48:31 +01:00
|
|
|
$nextpage = '';
|
|
|
|
}
|
|
|
|
else if (isset($_GET['open']))
|
|
|
|
{
|
|
|
|
$nextpage = 'note';
|
|
|
|
$title = $_GET['param'];
|
2024-02-19 12:20:20 +01:00
|
|
|
}
|
2024-03-07 12:48:31 +01:00
|
|
|
|
|
|
|
if ($nextpage == 'note')
|
2024-02-14 14:23:25 +01:00
|
|
|
{
|
2024-02-19 10:18:10 +01:00
|
|
|
$now = date("Y-m-d H.i.s", time());
|
2024-03-06 08:33:44 +01:00
|
|
|
if (!$title)
|
2024-02-16 18:08:18 +01:00
|
|
|
{
|
2024-03-06 08:33:44 +01:00
|
|
|
$title = $now;
|
2024-02-16 18:08:18 +01:00
|
|
|
}
|
2024-02-14 08:41:48 +01:00
|
|
|
|
2024-03-06 08:33:44 +01:00
|
|
|
if (!file_exists($dir . '/' . $title))
|
2024-02-14 14:23:25 +01:00
|
|
|
{
|
2024-02-19 10:26:10 +01:00
|
|
|
$content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n";
|
2024-03-07 10:02:11 +01:00
|
|
|
savenote($title, $content);
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
2024-02-19 10:18:10 +01:00
|
|
|
else if (!$content)
|
2024-02-14 14:23:25 +01:00
|
|
|
{
|
2024-03-06 08:33:44 +01:00
|
|
|
$content = file_get_contents($dir . '/' . $title);
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
2024-03-12 12:12:13 +01:00
|
|
|
|
2024-03-15 15:11:51 +01:00
|
|
|
clearstatcache();
|
|
|
|
$lastchanged = filemtime($dir . '/' . $title);
|
2024-03-11 13:58:27 +01:00
|
|
|
$lines = substr_count($content, "\r\n");
|
|
|
|
$words = substr_count($content, " ") + $lines;
|
|
|
|
$chars = strlen($content);
|
2024-03-06 11:53:57 +01:00
|
|
|
|
2024-03-11 13:58:27 +01:00
|
|
|
$rows = max(20, $lines) * 2;
|
2024-03-06 11:53:57 +01:00
|
|
|
|
2024-03-06 08:33:44 +01:00
|
|
|
require('note.php');
|
2024-03-06 11:53:57 +01:00
|
|
|
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
2024-03-07 12:48:31 +01:00
|
|
|
else if ($nextpage == 'home')
|
2024-02-14 14:23:25 +01:00
|
|
|
{
|
2024-03-06 08:33:44 +01:00
|
|
|
if (isset($_GET['param']))
|
2024-02-14 14:23:00 +01:00
|
|
|
{
|
2024-03-06 08:33:44 +01:00
|
|
|
$param = $_GET['param'];
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
2024-03-06 08:33:44 +01:00
|
|
|
require('home.php');
|
2024-03-06 11:53:57 +01:00
|
|
|
|
2024-03-07 10:02:11 +01:00
|
|
|
echo '<div>';
|
|
|
|
|
|
|
|
foreach($_SESSION['index'] as $path)
|
2024-03-06 11:53:57 +01:00
|
|
|
{
|
|
|
|
$tags = '';
|
|
|
|
$name = basename($path);
|
2024-03-06 12:14:08 +01:00
|
|
|
if (!str_ends_with($name, '.del'))
|
2024-03-06 11:53:57 +01:00
|
|
|
{
|
2024-03-08 16:45:50 +01:00
|
|
|
if ($_GET['param'] && (isset($_GET['search']) || isset($_GET['tags'])))
|
2024-03-06 11:53:57 +01:00
|
|
|
{
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
|
2024-03-07 12:48:31 +01:00
|
|
|
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)))
|
2024-03-06 11:53:57 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '<div><a href=index.php?open=true¶m=' . urlencode($name) . '>' . $name .'</a>';
|
2024-03-08 16:45:50 +01:00
|
|
|
if (isset($content) && isset($_GET['tags']))
|
2024-03-06 11:53:57 +01:00
|
|
|
{
|
|
|
|
$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¶m=' . $tag . '">' . $tag . '</a> ');
|
|
|
|
}
|
|
|
|
echo '</span>';
|
|
|
|
}
|
|
|
|
}
|
2024-03-07 12:48:31 +01:00
|
|
|
else if (isset($_GET['search']) && str_contains(strtolower($content), strtolower($param)))
|
2024-03-06 11:53:57 +01:00
|
|
|
{
|
|
|
|
$pos = strpos(strtolower($content), strtolower($param));
|
2024-03-06 12:14:08 +01:00
|
|
|
echo '<span class="grey"> ' . $param . substr($content, $pos + strlen($param), 42) . '</span>';
|
2024-03-06 11:53:57 +01:00
|
|
|
}
|
|
|
|
echo'</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</div>';
|
2024-02-14 14:23:25 +01:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</body>
|
2024-02-13 22:57:28 +01:00
|
|
|
</html>
|