From 92354d7e4a1f7ee49b0ca6dc578938fb4b8921a0 Mon Sep 17 00:00:00 2001 From: ChatGPT Date: Sun, 22 Nov 2026 00:59:59 +0800 Subject: [PATCH] Manage dynamic blocks and expand the editor library --- README.md | 6 +- app/Content/BlockTemplates.php | 56 +++- app/Content/Database.php | 14 + app/Content/Html.php | 18 +- app/Content/Repository.php | 23 +- app/Controller/AdminController.php | 59 +++- app/Controller/SiteController.php | 15 +- app/Controller/StudioController.php | 2 +- app/view/admin-page.php | 48 +++- app/view/admin-section.php | 28 +- app/view/network-groups.php | 22 +- app/view/network-items.php | 27 ++ app/view/page.php | 21 +- app/view/section.php | 33 ++- app/view/studio-anchor-form.php | 24 ++ app/view/studio-feed-fields.php | 15 + app/view/studio-icon.php | 12 + app/view/studio-layers.php | 31 +-- app/view/studio-library-panel.php | 8 +- app/view/studio-templates.php | 4 +- public/assets/admin.css | 38 ++- public/assets/site.css | 11 + public/assets/studio.js | 260 +++++++++++++++--- .../existing-highspeaker-comparison.webp | Bin 0 -> 27596 bytes .../existing-highspeaker-features.webp | Bin 0 -> 23136 bytes .../existing-highspeaker-get.webp | Bin 0 -> 7490 bytes .../existing-highspeaker-hero.webp | Bin 0 -> 15008 bytes .../existing-highspeaker-pricing.webp | Bin 0 -> 17162 bytes .../existing-highspeaker-registration.webp | Bin 0 -> 25500 bytes .../existing-highspeaker-support.webp | Bin 0 -> 22346 bytes .../existing-home-about.webp | Bin 0 -> 13150 bytes .../template-previews/existing-home-blog.webp | Bin 0 -> 4002 bytes .../template-previews/existing-home-hero.webp | Bin 0 -> 15336 bytes .../existing-home-product.webp | Bin 0 -> 22232 bytes .../existing-pagepan-demo.webp | Bin 0 -> 17848 bytes .../existing-pagepan-download.webp | Bin 0 -> 27960 bytes .../existing-pagepan-features.webp | Bin 0 -> 15280 bytes .../existing-pagepan-hero.webp | Bin 0 -> 16562 bytes .../existing-pagepan-licensing.webp | Bin 0 -> 29210 bytes .../existing-pagepan-pricing.webp | Bin 0 -> 27268 bytes .../template-previews/existing-sc-faq.webp | Bin 0 -> 11498 bytes .../template-previews/existing-sc-fees.webp | Bin 0 -> 18414 bytes .../template-previews/existing-sc-go.webp | Bin 0 -> 11232 bytes .../template-previews/existing-sc-hero.webp | Bin 0 -> 17018 bytes .../existing-sc-materials.webp | Bin 0 -> 17550 bytes .../existing-sc-options.webp | Bin 0 -> 19862 bytes .../existing-sc-pricing.webp | Bin 0 -> 27638 bytes .../template-previews/existing-sc-terms.webp | Bin 0 -> 9392 bytes .../template-previews/existing-sc-why.webp | Bin 0 -> 21958 bytes .../existing-shnu-sc-benefits.webp | Bin 0 -> 19130 bytes .../existing-shnu-sc-faq.webp | Bin 0 -> 11498 bytes .../existing-shnu-sc-fees.webp | Bin 0 -> 18414 bytes .../existing-shnu-sc-go.webp | Bin 0 -> 11232 bytes .../existing-shnu-sc-hero.webp | Bin 0 -> 20576 bytes .../existing-shnu-sc-materials.webp | Bin 0 -> 17550 bytes .../existing-shnu-sc-options.webp | Bin 0 -> 19862 bytes .../existing-shnu-sc-pricing.webp | Bin 0 -> 29068 bytes .../existing-shnu-sc-stories.webp | Bin 0 -> 19544 bytes .../existing-shnu-sc-terms.webp | Bin 0 -> 29754 bytes .../existing-shnu-sc-why.webp | Bin 0 -> 21896 bytes public/assets/template-previews/network.webp | Bin 0 -> 8026 bytes .../template-previews/product-links.webp | Bin 0 -> 8228 bytes tests/studio-browser.cjs | 84 +++++- 63 files changed, 671 insertions(+), 188 deletions(-) create mode 100644 app/view/network-items.php create mode 100644 app/view/studio-anchor-form.php create mode 100644 app/view/studio-feed-fields.php create mode 100644 app/view/studio-icon.php create mode 100644 public/assets/template-previews/existing-highspeaker-comparison.webp create mode 100644 public/assets/template-previews/existing-highspeaker-features.webp create mode 100644 public/assets/template-previews/existing-highspeaker-get.webp create mode 100644 public/assets/template-previews/existing-highspeaker-hero.webp create mode 100644 public/assets/template-previews/existing-highspeaker-pricing.webp create mode 100644 public/assets/template-previews/existing-highspeaker-registration.webp create mode 100644 public/assets/template-previews/existing-highspeaker-support.webp create mode 100644 public/assets/template-previews/existing-home-about.webp create mode 100644 public/assets/template-previews/existing-home-blog.webp create mode 100644 public/assets/template-previews/existing-home-hero.webp create mode 100644 public/assets/template-previews/existing-home-product.webp create mode 100644 public/assets/template-previews/existing-pagepan-demo.webp create mode 100644 public/assets/template-previews/existing-pagepan-download.webp create mode 100644 public/assets/template-previews/existing-pagepan-features.webp create mode 100644 public/assets/template-previews/existing-pagepan-hero.webp create mode 100644 public/assets/template-previews/existing-pagepan-licensing.webp create mode 100644 public/assets/template-previews/existing-pagepan-pricing.webp create mode 100644 public/assets/template-previews/existing-sc-faq.webp create mode 100644 public/assets/template-previews/existing-sc-fees.webp create mode 100644 public/assets/template-previews/existing-sc-go.webp create mode 100644 public/assets/template-previews/existing-sc-hero.webp create mode 100644 public/assets/template-previews/existing-sc-materials.webp create mode 100644 public/assets/template-previews/existing-sc-options.webp create mode 100644 public/assets/template-previews/existing-sc-pricing.webp create mode 100644 public/assets/template-previews/existing-sc-terms.webp create mode 100644 public/assets/template-previews/existing-sc-why.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-benefits.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-faq.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-fees.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-go.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-hero.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-materials.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-options.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-pricing.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-stories.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-terms.webp create mode 100644 public/assets/template-previews/existing-shnu-sc-why.webp create mode 100644 public/assets/template-previews/network.webp create mode 100644 public/assets/template-previews/product-links.webp diff --git a/README.md b/README.md index 9d84e3d..8709710 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ php bin/admin.php reset admin@example.com ## 后台编辑 - **网站后台**可按名称、地址或发布状态查找页面,从列表打开画布、公开页或草稿预览。 -- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧分为「组件」「元素」「图层」。先进入分类,再查找并插入模板或基础元素。悬停或键盘聚焦缩略图可放大,点击可打开预览。 +- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧分为「组件」「元素」「图层」。先进入分类,再查找并插入模板或基础元素。已有五个内置页面的首屏图文和正文区块都可复用,徽标、按钮组、面包屑、进度、通知和折叠等元素参考 [Preline UI 免费组件文档](https://preline.co/docs/index.html),用本站样式实现。悬停或键盘聚焦缩略图可放大,点击可打开预览。 - **媒体库**集中列出项目静态文件及上传文件,支持查找、选取、复制路径、改名和归档。归档资源的已有 URL 保持可访问。上传文件放在 `LAYSENSE_MEDIA_DIR`,由 `/assets/uploads/` 提供。 - **文章**使用自托管的 TOAST UI Editor 3.2.2(MIT)。Markdown 左侧源码、右侧实时预览,富文本使用所见即所得模式。文章可以加入多个分类,可在「管理分类」创建新分类。 -- **分类文章**支持在任意页面添加,保存区块后在「图层」中编辑分类、展示数量和合并或标签页模式。「查看全部动态」和翻页只列出该区块所选的分类。 +- **分类文章**支持在任意页面添加,选中动态模块后可用浮动工具条打开设置、复制或删除,随页面一起保存。文章列表和项目与伙伴卡片共用分类设置。「查看全部动态」和翻页只列出该区块所选的分类。 - **产品与服务**(`/services`)和**支持项目与合作伙伴**(`/network`)由文章分类生成。通过文章的目录卡片设置图片、链接和排序,使用草稿状态可从目录撤下。 - **网站设置**分别编辑页头标志、导航及按钮,和页脚的公司信息、产品、公司及资源链接和备注。页脚设置可恢复原站内容。CDN 设置接受 HTTPS 源站地址。浏览器看到的公开 `/assets/…` 路径使用该源站。 - 文章支持摘要和标签。状态选「草稿」可撤回公开文章。已发布文章改网址标识后,旧标识会自动跳转。 @@ -71,7 +71,7 @@ location = /admin/media { | `LAYSENSE_SECURE_COOKIES` | 默认关闭 · 本地 HTTP 使用默认值。生产 HTTPS 设置为 `1`。 | | `LAYSENSE_TRUSTED_PROXIES` | 默认 `127.0.0.1,::1` · 逗号分隔的受信反代 IP,设为空字符串可关闭信任 | -SQLite 已启用 WAL。使用上一版多分类文章结构的站点,可用当前 `LAYSENSE_DB` 运行 `php bin/install.php` 增加对齐字段,之后重启 Webman。全新安装时,将 `LAYSENSE_DB` 指向新文件并按上面的步骤初始化和创建管理员。安装会预载网站自带页面、文章、产品和伙伴目录。服务用户需要对 SQLite 目录、媒体目录和 `runtime/` 有写权限。备份可用 `sqlite3 storage/laysense.sqlite ".backup 'laysense-backup.sqlite'"`,媒体目录单独保存。 +SQLite 已启用 WAL。使用上一版多分类文章结构的站点,可用当前 `LAYSENSE_DB` 运行 `php bin/install.php` 增量安装,之后重启 Webman。首页五联导航和伙伴动态模块会作为可管理区块导入一次。全新安装时,将 `LAYSENSE_DB` 指向新文件并按上面的步骤初始化和创建管理员。安装会预载网站自带页面、文章、产品和伙伴目录。服务用户需要对 SQLite 目录、媒体目录和 `runtime/` 有写权限。备份可用 `sqlite3 storage/laysense.sqlite ".backup 'laysense-backup.sqlite'"`,媒体目录单独保存。 ### CDN diff --git a/app/Content/BlockTemplates.php b/app/Content/BlockTemplates.php index c8feba0..50a30b2 100644 --- a/app/Content/BlockTemplates.php +++ b/app/Content/BlockTemplates.php @@ -8,6 +8,10 @@ final class BlockTemplates { public const ARTICLE_FEED = '{"categories":["announcement","news","product"],"mode":"merged","limit":6}'; + public const NETWORK_FEED = '{"categories":["supported-projects","partners"],"mode":"network","limit":30}'; + + public const PRODUCT_LINKS = '
产品与服务PAGEPAN可视化建站HighSpeaker DNS开源智能解析软著代理登记申请与材料服务SHNU 学生软著申请方案
'; + public const ELEMENT_GROUPS = [ 'text-elements' => ['文字与列表', [ 'paragraph' => ['段落', '

