bbn/index.php

143 lines
3.1 KiB
PHP
Raw Normal View History

2024-02-13 22:57:28 +01:00
<!DOCTYPE html>
<html>
2024-02-14 14:23:25 +01:00
<head>
2024-03-06 10:58:21 +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
require 'settings.php';
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');
echo '<p>Access denied.</p>';
exit;
}
$action = '';
2024-03-06 08:33:44 +01:00
if (isset($_GET['open']))
{
$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']))
2024-02-20 16:23:37 +01:00
{
$action = 'save';
}
2024-03-06 08:33:44 +01:00
else if(isset($_GET['home']))
{
$action = '';
}
else if (isset($_POST['preview']))
{
$action = 'preview';
}
2024-02-20 16:23:37 +01:00
$content = '';
2024-03-06 08:33:44 +01:00
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')
2024-02-14 14:23:25 +01:00
{
$title = $_POST['title'];
$content = $_POST['content'];
file_put_contents($dir . '/' . $title, $content);
$previoustitle = $_POST['previoustitle'];
if ($title != $previoustitle)
{
rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del');
}
$action = 'open';
2024-03-06 08:33:44 +01:00
$_GET['param'] = $title;
2024-02-20 16:23:37 +01:00
if (isset($_POST['home']))
{
header('Location: index.php');
}
2024-02-14 14:23:25 +01:00
}
else if ($action == 'delete')
2024-02-14 14:23:25 +01:00
{
$title = $_POST['title'];
rename($dir . '/' . $title, $dir . '/' . $title . '.del');
}
2024-02-13 22:57:28 +01:00
2024-02-19 12:20:20 +01:00
if ($action == 'preview')
{
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, '---'))
{
$pos = strpos($content, '---', 3);
}
2024-02-19 12:20:20 +01:00
$Parsedown = new Parsedown();
$Parsedown->setBreaksEnabled(true);
2024-03-06 08:33:44 +01:00
echo $Parsedown->text('# ' . $title . "\r\n" . substr($content, $pos + 3));
2024-02-19 12:20:20 +01:00
}
else if ($action == 'open')
2024-02-14 14:23:25 +01:00
{
2024-03-06 08:33:44 +01:00
$title = $_GET['param'];
$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-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-06 08:33:44 +01:00
file_put_contents($dir . '/' . $title, $content);
2024-02-14 14:23:25 +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-06 08:33:44 +01:00
require('note.php');
2024-02-14 14:23:25 +01:00
}
else
{
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-02-14 14:23:25 +01:00
}
?>
</body>
2024-02-13 22:57:28 +01:00
</html>