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 download() { $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 (!isset($_GET['clip']) && (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'; if (isset($_GET['download'])) { download(); } ?> bbn setBreaksEnabled(true); echo $Parsedown->text('# ' . $title . "\r\n" . substr($content, $pos)); $nextpage = ''; } else if (isset($_GET['open'])) { $nextpage = 'note'; $title = $_GET['param']; } if ($nextpage == 'note') { $now = date("Y-m-d H.i.s", time()); if (!$title) { $title = $now; } if (!file_exists($dir . '/' . $title . '.md')) { $content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n"; savenote($title, $content); } else if (!$content) { $content = file_get_contents($dir . '/' . $title . '.md'); } clearstatcache(); $lastchanged = filemtime($dir . '/' . $title . '.md'); $lines = substr_count($content, "\r\n"); $words = substr_count($content, " ") + $lines; $chars = strlen($content); $rows = max(20, $lines) * 2; require('note.php'); } else if ($nextpage == 'home') { if (isset($_GET['param'])) { $param = $_GET['param']; } require('home.php'); echo '
'; foreach($_SESSION['index'] as $path) { $tags = ''; $name = basename($path); if (!str_ends_with($name, '.del')) { if (($_GET['param'] && isset($_GET['search'])) || isset($_GET['tags'])) { $content = file_get_contents($path . '.md'); if ( // param does not match content or title (isset($_GET['search']) && !str_contains(strtolower($content), strtolower($param)) && !str_contains(strtolower($name), strtolower($param))) || // param does not match tags (isset($_GET['tags']) && !preg_match('/tags:.*' . $param . '/i', $content)) ) { continue; } else if (isset($_GET['search']) && $param == $name) { header('Location: index.php?open=true¶m=' . urlencode($name)); die(); } } echo '
' . $name .''; if (isset($content) && isset($_GET['tags'])) { $tags = array(); $hastags = preg_match_all('/tags:(.*)/i', $content, $tags, PREG_SET_ORDER); if ($hastags) { $tagslist = explode(',', $tags[0][1]); echo ' '; foreach ($tagslist as $tag) { $tag = trim($tag); echo('' . $tag . ' '); } echo ''; } } else if (isset($_GET['search']) && str_contains(strtolower($content), strtolower($param))) { $pos = strpos(strtolower($content), strtolower($param)); echo ' ' . $param . substr($content, $pos + strlen($param), 42) . ''; } echo'
'; } } echo '
'; } ?>