填写正文。

'], @@ -16,24 +20,39 @@ final class BlockTemplates 'blockquote' => ['引用', '

填写需要引用的内容。

'], 'bullet-list' => ['项目列表', ''], 'ordered-list' => ['编号列表', '
  1. 填写第一项
  2. 填写第二项
'], + 'heading-kicker' => ['标题眉标', '

填写分类名称

'], + 'tag' => ['徽标', '

填写标签

'], + 'large-number' => ['重点数字', '

填写数字

'], 'definition-list' => ['术语说明', '
填写术语
填写术语说明。
'], ]], 'link-elements' => ['链接与按钮', [ 'button' => ['主按钮', '

联系来笙

'], 'outline-button' => ['描边按钮', '

查看服务

'], 'text-link' => ['文字链接', '

阅读文章

'], + 'button-group' => ['按钮组', '
查看服务联系团队
'], + 'breadcrumbs' => ['面包屑', ''], + 'download-link' => ['下载入口', '

查看下载

'], 'email-link' => ['邮件链接', '

发送邮件

'], ]], 'media-elements' => ['图片与影音', [ 'image' => ['图片', '', 'image/'], 'video' => ['视频', '', 'video/'], 'audio' => ['音频', '', 'audio/'], + 'qr-image' => ['二维码', '', 'image/'], + 'image-link' => ['图片链接', '

