WebOrbiton
v2.0.0.0

Publisium

136 lines · 6.6 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (!Auth::hasRoleAtLeast(Auth::ROLE_MANAGING_EDITOR)) {
  6. echo '<p>Only managing editors and above can edit pages.</p>';
  7. return;
  8. }
  9. ​
  10. $db = Database::site();
  11. ​
  12. $editingHome = isset($_GET['home']);
  13. $pageId = $editingHome ? null : ((int) ($_GET['page_id'] ?? 0) ?: null);
  14. $editingPage = null;
  15. $showForm = !$editingHome && ($pageId !== null || isset($_GET['new']));
  16. ​
  17. if ($pageId !== null) {
  18. $statement = $db->prepare('SELECT * FROM pages WHERE id = :id LIMIT 1');
  19. $statement->execute(['id' => $pageId]);
  20. $editingPage = $statement->fetch() ?: null;
  21. }
  22. ​
  23. $pages = $db->query('SELECT * FROM pages ORDER BY sort_order ASC, title ASC')->fetchAll();
  24. $blocksJson = $editingPage['content_blocks'] ?? '{"blocks":[]}';
  25. ​
  26. ?>
  27. <div class="dash-header-row">
  28. <h1 class="dash-title"><?= Icons::icon("pages", "icon icon-lg") ?>Pages</h1>
  29. <?php if (!$showForm && !$editingHome): ?>
  30. <a href="dashboard.php?view=pages&new=1" class="dash-btn dash-btn-primary"><?= Icons::icon('plus', 'icon icon-sm') ?>New page</a>
  31. <?php endif; ?>
  32. </div>
  33. ​
  34. <table class="dash-table">
  35. <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>
  36. <tbody>
  37. <tr class="page-row-home">
  38. <td><?= Icons::icon('home', 'icon icon-sm') ?>Home page</td>
  39. <td><span class="status-pill status-published">Published</span></td>
  40. <td>Linked from the site name</td>
  41. <td class="dash-table-actions">
  42. <a href="dashboard.php?view=pages&home=1" class="dash-btn-small"><?= Icons::icon('edit', 'icon icon-sm') ?>Edit</a>
  43. <?php if (Languages::enabled()): ?>
  44. <a href="translate.php?type=home&id=1" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?>Translate</a>
  45. <?php endif; ?>
  46. <a href="<?= htmlspecialchars(SiteFront::homeUrl(''), ENT_QUOTES) ?>" target="_blank" rel="noopener" class="dash-btn-small"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a>
  47. </td>
  48. </tr>
  49. <?php foreach ($pages as $page): ?>
  50. <tr>
  51. <td><?= htmlspecialchars($page['title']) ?></td>
  52. <td><span class="status-pill status-<?= htmlspecialchars($page['status']) ?>"><?= htmlspecialchars(dashStatusLabel((string) $page['status'])) ?></span></td>
  53. <td><?= $page['show_in_menu'] ? 'Yes' : 'No' ?></td>
  54. <td class="dash-table-actions">
  55. <a href="dashboard.php?view=pages&page_id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('edit', 'icon icon-sm') ?>Edit</a>
  56. <?php if (Languages::enabled()): ?>
  57. <a href="translate.php?type=page&id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?>Translate</a>
  58. <?php endif; ?>
  59. <form method="post" style="display:inline;" onsubmit="return confirm('Delete this page? It disappears from the site right away.');">
  60. <?= Csrf::field() ?>
  61. <input type="hidden" name="action" value="delete_page">
  62. <input type="hidden" name="page_id" value="<?= (int) $page['id'] ?>">
  63. <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Delete</button>
  64. </form>
  65. </td>
  66. </tr>
  67. <?php endforeach; ?>
  68. </tbody>
  69. </table>
  70. ​
  71. <?php if ($editingHome): ?>
  72. <?php require_once __DIR__ . '/../includes/contact.php'; ?>
  73. <div class="sidebar-box" style="margin-top:20px;">
  74. <h2 class="dash-subtitle" style="margin-top:0;"><?= Icons::icon('home', 'icon icon-sm') ?>Edit home page</h2>
  75. <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>
  76. ​
  77. <form method="post" id="page-form">
  78. <?= Csrf::field() ?>
  79. <input type="hidden" name="action" value="save_homepage">
  80. <input type="hidden" name="blocks_json" id="blocks_json_input">
  81. ​
  82. <label><?= Icons::icon('layout', 'icon icon-sm') ?>Layout</label>
  83. <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>
  84. ​
  85. <div class="publish-actions">
  86. <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save home page</button>
  87. <a href="dashboard.php?view=pages" class="dash-btn"><?= Icons::icon('x', 'icon icon-sm') ?>Cancel</a>
  88. </div>
  89. </form>
  90. </div>
  91. ​
  92. <?= Asset::js('assets/block-editor.js') ?>
  93. <?php require_once __DIR__ . '/../includes/ai.php'; ?>
  94. <?= Ai::widgetMarkup() ?>
  95. <?php endif; ?>
  96. ​
  97. <?php if ($showForm): ?>
  98. <div class="sidebar-box" style="margin-top:20px;">
  99. <h2 class="dash-subtitle" style="margin-top:0;"><?= Icons::icon('pages', 'icon icon-sm') ?><?= $editingPage ? 'Edit page' : 'New page' ?></h2>
  100. ​
  101. <form method="post" id="page-form">
  102. <?= Csrf::field() ?>
  103. <input type="hidden" name="action" value="save_page">
  104. <?php if ($editingPage): ?>
  105. <input type="hidden" name="page_id" value="<?= (int) $editingPage['id'] ?>">
  106. <?php endif; ?>
  107. <input type="hidden" name="blocks_json" id="blocks_json_input">
  108. ​
  109. <label><?= Icons::icon('heading', 'icon icon-sm') ?>Title</label>
  110. <input type="text" name="title" value="<?= htmlspecialchars($editingPage['title'] ?? '') ?>" required>
  111. ​
  112. <label><?= Icons::icon('quote', 'icon icon-sm') ?>Content</label>
  113. <?php require_once __DIR__ . '/../includes/contact.php'; ?>
  114. <div id="block-editor-root" data-contact-form="<?= ContactForm::isEnabled() ? 'enabled' : 'disabled' ?>" data-initial-blocks='<?= htmlspecialchars($blocksJson, ENT_QUOTES) ?>'></div>
  115. ​
  116. <label><input type="checkbox" name="show_in_menu" <?= !empty($editingPage['show_in_menu']) ? 'checked' : '' ?>> Show in site menu</label>
  117. <label><input type="checkbox" name="noindex" <?= !empty($editingPage['noindex']) ? 'checked' : '' ?>> Hide from search engines (noindex)</label>
  118. ​
  119. <label><?= Icons::icon('flag', 'icon icon-sm') ?>Status</label>
  120. <select name="status">
  121. <option value="draft" <?= ($editingPage['status'] ?? 'draft') === 'draft' ? 'selected' : '' ?>>Draft</option>
  122. <option value="published" <?= ($editingPage['status'] ?? '') === 'published' ? 'selected' : '' ?>>Published</option>
  123. </select>
  124. ​
  125. <div class="publish-actions">
  126. <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save page</button>
  127. <a href="dashboard.php?view=pages" class="dash-btn"><?= Icons::icon('x', 'icon icon-sm') ?>Cancel</a>
  128. </div>
  129. </form>
  130. </div>
  131. ​
  132. <?= Asset::js('assets/block-editor.js') ?>
  133. <?php require_once __DIR__ . '/../includes/ai.php'; ?>
  134. <?= Ai::widgetMarkup() ?>
  135. <?php endif; ?>
  136. ​