From 05af3950c40e5724f1cd9ed662528c0832fb1297 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Wed, 29 Mar 2023 22:44:18 +0200 Subject: Updated 3 files and deleted includes/jobs/CleanupDocs.php (automated) --- includes/refresh.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'includes/refresh.php') diff --git a/includes/refresh.php b/includes/refresh.php index 9abe297..98bda15 100644 --- a/includes/refresh.php +++ b/includes/refresh.php @@ -45,6 +45,25 @@ foreach ($screens as $screen) { if ($delete) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens/" . $screen); } +$documents = array_map(function ($i) { + return [ + "id" => substr($i, 0, -5), + ...(json_decode(file_get_contents("./data/docs/" . $i), true) ?? []) + ]; +}, array_filter(scandir("./data/docs"), function ($i) { + return !str_starts_with($i, ".") && str_ends_with($i, ".json"); +})); + +$deletable = array_values(array_filter($documents, function ($i) { + return str_starts_with(strip_tags($i["contents"]), "/delete"); +})); + +foreach ($deletable as $item) { + if (time() - $item["last"]["date"] > 86400) { + unlink("./data/docs/" . $item["id"] . ".json"); + } +} + function rscandir($dir) { global $ignore; $files = []; -- cgit