PAGEPAN 产品预览

'], ]], 'structure-elements' => ['版式与数据', [ 'separator' => ['分割线', '
'], 'spacer' => ['留白', '
'], 'code' => ['代码块', '
填写代码
'], 'basic-table' => ['数据表格', '
名称数据
填写名称填写数据
'], + 'progress' => ['进度条', '

完成进度

65%
'], + 'alert' => ['提示卡', '

请注意

填写一条提示信息。

'], + 'simple-card' => ['内容卡片', '

填写卡片标题

填写卡片内容。

'], + 'link-card' => ['链接卡片', '

查看资料

填写链接指向的资料说明。

打开资料
'], + 'list-group' => ['列表组', ''], + 'empty-card' => ['空状态', '

暂无内容

填写访客可以执行的下一步。

查看站点动态
'], + 'status-note' => ['状态提示', '

已完成

填写操作结果或服务状态。

'], 'disclosure' => ['折叠内容', '
填写折叠标题

填写展开后的内容。

'], ]], ]; @@ -42,7 +61,8 @@ final class BlockTemplates 'content' => ['标题与正文', [ 'headline' => ['标题与简介', '

填写区块标题

用一句话补充背景或说明。

'], 'text' => ['正文', '

在这里输入区块内容。

'], - 'articles' => ['分类文章', ''], + 'articles' => ['分类文章', '', '', self::ARTICLE_FEED], + 'network' => ['支持项目与合作伙伴', '', '', self::NETWORK_FEED], 'list' => ['步骤列表', '
  1. 填写第一步
  2. 填写第二步
  3. 填写第三步
