forked from laysense/laysense.cn
Rebuild Laysense site with Webman and SQLite CMS
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
final class Database
|
||||
{
|
||||
private static ?PDO $connection = null;
|
||||
|
||||
public static function connect(): PDO
|
||||
{
|
||||
if (self::$connection !== null) {
|
||||
return self::$connection;
|
||||
}
|
||||
|
||||
$path = getenv('LAYSENSE_DB') ?: dirname(__DIR__, 2) . '/storage/laysense.sqlite';
|
||||
if (!is_dir(dirname($path)) && !mkdir(dirname($path), 0750, true) && !is_dir(dirname($path))) {
|
||||
throw new RuntimeException('无法创建 SQLite 存放目录。');
|
||||
}
|
||||
|
||||
$pdo = new PDO('sqlite:' . $path, options: [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);
|
||||
$pdo->exec('PRAGMA busy_timeout = 5000');
|
||||
$pdo->exec('PRAGMA foreign_keys = ON');
|
||||
self::$connection = $pdo;
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
public static function initialize(): void
|
||||
{
|
||||
$root = dirname(__DIR__, 2);
|
||||
$seed = json_decode(file_get_contents($root . '/resources/seed.json'), true, flags: JSON_THROW_ON_ERROR);
|
||||
$pdo = self::connect();
|
||||
$pdo->exec('PRAGMA journal_mode = WAL');
|
||||
|
||||
self::write(function (PDO $pdo) use ($root, $seed): void {
|
||||
$pdo->exec(file_get_contents($root . '/resources/schema.sql'));
|
||||
$site = $pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)');
|
||||
$site->execute([self::json($seed['site'])]);
|
||||
|
||||
$pageQuery = $pdo->prepare('INSERT OR IGNORE INTO pages
|
||||
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks, partners)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
$sectionQuery = $pdo->prepare('INSERT OR IGNORE INTO sections
|
||||
(page_slug, key, title, lead, style, body, position) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
||||
foreach ($seed['pages'] as $page) {
|
||||
$pageQuery->execute([
|
||||
$page['slug'], $page['name'], $page['title'], $page['description'], $page['heading'],
|
||||
$page['accent'], $page['lead'], $page['image'], $page['alt'],
|
||||
self::json($page['actions']), self::json($page['quicklinks']), self::json($page['partners'] ?? []),
|
||||
]);
|
||||
if ($pageQuery->rowCount() !== 1) {
|
||||
continue;
|
||||
}
|
||||
foreach ($page['sections'] as $index => $section) {
|
||||
$sectionQuery->execute([
|
||||
$page['slug'], $section['key'], $section['title'], $section['lead'],
|
||||
$section['style'], Html::sanitize($section['body']), $index,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$article = $pdo->prepare('INSERT OR IGNORE INTO articles
|
||||
(slug, title, category, summary, body, tags, status, published_at, updated_at, legacy_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
foreach ($seed['articles'] as $item) {
|
||||
$exists = $pdo->prepare('SELECT 1 FROM article_redirects WHERE slug = ?');
|
||||
$exists->execute([$item['slug']]);
|
||||
if ($exists->fetchColumn()) {
|
||||
continue;
|
||||
}
|
||||
$article->execute([
|
||||
$item['slug'], $item['title'], $item['category'], $item['summary'], $item['body'],
|
||||
self::json($item['tags']), $item['status'], $item['date'], $item['date'], $item['legacy'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function write(callable $operation): mixed
|
||||
{
|
||||
$pdo = self::connect();
|
||||
$pdo->exec('BEGIN IMMEDIATE');
|
||||
try {
|
||||
$result = $operation($pdo);
|
||||
$pdo->exec('COMMIT');
|
||||
|
||||
return $result;
|
||||
} catch (Throwable $error) {
|
||||
$pdo->exec('ROLLBACK');
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
public static function json(array $data): string
|
||||
{
|
||||
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMNode;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
|
||||
final class Html
|
||||
{
|
||||
private const TAGS = [
|
||||
'a' => ['href'], 'article' => [], 'b' => [], 'blockquote' => [], 'br' => [],
|
||||
'caption' => [], 'code' => [], 'dd' => [], 'details' => [], 'div' => ['role', 'aria-label', 'tabindex'],
|
||||
'dl' => [], 'dt' => [], 'em' => [], 'h3' => [], 'h4' => [], 'h5' => [], 'hr' => [], 'i' => [],
|
||||
'img' => ['src', 'alt', 'loading', 'width', 'height'], 'label' => ['for'],
|
||||
'li' => [], 'ol' => [], 'p' => [], 'pre' => [], 'progress' => ['max', 'value'], 's' => [],
|
||||
'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'],
|
||||
];
|
||||
|
||||
public static function url(string $value, bool $media = false): bool
|
||||
{
|
||||
if ($value === '' || preg_match('/[\x00-\x20\x7f\\\\]/', $value)) {
|
||||
return false;
|
||||
}
|
||||
if (str_starts_with($value, '/')) {
|
||||
return !str_starts_with($value, '//');
|
||||
}
|
||||
if (str_starts_with($value, '#')) {
|
||||
return !$media && strlen($value) > 1;
|
||||
}
|
||||
$scheme = strtolower((string) parse_url($value, PHP_URL_SCHEME));
|
||||
|
||||
return in_array($scheme, $media ? ['https'] : ['https', 'http', 'mailto', 'tel'], true);
|
||||
}
|
||||
|
||||
public static function markdown(string $text): string
|
||||
{
|
||||
static $converter;
|
||||
$converter ??= new CommonMarkConverter(['html_input' => 'strip', 'allow_unsafe_links' => false, 'max_nesting_level' => 30]);
|
||||
|
||||
$html = $converter->convert($text)->getContent();
|
||||
|
||||
return str_replace(['<h1>', '</h1>'], ['<h2>', '</h2>'], $html);
|
||||
}
|
||||
|
||||
public static function sanitize(string $html): string
|
||||
{
|
||||
$document = new DOMDocument('1.0', 'UTF-8');
|
||||
$document->loadHTML('<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body>' . $html . '</body></html>', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
|
||||
$body = $document->getElementsByTagName('body')->item(0);
|
||||
if (!$body) {
|
||||
return '';
|
||||
}
|
||||
self::sanitizeChildren($body);
|
||||
$output = '';
|
||||
foreach ($body->childNodes as $child) {
|
||||
$output .= $document->saveHTML($child);
|
||||
}
|
||||
|
||||
return trim($output);
|
||||
}
|
||||
|
||||
private static function sanitizeChildren(DOMNode $parent): void
|
||||
{
|
||||
foreach (iterator_to_array($parent->childNodes) as $element) {
|
||||
if ($element->nodeType === XML_COMMENT_NODE) {
|
||||
$parent->removeChild($element);
|
||||
continue;
|
||||
}
|
||||
if (!$element instanceof DOMElement) {
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists($element->tagName, self::TAGS)) {
|
||||
$parent->removeChild($element);
|
||||
continue;
|
||||
}
|
||||
$allowed = [...self::TAGS[$element->tagName], 'class', 'id'];
|
||||
foreach (iterator_to_array($element->attributes) as $attribute) {
|
||||
$name = $attribute->name;
|
||||
$value = $attribute->value;
|
||||
if (!in_array($name, $allowed, true)
|
||||
|| ($name === 'href' && !self::url($value))
|
||||
|| (in_array($name, ['src', 'poster'], true) && !self::url($value, true))
|
||||
|| ($name === 'tabindex' && $value !== '0')) {
|
||||
$element->removeAttribute($name);
|
||||
}
|
||||
}
|
||||
self::sanitizeChildren($element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
|
||||
final class Repository
|
||||
{
|
||||
public const CATEGORIES = ['announcement' => '公告', 'news' => '新闻', 'product' => '产品'];
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdo = Database::connect();
|
||||
}
|
||||
|
||||
public function site(): array
|
||||
{
|
||||
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
|
||||
{
|
||||
return $this->pdo->query('SELECT slug, name, title, updated_at FROM pages ORDER BY rowid')->fetchAll();
|
||||
}
|
||||
|
||||
public function page(string $slug): ?array
|
||||
{
|
||||
$page = $this->one('SELECT * FROM pages WHERE slug = ?', [$slug]);
|
||||
if (!$page) {
|
||||
return null;
|
||||
}
|
||||
foreach (['actions', 'quicklinks', 'partners'] as $key) {
|
||||
$page[$key] = json_decode($page[$key], true, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$query = $this->pdo->prepare('SELECT * FROM sections WHERE page_slug = ? ORDER BY position, key');
|
||||
$query->execute([$slug]);
|
||||
$page['sections'] = $query->fetchAll();
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function section(string $page, string $key): ?array
|
||||
{
|
||||
return $this->one('SELECT * FROM sections WHERE page_slug = ? AND key = ?', [$page, $key]);
|
||||
}
|
||||
|
||||
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->execute([
|
||||
$data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
|
||||
$data['image'], $data['alt'], Database::json($data['actions']), self::now(), $slug, $version,
|
||||
]);
|
||||
self::checkVersion($query->rowCount());
|
||||
}
|
||||
|
||||
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
|
||||
WHERE page_slug = ? AND key = ? AND version = ?');
|
||||
$query->execute([$data['title'], $data['lead'], $data['body'], $page, $key, $version]);
|
||||
self::checkVersion($query->rowCount());
|
||||
$query = $pdo->prepare('UPDATE pages SET updated_at = ? WHERE slug = ?');
|
||||
$query->execute([self::now(), $page]);
|
||||
});
|
||||
}
|
||||
|
||||
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';
|
||||
$args = [];
|
||||
if ($public) {
|
||||
$sql .= " AND status = 'published' AND published_at IS NOT NULL";
|
||||
}
|
||||
if ($category !== null) {
|
||||
$sql .= ' AND category = ?';
|
||||
$args[] = $category;
|
||||
}
|
||||
if ($tag !== null) {
|
||||
$sql .= ' AND EXISTS (SELECT 1 FROM json_each(articles.tags) WHERE value = ?)';
|
||||
$args[] = $tag;
|
||||
}
|
||||
$order = $public ? 'published_at' : 'updated_at';
|
||||
$query = $this->pdo->prepare($sql . ' ORDER BY ' . $order . ' DESC, id DESC LIMIT ? OFFSET ?');
|
||||
$query->execute([...$args, $limit, $offset]);
|
||||
|
||||
return array_map(self::decodeArticle(...), $query->fetchAll());
|
||||
}
|
||||
|
||||
public function articleById(int $id): ?array
|
||||
{
|
||||
return self::decodeArticle($this->one('SELECT * FROM articles WHERE id = ?', [$id]));
|
||||
}
|
||||
|
||||
public function published(string $slug): ?array
|
||||
{
|
||||
return self::decodeArticle($this->one("SELECT * FROM articles WHERE slug = ? AND status = 'published'", [$slug]));
|
||||
}
|
||||
|
||||
public function articleRedirect(string $slug): ?array
|
||||
{
|
||||
return $this->one("SELECT articles.slug FROM article_redirects
|
||||
JOIN articles ON articles.id = article_redirects.article_id
|
||||
WHERE article_redirects.slug = ? AND articles.status = 'published'", [$slug]);
|
||||
}
|
||||
|
||||
public function legacyArticle(string $path): ?array
|
||||
{
|
||||
return $this->one("SELECT slug FROM articles WHERE legacy_path = ? AND status = 'published'", [$path]);
|
||||
}
|
||||
|
||||
public function saveArticle(?int $id, array $data, int $version): int
|
||||
{
|
||||
return Database::write(function (PDO $pdo) use ($id, $data, $version): int {
|
||||
$old = $id !== null ? $this->articleById($id) : null;
|
||||
if ($id !== null && (!$old || $old['version'] !== $version)) {
|
||||
self::checkVersion(0);
|
||||
}
|
||||
$existing = $this->one('SELECT id FROM articles WHERE slug = ?', [$data['slug']]);
|
||||
$redirect = $this->one('SELECT article_id FROM article_redirects WHERE slug = ?', [$data['slug']]);
|
||||
if (($existing && $existing['id'] !== $id) || ($redirect && $redirect['article_id'] !== $id)) {
|
||||
throw new RuntimeException('此网址标识已被使用。');
|
||||
}
|
||||
$publishedAt = $old['published_at'] ?? ($data['status'] === 'published' ? self::now() : null);
|
||||
$values = [
|
||||
$data['slug'], $data['title'], $data['category'], $data['summary'], $data['body'],
|
||||
Database::json($data['tags']), $data['status'], $publishedAt, self::now(),
|
||||
];
|
||||
if ($id === null) {
|
||||
$query = $pdo->prepare('INSERT INTO articles
|
||||
(slug, title, category, summary, body, tags, status, published_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
$query->execute($values);
|
||||
|
||||
return (int) $pdo->lastInsertId();
|
||||
}
|
||||
if ($old['slug'] !== $data['slug']) {
|
||||
$pdo->prepare('DELETE FROM article_redirects WHERE slug = ? AND article_id = ?')->execute([$data['slug'], $id]);
|
||||
$pdo->prepare('INSERT INTO article_redirects (slug, article_id) VALUES (?, ?)')->execute([$old['slug'], $id]);
|
||||
}
|
||||
$query = $pdo->prepare('UPDATE articles SET slug = ?, title = ?, category = ?, summary = ?, body = ?, tags = ?,
|
||||
status = ?, published_at = ?, updated_at = ?, version = version + 1 WHERE id = ? AND version = ?');
|
||||
$query->execute([...$values, $id, $version]);
|
||||
self::checkVersion($query->rowCount());
|
||||
|
||||
return $id;
|
||||
});
|
||||
}
|
||||
|
||||
public function sitemapArticles(): iterable
|
||||
{
|
||||
$query = $this->pdo->query("SELECT slug, updated_at FROM articles WHERE status = 'published' AND trim(body) <> '' ORDER BY slug");
|
||||
yield from $query;
|
||||
}
|
||||
|
||||
public function administrator(string $email): ?array
|
||||
{
|
||||
return $this->one('SELECT id, email, password_hash FROM users WHERE email = ?', [$email]);
|
||||
}
|
||||
|
||||
public function administratorById(int $id): ?array
|
||||
{
|
||||
return $this->one('SELECT id, email, password_hash FROM users WHERE id = ?', [$id]);
|
||||
}
|
||||
|
||||
public function recordLoginAttempt(string $address): bool
|
||||
{
|
||||
return Database::write(function (PDO $pdo) use ($address): bool {
|
||||
$now = time();
|
||||
$pdo->prepare('DELETE FROM login_attempts WHERE expires_at <= ?')->execute([$now]);
|
||||
$current = $this->one('SELECT attempts FROM login_attempts WHERE address = ?', [$address]);
|
||||
if ($current && $current['attempts'] >= 12) {
|
||||
return false;
|
||||
}
|
||||
$query = $pdo->prepare('INSERT INTO login_attempts (address, attempts, expires_at) VALUES (?, 1, ?)
|
||||
ON CONFLICT (address) DO UPDATE SET attempts = attempts + 1');
|
||||
$query->execute([$address, $now + 900]);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public function clearLoginAttempts(string $address): void
|
||||
{
|
||||
$this->pdo->prepare('DELETE FROM login_attempts WHERE address = ?')->execute([$address]);
|
||||
}
|
||||
|
||||
private function one(string $sql, array $args): ?array
|
||||
{
|
||||
$query = $this->pdo->prepare($sql);
|
||||
$query->execute($args);
|
||||
|
||||
return $query->fetch() ?: null;
|
||||
}
|
||||
|
||||
private static function decodeArticle(?array $article): ?array
|
||||
{
|
||||
if ($article !== null) {
|
||||
$article['tags'] = json_decode($article['tags'], true, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
private static function now(): string
|
||||
{
|
||||
return date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
private static function checkVersion(int $count): void
|
||||
{
|
||||
if ($count !== 1) {
|
||||
throw new RuntimeException('此内容已在其他窗口更新。请保留你的修改,重新打开后再合并。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use support\Response;
|
||||
|
||||
final class View
|
||||
{
|
||||
public static function render(string $template, array $data, int $status = 200, bool $admin = false): Response
|
||||
{
|
||||
$html = self::fragment($template, $data);
|
||||
$page = self::fragment($admin ? 'admin-layout' : 'layout', $data + ['content' => $html]);
|
||||
$headers = [
|
||||
'Content-Type' => 'text/html; charset=utf-8',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
'Referrer-Policy' => 'strict-origin-when-cross-origin',
|
||||
'X-Frame-Options' => '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'",
|
||||
];
|
||||
if ($admin) {
|
||||
$headers['Cache-Control'] = 'no-store';
|
||||
$headers['X-Robots-Tag'] = 'noindex, nofollow';
|
||||
} elseif (($data['noindex'] ?? false) || $status >= 400) {
|
||||
$headers['X-Robots-Tag'] = 'noindex';
|
||||
}
|
||||
|
||||
return new Response($status, $headers, $page);
|
||||
}
|
||||
|
||||
public static function fragment(string $template, array $data = []): string
|
||||
{
|
||||
extract($data, EXTR_SKIP);
|
||||
ob_start();
|
||||
try {
|
||||
require dirname(__DIR__) . '/view/' . $template . '.php';
|
||||
|
||||
return (string) ob_get_contents();
|
||||
} finally {
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
|
||||
public static function escape(string|int|null $value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
|
||||
public static function absolute(string $path): string
|
||||
{
|
||||
return rtrim(getenv('LAYSENSE_SITE_URL') ?: 'https://laysense.cn', '/') . $path;
|
||||
}
|
||||
|
||||
public static function date(?string $value, string $format = 'Y年n月j日'): string
|
||||
{
|
||||
return $value ? date($format, strtotime($value)) : '';
|
||||
}
|
||||
|
||||
public static function redirect(string $path, int $status = 303): Response
|
||||
{
|
||||
return new Response($status, ['Location' => $path, 'Cache-Control' => $status === 301 ? 'public, max-age=300' : 'no-store'], '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Html;
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
use RuntimeException;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
final class AdminController
|
||||
{
|
||||
private ?array $user = null;
|
||||
|
||||
public function login(Request $request): Response
|
||||
{
|
||||
if ($this->signedIn($request)) {
|
||||
return View::redirect('/admin');
|
||||
}
|
||||
$error = '';
|
||||
$email = '';
|
||||
$status = 200;
|
||||
if ($request->method() === 'POST') {
|
||||
if (!$this->validToken($request)) {
|
||||
return $this->error($request, '表单已过期,请刷新后重试。', 403);
|
||||
}
|
||||
$email = strtolower($this->input($request, 'email'));
|
||||
$password = $this->input($request, 'password', trimValue: false);
|
||||
$repo = new Repository();
|
||||
$address = $this->address($request);
|
||||
if (!$repo->recordLoginAttempt($address)) {
|
||||
$error = '尝试次数过多,请在 15 分钟后重试。';
|
||||
$status = 429;
|
||||
} else {
|
||||
$user = strlen($email) <= 254 ? $repo->administrator($email) : null;
|
||||
$hash = $user['password_hash'] ?? '$2y$12$XGNKW.dBbfpUrZT8MYvWquCW1dBN3fIlVb29tlaoFIge3YDWG0AzG';
|
||||
if (strlen($password) <= 72 && password_verify($password, $hash) && $user) {
|
||||
$request->sessionRegenerateId(true);
|
||||
$request->session()->flush();
|
||||
$request->session()->set('admin_id', $user['id']);
|
||||
$request->session()->set('auth_version', hash('sha256', $user['password_hash']));
|
||||
$request->session()->set('admin_since', time());
|
||||
$repo->clearLoginAttempts($address);
|
||||
|
||||
return View::redirect('/admin');
|
||||
}
|
||||
$error = '邮箱或密码有误。';
|
||||
$status = 422;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-login', ['title' => '登录内容管理', 'error' => $error, 'email' => $email], $status);
|
||||
}
|
||||
|
||||
public function logout(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$request->session()->flush();
|
||||
$request->sessionRegenerateId(true);
|
||||
|
||||
return View::redirect('/admin/login');
|
||||
}
|
||||
|
||||
public function dashboard(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$repo = new Repository();
|
||||
|
||||
return $this->render($request, 'admin-dashboard', [
|
||||
'title' => '内容管理', 'pages' => $repo->pages(), 'articles' => $repo->articles(public: false, limit: 5),
|
||||
]);
|
||||
}
|
||||
|
||||
public function articles(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$page = max(1, min(10000, (int) $request->get('page', 1)));
|
||||
$articles = (new Repository())->articles(public: false, limit: 31, offset: ($page - 1) * 30);
|
||||
|
||||
return $this->render($request, 'admin-articles', [
|
||||
'title' => '文章与动态', 'articles' => array_slice($articles, 0, 30), 'pageNumber' => $page, 'hasNext' => count($articles) > 30,
|
||||
]);
|
||||
}
|
||||
|
||||
public function article(Request $request, ?string $id = null): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$repo = new Repository();
|
||||
$article = $id !== null ? $repo->articleById((int) $id) : [
|
||||
'title' => '', 'slug' => '', 'summary' => '', 'category' => 'news', 'body' => '',
|
||||
'tags' => [], 'status' => 'draft', 'version' => 0,
|
||||
];
|
||||
if (!$article) {
|
||||
return $this->error($request, '找不到这篇文章。', 404);
|
||||
}
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
$data = $this->articleInput($request);
|
||||
$article = array_replace($article, $data, ['version' => $this->version($request)]);
|
||||
try {
|
||||
if (mb_strlen($data['title']) < 1 || mb_strlen($data['title']) > 120
|
||||
|| !preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/D', $data['slug']) || strlen($data['slug']) > 100
|
||||
|| mb_strlen($data['summary']) > 250 || strlen($data['body']) > 200000
|
||||
|| !isset(Repository::CATEGORIES[$data['category']])
|
||||
|| !in_array($data['status'], ['draft', 'published'], true)) {
|
||||
throw new RuntimeException('请检查标题、网址标识、分类、摘要和正文长度。');
|
||||
}
|
||||
if ($data['status'] === 'published' && trim(Html::markdown($data['body'])) === '') {
|
||||
throw new RuntimeException('发布前请填写文章正文。');
|
||||
}
|
||||
$saved = $repo->saveArticle($id === null ? null : (int) $id, $data, $this->version($request));
|
||||
|
||||
return View::redirect('/admin/articles/' . $saved . '?saved=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-article', [
|
||||
'title' => $id === null ? '新建文章' : '编辑文章', 'article' => $article, 'error' => $error,
|
||||
'articleId' => $id, 'saved' => $request->get('saved') === '1',
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
public function page(Request $request, string $slug): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
if (!$page) {
|
||||
return $this->error($request, '找不到此页面。', 404);
|
||||
}
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
$data = [];
|
||||
foreach (['title', 'description', 'heading', 'accent', 'lead', 'image', 'alt'] as $field) {
|
||||
$data[$field] = $this->input($request, $field);
|
||||
}
|
||||
$data['actions'] = [];
|
||||
$validButtons = true;
|
||||
foreach ([1, 2] as $index) {
|
||||
$label = $this->input($request, 'label' . $index);
|
||||
$url = $this->input($request, 'url' . $index);
|
||||
if ($label === '' && $url === '') {
|
||||
continue;
|
||||
}
|
||||
$data['actions'][] = [$url, $label];
|
||||
$validButtons = $validButtons && mb_strlen($label) <= 50 && $label !== '' && strlen($url) <= 1000 && Html::url($url);
|
||||
}
|
||||
$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['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) {
|
||||
throw new RuntimeException('请检查页面标题、说明、图片地址和按钮链接。');
|
||||
}
|
||||
$repo->savePage($slug, $data, $this->version($request));
|
||||
|
||||
return View::redirect('/admin/pages/' . $slug . '?saved=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-page', [
|
||||
'title' => '编辑 ' . $page['name'], 'page' => $page, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
public function section(Request $request, string $slug, string $key): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$repo = new Repository();
|
||||
$section = $repo->section($slug, $key);
|
||||
if (!$section) {
|
||||
return $this->error($request, '找不到此区块。', 404);
|
||||
}
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
$data = [
|
||||
'title' => $this->input($request, 'title'), 'lead' => $this->input($request, 'lead'),
|
||||
'body' => $this->input($request, 'body'),
|
||||
];
|
||||
$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) {
|
||||
throw new RuntimeException('请填写区块标题,并检查说明及正文长度。');
|
||||
}
|
||||
$data['body'] = Html::sanitize($data['body']);
|
||||
$repo->saveSection($slug, $key, $data, $this->version($request));
|
||||
|
||||
return View::redirect('/admin/pages/' . $slug . '/' . $key . '?saved=1');
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-section', [
|
||||
'title' => '编辑区块', 'section' => $section, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
public function preview(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$body = $this->input($request, 'body');
|
||||
if (strlen($body) > 300000) {
|
||||
return new Response(413, ['Cache-Control' => 'no-store'], '正文太长。');
|
||||
}
|
||||
$html = $this->input($request, 'format') === 'html' ? Html::sanitize($body) : Html::markdown($body);
|
||||
|
||||
return new Response(200, [
|
||||
'Content-Type' => 'text/html; charset=utf-8', 'Cache-Control' => 'no-store', 'X-Robots-Tag' => 'noindex, nofollow',
|
||||
'Content-Security-Policy' => "default-src 'none'; frame-ancestors 'none'; sandbox",
|
||||
], $html);
|
||||
}
|
||||
|
||||
private function guard(Request $request): ?Response
|
||||
{
|
||||
if (!$this->signedIn($request)) {
|
||||
return View::redirect('/admin/login');
|
||||
}
|
||||
if ($request->method() === 'POST' && !$this->validToken($request)) {
|
||||
return $this->error($request, '表单已过期,请刷新后重试。', 403);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function signedIn(Request $request): bool
|
||||
{
|
||||
$session = $request->session();
|
||||
$id = $session->get('admin_id');
|
||||
if (!is_int($id) || (int) $session->get('admin_since') < time() - 8 * 60 * 60) {
|
||||
return false;
|
||||
}
|
||||
$user = (new Repository())->administratorById($id);
|
||||
if (!$user || !hash_equals(hash('sha256', $user['password_hash']), (string) $session->get('auth_version'))) {
|
||||
$session->flush();
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->user = $user;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function token(Request $request): string
|
||||
{
|
||||
$session = $request->session();
|
||||
$token = $session->get('csrf');
|
||||
if (!is_string($token)) {
|
||||
$token = bin2hex(random_bytes(32));
|
||||
$session->set('csrf', $token);
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
private function validToken(Request $request): bool
|
||||
{
|
||||
return hash_equals($this->token($request), $this->input($request, 'csrf'));
|
||||
}
|
||||
|
||||
private function input(Request $request, string $key, bool $trimValue = true): string
|
||||
{
|
||||
$value = $request->post($key, '');
|
||||
if (!is_string($value) || !mb_check_encoding($value, 'UTF-8')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $trimValue ? trim($value) : $value;
|
||||
}
|
||||
|
||||
private function version(Request $request): int
|
||||
{
|
||||
$version = $this->input($request, 'version');
|
||||
|
||||
return ctype_digit($version) ? (int) $version : -1;
|
||||
}
|
||||
|
||||
private function articleInput(Request $request): array
|
||||
{
|
||||
$data = [];
|
||||
foreach (['title', 'slug', 'category', 'summary', 'body', 'status'] as $key) {
|
||||
$data[$key] = $this->input($request, $key);
|
||||
}
|
||||
$tags = preg_split('/[,,\r\n]+/u', $this->input($request, 'tags'));
|
||||
$data['tags'] = array_values(array_unique(array_slice(array_filter(
|
||||
array_map('trim', $tags),
|
||||
static fn (string $tag): bool => $tag !== '' && mb_strlen($tag) <= 80 && !str_contains($tag, '/'),
|
||||
), 0, 12)));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function address(Request $request): string
|
||||
{
|
||||
$peer = $request->getRemoteIp();
|
||||
$trusted = explode(',', getenv('LAYSENSE_TRUSTED_PROXIES') ?: '');
|
||||
$candidate = $request->header('x-real-ip', '');
|
||||
|
||||
return in_array($peer, $trusted, true) && filter_var($candidate, FILTER_VALIDATE_IP) ? $candidate : $peer;
|
||||
}
|
||||
|
||||
private function validationMessage(RuntimeException $exception): string
|
||||
{
|
||||
if ($exception instanceof \PDOException) {
|
||||
error_log($exception->getMessage());
|
||||
|
||||
return '保存失败,请稍后重试。';
|
||||
}
|
||||
|
||||
return $exception->getMessage();
|
||||
}
|
||||
|
||||
private function render(Request $request, string $view, array $data, int $status = 200): Response
|
||||
{
|
||||
return View::render($view, $data + ['token' => $this->token($request), 'user' => $this->user], $status, true);
|
||||
}
|
||||
|
||||
private function error(Request $request, string $message, int $status): Response
|
||||
{
|
||||
return $this->render($request, 'admin-error', ['title' => $message], $status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Html;
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
final class SiteController
|
||||
{
|
||||
public function home(Request $request): Response
|
||||
{
|
||||
return $this->page($request, 'home');
|
||||
}
|
||||
|
||||
public function page(Request $request, string $slug): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
if (!$page) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$isHome = $slug === 'home';
|
||||
|
||||
return View::render('page', [
|
||||
'site' => $repo->site(),
|
||||
'page' => $page,
|
||||
'path' => $isHome ? '/' : '/' . $slug,
|
||||
'title' => $page['title'],
|
||||
'description' => $page['description'],
|
||||
'socialImage' => $page['image'],
|
||||
'socialAlt' => $page['alt'],
|
||||
'articles' => $isHome ? $repo->articles(limit: 3) : [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function archive(Request $request, ?string $category = null, ?string $tag = null): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$title = $category ? Repository::CATEGORIES[$category] : ($tag ?: '来笙动态');
|
||||
$path = '/articles' . ($category ? '/category/' . $category : ($tag ? '/tag/' . rawurlencode($tag) : ''));
|
||||
$number = $request->get('page', '1');
|
||||
if (!is_scalar($number) || !preg_match('/^[1-9][0-9]{0,4}$/D', (string) $number)) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$page = (int) $number;
|
||||
$articles = $repo->articles($category, $tag, limit: 21, offset: ($page - 1) * 20);
|
||||
if ($page > 1 && $articles === []) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
|
||||
return View::render('archive', [
|
||||
'site' => $repo->site(), 'title' => $title . ' · 来笙', 'headline' => $title,
|
||||
'description' => '查看来笙的公告、新闻和产品动态。',
|
||||
'path' => $path . ($page > 1 ? '?page=' . $page : ''), 'archivePath' => $path,
|
||||
'category' => $category, 'tag' => $tag, 'pageNumber' => $page,
|
||||
'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
|
||||
'noindex' => $articles === [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function tagged(Request $request, string $tag): Response
|
||||
{
|
||||
$tag = rawurldecode($tag);
|
||||
if (mb_strlen($tag) > 80 || $tag === '') {
|
||||
return $this->missing($request);
|
||||
}
|
||||
|
||||
return $this->archive($request, tag: $tag);
|
||||
}
|
||||
|
||||
public function article(Request $request, string $slug): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$article = $repo->published($slug);
|
||||
if (!$article) {
|
||||
$redirect = $repo->articleRedirect($slug);
|
||||
|
||||
return $redirect ? View::redirect('/articles/' . $redirect['slug'], 301) : $this->missing($request);
|
||||
}
|
||||
$articleHtml = Html::markdown($article['body']);
|
||||
|
||||
return View::render('article', [
|
||||
'site' => $repo->site(), 'article' => $article, 'articleHtml' => $articleHtml,
|
||||
'title' => $article['title'] . ' · 来笙',
|
||||
'description' => $article['summary'] ?: mb_substr(trim(strip_tags($articleHtml)), 0, 150) ?: $article['title'],
|
||||
'path' => '/articles/' . $article['slug'], 'noindex' => trim($articleHtml) === '',
|
||||
]);
|
||||
}
|
||||
|
||||
public function legacyArticle(Request $request, string $id): Response
|
||||
{
|
||||
$article = (new Repository())->legacyArticle('/news/id/' . $id . '.html');
|
||||
|
||||
return $article ? View::redirect('/articles/' . $article['slug'], 301) : $this->missing($request);
|
||||
}
|
||||
|
||||
public function legacyCategory(Request $request, string $id): Response
|
||||
{
|
||||
$target = [
|
||||
'1' => '/articles/category/product', '2' => '/articles/category/news', '3' => '/articles/category/announcement',
|
||||
'5' => '/#supported-projects', '6' => '/#partners',
|
||||
][$id] ?? null;
|
||||
|
||||
return $target ? View::redirect($target, 301) : $this->missing($request);
|
||||
}
|
||||
|
||||
public function legacyTag(Request $request, string $tag): Response
|
||||
{
|
||||
return View::redirect('/articles/tag/' . rawurlencode(rawurldecode($tag)), 301);
|
||||
}
|
||||
|
||||
public function sitemap(Request $request): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$xml = ['<?xml version="1.0" encoding="UTF-8"?>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'];
|
||||
$pages = $repo->pages();
|
||||
if ($repo->articles(limit: 1)) {
|
||||
$pages[] = ['slug' => 'articles', 'updated_at' => null];
|
||||
}
|
||||
foreach ($pages as $page) {
|
||||
$xml[] = $this->sitemapUrl($page['slug'] === 'home' ? '/' : '/' . $page['slug'], $page['updated_at']);
|
||||
}
|
||||
foreach ($repo->sitemapArticles() as $article) {
|
||||
$xml[] = $this->sitemapUrl('/articles/' . $article['slug'], $article['updated_at']);
|
||||
}
|
||||
$xml[] = '</urlset>';
|
||||
|
||||
return new Response(200, ['Content-Type' => 'application/xml; charset=utf-8'], implode("\n", $xml) . "\n");
|
||||
}
|
||||
|
||||
public function robots(Request $request): Response
|
||||
{
|
||||
return new Response(200, ['Content-Type' => 'text/plain; charset=utf-8'],
|
||||
"User-agent: *\nAllow: /\nDisallow: /admin\nSitemap: " . View::absolute('/sitemap.xml') . "\n");
|
||||
}
|
||||
|
||||
public function missing(Request $request): Response
|
||||
{
|
||||
$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)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
||||
}
|
||||
}
|
||||
|
||||
return View::render('missing', [
|
||||
'site' => (new Repository())->site(), 'title' => '页面未找到 · 来笙', 'description' => '',
|
||||
'path' => null, 'noindex' => true,
|
||||
], 404);
|
||||
}
|
||||
|
||||
private function sitemapUrl(string $path, ?string $updated): string
|
||||
{
|
||||
$url = htmlspecialchars(View::absolute($path), ENT_XML1 | ENT_QUOTES, 'UTF-8');
|
||||
$date = $updated ? '<lastmod>' . View::date($updated, 'Y-m-d') . '</lastmod>' : '';
|
||||
|
||||
return ' <url><loc>' . $url . '</loc>' . $date . '</url>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<?php if ($articles): ?>
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($articles as $item): ?>
|
||||
<li>
|
||||
<div><strong><?= $e($item['title']) ?></strong>
|
||||
<small><?= $e(Repository::CATEGORIES[$item['category']]) ?> · <?= $item['status'] === 'published' ? '已发布' : '草稿' ?> · <?= $e(View::date($item['updated_at'])) ?></small>
|
||||
</div>
|
||||
<a class="button button-outline" href="/admin/articles/<?= $e($item['id']) ?>">编辑文章</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
<p class="empty-state">暂无文章。</p>
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<a class="back-link" href="/admin/articles">返回文章列表</a>
|
||||
<header class="admin-heading">
|
||||
<h1><?= $e($title) ?></h1>
|
||||
<?php if ($articleId && $article['status'] === 'published' && $article['slug'] !== ''): ?>
|
||||
<a class="button button-outline" href="/articles/<?= $e($article['slug']) ?>">查看公开页面</a>
|
||||
<?php endif ?>
|
||||
</header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/articles/<?= $e($articleId ?? 'new') ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($article['version']) ?>">
|
||||
<label>文章标题<input name="title" value="<?= $e($article['title']) ?>" required maxlength="120"></label>
|
||||
<div class="form-grid">
|
||||
<label>网址标识<input name="slug" value="<?= $e($article['slug']) ?>" required maxlength="100" pattern="[a-z0-9]+(-[a-z0-9]+)*" placeholder="product-update"><small>使用小写英文字母、数字和连字符。</small></label>
|
||||
<label>分类<select name="category">
|
||||
<?php foreach (Repository::CATEGORIES as $key => $label): ?>
|
||||
<option value="<?= $e($key) ?>" <?= $article['category'] === $key ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
</div>
|
||||
<label>标签<input name="tags" value="<?= $e(implode(',', $article['tags'])) ?>" placeholder="用逗号分隔"></label>
|
||||
<label>摘要<textarea name="summary" rows="2" maxlength="250"><?= $e($article['summary']) ?></textarea><small>用于动态列表和搜索摘要。</small></label>
|
||||
<?= View::fragment('admin-editor', ['format' => 'markdown', 'body' => $article['body']]) ?>
|
||||
<div class="form-submit">
|
||||
<label>发布状态<select name="status">
|
||||
<option value="draft" <?= $article['status'] === 'draft' ? 'selected' : '' ?>>草稿</option>
|
||||
<option value="published" <?= $article['status'] === 'published' ? 'selected' : '' ?>>已发布</option>
|
||||
</select></label>
|
||||
<button class="button button-primary" type="submit">保存文章</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
?>
|
||||
<header class="admin-heading">
|
||||
<h1>文章与动态</h1>
|
||||
<a class="button button-primary" href="/admin/articles/new">新建文章</a>
|
||||
</header>
|
||||
<div class="admin-panel">
|
||||
<?= View::fragment('admin-article-list', ['articles' => $articles]) ?>
|
||||
</div>
|
||||
<?php if ($pageNumber > 1 || $hasNext): ?>
|
||||
<nav class="pagination" aria-label="文章分页">
|
||||
<?php if ($pageNumber > 1): ?><a class="button button-outline" href="/admin/articles?page=<?= $pageNumber - 1 ?>">上一页</a><?php endif ?>
|
||||
<span>第 <?= $pageNumber ?> 页</span>
|
||||
<?php if ($hasNext): ?><a class="button button-outline" href="/admin/articles?page=<?= $pageNumber + 1 ?>">下一页</a><?php endif ?>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<header class="admin-heading">
|
||||
<div><h1>内容管理</h1><p>管理网站页面、文章、公告和产品动态。</p></div>
|
||||
<a class="button button-primary" href="/admin/articles/new">新建文章</a>
|
||||
</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>
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($page['slug']) ?>">编辑页面</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="admin-panel" aria-labelledby="recent-title">
|
||||
<div class="admin-heading compact"><h2 id="recent-title">最近编辑的文章</h2><a href="/admin/articles">管理全部文章</a></div>
|
||||
<?= View::fragment('admin-article-list', ['articles' => $articles]) ?>
|
||||
</section>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<div class="editor" data-editor data-format="<?= $format ?>">
|
||||
<label for="editor-text">正文(<?= $format === 'markdown' ? 'Markdown' : 'HTML' ?>)</label>
|
||||
<div class="editor-toolbar">
|
||||
<div role="group" aria-label="插入格式">
|
||||
<button type="button" data-insert="heading">小标题</button>
|
||||
<button type="button" data-insert="bold">粗体</button>
|
||||
<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>
|
||||
</div>
|
||||
<textarea id="editor-text" name="body" rows="15" spellcheck="false"><?= $e($body) ?></textarea>
|
||||
<?php if ($format === 'html'): ?>
|
||||
<p class="field-note">支持段落、标题、链接、图片、列表、表格和折叠问答。保存时会清理脚本、内联样式等标签或属性。</p>
|
||||
<?php endif ?>
|
||||
<div class="editor-preview rich prose" id="editor-preview" aria-live="polite" hidden></div>
|
||||
</div>
|
||||
@@ -0,0 +1,2 @@
|
||||
<h1><?= App\Content\View::escape($title) ?></h1>
|
||||
<a class="button button-primary" href="/admin">返回内容管理</a>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php use App\Content\View; ?>
|
||||
<?php if ($error): ?><p class="feedback error" role="alert"><?= View::escape($error) ?></p><?php endif ?>
|
||||
<?php if ($saved && !$error): ?><p class="feedback success" role="status">已保存。</p><?php endif ?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title><?= $e($title) ?> · 来笙 CMS</title>
|
||||
<link rel="icon" href="/assets/favicon.png" type="image/png">
|
||||
<link rel="stylesheet" href="/assets/site.css">
|
||||
<link rel="stylesheet" href="/assets/admin.css">
|
||||
<script src="/assets/admin.js" defer></script>
|
||||
</head>
|
||||
<body class="admin-body">
|
||||
<a class="skip-link" href="#admin-content">跳到内容</a>
|
||||
<header class="admin-bar">
|
||||
<div class="admin-wrap admin-bar-inner">
|
||||
<a class="wordmark" href="/admin" aria-label="来笙内容管理首页"><img src="/assets/wordmark.webp" alt="来笙 Laysense" width="130" height="33"></a>
|
||||
<?php if ($user): ?>
|
||||
<nav aria-label="后台导航">
|
||||
<a href="/admin">页面</a>
|
||||
<a href="/admin/articles">文章</a>
|
||||
<a href="/">访问网站</a>
|
||||
<form method="post" action="/admin/logout">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<button class="button button-outline" type="submit">退出</button>
|
||||
</form>
|
||||
</nav>
|
||||
<?php else: ?>
|
||||
<a class="back-link" href="/">返回网站</a>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</header>
|
||||
<main class="admin-wrap admin-main" id="admin-content"><?= $content ?></main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<div class="login-box">
|
||||
<h1>登录内容管理</h1>
|
||||
<p>编辑来笙网站的页面、公告和文章。</p>
|
||||
<?php if ($error): ?><p class="feedback error" role="alert"><?= $e($error) ?></p><?php endif ?>
|
||||
<form class="admin-form" method="post" action="/admin/login">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<label>管理员邮箱<input name="email" type="email" value="<?= $e($email) ?>" autocomplete="username" required maxlength="254"></label>
|
||||
<label>密码<input name="password" type="password" autocomplete="current-password" required></label>
|
||||
<button class="button button-primary" type="submit">登录</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$slug = $page['slug'];
|
||||
?>
|
||||
<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>
|
||||
</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">
|
||||
<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>图片替代文本<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>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$slug = $section['page_slug'];
|
||||
$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>
|
||||
</header>
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/pages/<?= $e($slug) ?>/<?= $e($key) ?>">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<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>
|
||||
<?= 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,29 @@
|
||||
<?php
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<section class="section article-page" aria-labelledby="archive-title" data-enter>
|
||||
<div class="wrap">
|
||||
<div class="section-heading">
|
||||
<?php if ($tag || $category): ?><a class="back-link" href="/articles">全部动态</a><?php endif ?>
|
||||
<h1 id="archive-title"><?= $e($headline) ?></h1>
|
||||
<p>来笙的公告、新闻和产品动态。</p>
|
||||
</div>
|
||||
<nav class="filter-nav" aria-label="动态分类">
|
||||
<a href="/articles" <?= !$category && !$tag ? 'aria-current="page"' : '' ?>>全部</a>
|
||||
<?php foreach (Repository::CATEGORIES as $key => $label): ?>
|
||||
<a href="/articles/category/<?= $e($key) ?>" <?= $category === $key ? 'aria-current="page"' : '' ?>><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<?= View::fragment('article-list', ['articles' => $articles]) ?>
|
||||
<?php if ($pageNumber > 1 || $hasNext): ?>
|
||||
<nav class="pagination" aria-label="动态分页">
|
||||
<?php if ($pageNumber > 1): ?><a class="button button-outline" href="<?= $e($archivePath . ($pageNumber > 2 ? '?page=' . ($pageNumber - 1) : '')) ?>" rel="prev">上一页</a><?php endif ?>
|
||||
<span>第 <?= $e($pageNumber) ?> 页</span>
|
||||
<?php if ($hasNext): ?><a class="button button-outline" href="<?= $e($archivePath . '?page=' . ($pageNumber + 1)) ?>" rel="next">下一页</a><?php endif ?>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<?php if ($articles): ?>
|
||||
<ul class="article-list">
|
||||
<?php foreach ($articles as $item): ?>
|
||||
<li>
|
||||
<a class="article-row" href="/articles/<?= $e($item['slug']) ?>">
|
||||
<span class="article-category"><?= $e(Repository::CATEGORIES[$item['category']]) ?></span>
|
||||
<span class="article-row-title"><?= $e($item['title']) ?>
|
||||
<?php if ($item['summary']): ?><small><?= $e($item['summary']) ?></small><?php endif ?>
|
||||
</span>
|
||||
<time datetime="<?= $e(View::date($item['published_at'], 'Y-m-d')) ?>"><?= $e(View::date($item['published_at'], 'Y.m.d')) ?></time>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
<p class="empty-state">暂无已发布的动态。</p>
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
use App\Content\Repository;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<article class="section article-page" itemscope itemtype="https://schema.org/Article" data-enter>
|
||||
<div class="wrap reading-wrap">
|
||||
<a class="back-link" href="/articles">全部动态</a>
|
||||
<header class="section-heading">
|
||||
<div class="article-meta">
|
||||
<a href="/articles/category/<?= $e($article['category']) ?>" itemprop="articleSection"><?= $e(Repository::CATEGORIES[$article['category']]) ?></a>
|
||||
<time itemprop="datePublished" datetime="<?= $e(View::date($article['published_at'], DATE_ATOM)) ?>"><?= $e(View::date($article['published_at'])) ?></time>
|
||||
<meta itemprop="dateModified" content="<?= $e(View::date($article['updated_at'], DATE_ATOM)) ?>">
|
||||
</div>
|
||||
<h1 itemprop="headline"><?= $e($article['title']) ?></h1>
|
||||
<?php if ($article['summary']): ?><p itemprop="description"><?= $e($article['summary']) ?></p><?php endif ?>
|
||||
<span itemprop="author" itemscope itemtype="https://schema.org/Organization"><meta itemprop="name" content="<?= $e($site['name']) ?>"></span>
|
||||
</header>
|
||||
<div class="rich prose" itemprop="articleBody">
|
||||
<?php if (trim($articleHtml) !== ''): ?>
|
||||
<?= $articleHtml ?>
|
||||
<?php else: ?>
|
||||
<p class="empty-state">此公告的原文暂不可用。</p>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if ($article['tags']): ?>
|
||||
<nav class="filter-nav" aria-label="文章标签">
|
||||
<?php foreach ($article['tags'] as $tag): ?>
|
||||
<a href="/articles/tag/<?= $e(rawurlencode($tag)) ?>"><?= $e($tag) ?></a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</article>
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$canonical = $path !== null ? View::absolute($path) : null;
|
||||
$imageUrl = !empty($socialImage) ? $socialImage : '/assets/original/home-hero.webp';
|
||||
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', '关于来笙'],
|
||||
];
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN" data-type="<?= $e($kind) ?>" data-buttons="solid" data-motion="on">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?= $e($title) ?></title>
|
||||
<meta name="description" content="<?= $e($description) ?>">
|
||||
<meta name="theme-color" content="#f5f7fb">
|
||||
<meta name="page-type" content="<?= $e($kind) ?>">
|
||||
<meta name="site-kind" content="<?= $e($siteKind) ?>">
|
||||
<?php if ($canonical): ?>
|
||||
<link rel="canonical" href="<?= $e($canonical) ?>">
|
||||
<meta property="og:url" content="<?= $e($canonical) ?>">
|
||||
<?php endif ?>
|
||||
<?php if (!empty($noindex)): ?><meta name="robots" content="noindex"><?php endif ?>
|
||||
<meta property="og:type" content="<?= isset($article) ? 'article' : 'website' ?>">
|
||||
<meta property="og:locale" content="zh_CN">
|
||||
<meta property="og:site_name" content="来笙 Laysense">
|
||||
<meta property="og:title" content="<?= $e($title) ?>">
|
||||
<meta property="og:description" content="<?= $e($description) ?>">
|
||||
<meta property="og:image" content="<?= $e($imageUrl) ?>">
|
||||
<meta property="og:image:alt" content="<?= $e(($socialAlt ?? '') ?: '来笙 Laysense') ?>">
|
||||
<?php if (isset($article)): ?>
|
||||
<meta property="article:published_time" content="<?= $e(View::date($article['published_at'], DATE_ATOM)) ?>">
|
||||
<meta property="article:modified_time" content="<?= $e(View::date($article['updated_at'], DATE_ATOM)) ?>">
|
||||
<?php endif ?>
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<link rel="icon" href="/assets/favicon.png" type="image/png">
|
||||
<link rel="stylesheet" href="/assets/site.css">
|
||||
<script src="/assets/site.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<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">
|
||||
</a>
|
||||
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
|
||||
<span></span><span></span><span class="sr-only">菜单</span>
|
||||
</button>
|
||||
<nav id="primary-navigation" class="primary-nav" aria-label="主导航">
|
||||
<?php foreach ($nav as [$url, $label]): ?>
|
||||
<?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>
|
||||
</nav>
|
||||
<a class="button button-outline masthead-action" href="#contact">联系来笙</a>
|
||||
</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>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,8 @@
|
||||
<section class="section article-page">
|
||||
<div class="wrap">
|
||||
<p class="overline">404</p>
|
||||
<h1>页面未找到</h1>
|
||||
<p>请检查网址,或回到首页浏览产品与服务。</p>
|
||||
<a class="button button-primary" href="/">返回首页</a>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$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="hero-copy">
|
||||
<?php if (!$home): ?>
|
||||
<nav class="breadcrumbs" aria-label="面包屑" itemscope itemtype="https://schema.org/BreadcrumbList">
|
||||
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
|
||||
<a itemprop="item" href="/"><span itemprop="name">首页</span></a>
|
||||
<meta itemprop="position" content="1">
|
||||
</span>
|
||||
<span class="crumb-divider" aria-hidden="true">/</span>
|
||||
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
|
||||
<a itemprop="item" href="/<?= $e($page['slug']) ?>" aria-current="page"><span itemprop="name"><?= $e($page['name']) ?></span></a>
|
||||
<meta itemprop="position" content="2">
|
||||
</span>
|
||||
</nav>
|
||||
<?php else: ?>
|
||||
<p class="overline hero-label">上海来笙信息科技有限公司</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>
|
||||
<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>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($page['image'] !== ''): ?>
|
||||
<div class="hero-visual <?= $home ? 'hero-illustration' : ($service ? 'hero-service-art' : 'app-frame') ?>" data-visual>
|
||||
<img src="<?= $e($page['image']) ?>" alt="<?= $e($page['alt']) ?>" width="1448" height="1086" fetchpriority="high">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if ($home): ?>
|
||||
<div class="wrap hero-directory">
|
||||
<span class="overline">产品与服务</span>
|
||||
<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>
|
||||
<a href="/shnu-sc"><span>SHNU 学生</span><small>软著申请方案</small></a>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</section>
|
||||
<?php if ($page['quicklinks']): ?>
|
||||
<nav class="section-nav" aria-label="本页目录">
|
||||
<div class="wrap section-nav-inner">
|
||||
<?php foreach ($page['quicklinks'] as [$url, $label]): ?>
|
||||
<a href="<?= $e($url) ?>"><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
<?php foreach ($page['sections'] as $section): ?>
|
||||
<?= View::fragment('section', ['section' => $section, 'moment' => $home && $section['key'] === 'about']) ?>
|
||||
<?php endforeach ?>
|
||||
<?php if ($home): ?>
|
||||
<section class="section home-news" id="blog" aria-labelledby="updates-heading">
|
||||
<div class="wrap">
|
||||
<div class="section-heading inline-heading">
|
||||
<h2 id="updates-heading">来笙动态</h2>
|
||||
<a class="button button-outline" href="/articles">查看全部动态</a>
|
||||
</div>
|
||||
<?= View::fragment('article-list', ['articles' => $articles]) ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php if ($page['partners']): ?>
|
||||
<section class="section network" aria-labelledby="network-heading">
|
||||
<div class="wrap">
|
||||
<div class="section-heading"><h2 id="network-heading">支持项目与合作伙伴</h2></div>
|
||||
<?php foreach (['来笙支持项目' => 'supported-projects', '来笙合作伙伴' => 'partners'] as $group => $id): ?>
|
||||
<div class="network-group" id="<?= $e($id) ?>">
|
||||
<h3><?= $e($group) ?></h3>
|
||||
<ul class="network-list">
|
||||
<?php foreach ($page['partners'] as $partner): ?>
|
||||
<?php if ($partner['group'] !== $group) { continue; } ?>
|
||||
<li>
|
||||
<?php if ($partner['url']): ?><a href="<?= $e($partner['url']) ?>"><?php else: ?><div><?php endif ?>
|
||||
<?php if ($partner['image']): ?>
|
||||
<img src="<?= $e($partner['image']) ?>" alt="" loading="lazy" width="76" height="28">
|
||||
<?php endif ?>
|
||||
<span><?= $e($partner['name']) ?></span>
|
||||
<?php if ($partner['url']): ?></a><?php else: ?></div><?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<section class="section section-<?= $e($section['style']) ?>" id="<?= $e($section['key']) ?>" aria-labelledby="heading-<?= $e($section['key']) ?>" <?= $moment ? 'data-moment="iris-opens"' : '' ?>>
|
||||
<div class="wrap">
|
||||
<div class="section-heading">
|
||||
<h2 id="heading-<?= $e($section['key']) ?>"><?= $e($section['title']) ?></h2>
|
||||
<?php if ($section['lead']): ?><p><?= $e($section['lead']) ?></p><?php endif ?>
|
||||
</div>
|
||||
<div class="rich"><?= $section['body'] ?></div>
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user