purge_stale.php 581 B

1234567891011121314151617181920212223242526
  1. <?php
  2. require_once("./lib/misc.php");
  3. function purge_stale_threads(array $data, int $expiry_hours = 24): array {
  4. if ($expiry_hours === 0)
  5. return $data;
  6. $expiry_time = $expiry_hours * 60 * 60;
  7. $current_time = time();
  8. $filtered_threads = [];
  9. foreach ($data as $thread) {
  10. $last_reply_time = $thread['bump_time'];
  11. $is_expired = ($current_time - $last_reply_time) >= $expiry_time;
  12. if (count($thread['posts']) > 1 || !$is_expired ) {
  13. $filtered_threads[] = $thread;
  14. }
  15. }
  16. return $filtered_threads;
  17. }
  18. ?>