'], 'notice' => ['重点提示', '

填写重要提示

说明访客需要知悉的事项、条件或时间。

'], ]], @@ -74,6 +94,7 @@ final class BlockTemplates 'pricing' => ['双方案报价', '
'], ]], 'actions' => ['导航与引导', [ + 'product-links' => ['产品与服务五联导航', self::PRODUCT_LINKS], 'navigation' => ['快速导航', ''], 'cta' => ['行动按钮', '

说明下一步。

联系来笙

'], 'resources' => ['资料与链接', ''], @@ -81,9 +102,40 @@ final class BlockTemplates ]], ]; + public static function groups(): array + { + static $groups; + if ($groups !== null) { + return $groups; + } + + $groups = self::GROUPS; + $seed = json_decode(file_get_contents(dirname(__DIR__, 2) . '/resources/seed.json'), true, flags: JSON_THROW_ON_ERROR); + foreach ($seed['pages'] as $page) { + $links = ''; + foreach ($page['actions'] as [$url, $label]) { + $links .= '' . View::escape($label) . ''; + } + $hero = '
' . View::escape($page['alt']) . '' + . '

' . View::escape(trim($page['heading'] . ' ' . $page['accent'])) . '

' . View::escape($page['lead']) + . '

' . $links . '
'; + $items = ['existing-' . $page['slug'] . '-hero' => ['首屏图文', $hero]]; + foreach ($page['sections'] as $section) { + $items['existing-' . $page['slug'] . '-' . $section['key']] = [ + $section['title'], Html::sanitize($section['body']), $section['lead'], + isset($section['feed']) ? Database::json($section['feed']) : null, + $section['style'], + ]; + } + $groups['existing-' . $page['slug']] = ['现有页面 · ' . $page['name'], $items]; + } + + return $groups; + } + public static function find(string $key): ?array { - foreach (self::GROUPS as [, $templates]) { + foreach (self::groups() as [, $templates]) { if (isset($templates[$key])) { return $templates[$key]; } diff --git a/app/Content/Database.php b/app/Content/Database.php index 2ce7641..6beb057 100644 --- a/app/Content/Database.php +++ b/app/Content/Database.php @@ -75,6 +75,20 @@ final class Database } } + if ((int) $pdo->query('PRAGMA user_version')->fetchColumn() === 0) { + $heroDirectory = $pdo->prepare("INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, position) + VALUES ('home', 'hero-directory', '产品与服务导航', '', 'hero-links', ?, -1)"); + $heroDirectory->execute([BlockTemplates::PRODUCT_LINKS]); + $network = $pdo->prepare("INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, feed, position) + SELECT 'home', 'network', '支持项目与合作伙伴', '', 'plain', '', ?, COALESCE(MAX(position), -1) + 1 + FROM sections WHERE page_slug = 'home'"); + $network->execute([BlockTemplates::NETWORK_FEED]); + if ($heroDirectory->rowCount() + $network->rowCount() > 0) { + $pdo->exec("UPDATE pages SET version = version + 1 WHERE slug = 'home'"); + } + $pdo->exec('PRAGMA user_version = 1'); + } + $category = $pdo->prepare('INSERT OR IGNORE INTO article_categories (slug, name) VALUES (?, ?)'); foreach (Repository::CATEGORIES as $slug => $name) { $category->execute([$slug, $name]); diff --git a/app/Content/Html.php b/app/Content/Html.php index 60df8c5..34505f2 100644 --- a/app/Content/Html.php +++ b/app/Content/Html.php @@ -88,7 +88,7 @@ final class Html return $result; } - public static function sanitize(string $html): string + public static function sanitize(string $html, ?string $anchorPrefix = null): string { $document = new DOMDocument('1.0', 'UTF-8'); $document->loadHTML('' . $html . '', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET); @@ -97,6 +97,22 @@ final class Html return ''; } self::sanitizeChildren($body); + if ($anchorPrefix !== null) { + $ids = []; + foreach ($body->getElementsByTagName('*') as $element) { + $id = $element->getAttribute('id'); + if ($id !== '') { + $ids[$id] = $anchorPrefix . '-' . $id; + $element->setAttribute('id', $ids[$id]); + } + } + foreach ($body->getElementsByTagName('a') as $link) { + $href = $link->getAttribute('href'); + if (str_starts_with($href, '#') && isset($ids[substr($href, 1)])) { + $link->setAttribute('href', '#' . $ids[substr($href, 1)]); + } + } + } $output = ''; foreach ($body->childNodes as $child) { $output .= $document->saveHTML($child); diff --git a/app/Content/Repository.php b/app/Content/Repository.php index 3d35699..77a8ca1 100644 --- a/app/Content/Repository.php +++ b/app/Content/Repository.php @@ -86,7 +86,9 @@ final class Repository ]); self::checkVersion($query->rowCount()); foreach ($sections as $section) { - if ($section['version'] === null) { + if (!empty($section['delete'])) { + self::deleteSection($pdo, $slug, $section['key'], $section['version']); + } elseif ($section['version'] === null) { self::insertSection($pdo, $slug, $section['key'], $section); } else { self::updateSection($pdo, $slug, $section['key'], $section, $section['version']); @@ -111,10 +113,10 @@ final class Repository self::checkVersion($query->rowCount()); } - public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null): void + public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null, string $lead = ''): void { - Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed): void { - self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed') + ['lead' => '']); + 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); }); } @@ -129,6 +131,13 @@ final class Repository } } + private static function deleteSection(PDO $pdo, string $page, string $key, int $version): void + { + $query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?'); + $query->execute([$page, $key, $version]); + self::checkVersion($query->rowCount()); + } + public function arrangeSection(string $page, string $key, string $operation, int $version, int $pageVersion): void { Database::write(function (PDO $pdo) use ($page, $key, $operation, $version, $pageVersion): void { @@ -137,14 +146,12 @@ final class Repository $revision = $current->fetchColumn(); self::checkVersion($revision !== false && (int) $revision === $pageVersion ? 1 : 0); if ($operation === 'delete') { - $query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?'); - $query->execute([$page, $key, $version]); - self::checkVersion($query->rowCount()); + self::deleteSection($pdo, $page, $key, $version); self::touchPage($pdo, $page, structureChanged: true); return; } - $query = $pdo->prepare('SELECT key, version FROM sections WHERE page_slug = ? ORDER BY position, key'); + $query = $pdo->prepare("SELECT key, version FROM sections WHERE page_slug = ? AND style <> 'hero-links' ORDER BY position, key"); $query->execute([$page]); $revisions = $query->fetchAll(PDO::FETCH_KEY_PAIR); if (!array_key_exists($key, $revisions)) { diff --git a/app/Controller/AdminController.php b/app/Controller/AdminController.php index c9602ab..1aa1386 100644 --- a/app/Controller/AdminController.php +++ b/app/Controller/AdminController.php @@ -268,7 +268,7 @@ class AdminController strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true)) || !$validButtons) { throw new RuntimeException('请检查页面标题、说明、图片地址和按钮链接。'); } - $sections = $this->canvasSections($request->post('canvas_sections', ''), $page['sections']); + $sections = $this->canvasSections($request->post('canvas_sections', ''), $page['sections'], $repo->categories()); $repo->savePage($slug, $data, $this->version($request), $sections); return $this->success($request, '/admin/pages/' . $slug . '?saved=1'); @@ -278,7 +278,7 @@ class AdminController } return $this->render($request, 'admin-page', [ - 'title' => '编辑 ' . $page['name'], 'page' => $page, 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1', + 'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1', ], $error !== '' ? 422 : 200); } @@ -299,12 +299,12 @@ class AdminController $data = [ 'title' => $this->input($request, 'title'), 'lead' => $this->input($request, 'lead'), 'body' => $this->input($request, 'body'), - 'style' => $request->post('style') === null ? $section['style'] : $this->input($request, 'style'), + 'style' => $savedStyle === 'hero-links' || $request->post('style') === null ? $savedStyle : $this->input($request, 'style'), 'feed' => $section['feed'], ]; $section = array_replace($section, $data, ['version' => $this->version($request)]); try { - if ($request->post('feed_mode') !== null) { + if ($savedStyle !== 'hero-links' && $request->post('feed_mode') !== null) { $data['feed'] = $section['feed'] = $this->feedInput($request, $categories); } $this->checkSection($data, $savedStyle); @@ -322,7 +322,7 @@ class AdminController ], $error !== '' ? 422 : 200); } - private function canvasSections(mixed $payload, array $sections): array + private function canvasSections(mixed $payload, array $sections, array $categories): array { if ($payload === '') { return []; @@ -336,15 +336,46 @@ class AdminController foreach ($changes as $change) { $key = $change['key'] ?? null; $version = $change['version'] ?? null; - $fields = $change['fields'] ?? null; + $fields = $change['fields'] ?? []; $alignments = $change['alignments'] ?? null; + $feed = $change['feed'] ?? null; + $delete = ($change['delete'] ?? false) === true; $isNew = is_array($change) && array_key_exists('version', $change) && $version === null; - if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || ($fields === [] && $alignments === null) + if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || (!$delete && $fields === [] && $alignments === null && $feed === null) || ($isNew ? (isset($available[$key]) || !preg_match('/^block-[a-f0-9]{32}$/D', $key)) : (!isset($available[$key]) || !is_int($version) || $version !== (int) $available[$key]['version']))) { throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。'); } + if ($delete) { + if ($isNew || empty($available[$key]['feed'])) { + throw new RuntimeException('此区块不能通过模块工具删除。'); + } + $updates[$key] = compact('key', 'version', 'delete'); + continue; + } $section = $available[$key] ?? ['key' => $key, 'title' => '', 'lead' => '', 'body' => '', 'style' => 'plain']; + if ($isNew && isset($change['template'])) { + $preset = is_string($change['template']) ? BlockTemplates::find($change['template']) : null; + if ($preset === null) { + throw new RuntimeException('区块模板已失效。'); + } + $section['feed'] = $preset[3] ?? null; + $section['style'] = $preset[4] ?? 'plain'; + } + if ($isNew && isset($change['copyOf'])) { + $source = $change['copyOf']['key'] ?? null; + $sourceVersion = $change['copyOf']['version'] ?? null; + if (!is_string($source) || empty($available[$source]['feed']) || $sourceVersion !== (int) $available[$source]['version']) { + throw new RuntimeException('原模块已变更,请刷新画布后再复制。'); + } + $section = array_replace($available[$source], ['key' => $key]); + } + if ($feed !== null) { + if (!is_array($feed) || empty($section['feed'])) { + throw new RuntimeException('模块设置不正确。'); + } + $section['feed'] = $this->encodeFeed($feed['mode'] ?? null, $feed['categories'] ?? null, $feed['limit'] ?? null, $categories); + } foreach ($fields as $field => $value) { if (!in_array($field, ['title', 'lead', 'body'], true)) { throw new RuntimeException('画布内容无效。'); @@ -364,9 +395,6 @@ class AdminController if (isset($fields['body'])) { $section['body'] = Html::sanitize($section['body']); } - if ($isNew && ($change['template'] ?? null) === 'articles') { - $section['feed'] = BlockTemplates::ARTICLE_FEED; - } $section['version'] = $version; $updates[$key] = $section; } @@ -546,9 +574,14 @@ class AdminController if ($mode === 'off') { return null; } - $categories = $this->selectedCategories($request->post('feed_categories')); - $limit = filter_var($this->input($request, 'feed_limit'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 30]]); - if (!in_array($mode, ['merged', 'tabs'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) { + return $this->encodeFeed($mode, $request->post('feed_categories'), $this->input($request, 'feed_limit'), $available); + } + + private function encodeFeed(mixed $mode, mixed $selected, mixed $value, array $available): string + { + $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'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) { throw new RuntimeException('请选择文章分类,并将展示数量设为 1 至 30。'); } diff --git a/app/Controller/SiteController.php b/app/Controller/SiteController.php index 1e9585f..43a8968 100644 --- a/app/Controller/SiteController.php +++ b/app/Controller/SiteController.php @@ -37,14 +37,20 @@ final class SiteController continue; } $feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR); - $tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1; + $network = $feed['mode'] === 'network'; + $grouped = $network || ($feed['mode'] === 'tabs' && count($feed['categories']) > 1); + $archivePath = '/articles/feed/' . $slug . '/' . $section['key']; + if ($network && count($feed['categories']) === 2 && !array_diff($feed['categories'], ['supported-projects', 'partners'])) { + $archivePath = '/network'; + } + $section['archivePath'] = $page['status'] === 'published' ? $archivePath : null; $section['articleFeed'] = []; - $section['archivePath'] = $page['status'] === 'published' ? '/articles/feed/' . $slug . '/' . $section['key'] : null; - foreach ($tabs ? $feed['categories'] : [''] as $category) { + $section['networkFeed'] = $network; + foreach ($grouped ? $feed['categories'] : [''] as $category) { $selected = $category === '' ? $feed['categories'] : [$category]; $section['articleFeed'][] = [ 'categories' => $selected, 'label' => $categories[$category] ?? '', - 'articles' => $repo->articles($selected, limit: $feed['limit']), + 'articles' => $repo->articles($selected, limit: $feed['limit'], directoryOrder: $network), ]; } } @@ -58,7 +64,6 @@ final class SiteController 'description' => $page['description'], 'socialImage' => $page['image'], 'socialAlt' => $page['alt'], - 'network' => $isHome ? $this->networkGroups($repo) : [], 'previewMode' => $preview, 'canvas' => $preview && $canvas, 'noindex' => $preview, ]); } diff --git a/app/Controller/StudioController.php b/app/Controller/StudioController.php index 00799a2..a4a92eb 100644 --- a/app/Controller/StudioController.php +++ b/app/Controller/StudioController.php @@ -74,7 +74,7 @@ final class StudioController extends AdminController if ($preset === null) { throw new RuntimeException('请选择区块类型。'); } - $repo->createSection($slug, $key, $preset[0], 'plain', $preset[1], $type === 'articles' ? BlockTemplates::ARTICLE_FEED : null); + $repo->createSection($slug, $key, $preset[0], $preset[4] ?? 'plain', Html::sanitize($preset[1], $key), $preset[3] ?? null, $preset[2] ?? ''); return $this->success($request, "/admin/pages/$slug/$key"); } diff --git a/app/view/admin-page.php b/app/view/admin-page.php index 2de715c..1358643 100644 --- a/app/view/admin-page.php +++ b/app/view/admin-page.php @@ -10,8 +10,10 @@ $previewUrl = '/admin/pages/' . $slug . '/preview'; ?> 返回页面
-

