Prepare LaySite 1.5.0 canvas and publishing improvements
This commit is contained in:
@@ -18,6 +18,8 @@ final class CanvasStyle
|
||||
'mt' => ['margin-top', -128, 128], 'mr' => ['margin-right', -128, 128],
|
||||
'mb' => ['margin-bottom', -128, 128], 'ml' => ['margin-left', -128, 128],
|
||||
'size' => ['font-size', 8, 144],
|
||||
'letter' => ['letter-spacing', -5, 24],
|
||||
'line' => ['line-height', 8, 30],
|
||||
];
|
||||
private const TYPOGRAPHY = [
|
||||
'weight-bold' => 'font-weight:700', 'weight-normal' => 'font-weight:400',
|
||||
@@ -95,7 +97,7 @@ final class CanvasStyle
|
||||
|
||||
private static function classList(mixed $value, bool $textOnly = false): string
|
||||
{
|
||||
if (!is_string($value) || strlen($value) > 320) {
|
||||
if (!is_string($value) || strlen($value) > 1800) {
|
||||
throw new RuntimeException('画布样式无效。');
|
||||
}
|
||||
$classes = [];
|
||||
@@ -109,9 +111,11 @@ final class CanvasStyle
|
||||
$classes[$property] = $class;
|
||||
} elseif ($property === 'color' && ($size === 'theme' || preg_match('/^[a-f0-9]{6}$/D', $size))) {
|
||||
$classes[$property] = $class;
|
||||
} elseif (!$textOnly && $property === 'fill' && self::fill($size) !== null) {
|
||||
$classes[$property] = $class;
|
||||
} elseif (!$textOnly && $property === 'display' && in_array($size, ['block', 'inline', 'inline-block'], true)) {
|
||||
$classes[$property] = $class;
|
||||
} elseif ((!$textOnly || $property === 'size') && isset(self::PROPERTIES[$property])
|
||||
} elseif ((!$textOnly || in_array($property, ['size', 'letter', 'line'], true)) && isset(self::PROPERTIES[$property])
|
||||
&& preg_match('/^(?:0|-?[1-9]\d{0,2})$/D', $size)) {
|
||||
[, $min, $max] = self::PROPERTIES[$property];
|
||||
if ((int) $size >= $min && (int) $size <= $max) {
|
||||
@@ -163,12 +167,46 @@ final class CanvasStyle
|
||||
return $markup;
|
||||
}
|
||||
|
||||
public static function colorRules(string $markup): string
|
||||
private static function fill(string $token): ?string
|
||||
{
|
||||
preg_match_all('/\bstudio-style-color-([a-f0-9]{6})(?![\w-])/', $markup, $matches);
|
||||
if (preg_match('/^solid-([a-f0-9]{6})$/D', $token, $parts)) {
|
||||
return 'background:#' . $parts[1] . '!important';
|
||||
}
|
||||
if (preg_match('/^gradient-(0|[1-9]\d{0,2})-([a-f0-9]{6})-([a-f0-9]{6})$/D', $token, $parts) && (int) $parts[1] <= 360) {
|
||||
return "background:linear-gradient({$parts[1]}deg,#{$parts[2]},#{$parts[3]})!important";
|
||||
}
|
||||
if (!preg_match('/^image-([A-Za-z0-9_-]{1,1334})$/D', $token, $parts)) {
|
||||
return null;
|
||||
}
|
||||
$url = base64_decode(strtr($parts[1], '-_', '+/'), true);
|
||||
if ($url === false || strlen($url) > 1000 || !mb_check_encoding($url, 'UTF-8') || !Html::url($url, true)
|
||||
|| rtrim(strtr(base64_encode($url), '+/', '-_'), '=') !== $parts[1]) {
|
||||
return null;
|
||||
}
|
||||
// Quote the URL for CSS and keep the result safe inside a raw-text HTML style element.
|
||||
$escaped = str_replace(['"', '<', '>'], ['\\22 ', '\\3c ', '\\3e '], $url);
|
||||
|
||||
return 'background-image:url("' . $escaped . '")!important;background-position:center!important;background-size:cover!important;background-repeat:no-repeat!important';
|
||||
}
|
||||
|
||||
public static function dynamicRules(string $markup): string
|
||||
{
|
||||
preg_match_all('/\bstudio-style-(color|fill)-([A-Za-z0-9_-]+)(?![\w-])/', $markup, $matches, PREG_SET_ORDER);
|
||||
$css = '';
|
||||
foreach (array_unique($matches[1]) as $hex) {
|
||||
$css .= ".studio-style-color-{$hex}{color:#{$hex}!important}\n";
|
||||
$seen = [];
|
||||
foreach ($matches as [$class, $property, $value]) {
|
||||
if (isset($seen[$class])) {
|
||||
continue;
|
||||
}
|
||||
$seen[$class] = true;
|
||||
if ($property === 'color') {
|
||||
$rule = preg_match('/^[a-f0-9]{6}$/D', $value) ? "color:#{$value}!important" : null;
|
||||
} else {
|
||||
$rule = self::fill($value);
|
||||
}
|
||||
if ($rule !== null) {
|
||||
$css .= ".$class" . '{' . $rule . "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $css;
|
||||
@@ -177,9 +215,11 @@ final class CanvasStyle
|
||||
public static function stylesheet(): string
|
||||
{
|
||||
$css = '';
|
||||
foreach (self::PROPERTIES as $key => [$property, $min, $max]) {
|
||||
foreach (self::PROPERTIES as $key => $definition) {
|
||||
[$property, $min, $max] = $definition;
|
||||
for ($value = $min; $value <= $max; $value++) {
|
||||
$css .= '.' . self::PREFIX . "$key-$value{{$property}:{$value}px!important}\n";
|
||||
$length = $key === 'line' ? $value / 10 : $value . 'px';
|
||||
$css .= '.' . self::PREFIX . "$key-$value{{$property}:{$length}!important}\n";
|
||||
}
|
||||
}
|
||||
for ($width = self::MIN_MEDIA_SCALE; $width <= 100; $width++) {
|
||||
|
||||
+13
-11
@@ -68,17 +68,19 @@ final class Database
|
||||
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
|
||||
VALUES ('home', '首页', '我的网站', '欢迎访问我的网站。', '我的网站', '', '', '', '', '[]', '[]')")
|
||||
->execute();
|
||||
$articles = $pdo->prepare("INSERT OR IGNORE INTO pages
|
||||
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
|
||||
VALUES ('articles', '文章与动态', '文章与动态', '浏览站点发布的文章。', '文章与动态', '', '', '', '', '[]', '[]')");
|
||||
$articles->execute();
|
||||
if ($articles->rowCount() === 1) {
|
||||
$pdo->prepare("INSERT INTO sections (page_slug, key, title, lead, body, feed, position)
|
||||
VALUES ('articles', 'posts', '最新文章', '', '', ?, 0)")->execute([BlockTemplates::ARTICLE_FEED]);
|
||||
}
|
||||
$category = $pdo->prepare('INSERT OR IGNORE INTO article_categories (slug, name) VALUES (?, ?)');
|
||||
foreach (Repository::CATEGORIES as $slug => $name) {
|
||||
$category->execute([$slug, $name]);
|
||||
if ($version === 0) {
|
||||
$articles = $pdo->prepare("INSERT OR IGNORE INTO pages
|
||||
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
|
||||
VALUES ('articles', '文章与动态', '文章与动态', '浏览站点发布的文章。', '文章与动态', '', '', '', '', '[]', '[]')");
|
||||
$articles->execute();
|
||||
if ($articles->rowCount() === 1) {
|
||||
$pdo->prepare("INSERT INTO sections (page_slug, key, title, lead, body, feed, position)
|
||||
VALUES ('articles', 'posts', '最新文章', '', '', ?, 0)")->execute([BlockTemplates::ARTICLE_FEED]);
|
||||
}
|
||||
$category = $pdo->prepare('INSERT OR IGNORE INTO article_categories (slug, name) VALUES (?, ?)');
|
||||
foreach (Repository::CATEGORIES as $slug => $name) {
|
||||
$category->execute([$slug, $name]);
|
||||
}
|
||||
}
|
||||
if ($version < 2) {
|
||||
OAuthCredentials::migrateLegacy($pdo);
|
||||
|
||||
@@ -39,6 +39,18 @@ final class DesignLibrary
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
||||
public static function palettes(): array
|
||||
{
|
||||
$rows = Database::connect()->query("SELECT id, name, preset, payload FROM design_presets
|
||||
WHERE kind = 'palette' ORDER BY id")->fetchAll();
|
||||
foreach ($rows as &$row) {
|
||||
$row['colors'] = self::normalize('palette', $row['preset'], json_decode($row['payload'], true, flags: JSON_THROW_ON_ERROR));
|
||||
unset($row['payload'], $row['preset']);
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function find(int $id, string $kind): ?array
|
||||
{
|
||||
if ($id < 1) {
|
||||
|
||||
@@ -128,4 +128,19 @@ final class LayoutPage
|
||||
DesignLibrary::setDefault($pdo, $kind, $id, $config['default']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function deletePreset(PDO $pdo, string $kind, int $id): void
|
||||
{
|
||||
$field = $kind . '_id';
|
||||
$pdo->prepare("UPDATE pages SET $field = NULL, version = version + 1 WHERE $field = ?")->execute([$id]);
|
||||
$site = json_decode($pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
if (($site['layout_defaults'][$kind] ?? null) === $id) {
|
||||
unset($site['layout_defaults'][$kind]);
|
||||
}
|
||||
if (($site[$field] ?? null) === $id) {
|
||||
$site[$field] = $site['layout_defaults'][$kind] ?? null;
|
||||
}
|
||||
$pdo->prepare('UPDATE site_settings SET payload = ? WHERE id = 1')->execute([Database::json($site)]);
|
||||
$pdo->prepare('DELETE FROM design_presets WHERE id = ?')->execute([$id]);
|
||||
}
|
||||
}
|
||||
|
||||
+64
-11
@@ -98,7 +98,7 @@ final class Repository
|
||||
$catalog = $feed['mode'] === 'catalog';
|
||||
$grouped = $network || ($feed['mode'] === 'tabs' && count($feed['categories']) > 1);
|
||||
$archivePath = '/articles/feed/' . $page['slug'] . '/' . $section['key'];
|
||||
$section['archivePath'] = empty($page['layout_kind']) && ($page['page_type'] ?? 'page') === 'page' && $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['archivePath'] = $feed['categories'] && empty($page['layout_kind']) && ($page['page_type'] ?? 'page') === 'page' && $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['articleFeed'] = [];
|
||||
$section['networkFeed'] = $network;
|
||||
$section['catalogFeed'] = $catalog;
|
||||
@@ -129,9 +129,9 @@ final class Repository
|
||||
AND sections.key = ? AND sections.feed IS NOT NULL", [$page, $key]);
|
||||
}
|
||||
|
||||
public function savePage(string $slug, array $data, int $version, array $sections = [], bool $replaceDraftSections = false, ?array $sectionOrder = null): void
|
||||
public function savePage(string $slug, array $data, int $version, array $sections = [], bool $replaceDraftSections = false, ?array $sectionOrder = null): array
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($slug, $data, $version, $sections, $replaceDraftSections, $sectionOrder): void {
|
||||
return Database::write(function (PDO $pdo) use ($slug, $data, $version, $sections, $replaceDraftSections, $sectionOrder): array {
|
||||
$head = $data['head_html'] ?? null;
|
||||
$query = $pdo->prepare('UPDATE pages SET name = ?, title = ?, description = ?, heading = ?, accent = ?, lead = ?,
|
||||
image = ?, alt = ?, image_scale = ?, alignments = ?, actions = ?, quicklinks = ?, visibility = ?, header_id = ?, footer_id = ?, palette_id = ?, status = ?, updated_at = ?,
|
||||
@@ -163,9 +163,29 @@ final class Repository
|
||||
if ($sectionOrder !== null) {
|
||||
self::writeSectionOrder($pdo, $slug, $sectionOrder);
|
||||
}
|
||||
$page = $this->page($slug);
|
||||
if (isset($data['layoutConfig'])) {
|
||||
LayoutPage::saveSettings($pdo, $this->page($slug), $data['layoutConfig']);
|
||||
LayoutPage::saveSettings($pdo, $page, $data['layoutConfig']);
|
||||
}
|
||||
|
||||
return $page;
|
||||
});
|
||||
}
|
||||
|
||||
public function deletePage(string $slug, int $version): void
|
||||
{
|
||||
if ($slug === 'home') {
|
||||
throw new RuntimeException('首页是站点入口,不能删除。');
|
||||
}
|
||||
Database::write(function (PDO $pdo) use ($slug, $version): void {
|
||||
$page = $this->page($slug);
|
||||
$delete = $pdo->prepare('DELETE FROM pages WHERE slug = ? AND version = ?');
|
||||
$delete->execute([$slug, $version]);
|
||||
self::checkVersion($delete->rowCount());
|
||||
if ($page['layout_id'] !== null) {
|
||||
LayoutPage::deletePreset($pdo, $page['layout_kind'], $page['layout_id']);
|
||||
}
|
||||
SiteDesign::unsetSystemPage($pdo, $slug);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,7 +209,7 @@ final class Repository
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed, $lead): void {
|
||||
self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed', 'lead'));
|
||||
self::touchPage($pdo, $page, structureChanged: true);
|
||||
self::touchPage($pdo, $page);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -197,7 +217,14 @@ final class Repository
|
||||
{
|
||||
$query = $pdo->prepare('INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, feed, alignments, presentation, position)
|
||||
SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE(MAX(position), -1) + 1 FROM sections WHERE page_slug = ?');
|
||||
$query->execute([$page, $key, $data['title'], $data['lead'], $data['style'], $data['body'], $data['feed'] ?? null, $data['alignments'] ?? '{}', $data['presentation'] ?? '{}', $page]);
|
||||
$feed = $data['feed'] ?? null;
|
||||
if ($feed !== null) {
|
||||
$config = json_decode($feed, true, flags: JSON_THROW_ON_ERROR);
|
||||
$available = $pdo->query('SELECT slug FROM article_categories')->fetchAll(PDO::FETCH_COLUMN);
|
||||
$config['categories'] = array_values(array_intersect($config['categories'], $available));
|
||||
$feed = Database::json($config);
|
||||
}
|
||||
$query->execute([$page, $key, $data['title'], $data['lead'], $data['style'], $data['body'], $feed, $data['alignments'] ?? '{}', $data['presentation'] ?? '{}', $page]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此区块锚点已被使用。');
|
||||
}
|
||||
@@ -233,7 +260,7 @@ final class Repository
|
||||
self::checkVersion($revision !== false && (int) $revision === $pageVersion ? 1 : 0);
|
||||
if ($operation === 'delete') {
|
||||
self::deleteSection($pdo, $page, $key, $version);
|
||||
self::touchPage($pdo, $page, structureChanged: true);
|
||||
self::touchPage($pdo, $page);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -252,7 +279,7 @@ final class Repository
|
||||
}
|
||||
[$keys[$index], $keys[$other]] = [$keys[$other], $keys[$index]];
|
||||
self::writeSectionOrder($pdo, $page, $keys);
|
||||
self::touchPage($pdo, $page, structureChanged: true);
|
||||
self::touchPage($pdo, $page);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -270,10 +297,9 @@ final class Repository
|
||||
}
|
||||
}
|
||||
|
||||
private static function touchPage(PDO $pdo, string $slug, bool $structureChanged = false): void
|
||||
private static function touchPage(PDO $pdo, string $slug): void
|
||||
{
|
||||
$revision = $structureChanged ? ', version = version + 1' : '';
|
||||
$pdo->prepare('UPDATE pages SET updated_at = ?' . $revision . ' WHERE slug = ?')->execute([self::now(), $slug]);
|
||||
$pdo->prepare('UPDATE pages SET updated_at = ?, version = version + 1 WHERE slug = ?')->execute([self::now(), $slug]);
|
||||
}
|
||||
|
||||
public function categories(): array
|
||||
@@ -290,6 +316,33 @@ final class Repository
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteCategory(string $slug): void
|
||||
{
|
||||
Database::write(static function (PDO $pdo) use ($slug): void {
|
||||
$pdo->prepare('UPDATE articles SET version = version + 1 WHERE id IN
|
||||
(SELECT article_id FROM article_category_links WHERE category_slug = ?)')->execute([$slug]);
|
||||
$pdo->prepare('DELETE FROM article_category_links WHERE category_slug = ?')->execute([$slug]);
|
||||
$delete = $pdo->prepare('DELETE FROM article_categories WHERE slug = ?');
|
||||
$delete->execute([$slug]);
|
||||
self::checkVersion($delete->rowCount());
|
||||
|
||||
$sections = $pdo->prepare("SELECT page_slug, key, feed FROM sections WHERE EXISTS
|
||||
(SELECT 1 FROM json_each(sections.feed, '$.categories') WHERE value = ?)");
|
||||
$sections->execute([$slug]);
|
||||
$update = $pdo->prepare('UPDATE sections SET feed = ?, version = version + 1 WHERE page_slug = ? AND key = ?');
|
||||
$affected = [];
|
||||
foreach ($sections->fetchAll() as $section) {
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$feed['categories'] = array_values(array_diff($feed['categories'], [$slug]));
|
||||
$update->execute([Database::json($feed), $section['page_slug'], $section['key']]);
|
||||
$affected[$section['page_slug']] = true;
|
||||
}
|
||||
foreach (array_keys($affected) as $page) {
|
||||
self::touchPage($pdo, $page);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function articles(string|array|null $category = null, ?string $tag = null, bool $public = true,
|
||||
int $limit = 30, int $offset = 0, bool $directoryOrder = false): array
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ final class View
|
||||
}
|
||||
}
|
||||
$html = self::fragment($template, $data);
|
||||
$data['canvasColors'] = $admin ? '' : CanvasStyle::colorRules($html . ($data['headerMarkup'] ?? '') . ($data['footerMarkup'] ?? ''));
|
||||
$data['canvasColors'] = $admin ? '' : CanvasStyle::dynamicRules($html . ($data['headerMarkup'] ?? '') . ($data['footerMarkup'] ?? ''));
|
||||
$headSources = $admin ? [] : array_filter([$data['site']['head_html'] ?? '', $data['page']['head_html'] ?? '']);
|
||||
$data['styleNonce'] = $data['canvasColors'] !== '' || !empty($data['canvas']) || $headSources !== []
|
||||
? base64_encode(random_bytes(18)) : '';
|
||||
|
||||
@@ -127,7 +127,7 @@ class AdminController
|
||||
|
||||
return $this->render($request, 'admin-dashboard', [
|
||||
'title' => '内容管理', 'pages' => $repo->pages(), 'articles' => $repo->articles(public: false, limit: 5),
|
||||
'site' => $repo->site(),
|
||||
'site' => $repo->site(), 'deleted' => $request->get('deleted') === '1',
|
||||
'pageTemplateDrawer' => true,
|
||||
]);
|
||||
}
|
||||
@@ -237,9 +237,24 @@ class AdminController
|
||||
return $this->render($request, 'admin-article-categories', [
|
||||
'title' => '文章分类', 'categories' => $repo->categories(), 'name' => $name, 'slug' => $slug,
|
||||
'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'deleted' => $request->get('deleted') === '1',
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
public function deleteCategory(Request $request, string $slug): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
try {
|
||||
(new Repository())->deleteCategory($slug);
|
||||
} catch (RuntimeException $exception) {
|
||||
return $this->error($request, $this->validationMessage($exception), 422);
|
||||
}
|
||||
|
||||
return $this->success($request, '/admin/article-categories?deleted=1');
|
||||
}
|
||||
|
||||
public function article(Request $request, ?string $id = null): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
@@ -248,10 +263,10 @@ class AdminController
|
||||
$repo = new Repository();
|
||||
$categories = $repo->categories();
|
||||
$preset = $request->get('category');
|
||||
$preset = is_string($preset) && isset($categories[$preset]) ? $preset : 'news';
|
||||
$preset = is_string($preset) && isset($categories[$preset]) ? $preset : (isset($categories['news']) ? 'news' : null);
|
||||
$article = $id !== null ? $repo->articleById((int) $id) : [
|
||||
'title' => '', 'slug' => '', 'summary' => '', 'body' => '', 'body_format' => 'markdown',
|
||||
'categories' => [$preset => $categories[$preset]], 'card' => [], 'tags' => [], 'status' => 'draft', 'version' => 0,
|
||||
'categories' => $preset === null ? [] : [$preset => $categories[$preset]], 'card' => [], 'tags' => [], 'status' => 'draft', 'version' => 0,
|
||||
];
|
||||
if (!$article) {
|
||||
return $this->error($request, '找不到这篇文章。', 404);
|
||||
@@ -267,7 +282,7 @@ class AdminController
|
||||
if (mb_strlen($data['title']) < 1 || mb_strlen($data['title']) > 120
|
||||
|| !preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/D', $data['slug']) || strlen($data['slug']) > 100
|
||||
|| mb_strlen($data['summary']) > 250 || strlen($data['body']) > 200000
|
||||
|| $data['categories'] === [] || array_diff($data['categories'], array_keys($categories))
|
||||
|| array_diff($data['categories'], array_keys($categories))
|
||||
|| !in_array($data['body_format'], ['markdown', 'html'], true)
|
||||
|| !in_array($data['status'], ['draft', 'published'], true)) {
|
||||
throw new RuntimeException('请检查标题、网址标识、分类、摘要和正文长度。');
|
||||
@@ -338,7 +353,8 @@ class AdminController
|
||||
if ($layout) {
|
||||
$data['title'] = $data['name'];
|
||||
}
|
||||
$data['status'] = $layout || $request->post('status') === null || $slug === 'home' ? $page['status'] : $this->input($request, 'status');
|
||||
$publication = $request->post('status');
|
||||
$data['status'] = $layout || $publication === null || $slug === 'home' ? $page['status'] : $this->input($request, 'status');
|
||||
$scale = $this->input($request, 'image_scale');
|
||||
$data['image_scale'] = $request->post('image_scale') === null ? (int) $page['image_scale']
|
||||
: (ctype_digit($scale) ? (int) $scale : -1);
|
||||
@@ -420,7 +436,17 @@ class AdminController
|
||||
throw new RuntimeException('区块顺序无效。');
|
||||
}
|
||||
}
|
||||
$repo->savePage($slug, $data, $this->version($request), $sections, sectionOrder: $order === '' ? null : $order);
|
||||
$saved = $repo->savePage($slug, $data, $this->version($request), $sections, sectionOrder: $order === '' ? null : $order);
|
||||
if ($request->isAjax()) {
|
||||
return $this->json([
|
||||
'saved' => true, 'version' => $saved['version'], 'name' => $saved['name'], 'status' => $saved['status'],
|
||||
'sections' => array_map(static function (array $section) use ($sections): array {
|
||||
$key = $section['key'];
|
||||
return ['key' => $key, 'version' => $section['version']]
|
||||
+ (isset($sections[$key]) ? ['body' => $section['body'], 'feed' => $section['feed']] : []);
|
||||
}, $saved['sections']),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $slug . '?saved=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
@@ -434,9 +460,24 @@ class AdminController
|
||||
'layoutBase' => $layout && ($site['layout_defaults'][$layoutKind] ?? null) === $layout['id'],
|
||||
'siteName' => $site['name'], 'layoutHasMember' => $layoutKind === 'header' && LayoutPage::hasMember($page['sections']),
|
||||
'layoutDefaults' => array_intersect_key($site, ['header_id' => true, 'footer_id' => true]),
|
||||
'palettes' => DesignLibrary::palettes(),
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
public function deletePage(Request $request, string $slug): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
try {
|
||||
(new Repository())->deletePage($slug, $this->version($request));
|
||||
} catch (RuntimeException $exception) {
|
||||
return $this->error($request, $this->validationMessage($exception), 422);
|
||||
}
|
||||
|
||||
return $this->success($request, '/admin?deleted=1');
|
||||
}
|
||||
|
||||
public function section(Request $request, string $slug, string $key): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
@@ -741,8 +782,8 @@ class AdminController
|
||||
{
|
||||
$categories = $this->selectedCategories($selected);
|
||||
$limit = filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 30]]);
|
||||
if (!in_array($mode, ['merged', 'tabs', 'network', 'catalog'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) {
|
||||
throw new RuntimeException('请选择文章分类,并将展示数量设为 1 至 30。');
|
||||
if (!in_array($mode, ['merged', 'tabs', 'network', 'catalog'], true) || array_diff($categories, array_keys($available)) || $limit === false) {
|
||||
throw new RuntimeException('请检查展示方式、分类和展示数量(1 至 30)。');
|
||||
}
|
||||
|
||||
return Database::json(compact('categories', 'mode', 'limit'));
|
||||
|
||||
@@ -27,7 +27,7 @@ final class DesignController extends AdminController
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-design', [
|
||||
'title' => '站点设计', 'items' => DesignLibrary::all('palette'),
|
||||
'title' => '站点设计', 'items' => DesignLibrary::palettes(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ $e = View::escape(...);
|
||||
<a class="back-link" href="/admin/articles">返回文章列表</a>
|
||||
<header class="admin-heading"><h1>文章分类</h1></header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<?php if ($deleted): ?><p class="feedback success" data-save-confirmation role="status">分类已删除。</p><?php endif ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/article-categories">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<div class="form-grid">
|
||||
@@ -14,8 +15,19 @@ $e = View::escape(...);
|
||||
</div>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit">创建分类</button></div>
|
||||
</form>
|
||||
<nav class="filter-nav" aria-label="查看分类">
|
||||
<?php foreach ($categories as $key => $label): ?>
|
||||
<a href="/admin/articles?category=<?= $e($key) ?>"><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<section class="admin-panel">
|
||||
<h2>已有分类</h2>
|
||||
<?php if (!$categories): ?><p class="field-note">暂无文章分类。</p><?php endif ?>
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($categories as $key => $label): ?>
|
||||
<li>
|
||||
<a href="/admin/articles?category=<?= $e($key) ?>"><?= $e($label) ?></a>
|
||||
<form method="post" action="/admin/article-categories/<?= $e($key) ?>/delete">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<button type="submit" class="button button-outline destructive-action"
|
||||
data-confirm="<?= $e('删除「' . $label . '」后,文章会保留,引用该分类的动态组件将移除这个分类。') ?>"><?= View::fragment('studio-icon', ['icon' => 'delete']) ?>删除分类</button>
|
||||
</form>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@@ -6,6 +6,7 @@ $checked = array_fill_keys($selected, true);
|
||||
?>
|
||||
<fieldset class="category-checks">
|
||||
<legend><?= $e($legend) ?></legend>
|
||||
<?php if (!$categories): ?><p class="field-note">暂无分类。</p><?php endif ?>
|
||||
<div>
|
||||
<?php foreach ($categories as $key => $label): ?>
|
||||
<label><input type="checkbox" name="<?= $e($name) ?>[]" value="<?= $e($key) ?>" <?= isset($checked[$key]) ? 'checked' : '' ?>> <?= $e($label) ?></label>
|
||||
|
||||
@@ -22,6 +22,7 @@ foreach (['header', 'footer'] as $kind) {
|
||||
<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">
|
||||
@@ -64,6 +65,14 @@ foreach (['header', 'footer'] as $kind) {
|
||||
'icon' => $public ? 'external' : 'preview',
|
||||
'label' => ($public ? '查看公开页面' : '预览页面') . ' · ' . $page['name'],
|
||||
]) ?>
|
||||
<?php if ($page['slug'] !== 'home'): ?>
|
||||
<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('确定删除「' . $page['name'] . '」?此操作不可撤销。') ?>"><?= View::fragment('studio-icon', ['icon' => 'delete']) ?></button>
|
||||
</form>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
|
||||
@@ -16,7 +16,9 @@ $e = View::escape(...);
|
||||
<?php if (!$items): ?><p class="field-note">暂无自定义配色。</p><?php endif ?>
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($items as $item): ?>
|
||||
<li><strong><?= $e($item['name']) ?></strong>
|
||||
<li><div class="palette-name"><strong><?= $e($item['name']) ?></strong>
|
||||
<?= View::fragment('palette-swatches', ['colors' => $item['colors']]) ?>
|
||||
</div>
|
||||
<a class="button button-outline" href="/admin/design/palette/<?= $e($item['id']) ?>"><?= View::fragment('studio-icon', ['icon' => 'edit']) ?>编辑</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
|
||||
@@ -20,10 +20,10 @@ $active = match (true) {
|
||||
<link rel="icon" href="<?= $e(Assets::DEFAULT_ICON) ?>" type="image/webp">
|
||||
<title><?= $e($title) ?> CMS</title>
|
||||
<link rel="stylesheet" href="/assets/site.css">
|
||||
<link rel="stylesheet" href="/assets/admin.css">
|
||||
<link rel="stylesheet" href="/assets/admin.css?v=<?= $e($laysiteVersion) ?>">
|
||||
<script src="<?= $e(Assets::JQUERY) ?>" defer></script>
|
||||
<script src="/assets/admin.js" defer></script>
|
||||
<script src="/assets/studio.js" defer></script>
|
||||
<script src="/assets/admin.js?v=<?= $e($laysiteVersion) ?>" defer></script>
|
||||
<script src="/assets/studio.js?v=<?= $e($laysiteVersion) ?>" defer></script>
|
||||
<?php if ($adminPath === '/admin/about'): ?>
|
||||
<script src="/assets/admin-about.js" defer></script>
|
||||
<?php endif ?>
|
||||
@@ -66,7 +66,7 @@ $active = match (true) {
|
||||
<a href="/admin/design"<?= $active === 'settings' ? ' aria-current="page"' : '' ?>>站点设计</a>
|
||||
</nav>
|
||||
<div class="admin-utility">
|
||||
<?= View::fragment('admin-view-link', ['href' => '/', 'icon' => 'globe']) ?>
|
||||
<?= View::fragment('admin-view-link', ['href' => '/', 'icon' => 'website', 'label' => '访问网站']) ?>
|
||||
<details class="admin-account">
|
||||
<summary><?= View::fragment('studio-icon', ['icon' => 'account']) ?>账户<?= View::fragment('studio-icon', ['icon' => 'chevron']) ?></summary>
|
||||
<div class="admin-account-menu">
|
||||
@@ -81,7 +81,7 @@ $active = match (true) {
|
||||
</details>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?= View::fragment('admin-view-link', ['href' => '/', 'icon' => 'globe', 'label' => '返回网站']) ?>
|
||||
<?= View::fragment('admin-view-link', ['href' => '/', 'icon' => 'website', 'label' => '返回网站']) ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
+102
-65
@@ -10,6 +10,9 @@ use App\Content\View;
|
||||
$e = View::escape(...);
|
||||
$slug = $page['slug'];
|
||||
$path = $slug === 'home' ? '/' : '/' . $slug;
|
||||
$published = $page['status'] === 'published';
|
||||
$publicPage = !$page['layout_kind'] && $page['page_type'] === 'page';
|
||||
$paletteOptions = [['id' => '', 'name' => '页面原有配色', 'colors' => []], ...$palettes];
|
||||
$previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
$systemLabel = SystemPage::TYPES[$page['page_type']] ?? null;
|
||||
$fontSizes = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144];
|
||||
@@ -17,9 +20,9 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
?>
|
||||
<a class="back-link" href="/admin">返回页面</a>
|
||||
<header class="admin-heading">
|
||||
<div><h1><?= $e($title) ?></h1><p class="studio-page-meta">
|
||||
<div><h1 data-page-editor-title><?= $e($title) ?></h1><p class="studio-page-meta">
|
||||
<?php if ($layout): ?><span class="dashboard-page-state"><?= $e(LayoutPage::TYPES[$layout['kind']]) ?></span>
|
||||
<?php else: ?><?php if ($systemLabel): ?><span><?= $e($systemLabel) ?></span><?php else: ?><code><?= $e($path) ?></code><?php endif ?><span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span><?php endif ?>
|
||||
<?php else: ?><?php if ($systemLabel): ?><span><?= $e($systemLabel) ?></span><?php else: ?><code><?= $e($path) ?></code><?php endif ?><span class="dashboard-page-state" data-page-publication data-published="<?= $published ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span><?php endif ?>
|
||||
</p></div>
|
||||
<div class="actions">
|
||||
<a class="button button-outline" href="#studio-page-settings"><?= View::fragment('studio-icon', ['icon' => 'settings']) ?>页面设置</a>
|
||||
@@ -31,11 +34,14 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<?php endforeach ?>
|
||||
<button type="button" class="button button-outline" data-open-page-templates hidden><?= View::fragment('studio-icon', ['icon' => 'templates']) ?>整页模板</button>
|
||||
<?php if ($systemLabel): ?><a class="button button-outline" href="/admin/settings"><?= View::fragment('studio-icon', ['icon' => 'settings']) ?>站点设置</a>
|
||||
<?php elseif ($page['status'] === 'published'): ?><?= View::fragment('admin-view-link', ['href' => $path, 'icon' => 'external']) ?><?php endif ?>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
<?php if ($layout || $systemLabel || $page['status'] !== 'published'): ?>
|
||||
<?php if ($publicPage): ?>
|
||||
<span data-page-public<?= $published ? '' : ' hidden' ?>><?= View::fragment('admin-view-link', ['href' => $path, 'icon' => 'external']) ?></span>
|
||||
<?php endif ?>
|
||||
<span data-page-preview<?= $publicPage && $published ? ' hidden' : '' ?>>
|
||||
<?= View::fragment('admin-view-link', ['href' => $previewUrl, 'icon' => 'preview', 'label' => '预览已保存内容']) ?>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
</div>
|
||||
</header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
@@ -57,14 +63,17 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
</div>
|
||||
</div>
|
||||
<div class="editor-toolbar studio-canvas-toolbar" data-canvas-toolbar hidden aria-label="正文工具">
|
||||
<div>
|
||||
<button type="button" data-canvas-command="heading">小标题</button>
|
||||
<button type="button" data-canvas-command="paragraph" title="换段(Ctrl/⌘+Enter)" aria-keyshortcuts="Control+Enter Meta+Enter">换段</button>
|
||||
<button type="button" data-canvas-command="list">列表</button>
|
||||
<button type="button" data-canvas-command="link">插入链接</button>
|
||||
<button type="button" data-canvas-command="media">插入媒体</button>
|
||||
<div data-canvas-text-commands role="group" aria-label="插入文本结构" hidden>
|
||||
<?php foreach (['heading' => '小标题', 'paragraph' => '换段', 'list' => '列表', 'link' => '插入链接'] as $command => $label): ?>
|
||||
<button type="button" data-canvas-command="<?= $command ?>" aria-label="<?= $label ?>"
|
||||
title="<?= $label ?><?= $command === 'paragraph' ? '(Ctrl/⌘+Enter)' : '' ?>"<?= $command === 'paragraph' ? ' aria-keyshortcuts="Control+Enter Meta+Enter"' : '' ?>><?= View::fragment('studio-icon', ['icon' => $command]) ?></button>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<div class="canvas-format-tools" role="group" aria-label="文字格式">
|
||||
<div role="group" aria-label="插入与填充" data-canvas-insert hidden>
|
||||
<button type="button" data-canvas-command="media" aria-label="插入媒体" title="插入媒体" hidden><?= View::fragment('studio-icon', ['icon' => 'media']) ?></button>
|
||||
<button type="button" data-canvas-background aria-label="背景填充" title="背景填充" hidden><?= View::fragment('studio-icon', ['icon' => 'fill']) ?></button>
|
||||
</div>
|
||||
<div class="canvas-format-tools" role="group" aria-label="文字格式" data-canvas-text-tools hidden>
|
||||
<div class="canvas-font-picker">
|
||||
<label for="canvas-font-size">字号</label>
|
||||
<div class="canvas-font-combo">
|
||||
@@ -75,18 +84,25 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<label>文字颜色 <input type="color" aria-label="文字颜色" data-canvas-color disabled></label>
|
||||
<button type="button" data-clear-color title="恢复默认文字颜色" aria-label="恢复默认文字颜色" disabled><?= View::fragment('studio-icon', ['icon' => 'refresh']) ?></button>
|
||||
<label>字距 <input type="number" data-canvas-letter min="-5" max="24" step="1" placeholder="px" aria-label="字距(px)"></label>
|
||||
<label>行距 <input type="number" data-canvas-line min="0.8" max="3" step="0.1" placeholder="倍" aria-label="行距(倍)"></label>
|
||||
<button type="button" data-canvas-color title="文字颜色" aria-label="文字颜色"><span aria-hidden="true">A</span><svg viewBox="0 0 16 4" aria-hidden="true"><rect width="16" height="4" rx="1" fill="currentColor"/></svg></button>
|
||||
<button type="button" data-canvas-format="weight" aria-label="加粗" title="加粗" aria-pressed="false" disabled><strong>B</strong></button>
|
||||
<button type="button" data-canvas-format="slant" aria-label="斜体" title="斜体" aria-pressed="false" disabled><em>I</em></button>
|
||||
<button type="button" data-canvas-format="strike" aria-label="删除线" title="删除线" aria-pressed="false" disabled><s>S</s></button>
|
||||
</div>
|
||||
<label class="canvas-image-display">图片布局 <select data-canvas-image-display disabled>
|
||||
<label class="canvas-image-display" hidden>图片布局 <select data-canvas-image-display disabled>
|
||||
<option value="">随模板</option><option value="block">块级</option><option value="inline">行内</option><option value="inline-block">行内块</option>
|
||||
</select></label>
|
||||
<div class="studio-media-sizing" data-media-sizing hidden>
|
||||
<output data-media-size aria-hidden="true"></output>
|
||||
<button class="button button-outline" type="button" data-reset-media>原始尺寸</button>
|
||||
<button class="button button-outline" type="button" data-replace-media>替换媒体</button>
|
||||
</div>
|
||||
<div role="group" aria-label="画布历史">
|
||||
<button type="button" data-canvas-history="undo" title="撤销(Ctrl/⌘ Z)" disabled>撤销</button>
|
||||
<button type="button" data-canvas-history="redo" title="重做(Ctrl/⌘ Shift Z)" disabled>重做</button>
|
||||
<?php foreach (['undo' => ['撤销', 'Ctrl/⌘+Z'], 'redo' => ['重做', 'Ctrl/⌘+Shift+Z']] as $direction => [$label, $shortcut]): ?>
|
||||
<button type="button" data-canvas-history="<?= $direction ?>" aria-label="<?= $label ?>" title="<?= $label ?>(<?= $shortcut ?>)" disabled><?= View::fragment('studio-icon', ['icon' => $direction]) ?></button>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<button class="button button-primary" form="studio-page-settings" type="submit"><?= View::fragment('studio-icon', ['icon' => 'save']) ?>保存页面</button>
|
||||
</div>
|
||||
@@ -103,13 +119,10 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<button class="studio-media-handle" type="button" role="slider" aria-label="媒体宽度" aria-valuemin="<?= CanvasStyle::MIN_MEDIA_SCALE ?>" aria-valuemax="100" aria-valuenow="100" data-media-handle hidden></button>
|
||||
<div class="studio-media-sizing" data-media-sizing hidden>
|
||||
<output data-media-size aria-hidden="true"></output>
|
||||
<button class="button button-outline" type="button" data-reset-media>原始尺寸</button>
|
||||
<button class="button button-outline" type="button" data-replace-media>替换媒体</button>
|
||||
</div>
|
||||
</div>
|
||||
<?= View::fragment('studio-fill') ?>
|
||||
<p class="field-note studio-canvas-status" data-canvas-status role="status"></p>
|
||||
<p class="feedback success" data-page-save-feedback role="status" hidden></p>
|
||||
<dialog class="media-picker canvas-source" data-canvas-source aria-labelledby="canvas-source-heading">
|
||||
<div class="admin-heading compact"><h2 id="canvas-source-heading">编辑区块 HTML</h2></div>
|
||||
<form class="admin-form" method="dialog">
|
||||
@@ -197,7 +210,7 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
</dialog>
|
||||
</section>
|
||||
</div>
|
||||
<form id="studio-page-settings" class="admin-form admin-panel studio-inspector" method="post" action="/admin/pages/<?= $e($slug) ?>">
|
||||
<form id="studio-page-settings" class="admin-form admin-panel studio-inspector" data-save-inline data-public-page="<?= $publicPage ? '1' : '0' ?>" method="post" action="/admin/pages/<?= $e($slug) ?>">
|
||||
<h2>页面设置</h2>
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($page['version']) ?>">
|
||||
@@ -219,44 +232,60 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<?php if (!$layout && !$systemLabel && $slug !== 'home'): ?><button class="button button-outline" type="button" disabled data-hero-control="breadcrumbs">面包屑路径</button><?php endif ?>
|
||||
</div>
|
||||
</details>
|
||||
<label>页面名称<input name="name" value="<?= $e($page['name']) ?>" required maxlength="100"></label>
|
||||
<?php if ($layout): ?>
|
||||
<input type="hidden" name="title" value="<?= $e($page['title']) ?>">
|
||||
<?php if ($layoutDefault && $layoutBase): ?>
|
||||
<p class="field-note">当前站点默认<?= $e(LayoutPage::TYPES[$layout['kind']]) ?></p>
|
||||
<?php else: ?>
|
||||
<label><input type="checkbox" name="make_default" value="1"<?= $layoutDefault ? ' checked' : '' ?>> 用作站点默认<?= $e(LayoutPage::TYPES[$layout['kind']]) ?></label>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<label>SEO 标题<input name="title" value="<?= $e($page['title']) ?>" required maxlength="160"></label>
|
||||
<label>SEO 描述<textarea name="description" rows="2" maxlength="300"><?= $e($page['description']) ?></textarea></label>
|
||||
<?php endif ?>
|
||||
<fieldset class="admin-options form-grid">
|
||||
<legend>页面显示</legend>
|
||||
<?php $heroVisible = $page['visibility']['hero'] ?? true; ?>
|
||||
<label>首屏<select name="show_hero"><option value="1"<?= $heroVisible ? ' selected' : '' ?>>显示</option>
|
||||
<option value="0"<?= !$heroVisible ? ' selected' : '' ?>>隐藏</option></select></label>
|
||||
<?php if (!$layout): ?>
|
||||
<?php foreach (['header' => '页头', 'footer' => '页脚'] as $kind => $label): ?>
|
||||
<?php $visible = $page['visibility'][$kind] ?? true; ?>
|
||||
<label><?= $e($label) ?><select name="<?= $e($kind) ?>_choice">
|
||||
<option value="hidden"<?= !$visible ? ' selected' : '' ?>>隐藏</option>
|
||||
<option value=""<?= $visible && $page[$kind . '_id'] === null ? ' selected' : '' ?>>站点默认</option>
|
||||
<?php foreach ($designs as $item): ?>
|
||||
<?php if ($item['kind'] !== $kind) continue; ?>
|
||||
<option value="<?= $e($item['id']) ?>"<?= $visible && $page[$kind . '_id'] === $item['id'] ? ' selected' : '' ?>><?= $e($item['name']) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<?php endforeach ?>
|
||||
<label>配色方案<select name="palette_id">
|
||||
<option value="">页面原有配色</option>
|
||||
<?php foreach ($designs as $item): ?>
|
||||
<?php if ($item['kind'] !== 'palette') continue; ?>
|
||||
<option value="<?= $e($item['id']) ?>"<?= $page['palette_id'] === $item['id'] ? ' selected' : '' ?>><?= $e($item['name']) ?></option>
|
||||
<div class="studio-settings-grid">
|
||||
<div class="studio-settings-content">
|
||||
<label>页面名称<input name="name" value="<?= $e($page['name']) ?>" required maxlength="100"></label>
|
||||
<?php if ($layout): ?>
|
||||
<input type="hidden" name="title" value="<?= $e($page['title']) ?>">
|
||||
<?php if ($layoutDefault && $layoutBase): ?>
|
||||
<p class="field-note">当前站点默认<?= $e(LayoutPage::TYPES[$layout['kind']]) ?></p>
|
||||
<?php else: ?>
|
||||
<label><input type="checkbox" name="make_default" value="1"<?= $layoutDefault ? ' checked' : '' ?>> 用作站点默认<?= $e(LayoutPage::TYPES[$layout['kind']]) ?></label>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<label>SEO 标题<input name="title" value="<?= $e($page['title']) ?>" required maxlength="160"></label>
|
||||
<label>SEO 描述<textarea name="description" rows="2" maxlength="300"><?= $e($page['description']) ?></textarea></label>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<fieldset class="admin-options form-grid">
|
||||
<legend>页面显示</legend>
|
||||
<?php $heroVisible = $page['visibility']['hero'] ?? true; ?>
|
||||
<label>首屏<select name="show_hero"><option value="1"<?= $heroVisible ? ' selected' : '' ?>>显示</option>
|
||||
<option value="0"<?= !$heroVisible ? ' selected' : '' ?>>隐藏</option></select></label>
|
||||
<?php if (!$layout): ?>
|
||||
<?php foreach (['header' => '页头', 'footer' => '页脚'] as $kind => $label): ?>
|
||||
<?php $visible = $page['visibility'][$kind] ?? true; ?>
|
||||
<label><?= $e($label) ?><select name="<?= $e($kind) ?>_choice">
|
||||
<option value="hidden"<?= !$visible ? ' selected' : '' ?>>隐藏</option>
|
||||
<option value=""<?= $visible && $page[$kind . '_id'] === null ? ' selected' : '' ?>>站点默认</option>
|
||||
<?php foreach ($designs as $item): ?>
|
||||
<?php if ($item['kind'] !== $kind) continue; ?>
|
||||
<option value="<?= $e($item['id']) ?>"<?= $visible && $page[$kind . '_id'] === $item['id'] ? ' selected' : '' ?>><?= $e($item['name']) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<?php endif ?>
|
||||
</fieldset>
|
||||
<div data-palette-picker>
|
||||
<label for="page-palette">配色方案</label>
|
||||
<select id="page-palette" name="palette_id">
|
||||
<?php foreach ($paletteOptions as $option): ?>
|
||||
<option value="<?= $e($option['id']) ?>"<?= (string) $page['palette_id'] === (string) $option['id'] ? ' selected' : '' ?>><?= $e($option['name']) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<details class="palette-picker" hidden>
|
||||
<summary aria-label="选择配色方案"><span data-palette-current></span><?= View::fragment('studio-icon', ['icon' => 'chevron']) ?></summary>
|
||||
<div class="palette-picker-options">
|
||||
<?php foreach ($paletteOptions as $option): ?>
|
||||
<button type="button" data-palette-option="<?= $e($option['id']) ?>"
|
||||
aria-pressed="<?= (string) $page['palette_id'] === (string) $option['id'] ? 'true' : 'false' ?>">
|
||||
<span class="palette-name"><?= $e($option['name']) ?><?= $option['colors'] ? View::fragment('palette-swatches', ['colors' => $option['colors']]) : '' ?></span>
|
||||
</button>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php if (($layout['kind'] ?? '') === 'header'): ?>
|
||||
<details class="admin-options" data-shared-auth<?= $layoutHasMember ? '' : ' hidden' ?>>
|
||||
<summary>会员登录设置</summary>
|
||||
@@ -278,16 +307,24 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<input type="hidden" name="<?= $e($field) ?>" value="<?= $e($value) ?>">
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
<?php if (!$layout && $slug !== 'home'): ?>
|
||||
<label>发布状态<select name="status"><option value="draft" <?= $page['status'] === 'draft' ? 'selected' : '' ?>>草稿</option>
|
||||
<option value="published" <?= $page['status'] === 'published' ? 'selected' : '' ?>>已发布</option></select></label>
|
||||
<?php endif ?>
|
||||
<?php if ($headEditor): ?>
|
||||
<?= View::fragment('head-settings', ['label' => '本页 Head', 'head' => $page['head_html']]) ?>
|
||||
<?php elseif (!$layout): ?>
|
||||
<p class="field-note">本页 Head 尚不可用。<?= $e(Database::MIGRATION_REQUIRED) ?></p>
|
||||
<?php endif ?>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit"><?= View::fragment('studio-icon', ['icon' => 'save']) ?>保存页面</button></div>
|
||||
<div class="form-submit studio-settings-actions">
|
||||
<button class="button button-primary" type="submit"><?= View::fragment('studio-icon', ['icon' => 'save']) ?>保存页面</button>
|
||||
<?php if (!$layout && $slug !== 'home'): ?>
|
||||
<div class="studio-publication">
|
||||
<span>发布状态</span><span class="dashboard-page-state" data-page-publication data-published="<?= $published ? 'true' : 'false' ?>"><?= $published ? '已发布' : '草稿' ?></span>
|
||||
<button class="button button-outline" type="submit" name="status" value="<?= $published ? 'draft' : 'published' ?>" data-publish-button>
|
||||
<span data-publication-action="published"<?= $published ? ' hidden' : '' ?>><?= View::fragment('studio-icon', ['icon' => 'publish']) ?>发布</span>
|
||||
<span data-publication-action="draft"<?= $published ? '' : ' hidden' ?>><?= View::fragment('studio-icon', ['icon' => 'unpublish']) ?>转为草稿</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<p class="feedback success" data-page-save-feedback role="status" hidden></p>
|
||||
</form>
|
||||
</div>
|
||||
<?php if (!$layout): ?><?= View::fragment('studio-page-templates', compact('token')) ?><?php endif ?>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\View;
|
||||
|
||||
$previewKeys = ['accent', 'ink', 'muted', 'paper', 'white', 'line', 'accent-deep', 'accent-light', 'button-ink'];
|
||||
?>
|
||||
<svg class="palette-swatches" viewBox="0 0 133 14" aria-hidden="true" focusable="false">
|
||||
<?php foreach ($previewKeys as $index => $key): ?>
|
||||
<circle cx="<?= 7 + 15 * $index ?>" cy="7" r="6" data-color-key="<?= View::escape($key) ?>" fill="<?= View::escape($colors[$key] ?? DesignLibrary::COLORS[$key][1]) ?>"/>
|
||||
<?php endforeach ?>
|
||||
</svg>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<dialog class="media-picker canvas-fill" data-canvas-fill aria-labelledby="canvas-fill-title" data-color-labels="<?= $e(json_encode(array_map(static fn (array $color): string => $color[0], DesignLibrary::COLORS), JSON_THROW_ON_ERROR)) ?>">
|
||||
<div class="admin-heading compact"><h2 id="canvas-fill-title" data-fill-title>背景填充</h2></div>
|
||||
<form method="dialog" class="admin-form">
|
||||
<div class="preview-selector" role="tablist" aria-label="背景填充类型" data-fill-tabs>
|
||||
<?php foreach (['solid' => '纯色', 'gradient' => '渐变色', 'image' => '背景图'] as $mode => $label): ?>
|
||||
<button class="button button-outline" type="button" role="tab" id="fill-tab-<?= $mode ?>" aria-selected="false"
|
||||
aria-controls="fill-panel-<?= $mode ?>" data-fill-tab="<?= $mode ?>"><?= $label ?></button>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<div id="fill-panel-solid" role="tabpanel" aria-labelledby="fill-tab-solid" data-fill-panel="solid">
|
||||
<label>颜色<input type="color" name="solid" value="#ffffff"></label>
|
||||
<div class="canvas-color-swatches" data-fill-swatches="solid" role="group" aria-label="当前配色方案"></div>
|
||||
</div>
|
||||
<div id="fill-panel-gradient" role="tabpanel" aria-labelledby="fill-tab-gradient" data-fill-panel="gradient" hidden>
|
||||
<div class="form-grid">
|
||||
<div>
|
||||
<label>起始色<input type="color" name="start" value="#ffffff"></label>
|
||||
<div class="canvas-color-swatches" data-fill-swatches="start" role="group" aria-label="起始色 · 当前配色方案"></div>
|
||||
</div>
|
||||
<div>
|
||||
<label>结束色<input type="color" name="end" value="#214ed7"></label>
|
||||
<div class="canvas-color-swatches" data-fill-swatches="end" role="group" aria-label="结束色 · 当前配色方案"></div>
|
||||
</div>
|
||||
</div>
|
||||
<label>角度(°)<input type="number" name="angle" min="0" max="360" step="1" value="90"></label>
|
||||
</div>
|
||||
<div id="fill-panel-image" role="tabpanel" aria-labelledby="fill-tab-image" data-fill-panel="image" hidden>
|
||||
<label>图片链接<input type="text" name="image" maxlength="1000" placeholder="/assets/uploads/… 或 https://…"></label>
|
||||
<button class="button button-outline" type="button" data-fill-media><?= View::fragment('studio-icon', ['icon' => 'media']) ?>从媒体库选择</button>
|
||||
</div>
|
||||
<p class="feedback error" data-fill-error role="alert" hidden></p>
|
||||
<div class="actions">
|
||||
<button class="button button-primary" type="submit">应用</button>
|
||||
<button class="button button-outline" type="button" data-fill-reset>恢复默认</button>
|
||||
<button class="button button-outline" type="button" data-fill-close>取消</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -11,6 +11,16 @@ $paths = [
|
||||
'delete' => '<path d="M4 7h16M9 7V4h6v3m3 0-.8 13H6.8L6 7m4 4v5m4-5v5"/>',
|
||||
'external' => '<path d="M13 5h6v6m0-6-8 8m6 0v5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1h5"/>',
|
||||
'preview' => '<path d="M2.5 12s3.5-6 9.5-6 9.5 6 9.5 6-3.5 6-9.5 6-9.5-6-9.5-6Z"/><circle cx="12" cy="12" r="2.5"/>',
|
||||
'website' => '<rect x="3" y="4.5" width="18" height="15" rx="2"/><path d="M3 9h18m-7 3h4v4m0-4-5 5"/>',
|
||||
'heading' => '<path d="M5 5v14M15 5v14M5 12h10m4-3h2m-2 6h2"/>',
|
||||
'paragraph' => '<path d="M14 4h6m-3 0v16m-4 0V4h-2a4.5 4.5 0 0 0 0 9h2"/>',
|
||||
'list' => '<path d="M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01"/>',
|
||||
'link' => '<path d="m10 14 4-4m-6 6-1 1a3.5 3.5 0 0 1-5-5l4-4a3.5 3.5 0 0 1 5 0m2 8a3.5 3.5 0 0 0 5 0l4-4a3.5 3.5 0 0 0-5-5l-1 1"/>',
|
||||
'undo' => '<path d="M4 4v6h6m-6 0 2-2a8 8 0 1 1 0 12"/>',
|
||||
'redo' => '<path d="M20 4v6h-6m6 0-2-2a8 8 0 1 0 0 12"/>',
|
||||
'publish' => '<path d="M12 16V4m-4 4 4-4 4 4M4 15v5h16v-5"/>',
|
||||
'unpublish' => '<path d="M12 4v12m-4-4 4 4 4-4M4 15v5h16v-5"/>',
|
||||
'fill' => '<path d="m8 3 8 8m-6-5 7 7-7 7-7-7 7-7Zm-5 7h12m3 1s-2 2.7-2 4a2 2 0 0 0 4 0c0-1.3-2-4-2-4Z"/>',
|
||||
'globe' => '<circle cx="12" cy="12" r="9"/><ellipse cx="12" cy="12" rx="4" ry="9"/><path d="M3 12h18"/>',
|
||||
'account' => '<circle cx="12" cy="8" r="3.2"/><path d="M5 20v-2a7 7 0 0 1 14 0v2"/>',
|
||||
'chevron' => '<path d="m6 9 6 6 6-6"/>',
|
||||
|
||||
Reference in New Issue
Block a user