forked from laysense/laysense.cn
Add visual CMS, media library and product directory
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use RuntimeException;
|
||||
|
||||
final class Assets
|
||||
{
|
||||
public static function cdn(string $value): string
|
||||
{
|
||||
$value = rtrim(trim($value), '/');
|
||||
if ($value !== '' && (strlen($value) > 263 || !preg_match('~^https://(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?::[0-9]{1,5})?$~iD', $value))) {
|
||||
throw new RuntimeException('请填写 HTTPS CDN 源站地址,例如 https://cdn.laysense.cn。');
|
||||
}
|
||||
if (($port = parse_url($value, PHP_URL_PORT)) !== null && ($port === false || $port < 1)) {
|
||||
throw new RuntimeException('CDN 端口无效。');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function url(string $path, string $cdn): string
|
||||
{
|
||||
return str_starts_with($path, '/assets/') ? $cdn . $path : $path;
|
||||
}
|
||||
|
||||
public static function rewrite(string $html, string $cdn): string
|
||||
{
|
||||
if ($cdn === '') {
|
||||
return $html;
|
||||
}
|
||||
$document = new DOMDocument('1.0', 'UTF-8');
|
||||
$document->loadHTML($html, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
|
||||
$xpath = new DOMXPath($document);
|
||||
foreach ($xpath->query('//@src | //@href | //@poster') as $attribute) {
|
||||
$attribute->value = self::url($attribute->value, $cdn);
|
||||
}
|
||||
|
||||
return $document->saveHTML();
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,9 @@ final class Database
|
||||
|
||||
self::write(function (PDO $pdo) use ($root, $seed): void {
|
||||
$pdo->exec(file_get_contents($root . '/resources/schema.sql'));
|
||||
if (!in_array('status', array_column($pdo->query('PRAGMA table_info(pages)')->fetchAll(), 'name'), true)) {
|
||||
$pdo->exec("ALTER TABLE pages ADD COLUMN status TEXT NOT NULL DEFAULT 'published' CHECK (status IN ('draft', 'published'))");
|
||||
}
|
||||
$site = $pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)');
|
||||
$site->execute([self::json($seed['site'])]);
|
||||
|
||||
@@ -85,6 +88,10 @@ final class Database
|
||||
if ($migration->rowCount() === 1) {
|
||||
PagepanFeatureIcons::migrate($pdo);
|
||||
}
|
||||
$migration->execute(['product_directory_and_service_icons']);
|
||||
if ($migration->rowCount() === 1) {
|
||||
DesignMigration::apply($pdo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMXPath;
|
||||
use PDO;
|
||||
|
||||
final class DesignMigration
|
||||
{
|
||||
public static function apply(PDO $pdo): void
|
||||
{
|
||||
$stock = json_decode(file_get_contents(dirname(__DIR__, 2) . '/resources/seed.json'), true, flags: JSON_THROW_ON_ERROR);
|
||||
$home = array_column($stock['pages'], null, 'slug')['home'];
|
||||
$stockBody = Html::sanitize(array_column($home['sections'], 'body', 'key')['product']);
|
||||
$doc = new DOMDocument('1.0', 'UTF-8');
|
||||
$doc->loadHTML('<meta charset="UTF-8">' . $stockBody, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
|
||||
$xpath = new DOMXPath($doc);
|
||||
$insert = $pdo->prepare('INSERT INTO catalog (name, category, body, image, alt, url, label, extra_url, extra_label, position)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
foreach ($xpath->query('//article[contains(concat(" ", @class, " "), " project ")]') as $position => $card) {
|
||||
$image = $xpath->query('.//img', $card)->item(0);
|
||||
$links = $xpath->query('.//a', $card);
|
||||
$body = '';
|
||||
foreach ($xpath->query('.//p', $card) as $paragraph) {
|
||||
$body .= $doc->saveHTML($paragraph);
|
||||
}
|
||||
$insert->execute([
|
||||
trim($xpath->evaluate('string(.//h3)', $card)), trim($xpath->evaluate('string(.//span)', $card)),
|
||||
Html::sanitize($body), $image->getAttribute('src'), $image->getAttribute('alt'),
|
||||
$links->item(0)->getAttribute('href'), trim($links->item(0)->textContent),
|
||||
$links->item(1)?->getAttribute('href') ?? '', trim($links->item(1)?->textContent ?? ''), $position * 10,
|
||||
]);
|
||||
}
|
||||
$pdo->prepare('INSERT INTO catalog (name, category, body, image, alt, url, label, position) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')
|
||||
->execute(['SHNU 学生软著服务', '校园服务', '<p>面向 SHNU 学生的软件著作权申请服务。</p>',
|
||||
'/assets/original/shnu-hero.webp', '', '/shnu-sc', '查看学生方案', 30]);
|
||||
$pdo->prepare("UPDATE sections SET body = ?, version = version + 1
|
||||
WHERE page_slug = 'home' AND key = 'product' AND version = 0 AND body = ?")
|
||||
->execute(['<p>浏览来笙的建站工具、智能 DNS 和软件著作权服务。</p><a class="button button-primary" href="/services">查看产品与服务</a>', $stockBody]);
|
||||
|
||||
$choices = $pdo->query("SELECT page_slug, body FROM sections WHERE key = 'why' AND page_slug IN ('sc', 'shnu-sc')");
|
||||
$updateChoice = $pdo->prepare("UPDATE sections SET body = ?, version = version + 1 WHERE page_slug = ? AND key = 'why'");
|
||||
foreach ($choices->fetchAll() as $section) {
|
||||
$body = preg_replace('~(<article\b[^>]*class="[^"]*\bfeature-card)("(?:[^>]*>)\s*<h[2-4]>选择来笙</h[2-4]>)~u',
|
||||
'$1 choice-card$2', $section['body']);
|
||||
if ($body !== null && $body !== $section['body']) {
|
||||
$updateChoice->execute([$body, $section['page_slug']]);
|
||||
}
|
||||
}
|
||||
|
||||
$icons = ['/assets/original/10-1.png' => '/assets/service/project.svg',
|
||||
'/assets/original/10-2.png' => '/assets/service/code.svg', '/assets/original/10-3.png' => '/assets/service/support.svg'];
|
||||
$sections = $pdo->query("SELECT page_slug, body FROM sections WHERE key = 'options' AND page_slug IN ('sc', 'shnu-sc')");
|
||||
$update = $pdo->prepare("UPDATE sections SET body = ?, version = version + 1 WHERE page_slug = ? AND key = 'options'");
|
||||
foreach ($sections->fetchAll() as $section) {
|
||||
$body = strtr($section['body'], $icons);
|
||||
$body = preg_replace('/(<article\b[^>]*>)\s*<li\b[^>]*>(.*?)<\/li>\s*(<\/article>)/s', '$1$2$3', $body);
|
||||
if ($body !== $section['body']) {
|
||||
$update->execute([$body, $section['page_slug']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ use League\CommonMark\CommonMarkConverter;
|
||||
final class Html
|
||||
{
|
||||
private const TAGS = [
|
||||
'a' => ['href'], 'article' => [], 'b' => [], 'blockquote' => [], 'br' => [],
|
||||
'a' => ['href'], 'article' => [], 'audio' => ['src', 'controls', 'preload'], 'b' => [], 'blockquote' => [], 'br' => [],
|
||||
'caption' => [], 'code' => [], 'dd' => [], 'details' => [], 'div' => ['role', 'aria-label', 'tabindex'],
|
||||
'dl' => [], 'dt' => [], 'em' => [], 'h1' => [], 'h2' => [], 'h3' => [], 'h4' => [], 'h5' => [], 'h6' => [], 'hr' => [], 'i' => [],
|
||||
'img' => ['src', 'alt', 'loading', 'width', 'height'], 'label' => ['for'],
|
||||
@@ -20,7 +20,7 @@ final class Html
|
||||
'small' => [], 'source' => ['src', 'type'], 'span' => [], 'strong' => [], 'summary' => [],
|
||||
'table' => [], 'tbody' => [], 'td' => ['colspan', 'rowspan'], 'tfoot' => [],
|
||||
'th' => ['scope', 'colspan', 'rowspan'], 'thead' => [], 'tr' => [], 'ul' => [],
|
||||
'video' => ['controls', 'muted', 'playsinline', 'poster', 'preload'],
|
||||
'video' => ['src', 'controls', 'muted', 'playsinline', 'poster', 'preload'],
|
||||
];
|
||||
|
||||
public static function url(string $value, bool $media = false): bool
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMXPath;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
use Webman\Http\UploadFile;
|
||||
|
||||
final class Media
|
||||
{
|
||||
public const MAX_BYTES = 64 * 1024 * 1024;
|
||||
|
||||
private const EXTENSIONS = [
|
||||
'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/webp' => 'webp',
|
||||
'image/avif' => 'avif', 'image/x-icon' => 'ico', 'image/vnd.microsoft.icon' => 'ico', 'image/svg+xml' => 'svg',
|
||||
'video/mp4' => 'mp4', 'video/webm' => 'webm', 'video/quicktime' => 'mov',
|
||||
'audio/mpeg' => 'mp3', 'audio/ogg' => 'ogg', 'audio/wav' => 'wav',
|
||||
'application/pdf' => 'pdf', 'font/woff' => 'woff', 'font/woff2' => 'woff2',
|
||||
];
|
||||
|
||||
public static function all(bool $includeArchived = false): array
|
||||
{
|
||||
$query = 'SELECT name, label, mime, size, created_at, archived FROM media' . ($includeArchived ? '' : ' WHERE archived = 0');
|
||||
$files = Database::connect()->query($query . ' ORDER BY created_at DESC, name')->fetchAll();
|
||||
foreach ($files as &$file) {
|
||||
$file['url'] = '/assets/uploads/' . $file['name'];
|
||||
}
|
||||
unset($file);
|
||||
|
||||
$root = dirname(__DIR__, 2) . '/public/assets';
|
||||
$builtIn = [];
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root)) as $file) {
|
||||
if (!$file->isFile() || $file->isLink() || str_starts_with($file->getFilename(), '.')) {
|
||||
continue;
|
||||
}
|
||||
$path = str_replace(DIRECTORY_SEPARATOR, '/', substr($file->getPathname(), strlen($root) + 1));
|
||||
$label = $file->getFilename();
|
||||
$type = array_search(strtolower($file->getExtension()), self::EXTENSIONS, true) ?: 'application/octet-stream';
|
||||
$builtIn[] = ['label' => $label, 'name' => '', 'mime' => $type, 'size' => $file->getSize(),
|
||||
'url' => '/assets/' . $path, 'archived' => 0];
|
||||
}
|
||||
usort($builtIn, static fn (array $left, array $right): int => strnatcasecmp($left['url'], $right['url']));
|
||||
|
||||
return [...$files, ...$builtIn];
|
||||
}
|
||||
|
||||
public static function upload(UploadFile $file, string $label): void
|
||||
{
|
||||
if (!$file->isValid() || ($size = $file->getSize()) < 1 || $size > self::MAX_BYTES) {
|
||||
throw new RuntimeException('请选择大小不超过 64 MB 的有效文件。');
|
||||
}
|
||||
$source = $file->getPathname();
|
||||
$mime = (new \finfo(FILEINFO_MIME_TYPE))->file($source);
|
||||
$extension = self::EXTENSIONS[$mime] ?? null;
|
||||
if ($extension === null) {
|
||||
throw new RuntimeException('文件类型不受支持。');
|
||||
}
|
||||
$content = $mime === 'image/svg+xml' ? self::safeSvg($source, $size) : null;
|
||||
$name = bin2hex(random_bytes(16)) . '.' . $extension;
|
||||
$directory = self::directory();
|
||||
if (!is_dir($directory) && !mkdir($directory, 0750, true) && !is_dir($directory)) {
|
||||
throw new RuntimeException('资源目录无法创建。');
|
||||
}
|
||||
$path = $directory . '/' . $name;
|
||||
try {
|
||||
$written = $content === null ? copy($source, $path) : file_put_contents($path, $content) === strlen($content);
|
||||
if (!$written) {
|
||||
throw new RuntimeException('文件写入失败。');
|
||||
}
|
||||
$query = Database::connect()->prepare('INSERT INTO media (name, label, mime, size, created_at) VALUES (?, ?, ?, ?, ?)');
|
||||
$query->execute([$name, $label, $mime, $content === null ? $size : strlen($content), gmdate('c')]);
|
||||
} catch (Throwable $error) {
|
||||
if (is_file($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
public static function find(string $name): ?array
|
||||
{
|
||||
$query = Database::connect()->prepare('SELECT * FROM media WHERE name = ?');
|
||||
$query->execute([$name]);
|
||||
|
||||
return $query->fetch() ?: null;
|
||||
}
|
||||
|
||||
public static function update(string $name, string $label, bool $archived): void
|
||||
{
|
||||
Database::connect()->prepare('UPDATE media SET label = ?, archived = ? WHERE name = ?')
|
||||
->execute([$label, (int) $archived, $name]);
|
||||
}
|
||||
|
||||
public static function directory(): string
|
||||
{
|
||||
return rtrim(getenv('LAYSENSE_MEDIA_DIR') ?: dirname(__DIR__, 2) . '/storage/media', '/');
|
||||
}
|
||||
|
||||
private static function safeSvg(string $source, int $size): string
|
||||
{
|
||||
if ($size > 512 * 1024) {
|
||||
throw new RuntimeException('SVG 图标最大支持 512 KB。');
|
||||
}
|
||||
$svg = new DOMDocument();
|
||||
if (!$svg->loadXML(file_get_contents($source), LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING) || $svg->doctype
|
||||
|| $svg->documentElement?->namespaceURI !== 'http://www.w3.org/2000/svg' || $svg->documentElement->localName !== 'svg') {
|
||||
throw new RuntimeException('SVG 图标格式无效。');
|
||||
}
|
||||
$tags = ['svg', 'g', 'path', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'title', 'desc'];
|
||||
$attributes = ['viewBox', 'width', 'height', 'fill', 'fill-rule', 'fill-opacity', 'stroke', 'stroke-width', 'stroke-linecap',
|
||||
'stroke-linejoin', 'stroke-dasharray', 'stroke-opacity', 'curve', 'clip-rule', 'opacity', 'd', 'x', 'y',
|
||||
'rx', 'ry', 'cx', 'cy', 'r', 'x1', 'x2', 'y1', 'y2', 'points', 'transform'];
|
||||
foreach ((new DOMXPath($svg))->query('//*') as $element) {
|
||||
if (!$element instanceof DOMElement || $element->namespaceURI !== 'http://www.w3.org/2000/svg'
|
||||
|| !in_array($element->localName, $tags, true)) {
|
||||
throw new RuntimeException('SVG 仅支持基础矢量元素。');
|
||||
}
|
||||
foreach ($element->attributes as $attribute) {
|
||||
if ($attribute->namespaceURI !== null || !in_array($attribute->localName, $attributes, true)
|
||||
|| !preg_match('/^[a-z0-9#.,%\s()+-]*$/iD', $attribute->value) || preg_match('/url\s*\(/i', $attribute->value)) {
|
||||
throw new RuntimeException('SVG 包含不支持的属性或外部引用。');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $svg->saveXML($svg->documentElement);
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,22 @@ final class Repository
|
||||
return json_decode((string) $this->pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
public function pages(): array
|
||||
public function pages(bool $publishedOnly = false): array
|
||||
{
|
||||
return $this->pdo->query('SELECT slug, name, title, updated_at FROM pages ORDER BY rowid')->fetchAll();
|
||||
$where = $publishedOnly ? " WHERE status = 'published'" : '';
|
||||
|
||||
return $this->pdo->query('SELECT slug, name, title, updated_at, status FROM pages' . $where . ' ORDER BY rowid')->fetchAll();
|
||||
}
|
||||
|
||||
public function createPage(string $slug, string $name): void
|
||||
{
|
||||
$query = $this->pdo->prepare("INSERT OR IGNORE INTO pages (slug, name, title, description, heading, accent,
|
||||
lead, image, alt, actions, quicklinks, partners, status, updated_at)
|
||||
VALUES (?, ?, ?, '', ?, '', '', '', '', '[]', '[]', '[]', 'draft', ?)");
|
||||
$query->execute([$slug, $name, $name . ' · 来笙', $name, self::now()]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此页面地址已存在。');
|
||||
}
|
||||
}
|
||||
|
||||
public function page(string $slug): ?array
|
||||
@@ -50,11 +63,12 @@ final class Repository
|
||||
|
||||
public function savePage(string $slug, array $data, int $version): void
|
||||
{
|
||||
$query = $this->pdo->prepare('UPDATE pages SET title = ?, description = ?, heading = ?, accent = ?, lead = ?,
|
||||
image = ?, alt = ?, actions = ?, updated_at = ?, version = version + 1 WHERE slug = ? AND version = ?');
|
||||
$query = $this->pdo->prepare('UPDATE pages SET name = ?, title = ?, description = ?, heading = ?, accent = ?, lead = ?,
|
||||
image = ?, alt = ?, actions = ?, quicklinks = ?, status = ?, updated_at = ?, version = version + 1 WHERE slug = ? AND version = ?');
|
||||
$query->execute([
|
||||
$data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
|
||||
$data['image'], $data['alt'], Database::json($data['actions']), self::now(), $slug, $version,
|
||||
$data['name'], $data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
|
||||
$data['image'], $data['alt'], Database::json($data['actions']), Database::json($data['quicklinks']),
|
||||
$data['status'], self::now(), $slug, $version,
|
||||
]);
|
||||
self::checkVersion($query->rowCount());
|
||||
}
|
||||
@@ -62,15 +76,64 @@ final class Repository
|
||||
public function saveSection(string $page, string $key, array $data, int $version): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $data, $version): void {
|
||||
$query = $pdo->prepare('UPDATE sections SET title = ?, lead = ?, body = ?, version = version + 1
|
||||
$query = $pdo->prepare('UPDATE sections SET title = ?, lead = ?, body = ?, style = ?, version = version + 1
|
||||
WHERE page_slug = ? AND key = ? AND version = ?');
|
||||
$query->execute([$data['title'], $data['lead'], $data['body'], $page, $key, $version]);
|
||||
$query->execute([$data['title'], $data['lead'], $data['body'], $data['style'], $page, $key, $version]);
|
||||
self::checkVersion($query->rowCount());
|
||||
$query = $pdo->prepare('UPDATE pages SET updated_at = ? WHERE slug = ?');
|
||||
$query->execute([self::now(), $page]);
|
||||
});
|
||||
}
|
||||
|
||||
public function createSection(string $page, string $key, string $title, string $style, string $body): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body): void {
|
||||
$query = $pdo->prepare('INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, position)
|
||||
SELECT ?, ?, ?, ?, ?, ?, COALESCE(MAX(position), -1) + 1 FROM sections WHERE page_slug = ?');
|
||||
$query->execute([$page, $key, $title, '', $style, $body, $page]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此区块锚点已被使用。');
|
||||
}
|
||||
self::touchPage($pdo, $page);
|
||||
});
|
||||
}
|
||||
|
||||
public function arrangeSection(string $page, string $key, string $operation, int $version): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($page, $key, $operation, $version): void {
|
||||
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::touchPage($pdo, $page);
|
||||
|
||||
return;
|
||||
}
|
||||
$query = $pdo->prepare('SELECT key FROM sections WHERE page_slug = ? ORDER BY position, key');
|
||||
$query->execute([$page]);
|
||||
$keys = $query->fetchAll(PDO::FETCH_COLUMN);
|
||||
$index = array_search($key, $keys, true);
|
||||
if ($index === false) {
|
||||
throw new RuntimeException('找不到该区块。');
|
||||
}
|
||||
$other = $index + ($operation === 'up' ? -1 : 1);
|
||||
if (!isset($keys[$other])) {
|
||||
return;
|
||||
}
|
||||
[$keys[$index], $keys[$other]] = [$keys[$other], $keys[$index]];
|
||||
$query = $pdo->prepare('UPDATE sections SET position = ? WHERE page_slug = ? AND key = ?');
|
||||
foreach ($keys as $position => $section) {
|
||||
$query->execute([$position, $page, $section]);
|
||||
}
|
||||
self::touchPage($pdo, $page);
|
||||
});
|
||||
}
|
||||
|
||||
private static function touchPage(PDO $pdo, string $slug): void
|
||||
{
|
||||
$pdo->prepare('UPDATE pages SET updated_at = ? WHERE slug = ?')->execute([self::now(), $slug]);
|
||||
}
|
||||
|
||||
public function articles(?string $category = null, ?string $tag = null, bool $public = true, int $limit = 30, int $offset = 0): array
|
||||
{
|
||||
$sql = 'SELECT * FROM articles WHERE 1 = 1';
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
|
||||
final class SiteDesign
|
||||
{
|
||||
public const DEFAULT_HEADER = [
|
||||
'logo' => '/assets/wordmark.webp', 'alt' => 'Laysense 来笙',
|
||||
'links' => [['/', '首页'], ['/services', '产品与服务'], ['/articles', '动态'], ['/#about', '关于来笙']],
|
||||
'button' => ['#contact', '联系来笙'],
|
||||
];
|
||||
|
||||
public const DEFAULT_FOOTER = [
|
||||
'logo' => '/assets/wordmark.webp', 'alt' => '来笙 Laysense',
|
||||
'products_title' => '产品与服务',
|
||||
'products' => [['/pagepan', 'PAGEPAN 小飞页'], ['/highspeaker', 'HighSpeaker DNS'], ['/sc', '软著代理服务'], ['/shnu-sc', 'SHNU 学生软著服务']],
|
||||
'company_title' => '公司',
|
||||
'company' => [['/#about', '关于来笙'], ['/articles', '来笙动态'], ['https://git.laysense.com', 'Laysense Git'], ['https://www.layso.de', 'LaySo']],
|
||||
'phones' => [['tel:+16699004532', '+1 (669) 900 4532'], ['tel:+85257012856', '+852 5701 2856']],
|
||||
];
|
||||
|
||||
public static function parseLinks(string $value): array
|
||||
{
|
||||
$links = [];
|
||||
foreach (preg_split('/\R/u', $value, -1, PREG_SPLIT_NO_EMPTY) as $line) {
|
||||
if (trim($line) === '') {
|
||||
continue;
|
||||
}
|
||||
[$label, $url] = array_map('trim', array_pad(explode('|', $line, 2), 2, ''));
|
||||
if ($label === '' || mb_strlen($label) > 70 || strlen($url) > 1000 || !Html::url($url) || count($links) >= 20) {
|
||||
throw new RuntimeException('每行填写「文案 | 链接」,最多 20 条。');
|
||||
}
|
||||
$links[] = [$url, $label];
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public static function linkText(array $links): string
|
||||
{
|
||||
return implode("\n", array_map(static fn (array $link): string => $link[1] . ' | ' . $link[0], $links));
|
||||
}
|
||||
|
||||
public static function saveSettings(string $part, array $data, int $version): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($part, $data, $version): void {
|
||||
$site = json_decode((string) $pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
if (($site['revisions'][$part] ?? 0) !== $version) {
|
||||
throw new RuntimeException('设置已在另一页面更新。请复制本次修改后重新打开。');
|
||||
}
|
||||
$site[$part] = $data;
|
||||
$site['revisions'][$part] = $version + 1;
|
||||
$pdo->prepare('UPDATE site_settings SET payload = ? WHERE id = 1')->execute([Database::json($site)]);
|
||||
});
|
||||
}
|
||||
|
||||
public static function catalog(): array
|
||||
{
|
||||
return Database::connect()->query('SELECT * FROM catalog ORDER BY position, id')->fetchAll();
|
||||
}
|
||||
|
||||
public static function product(int $id): ?array
|
||||
{
|
||||
$query = Database::connect()->prepare('SELECT * FROM catalog WHERE id = ?');
|
||||
$query->execute([$id]);
|
||||
|
||||
return $query->fetch() ?: null;
|
||||
}
|
||||
|
||||
public static function saveProduct(?int $id, array $product, int $version): int
|
||||
{
|
||||
$pdo = Database::connect();
|
||||
$fields = ['name', 'category', 'body', 'image', 'alt', 'url', 'label', 'extra_url', 'extra_label', 'position'];
|
||||
$values = array_map(static fn (string $field) => $product[$field], $fields);
|
||||
if ($id === null) {
|
||||
$pdo->prepare('INSERT INTO catalog (' . implode(', ', $fields) . ') VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
|
||||
->execute($values);
|
||||
|
||||
return (int) $pdo->lastInsertId();
|
||||
}
|
||||
|
||||
$query = $pdo->prepare('UPDATE catalog SET ' . implode(' = ?, ', $fields) . ' = ?, version = version + 1 WHERE id = ? AND version = ?');
|
||||
$query->execute([...$values, $id, $version]);
|
||||
self::checkProduct($query->rowCount());
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function deleteProduct(int $id, int $version): void
|
||||
{
|
||||
$query = Database::connect()->prepare('DELETE FROM catalog WHERE id = ? AND version = ?');
|
||||
$query->execute([$id, $version]);
|
||||
self::checkProduct($query->rowCount());
|
||||
}
|
||||
|
||||
private static function checkProduct(int $count): void
|
||||
{
|
||||
if ($count !== 1) {
|
||||
throw new RuntimeException('此项目已在另一页面更新,请重新打开。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,21 @@ final class View
|
||||
{
|
||||
public static function render(string $template, array $data, int $status = 200, bool $admin = false): Response
|
||||
{
|
||||
$cdn = $admin || !empty($data['previewMode']) ? '' : ($data['site']['cdn']['origin'] ?? '');
|
||||
$data['cdn'] = $cdn;
|
||||
$html = self::fragment($template, $data);
|
||||
$page = self::fragment($admin ? 'admin-layout' : 'layout', $data + ['content' => $html]);
|
||||
$page = Assets::rewrite(self::fragment($admin ? 'admin-layout' : 'layout', $data + ['content' => $html]), $cdn);
|
||||
$assetSources = $cdn === '' ? "'self'" : "'self' " . $cdn;
|
||||
$headers = [
|
||||
'Content-Type' => 'text/html; charset=utf-8',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
'Referrer-Policy' => 'strict-origin-when-cross-origin',
|
||||
'X-Frame-Options' => 'DENY',
|
||||
'X-Frame-Options' => !empty($data['previewMode']) ? 'SAMEORIGIN' : 'DENY',
|
||||
'Content-Security-Policy' => "default-src 'self'; img-src 'self' https:; media-src 'self' https:; "
|
||||
. "style-src 'self'; script-src 'self'; frame-ancestors 'none'; form-action 'self'; base-uri 'none'; object-src 'none'",
|
||||
. "style-src $assetSources; script-src $assetSources; font-src $assetSources; frame-src 'self'; frame-ancestors "
|
||||
. (!empty($data['previewMode']) ? "'self'" : "'none'") . "; form-action 'self'; base-uri 'none'; object-src 'none'",
|
||||
];
|
||||
if ($admin) {
|
||||
if ($admin || !empty($data['previewMode'])) {
|
||||
$headers['Cache-Control'] = 'no-store';
|
||||
$headers['X-Robots-Tag'] = 'noindex, nofollow';
|
||||
} elseif (($data['noindex'] ?? false) || $status >= 400) {
|
||||
|
||||
@@ -8,12 +8,13 @@ use App\Content\Database;
|
||||
use App\Content\Html;
|
||||
use App\Content\Passwords;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
use App\Http\Request;
|
||||
use RuntimeException;
|
||||
use support\Response;
|
||||
|
||||
final class AdminController
|
||||
class AdminController
|
||||
{
|
||||
private ?array $user = null;
|
||||
|
||||
@@ -189,6 +190,8 @@ final class AdminController
|
||||
foreach (['title', 'description', 'heading', 'accent', 'lead', 'image', 'alt'] as $field) {
|
||||
$data[$field] = $this->input($request, $field);
|
||||
}
|
||||
$data['name'] = $request->post('name') === null ? $page['name'] : $this->input($request, 'name');
|
||||
$data['status'] = $request->post('status') === null || $slug === 'home' ? $page['status'] : $this->input($request, 'status');
|
||||
$data['actions'] = [];
|
||||
$validButtons = true;
|
||||
foreach ([1, 2] as $index) {
|
||||
@@ -202,8 +205,10 @@ final class AdminController
|
||||
}
|
||||
$page = array_replace($page, $data, ['version' => $this->version($request)]);
|
||||
try {
|
||||
if ($data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
$data['description'] === '' || mb_strlen($data['description']) > 300 ||
|
||||
$data['quicklinks'] = $request->post('quicklinks') === null ? $page['quicklinks'] : SiteDesign::parseLinks($this->input($request, 'quicklinks'));
|
||||
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|
||||
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
($data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
$data['heading'] === '' || mb_strlen($data['heading'] . $data['accent']) > 110 ||
|
||||
mb_strlen($data['lead']) > 600 || mb_strlen($data['alt']) > 200 ||
|
||||
strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true)) || !$validButtons) {
|
||||
@@ -232,15 +237,18 @@ final class AdminController
|
||||
if (!$section) {
|
||||
return $this->error($request, '找不到此区块。', 404);
|
||||
}
|
||||
$savedStyle = $section['style'];
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
$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'),
|
||||
];
|
||||
$section = array_replace($section, $data, ['version' => $this->version($request)]);
|
||||
try {
|
||||
if ($data['title'] === '' || mb_strlen($data['title']) > 100 || mb_strlen($data['lead']) > 500 || strlen($data['body']) > 300000) {
|
||||
if ($data['title'] === '' || mb_strlen($data['title']) > 100 || mb_strlen($data['lead']) > 500 || strlen($data['body']) > 300000
|
||||
|| !in_array($data['style'], [$savedStyle, 'plain', 'tinted'], true)) {
|
||||
throw new RuntimeException('请填写区块标题,并检查说明及正文长度。');
|
||||
}
|
||||
$data['body'] = Html::sanitize($data['body']);
|
||||
@@ -253,7 +261,7 @@ final class AdminController
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-section', [
|
||||
'title' => '编辑区块', 'section' => $section, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'title' => '编辑区块', 'section' => $section, 'savedStyle' => $savedStyle, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
@@ -274,7 +282,7 @@ final class AdminController
|
||||
], $html);
|
||||
}
|
||||
|
||||
private function guard(Request $request): ?Response
|
||||
protected function guard(Request $request): ?Response
|
||||
{
|
||||
if (!$this->signedIn($request)) {
|
||||
return $request->isAjax()
|
||||
@@ -340,7 +348,7 @@ final class AdminController
|
||||
return is_string($token) && hash_equals($token, $this->input($request, 'csrf'));
|
||||
}
|
||||
|
||||
private function input(Request $request, string $key, bool $trimValue = true): string
|
||||
protected function input(Request $request, string $key, bool $trimValue = true): string
|
||||
{
|
||||
$value = $request->post($key, '');
|
||||
if (!is_string($value) || !mb_check_encoding($value, 'UTF-8')) {
|
||||
@@ -350,7 +358,7 @@ final class AdminController
|
||||
return $trimValue ? trim($value) : $value;
|
||||
}
|
||||
|
||||
private function version(Request $request): int
|
||||
protected function version(Request $request): int
|
||||
{
|
||||
$version = $this->input($request, 'version');
|
||||
|
||||
@@ -372,7 +380,7 @@ final class AdminController
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function validationMessage(RuntimeException $exception): string
|
||||
protected function validationMessage(RuntimeException $exception): string
|
||||
{
|
||||
if ($exception instanceof \PDOException) {
|
||||
error_log($exception->getMessage());
|
||||
@@ -383,12 +391,12 @@ final class AdminController
|
||||
return $exception->getMessage();
|
||||
}
|
||||
|
||||
private function success(Request $request, string $path): Response
|
||||
protected function success(Request $request, string $path): Response
|
||||
{
|
||||
return $request->isAjax() ? $this->json(['redirect' => $path]) : View::redirect($path);
|
||||
}
|
||||
|
||||
private function json(array $payload, int $status = 200): Response
|
||||
protected function json(array $payload, int $status = 200): Response
|
||||
{
|
||||
return new Response($status, [
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
@@ -398,7 +406,7 @@ final class AdminController
|
||||
], Database::json($payload));
|
||||
}
|
||||
|
||||
private function render(Request $request, string $view, array $data, int $status = 200): Response
|
||||
protected function render(Request $request, string $view, array $data, int $status = 200): Response
|
||||
{
|
||||
$token = $this->token($request);
|
||||
if ($request->isAjax() && $status >= 400) {
|
||||
@@ -411,7 +419,7 @@ final class AdminController
|
||||
return View::render($view, $data + ['token' => $token, 'user' => $this->user], $status, true);
|
||||
}
|
||||
|
||||
private function error(Request $request, string $message, int $status): Response
|
||||
protected function error(Request $request, string $message, int $status): Response
|
||||
{
|
||||
return $this->render($request, 'admin-error', ['title' => $message], $status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Media;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
final class MediaController
|
||||
{
|
||||
public function file(Request $request, string $name): Response
|
||||
{
|
||||
$media = Media::find($name);
|
||||
$path = Media::directory() . '/' . $name;
|
||||
if (!$media || !is_file($path)) {
|
||||
return new Response(404);
|
||||
}
|
||||
|
||||
$length = (int) $media['size'];
|
||||
$headers = [
|
||||
'Content-Type' => $media['mime'], 'X-Content-Type-Options' => 'nosniff',
|
||||
'Content-Security-Policy' => "default-src 'none'; sandbox",
|
||||
'Cache-Control' => 'public, max-age=31536000, immutable',
|
||||
'Access-Control-Allow-Origin' => '*', 'Accept-Ranges' => 'bytes',
|
||||
];
|
||||
$range = $request->header('range');
|
||||
if ($range === null) {
|
||||
return (new Response(200, $headers + ['Content-Length' => (string) $length]))->withFile($path);
|
||||
}
|
||||
if (!preg_match('/^bytes=(\d*)-(\d*)$/D', $range, $parts) || $parts[1] === '' && $parts[2] === '') {
|
||||
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
|
||||
}
|
||||
$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]);
|
||||
if ($end < $start) {
|
||||
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
|
||||
}
|
||||
$count = $end - $start + 1;
|
||||
|
||||
return (new Response(206, $headers + ['Content-Length' => (string) $count, 'Content-Range' => "bytes $start-$end/$length"]))
|
||||
->withFile($path, $start, $count);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Content\Html;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -21,9 +22,15 @@ final class SiteController
|
||||
{
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
if (!$page) {
|
||||
if (!$page || $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
|
||||
return $this->missing($request);
|
||||
}
|
||||
return $this->renderPage($repo, $page);
|
||||
}
|
||||
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false): Response
|
||||
{
|
||||
$slug = $page['slug'];
|
||||
$isHome = $slug === 'home';
|
||||
|
||||
return View::render('page', [
|
||||
@@ -35,6 +42,17 @@ final class SiteController
|
||||
'socialImage' => $page['image'],
|
||||
'socialAlt' => $page['alt'],
|
||||
'articles' => $isHome ? $repo->articles(limit: 3) : [],
|
||||
'previewMode' => $preview, 'noindex' => $preview,
|
||||
]);
|
||||
}
|
||||
|
||||
public function services(Request $request): Response
|
||||
{
|
||||
return View::render('services', [
|
||||
'site' => (new Repository())->site(), 'path' => '/services',
|
||||
'title' => '产品与服务 · 来笙 Laysense',
|
||||
'description' => '浏览来笙的建站工具、智能 DNS 和软件著作权服务。',
|
||||
'products' => SiteDesign::catalog(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -118,7 +136,8 @@ final class SiteController
|
||||
{
|
||||
$repo = new Repository();
|
||||
$xml = ['<?xml version="1.0" encoding="UTF-8"?>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'];
|
||||
$pages = $repo->pages();
|
||||
$pages = $repo->pages(publishedOnly: true);
|
||||
$pages[] = ['slug' => 'services', 'updated_at' => null];
|
||||
if ($repo->articles(limit: 1)) {
|
||||
$pages[] = ['slug' => 'articles', 'updated_at' => null];
|
||||
}
|
||||
@@ -144,7 +163,9 @@ final class SiteController
|
||||
$path = $request->path();
|
||||
if ($request->method() === 'GET' && strlen($path) > 1 && str_ends_with($path, '/')) {
|
||||
$normal = rtrim($path, '/');
|
||||
if (preg_match('~^/(?:pagepan|highspeaker|sc|shnu-sc|articles(?:/[a-z0-9-]+){0,2})$~D', $normal)) {
|
||||
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
|
||||
$known = $single && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published' && $normal !== '/home';
|
||||
if ($known || $normal === '/services' || preg_match('~^/articles(?:/[a-z0-9-]+){0,2}$~D', $normal)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Assets;
|
||||
use App\Content\Html;
|
||||
use App\Content\Media;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Http\Request;
|
||||
use RuntimeException;
|
||||
use support\Response;
|
||||
use Webman\Http\UploadFile;
|
||||
|
||||
final class StudioController extends AdminController
|
||||
{
|
||||
private const BLOCKS = [
|
||||
'text' => ['正文', '<p>在这里输入区块内容。</p>'],
|
||||
'image' => ['图文', '<p>介绍图片内容,然后从媒体库插入图片。</p>'],
|
||||
'cta' => ['行动按钮', '<p>说明下一步。</p><p><a class="button button-primary" href="#contact">联系来笙</a></p>'],
|
||||
'faq' => ['常见问题', '<div class="faq"><details><summary>请输入问题</summary><div><p>请输入答案。</p></div></details></div>'],
|
||||
];
|
||||
|
||||
public function newPage(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$data = ['title' => '新建页面', 'name' => '', 'slug' => '', 'error' => ''];
|
||||
if ($request->method() === 'POST') {
|
||||
$data['name'] = $this->input($request, 'name');
|
||||
$data['slug'] = $this->input($request, 'slug');
|
||||
try {
|
||||
if (!$this->slug($data['slug']) || in_array($data['slug'], ['admin', 'assets', 'articles', 'home', 'services', 'news', 'main', 'favicon'], true)
|
||||
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
throw new RuntimeException('请填写页面名称及可用的网址标识。');
|
||||
}
|
||||
(new Repository())->createPage($data['slug'], $data['name']);
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $data['slug']);
|
||||
} catch (RuntimeException $error) {
|
||||
$data['error'] = $this->validationMessage($error);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'studio-new-page', $data, $data['error'] === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
public function previewPage(Request $request, string $slug): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
|
||||
return $page ? (new SiteController())->renderPage($repo, $page, true) : $this->error($request, '找不到此页面。', 404);
|
||||
}
|
||||
|
||||
public function blocks(Request $request, string $slug): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$repo = new Repository();
|
||||
if (!$repo->page($slug)) {
|
||||
return $this->error($request, '找不到此页面。', 404);
|
||||
}
|
||||
$action = $this->input($request, 'operation');
|
||||
$key = $this->input($request, 'key');
|
||||
try {
|
||||
if (!$this->slug($key) || in_array($key, ['preview', 'home', 'contact', 'main-content', 'blog', 'partners', 'supported-projects'], true)) {
|
||||
throw new RuntimeException('区块锚点不可用。');
|
||||
}
|
||||
if ($action === 'create') {
|
||||
$preset = self::BLOCKS[$this->input($request, 'preset')] ?? null;
|
||||
if ($preset === null) {
|
||||
throw new RuntimeException('请选择区块类型。');
|
||||
}
|
||||
$repo->createSection($slug, $key, $preset[0], 'plain', $preset[1]);
|
||||
|
||||
return $this->success($request, "/admin/pages/$slug/$key");
|
||||
}
|
||||
if (!in_array($action, ['up', 'down', 'delete'], true)) {
|
||||
throw new RuntimeException('操作不可用。');
|
||||
}
|
||||
$repo->arrangeSection($slug, $key, $action, $this->version($request));
|
||||
|
||||
return $this->success($request, "/admin/pages/$slug#blocks");
|
||||
} catch (RuntimeException $error) {
|
||||
return $this->error($request, $this->validationMessage($error), 422);
|
||||
}
|
||||
}
|
||||
|
||||
public function settings(Request $request, string $part): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$site = (new Repository())->site();
|
||||
$defaults = match ($part) {
|
||||
'header' => SiteDesign::DEFAULT_HEADER,
|
||||
'footer' => SiteDesign::DEFAULT_FOOTER + array_intersect_key($site, array_flip(['name', 'address', 'email', 'copyright', 'registration', 'terms'])),
|
||||
'cdn' => ['origin' => ''],
|
||||
};
|
||||
$config = ($site[$part] ?? []) + $defaults;
|
||||
$version = $site['revisions'][$part] ?? 0;
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
try {
|
||||
$config = $this->settingsInput($request, $part, $defaults);
|
||||
SiteDesign::saveSettings($part, $config, $this->version($request));
|
||||
|
||||
return $this->success($request, '/admin/settings/' . $part . '?saved=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
$version = $this->version($request);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'studio-settings', [
|
||||
'part' => $part, 'config' => $config, 'revision' => $version, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'title' => ['header' => '页头', 'footer' => '页脚', 'cdn' => '静态资源 CDN'][$part],
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
public function catalog(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
|
||||
return $this->render($request, 'studio-catalog', ['title' => '产品与服务', 'products' => SiteDesign::catalog()]);
|
||||
}
|
||||
|
||||
public function product(Request $request, ?string $id = null): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$fields = ['name', 'category', 'body', 'image', 'alt', 'url', 'label', 'extra_url', 'extra_label', 'position'];
|
||||
$product = $id !== null ? SiteDesign::product((int) $id) : array_fill_keys($fields, '') + ['version' => 0];
|
||||
if (!$product) {
|
||||
return $this->error($request, '找不到此产品或服务。', 404);
|
||||
}
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
try {
|
||||
if ($id !== null && $this->input($request, 'operation') === 'delete') {
|
||||
SiteDesign::deleteProduct((int) $id, $this->version($request));
|
||||
|
||||
return $this->success($request, '/admin/catalog');
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
$product[$field] = $this->input($request, $field);
|
||||
}
|
||||
$product['version'] = $this->version($request);
|
||||
$this->checkProduct($product);
|
||||
$product['body'] = Html::sanitize($product['body']);
|
||||
$savedId = SiteDesign::saveProduct($id === null ? null : (int) $id, $product, $product['version']);
|
||||
|
||||
return $this->success($request, '/admin/catalog/' . $savedId . '?saved=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'studio-product', [
|
||||
'title' => $id === null ? '添加产品或服务' : '编辑产品或服务', 'product' => $product,
|
||||
'id' => $id, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
public function media(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
try {
|
||||
$file = $request->file('file');
|
||||
if (!$file instanceof UploadFile || !$file->isValid()) {
|
||||
throw new RuntimeException('请选择要上传的文件。');
|
||||
}
|
||||
$label = $this->input($request, 'label') ?: mb_substr((string) $file->getUploadName(), 0, 160);
|
||||
if (mb_strlen($label) > 160) {
|
||||
throw new RuntimeException('资源名称最多 160 个字符。');
|
||||
}
|
||||
Media::upload($file, $label);
|
||||
|
||||
return $this->success($request, '/admin/media?uploaded=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'studio-media', [
|
||||
'title' => '媒体库', 'files' => Media::all(true), 'error' => $error, 'saved' => $request->get('uploaded') === '1',
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
public function mediaOptions(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
|
||||
return $this->json(['files' => Media::all()]);
|
||||
}
|
||||
|
||||
public function mediaMeta(Request $request, string $name): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$label = $this->input($request, 'label');
|
||||
if (!Media::find($name)) {
|
||||
return $this->error($request, '找不到此资源。', 404);
|
||||
}
|
||||
if ($label === '' || mb_strlen($label) > 160) {
|
||||
return $this->error($request, '请输入资源名称,最多 160 个字符。', 422);
|
||||
}
|
||||
Media::update($name, $label, $this->input($request, 'archived') === '1');
|
||||
|
||||
return $this->success($request, '/admin/media');
|
||||
}
|
||||
|
||||
private function settingsInput(Request $request, string $part, array $defaults): array
|
||||
{
|
||||
if ($part === 'cdn') {
|
||||
return ['origin' => Assets::cdn($this->input($request, 'origin'))];
|
||||
}
|
||||
$result = [];
|
||||
foreach ($defaults as $key => $default) {
|
||||
$input = $this->input($request, $key);
|
||||
if (is_array($default)) {
|
||||
$result[$key] = SiteDesign::parseLinks($input);
|
||||
if ($key === 'button') {
|
||||
if (count($result[$key]) > 1) {
|
||||
throw new RuntimeException('页头按钮只接受一条链接。');
|
||||
}
|
||||
$result[$key] = $result[$key][0] ?? [];
|
||||
}
|
||||
} else {
|
||||
if (mb_strlen($input) > 1000) {
|
||||
throw new RuntimeException('设置字段过长。');
|
||||
}
|
||||
$result[$key] = $input;
|
||||
}
|
||||
}
|
||||
if ($result['logo'] !== '' && !Html::url($result['logo'], true)) {
|
||||
throw new RuntimeException('请输入有效的标志图片地址。');
|
||||
}
|
||||
if ($part === 'footer' && ($result['name'] === '' || ($result['email'] !== '' && !filter_var($result['email'], FILTER_VALIDATE_EMAIL)))) {
|
||||
throw new RuntimeException('请填写公司名称及有效的联系邮箱。');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function checkProduct(array $item): void
|
||||
{
|
||||
if ($item['name'] === '' || mb_strlen($item['name']) > 100 || $item['category'] === '' || mb_strlen($item['category']) > 70
|
||||
|| strlen($item['body']) > 300000 || strlen($item['image']) > 1000 || mb_strlen($item['alt']) > 200
|
||||
|| ($item['image'] !== '' && !Html::url($item['image'], true)) || !preg_match('/^-?\d{1,6}$/D', $item['position'])) {
|
||||
throw new RuntimeException('请检查名称、分类、简介、封面及排序字段。');
|
||||
}
|
||||
foreach ([['url', 'label'], ['extra_url', 'extra_label']] as [$href, $label]) {
|
||||
if ($href === 'extra_url' && $item[$href] === '' && $item[$label] === '') {
|
||||
continue;
|
||||
}
|
||||
if (strlen($item[$href]) > 1000 || !Html::url($item[$href]) || $item[$label] === '' || mb_strlen($item[$label]) > 70) {
|
||||
throw new RuntimeException('请填写按钮文案和有效链接。');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function slug(string $value): bool
|
||||
{
|
||||
return strlen($value) <= 70 && preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/D', $value) === 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\MiddlewareInterface;
|
||||
|
||||
final class PublicAssets implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$response = $handler($request);
|
||||
$path = $request->path();
|
||||
if (str_starts_with($path, '/assets/')) {
|
||||
$response->withHeader('Access-Control-Allow-Origin', '*');
|
||||
if ($path === '/assets/jquery-4.0.0.min.js') {
|
||||
$response->withHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@ $e = View::escape(...);
|
||||
?>
|
||||
<header class="admin-heading">
|
||||
<div><h1>内容管理</h1><p>管理网站页面、文章、公告和产品动态。</p></div>
|
||||
<a class="button button-primary" href="/admin/articles/new">新建文章</a>
|
||||
<div class="actions"><a class="button button-primary" href="/admin/new-page">新建页面</a>
|
||||
<a class="button button-outline" href="/admin/articles/new">新建文章</a></div>
|
||||
</header>
|
||||
<section class="admin-panel" aria-labelledby="pages-title">
|
||||
<h2 id="pages-title">网站页面</h2>
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($pages as $page): ?>
|
||||
<li>
|
||||
<div><strong><?= $e($page['name']) ?></strong><small><?= $e($page['slug'] === 'home' ? '/' : '/' . $page['slug']) ?></small></div>
|
||||
<div><strong><?= $e($page['name']) ?></strong><small><?= $e($page['slug'] === 'home' ? '/' : '/' . $page['slug']) ?> · <?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></small></div>
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($page['slug']) ?>">编辑页面</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
use App\Content\Html;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
@@ -12,11 +13,20 @@ $e = View::escape(...);
|
||||
<button type="button" data-insert="list">列表</button>
|
||||
<button type="button" data-insert="link">链接</button>
|
||||
</div>
|
||||
<button data-preview-button type="button" aria-controls="editor-preview" aria-expanded="false">预览正文</button>
|
||||
<?php if ($format === 'html'): ?>
|
||||
<button type="button" data-rich-media>插入媒体</button>
|
||||
<button type="button" data-source-toggle aria-pressed="false">HTML 源码</button>
|
||||
<?php else: ?>
|
||||
<button data-preview-button type="button" aria-controls="editor-preview" aria-expanded="false">预览正文</button>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if ($format === 'html'): ?>
|
||||
<div class="rich studio-rich" contenteditable="true" role="textbox" aria-multiline="true" aria-label="可视化正文" data-rich-canvas hidden><?= Html::sanitize($body) ?></div>
|
||||
<p class="field-note" data-rich-status role="status" hidden></p>
|
||||
<?php endif ?>
|
||||
<textarea id="editor-text" name="body" rows="15" spellcheck="false"><?= $e($body) ?></textarea>
|
||||
<?php if ($format === 'html'): ?>
|
||||
<p class="field-note">支持段落、标题、链接、图片、列表、表格和折叠问答。保存时会清理脚本、内联样式等标签或属性。</p>
|
||||
<p class="field-note">可以直接编辑文字,插入链接、图片、音视频。复杂区块可切换到 HTML 源码调整。</p>
|
||||
<?php endif ?>
|
||||
<div class="editor-preview rich prose" id="editor-preview" aria-live="polite" hidden></div>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@ $e = View::escape(...);
|
||||
<link rel="stylesheet" href="/assets/admin.css">
|
||||
<script src="/assets/jquery-4.0.0.min.js" defer></script>
|
||||
<script src="/assets/admin.js" defer></script>
|
||||
<script src="/assets/studio.js" defer></script>
|
||||
</head>
|
||||
<body class="admin-body">
|
||||
<a class="skip-link" href="#admin-content">跳到内容</a>
|
||||
@@ -25,6 +26,9 @@ $e = View::escape(...);
|
||||
<nav aria-label="后台导航">
|
||||
<a href="/admin">页面</a>
|
||||
<a href="/admin/articles">文章</a>
|
||||
<a href="/admin/media">媒体库</a>
|
||||
<a href="/admin/catalog">产品与服务</a>
|
||||
<a href="/admin/settings/header">网站设置</a>
|
||||
<a href="/admin/password">修改密码</a>
|
||||
<a href="/">访问网站</a>
|
||||
<form method="post" action="/admin/logout">
|
||||
@@ -38,5 +42,14 @@ $e = View::escape(...);
|
||||
</div>
|
||||
</header>
|
||||
<main class="admin-wrap admin-main" id="admin-content"><?= $content ?></main>
|
||||
<?php if ($user): ?>
|
||||
<dialog class="media-picker" id="media-picker" aria-labelledby="picker-heading">
|
||||
<header class="admin-heading compact"><h2 id="picker-heading">从媒体库选择</h2><button class="button button-outline" type="button" data-close-picker>关闭</button></header>
|
||||
<label>查找资源<input type="search" data-media-query placeholder="搜索文件名或资源路径"></label>
|
||||
<p data-picker-status role="status"></p>
|
||||
<div class="picker-grid" data-picker-items></div>
|
||||
<a class="back-link" href="/admin/media" target="_blank" rel="noopener">打开媒体库上传</a>
|
||||
</dialog>
|
||||
<?php endif ?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+81
-34
@@ -1,46 +1,93 @@
|
||||
<?php
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$slug = $page['slug'];
|
||||
$path = $slug === 'home' ? '/' : '/' . $slug;
|
||||
$previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
?>
|
||||
<a class="back-link" href="/admin">返回内容管理</a>
|
||||
<a class="back-link" href="/admin">返回页面</a>
|
||||
<header class="admin-heading">
|
||||
<h1><?= $e($title) ?></h1>
|
||||
<a class="button button-outline" href="<?= $e($slug === 'home' ? '/' : '/' . $slug) ?>">查看公开页面</a>
|
||||
<div><h1><?= $e($title) ?></h1><p><?= $e($path) ?> · <?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></p></div>
|
||||
<div class="actions">
|
||||
<?php if ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
|
||||
<a class="button button-outline" href="<?= $e($previewUrl) ?>" target="_blank" rel="noopener">打开预览</a>
|
||||
</div>
|
||||
</header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/pages/<?= $e($slug) ?>">
|
||||
<h2>首屏与 SEO</h2>
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($page['version']) ?>">
|
||||
<label>SEO 标题<input name="title" value="<?= $e($page['title']) ?>" required maxlength="160"></label>
|
||||
<label>SEO 描述<textarea name="description" rows="3" required maxlength="300"><?= $e($page['description']) ?></textarea></label>
|
||||
<div class="form-grid">
|
||||
<div class="studio-layout">
|
||||
<div>
|
||||
<section class="admin-panel studio-preview" data-preview-studio aria-labelledby="studio-preview-title">
|
||||
<div class="admin-heading compact">
|
||||
<h2 id="studio-preview-title">页面预览</h2>
|
||||
<div class="preview-selector" aria-label="预览尺寸">
|
||||
<button type="button" class="button button-outline" data-preview-size="desktop" aria-pressed="true">桌面</button>
|
||||
<button type="button" class="button button-outline" data-preview-size="phone" aria-pressed="false">手机</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="studio-frame-window">
|
||||
<iframe title="当前保存的页面" src="<?= $e($previewUrl) ?>" sandbox="allow-same-origin" loading="lazy"></iframe>
|
||||
</div>
|
||||
<p class="field-note">可在画布内直接编辑标题和简介。其他改动保存后刷新预览。</p>
|
||||
</section>
|
||||
<section class="admin-panel" id="blocks">
|
||||
<h2>内容区块</h2>
|
||||
<ul class="admin-list studio-blocks">
|
||||
<?php foreach ($page['sections'] as $index => $item): ?>
|
||||
<li>
|
||||
<div><strong><?= $e($item['title']) ?></strong><small>#<?= $e($item['key']) ?></small></div>
|
||||
<div class="actions studio-block-actions">
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($slug) ?>/<?= $e($item['key']) ?>">编辑</a>
|
||||
<form method="post" action="/admin/page-blocks/<?= $e($slug) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="key" value="<?= $e($item['key']) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
||||
<button class="button button-outline" name="operation" value="up" type="submit" <?= $index === 0 ? 'disabled' : '' ?>>上移</button>
|
||||
<button class="button button-outline" name="operation" value="down" type="submit" <?= $index === count($page['sections']) - 1 ? 'disabled' : '' ?>>下移</button>
|
||||
<button class="button button-outline" name="operation" value="delete" type="submit" data-confirm="删除这个区块?">删除</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<form class="admin-form studio-block-add" method="post" action="/admin/page-blocks/<?= $e($slug) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="operation" value="create">
|
||||
<div class="form-grid">
|
||||
<label>区块锚点<input name="key" pattern="[a-z0-9]+(-[a-z0-9]+)*" maxlength="70" placeholder="overview" required></label>
|
||||
<label>区块类型<select name="preset"><option value="text">正文</option><option value="image">图文</option><option value="cta">行动按钮</option><option value="faq">常见问题</option></select></label>
|
||||
</div>
|
||||
<div class="form-submit"><button type="submit" class="button button-primary">添加区块</button></div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
<form class="admin-form admin-panel studio-inspector" 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']) ?>">
|
||||
<label>页面名称<input name="name" value="<?= $e($page['name']) ?>" required maxlength="100"></label>
|
||||
<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>
|
||||
<label>首屏标题<input name="heading" value="<?= $e($page['heading']) ?>" required maxlength="110"></label>
|
||||
<label>标题第二行<input name="accent" value="<?= $e($page['accent']) ?>" maxlength="110"></label>
|
||||
</div>
|
||||
<label>首屏简介<textarea name="lead" rows="3" maxlength="600"><?= $e($page['lead']) ?></textarea></label>
|
||||
<div class="form-grid">
|
||||
<label>首屏图片地址<input name="image" value="<?= $e($page['image']) ?>" maxlength="1000"></label>
|
||||
<label>首屏简介<textarea name="lead" rows="2" maxlength="600"><?= $e($page['lead']) ?></textarea></label>
|
||||
<?= View::fragment('studio-asset-field', ['label' => '首屏图片', 'name' => 'image', 'value' => $page['image']]) ?>
|
||||
<label>图片替代文本<input name="alt" value="<?= $e($page['alt']) ?>" maxlength="200"></label>
|
||||
</div>
|
||||
<?php foreach ([1, 2] as $index): ?>
|
||||
<div class="form-grid">
|
||||
<label>按钮 <?= $index ?> 文案<input name="label<?= $index ?>" value="<?= $e($page['actions'][$index - 1][1] ?? '') ?>" maxlength="50"></label>
|
||||
<label>按钮 <?= $index ?> 链接<input name="url<?= $index ?>" value="<?= $e($page['actions'][$index - 1][0] ?? '') ?>" maxlength="1000"></label>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit">保存页面</button></div>
|
||||
</form>
|
||||
<section class="admin-panel">
|
||||
<h2>内容区块</h2>
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($page['sections'] as $item): ?>
|
||||
<li>
|
||||
<div><strong><?= $e($item['title']) ?></strong><small>#<?= $e($item['key']) ?></small></div>
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($slug) ?>/<?= $e($item['key']) ?>">编辑区块</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
<details>
|
||||
<summary>首屏按钮和页面目录</summary>
|
||||
<?php foreach ([1, 2] as $index): ?>
|
||||
<label>按钮 <?= $index ?> 文案<input name="label<?= $index ?>" value="<?= $e($page['actions'][$index - 1][1] ?? '') ?>" maxlength="50"></label>
|
||||
<label>按钮 <?= $index ?> 链接<input name="url<?= $index ?>" value="<?= $e($page['actions'][$index - 1][0] ?? '') ?>" maxlength="1000"></label>
|
||||
<?php endforeach ?>
|
||||
<label>本页目录<textarea name="quicklinks" rows="3" placeholder="概览 | #overview"><?= $e(SiteDesign::linkText($page['quicklinks'])) ?></textarea>
|
||||
<small>每行填写「文案 | 链接」。</small>
|
||||
</label>
|
||||
</details>
|
||||
<?php if ($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 ?>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit">保存页面</button></div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@ $key = $section['key'];
|
||||
<a class="back-link" href="/admin/pages/<?= $e($slug) ?>">返回页面编辑</a>
|
||||
<header class="admin-heading">
|
||||
<div><h1><?= $e($title) ?></h1><p><?= $e($slug) ?> · #<?= $e($key) ?></p></div>
|
||||
<a class="button button-outline" href="<?= $e(($slug === 'home' ? '/' : '/' . $slug) . '#' . $key) ?>">查看公开区块</a>
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($slug) ?>/preview#<?= $e($key) ?>" target="_blank" rel="noopener">预览区块</a>
|
||||
</header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/pages/<?= $e($slug) ?>/<?= $e($key) ?>">
|
||||
@@ -16,6 +16,11 @@ $key = $section['key'];
|
||||
<input type="hidden" name="version" value="<?= $e($section['version']) ?>">
|
||||
<label>区块标题<input name="title" value="<?= $e($section['title']) ?>" required maxlength="100"></label>
|
||||
<label>区块简介<textarea name="lead" rows="2" maxlength="500"><?= $e($section['lead']) ?></textarea></label>
|
||||
<label>区块背景<select name="style">
|
||||
<?php foreach (array_unique([$savedStyle, 'plain', 'tinted']) as $style): ?>
|
||||
<option value="<?= $e($style) ?>" <?= $style === $section['style'] ? 'selected' : '' ?>><?= $e(['plain' => '默认', 'tinted' => '浅色背景'][$style] ?? '保留原布局') ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<?= View::fragment('admin-editor', ['format' => 'html', 'body' => $section['body']]) ?>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit">保存区块</button></div>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<footer class="site-footer" id="contact">
|
||||
<div class="wrap">
|
||||
<div class="footer-grid">
|
||||
<div class="footer-company" itemscope itemtype="https://schema.org/Organization">
|
||||
<?php if ($footer['logo'] !== ''): ?>
|
||||
<a href="/" itemprop="url" aria-label="来笙 Laysense 首页">
|
||||
<img src="<?= $e($footer['logo']) ?>" alt="<?= $e($footer['alt']) ?>" width="130" height="33" itemprop="logo" loading="lazy">
|
||||
</a>
|
||||
<?php endif ?>
|
||||
<p itemprop="name"><?= $e($footer['name']) ?></p>
|
||||
<?php if ($footer['address']): ?><address itemprop="address"><?= $e($footer['address']) ?></address><?php endif ?>
|
||||
<?php if ($footer['email']): ?>
|
||||
<a itemprop="email" href="mailto:<?= $e($footer['email']) ?>"><?= $e($footer['email']) ?></a>
|
||||
<?php endif ?>
|
||||
<div class="payment-methods" aria-label="支持的付款方式">
|
||||
<img src="/assets/original/payment-taobao.png" alt="淘宝" width="26" height="26" loading="lazy">
|
||||
<img src="/assets/original/payment-alipay.png" alt="支付宝" width="26" height="26" loading="lazy">
|
||||
<img src="/assets/original/payment-wechat.png" alt="微信支付" width="26" height="26" loading="lazy">
|
||||
</div>
|
||||
</div>
|
||||
<?php foreach (['products', 'company'] as $group): ?>
|
||||
<?php if (!$footer[$group] && $footer[$group . '_title'] === '') { continue; } ?>
|
||||
<div>
|
||||
<?php if ($footer[$group . '_title'] !== ''): ?><p class="footer-label"><?= $e($footer[$group . '_title']) ?></p><?php endif ?>
|
||||
<?php foreach ($footer[$group] as [$url, $label]): ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a><?php endforeach ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<div class="footer-meta">
|
||||
<?php if ($footer['copyright']): ?><p><?= $e($footer['copyright']) ?> 2024–<?= $e(date('Y')) ?></p><?php endif ?>
|
||||
<?php if ($footer['phones']): ?>
|
||||
<p>全球号码
|
||||
<?php foreach ($footer['phones'] as $index => [$url, $label]): ?>
|
||||
<?= $index ? ' / ' : '' ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
<?php if ($footer['registration']): ?><a href="https://beian.miit.gov.cn/"><?= $e($footer['registration']) ?></a><?php endif ?>
|
||||
<?php if ($footer['terms']): ?><p class="footer-terms"><?= $e($footer['terms']) ?></p><?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
+18
-46
@@ -1,17 +1,21 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
use App\Content\Assets;
|
||||
use App\Content\SiteDesign;
|
||||
|
||||
$e = View::escape(...);
|
||||
$canonical = $path !== null ? View::absolute($path) : null;
|
||||
$imageUrl = !empty($socialImage) ? $socialImage : '/assets/original/home-hero.webp';
|
||||
$imageUrl = Assets::url($imageUrl, $cdn);
|
||||
if (str_starts_with($imageUrl, '/')) {
|
||||
$imageUrl = View::absolute($imageUrl);
|
||||
}
|
||||
$kind = in_array($page['slug'] ?? '', ['sc', 'shnu-sc'], true) ? 'service' : 'software';
|
||||
$siteKind = $kind === 'service' ? 'other' : 'software';
|
||||
$nav = [
|
||||
['/', '首页'], ['/#product', '产品与服务'], ['/articles', '动态'], ['/#about', '关于来笙'],
|
||||
];
|
||||
$header = ($site['header'] ?? []) + SiteDesign::DEFAULT_HEADER;
|
||||
$footer = ($site['footer'] ?? []) + SiteDesign::DEFAULT_FOOTER + $site;
|
||||
$nav = $header['links'];
|
||||
$contact = $header['button'];
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN" data-type="<?= $e($kind) ?>" data-buttons="solid" data-motion="on">
|
||||
@@ -45,12 +49,14 @@ $nav = [
|
||||
<script src="/assets/jquery-4.0.0.min.js" defer></script>
|
||||
<script src="/assets/site.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<body<?= $kind === 'service' ? ' class="copyright-service"' : '' ?>>
|
||||
<a class="skip-link" href="#main-content">跳到内容</a>
|
||||
<header class="masthead">
|
||||
<div class="wrap masthead-inner">
|
||||
<a class="wordmark" href="/" aria-label="来笙 Laysense 首页">
|
||||
<img src="/assets/wordmark.webp" alt="Laysense 来笙" width="130" height="33">
|
||||
<?php if ($header['logo'] !== ''): ?>
|
||||
<img src="<?= $e($header['logo']) ?>" alt="<?= $e($header['alt']) ?>" width="130" height="33">
|
||||
<?php else: ?>来笙 Laysense<?php endif ?>
|
||||
</a>
|
||||
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
|
||||
<span></span><span></span><span class="sr-only">菜单</span>
|
||||
@@ -60,50 +66,16 @@ $nav = [
|
||||
<?php $current = $url === $path || ($url === '/articles' && str_starts_with($path ?? '', '/articles')); ?>
|
||||
<a href="<?= $e($url) ?>" <?= $current ? 'aria-current="page"' : '' ?>><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
<a class="mobile-contact" href="#contact">联系来笙</a>
|
||||
<?php if ($contact): ?>
|
||||
<a class="mobile-contact" href="<?= $e($contact[0]) ?>"><?= $e($contact[1]) ?></a>
|
||||
<?php endif ?>
|
||||
</nav>
|
||||
<a class="button button-outline masthead-action" href="#contact">联系来笙</a>
|
||||
<?php if ($contact): ?>
|
||||
<a class="button button-outline masthead-action" href="<?= $e($contact[0]) ?>"><?= $e($contact[1]) ?></a>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</header>
|
||||
<main id="main-content" tabindex="-1"><?= $content ?></main>
|
||||
<footer class="site-footer" id="contact">
|
||||
<div class="wrap">
|
||||
<div class="footer-grid">
|
||||
<div class="footer-company" itemscope itemtype="https://schema.org/Organization">
|
||||
<a href="/" itemprop="url" aria-label="来笙 Laysense 首页">
|
||||
<img src="/assets/wordmark.webp" alt="来笙 Laysense" width="130" height="33" itemprop="logo" loading="lazy">
|
||||
</a>
|
||||
<p itemprop="name"><?= $e($site['name']) ?></p>
|
||||
<address itemprop="address"><?= $e($site['address']) ?></address>
|
||||
<a itemprop="email" href="mailto:<?= $e($site['email']) ?>"><?= $e($site['email']) ?></a>
|
||||
<div class="payment-methods" aria-label="支持的付款方式">
|
||||
<img src="/assets/original/payment-taobao.png" alt="淘宝" width="26" height="26" loading="lazy">
|
||||
<img src="/assets/original/payment-alipay.png" alt="支付宝" width="26" height="26" loading="lazy">
|
||||
<img src="/assets/original/payment-wechat.png" alt="微信支付" width="26" height="26" loading="lazy">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="footer-label">产品与服务</p>
|
||||
<a href="/pagepan">PAGEPAN 小飞页</a>
|
||||
<a href="/highspeaker">HighSpeaker DNS</a>
|
||||
<a href="/sc">软著代理服务</a>
|
||||
<a href="/shnu-sc">SHNU 学生软著服务</a>
|
||||
</div>
|
||||
<div>
|
||||
<p class="footer-label">公司</p>
|
||||
<a href="/#about">关于来笙</a>
|
||||
<a href="/articles">来笙动态</a>
|
||||
<a href="https://git.laysense.com">Laysense Git</a>
|
||||
<a href="https://www.layso.de">LaySo</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-meta">
|
||||
<p><?= $e($site['copyright']) ?> 2024–<?= $e(date('Y')) ?></p>
|
||||
<p>全球号码 <a href="tel:+16699004532">+1 (669) 900 4532</a> / <a href="tel:+85257012856">+852 5701 2856</a></p>
|
||||
<a href="https://beian.miit.gov.cn/"><?= $e($site['registration']) ?></a>
|
||||
<p class="footer-terms"><?= $e($site['terms']) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<?= View::fragment('footer', ['footer' => $footer]) ?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+6
-6
@@ -7,7 +7,7 @@ $home = $page['slug'] === 'home';
|
||||
$service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
|
||||
?>
|
||||
<section class="hero hero-<?= $e($page['slug']) ?>" id="home" data-enter>
|
||||
<div class="wrap hero-inner">
|
||||
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>">
|
||||
<div class="hero-copy">
|
||||
<?php if (!$home): ?>
|
||||
<nav class="breadcrumbs" aria-label="面包屑" itemscope itemtype="https://schema.org/BreadcrumbList">
|
||||
@@ -22,13 +22,13 @@ $service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
|
||||
</span>
|
||||
</nav>
|
||||
<?php else: ?>
|
||||
<p class="overline hero-label">上海来笙信息科技有限公司</p>
|
||||
<p class="overline hero-label"><?= $e($site['footer']['name'] ?? $site['name']) ?></p>
|
||||
<?php endif ?>
|
||||
<h1><?= $e($page['heading']) ?><?php if ($page['accent'] !== ''): ?><br><span><?= $e($page['accent']) ?></span><?php endif ?></h1>
|
||||
<p class="hero-lead"><?= $e($page['lead']) ?></p>
|
||||
<h1><span class="hero-heading-primary" data-studio-field="heading"><?= $e($page['heading']) ?></span><?php if ($page['accent'] !== ''): ?><br><span><?= $e($page['accent']) ?></span><?php endif ?></h1>
|
||||
<p class="hero-lead" data-studio-field="lead"><?= $e($page['lead']) ?></p>
|
||||
<div class="actions hero-actions">
|
||||
<?php foreach ($page['actions'] as $index => [$url, $label]): ?>
|
||||
<a class="button <?= $index ? 'button-outline' : 'button-primary' ?>" href="<?= $e($url) ?>"><?= $e($label) ?></a>
|
||||
<a class="button <?= $index ? 'button-outline' : 'button-primary' ?>" href="<?= $e($home && $url === '/#product' ? '/services' : $url) ?>"><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -40,7 +40,7 @@ $service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
|
||||
</div>
|
||||
<?php if ($home): ?>
|
||||
<div class="wrap hero-directory">
|
||||
<span class="overline">产品与服务</span>
|
||||
<a class="overline directory-label" href="/services">产品与服务</a>
|
||||
<a href="/pagepan"><span>PAGEPAN</span><small>可视化建站</small></a>
|
||||
<a href="/highspeaker"><span>HighSpeaker DNS</span><small>开源智能解析</small></a>
|
||||
<a href="/sc"><span>软著代理</span><small>登记申请与材料服务</small></a>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<section class="section catalog-hero">
|
||||
<div class="wrap">
|
||||
<nav class="breadcrumbs" aria-label="面包屑"><a href="/">首页</a><span aria-hidden="true">/</span><span aria-current="page">产品与服务</span></nav>
|
||||
<h1>产品与服务</h1>
|
||||
<p>自托管建站、开源智能 DNS 与软件著作权代理服务。</p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section catalog-listing" aria-label="产品与服务目录">
|
||||
<div class="wrap">
|
||||
<?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?>
|
||||
<div class="catalog-grid">
|
||||
<?php foreach ($products as $product): ?>
|
||||
<article class="catalog-card">
|
||||
<?php if ($product['image']): ?>
|
||||
<div class="catalog-image"><img src="<?= $e($product['image']) ?>" alt="<?= $e($product['alt']) ?>" loading="lazy"></div>
|
||||
<?php endif ?>
|
||||
<div class="catalog-content">
|
||||
<p class="overline"><?= $e($product['category']) ?></p>
|
||||
<h2><?= $e($product['name']) ?></h2>
|
||||
<div class="rich"><?= $product['body'] ?></div>
|
||||
<div class="actions">
|
||||
<a class="button button-primary" href="<?= $e($product['url']) ?>"><?= $e($product['label']) ?></a>
|
||||
<?php if ($product['extra_url']): ?><a href="<?= $e($product['extra_url']) ?>"><?= $e($product['extra_label']) ?></a><?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<div class="asset-field">
|
||||
<label><?= $e($label) ?><input name="<?= $e($name) ?>" value="<?= $e($value) ?>" maxlength="1000"></label>
|
||||
<button type="button" class="button button-outline" data-asset-pick="<?= $e($name) ?>" data-asset-type="image/">媒体库</button>
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<header class="admin-heading">
|
||||
<div><h1>产品与服务</h1><p>管理公开目录中的条目、分类和按钮链接。</p></div>
|
||||
<div class="actions"><a class="button button-outline" href="/services">查看目录</a><a class="button button-primary" href="/admin/catalog/new">添加条目</a></div>
|
||||
</header>
|
||||
<section class="admin-panel">
|
||||
<?php if (!$products): ?><p class="empty-state">暂无产品或服务。</p><?php endif ?>
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($products as $item): ?>
|
||||
<li><div><strong><?= $e($item['name']) ?></strong><small><?= $e($item['category']) ?> · <?= $e($item['url']) ?></small></div>
|
||||
<a class="button button-outline" href="/admin/catalog/<?= $e($item['id']) ?>">编辑</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<header class="admin-heading"><div><h1>媒体库</h1><p>统一查找并引用静态文件、图片、图标和音视频。</p></div></header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/media" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<div class="form-grid">
|
||||
<label>文件<input type="file" name="file" accept="image/*,video/*,audio/*,.pdf,.woff,.woff2" required>
|
||||
<small>支持常见图片、SVG 图标、音视频、PDF、WOFF/WOFF2,单文件最大 64 MB。</small>
|
||||
</label>
|
||||
<label>资源名称<input name="label" maxlength="160" placeholder="默认使用文件名"></label>
|
||||
</div>
|
||||
<div class="form-submit"><button type="submit" class="button button-primary">上传文件</button></div>
|
||||
</form>
|
||||
<section class="admin-panel media-library" data-media-library aria-labelledby="library-heading">
|
||||
<h2 id="library-heading">资源列表</h2>
|
||||
<div class="form-grid">
|
||||
<label>搜索<input type="search" data-library-query placeholder="搜索名称或路径"></label>
|
||||
<label>类型<select data-library-type><option value="">全部资源</option><option value="image/">图片与图标</option><option value="video/">视频</option><option value="audio/">音频</option><option value="other">其他文件</option></select></label>
|
||||
</div>
|
||||
<p data-library-count role="status"></p>
|
||||
<div class="media-grid">
|
||||
<?php foreach ($files as $file): ?>
|
||||
<article class="media-card" data-library-card data-mime="<?= $e($file['mime']) ?>" data-search="<?= $e($file['label'] . ' ' . $file['url']) ?>">
|
||||
<?php if (str_starts_with($file['mime'], 'image/')): ?>
|
||||
<img src="<?= $e($file['url']) ?>" alt="" loading="lazy">
|
||||
<?php else: ?>
|
||||
<p class="media-file-type"><?= $e(strtolower(pathinfo($file['url'], PATHINFO_EXTENSION))) ?></p>
|
||||
<?php endif ?>
|
||||
<h3><?= $e($file['label']) ?></h3>
|
||||
<small><?= $e((string) max(1, ceil($file['size'] / 1024))) ?> KB · <?= $file['name'] === '' ? '项目文件' : ($file['archived'] ? '已归档' : '上传文件') ?></small>
|
||||
<div class="actions"><a href="<?= $e($file['url']) ?>" target="_blank" rel="noopener">打开</a><button type="button" class="button button-outline" data-copy-asset="<?= $e($file['url']) ?>">复制路径</button></div>
|
||||
<?php if ($file['name'] !== ''): ?>
|
||||
<details><summary>管理文件</summary>
|
||||
<form class="admin-form" method="post" action="/admin/media/<?= $e($file['name']) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<label>名称<input name="label" value="<?= $e($file['label']) ?>" maxlength="160" required></label>
|
||||
<label class="media-archive"><input type="checkbox" name="archived" value="1" <?= $file['archived'] ? 'checked' : '' ?>>归档</label>
|
||||
<small>归档从选取器隐藏文件,已有链接仍可访问。</small>
|
||||
<button type="submit" class="button button-outline">保存</button>
|
||||
</form>
|
||||
</details>
|
||||
<?php endif ?>
|
||||
</article>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<a class="back-link" href="/admin">返回页面</a>
|
||||
<header class="admin-heading"><h1>新建页面</h1></header>
|
||||
<?= View::fragment('admin-feedback', ['error' => $error, 'saved' => false]) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/new-page">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<label>页面名称<input name="name" maxlength="100" value="<?= $e($name) ?>" required></label>
|
||||
<label>网址标识<input name="slug" maxlength="70" value="<?= $e($slug) ?>" pattern="[a-z0-9]+(-[a-z0-9]+)*" placeholder="my-page" required>
|
||||
<small>创建后为草稿。可在编辑画布中预览,并自行发布。</small>
|
||||
</label>
|
||||
<div class="form-submit"><button type="submit" class="button button-primary">创建草稿</button></div>
|
||||
</form>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<a class="back-link" href="/admin/catalog">返回目录管理</a>
|
||||
<header class="admin-heading"><h1><?= $e($title) ?></h1></header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/catalog/<?= $e($id ?? 'new') ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($product['version']) ?>">
|
||||
<div class="form-grid">
|
||||
<label>名称<input name="name" value="<?= $e($product['name']) ?>" required maxlength="100"></label>
|
||||
<label>分类<input name="category" value="<?= $e($product['category']) ?>" required maxlength="70"></label>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<?= View::fragment('studio-asset-field', ['label' => '封面', 'name' => 'image', 'value' => $product['image']]) ?>
|
||||
<label>封面替代文本<input name="alt" value="<?= $e($product['alt']) ?>" maxlength="200"></label>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label>按钮文案<input name="label" value="<?= $e($product['label']) ?>" required maxlength="70"></label>
|
||||
<label>按钮链接<input name="url" value="<?= $e($product['url']) ?>" required maxlength="1000"></label>
|
||||
<label>次要链接文案<input name="extra_label" value="<?= $e($product['extra_label']) ?>" maxlength="70"></label>
|
||||
<label>次要链接<input name="extra_url" value="<?= $e($product['extra_url']) ?>" maxlength="1000"></label>
|
||||
</div>
|
||||
<label>排序<input type="number" name="position" min="-999999" max="999999" value="<?= $e($product['position'] === '' ? 100 : $product['position']) ?>" required><small>数值越小越靠前。</small></label>
|
||||
<?= View::fragment('admin-editor', ['format' => 'html', 'body' => $product['body']]) ?>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit">保存条目</button></div>
|
||||
</form>
|
||||
<?php if ($id !== null): ?>
|
||||
<form class="admin-form" method="post" action="/admin/catalog/<?= $e($id) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($product['version']) ?>">
|
||||
<div class="form-submit"><button class="button button-outline" type="submit" name="operation" value="delete" data-confirm="从公开目录删除此条目?">删除条目</button></div>
|
||||
</form>
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<header class="admin-heading"><h1><?= $e($title) ?></h1><a class="button button-outline" href="/" target="_blank" rel="noopener">查看公开网站</a></header>
|
||||
<nav class="filter-nav" aria-label="网站设置">
|
||||
<?php foreach (['header' => '页头', 'footer' => '页脚', 'cdn' => 'CDN'] as $key => $text): ?>
|
||||
<a href="/admin/settings/<?= $key ?>" <?= $key === $part ? 'aria-current="page"' : '' ?>><?= $text ?></a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel settings-form" method="post" action="/admin/settings/<?= $e($part) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($revision) ?>">
|
||||
<?php if ($part === 'cdn'): ?>
|
||||
<label>CDN 源站地址<input name="origin" type="url" value="<?= $e($config['origin']) ?>" placeholder="https://cdn.laysense.cn">
|
||||
<small>留空时直接从站点提供资源。配置后,公开页面中的 /assets/ 路径会改用此域名。</small>
|
||||
</label>
|
||||
<?php else: ?>
|
||||
<?= View::fragment('studio-asset-field', ['label' => '站点标志', 'name' => 'logo', 'value' => $config['logo']]) ?>
|
||||
<label>标志替代文本<input name="alt" value="<?= $e($config['alt']) ?>" maxlength="200"></label>
|
||||
<?php if ($part === 'header'): ?>
|
||||
<label>主导航<textarea name="links" rows="6" placeholder="产品与服务 | /services"><?= $e(SiteDesign::linkText($config['links'])) ?></textarea>
|
||||
<small>每行填写「文案 | 链接」,按输入顺序展示。</small>
|
||||
</label>
|
||||
<label>右侧按钮<input name="button" value="<?= $e($config['button'] ? SiteDesign::linkText([$config['button']]) : '') ?>" placeholder="联系来笙 | #contact"></label>
|
||||
<?php else: ?>
|
||||
<div class="form-grid">
|
||||
<?php foreach (['name' => '公司名称', 'address' => '联系地址', 'email' => '邮箱', 'registration' => '备案号', 'copyright' => '版权信息'] as $key => $text): ?>
|
||||
<label><?= $text ?><input name="<?= $key ?>" value="<?= $e($config[$key] ?? '') ?>" <?= $key === 'name' ? 'required' : '' ?>></label>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<label>联系号码<textarea name="phones" rows="3"><?= $e(SiteDesign::linkText($config['phones'])) ?></textarea>
|
||||
<small>每行填写「显示号码 | tel:号码」。</small>
|
||||
</label>
|
||||
<div class="form-grid">
|
||||
<?php foreach (['products' => '第一列', 'company' => '第二列'] as $key => $text): ?>
|
||||
<div class="admin-form">
|
||||
<label><?= $text ?>标题<input name="<?= $key ?>_title" value="<?= $e($config[$key . '_title']) ?>"></label>
|
||||
<label><?= $text ?>链接<textarea name="<?= $key ?>" rows="6"><?= $e(SiteDesign::linkText($config[$key])) ?></textarea>
|
||||
<small>每行填写「文案 | 链接」。</small>
|
||||
</label>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<label>页脚备注<textarea name="terms" rows="2"><?= $e($config['terms'] ?? '') ?></textarea></label>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
<div class="form-submit"><button class="button button-primary" type="submit">保存设置</button></div>
|
||||
</form>
|
||||
Reference in New Issue
Block a user