Files
laoyang ee256adc4b 界面主题:5 套经典配色,按账号记住
系统设置里多一块「🎨 我的界面主题」,点卡片即时预览、保存后全站生效,不用重新登录。

- lib/theme.php(新增):主题注册表 ticket/indigo/forest/wine/midnight,
  分别是「复古票根(暖橙,默认)/ 靛蓝 / 松林 / 绛红 / 暗夜(深色)」。
  currentThemeKey() 以 session 为准,session 里没有就从 admins.theme 补读一次
  —— 升级前就已经登录着的会话也能立刻用上自己账号存的主题。库里是脏值时回落默认主题。
- css/themes.css(新增):5 套调色板,全部以 [data-theme="<key>"] 规则块给出,
  每套 16 个变量一个不少。**必须排在 css/style.css 之后加载**:两者优先级相同
  (都是 0,1,0),靠后出现者胜。另加 --primary-rgb("R, G, B" 三元组),
  页面里的淡色底/光晕一律 rgba(var(--primary-rgb), α),所以加一套主题只需动 CSS,
  页面与 JS 一行都不用改;每套还要声明 color-scheme,否则暗色主题下原生控件
  (日期选择器、下拉、滚动条)仍是刺眼的白底。
- css/style.css::root 保留默认主题那一份作兜底;导航底色改走 --nav-bg,
  滚动条改走变量,按钮光晕改走 --primary-rgb。
- lib/db.php / lib/auth.php:admins 增列 theme(幂等 ALTER,老库自动补,空值 = 默认主题);
  setAdminTheme() 校验 key、写库、同步 session。
- settings.php:主题卡片区。每张预览卡自己套一层 data-theme,用的就是那套主题真实的
  变量,因此「预览所见」与「换上去之后」必然一致,不必再抄一份色值;另有一小段 JS
  在点选时改 <html data-theme> 做即时预览(没脚本时选中后提交同样生效)。
- 14 个页面:<html> 上输出 data-theme,并在 style.css 之后引入 themes.css;
  内联样式里写死的橙色 rgba(230,126,34,…) 全部改走 rgba(var(--primary-rgb),…);
  影院/观影人色板选中态的描边由 #333 改为 var(--text-primary)(暗色主题下才看得见)。
- annual_report.php:报告本身仍是深色「海报」版式,但点缀色跟随主题;
  Chart.js 画在 canvas 上读不到 CSS 变量,改为运行时从 <html> 的计算样式取色。

顺手修的两个坑:
1. 注释里**不能**出现 PHP 起止标签。PHP 的结束标签在 // 注释里同样会关闭 PHP 模式,
   之后若再出现短标签就会被真的执行 —— lib/theme.php 的用法说明里写了完整标签示例,
   导致该文件被 require 时直接 Fatal error、整站白屏,而 php -l 查不出来(只看语法)。
   现在部署脚本里加了一道静态断言专门挡这个。
2. themesCssLink() 的返回值末尾补一个换行:PHP 会吃掉结束标签后面那一个换行,
   不补的话渲染结果里这一行会和下一行黏成一行。

