1. 独立页(登录/安装/错误)套上 HTML 骨架 —— 修「首页为什么没有样式」: 新增 templates/layout-bare.php,View::render 对独立页也走完整 <head> + CSS。 2. 以个人为中心:Kinship::label() 现算称呼、Auth::homeTitle() 出「X的家书」; 同一批人在不同登录者眼里自动变成公公婆婆 / 岳父岳母(不存一次性称谓)。 3. 附件存储可配置:Storage 门面(local / 阿里云 OSS),库里只存相对键, 云端失败自动回退本地;设置页可选驱动并填 OSS 参数(照 MovieLog 的方案)。 4. 三种角色:admin / member / guest,访客只读、写操作一律 403; accounts.role 枚举扩容,老库靠 Schema::ensure() 自动升级。 5. 家谱:只存相邻两代的边(parent / spouse),其余称呼全部推导 —— 兄弟姐妹不存边(共同父母 + birth_rank 排行推长子/次女、哥哥/妹妹), 认不清的人用虚拟人物 is_placeholder 占位,关系天然双向。 顺带修掉本地 e2e 挖出的 8 个线上级 bug(性别写死、长幼方向反、关系方向静默写反、 birth_rank 不从表单取回、隐式可空参数致响应头失效、无文件字段被误判为上传失败、 layout 变量撞车覆盖 $me、世代 0 显示成「下 0 代」)。 验证:kinship 单测 37/0 · HTTP e2e 81/0 · 老库升级专测 14/0 · 反向验证 11/11(把每个修复改回旧写法,对应断言都会变红)。
78 lines
2.8 KiB
PHP
78 lines
2.8 KiB
PHP
<?php
|
||
/**
|
||
* 应用引导:配置加载、会话、自动加载、全局辅助函数。
|
||
* 每个页面/入口只需 require 这一个文件。
|
||
*/
|
||
|
||
declare(strict_types=1);
|
||
|
||
// ---------------- 自动加载(避免「新增类忘了 require」这类事故)----------------
|
||
spl_autoload_register(function ($class) {
|
||
if (strpos($class, 'App\\') !== 0) {
|
||
return;
|
||
}
|
||
// App\Storage\OssDriver → app/Storage/OssDriver.php(子命名空间靠这段映射)
|
||
$rel = str_replace('\\', '/', substr($class, 4));
|
||
$file = __DIR__ . '/' . $rel . '.php';
|
||
if (is_file($file)) {
|
||
require $file;
|
||
}
|
||
});
|
||
|
||
define('FB_ROOT', dirname(__DIR__));
|
||
define('FB_APP', __DIR__);
|
||
define('FB_UPLOADS', FB_ROOT . '/uploads');
|
||
|
||
// ---------------- 配置 ----------------
|
||
$configFile = FB_ROOT . '/config.php';
|
||
if (!is_file($configFile)) {
|
||
http_response_code(500);
|
||
echo '<!doctype html><meta charset="utf-8"><title>家书 · 未配置</title>'
|
||
. '<div style="max-width:520px;margin:12vh auto;padding:28px 32px;'
|
||
. 'background:#fff;border:1px solid rgba(47,36,30,.1);border-radius:16px;'
|
||
. 'font:15px/1.8 -apple-system,\'PingFang SC\',\'Microsoft YaHei\',sans-serif;color:#2F241E">'
|
||
. '<h1 style="font-size:18px;margin:0 0 12px">还差一步:没有找到 config.php</h1>'
|
||
. '<p style="color:#7C6A5B;margin:0 0 16px">'
|
||
. '请复制同目录下的 <code>config.example.php</code> 为 <code>config.php</code>,'
|
||
. '填好数据库连接与 app_key 后再访问。</p>'
|
||
. '</div>';
|
||
exit;
|
||
}
|
||
|
||
$GLOBALS['config'] = require $configFile;
|
||
|
||
// ---------------- 错误报告(线上不显示错误,避免泄露路径与库信息)----------------
|
||
$debug = !empty($GLOBALS['config']['debug']);
|
||
error_reporting(E_ALL);
|
||
ini_set('display_errors', $debug ? '1' : '0');
|
||
ini_set('log_errors', '1');
|
||
|
||
// ---------------- 时区:日期是家书的核心数据,一开始就必须明确 ----------------
|
||
date_default_timezone_set($GLOBALS['config']['timezone'] ?? 'Asia/Shanghai');
|
||
|
||
// ---------------- 安全响应头 ----------------
|
||
// Referrer-Policy: 跨域取图不带 Referer —— 这一条能兜住云存储防盗链
|
||
// 导致的「图片不显示、但地址栏直接打开没问题」那类怪异现象。
|
||
if (!headers_sent()) {
|
||
header('Referrer-Policy: same-origin');
|
||
header('X-Content-Type-Options: nosniff');
|
||
}
|
||
|
||
// ---------------- 会话 ----------------
|
||
$isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
||
|| (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https');
|
||
|
||
session_name('fbsid');
|
||
session_set_cookie_params([
|
||
'lifetime' => 0,
|
||
'path' => '/',
|
||
'secure' => $isHttps,
|
||
'httponly' => true,
|
||
'samesite' => 'Lax',
|
||
]);
|
||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||
session_start();
|
||
}
|
||
|
||
require FB_APP . '/helpers.php';
|