Access denied.

'; exit; } session_start(); if (!isset($_SESSION['index']) || isset($_GET['reindex']) || empty($_SESSION['index'])) { $files = glob($dir . '/*'); usort($files, function($a, $b) { return filemtime($b) - filemtime($a); }); $_SESSION['index'] = array_map(fn($value): string => str_replace('.md', '', $value), $files); } function cleanstring($string) { return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', strtolower($string)); } function downloadnote($path) { header('Content-disposition: attachment; filename=' . basename($path)); header('Content-type: text/markdown'); readfile($path); exit; } 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)); } else { echo"file does not exist"; } } } $zip->close(); header('Content-disposition: attachment; filename=' . $zip_name); header('Content-type: application/zip'); readfile($zip_name); unlink($zip_name); exit; } function removefromindex($title) { global $dir; $key = array_search($dir . '/' . $title, $_SESSION['index']); if ($key !== FALSE) { array_splice($_SESSION['index'], $key, 1); } } function savenote($title, $content) { global $dir; $path = $dir . '/' . $title; $lastchanged = filemtime($path); $previous = $_POST['lastchanged']; if ((int)$lastchanged > (int)$previous) { $tempcontent = file_get_contents($path . '.md'); if ($tempcontent != $content) { $temptitle = $title . '_' . $lastchanged; file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); array_unshift($_SESSION['index'], $dir . '/' . $temptitle); echo '
Conflict detected. See backup: ' . $temptitle . '
'; } } file_put_contents($path . '.md', $content); removefromindex($title); array_unshift($_SESSION['index'], $path); } function linksdiv($content) { $divcontent = '
'; $links = array(); if (preg_match_all('/\[\[(.*)\]\]/', $content, $links, PREG_SET_ORDER)) { foreach($links as $link) { $divcontent .= '
' . $link[1] . '
'; } } $links = array(); if (preg_match_all('/(https?:.*)\b/', $content, $links, PREG_SET_ORDER)) { foreach($links as $link) { $divcontent .= '
' . $link[1] . '
'; } } $divcontent .= '
'; return $divcontent; } $nextpage = 'home'; $preview = ''; if (isset($_GET['download'])) { downloadall(); } else if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['download'])) { $title = $_POST['title']; $content = $_POST['content']; 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'); } else if (!isset($_POST['home'])) { $nextpage = 'note'; } } else if (isset($_POST['delete'])) { $title = $_POST['title']; rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del'); removefromindex($title); } else if (isset($_POST['preview'])) { require 'libs/Parsedown.php'; $title = $_POST['title']; $content = $_POST['content']; $pos = 0; if (str_starts_with($content, '---')) { $pos = strpos($content, '---', 3) + 3; } $Parsedown = new Parsedown(); $Parsedown->setBreaksEnabled(true); $preview = $Parsedown->text('# ' . $title . "\r\n" . substr($content, $pos)); $nextpage = 'preview'; } else if (isset($_GET['open'])) { $nextpage = 'note'; $title = $_GET['param']; } ?> <?php if ($nextpage != 'home' && isset($title)) { echo $title; } else { echo 'bbn'; } ?> '; foreach($_SESSION['index'] as $path) { $name = basename($path); if (!str_ends_with($name, '.del')) { if (($_GET['param'] && isset($_GET['search']))) { $content = file_get_contents($path . '.md'); if (isset($_GET['search']) && !str_contains(cleanstring($content), cleanstring($param)) && !str_contains(cleanstring($name), cleanstring($param))) { continue; } } echo '
' . $name .''; if (isset($_GET['search']) && str_contains(cleanstring($content), cleanstring($param))) { $pos = strpos(cleanstring($content), cleanstring($param)); echo ' ' . $param . substr($content, $pos + strlen($param), 42) . ''; } echo'
'; } } echo ''; } ?>