回归:theme_e2e 111/111(含老库自动补列、脏值回落、5 个选项渲染、切换后落库+落 session+
立刻生效、跨账号隔离、非法 key 与注入被拒、themes.css 完整性、:root 与 ticket 一致、
无残留写死主色、无悬空 CSS 变量);reviews_e2e 84/84、fetch_movie 76/76、storage 196/196。
A/B 48 个响应:把「新增 head 行 / data-theme 属性 / 橙色→变量」三类等价替换归一化、
并把设置页新增区块整块删掉之后,**其余部分逐字节一致,零残留差异**。
线上 PHP 7.4.30 / 8.1.7 双版本冒烟全通过(迁移、5 套主题切换、跨账号隔离均验证,
写测试后已把 admin #1 的主题原样还原、其它账号一字未动)。
2026-09-22 20:33:47 +08:00

214 lines
8.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// ============================================
// 文件: index.php (含搜索 + 观影人头像)
// ============================================
require_once 'config.php';
checkLogin();
$admin = getCurrentAdmin();
// 获取搜索关键词
$keyword = isset($_GET['keyword']) ? trim($_GET['keyword']) : '';
if (!empty($keyword)) {
$movies = searchMovies($keyword);
} else {
$movies = getMovies();
}
// 挂上评价概况(几条评价 / 平均分),一次查询,列表里只展示有评价的电影
attachReviewStatsToMovies($movies);
?>
<!DOCTYPE html>
<html lang="zh-CN"<?= themeAttr() ?>>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>电影日志 - 我的电影</title>
<link rel="stylesheet" href="css/style.css">
<?= themesCssLink() ?>
<style>
/* 搜索栏样式 */
.search-bar {
display: flex;
gap: 10px;
align-items: center;
background: var(--card-bg);
padding: 8px 16px;
border-radius: 12px;
box-shadow: var(--shadow);
border: 1px solid var(--border-color);
max-width: 500px;
margin-bottom: 20px;
}
.search-bar input[type="text"] {
flex: 1;
border: none;
outline: none;
padding: 10px 12px;
font-size: 15px;
background: transparent;
color: var(--text-primary);
}
.search-bar button {
background: var(--primary);
color: #fff;
border: none;
padding: 8px 20px;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: background 0.2s;
white-space: nowrap;
}
.search-bar button:hover {
background: var(--primary-dark);
}
.search-bar .clear-btn {
background: transparent;
color: var(--text-secondary);
padding: 8px 12px;
font-size: 14px;
}
.search-bar .clear-btn:hover {
background: var(--bg-secondary);
}
.search-info {
color: var(--text-secondary);
font-size: 14px;
margin-bottom: 16px;
}
/* 观影人头像标签 */
.viewer-tag {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 12px;
padding: 2px 6px;
border-radius: 12px;
background: rgba(0,0,0,0.04);
}
.viewer-tag img {
width: 18px;
height: 18px;
border-radius: 50%;
object-fit: cover;
}
.card-viewers {
margin-top: 6px;
display: flex;
flex-wrap: wrap;
gap: 4px 8px;
}
/* 评价均分(有人评价过才显示) */
.meta-rating {
color: var(--primary);
font-weight: 600;
}
@media (max-width: 600px) {
.search-bar {
flex-wrap: wrap;
padding: 8px;
}
.search-bar input[type="text"] {
width: 100%;
flex: 0 0 100%;
padding: 8px 12px;
}
.search-bar button {
flex: 1;
}
}
</style>
</head>
<body>
<?php include 'nav.php'; ?>
<main class="main-content">
<div class="page-header">
<div>
<h2><?= empty($keyword) ? '我的电影' : '搜索结果' ?></h2>
<p class="subtitle">
<?php if (empty($keyword)): ?>
共 <?= count($movies) ?> 部 · 按观影日期排序
<?php else: ?>
找到 <?= count($movies) ?> 部匹配“<strong><?= h($keyword) ?></strong>”的电影
<?php endif; ?>
</p>
</div>
</div>
<!-- 搜索栏 -->
<form method="GET" action="" class="search-bar">
<input type="text" name="keyword" placeholder="搜索电影名称、影院、观影人..." value="<?= h($keyword) ?>">
<button type="submit">🔍 搜索</button>
<?php if (!empty($keyword)): ?>
<a href="index.php" class="clear-btn">✕ 清除</a>
<?php endif; ?>
</form>
<?php if (empty($movies)): ?>
<div class="empty-state">
<div class="empty-icon">🎥</div>
<h3><?= empty($keyword) ? '还没有电影记录' : '没有找到匹配的电影' ?></h3>
<p><?= empty($keyword) ? '点击「添加电影」开始记录你的观影之旅吧' : '尝试其他关键词' ?></p>
<?php if (empty($keyword)): ?>
<a href="add.php" class="btn btn-primary">➕ 添加第一部电影</a>
<?php else: ?>
<a href="index.php" class="btn btn-outline">查看全部电影</a>
<?php endif; ?>
</div>
<?php else: ?>
<div class="waterfall">
<?php foreach ($movies as $movie): ?>
<div class="movie-card" onclick="location.href='detail.php?id=<?= $movie['id'] ?>'">
<div class="card-image">
<?php
$poster = posterUrl($movie['poster_path']);
if (strpos($poster, 'placeholder') !== false):
?>
<div class="placeholder-poster">
<span>🎬</span>
<span class="placeholder-title"><?= h($movie['title']) ?></span>
</div>
<?php else: ?>
<img src="<?= $poster ?>" alt="<?= h($movie['title']) ?>" loading="lazy">
<?php endif; ?>
</div>
<div class="card-body">
<h3 class="card-title"><?= h($movie['title']) ?></h3>
<div class="card-meta">
<span class="meta-date">📅 <?= $movie['watch_date'] ? date('Y年m月d日', strtotime($movie['watch_date'])) : '日期待补' ?></span>
<?php if ($movie['cinema_name']): ?>
<span class="meta-cinema" style="color: <?= h($movie['cinema_color'] ?? '#888888') ?>;">
🏛️ <?= h($movie['cinema_name']) ?>
</span>
<?php endif; ?>
<?php if (!empty($movie['review_count'])): ?>
<span class="meta-rating" title="共 <?= (int)$movie['review_count'] ?> 条评价">
⭐ <?= $movie['review_avg'] ?><span style="color: var(--text-secondary); font-weight: 400;">/10</span>
</span>
<?php endif; ?>
</div>
<!-- 观影人 -->
<?php if (!empty($movie['viewers'])): ?>
<div class="card-viewers">
<?php foreach ($movie['viewers'] as $viewer): ?>
<span class="viewer-tag" style="color: <?= h($viewer['color'] ?: '#888888') ?>;">
<img src="<?= getAvatarUrl($viewer['avatar'] ?? null, $viewer['name']) ?>" alt="<?= h($viewer['name']) ?>">
<?= h($viewer['name']) ?>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</main>
<script src="js/main.js"></script>
</body>
</html>