diff options
Diffstat (limited to 'private/hooks.php')
-rw-r--r-- | private/hooks.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/private/hooks.php b/private/hooks.php new file mode 100644 index 0000000..518582e --- /dev/null +++ b/private/hooks.php @@ -0,0 +1,30 @@ +<?php + +echo("\nLoading all profiles..."); +$profiles = scandir("./profiles"); +foreach ($profiles as $profile) { + if ($profile !== "." && $profile !== ".." && $profile !== "_base.json") { + echo("\nProcessing profile: " . $profile); + $staging = json_decode(file_get_contents("./profiles/" . $profile), true); + foreach ($staging['files'] as $index=>$file) { + echo("\nProcessing file: " . $file['id']); + $old = new DateTime($file['expiration']); + $new = new DateTime(); + $oldd = $old->format("U"); + $newd = $new->format("U"); + if (($oldd - $newd) < 1) { + echo("\nFile " . $file['id'] . " has expired, deleting it"); + unlink("./shares/" . $file['file']); + if (array_search($file, $staging['files']) !== false) { + unset($staging['files'][array_search($file, $staging['files'])]); + } + } else { + echo("\nFile " . $file['id'] . " still has " . ($oldd - $newd) . " seconds remaining before deleting"); + } + } + echo("\nSaving..."); + file_put_contents("./profiles/" . $profile, json_encode($staging, JSON_PRETTY_PRINT)); + } +} + +echo("\nDone!\n");
\ No newline at end of file |