·

+

+

@@ -20,7 +22,10 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
@@ -45,13 +50,13 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
-

单击画布元素可设置对齐、复制或删除。选中媒体后可拖动边缘手柄调整宽度。

+

编辑属性

+ + +
@@ -80,6 +88,19 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
+ +

模块设置

+
+ + + $categories, 'feed' => [], 'allowOff' => false]) ?> + +
+ + +
+
+
@@ -88,6 +109,15 @@ $previewUrl = '/admin/pages/' . $slug . '/preview'; +
+ 首屏与目录 +
+ + + + +
+
diff --git a/app/view/admin-section.php b/app/view/admin-section.php index 6eda29c..1bac8dd 100644 --- a/app/view/admin-section.php +++ b/app/view/admin-section.php @@ -17,23 +17,17 @@ $feed = json_decode($section['feed'] ?? '{}', true, flags: JSON_THROW_ON_ERROR); - -
> - 文章组件 -
- - -
- 'feed_categories', 'selected' => $feed['categories'] ?? [], 'categories' => $categories, 'legend' => '展示哪些分类(可多选)']) ?> -
+ + +
> + 动态模块 + $categories, 'feed' => $feed, 'allowOff' => true]) ?> +
+ 'html', 'body' => $section['body']]) ?>
diff --git a/app/view/network-groups.php b/app/view/network-groups.php index 39d659f..b2415b5 100644 --- a/app/view/network-groups.php +++ b/app/view/network-groups.php @@ -1,6 +1,4 @@ ">

