WebOrbiton
v1.0.0.9

Publisium

66 lines · 3.5 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. $db = Database::site();
  6. ​
  7. $myArticleCount = 0;
  8. $pendingCount = 0;
  9. $publishedCount = 0;
  10. ​
  11. if (Auth::isAdministrative()) {
  12. $publishedCount = (int) $db->query("SELECT COUNT(*) AS c FROM articles WHERE status = 'published'")->fetch()['c'];
  13. $pendingCount = (int) $db->query("SELECT COUNT(*) AS c FROM articles WHERE status = 'pending_review'")->fetch()['c'];
  14. } else {
  15. $statement = $db->prepare("SELECT COUNT(*) AS c FROM articles WHERE author_id = :id AND deleted_at IS NULL");
  16. $statement->execute(['id' => $currentUser['id']]);
  17. $myArticleCount = (int) $statement->fetch()['c'];
  18. ​
  19. $statement = $db->prepare("SELECT COUNT(*) AS c FROM articles WHERE author_id = :id AND status = 'published'");
  20. $statement->execute(['id' => $currentUser['id']]);
  21. $publishedCount = (int) $statement->fetch()['c'];
  22. }
  23. ​
  24. $recentStatement = $db->prepare(
  25. Auth::isAdministrative()
  26. ? 'SELECT a.*, 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 NULL ORDER BY a.updated_at DESC LIMIT 8'
  27. : 'SELECT a.*, 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.author_id = :id AND a.deleted_at IS NULL ORDER BY a.updated_at DESC LIMIT 8'
  28. );
  29. if (!Auth::isAdministrative()) {
  30. $recentStatement->execute(['id' => $currentUser['id']]);
  31. } else {
  32. $recentStatement->execute();
  33. }
  34. $recentArticles = $recentStatement->fetchAll();
  35. ​
  36. ?>
  37. <h1 class="dash-title"><?= Icons::icon("overview", "icon icon-lg") ?>Overview</h1>
  38. ​
  39. <div class="dash-cards">
  40. <?php if (Auth::isAdministrative()): ?>
  41. <div class="dash-card"><div class="dash-card-value"><?= $publishedCount ?></div><div class="dash-card-label">Published articles</div></div>
  42. <div class="dash-card"><div class="dash-card-value"><?= $pendingCount ?></div><div class="dash-card-label">Waiting for review</div></div>
  43. <?php else: ?>
  44. <div class="dash-card"><div class="dash-card-value"><?= $myArticleCount ?></div><div class="dash-card-label">Your articles</div></div>
  45. <div class="dash-card"><div class="dash-card-value"><?= $publishedCount ?></div><div class="dash-card-label">Published</div></div>
  46. <?php endif; ?>
  47. </div>
  48. ​
  49. <h2 class="dash-subtitle"><?= Icons::icon('activity', 'icon icon-sm') ?>Recently updated</h2>
  50. <table class="dash-table">
  51. <thead><tr><th><?= Icons::icon('heading', 'icon icon-sm') ?>Title</th><th><?= Icons::icon('user', 'icon icon-sm') ?>Author</th><th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th><th><?= Icons::icon('clock', 'icon icon-sm') ?>Updated</th></tr></thead>
  52. <tbody>
  53. <?php foreach ($recentArticles as $article): ?>
  54. <tr>
  55. <td><a href="dashboard.php?view=article-edit&id=<?= (int) $article['id'] ?>"><?= htmlspecialchars($article['title']) ?></a></td>
  56. <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>
  57. <td><span class="status-pill status-<?= htmlspecialchars($article['status']) ?>"><?= htmlspecialchars(dashStatusLabel((string) $article['status'])) ?></span></td>
  58. <td><?= htmlspecialchars($article['updated_at']) ?></td>
  59. </tr>
  60. <?php endforeach; ?>
  61. <?php if (empty($recentArticles)): ?>
  62. <tr><td colspan="4">Nothing here yet. Your latest articles will show up here.</td></tr>
  63. <?php endif; ?>
  64. </tbody>
  65. </table>
  66. ​