v2.0.0.0
Publisium
- <?php
-
- declare(strict_types=1);
-
- $db = Database::site();
- $action = (string) ($_POST['action'] ?? '');
- $commentId = (int) ($_POST['comment_id'] ?? 0);
-
- if ($action === 'approve_comment' && $commentId > 0) {
- $db->prepare("UPDATE article_comments SET status = 'approved' WHERE id = :id")->execute(['id' => $commentId]);
- ActivityLog::record('comments.approve', 'comment', $commentId);
- $flashMessage = 'Comment approved. It’s visible on the site now.';
- } elseif ($action === 'hide_comment' && $commentId > 0) {
- $db->prepare("UPDATE article_comments SET status = 'pending' WHERE id = :id")->execute(['id' => $commentId]);
- ActivityLog::record('comments.hide', 'comment', $commentId);
- $flashMessage = 'Comment hidden. It’s back in the waiting list.';
- } elseif ($action === 'delete_comment' && $commentId > 0) {
- $db->prepare('DELETE FROM article_comments WHERE id = :id OR parent_id = :parent')->execute(['id' => $commentId, 'parent' => $commentId]);
- ActivityLog::record('comments.delete', 'comment', $commentId);
- $flashMessage = 'Comment deleted, together with its replies.';
- } elseif ($action === 'delete_pending_comments') {
- // Replies under a waiting comment would be left without a thread, so they go too.
- $db->exec("DELETE r FROM article_comments r JOIN article_comments p ON p.id = r.parent_id WHERE p.status = 'pending'");
- $deleted = $db->exec("DELETE FROM article_comments WHERE status = 'pending'");
- ActivityLog::record('comments.delete_pending', null, null, (string) $deleted . ' deleted');
- $flashMessage = 'All waiting comments were deleted.';
- }
-