暂无已发布条目。

- + $group['articles'], 'standalone' => $standalone]) ?> diff --git a/app/view/network-items.php b/app/view/network-items.php new file mode 100644 index 0000000..a99ed32 --- /dev/null +++ b/app/view/network-items.php @@ -0,0 +1,27 @@ + + diff --git a/app/view/page.php b/app/view/page.php index f33dad0..f16fb89 100644 --- a/app/view/page.php +++ b/app/view/page.php @@ -55,15 +55,11 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' . - - - + + + $section, 'moment' => false, 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?> + + - $section, 'moment' => $home && $section['key'] === 'about', 'canvas' => $canvas]) ?> + + $section, 'moment' => $home && $section['key'] === 'about', 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?> + - - $network, 'standalone' => false]) ?> - diff --git a/app/view/section.php b/app/view/section.php index 3d9cfe7..34ca269 100644 --- a/app/view/section.php +++ b/app/view/section.php @@ -4,20 +4,45 @@ use App\Content\View; $e = View::escape(...); $canvas ??= false; $body = $section['body']; +$dynamic = isset($section['feed']); +$studio = $canvas ? ' data-studio-section="' . $e($section['version']) . '" data-studio-source="' . $e(base64_encode($section['body'])) . '"' : ''; +if ($canvas && $dynamic) { + $studio .= ' data-studio-dynamic data-studio-feed="' . $e($section['feed']) . '" tabindex="0"'; +} +if ($section['style'] === 'hero-links'): +?> +
> + + >
+ +查看全部动态

