v2.0.0.1
Publisium
- <?php
-
- declare(strict_types=1);
-
- if (!Auth::hasRoleAtLeast(Auth::ROLE_MANAGING_EDITOR)) {
- echo '<p>Only managing editors and above can edit pages.</p>';
- return;
- }
-
- $db = Database::site();
-
- $editingHome = isset($_GET['home']);
- $pageId = $editingHome ? null : ((int) ($_GET['page_id'] ?? 0) ?: null);
- $editingPage = null;
- $showForm = !$editingHome && ($pageId !== null || isset($_GET['new']));
-
- if ($pageId !== null) {
- $statement = $db->prepare('SELECT * FROM pages WHERE id = :id LIMIT 1');
- $statement->execute(['id' => $pageId]);
- $editingPage = $statement->fetch() ?: null;
- }
-
- $pages = $db->query('SELECT * FROM pages ORDER BY sort_order ASC, title ASC')->fetchAll();
- $blocksJson = $editingPage['content_blocks'] ?? '{"blocks":[]}';
-
- ?>
- <div class="dash-header-row">
- <h1 class="dash-title"><?= Icons::icon("pages", "icon icon-lg") ?>Pages</h1>
- <?php if (!$showForm && !$editingHome): ?>
- <a href="dashboard.php?view=pages&new=1" class="dash-btn dash-btn-primary"><?= Icons::icon('plus', 'icon icon-sm') ?>New page</a>
- <?php endif; ?>
- </div>
-
- <table class="dash-table">
- <thead><tr><th><?= Icons::icon('heading', 'icon icon-sm') ?>Title</th><th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th><th><?= Icons::icon('menu', 'icon icon-sm') ?>In menu</th><th></th></tr></thead>
- <tbody>
- <tr class="page-row-home">
- <td><?= Icons::icon('home', 'icon icon-sm') ?>Home page</td>
- <td><span class="status-pill status-published">Published</span></td>
- <td>Linked from the site name</td>
- <td class="dash-table-actions">
- <a href="dashboard.php?view=pages&home=1" class="dash-btn-small"><?= Icons::icon('edit', 'icon icon-sm') ?>Edit</a>
- <?php if (Languages::enabled()): ?>
- <a href="translate.php?type=home&id=1" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?>Translate</a>
- <?php endif; ?>
- <a href="<?= htmlspecialchars(SiteFront::homeUrl(''), ENT_QUOTES) ?>" target="_blank" rel="noopener" class="dash-btn-small"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a>
- </td>
- </tr>
- <?php foreach ($pages as $page): ?>
- <tr>
- <td><?= htmlspecialchars($page['title']) ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($page['status']) ?>"><?= htmlspecialchars(dashStatusLabel((string) $page['status'])) ?></span></td>
- <td><?= $page['show_in_menu'] ? 'Yes' : 'No' ?></td>
- <td class="dash-table-actions">
- <a href="dashboard.php?view=pages&page_id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('edit', 'icon icon-sm') ?>Edit</a>
- <?php if (Languages::enabled()): ?>
- <a href="translate.php?type=page&id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?>Translate</a>
- <?php endif; ?>
- <form method="post" style="display:inline;" onsubmit="return confirm('Delete this page? It disappears from the site right away.');">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="delete_page">
- <input type="hidden" name="page_id" value="<?= (int) $page['id'] ?>">
- <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Delete</button>
- </form>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
-
- <?php if ($editingHome): ?>
- <?php require_once __DIR__ . '/../includes/contact.php'; ?>
- <div class="sidebar-box" style="margin-top:20px;">
- <h2 class="dash-subtitle" style="margin-top:0;"><?= Icons::icon('home', 'icon icon-sm') ?>Edit home page</h2>
- <p style="color:var(--muted);font-size:13px;margin:0 0 14px;">Featured articles and Latest articles always stay on the home page. Move them where you like and add your own blocks around them.</p>
-
- <form method="post" id="page-form">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="save_homepage">
- <input type="hidden" name="blocks_json" id="blocks_json_input">
-
- <label><?= Icons::icon('layout', 'icon icon-sm') ?>Layout</label>
- <div id="block-editor-root" data-system-blocks="home" data-draft-key="publisium_homepage_draft" data-contact-form="<?= ContactForm::isEnabled() ? 'enabled' : 'disabled' ?>" data-featured-enabled="<?= (SiteFront::settings()['featured_banner_enabled'] ?? '0') === '1' ? '1' : '0' ?>" data-initial-blocks='<?= htmlspecialchars(json_encode(['blocks' => BlockEditor::homepageBlocks(SiteFront::settings())], JSON_UNESCAPED_UNICODE), ENT_QUOTES) ?>'></div>
-
- <div class="publish-actions">
- <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save home page</button>
- <a href="dashboard.php?view=pages" class="dash-btn"><?= Icons::icon('x', 'icon icon-sm') ?>Cancel</a>
- </div>
- </form>
- </div>
-
- <?= Asset::js('assets/block-editor.js') ?>
- <?php require_once __DIR__ . '/../includes/ai.php'; ?>
- <?= Ai::widgetMarkup() ?>
- <?php endif; ?>
-
- <?php if ($showForm): ?>
- <div class="sidebar-box" style="margin-top:20px;">
- <h2 class="dash-subtitle" style="margin-top:0;"><?= Icons::icon('pages', 'icon icon-sm') ?><?= $editingPage ? 'Edit page' : 'New page' ?></h2>
-
- <form method="post" id="page-form">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="save_page">
- <?php if ($editingPage): ?>
- <input type="hidden" name="page_id" value="<?= (int) $editingPage['id'] ?>">
- <?php endif; ?>
- <input type="hidden" name="blocks_json" id="blocks_json_input">
-
- <label><?= Icons::icon('heading', 'icon icon-sm') ?>Title</label>
- <input type="text" name="title" value="<?= htmlspecialchars($editingPage['title'] ?? '') ?>" required>
-
- <label><?= Icons::icon('quote', 'icon icon-sm') ?>Content</label>
- <?php require_once __DIR__ . '/../includes/contact.php'; ?>
- <div id="block-editor-root" data-contact-form="<?= ContactForm::isEnabled() ? 'enabled' : 'disabled' ?>" data-initial-blocks='<?= htmlspecialchars($blocksJson, ENT_QUOTES) ?>'></div>
-
- <label><input type="checkbox" name="show_in_menu" <?= !empty($editingPage['show_in_menu']) ? 'checked' : '' ?>> Show in site menu</label>
- <label><input type="checkbox" name="noindex" <?= !empty($editingPage['noindex']) ? 'checked' : '' ?>> Hide from search engines (noindex)</label>
-
- <label><?= Icons::icon('flag', 'icon icon-sm') ?>Status</label>
- <select name="status">
- <option value="draft" <?= ($editingPage['status'] ?? 'draft') === 'draft' ? 'selected' : '' ?>>Draft</option>
- <option value="published" <?= ($editingPage['status'] ?? '') === 'published' ? 'selected' : '' ?>>Published</option>
- </select>
-
- <div class="publish-actions">
- <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save page</button>
- <a href="dashboard.php?view=pages" class="dash-btn"><?= Icons::icon('x', 'icon icon-sm') ?>Cancel</a>
- </div>
- </form>
- </div>
-
- <?= Asset::js('assets/block-editor.js') ?>
- <?php require_once __DIR__ . '/../includes/ai.php'; ?>
- <?= Ai::widgetMarkup() ?>
- <?php endif; ?>
-