Files
laysense.cn/app/view/admin-dashboard.php
T

88 lines
5.7 KiB
PHP

<?php
use App\Content\LayoutPage;
use App\Content\SystemPage;
use App\Content\View;
$e = View::escape(...);
$pageTypeLabels = LayoutPage::TYPES + SystemPage::TYPES;
$regular = array_filter($pages, static fn (array $page): bool => $page['layout_kind'] === null && $page['page_type'] === 'page');
$live = count(array_filter($regular, static fn (array $page): bool => $page['status'] === 'published'));
$defaultSlugs = [];
foreach (['header', 'footer'] as $kind) {
if (isset($site[$kind . '_id'])) {
$defaultSlugs[$kind] = LayoutPage::slug($kind, $site[$kind . '_id']);
}
}
?>
<header class="admin-heading dashboard-heading">
<h1>网站后台</h1>
<div class="actions">
<a class="button button-primary" href="/admin/new-page"><?= View::fragment('studio-icon', ['icon' => 'add']) ?>新建页面</a>
<button type="button" class="button button-outline" data-open-page-templates hidden><?= View::fragment('studio-icon', ['icon' => 'templates']) ?>整页模板</button>
<a class="button button-outline" href="/admin/articles/new"><?= View::fragment('studio-icon', ['icon' => 'edit']) ?>写文章</a>
</div>
</header>
<div class="dashboard-grid">
<section class="admin-panel dashboard-pages" aria-labelledby="pages-title" data-page-list>
<div class="admin-heading compact">
<h2 id="pages-title">网站页面</h2>
<p class="field-note"><?= $live ?> 个已发布 · <?= count($regular) - $live ?> 个草稿 · <?= count($pages) - count($regular) ?> 个特殊页面</p>
</div>
<div class="dashboard-filters" data-page-filters hidden>
<label>查找页面<input type="search" data-page-search placeholder="页面名称或地址"></label>
<label>状态或类型<select data-page-status>
<option value="">全部页面</option>
<option value="published">已发布</option>
<option value="draft">草稿</option>
<option value="header">页头</option>
<option value="footer">页脚</option>
<?php foreach (SystemPage::TYPES as $type => $label): ?><option value="<?= $e($type) ?>"><?= $e($label) ?></option><?php endforeach ?>
</select></label>
</div>
<p class="empty-state" data-page-empty role="status"<?= $pages ? ' hidden' : '' ?>><?= $pages ? '没有匹配的页面。' : '暂无页面。' ?></p>
<ul class="admin-list dashboard-page-list">
<?php foreach ($pages as $page): ?>
<?php
$type = $page['page_type'];
$kind = $page['layout_kind'] ?? (isset(SystemPage::TYPES[$type]) ? $type : null);
$label = $kind === null ? '' : ($pageTypeLabels[$kind] ?? '');
$path = $page['slug'] === 'home' ? '/' : '/' . $page['slug'];
$published = $page['status'] === 'published';
$public = $kind === null && $published;
?>
<li data-page-item="<?= $e($kind ?? $page['status']) ?>" data-page-label="<?= $e($page['name'] . ' ' . $page['title'] . ' ' . ($kind ? $label : $path)) ?>">
<div class="dashboard-page-label"><strong><?= $e($page['name']) ?></strong>
<?php if ($kind === null): ?><small><?= $e($path) ?></small>
<?php elseif (($defaultSlugs[$kind] ?? null) === $page['slug']): ?><small>站点默认</small>
<?php elseif (($site['system_pages'][$kind] ?? null) === $page['slug']): ?><small><?= $kind === 'maintenance' ? ($site['maintenance_enabled'] ? '维护模式已开启' : '已选作维护页') : '已启用为 404 页' ?></small><?php endif ?>
</div>
<span class="dashboard-page-state" data-published="<?= !$page['layout_kind'] && $published ? 'true' : 'false' ?>"><?= $kind ? $e($label) : ($published ? '已发布' : '草稿') ?><?= isset(SystemPage::TYPES[$type]) ? ($published ? ' · 已发布' : ' · 草稿') : '' ?></span>
<div class="dashboard-page-actions">
<a class="button button-outline" href="/admin/pages/<?= $e($page['slug']) ?>"><?= View::fragment('studio-icon', ['icon' => 'edit']) ?>编辑页面</a>
<?= View::fragment('admin-view-link', [
'href' => $public ? $path : '/admin/pages/' . $page['slug'] . '/preview',
'icon' => $public ? 'external' : 'preview',
'label' => ($public ? '查看公开页面' : '预览页面') . ' · ' . $page['name'],
]) ?>
</div>
</li>
<?php endforeach ?>
</ul>
</section>
<div class="dashboard-secondary">
<section class="admin-panel" aria-labelledby="recent-title">
<div class="admin-heading compact"><h2 id="recent-title">最近编辑的文章</h2></div>
<?= View::fragment('admin-article-list', ['articles' => $articles]) ?>
<a class="back-link" href="/admin/articles">管理全部文章</a>
</section>
<section class="admin-panel dashboard-settings" aria-labelledby="quick-title">
<h2 id="quick-title">站点编辑</h2>
<ul class="dashboard-setting-buttons">
<li><a class="button button-outline" href="/admin/settings"><?= View::fragment('studio-icon', ['icon' => 'settings']) ?>站点设置</a></li>
<li><a class="button button-outline" href="/admin/media"><?= View::fragment('studio-icon', ['icon' => 'media']) ?>打开媒体库</a></li>
</ul>
</section>
</div>
</div>
<?= View::fragment('studio-page-templates', compact('token')) ?>