') { +if ($dynamic && $body === '

查看全部动态

') { $body = ''; } +$network = $section['networkFeed'] ?? false; ?> -
> +
>

>

>

- + + + +
+

+ $group['articles'], 'standalone' => false]) ?> +
+ +

查看全部

+ $section['articleFeed'], 'sectionKey' => $section['key'], 'archivePath' => $section['archivePath']]) ?> -
>
+
>
diff --git a/app/view/studio-anchor-form.php b/app/view/studio-anchor-form.php new file mode 100644 index 0000000..ca0395f --- /dev/null +++ b/app/view/studio-anchor-form.php @@ -0,0 +1,24 @@ + +
+ 按锚点新建区块 +
+ + + + + +
+
diff --git a/app/view/studio-feed-fields.php b/app/view/studio-feed-fields.php new file mode 100644 index 0000000..1479810 --- /dev/null +++ b/app/view/studio-feed-fields.php @@ -0,0 +1,15 @@ + '不展示'] : []) + ['merged' => '合并列表', 'tabs' => '分类标签页', 'network' => '项目与伙伴卡片']; +?> +
+ + +
+ 'feed_categories', 'selected' => $feed['categories'] ?? [], 'categories' => $categories, 'legend' => '展示分类']) ?> diff --git a/app/view/studio-icon.php b/app/view/studio-icon.php new file mode 100644 index 0000000..06e8b10 --- /dev/null +++ b/app/view/studio-icon.php @@ -0,0 +1,12 @@ + '', + 'center' => '', + 'right' => '', + 'settings' => '', + 'edit' => '', + 'copy' => '', + 'delete' => '', +]; +?> + diff --git a/app/view/studio-layers.php b/app/view/studio-layers.php index bebdd61..b09e05b 100644 --- a/app/view/studio-layers.php +++ b/app/view/studio-layers.php @@ -1,39 +1,14 @@ -
- 首屏与目录 - - - - -
-
- 按锚点新建区块 -
- - - - - -
-
区块顺序
    $item): ?> +
  • #
    @@ -44,8 +19,8 @@ $e = View::escape(...); - - + +
    diff --git a/app/view/studio-library-panel.php b/app/view/studio-library-panel.php index 3e082a9..43fac43 100644 --- a/app/view/studio-library-panel.php +++ b/app/view/studio-library-panel.php @@ -13,6 +13,7 @@ $modules = $kind === 'modules';
+