back to files backend
This commit is contained in:
parent
6519fa6827
commit
36e534be13
8 changed files with 63 additions and 62 deletions
|
|
@ -1,18 +1,40 @@
|
|||
<?php
|
||||
$_shared = $_SERVER["DOCUMENT_ROOT"] . "/templates";
|
||||
$_shared = $_SERVER["DOCUMENT_ROOT"]."/templates";
|
||||
require "$_shared/lib.php";
|
||||
$_title = "Notes";
|
||||
require "$_shared/header.php";
|
||||
?>
|
||||
<a href="write.php">Write a note</a><br>
|
||||
<h4>Notes</h4>
|
||||
<?php
|
||||
require_once "$_shared/lib.php";
|
||||
$pdo = pdo_init();
|
||||
$entries = $pdo->query("select * from notes.entries order by date desc");
|
||||
foreach ($entries as $entry) {
|
||||
$id = $entry["id"];
|
||||
$text = $entry["title"];
|
||||
echo "<a href='write.php?id=$id'>$text</a><br>\n";
|
||||
$name = $_GET["name"];
|
||||
$baseDir = __DIR__."/files/$name";
|
||||
echo "<a href='write.php?name=$name'>New note</a><br>\n";
|
||||
foreach (scandir($baseDir) as $entry) {
|
||||
if ($entry === ".") continue;
|
||||
$path = "$baseDir/$entry";
|
||||
$newName = trim("$name/$entry", "/");
|
||||
if (is_dir($path)) {
|
||||
$elem["type"] = "dirs";
|
||||
$elem["href"] = ".?name=$newName";
|
||||
} else if (substr($entry, -5) === ".note") {
|
||||
$elem["type"] = "notes";
|
||||
$entry = substr($entry, 0, -5);
|
||||
$elem["href"] = "write.php?name=$newName";
|
||||
} else {
|
||||
$elem["type"] = "files";
|
||||
$elem["href"] = "files/$newName";
|
||||
}
|
||||
$elem["entry"] = $entry;
|
||||
$elem["date"] = filemtime($path);
|
||||
$elems[] = $elem;
|
||||
}
|
||||
usort($elems, function($a, $b) {
|
||||
return $a["type"] <=> $b["type"] ?: $b["date"] <=> $a["date"];
|
||||
});
|
||||
foreach ($elems as $elem) {
|
||||
if ($elem["type"] !== $type) {
|
||||
$type = $elem["type"];
|
||||
echo "<h4>$type</h4>\n";
|
||||
}
|
||||
$text = date("Y-m-d\TH:i", $elem["date"])." ".$elem["entry"];
|
||||
echo "<a href='".$elem["href"]."'>$text</a><br>\n";
|
||||
}
|
||||
require "$_shared/footer.php";
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue