WebOrbiton
v2.0.0.1

Publisium

38 lines · 1.1 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (!Auth::canModerate()) {
  6. exit;
  7. }
  8. ​
  9. $articleId = (int) ($_POST['article_id'] ?? 0);
  10. $decision = $_POST['decision'] ?? '';
  11. $reason = trim((string) ($_POST['rejection_reason'] ?? ''));
  12. ​
  13. if ($articleId <= 0) {
  14. exit;
  15. }
  16. ​
  17. $db = Database::site();
  18. ​
  19. if ($decision === 'approve') {
  20. $statement = $db->prepare(
  21. "UPDATE articles SET status = 'published', published_at = COALESCE(published_at, NOW()), rejection_reason = NULL WHERE id = :id AND deleted_at IS NULL"
  22. );
  23. $statement->execute(['id' => $articleId]);
  24. }
  25. ​
  26. if ($decision === 'reject') {
  27. $statement = $db->prepare(
  28. "UPDATE articles SET status = 'rejected', rejection_reason = :reason WHERE id = :id AND deleted_at IS NULL"
  29. );
  30. $statement->execute(['id' => $articleId, 'reason' => $reason]);
  31. }
  32. ​
  33. if ($decision === 'mark_paid' || $decision === 'mark_free') {
  34. $accessType = $decision === 'mark_paid' ? 'paid' : 'free';
  35. $statement = $db->prepare('UPDATE articles SET access_type = :access_type WHERE id = :id AND deleted_at IS NULL');
  36. $statement->execute(['access_type' => $accessType, 'id' => $articleId]);
  37. }
  38. ​