WebOrbiton
v1.0.0.6

Publisium

69 lines · 3.3 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. $db = Database::site();
  6. $isAdmin = Auth::hasRoleAtLeast(Auth::ROLE_EDITOR_IN_CHIEF);
  7. ​
  8. $statement = $isAdmin
  9. ? $db->query('SELECT a.id, a.title, a.trashed_status, a.deleted_at, COALESCE(t.display_name, a.author_name) AS display_name, a.author_id AS owner_id FROM articles a LEFT JOIN team_accounts t ON t.id = a.author_id WHERE a.deleted_at IS NOT NULL ORDER BY a.deleted_at DESC')
  10. : $db->prepare('SELECT a.id, a.title, a.trashed_status, a.deleted_at, COALESCE(t.display_name, a.author_name) AS display_name, a.author_id AS owner_id FROM articles a LEFT JOIN team_accounts t ON t.id = a.author_id WHERE a.deleted_at IS NOT NULL AND a.author_id = :id ORDER BY a.deleted_at DESC');
  11. ​
  12. if (!$isAdmin) {
  13. $statement->execute(['id' => $currentUser['id']]);
  14. }
  15. ​
  16. $trashed = $statement->fetchAll();
  17. ​
  18. ?>
  19. <div class="dash-header-row">
  20. <h1 class="dash-title"><?= Icons::icon('trash', 'icon icon-lg') ?>Trash</h1>
  21. <a href="dashboard.php?view=articles" class="dash-btn"><?= Icons::icon('articles', 'icon icon-sm') ?>Back to articles</a>
  22. <?php if (!empty($trashed)): ?>
  23. <form method="post" style="display:inline;" onsubmit="return confirm('Delete everything in the trash for good? You won\'t be able to get it back.');">
  24. <?= Csrf::field() ?>
  25. <input type="hidden" name="action" value="empty_trash">
  26. <button type="submit" class="dash-btn dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Empty trash</button>
  27. </form>
  28. <?php endif; ?>
  29. </div>
  30. ​
  31. <table class="dash-table">
  32. <thead>
  33. <tr>
  34. <th><?= Icons::icon('heading', 'icon icon-sm') ?>Title</th>
  35. <th><?= Icons::icon('user', 'icon icon-sm') ?>Author</th>
  36. <th><?= Icons::icon('flag', 'icon icon-sm') ?>Status before</th>
  37. <th><?= Icons::icon('clock', 'icon icon-sm') ?>Deleted</th>
  38. <th></th>
  39. </tr>
  40. </thead>
  41. <tbody>
  42. <?php foreach ($trashed as $article): ?>
  43. <tr>
  44. <td><?= htmlspecialchars($article['title']) ?></td>
  45. <td><?= htmlspecialchars((string) ($article['display_name'] ?? 'System')) ?><?php if ($article['owner_id'] === null): ?> <span class="status-pill status-draft" title="The author's account was removed. The article stays on the site under their name.">system</span><?php endif; ?></td>
  46. <td><?= htmlspecialchars(dashStatusLabel((string) ($article['trashed_status'] ?? 'draft'))) ?></td>
  47. <td><?= htmlspecialchars($article['deleted_at']) ?></td>
  48. <td class="dash-table-actions">
  49. <form method="post" style="display:inline;">
  50. <?= Csrf::field() ?>
  51. <input type="hidden" name="action" value="restore_article">
  52. <input type="hidden" name="article_id" value="<?= (int) $article['id'] ?>">
  53. <button type="submit" class="dash-btn-small dash-btn-success"><?= Icons::icon('refresh', 'icon icon-sm') ?>Restore</button>
  54. </form>
  55. <form method="post" style="display:inline;" onsubmit="return confirm('Delete this article for good? You won\'t be able to get it back.');">
  56. <?= Csrf::field() ?>
  57. <input type="hidden" name="action" value="purge_article">
  58. <input type="hidden" name="article_id" value="<?= (int) $article['id'] ?>">
  59. <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Delete forever</button>
  60. </form>
  61. </td>
  62. </tr>
  63. <?php endforeach; ?>
  64. <?php if (empty($trashed)): ?>
  65. <tr><td colspan="5">The trash is empty. Deleted articles land here first, so you can still bring them back.</td></tr>
  66. <?php endif; ?>
  67. </tbody>
  68. </table>
  69. ​