Add visual header and footer layout editors

This commit is contained in:
2026-11-23 20:30:11 +08:00
parent 4e3964a6eb
commit 636788b65c
16 changed files with 714 additions and 95 deletions
+5 -1
View File
@@ -125,7 +125,11 @@ final class DesignLibrary
}
}
$clean['components'] = array_values(array_unique($components));
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
try {
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
} catch (RuntimeException $error) {
throw new DesignFieldError('links', $error->getMessage());
}
try {
$clean['action'] = Buttons::validate($data['action'] ?? []);
} catch (RuntimeException $error) {
+1
View File
@@ -319,6 +319,7 @@ class AdminController
return $this->render($request, 'admin-page', [
'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
'pageTemplateDrawer' => true, 'designs' => DesignLibrary::all(),
'layoutDefaults' => array_intersect_key($repo->site(), ['header_id' => true, 'footer_id' => true]),
], $error !== '' ? 422 : 200);
}
+16 -5
View File
@@ -43,7 +43,8 @@ final class DesignController extends AdminController
$field = '';
$secret = '';
$links = SiteDesign::linkText($item['payload']['links'] ?? []);
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
$site = (new Repository())->site();
$default = $id === null ? $request->get('default') === '1' : ($site[$kind . '_id'] ?? null) === $id;
if ($request->method() === 'POST') {
try {
$savedProvider = $item['payload']['provider'] ?? [];
@@ -73,10 +74,19 @@ final class DesignController extends AdminController
}
$secret = $this->input($request, 'provider_secret', trimValue: false);
}
try {
$item['payload']['links'] = SiteDesign::parseLinks($links);
} catch (RuntimeException $ex) {
throw new DesignFieldError('links', $ex->getMessage());
if ($request->post('canvas_links') !== null) {
$draftLinks = json_decode($this->input($request, 'canvas_links'), true);
if (!is_array($draftLinks) || !array_is_list($draftLinks)
|| array_filter($draftLinks, 'is_array') !== $draftLinks) {
throw new DesignFieldError('links', '导航链接格式无效。');
}
$item['payload']['links'] = $draftLinks;
} else {
try {
$item['payload']['links'] = SiteDesign::parseLinks($links);
} catch (RuntimeException $ex) {
throw new DesignFieldError('links', $ex->getMessage());
}
}
}
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret);
@@ -98,6 +108,7 @@ final class DesignController extends AdminController
return $this->render($request, 'admin-design-edit', [
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '',
'layoutEditor' => $kind !== 'palette', 'wideAdmin' => $kind !== 'palette', 'siteName' => $site['name'],
'saved' => $error === '' && $request->get('saved') === '1',
], $error === '' ? 200 : 422);
}
+119 -65
View File
@@ -1,5 +1,6 @@
<?php
use App\Content\Buttons;
use App\Content\Database;
use App\Content\DesignLibrary;
use App\Content\View;
@@ -23,80 +24,133 @@ $fieldError = static function (string $name) use ($errorId, $field, $error, $e):
<?php if ($key !== 'new'): ?><a class="button button-outline" href="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>/preview" target="_blank" rel="noopener noreferrer">预览已保存的配置</a><?php endif ?>
</header>
<?= View::fragment('admin-feedback', ['error' => $field === '' ? $error : '', 'saved' => $saved]) ?>
<form class="admin-form admin-panel" method="post" action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>">
<form class="admin-form<?= $layoutEditor ? ' design-editor' : ' admin-panel' ?>" method="post"
action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>"<?= $layoutEditor ? ' data-layout-editor="' . $e($kind) . '" data-site-name="' . $e($siteName) . '"' : '' ?>>
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
<label>布局模板<select name="preset" data-layout-preset<?= $describe('preset') ?>>
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
<option value="<?= $e($preset) ?>" <?= $preset === $item['preset'] ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?>
</select><?php $fieldError('preset'); ?></label>
<?php if ($kind === 'palette'): ?>
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
<input type="hidden" name="preset" value="custom">
<?php $fieldError('preset'); ?>
<div class="palette-fields">
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
<label><?= $e($label) ?><input type="<?= $field === $color ? 'text' : 'color' ?>" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"<?= $describe($color) ?>><?php $fieldError($color); ?></label>
<?php endforeach ?>
</div>
<div class="form-submit"><button type="submit" class="button button-primary">保存配置</button></div>
<?php else: ?>
<fieldset class="admin-options"<?= $describe('components') ?>><legend>组件及顺序</legend>
<ul class="admin-list layout-components" data-layout-components>
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
<li><label><input type="checkbox" name="components[]" value="<?= $e($component) ?>" <?= in_array($component, $data['components'], true) ? 'checked' : '' ?>><?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?></label>
<div class="actions"><button type="button" class="button button-outline" data-component-move="-1">上移</button><button type="button" class="button button-outline" data-component-move="1">下移</button></div></li>
<?php endforeach ?>
</ul>
<?php $fieldError('components'); ?>
</fieldset>
<div class="form-grid">
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
<div>
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
<?php $fieldError('logo'); ?>
</div>
<div class="admin-panel design-editor-bar">
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
<label><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></label>
<button type="submit" class="button button-primary">保存配置</button>
</div>
<div class="design-editor-grid">
<div class="design-editor-main">
<section class="admin-panel design-canvas" data-layout-workspace hidden aria-labelledby="design-canvas-title">
<div class="admin-heading compact">
<h2 id="design-canvas-title">编辑画布</h2>
<div class="preview-selector" role="group" aria-label="预览尺寸">
<button type="button" class="button button-outline" data-layout-viewport="desktop" aria-pressed="true">桌面</button>
<button type="button" class="button button-outline" data-layout-viewport="phone" aria-pressed="false">手机</button>
</div>
</div>
<div class="design-canvas-stage">
<div class="design-canvas-viewport">
<iframe data-layout-frame sandbox="allow-same-origin" title="可编辑的<?= $kind === 'header' ? '页头' : '页脚' ?>画布"
srcdoc="<?= $e(View::fragment('design-layout-document', ['kind' => $kind, 'preset' => array_key_first(DesignLibrary::PRESETS[$kind]), 'layoutEditor' => true])) ?>"></iframe>
</div>
<p class="field-note" data-layout-empty hidden>勾选组件,添加到画布。</p>
</div>
<p class="field-note">点击画布中的文字可直接修改。链接、图片和用户区在组件面板设置。</p>
</section>
<fieldset class="admin-panel design-templates"<?= $describe('preset') ?>>
<legend>布局模板</legend>
<div class="design-template-grid">
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
<label class="design-template-choice">
<span class="design-template-image">
<iframe aria-hidden="true" tabindex="-1" inert title="<?= $e($label) ?>缩略预览" sandbox
srcdoc="<?= $e(View::fragment('design-layout-document', ['kind' => $kind, 'preset' => $preset, 'layoutEditor' => false])) ?>"></iframe>
</span>
<span class="design-template-caption"><input type="radio" name="preset" value="<?= $e($preset) ?>" data-layout-preset required <?= $preset === $item['preset'] ? 'checked' : '' ?>><?= $e($label) ?></span>
</label>
<?php endforeach ?>
</div>
<?php $fieldError('preset'); ?>
</fieldset>
</div>
<aside class="admin-panel design-editor-inspector" aria-label="组件和属性">
<fieldset class="admin-options design-component-panel"<?= $describe('components') ?>>
<legend>组件</legend>
<ul class="admin-list layout-components" data-layout-components>
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
<li data-layout-layer="<?= $e($component) ?>">
<label><input type="checkbox" name="components[]" value="<?= $e($component) ?>" <?= in_array($component, $data['components'], true) ? 'checked' : '' ?>><?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?></label>
<div class="actions">
<button type="button" class="button button-outline" data-layout-select="<?= $e($component) ?>" aria-label="编辑<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="编辑<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" hidden><?= View::fragment('studio-icon', ['icon' => 'edit']) ?></button>
<button type="button" class="button button-outline" data-component-move="-1" aria-label="上移<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="上移">↑</button>
<button type="button" class="button button-outline" data-component-move="1" aria-label="下移<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="下移">↓</button>
</div>
</li>
<?php endforeach ?>
</ul>
<?php $fieldError('components'); ?>
</fieldset>
<fieldset class="admin-options design-properties" data-layout-panel="brand">
<legend>站点标识</legend>
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
<div>
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
<?php $fieldError('logo'); ?>
</div>
</fieldset>
<fieldset class="admin-options design-properties" data-layout-panel="links"<?= $describe('links') ?>>
<legend><?= $kind === 'header' ? '导航链接' : '页脚链接' ?></legend>
<label data-layout-legacy-links>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small></label>
<input type="hidden" name="canvas_links" value="<?= $e(Database::json($data['links'] ?? [])) ?>" disabled>
<div data-layout-link-editor hidden>
<div class="design-link-rows" data-layout-link-rows></div>
<button class="button button-outline" type="button" data-layout-link-add>添加链接</button>
<template data-layout-link-template>
<div class="design-link-row">
<label>文案<input maxlength="70" data-layout-link-field="1"></label>
<label>地址<input maxlength="1000" data-layout-link-field="0" placeholder="/articles"></label>
<div class="design-link-controls">
<button class="button button-outline" type="button" data-layout-link-move="-1" title="上移链接" aria-label="上移链接">↑</button>
<button class="button button-outline" type="button" data-layout-link-move="1" title="下移链接" aria-label="下移链接">↓</button>
<button class="button button-outline" type="button" data-layout-link-remove title="删除链接" aria-label="删除链接"><?= View::fragment('studio-icon', ['icon' => 'delete']) ?></button>
</div>
</div>
</template>
</div>
<?php $fieldError('links'); ?>
</fieldset>
<?php if ($kind === 'header'): ?>
<fieldset class="admin-options design-properties" data-layout-panel="action"<?= $describe('action') ?>>
<legend>行动按钮</legend>
<label>文案<input name="action_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></label>
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?></select></label>
<label><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</label>
<?php $fieldError('action'); ?>
</fieldset>
<div data-layout-panel="account">
<?= View::fragment('design-provider-fields', compact('item', 'provider', 'e', 'describe', 'fieldError', 'reenterSecret', 'field') + ['components' => $data['components']]) ?>
</div>
<?php else: ?>
<fieldset class="admin-options design-properties" data-layout-panel="text">
<legend>说明文字</legend>
<label>内容<textarea name="text" rows="3" maxlength="1200"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
</fieldset>
<fieldset class="admin-options design-properties" data-layout-panel="legal">
<legend>版权文字</legend>
<label>内容<input name="legal" maxlength="300" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
</fieldset>
<?php endif ?>
</aside>
</div>
<label>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small><?php $fieldError('links'); ?></label>
<?php if ($kind === 'header'): ?>
<fieldset class="admin-options form-grid"<?= $describe('action') ?>><legend>行动按钮</legend>
<label>文案<input name="action_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></label>
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?></select></label>
<label><span><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</span></label>
<?php $fieldError('action'); ?>
</fieldset>
<fieldset class="admin-options form-grid" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $data['components']) ? '' : ' hidden' ?>><legend>用户区认证</legend>
<label>认证方式<select name="provider_mode"<?= $describe('provider_mode') ?>><option value="">关闭</option>
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?>
</select><?php $fieldError('provider_mode'); ?></label>
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"<?= $describe('provider_client_id') ?>><?php $fieldError('provider_client_id'); ?></label>
<label data-provider-field>客户端密钥
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password"<?= $describe('provider_secret') ?>>
<?php $fieldError('provider_secret'); ?>
<?php if ($reenterSecret && $field !== 'provider_secret'): ?><small>请重新输入本次提交的客户端密钥。</small><?php endif ?>
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
</label>
<label data-provider-field>令牌端点认证<select name="provider_token_auth"<?= $describe('provider_token_auth') ?>>
<?php foreach (['' => '自动', 'client_secret_basic' => 'HTTP Basic', 'client_secret_post' => '表单客户端密钥'] as $method => $label): ?>
<option value="<?= $e($method) ?>" <?= ($provider['token_auth'] ?? '') === $method ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?>
</select><?php $fieldError('provider_token_auth'); ?></label>
<label data-provider-field>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"<?= $describe('provider_scope') ?>><?php $fieldError('provider_scope'); ?></label>
<label data-provider-mode="oidc">OIDC Issuer<input name="provider_issuer" value="<?= $e($provider['issuer'] ?? '') ?>" placeholder="https://id.example.com"<?= $describe('provider_issuer') ?>><?php $fieldError('provider_issuer'); ?></label>
<?php foreach (['authorization' => '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?>
<label data-provider-mode="oauth2"><?= $e($label) ?><input name="provider_<?= $e($providerField) ?>" value="<?= $e($provider[$providerField] ?? '') ?>"<?= $describe('provider_' . $providerField) ?>><?php $fieldError('provider_' . $providerField); ?></label>
<?php endforeach ?>
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
</fieldset>
<?php else: ?>
<label>说明文字<textarea name="text" rows="3"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
<label>版权文字<input name="legal" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
<?php endif ?>
<label><span><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></span></label>
<?php endif ?>
<button type="submit" class="button button-primary">保存配置</button>
</form>
+4
View File
@@ -24,6 +24,10 @@ $active = match (true) {
<script src="/assets/jquery-4.0.0.min.js" defer></script>
<script src="/assets/admin.js" defer></script>
<script src="/assets/studio.js" defer></script>
<?php if (!empty($layoutEditor)): ?>
<link rel="stylesheet" href="/assets/design-editor.css">
<script src="/assets/design-editor.js" defer></script>
<?php endif ?>
<?php if (!empty($pageTemplateDrawer)): ?>
<link rel="stylesheet" href="/assets/page-template-drawer.css">
<script src="/assets/page-template-drawer.js" defer></script>
+5
View File
@@ -16,6 +16,11 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span></p></div>
<div class="actions">
<a class="button button-outline" href="#studio-page-settings">页面设置</a>
<?php foreach (['header' => '编辑页头', 'footer' => '编辑页脚'] as $kind => $label): ?>
<?php $default = $layoutDefaults[$kind . '_id'] ?? ''; $id = $page[$kind . '_id'] ?? $default; ?>
<a class="button button-outline" data-page-layout-editor="<?= $kind ?>" data-default-id="<?= $e($default) ?>"
href="/admin/design/<?= $kind ?>/<?= $id ? $e($id) : 'new?default=1' ?>" target="_blank" rel="noopener"><?= $label ?></a>
<?php endforeach ?>
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
<?php if ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
<a class="button button-outline" href="<?= $e($previewUrl) ?>" target="_blank" rel="noopener">打开预览</a>
+31
View File
@@ -0,0 +1,31 @@
<?php
use App\Content\DesignLibrary;
use App\Content\View;
$layout = [
'id' => 0,
'preset' => $preset,
'payload' => array_replace(DesignLibrary::defaults($kind), [
'brand' => '品牌名称',
'text' => '关于网站的一句话介绍。',
'links' => $layoutEditor ? [] : [['/', '首页'], ['/articles', '文章']],
'legal' => '© 品牌名称',
'action' => [['/articles', '了解更多', 'solid', false]],
]),
];
?>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/assets/site.css">
<link rel="stylesheet" href="/assets/design-editor.css">
</head>
<body class="design-frame <?= $layoutEditor ? 'design-frame-editing' : 'design-frame-sample' ?>">
<?= View::fragment($kind, [
$kind => $layout, 'site' => ['name' => '品牌名称'], 'showHeader' => true, 'showFooter' => true,
'path' => '/', 'visitor' => null, 'member' => $preset === 'member', 'layoutEditor' => $layoutEditor,
]) ?>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
<?php
use App\Content\DesignLibrary;
use App\Content\View;
?>
<fieldset class="admin-options design-properties" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $components) ? '' : ' hidden' ?>><legend>用户区认证</legend>
<label>认证方式<select name="provider_mode"<?= $describe('provider_mode') ?>><option value="">关闭</option>
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?>
</select><?php $fieldError('provider_mode'); ?></label>
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"<?= $describe('provider_client_id') ?>><?php $fieldError('provider_client_id'); ?></label>
<label data-provider-field>客户端密钥
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password"<?= $describe('provider_secret') ?>>
<?php $fieldError('provider_secret'); ?>
<?php if ($reenterSecret && $field !== 'provider_secret'): ?><small>请重新输入本次提交的客户端密钥。</small><?php endif ?>
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
</label>
<label data-provider-field>令牌端点认证<select name="provider_token_auth"<?= $describe('provider_token_auth') ?>>
<?php foreach (['' => '自动', 'client_secret_basic' => 'HTTP Basic', 'client_secret_post' => '表单客户端密钥'] as $method => $label): ?>
<option value="<?= $e($method) ?>" <?= ($provider['token_auth'] ?? '') === $method ? 'selected' : '' ?>><?= $e($label) ?></option>
<?php endforeach ?>
</select><?php $fieldError('provider_token_auth'); ?></label>
<label data-provider-field>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"<?= $describe('provider_scope') ?>><?php $fieldError('provider_scope'); ?></label>
<label data-provider-mode="oidc">OIDC Issuer<input name="provider_issuer" value="<?= $e($provider['issuer'] ?? '') ?>" placeholder="https://id.example.com"<?= $describe('provider_issuer') ?>><?php $fieldError('provider_issuer'); ?></label>
<?php foreach (['authorization' => '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?>
<label data-provider-mode="oauth2"><?= $e($label) ?><input name="provider_<?= $e($providerField) ?>" value="<?= $e($provider[$providerField] ?? '') ?>"<?= $describe('provider_' . $providerField) ?>><?php $fieldError('provider_' . $providerField); ?></label>
<?php endforeach ?>
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
</fieldset>
+11 -8
View File
@@ -4,22 +4,25 @@ use App\Content\View;
$e = View::escape(...);
$data = $footer['payload'];
$brand = $data['brand'] ?: $site['name'];
$layoutEditor ??= false;
$part = static fn (string $component): string => $layoutEditor ? ' data-layout-component="' . $component . '"' : '';
?>
<footer class="site-footer site-footer-<?= $e($footer['preset']) ?>" id="contact"<?= $showFooter ? '' : ' hidden' ?>>
<div class="wrap site-footer-components">
<?php foreach ($data['components'] as $component): ?>
<?php if ($component === 'brand'): ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页">
<?php if ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>" loading="lazy"><?php else: ?><?= $e($brand) ?><?php endif ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页"<?= $part('brand') ?>>
<?php if ($layoutEditor): ?><img alt="" hidden><span data-layout-text="brand"></span>
<?php elseif ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>" loading="lazy"><?php else: ?><?= $e($brand) ?><?php endif ?>
</a>
<?php elseif ($component === 'text' && $data['text'] !== ''): ?>
<p class="site-footer-text"><?= $e($data['text']) ?></p>
<?php elseif ($component === 'links' && $data['links']): ?>
<nav class="site-footer-nav" aria-label="页脚导航">
<?php elseif ($component === 'text' && ($layoutEditor || $data['text'] !== '')): ?>
<p class="site-footer-text"<?= $part('text') ?><?= $layoutEditor ? ' data-layout-text="text"' : '' ?>><?= $e($data['text']) ?></p>
<?php elseif ($component === 'links' && ($layoutEditor || $data['links'])): ?>
<nav class="site-footer-nav" aria-label="页脚导航"<?= $part('links') ?>>
<?php foreach ($data['links'] as [$url, $label]): ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a><?php endforeach ?>
</nav>
<?php elseif ($component === 'legal' && $data['legal'] !== ''): ?>
<small><?= $e($data['legal']) ?></small>
<?php elseif ($component === 'legal' && ($layoutEditor || $data['legal'] !== '')): ?>
<small<?= $part('legal') ?><?= $layoutEditor ? ' data-layout-text="legal"' : '' ?>><?= $e($data['legal']) ?></small>
<?php endif ?>
<?php endforeach ?>
</div>
+14 -9
View File
@@ -5,27 +5,32 @@ use App\Content\View;
$e = View::escape(...);
$data = $header['payload'];
$brand = $data['brand'] ?: $site['name'];
$layoutEditor ??= false;
$part = static fn (string $component): string => $layoutEditor ? ' data-layout-component="' . $component . '"' : '';
?>
<header class="masthead masthead-<?= $e($header['preset']) ?>"<?= $showHeader ? '' : ' hidden' ?>>
<div class="wrap masthead-inner">
<?php foreach ($data['components'] as $component): ?>
<?php if ($component === 'brand'): ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页">
<?php if ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页"<?= $part('brand') ?>>
<?php if ($layoutEditor): ?><img alt="" hidden><span data-layout-text="brand"></span>
<?php elseif ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
</a>
<?php elseif ($component === 'links' && $data['links']): ?>
<?php elseif ($component === 'links' && ($layoutEditor || $data['links'])): ?>
<?php if (!$layoutEditor): ?>
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
<span></span><span></span><span class="sr-only">菜单</span>
</button>
<nav id="primary-navigation" class="primary-nav" aria-label="主导航">
<?php endif ?>
<nav id="primary-navigation" class="primary-nav" aria-label="主导航"<?= $part('links') ?>>
<?php foreach ($data['links'] as [$url, $label]): ?>
<a href="<?= $e($url) ?>"<?= $url === $path ? ' aria-current="page"' : '' ?>><?= $e($label) ?></a>
<?php endforeach ?>
</nav>
<?php elseif ($component === 'action' && $data['action']): ?>
<?php [$url, $label, $style, $blank] = $data['action'][0]; ?>
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?>><?= $e($label) ?></a>
<?php elseif ($component === 'account' && $member): ?>
<?php elseif ($component === 'action' && ($layoutEditor || $data['action'])): ?>
<?php [$url, $label, $style, $blank] = $data['action'][0] ?? ['/', '', 'outline', false]; ?>
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?><?= $part('action') ?><?= $layoutEditor ? ' data-layout-text="action_label"' : '' ?>><?= $e($label) ?></a>
<?php elseif ($component === 'account' && ($layoutEditor || $member)): ?>
<?php if ($visitor): ?>
<a class="site-account" href="/account" aria-label="打开用户中心">
<?php if ($visitor['avatar'] !== ''): ?><img class="account-avatar" src="<?= $e($visitor['avatar']) ?>" alt="" width="36" height="36"><?php else: ?>
@@ -33,7 +38,7 @@ $brand = $data['brand'] ?: $site['name'];
<?php endif ?>
</a>
<?php else: ?>
<a class="button button-outline site-account" href="/account/login/<?= $e($header['id']) ?>">登录</a>
<a class="button button-outline site-account" href="/account/login/<?= $e($header['id']) ?>"<?= $part('account') ?>>登录</a>
<?php endif ?>
<?php endif ?>
<?php endforeach ?>