forked from laysense/laysite
95 lines
6.7 KiB
PHP
95 lines
6.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 && in_array($page['page_type'], ['page', 'home'], true));
|
|
$live = count(array_filter($regular, static fn (array $page): bool => $page['status'] === 'published'));
|
|
?>
|
|
<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>
|
|
<?php if ($deleted): ?><p class="feedback success" data-save-confirmation role="status">页面已删除。</p><?php endif ?>
|
|
<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="home">首页</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'] ?? ($type !== 'page' ? $type : null);
|
|
$label = $kind === null ? '' : ($pageTypeLabels[$kind] ?? '');
|
|
$home = $type === 'home';
|
|
$path = '/' . $page['slug'];
|
|
$deleteNote = '确定删除「' . $page['name'] . '」?此操作不可撤销。';
|
|
if ($home) {
|
|
$deleteNote .= '删除后,此页面将从首页候选中移除。';
|
|
}
|
|
$published = $page['status'] === 'published';
|
|
$public = ($kind === null || $home) && $published;
|
|
?>
|
|
<li data-page-item="<?= $e($kind ?? $page['status']) ?>" data-page-public-status="<?= $e($kind === null || $home ? $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 || $home): ?><small><?= $home ? '/ · ' : '' ?><?= $e($path) ?></small>
|
|
<?php elseif ($page['layout_id'] !== null && ($site[$kind . '_id'] ?? null) === $page['layout_id']): ?><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 ? '已发布' : '草稿') ?><?= ($home || 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'],
|
|
]) ?>
|
|
<form method="post" action="/admin/pages/<?= $e($page['slug']) ?>/delete">
|
|
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
|
<input type="hidden" name="version" value="<?= $e($page['version']) ?>">
|
|
<button class="button button-outline admin-view-link destructive-action" type="submit"
|
|
title="删除页面" aria-label="删除页面" data-confirm="<?= $e($deleteNote) ?>"><?= View::fragment('studio-icon', ['icon' => 'delete']) ?></button>
|
|
</form>
|
|
</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')) ?>
|