v2.0.0.1
Publisium
- <?php
-
- declare(strict_types=1);
-
- $db = Database::site();
-
- $isAdmin = Auth::isAdministrative();
-
- $statement = $isAdmin
- ? $db->query('SELECT a.*, COALESCE(t.display_name, a.author_name) AS display_name, a.author_id AS owner_id, c.name AS category_name FROM articles a LEFT JOIN team_accounts t ON t.id = a.author_id LEFT JOIN categories c ON c.id = a.category_id WHERE a.deleted_at IS NULL ORDER BY a.updated_at DESC')
- : $db->prepare('SELECT a.*, COALESCE(t.display_name, a.author_name) AS display_name, a.author_id AS owner_id, c.name AS category_name FROM articles a LEFT JOIN team_accounts t ON t.id = a.author_id LEFT JOIN categories c ON c.id = a.category_id WHERE a.author_id = :id AND a.deleted_at IS NULL ORDER BY a.updated_at DESC');
-
- if (!$isAdmin) {
- $statement->execute(['id' => $currentUser['id']]);
- $articles = $statement->fetchAll();
- } else {
- $articles = $statement->fetchAll();
- }
-
- $trashStatement = $isAdmin
- ? $db->query('SELECT COUNT(*) FROM articles WHERE deleted_at IS NOT NULL')
- : $db->prepare('SELECT COUNT(*) FROM articles WHERE deleted_at IS NOT NULL AND author_id = :id');
- if (!$isAdmin) {
- $trashStatement->execute(['id' => $currentUser['id']]);
- }
- $trashCount = (int) $trashStatement->fetchColumn();
-
- ?>
- <div class="dash-header-row">
- <h1 class="dash-title"><?= Icons::icon("articles", "icon icon-lg") ?>Articles</h1>
- <a href="dashboard.php?view=trash" class="dash-btn"><?= Icons::icon('trash', 'icon icon-sm') ?>Trash<?= $trashCount > 0 ? ' (' . $trashCount . ')' : '' ?></a>
- <a href="dashboard.php?view=article-edit" class="dash-btn dash-btn-primary"><?= Icons::icon('plus', 'icon icon-sm') ?>New article</a>
- </div>
-
- <table class="dash-table">
- <thead>
- <tr>
- <th><?= Icons::icon('heading', 'icon icon-sm') ?>Title</th>
- <th><?= Icons::icon('categories', 'icon icon-sm') ?>Category</th>
- <th><?= Icons::icon('user', 'icon icon-sm') ?>Author</th>
- <th><?= Icons::icon('lock', 'icon icon-sm') ?>Access</th>
- <th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th>
- <th><?= Icons::icon('clock', 'icon icon-sm') ?>Updated</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($articles as $article): ?>
- <tr>
- <td><a href="dashboard.php?view=article-edit&id=<?= (int) $article['id'] ?>"><?= htmlspecialchars($article['title']) ?></a></td>
- <td><?= htmlspecialchars($article['category_name'] ?? 'None') ?></td>
- <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>
- <td><?= $article['access_type'] === 'paid' ? 'Paid' : 'Free' ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($article['status']) ?>"><?= htmlspecialchars(dashStatusLabel((string) $article['status'])) ?></span></td>
- <td><?= htmlspecialchars($article['updated_at']) ?></td>
- <td class="dash-table-actions">
-
- <?php if ($isAdmin && $article['status'] === 'pending_review'): ?>
- <form method="post" style="display:inline;">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="moderate_article">
- <input type="hidden" name="article_id" value="<?= (int) $article['id'] ?>">
- <input type="hidden" name="decision" value="approve">
- <button type="submit" class="dash-btn-small dash-btn-success"><?= Icons::icon('check', 'icon icon-sm') ?>Approve</button>
- </form>
- <button type="button" class="dash-btn-small dash-btn-danger js-reject-btn" data-article-id="<?= (int) $article['id'] ?>"><?= Icons::icon('x', 'icon icon-sm') ?>Send back</button>
- <?php endif; ?>
-
- <form method="post" style="display:inline;" onsubmit="return confirm('Move this article to the trash?');">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="delete_article">
- <input type="hidden" name="article_id" value="<?= (int) $article['id'] ?>">
- <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Delete</button>
- </form>
- <?php if ($article['status'] === 'published' && !empty($article['slug'])): ?>
- <a href="<?= htmlspecialchars(SiteFront::articleUrl($article['slug'])) ?>" class="dash-btn-small" target="_blank" rel="noopener noreferrer"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a>
- <?php else: ?>
- <a href="article.php?preview=<?= (int) $article['id'] ?>" class="dash-btn-small" target="_blank" rel="noopener noreferrer"><?= Icons::icon('eye', 'icon icon-sm') ?>Preview</a>
- <?php endif; ?>
- </td>
- </tr>
-
- <?php if ($isAdmin && $article['status'] === 'pending_review'): ?>
- <tr class="js-reject-row" id="reject-row-<?= (int) $article['id'] ?>" style="display:none;">
- <td colspan="7">
- <form method="post">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="moderate_article">
- <input type="hidden" name="article_id" value="<?= (int) $article['id'] ?>">
- <input type="hidden" name="decision" value="reject">
- <input type="text" name="rejection_reason" placeholder="Tell the author what to change" class="dash-input-inline">
- <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('check', 'icon icon-sm') ?>Send back to author</button>
- </form>
- </td>
- </tr>
- <?php endif; ?>
-
- <?php endforeach; ?>
- <?php if (empty($articles)): ?>
- <tr><td colspan="7">No articles yet. Click New article to write your first one.</td></tr>
- <?php endif; ?>
- </tbody>
- </table>
-