bbn/index.php

110 lines
2.5 KiB
PHP
Raw Normal View History

2024-09-30 10:09:49 +02:00
<?php
2024-10-07 16:06:35 +02:00
require('common.php');
2024-09-30 10:09:49 +02:00
function cleanstring($string)
{
2024-10-16 13:58:19 +02:00
return iconv('UTF-8', 'UTF-8//TRANSLIT//IGNORE', strtolower($string));
}
function downloadall()
{
$zip = new ZipArchive();
$zip_name = 'bbn.zip';
$zip->open($zip_name, ZipArchive::CREATE);
foreach($_SESSION['index'] as $path)
{
if (!str_ends_with($path, '.del'))
{
$path = $path . '.md';
if (file_exists($path))
{
$zip->addFile($path, basename($path));
}
}
}
$zip->close();
header('Content-disposition: attachment; filename=' . $zip_name);
header('Content-type: application/zip');
readfile($zip_name);
unlink($zip_name);
}
2024-09-30 10:09:49 +02:00
if (isset($_GET['download']))
{
2024-10-02 11:49:15 +02:00
downloadall();
2024-10-07 16:26:16 +02:00
exit;
2024-09-30 10:09:49 +02:00
}
2024-10-01 10:51:28 +02:00
2024-10-07 16:06:35 +02:00
$filter = '';
if (isset($_GET['filter']))
2024-10-01 10:51:28 +02:00
{
2024-10-07 16:06:35 +02:00
$filter = $_GET['filter'];
2024-10-07 09:08:38 +02:00
}
2024-09-30 10:09:49 +02:00
?>
<!DOCTYPE html>
<html>
<head>
2024-10-07 16:06:35 +02:00
<title>bbn</title>
2024-09-30 10:09:49 +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 16:06:35 +02:00
<div>
2024-10-08 13:11:32 +02:00
<a href="note.php?new" class="grey" accesskey="n">new</a>
<a href="index.php?download" class="grey" accesskey="d">download</a>
2024-10-22 09:29:46 +02:00
<input form="home" placeholder="filter..." autofocus autocomplete="off" class="title" name="filter" value="<?php echo $filter; ?>" form="home">
2024-10-08 13:11:32 +02:00
<form action="index.php" method="GET" id="home">
<input hidden type="submit">
</form>
2024-10-07 16:06:35 +02:00
</div>
<div>
2024-09-30 10:09:49 +02:00
<?php
2024-10-15 17:14:07 +02:00
$index = 1;
2024-10-07 16:06:35 +02:00
foreach($_SESSION['index'] as $path)
{
2024-10-07 16:06:35 +02:00
$name = basename($path);
2024-10-10 10:22:32 +02:00
if (str_ends_with($name, '.del'))
{
continue;
}
2024-10-07 16:06:35 +02:00
if ($filter)
2024-03-06 11:53:57 +01:00
{
2024-10-07 16:06:35 +02:00
$content = file_get_contents($path . '.md');
if (!str_contains(cleanstring($content), cleanstring($filter)) && !str_contains(cleanstring($name), cleanstring($filter)))
2024-03-06 11:53:57 +01:00
{
2024-10-07 16:06:35 +02:00
continue;
2024-03-06 11:53:57 +01:00
}
}
2024-10-15 17:14:07 +02:00
echo '<div><a href=note.php?title=' . urlencode($name) . ' ';
if ($index < 10)
{
echo 'accesskey="' . $index .'" ';
}
$index++;
echo '>' . $name .'</a>';
2024-10-07 16:06:35 +02:00
if ($filter && str_contains(cleanstring($content), cleanstring($filter)))
{
2024-10-10 10:47:54 +02:00
$pos = strpos(cleanstring($content), cleanstring($filter));
2024-10-22 09:29:46 +02:00
$start = max($pos - 21, 0);
echo '<span class="grey">&nbsp;';
echo substr($content, $start, min(21, $pos));
echo '<b>' . $filter . '</b>';
echo substr($content, $pos + strlen($filter), 21);
echo '</span>';
2024-10-07 16:06:35 +02:00
}
echo'</div>';
2024-02-14 14:23:25 +01:00
}
?>
2024-10-07 16:06:35 +02:00
</div>
2024-02-14 14:23:25 +01:00
</body>
2024-10-10 10:47:54 +02:00
</html>