From 853d253a7dc0c7de6438310cd94a7ece2da9397c Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Fri, 12 Dec 2025 10:34:56 +0500 Subject: feat: store posts in text format --- lib/post.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/post.php (limited to 'lib') diff --git a/lib/post.php b/lib/post.php new file mode 100644 index 0000000..0aa41e2 --- /dev/null +++ b/lib/post.php @@ -0,0 +1,33 @@ + pathinfo($file, PATHINFO_FILENAME), + 'time' => filemtime($file), + 'contents' => file_get_contents($file) + ]); + } + + usort($posts, fn($a, $b) => $a['time'] == $b['time'] ? 0 : ($a['time'] > $b['time'] ? -1 : 1)); + + return $posts; +} + +function read_post(string $name) +{ + $name = basename($name); + $path = "{$_SERVER['DOCUMENT_ROOT']}/postsources/$name.txt"; + if (!file_exists($path)) { + return null; + } + + return [ + 'name' => $name, + 'time' => filemtime($path), + 'contents' => file_get_contents($path) + ]; +} \ No newline at end of file -- cgit v1.2.3