WebOrbiton
v2.0.0.0

Publisium

28 lines · 1.6 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. $db = Database::site();
  6. $action = (string) ($_POST['action'] ?? '');
  7. $commentId = (int) ($_POST['comment_id'] ?? 0);
  8. ​
  9. if ($action === 'approve_comment' && $commentId > 0) {
  10. $db->prepare("UPDATE article_comments SET status = 'approved' WHERE id = :id")->execute(['id' => $commentId]);
  11. ActivityLog::record('comments.approve', 'comment', $commentId);
  12. $flashMessage = 'Comment approved. It’s visible on the site now.';
  13. } elseif ($action === 'hide_comment' && $commentId > 0) {
  14. $db->prepare("UPDATE article_comments SET status = 'pending' WHERE id = :id")->execute(['id' => $commentId]);
  15. ActivityLog::record('comments.hide', 'comment', $commentId);
  16. $flashMessage = 'Comment hidden. It’s back in the waiting list.';
  17. } elseif ($action === 'delete_comment' && $commentId > 0) {
  18. $db->prepare('DELETE FROM article_comments WHERE id = :id OR parent_id = :parent')->execute(['id' => $commentId, 'parent' => $commentId]);
  19. ActivityLog::record('comments.delete', 'comment', $commentId);
  20. $flashMessage = 'Comment deleted, together with its replies.';
  21. } elseif ($action === 'delete_pending_comments') {
  22. // Replies under a waiting comment would be left without a thread, so they go too.
  23. $db->exec("DELETE r FROM article_comments r JOIN article_comments p ON p.id = r.parent_id WHERE p.status = 'pending'");
  24. $deleted = $db->exec("DELETE FROM article_comments WHERE status = 'pending'");
  25. ActivityLog::record('comments.delete_pending', null, null, (string) $deleted . ' deleted');
  26. $flashMessage = 'All waiting comments were deleted.';
  27. }
  28. ​