Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
584455c66d |
@@ -8,6 +8,8 @@ use RuntimeException;
|
|||||||
|
|
||||||
final class Assets
|
final class Assets
|
||||||
{
|
{
|
||||||
|
public const DEFAULT_ICON = '/assets/system/laysite-mark.webp';
|
||||||
|
|
||||||
public static function cdn(string $value): string
|
public static function cdn(string $value): string
|
||||||
{
|
{
|
||||||
$value = rtrim(trim($value), '/');
|
$value = rtrim(trim($value), '/');
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Content;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
final class DesignFieldError extends RuntimeException
|
||||||
|
{
|
||||||
|
public function __construct(public readonly string $field, string $message)
|
||||||
|
{
|
||||||
|
parent::__construct($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -93,14 +93,14 @@ final class DesignLibrary
|
|||||||
public static function normalize(string $kind, string $preset, array $data): array
|
public static function normalize(string $kind, string $preset, array $data): array
|
||||||
{
|
{
|
||||||
if (!isset(self::PRESETS[$kind][$preset])) {
|
if (!isset(self::PRESETS[$kind][$preset])) {
|
||||||
throw new RuntimeException('请选择可用的组件模板。');
|
throw new DesignFieldError('preset', '请选择可用的组件模板。');
|
||||||
}
|
}
|
||||||
if ($kind === 'palette') {
|
if ($kind === 'palette') {
|
||||||
$colors = [];
|
$colors = [];
|
||||||
foreach (self::COLORS as $key => [, $default]) {
|
foreach (self::COLORS as $key => [, $default]) {
|
||||||
$color = $data[$key] ?? $default;
|
$color = $data[$key] ?? $default;
|
||||||
if (!is_string($color) || !preg_match('/^#[\da-f]{6}$/iD', $color)) {
|
if (!is_string($color) || !preg_match('/^#[\da-f]{6}$/iD', $color)) {
|
||||||
throw new RuntimeException('颜色必须使用六位十六进制表示。');
|
throw new DesignFieldError($key, '颜色必须使用六位十六进制表示。');
|
||||||
}
|
}
|
||||||
$colors[$key] = strtolower($color);
|
$colors[$key] = strtolower($color);
|
||||||
}
|
}
|
||||||
@@ -110,23 +110,27 @@ final class DesignLibrary
|
|||||||
|
|
||||||
$clean = self::defaults($kind);
|
$clean = self::defaults($kind);
|
||||||
foreach (['brand' => 100, 'text' => 1200, 'legal' => 300, 'logo' => 1000] as $field => $limit) {
|
foreach (['brand' => 100, 'text' => 1200, 'legal' => 300, 'logo' => 1000] as $field => $limit) {
|
||||||
$clean[$field] = self::string($data[$field] ?? '', $limit);
|
$clean[$field] = self::string($data[$field] ?? '', $limit, $field);
|
||||||
}
|
}
|
||||||
if ($clean['logo'] !== '' && !Html::url($clean['logo'], true)) {
|
if ($clean['logo'] !== '' && !Html::url($clean['logo'], true)) {
|
||||||
throw new RuntimeException('请检查站点标识地址。');
|
throw new DesignFieldError('logo', '请检查站点标识地址。');
|
||||||
}
|
}
|
||||||
$components = $data['components'] ?? $clean['components'];
|
$components = $data['components'] ?? $clean['components'];
|
||||||
if (!is_array($components) || !array_is_list($components)) {
|
if (!is_array($components) || !array_is_list($components)) {
|
||||||
throw new RuntimeException('组件顺序无效。');
|
throw new DesignFieldError('components', '组件顺序无效。');
|
||||||
}
|
}
|
||||||
foreach ($components as $component) {
|
foreach ($components as $component) {
|
||||||
if (!is_string($component) || !isset(self::COMPONENTS[$kind][$component])) {
|
if (!is_string($component) || !isset(self::COMPONENTS[$kind][$component])) {
|
||||||
throw new RuntimeException('布局包含未知组件。');
|
throw new DesignFieldError('components', '布局包含未知组件。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$clean['components'] = array_values(array_unique($components));
|
$clean['components'] = array_values(array_unique($components));
|
||||||
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
|
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
|
||||||
|
try {
|
||||||
$clean['action'] = Buttons::validate($data['action'] ?? []);
|
$clean['action'] = Buttons::validate($data['action'] ?? []);
|
||||||
|
} catch (RuntimeException $error) {
|
||||||
|
throw new DesignFieldError('action', $error->getMessage());
|
||||||
|
}
|
||||||
$clean['provider'] = $kind === 'header' && $preset === 'member'
|
$clean['provider'] = $kind === 'header' && $preset === 'member'
|
||||||
? self::provider($data['provider'] ?? []) : [];
|
? self::provider($data['provider'] ?? []) : [];
|
||||||
|
|
||||||
@@ -140,27 +144,27 @@ final class DesignLibrary
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (!in_array($mode, ['oidc', 'oauth2'], true)) {
|
if (!in_array($mode, ['oidc', 'oauth2'], true)) {
|
||||||
throw new RuntimeException('请选择 OIDC 或 OAuth 2.0。');
|
throw new DesignFieldError('provider_mode', '请选择 OIDC 或 OAuth 2.0。');
|
||||||
}
|
}
|
||||||
$result = ['mode' => $mode];
|
$result = ['mode' => $mode];
|
||||||
foreach (['client_id', 'scope', 'issuer', 'authorization', 'token', 'userinfo', 'subject_field', 'name_field', 'avatar_field', 'token_auth'] as $field) {
|
foreach (['client_id', 'scope', 'issuer', 'authorization', 'token', 'userinfo', 'subject_field', 'name_field', 'avatar_field', 'token_auth'] as $field) {
|
||||||
$result[$field] = self::string($data[$field] ?? '', 600);
|
$result[$field] = self::string($data[$field] ?? '', 600, 'provider_' . $field);
|
||||||
}
|
}
|
||||||
if (!in_array($result['token_auth'], ['', 'client_secret_basic', 'client_secret_post'], true)) {
|
if (!in_array($result['token_auth'], ['', 'client_secret_basic', 'client_secret_post'], true)) {
|
||||||
throw new RuntimeException('令牌端点认证方式无效。');
|
throw new DesignFieldError('provider_token_auth', '令牌端点认证方式无效。');
|
||||||
}
|
}
|
||||||
if ($result['client_id'] === '') {
|
if ($result['client_id'] === '') {
|
||||||
throw new RuntimeException('请填写客户端 ID。');
|
throw new DesignFieldError('provider_client_id', '请填写客户端 ID。');
|
||||||
}
|
}
|
||||||
foreach ($mode === 'oidc' ? ['issuer'] : ['authorization', 'token', 'userinfo'] as $field) {
|
foreach ($mode === 'oidc' ? ['issuer'] : ['authorization', 'token', 'userinfo'] as $field) {
|
||||||
$url = parse_url($result[$field]);
|
$url = parse_url($result[$field]);
|
||||||
if (!$url || ($url['scheme'] ?? '') !== 'https' || empty($url['host'])
|
if (!$url || ($url['scheme'] ?? '') !== 'https' || empty($url['host'])
|
||||||
|| isset($url['user']) || isset($url['pass']) || isset($url['fragment']) || ($field === 'issuer' && isset($url['query'])) || !Html::url($result[$field], true)) {
|
|| isset($url['user']) || isset($url['pass']) || isset($url['fragment']) || ($field === 'issuer' && isset($url['query'])) || !Html::url($result[$field], true)) {
|
||||||
throw new RuntimeException('认证端点必须使用完整的 HTTPS 地址。');
|
throw new DesignFieldError('provider_' . $field, '认证端点必须使用完整的 HTTPS 地址。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($mode === 'oauth2' && $result['subject_field'] === '') {
|
if ($mode === 'oauth2' && $result['subject_field'] === '') {
|
||||||
throw new RuntimeException('OAuth 2.0 用户资料需要指定稳定的用户 ID 字段。');
|
throw new DesignFieldError('provider_subject_field', 'OAuth 2.0 用户资料需要指定稳定的用户 ID 字段。');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -183,9 +187,9 @@ final class DesignLibrary
|
|||||||
|
|
||||||
public static function save(string $kind, ?int $id, string $name, string $preset, array $data, int $version, bool $default, string $secret = ''): int
|
public static function save(string $kind, ?int $id, string $name, string $preset, array $data, int $version, bool $default, string $secret = ''): int
|
||||||
{
|
{
|
||||||
$name = self::string($name, 100);
|
$name = self::string($name, 100, 'name');
|
||||||
if ($name === '') {
|
if ($name === '') {
|
||||||
throw new RuntimeException('请填写配置名称。');
|
throw new DesignFieldError('name', '请填写配置名称。');
|
||||||
}
|
}
|
||||||
$clean = self::normalize($kind, $preset, $data);
|
$clean = self::normalize($kind, $preset, $data);
|
||||||
$payload = Database::json($clean);
|
$payload = Database::json($clean);
|
||||||
@@ -198,7 +202,7 @@ final class DesignLibrary
|
|||||||
$fields = array_flip(['mode', 'issuer', 'authorization', 'token', 'userinfo', 'client_id']);
|
$fields = array_flip(['mode', 'issuer', 'authorization', 'token', 'userinfo', 'client_id']);
|
||||||
if (empty($saved['credential_revision'])
|
if (empty($saved['credential_revision'])
|
||||||
|| array_intersect_key($provider, $fields) !== array_intersect_key($saved['payload']['provider'], $fields)) {
|
|| array_intersect_key($provider, $fields) !== array_intersect_key($saved['payload']['provider'], $fields)) {
|
||||||
throw new RuntimeException('启用登录或变更身份提供商时,请填写客户端密钥。');
|
throw new DesignFieldError('provider_secret', '启用登录或变更身份提供商时,请填写客户端密钥。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($id === null) {
|
if ($id === null) {
|
||||||
@@ -232,10 +236,10 @@ final class DesignLibrary
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function string(mixed $value, int $limit): string
|
private static function string(mixed $value, int $limit, string $field): string
|
||||||
{
|
{
|
||||||
if (!is_string($value) || !mb_check_encoding($value, 'UTF-8') || mb_strlen($value) > $limit) {
|
if (!is_string($value) || !mb_check_encoding($value, 'UTF-8') || mb_strlen($value) > $limit) {
|
||||||
throw new RuntimeException('配置包含无效或过长的文字。');
|
throw new DesignFieldError($field, '配置包含无效或过长的文字。');
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim($value);
|
return trim($value);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ final class OAuthCredentials
|
|||||||
public static function store(PDO $pdo, int $layout, string $secret): void
|
public static function store(PDO $pdo, int $layout, string $secret): void
|
||||||
{
|
{
|
||||||
if ($secret === '' || strlen($secret) > 4096 || str_contains($secret, "\0")) {
|
if ($secret === '' || strlen($secret) > 4096 || str_contains($secret, "\0")) {
|
||||||
throw new RuntimeException('客户端密钥为空或格式无效。');
|
throw new DesignFieldError('provider_secret', '客户端密钥为空或格式无效。');
|
||||||
}
|
}
|
||||||
$revision = bin2hex(random_bytes(16));
|
$revision = bin2hex(random_bytes(16));
|
||||||
$nonce = random_bytes(self::NONCE_BYTES);
|
$nonce = random_bytes(self::NONCE_BYTES);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use RuntimeException;
|
|||||||
|
|
||||||
final class PageDraft
|
final class PageDraft
|
||||||
{
|
{
|
||||||
public const RESERVED = ['admin', 'assets', 'home', 'account', 'mcp', 'palette', 'favicon'];
|
public const RESERVED = ['admin', 'assets', 'home', 'account', 'mcp', 'palette'];
|
||||||
|
|
||||||
public static function slug(mixed $value, array $reserved = self::RESERVED): string
|
public static function slug(mixed $value, array $reserved = self::RESERVED): string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ final class SiteBackup
|
|||||||
}
|
}
|
||||||
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
|
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
|
||||||
foreach ($tables['pages'] as &$row) {
|
foreach ($tables['pages'] as &$row) {
|
||||||
PageDraft::slug($row['slug'] ?? null, ['admin', 'assets', 'account', 'mcp', 'palette', 'favicon']);
|
PageDraft::slug($row['slug'] ?? null, array_diff(PageDraft::RESERVED, ['home']));
|
||||||
self::validateAssetUrl($row['image'] ?? '', true);
|
self::validateAssetUrl($row['image'] ?? '', true);
|
||||||
$row['actions'] = Database::json(Buttons::validate(self::decode($row['actions'] ?? '[]')));
|
$row['actions'] = Database::json(Buttons::validate(self::decode($row['actions'] ?? '[]')));
|
||||||
$row['quicklinks'] = Database::json(Buttons::validate(self::decode($row['quicklinks'] ?? '[]'), 20));
|
$row['quicklinks'] = Database::json(Buttons::validate(self::decode($row['quicklinks'] ?? '[]'), 20));
|
||||||
|
|||||||
@@ -648,6 +648,7 @@ class AdminController
|
|||||||
if ($request->isAjax() && $status >= 400) {
|
if ($request->isAjax() && $status >= 400) {
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'message' => $data['error'] ?? $data['title'],
|
'message' => $data['error'] ?? $data['title'],
|
||||||
|
...(!empty($data['field']) ? ['field' => $data['field']] : []),
|
||||||
...($status === 403 ? ['csrf' => $token] : []),
|
...($status === 403 ? ['csrf' => $token] : []),
|
||||||
], $status);
|
], $status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Content\Assets;
|
use App\Content\Assets;
|
||||||
use App\Content\Buttons;
|
use App\Content\DesignFieldError;
|
||||||
use App\Content\DesignLibrary;
|
use App\Content\DesignLibrary;
|
||||||
use App\Content\Repository;
|
use App\Content\Repository;
|
||||||
use App\Content\SiteDesign;
|
use App\Content\SiteDesign;
|
||||||
@@ -40,13 +40,17 @@ final class DesignController extends AdminController
|
|||||||
return $this->error($request, '找不到这项设计配置。', 404);
|
return $this->error($request, '找不到这项设计配置。', 404);
|
||||||
}
|
}
|
||||||
$error = '';
|
$error = '';
|
||||||
|
$field = '';
|
||||||
|
$secret = '';
|
||||||
|
$links = SiteDesign::linkText($item['payload']['links'] ?? []);
|
||||||
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
|
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
|
||||||
if ($request->method() === 'POST') {
|
if ($request->method() === 'POST') {
|
||||||
try {
|
try {
|
||||||
$savedProvider = $item['payload']['provider'] ?? [];
|
$savedProvider = $item['payload']['provider'] ?? [];
|
||||||
$secret = '';
|
|
||||||
$item['name'] = $this->input($request, 'name');
|
$item['name'] = $this->input($request, 'name');
|
||||||
$item['preset'] = $this->input($request, 'preset');
|
$item['preset'] = $this->input($request, 'preset');
|
||||||
|
$item['version'] = $this->version($request);
|
||||||
|
$default = $request->post('make_default') === '1';
|
||||||
if ($kind === 'palette') {
|
if ($kind === 'palette') {
|
||||||
foreach (DesignLibrary::COLORS as $color => $definition) {
|
foreach (DesignLibrary::COLORS as $color => $definition) {
|
||||||
$item['payload'][$color] = $this->input($request, $color);
|
$item['payload'][$color] = $this->input($request, $color);
|
||||||
@@ -54,11 +58,11 @@ final class DesignController extends AdminController
|
|||||||
} else {
|
} else {
|
||||||
$url = $this->input($request, 'action_url');
|
$url = $this->input($request, 'action_url');
|
||||||
$label = $this->input($request, 'action_label');
|
$label = $this->input($request, 'action_label');
|
||||||
|
$links = $this->input($request, 'links', trimValue: false);
|
||||||
$item['payload'] = [
|
$item['payload'] = [
|
||||||
'components' => $request->post('components', []),
|
'components' => $request->post('components', []),
|
||||||
'brand' => $this->input($request, 'brand'), 'logo' => $this->input($request, 'logo'),
|
'brand' => $this->input($request, 'brand'), 'logo' => $this->input($request, 'logo'),
|
||||||
'text' => $this->input($request, 'text'), 'legal' => $this->input($request, 'legal'),
|
'text' => $this->input($request, 'text'), 'legal' => $this->input($request, 'legal'),
|
||||||
'links' => SiteDesign::parseLinks($this->input($request, 'links')),
|
|
||||||
'action' => $url === '' && $label === '' ? [] : [[$url, $label, $this->input($request, 'action_style'), $request->post('action_blank') === '1']],
|
'action' => $url === '' && $label === '' ? [] : [[$url, $label, $this->input($request, 'action_style'), $request->post('action_blank') === '1']],
|
||||||
'provider' => $savedProvider,
|
'provider' => $savedProvider,
|
||||||
];
|
];
|
||||||
@@ -69,20 +73,32 @@ final class DesignController extends AdminController
|
|||||||
}
|
}
|
||||||
$secret = $this->input($request, 'provider_secret', trimValue: false);
|
$secret = $this->input($request, 'provider_secret', trimValue: false);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
$item['payload']['links'] = SiteDesign::parseLinks($links);
|
||||||
|
} catch (RuntimeException $ex) {
|
||||||
|
throw new DesignFieldError('links', $ex->getMessage());
|
||||||
}
|
}
|
||||||
$default = $request->post('make_default') === '1';
|
}
|
||||||
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $this->version($request), $default, $secret);
|
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret);
|
||||||
|
|
||||||
return $this->success($request, "/admin/design/$kind/$id?saved=1");
|
return $this->success($request, "/admin/design/$kind/$id?saved=1");
|
||||||
} catch (RuntimeException $ex) {
|
} catch (RuntimeException $ex) {
|
||||||
$error = $this->validationMessage($ex);
|
$error = $this->validationMessage($ex);
|
||||||
$item['payload'] = DesignLibrary::defaults($kind);
|
$field = $ex instanceof DesignFieldError ? $ex->field : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($kind !== 'palette') {
|
||||||
|
$components = $item['payload']['components'];
|
||||||
|
$item['payload']['components'] = is_array($components) ? array_values(array_intersect(
|
||||||
|
array_filter($components, 'is_string'), array_keys(DesignLibrary::COMPONENTS[$kind])
|
||||||
|
)) : [];
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render($request, 'admin-design-edit', [
|
return $this->render($request, 'admin-design-edit', [
|
||||||
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
|
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
|
||||||
'error' => $error, 'saved' => $request->get('saved') === '1',
|
'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '',
|
||||||
|
'saved' => $error === '' && $request->get('saved') === '1',
|
||||||
], $error === '' ? 200 : 422);
|
], $error === '' ? 200 : 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,23 +23,22 @@ final class MediaController
|
|||||||
'Content-Type' => $media['mime'], 'X-Content-Type-Options' => 'nosniff',
|
'Content-Type' => $media['mime'], 'X-Content-Type-Options' => 'nosniff',
|
||||||
'Content-Security-Policy' => "default-src 'none'; sandbox",
|
'Content-Security-Policy' => "default-src 'none'; sandbox",
|
||||||
'Cache-Control' => 'public, max-age=31536000, immutable',
|
'Cache-Control' => 'public, max-age=31536000, immutable',
|
||||||
'Access-Control-Allow-Origin' => '*', 'Accept-Ranges' => 'bytes',
|
'Access-Control-Allow-Origin' => '*',
|
||||||
];
|
];
|
||||||
$range = $request->header('range');
|
$range = $request->header('range');
|
||||||
if ($range === null) {
|
if ($range === null) {
|
||||||
return (new Response(200, $headers + ['Content-Length' => (string) $length]))->withFile($path);
|
return (new Response(200, $headers))->withFile($path);
|
||||||
}
|
}
|
||||||
|
$unsatisfiable = $headers + ['Accept-Ranges' => 'bytes', 'Content-Range' => "bytes */$length"];
|
||||||
if (!preg_match('/^bytes=(\d*)-(\d*)$/D', $range, $parts) || $parts[1] === '' && $parts[2] === '') {
|
if (!preg_match('/^bytes=(\d*)-(\d*)$/D', $range, $parts) || $parts[1] === '' && $parts[2] === '') {
|
||||||
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
|
return new Response(416, $unsatisfiable);
|
||||||
}
|
}
|
||||||
$start = $parts[1] === '' ? max(0, $length - (int) $parts[2]) : (int) $parts[1];
|
$start = $parts[1] === '' ? max(0, $length - (int) $parts[2]) : (int) $parts[1];
|
||||||
$end = $parts[1] === '' || $parts[2] === '' ? $length - 1 : min($length - 1, (int) $parts[2]);
|
$end = $parts[1] === '' || $parts[2] === '' ? $length - 1 : min($length - 1, (int) $parts[2]);
|
||||||
if ($end < $start) {
|
if ($end < $start) {
|
||||||
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
|
return new Response(416, $unsatisfiable);
|
||||||
}
|
}
|
||||||
$count = $end - $start + 1;
|
|
||||||
|
|
||||||
return (new Response(206, $headers + ['Content-Length' => (string) $count, 'Content-Range' => "bytes $start-$end/$length"]))
|
return (new Response(206, $headers))->withFile($path, $start, $end - $start + 1);
|
||||||
->withFile($path, $start, $count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Content\Assets;
|
||||||
use App\Content\Html;
|
use App\Content\Html;
|
||||||
use App\Content\Repository;
|
use App\Content\Repository;
|
||||||
use App\Content\View;
|
use App\Content\View;
|
||||||
|
use FastRoute\Dispatcher;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
|
use Webman\Route;
|
||||||
|
|
||||||
final class SiteController
|
final class SiteController
|
||||||
{
|
{
|
||||||
@@ -215,14 +218,21 @@ final class SiteController
|
|||||||
"User-agent: *\nAllow: /\nDisallow: /admin\nSitemap: " . View::absolute('/sitemap.xml') . "\n");
|
"User-agent: *\nAllow: /\nDisallow: /admin\nSitemap: " . View::absolute('/sitemap.xml') . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function favicon(Request $request): Response
|
||||||
|
{
|
||||||
|
return View::redirect(Assets::DEFAULT_ICON, 301);
|
||||||
|
}
|
||||||
|
|
||||||
public function missing(Request $request): Response
|
public function missing(Request $request): Response
|
||||||
{
|
{
|
||||||
$path = $request->path();
|
$path = $request->path();
|
||||||
if ($request->method() === 'GET' && strlen($path) > 1 && str_ends_with($path, '/')) {
|
if (in_array($request->method(), ['GET', 'HEAD'], true) && strlen($path) > 1 && str_ends_with($path, '/')) {
|
||||||
$normal = rtrim($path, '/');
|
$normal = rtrim($path, '/');
|
||||||
|
$entry = preg_match('~^/(?:admin|account)(?:/|$)~D', $normal)
|
||||||
|
&& Route::dispatch($request->method(), $normal)[0] === Dispatcher::FOUND;
|
||||||
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
|
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
|
||||||
$known = $single && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published' && $normal !== '/home';
|
if ($entry || ($single && $normal !== '/home' && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published')
|
||||||
if ($known || preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
|| preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||||
$query = $request->queryString();
|
$query = $request->queryString();
|
||||||
|
|
||||||
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace App\Controller;
|
|||||||
use App\Content\BlockTemplates;
|
use App\Content\BlockTemplates;
|
||||||
use App\Content\Html;
|
use App\Content\Html;
|
||||||
use App\Content\Media;
|
use App\Content\Media;
|
||||||
|
use App\Content\PageDraft;
|
||||||
use App\Content\PageTemplates;
|
use App\Content\PageTemplates;
|
||||||
use App\Content\Repository;
|
use App\Content\Repository;
|
||||||
use App\Http\Request;
|
use App\Http\Request;
|
||||||
@@ -29,7 +30,7 @@ final class StudioController extends AdminController
|
|||||||
$data['name'] = $this->input($request, 'name');
|
$data['name'] = $this->input($request, 'name');
|
||||||
$data['slug'] = $this->input($request, 'slug');
|
$data['slug'] = $this->input($request, 'slug');
|
||||||
try {
|
try {
|
||||||
if (!$this->slug($data['slug']) || in_array($data['slug'], ['admin', 'assets', 'home', 'account', 'mcp', 'palette', 'favicon'], true)
|
if (!$this->slug($data['slug']) || in_array($data['slug'], PageDraft::RESERVED, true)
|
||||||
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||||
throw new RuntimeException('请填写页面名称及可用的网址标识。');
|
throw new RuntimeException('请填写页面名称及可用的网址标识。');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,84 +1,100 @@
|
|||||||
<?php
|
<?php
|
||||||
use App\Content\Buttons;
|
use App\Content\Buttons;
|
||||||
use App\Content\DesignLibrary;
|
use App\Content\DesignLibrary;
|
||||||
use App\Content\SiteDesign;
|
|
||||||
use App\Content\View;
|
use App\Content\View;
|
||||||
|
|
||||||
$e = View::escape(...);
|
$e = View::escape(...);
|
||||||
$data = $item['payload'];
|
$data = $item['payload'];
|
||||||
$action = $data['action'][0] ?? [];
|
$action = $data['action'][0] ?? [];
|
||||||
$provider = $data['provider'] ?? [];
|
$provider = $data['provider'] ?? [];
|
||||||
|
$errorId = static fn (string $name): string => 'design-error-' . View::escape($name);
|
||||||
|
$describe = static fn (string $name): string => ' aria-describedby="' . $errorId($name) . '"'
|
||||||
|
. ($field === $name ? ' aria-invalid="true"' : '');
|
||||||
|
$fieldError = static function (string $name) use ($errorId, $field, $error, $e): void {
|
||||||
|
$invalid = $field === $name;
|
||||||
|
?>
|
||||||
|
<small class="design-field-error" id="<?= $errorId($name) ?>" data-field-error="<?= $e($name) ?>" role="alert" tabindex="-1"<?= $invalid ? '' : ' hidden' ?>><?= $invalid ? $e($error) : '' ?></small>
|
||||||
|
<?php
|
||||||
|
};
|
||||||
?>
|
?>
|
||||||
<a class="back-link" href="/admin/design">返回站点设计</a>
|
<a class="back-link" href="/admin/design">返回站点设计</a>
|
||||||
<header class="admin-heading">
|
<header class="admin-heading">
|
||||||
<h1><?= $e(['header' => '页头组件', 'footer' => '页脚组件', 'palette' => '配色方案'][$kind]) ?></h1>
|
<h1><?= $e(['header' => '页头组件', 'footer' => '页脚组件', 'palette' => '配色方案'][$kind]) ?></h1>
|
||||||
<?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 ?>
|
<?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>
|
</header>
|
||||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
<?= 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 admin-panel" method="post" action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>">
|
||||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||||
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
||||||
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required></label>
|
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
||||||
<label>布局模板<select name="preset" data-layout-preset>
|
<label>布局模板<select name="preset" data-layout-preset<?= $describe('preset') ?>>
|
||||||
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
|
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
|
||||||
<option value="<?= $e($preset) ?>" <?= $preset === $item['preset'] ? 'selected' : '' ?>><?= $e($label) ?></option>
|
<option value="<?= $e($preset) ?>" <?= $preset === $item['preset'] ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</select></label>
|
</select><?php $fieldError('preset'); ?></label>
|
||||||
<?php if ($kind === 'palette'): ?>
|
<?php if ($kind === 'palette'): ?>
|
||||||
<div class="palette-fields">
|
<div class="palette-fields">
|
||||||
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
|
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
|
||||||
<label><?= $e($label) ?><input type="color" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"></label>
|
<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 ?>
|
<?php endforeach ?>
|
||||||
</div>
|
</div>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<fieldset class="admin-options"><legend>组件及顺序</legend>
|
<fieldset class="admin-options"<?= $describe('components') ?>><legend>组件及顺序</legend>
|
||||||
<ul class="admin-list layout-components" data-layout-components>
|
<ul class="admin-list layout-components" data-layout-components>
|
||||||
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
|
<?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>
|
<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>
|
<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 ?>
|
<?php endforeach ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
<?php $fieldError('components'); ?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="form-grid">
|
<div class="form-grid">
|
||||||
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"></label>
|
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
|
||||||
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo']]) ?>
|
<div>
|
||||||
|
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
|
||||||
|
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
|
||||||
|
<?php $fieldError('logo'); ?>
|
||||||
</div>
|
</div>
|
||||||
<label>链接列表<textarea name="links" rows="4"><?= $e(SiteDesign::linkText($data['links'])) ?></textarea><small>每行填写「名称 | 链接」。</small></label>
|
</div>
|
||||||
|
<label>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small><?php $fieldError('links'); ?></label>
|
||||||
<?php if ($kind === 'header'): ?>
|
<?php if ($kind === 'header'): ?>
|
||||||
<fieldset class="admin-options form-grid"><legend>行动按钮</legend>
|
<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_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
|
||||||
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></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): ?>
|
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
|
||||||
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
|
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
<?php endforeach ?></select></label>
|
<?php endforeach ?></select></label>
|
||||||
<label><span><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</span></label>
|
<label><span><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</span></label>
|
||||||
|
<?php $fieldError('action'); ?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="admin-options form-grid" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $data['components']) ? '' : ' hidden' ?>><legend>用户区认证</legend>
|
<fieldset class="admin-options form-grid" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $data['components']) ? '' : ' hidden' ?>><legend>用户区认证</legend>
|
||||||
<label>认证方式<select name="provider_mode"><option value="">关闭</option>
|
<label>认证方式<select name="provider_mode"<?= $describe('provider_mode') ?>><option value="">关闭</option>
|
||||||
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
|
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
|
||||||
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
|
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</select></label>
|
</select><?php $fieldError('provider_mode'); ?></label>
|
||||||
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"></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>客户端密钥
|
<label data-provider-field>客户端密钥
|
||||||
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password">
|
<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 ?>
|
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
|
||||||
</label>
|
</label>
|
||||||
<label data-provider-field>令牌端点认证<select name="provider_token_auth">
|
<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): ?>
|
<?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>
|
<option value="<?= $e($method) ?>" <?= ($provider['token_auth'] ?? '') === $method ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</select></label>
|
</select><?php $fieldError('provider_token_auth'); ?></label>
|
||||||
<label data-provider-field>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"></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"></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 $field => $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($field) ?>" value="<?= $e($provider[$field] ?? '') ?>"></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 ?>
|
<?php endforeach ?>
|
||||||
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
|
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<label>说明文字<textarea name="text" rows="3"><?= $e($data['text']) ?></textarea></label>
|
<label>说明文字<textarea name="text" rows="3"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
|
||||||
<label>版权文字<input name="legal" value="<?= $e($data['legal']) ?>"></label>
|
<label>版权文字<input name="legal" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<label><span><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></span></label>
|
<label><span><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></span></label>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use App\Content\Assets;
|
||||||
use App\Content\View;
|
use App\Content\View;
|
||||||
|
|
||||||
$e = View::escape(...);
|
$e = View::escape(...);
|
||||||
@@ -16,7 +17,7 @@ $active = match (true) {
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="robots" content="noindex, nofollow">
|
<meta name="robots" content="noindex, nofollow">
|
||||||
<link rel="icon" href="/assets/system/laysite-mark.webp" type="image/webp">
|
<link rel="icon" href="<?= $e(Assets::DEFAULT_ICON) ?>" type="image/webp">
|
||||||
<title><?= $e($title) ?> CMS</title>
|
<title><?= $e($title) ?> CMS</title>
|
||||||
<link rel="stylesheet" href="/assets/site.css">
|
<link rel="stylesheet" href="/assets/site.css">
|
||||||
<link rel="stylesheet" href="/assets/admin.css">
|
<link rel="stylesheet" href="/assets/admin.css">
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ $showFooter = $page['visibility']['footer'] ?? true;
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title><?= $e($title) ?></title>
|
<title><?= $e($title) ?></title>
|
||||||
|
<link rel="icon" href="<?= $e(Assets::DEFAULT_ICON) ?>" type="image/webp">
|
||||||
<meta name="description" content="<?= $e($description) ?>">
|
<meta name="description" content="<?= $e($description) ?>">
|
||||||
<meta name="theme-color" content="#f5f7fb">
|
<meta name="theme-color" content="#f5f7fb">
|
||||||
<?php if ($canonical): ?>
|
<?php if ($canonical): ?>
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ use App\Content\View;
|
|||||||
$e = View::escape(...);
|
$e = View::escape(...);
|
||||||
?>
|
?>
|
||||||
<div class="asset-field">
|
<div class="asset-field">
|
||||||
<label><?= $e($label) ?><input name="<?= $e($name) ?>" value="<?= $e($value) ?>" maxlength="1000"></label>
|
<label><?= $e($label) ?><input name="<?= $e($name) ?>" value="<?= $e($value) ?>" maxlength="1000"<?php if (isset($describedBy)): ?> aria-describedby="<?= $e($describedBy) ?>"<?php endif ?><?= !empty($invalid) ? ' aria-invalid="true"' : '' ?>></label>
|
||||||
<button type="button" class="button button-outline" data-asset-pick="<?= $e($name) ?>" data-asset-type="image/">媒体库</button>
|
<button type="button" class="button button-outline" data-asset-pick="<?= $e($name) ?>" data-asset-type="image/">媒体库</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Route::get('/articles/feed/{slug:[a-z0-9-]+}/{key:[a-z0-9-]+}', [SiteController:
|
|||||||
Route::get('/articles/{slug:[a-z0-9-]+}', [SiteController::class, 'article']);
|
Route::get('/articles/{slug:[a-z0-9-]+}', [SiteController::class, 'article']);
|
||||||
Route::get('/robots.txt', [SiteController::class, 'robots']);
|
Route::get('/robots.txt', [SiteController::class, 'robots']);
|
||||||
Route::get('/sitemap.xml', [SiteController::class, 'sitemap']);
|
Route::get('/sitemap.xml', [SiteController::class, 'sitemap']);
|
||||||
|
Route::get('/favicon.ico', [SiteController::class, 'favicon']);
|
||||||
|
|
||||||
Route::add(['GET', 'POST'], '/admin/login', [AdminController::class, 'login']);
|
Route::add(['GET', 'POST'], '/admin/login', [AdminController::class, 'login']);
|
||||||
Route::post('/admin/logout', [AdminController::class, 'logout']);
|
Route::post('/admin/logout', [AdminController::class, 'logout']);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
}
|
}
|
||||||
.admin-form textarea { resize: vertical; }
|
.admin-form textarea { resize: vertical; }
|
||||||
.admin-form small, .field-note { color: var(--muted); font-size: .875rem; font-weight: 400; }
|
.admin-form small, .field-note { color: var(--muted); font-size: .875rem; font-weight: 400; }
|
||||||
|
.admin-form .design-field-error { color: #9c252a; grid-column: 1 / -1; }
|
||||||
|
.admin-form [aria-invalid=true] { border-color: #9c252a; }
|
||||||
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
|
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
|
||||||
.form-submit { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
|
.form-submit { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
|
||||||
.form-submit label { min-width: 10rem; }
|
.form-submit label { min-width: 10rem; }
|
||||||
|
|||||||
@@ -93,6 +93,21 @@ jQuery(function ($) {
|
|||||||
$feedback.prop('hidden', false).trigger('focus');
|
$feedback.prop('hidden', false).trigger('focus');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function designFieldError($form, response) {
|
||||||
|
if (!response?.field) return false;
|
||||||
|
const $feedback = $form.find('[data-field-error]').filter(function () {
|
||||||
|
return this.dataset.fieldError === response.field;
|
||||||
|
});
|
||||||
|
$feedback.text(response.message).prop('hidden', false);
|
||||||
|
if (!$feedback.is(':visible')) return false;
|
||||||
|
|
||||||
|
$form.find('[aria-describedby]').filter(function () {
|
||||||
|
return this.getAttribute('aria-describedby') === $feedback.attr('id');
|
||||||
|
}).attr('aria-invalid', 'true');
|
||||||
|
$feedback.trigger('focus');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('invalid', (event) => {
|
document.addEventListener('invalid', (event) => {
|
||||||
if (event.target.form?.method.toLowerCase() === 'post') clearSavedStatus();
|
if (event.target.form?.method.toLowerCase() === 'post') clearSavedStatus();
|
||||||
}, true);
|
}, true);
|
||||||
@@ -109,6 +124,8 @@ jQuery(function ($) {
|
|||||||
const $submit = $form.find(':submit:enabled');
|
const $submit = $form.find(':submit:enabled');
|
||||||
const multipart = $form.attr('enctype') === 'multipart/form-data';
|
const multipart = $form.attr('enctype') === 'multipart/form-data';
|
||||||
$form.attr('aria-busy', 'true').children('.ajax-feedback').prop('hidden', true);
|
$form.attr('aria-busy', 'true').children('.ajax-feedback').prop('hidden', true);
|
||||||
|
$form.find('[data-field-error]').text('').prop('hidden', true);
|
||||||
|
$form.find('[aria-describedby^="design-error-"]').removeAttr('aria-invalid');
|
||||||
$submit.prop('disabled', true);
|
$submit.prop('disabled', true);
|
||||||
$form.triggerHandler('studio:busy', [true]);
|
$form.triggerHandler('studio:busy', [true]);
|
||||||
|
|
||||||
@@ -148,7 +165,9 @@ jQuery(function ($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
|
if (!designFieldError($form, response)) {
|
||||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user