pub / rememori

Simple file-based bookmarking and notes application
git clone https://src.jayvii.de/pub/rememori.git
Home | Log | Files | Exports | Refs | README | RSS

commit 000f1cbe93f87f5864cd6783070dccc388abdefc
parent 26b03ded48ac46a324ec27de4d23a54e39b69590
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Thu, 24 Oct 2024 17:27:29 +0200

feat: add function to list notes

Diffstat:
Alib/list.php | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 112 insertions(+), 0 deletions(-)

diff --git a/lib/list.php b/lib/list.php @@ -0,0 +1,112 @@ +<!-- SPDX-License-Identifier: AGPL-3.0-or-later + SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de> +--> + +<?php + +function list_notes( + string $user, + string $category +) { + + /* Create full path name */ + $dirpath = "./data/" . $user . "/" . $category; + + /* list all available notes */ + $filematches = glob($dirpath . "/" . "*.txt"); + + if ($filematches !== false) { + + /* Gather each file next to its edit time stamp */ + $filenames = array(); + foreach ($filematches as $filename) { + + array_push( + $filenames, + array( + "name" => basename($filename), + "time" => filectime($filename) + ) + ); + } + + /* Sort filenames by edit timestamp */ + function sort_by_time($a, $b) { return $b["time"] - $a["time"]; } + usort($filenames, "sort_by_time"); + +?> + + <h3><?php echo $category; ?></h3> + <table> + <thead> + <tr> + <!-- 1st column: filename --> + <th><?php echo $GLOBALS["i18n_filename"]; ?></th> + <!-- 2nd column: edit time --> + <th><?php echo $GLOBALS["i18n_ctime"]; ?></th> + <!-- 3rd column: edit button --> + <th></th> + </tr> + </thead> + <tbody> + +<?php + /* loop through each filename and draw a table row */ + foreach ($filenames as $filename) { +?> + + <tr> + <!-- 1st column: filename --> + <td><?php echo $filename["name"]; ?></td> + <!-- 2nd column: edit time --> + <td><?php echo date("Y-m-d H:i:s", $filename["time"]); ?></td> + <!-- 3rd columne:form with edit-button --> + <td> + <form action="/" target="_self" method="post"> + <input + id="user" + name="user" + type="hidden" + value="<?php echo $user; ?>" + > + <input + id="category" + name="category" + type="hidden" + value="<?php echo $category; ?>" + > + <input + id="filename" + name="filename" + type="hidden" + value="<?php echo $filename["name"]; ?>" + > + <input + id="action" + name="action" + type="hidden" + value="edit" + > + <input + type="submit" + value="<?php echo $GLOBALS["i18n_edit"]; ?>" + > + </form> + </td> + </tr> + +<?php + + } // for-loop + +?> + </tbody> + </table> + +<?php + + } // if-statement + +} // function + +?>