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 = []; foreach (array_filter(scandir($dir), function ($i) { return !str_starts_with($i, "."); }) as $file) { if (in_array($dir . "/" . $file, $ignore)) continue; if (is_dir($dir . "/" . $file)) { array_push($files, ...rscandir($dir . "/" . $file)); } else { $files[] = $dir . "/" . $file; } } return array_unique($files); } function calculateVersionNumber() { $files = rscandir($_SERVER['DOCUMENT_ROOT']); $hashes = []; foreach ($files as $file) { $hashes[] = md5_file($file); } $hash = md5(implode("", $hashes)); return [$hash, $hashes]; } $versionHash = calculateVersionNumber(); if ($versionHash[0] !== $version["hash"]) { $version["hash"] = $versionHash[0]; $version["timestamp"] = time(); $version["revision"] = 0; $version["list"] = [ "current" => $versionHash[1], "old" => isset($version["list"]) ? $version["list"]["current"] ?? null : null ]; $version["build"]++; } else { $version["revision"]++; } file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/version.json", json_encode($version)); if (!is_link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"])) { link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other", $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"]); } echo("Backing up...\n"); $lastBackup = (int)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.txt")); if (time() - $lastBackup >= 3600) { require_once "./backup.inc"; file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/backup.txt", time()); echo("Backup completed\n"); } else { echo("Backup skipped\n"); } echo("Completed.\n");