初始化版本
This commit is contained in:
56
api/head.php
Normal file
56
api/head.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// 头像代理:转发 https://api.iyuns.com/api/head 并返回 { url }
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$endpoint = 'https://api.iyuns.com/api/head';
|
||||
|
||||
function fetch_json($url) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 8,
|
||||
CURLOPT_TIMEOUT => 12,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_USERAGENT => 'DiscussionProxy/1.0',
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if ($err) { return null; }
|
||||
$json = json_decode($body, true);
|
||||
return is_array($json) ? $json : null;
|
||||
}
|
||||
|
||||
$resp = fetch_json($endpoint);
|
||||
$url = '';
|
||||
if ($resp && ($resp['code'] ?? 0) == 200) {
|
||||
$url = preg_replace('/[`\s]/', '', (string)($resp['data'] ?? ''));
|
||||
}
|
||||
if (!$url) {
|
||||
// 远程失败时,回退到本地随机头像(遍历 avatars 下所有日期目录)
|
||||
$root = __DIR__ . '/../avatars';
|
||||
$candidates = [];
|
||||
if (is_dir($root)) {
|
||||
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root));
|
||||
foreach ($rii as $file) {
|
||||
if ($file->isFile()) {
|
||||
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
|
||||
if (in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
|
||||
$rel = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $file->getPathname()));
|
||||
$candidates[] = $rel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($candidates)) {
|
||||
shuffle($candidates);
|
||||
$url = $candidates[0];
|
||||
}
|
||||
}
|
||||
// 如果本地也没有,则后备一个 Unsplash 头像
|
||||
if (!$url) {
|
||||
$url = 'https://images.unsplash.com/photo-1547425260-76bcadfb4f9b?w=200&h=200&fit=crop';
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['url' => $url], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
70
api/picture.php
Normal file
70
api/picture.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// 图片代理:随机或指定来源(heisi/wapmeinvpic/baisi/meinvpic),返回 { url, source }
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$type = strtolower($_GET['type'] ?? '');
|
||||
$map = [
|
||||
'heisi' => 'https://api.iyuns.com/api/heisi',
|
||||
'wapmeinvpic' => 'https://api.iyuns.com/api/wapmeinvpic',
|
||||
'baisi' => 'https://api.iyuns.com/api/baisi',
|
||||
'meinvpic' => 'https://api.iyuns.com/api/meinvpic',
|
||||
'random4kPic' => 'https://api.iyuns.com/api/random4kPic',
|
||||
'jk' => 'https://api.iyuns.com/api/jk',
|
||||
];
|
||||
if (!$type || !isset($map[$type])) {
|
||||
$keys = array_keys($map);
|
||||
$type = $keys[array_rand($keys)];
|
||||
}
|
||||
$endpoint = $map[$type];
|
||||
|
||||
function fetch_json($url) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 8,
|
||||
CURLOPT_TIMEOUT => 12,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_USERAGENT => 'PictureProxy/1.0',
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if ($err) { return null; }
|
||||
$json = json_decode($body, true);
|
||||
return is_array($json) ? $json : null;
|
||||
}
|
||||
|
||||
$resp = fetch_json($endpoint);
|
||||
$url = '';
|
||||
if ($resp && ($resp['code'] ?? 0) == 200) {
|
||||
$url = preg_replace('/[`\s]/', '', (string)($resp['data'] ?? ''));
|
||||
}
|
||||
if (!$url) {
|
||||
// 远程失败时,回退到本地随机图片(遍历 pictures/images 下的所有图片)
|
||||
$root = __DIR__ . '/../pictures/images';
|
||||
$candidates = [];
|
||||
if (is_dir($root)) {
|
||||
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root));
|
||||
foreach ($rii as $file) {
|
||||
if ($file->isFile()) {
|
||||
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
|
||||
if (in_array($ext, ['jpg','jpeg','png','gif','webp'])) {
|
||||
$rel = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $file->getPathname()));
|
||||
$candidates[] = $rel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($candidates)) {
|
||||
shuffle($candidates);
|
||||
$url = $candidates[0];
|
||||
$type = 'local';
|
||||
}
|
||||
}
|
||||
// 如果本地也没有,则后备一张 Unsplash 图片
|
||||
if (!$url) {
|
||||
$url = 'https://images.unsplash.com/photo-1523206489230-c012c4783a90?w=1200&h=800&fit=crop';
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['url' => $url, 'source' => $type], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
71
api/review_action.php
Normal file
71
api/review_action.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// 审核接口:approve 或 reject 待审核视频
|
||||
// 需要管理员密码:my123123(或已登录的会话)
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
session_start();
|
||||
|
||||
$ADMIN_PASSWORD = 'my123123';
|
||||
$pendingDir = __DIR__ . '/../videos_pending';
|
||||
$videosDirRoot = __DIR__ . '/../videos';
|
||||
|
||||
function jsonOut($ok, $msg, $extra = []) {
|
||||
echo json_encode(array_merge(['ok' => $ok, 'msg' => $msg], $extra), JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||||
$file = isset($_POST['file']) ? $_POST['file'] : '';
|
||||
$password = isset($_POST['password']) ? $_POST['password'] : '';
|
||||
|
||||
// 会话已登录或提供了正确密码之一即可
|
||||
if (empty($_SESSION['admin_ok']) && $password !== $ADMIN_PASSWORD) {
|
||||
jsonOut(false, '管理员密码错误或未登录');
|
||||
}
|
||||
|
||||
if (!$action || !$file) {
|
||||
jsonOut(false, '缺少必要参数');
|
||||
}
|
||||
|
||||
// 基础安全处理,禁止路径穿越
|
||||
$basename = basename($file);
|
||||
$pendingPath = $pendingDir . '/' . $basename;
|
||||
if (!is_file($pendingPath)) {
|
||||
jsonOut(false, '待审核文件不存在');
|
||||
}
|
||||
|
||||
if ($action === 'reject') {
|
||||
$ok = @unlink($pendingPath);
|
||||
@unlink($pendingPath . '.json');
|
||||
jsonOut(!!$ok, $ok ? '已拒绝并删除' : '删除失败');
|
||||
}
|
||||
|
||||
if ($action === 'approve') {
|
||||
// 生成日期目录
|
||||
$dateDir = date('Y-m-d');
|
||||
$dstDir = $videosDirRoot . '/' . $dateDir;
|
||||
if (!is_dir($dstDir)) {
|
||||
@mkdir($dstDir, 0777, true);
|
||||
}
|
||||
// 根据扩展名生成唯一文件名
|
||||
$ext = strtolower(pathinfo($basename, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, ['mp4','webm','mov'])) {
|
||||
// 不支持的扩展也允许,但统一改成 mp4
|
||||
$ext = 'mp4';
|
||||
}
|
||||
$newName = 'video_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
|
||||
$dstPath = $dstDir . '/' . $newName;
|
||||
|
||||
$ok = @rename($pendingPath, $dstPath);
|
||||
@rename($pendingPath . '.json', $dstPath . '.json');
|
||||
if (!$ok) {
|
||||
jsonOut(false, '转存失败');
|
||||
}
|
||||
|
||||
// 返回相对路径,便于前端显示
|
||||
$rel = 'videos/' . $dateDir . '/' . $newName;
|
||||
jsonOut(true, '审核通过,已入库', ['path' => $rel]);
|
||||
}
|
||||
|
||||
jsonOut(false, '未知操作');
|
||||
?>
|
||||
56
api/review_picture_action.php
Normal file
56
api/review_picture_action.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// 图片审核 API:通过/拒绝 pictures_pending 中的图片
|
||||
session_start();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$ADMIN_PASSWORD = 'my123123';
|
||||
$pendingDir = __DIR__ . '/../pictures_pending';
|
||||
$picturesRoot = __DIR__ . '/../pictures/images/user';
|
||||
|
||||
function out($ok, $msg, $extra = []) {
|
||||
echo json_encode(array_merge(['ok'=>$ok,'msg'=>$msg], $extra), JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$authed = !empty($_SESSION['admin_ok']);
|
||||
if (!$authed) {
|
||||
$pwd = trim($_POST['password'] ?? '');
|
||||
if ($pwd === $ADMIN_PASSWORD) $authed = true;
|
||||
}
|
||||
if (!$authed) out(false, '未授权或密码错误');
|
||||
|
||||
$action = $_POST['action'] ?? '';
|
||||
$file = basename($_POST['file'] ?? '');
|
||||
if (!$action || !$file) out(false, '缺少必要参数');
|
||||
|
||||
$pendingPath = $pendingDir . '/' . $file;
|
||||
if (!is_file($pendingPath)) out(false, '待审核文件不存在');
|
||||
|
||||
if ($action === 'reject') {
|
||||
$ok = @unlink($pendingPath);
|
||||
@unlink($pendingPath . '.json');
|
||||
out(!!$ok, $ok ? '已拒绝并删除' : '删除失败');
|
||||
}
|
||||
|
||||
if ($action === 'approve') {
|
||||
$dateDir = date('Y-m-d');
|
||||
$dstDir = $picturesRoot . '/' . $dateDir;
|
||||
if (!is_dir($dstDir)) @mkdir($dstDir, 0777, true);
|
||||
|
||||
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, ['jpg','jpeg','png','gif','webp'])) $ext = 'jpg';
|
||||
$newName = 'image_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
|
||||
$dstPath = $dstDir . '/' . $newName;
|
||||
|
||||
$ok = @rename($pendingPath, $dstPath);
|
||||
@rename($pendingPath . '.json', $dstPath . '.json');
|
||||
if (!$ok) out(false, '转存失败');
|
||||
|
||||
// 相对路径(供前端或日志显示)
|
||||
$rel = 'pictures/images/user/' . $dateDir . '/' . $newName;
|
||||
out(true, '审核通过,已入库', ['path' => $rel]);
|
||||
}
|
||||
|
||||
out(false, '未知操作');
|
||||
?>
|
||||
|
||||
61
api/review_text_action.php
Normal file
61
api/review_text_action.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// 文案审核 API:通过/拒绝 texts_pending 中的 JSON 文案
|
||||
session_start();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$ADMIN_PASSWORD = 'my123123';
|
||||
|
||||
function resp($ok, $msg) {
|
||||
echo json_encode(['ok' => $ok, 'msg' => $msg], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$authed = !empty($_SESSION['admin_ok']);
|
||||
if (!$authed) {
|
||||
$pwd = trim($_POST['password'] ?? '');
|
||||
if ($pwd === $ADMIN_PASSWORD) $authed = true;
|
||||
}
|
||||
if (!$authed) resp(false, '未授权或密码错误');
|
||||
|
||||
$action = $_POST['action'] ?? '';
|
||||
$file = basename($_POST['file'] ?? '');
|
||||
|
||||
$pendingDir = __DIR__ . '/../texts_pending';
|
||||
$path = $pendingDir . '/' . $file;
|
||||
if ($file === '' || !is_file($path)) resp(false, '待处理文件不存在');
|
||||
|
||||
if ($action === 'approve') {
|
||||
$data = json_decode(@file_get_contents($path), true);
|
||||
if (!is_array($data) || empty($data['content'])) {
|
||||
resp(false, '文案数据无效');
|
||||
}
|
||||
|
||||
$title = trim($data['title'] ?? '');
|
||||
$content = trim($data['content'] ?? '');
|
||||
$text = $title !== '' ? ('【' . $title . '】 ' . $content) : $content;
|
||||
|
||||
// 追加到 texts/DATE/all.json
|
||||
$dateDir = __DIR__ . '/../texts/' . date('Y-m-d');
|
||||
if (!is_dir($dateDir)) @mkdir($dateDir, 0777, true);
|
||||
$allPath = $dateDir . '/all.json';
|
||||
$arr = [];
|
||||
if (is_file($allPath)) {
|
||||
$arr = json_decode(@file_get_contents($allPath), true);
|
||||
if (!is_array($arr)) $arr = [];
|
||||
}
|
||||
$arr[] = [
|
||||
'text' => $text,
|
||||
'source' => 'user',
|
||||
'created_at' => date('c'),
|
||||
];
|
||||
@file_put_contents($allPath, json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
|
||||
@unlink($path);
|
||||
resp(true, '已通过并入库');
|
||||
} else if ($action === 'reject') {
|
||||
@unlink($path);
|
||||
resp(true, '已拒绝并删除');
|
||||
} else {
|
||||
resp(false, '未知操作');
|
||||
}
|
||||
?>
|
||||
61
api/save_avatar.php
Normal file
61
api/save_avatar.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// 保存头像到本地(避免重复),不进行过期清理
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
function respond($ok, $message = '', $path = '') {
|
||||
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
$url = $data['url'] ?? '';
|
||||
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
respond(false, 'URL无效');
|
||||
}
|
||||
|
||||
$scheme = parse_url($url, PHP_URL_SCHEME);
|
||||
if (!in_array(strtolower($scheme), ['http','https'])) {
|
||||
respond(false, '仅支持http/https图片地址');
|
||||
}
|
||||
|
||||
$avatarsRoot = __DIR__ . '/../avatars';
|
||||
if (!is_dir($avatarsRoot)) { @mkdir($avatarsRoot, 0777, true); }
|
||||
$today = (new DateTime('now'))->format('Y-m-d');
|
||||
$targetDir = $avatarsRoot . '/' . $today;
|
||||
if (!is_dir($targetDir)) { @mkdir($targetDir, 0777, true); }
|
||||
|
||||
// 推断扩展名
|
||||
$pathExt = strtolower(pathinfo(parse_url($url, PHP_URL_PATH) ?? '', PATHINFO_EXTENSION));
|
||||
$allowed = ['jpg','jpeg','png','gif','webp'];
|
||||
if (!$pathExt || !in_array($pathExt, $allowed)) { $pathExt = 'jpg'; }
|
||||
|
||||
// 使用URL的basename作为文件名,若没有则用hash
|
||||
$basename = basename(parse_url($url, PHP_URL_PATH) ?: '');
|
||||
if (!$basename || $basename === '/' || $basename === '\\') {
|
||||
$basename = md5($url) . '.' . $pathExt;
|
||||
}
|
||||
if (strpos($basename, '.') === false) { $basename .= '.' . $pathExt; }
|
||||
$safeName = preg_replace('/[^\w\.-]+/u', '_', $basename);
|
||||
$targetPath = $targetDir . '/' . $safeName;
|
||||
|
||||
// 如果已存在,跳过下载
|
||||
if (file_exists($targetPath)) {
|
||||
respond(true, '文件已存在,跳过下载', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
}
|
||||
|
||||
// 下载保存
|
||||
try {
|
||||
$read = @fopen($url, 'rb');
|
||||
if (!$read) { respond(false, '无法读取远程图片'); }
|
||||
$write = @fopen($targetPath, 'wb');
|
||||
if (!$write) { respond(false, '无法写入文件'); }
|
||||
stream_copy_to_stream($read, $write);
|
||||
fclose($read);
|
||||
fclose($write);
|
||||
} catch (Throwable $e) {
|
||||
respond(false, '保存失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
|
||||
66
api/save_picture.php
Normal file
66
api/save_picture.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// 保存图片到本地,不做清理;保存目录按照远程URL的路径结构组织
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
function respond($ok, $message = '', $path = '') {
|
||||
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 读取JSON输入
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
$url = $data['url'] ?? '';
|
||||
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
respond(false, 'URL无效');
|
||||
}
|
||||
|
||||
// 只允许 http/https
|
||||
$scheme = parse_url($url, PHP_URL_SCHEME);
|
||||
if (!in_array(strtolower($scheme), ['http','https'])) {
|
||||
respond(false, '仅支持http/https图片地址');
|
||||
}
|
||||
|
||||
$root = __DIR__ . '/../pictures';
|
||||
if (!is_dir($root)) { @mkdir($root, 0777, true); }
|
||||
|
||||
// 解析远程路径:按照域名后的路径作为保存文件夹结构
|
||||
$path = parse_url($url, PHP_URL_PATH) ?: '';
|
||||
if (!$path) { respond(false, '无法解析远程路径'); }
|
||||
|
||||
// 将路径拆分并进行安全过滤,避免非法字符与上级目录
|
||||
$segments = array_values(array_filter(explode('/', $path), function($s){ return $s !== ''; }));
|
||||
if (!count($segments)) { respond(false, '路径为空'); }
|
||||
|
||||
$filename = array_pop($segments);
|
||||
$safeSegs = array_map(function($seg){
|
||||
$seg = preg_replace('/[^A-Za-z0-9._-]+/u', '_', $seg);
|
||||
return trim($seg, '._-') ?: 'unk';
|
||||
}, $segments);
|
||||
$safeName = preg_replace('/[^A-Za-z0-9._-]+/u', '_', $filename);
|
||||
if (!$safeName) { $safeName = 'image_' . time() . '.jpg'; }
|
||||
|
||||
$targetDir = $root;
|
||||
foreach ($safeSegs as $seg) { $targetDir .= DIRECTORY_SEPARATOR . $seg; if (!is_dir($targetDir)) { @mkdir($targetDir, 0777, true); } }
|
||||
$targetPath = $targetDir . DIRECTORY_SEPARATOR . $safeName;
|
||||
|
||||
// 如果文件已存在则跳过下载
|
||||
if (file_exists($targetPath)) {
|
||||
respond(true, '文件已存在,跳过下载', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
}
|
||||
|
||||
// 下载保存
|
||||
try {
|
||||
$read = @fopen($url, 'rb');
|
||||
if (!$read) { respond(false, '无法读取远程图片'); }
|
||||
$write = @fopen($targetPath, 'wb');
|
||||
if (!$write) { respond(false, '无法写入文件'); }
|
||||
stream_copy_to_stream($read, $write);
|
||||
fclose($read);
|
||||
fclose($write);
|
||||
} catch (Throwable $e) {
|
||||
respond(false, '保存失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
|
||||
63
api/save_text.php
Normal file
63
api/save_text.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// 保存讨论区文案到本地(避免重复),不进行过期清理
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
function respond($ok, $message = '', $path = '') {
|
||||
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
$text = trim($data['text'] ?? '');
|
||||
$source = trim($data['source'] ?? '');
|
||||
if ($text === '') { respond(false, '文本为空'); }
|
||||
|
||||
// 根目录
|
||||
$textsRoot = __DIR__ . '/../texts';
|
||||
if (!is_dir($textsRoot)) { @mkdir($textsRoot, 0777, true); }
|
||||
// 按来源(/后缀,即 yiyan/dujitang/renjian 等)创建子目录
|
||||
$safeSource = preg_replace('/[^A-Za-z0-9._-]+/u', '_', $source ?: 'unknown');
|
||||
$safeSource = trim($safeSource, '._-');
|
||||
if ($safeSource === '') { $safeSource = 'unknown'; }
|
||||
|
||||
// 日期目录
|
||||
$today = (new DateTime('now'))->format('Y-m-d');
|
||||
$targetDir = $textsRoot . '/' . $safeSource . '/' . $today;
|
||||
if (!is_dir($targetDir)) { @mkdir($targetDir, 0777, true); }
|
||||
|
||||
// 改为保存到同一天的单个文件 all.json
|
||||
$targetPath = $targetDir . '/all.json';
|
||||
|
||||
// 读取已有数据
|
||||
$entries = [];
|
||||
if (file_exists($targetPath)) {
|
||||
$rawJson = @file_get_contents($targetPath);
|
||||
$decoded = json_decode($rawJson, true);
|
||||
if (is_array($decoded)) { $entries = $decoded; }
|
||||
}
|
||||
|
||||
// 重复检查:文本完全相同则认为重复
|
||||
foreach ($entries as $e) {
|
||||
if (isset($e['text']) && trim((string)$e['text']) === $text) {
|
||||
respond(true, '文本已存在,跳过保存', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
}
|
||||
}
|
||||
|
||||
$entries[] = [
|
||||
'text' => $text,
|
||||
'source' => $source,
|
||||
'created_at' => (new DateTime('now'))->format(DateTime::ATOM),
|
||||
];
|
||||
|
||||
try {
|
||||
$json = json_encode($entries, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
if (@file_put_contents($targetPath, $json, LOCK_EX) === false) {
|
||||
respond(false, '无法写入文件');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
respond(false, '保存失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
|
||||
107
api/save_video.php
Normal file
107
api/save_video.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// 保存视频到本地,并清理超过2天的旧视频(第三天自动清除第一天的视频)
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
function respond($ok, $message = '', $path = '') {
|
||||
echo json_encode(['success' => $ok, 'message' => $message, 'path' => $path], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 递归删除目录及其内容(用于清理旧视频)
|
||||
function rrmdir($dir) {
|
||||
if (!is_dir($dir)) return;
|
||||
$items = @scandir($dir);
|
||||
if ($items === false) return;
|
||||
foreach ($items as $item) {
|
||||
if ($item === '.' || $item === '..') continue;
|
||||
$full = $dir . DIRECTORY_SEPARATOR . $item;
|
||||
if (is_dir($full)) {
|
||||
rrmdir($full);
|
||||
} else {
|
||||
@unlink($full);
|
||||
}
|
||||
}
|
||||
@rmdir($dir);
|
||||
}
|
||||
|
||||
// 读取JSON输入
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
$url = $data['url'] ?? '';
|
||||
$title = $data['title'] ?? '';
|
||||
|
||||
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
respond(false, 'URL无效');
|
||||
}
|
||||
|
||||
// 只允许 http/https
|
||||
$scheme = parse_url($url, PHP_URL_SCHEME);
|
||||
if (!in_array(strtolower($scheme), ['http','https'])) {
|
||||
respond(false, '仅支持http/https视频地址');
|
||||
}
|
||||
|
||||
$videosRoot = __DIR__ . '/../videos';
|
||||
if (!is_dir($videosRoot)) {
|
||||
@mkdir($videosRoot, 0777, true);
|
||||
}
|
||||
|
||||
$today = (new DateTime('now'))->format('Y-m-d');
|
||||
$targetDir = $videosRoot . '/' . $today;
|
||||
if (!is_dir($targetDir)) {
|
||||
@mkdir($targetDir, 0777, true);
|
||||
}
|
||||
|
||||
// 生成文件名
|
||||
$basename = basename(parse_url($url, PHP_URL_PATH) ?: 'video_' . time() . '.mp4');
|
||||
if (strpos($basename, '.') === false) { $basename .= '.mp4'; }
|
||||
$safeName = preg_replace('/[^\w\.-]+/u', '_', $basename);
|
||||
$targetPath = $targetDir . '/' . $safeName;
|
||||
|
||||
// 如果文件已存在则跳过下载
|
||||
$skipDownload = file_exists($targetPath);
|
||||
$msg = '保存成功';
|
||||
if ($skipDownload) {
|
||||
$msg = '文件已存在,跳过下载';
|
||||
} else {
|
||||
// 下载保存
|
||||
try {
|
||||
$read = @fopen($url, 'rb');
|
||||
if (!$read) { respond(false, '无法读取远程视频'); }
|
||||
$write = @fopen($targetPath, 'wb');
|
||||
if (!$write) { respond(false, '无法写入文件'); }
|
||||
stream_copy_to_stream($read, $write);
|
||||
fclose($read);
|
||||
fclose($write);
|
||||
} catch (Throwable $e) {
|
||||
respond(false, '保存失败: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复清理逻辑:仅保留最近两天的视频目录,删除更早的目录
|
||||
try {
|
||||
$dirs = @scandir($videosRoot);
|
||||
if (is_array($dirs)) {
|
||||
// 仅筛选形如 YYYY-MM-DD 的目录
|
||||
$dateDirs = [];
|
||||
foreach ($dirs as $d) {
|
||||
if ($d === '.' || $d === '..') continue;
|
||||
$path = $videosRoot . DIRECTORY_SEPARATOR . $d;
|
||||
if (is_dir($path) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $d)) {
|
||||
$dateDirs[] = $d;
|
||||
}
|
||||
}
|
||||
// 按日期升序排序
|
||||
sort($dateDirs);
|
||||
// 保留最近两天(末尾两项),其它全部删除
|
||||
if (count($dateDirs) > 30) {
|
||||
$toDelete = array_slice($dateDirs, 0, count($dateDirs) - 2);
|
||||
foreach ($toDelete as $del) {
|
||||
rrmdir($videosRoot . DIRECTORY_SEPARATOR . $del);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// 清理失败不影响主流程
|
||||
}
|
||||
|
||||
respond(true, $msg, str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
83
api/text.php
Normal file
83
api/text.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// 文案代理:随机或指定来源(yiyan/dujitang/renjian),返回 { text }
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$type = strtolower($_GET['type'] ?? '');
|
||||
$map = [
|
||||
'dujitang'=> 'https://api.iyuns.com/api/dujitang',
|
||||
'renjian' => 'https://api.iyuns.com/api/renjian',
|
||||
'ktff'=> 'https://v.api.aa1.cn/api/api-wenan-ktff/index.php?type=5', // 新增文艺文案
|
||||
'yiyan'=> 'https://v.api.aa1.cn/api/yiyan/index.php?type=json', // 新增纯文本一言
|
||||
'wenan_anwei'=> 'https://v.api.aa1.cn/api/api-wenan-anwei/index.php?type=json', // 新增文艺文案
|
||||
'wenan_gaoxiao'=> 'https://v.api.aa1.cn/api/api-wenan-gaoxiao/index.php?aa1=json', // 新增文艺文案
|
||||
'wenan_shenhuifu'=> 'https://v.api.aa1.cn/api/api-wenan-shenhuifu/index.php?aa1=json', // 新增文艺文案
|
||||
];
|
||||
if (!$type || !isset($map[$type])) {
|
||||
$keys = array_keys($map);
|
||||
$type = $keys[array_rand($keys)];
|
||||
}
|
||||
$endpoint = $map[$type];
|
||||
|
||||
function fetch_json($url) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 8,
|
||||
CURLOPT_TIMEOUT => 12,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_USERAGENT => 'DiscussionProxy/1.0',
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if ($err) { return null; }
|
||||
$json = json_decode($body, true);
|
||||
return is_array($json) ? $json : null;
|
||||
}
|
||||
|
||||
$resp = fetch_json($endpoint);
|
||||
$text = '';
|
||||
if ($resp && ($resp['code'] ?? 0) == 200) {
|
||||
$fields = ['yiyan','data','text','anwei','gaoxiao','shenhuifu'];
|
||||
foreach ($fields as $k) {
|
||||
$t = trim((string)($resp[$k] ?? ''));
|
||||
if ($t !== '') { $text = $t; break; }
|
||||
if (is_array($resp['data'] ?? null)) {
|
||||
$t = trim((string)($resp['data'][$k] ?? ''));
|
||||
if ($t !== '') { $text = $t; break; }
|
||||
}
|
||||
}
|
||||
$text = preg_replace('/[`]/', '', $text);
|
||||
}
|
||||
if (!$text) {
|
||||
// 远程失败时,回退到本地随机文案
|
||||
$root = __DIR__ . '/../texts';
|
||||
$pool = [];
|
||||
if (is_dir($root)) {
|
||||
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root));
|
||||
foreach ($rii as $file) {
|
||||
if ($file->isFile() && strtolower($file->getFilename()) === 'all.json') {
|
||||
$json = @file_get_contents($file->getPathname());
|
||||
if ($json) {
|
||||
$arr = json_decode($json, true);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $it) {
|
||||
$t = trim((string)($it['text'] ?? ''));
|
||||
if ($t !== '') { $pool[] = $t; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($pool)) {
|
||||
$text = $pool[array_rand($pool)];
|
||||
$type = 'local';
|
||||
} else {
|
||||
// 如果本地也没有,则使用一个默认文案
|
||||
$text = '今天也要元气满满!';
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['text' => $text, 'source' => $type], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
92
api/upload_picture.php
Normal file
92
api/upload_picture.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// 接收用户投稿的图片,保存到待审核目录 pictures_pending
|
||||
// 不直接进入 pictures/images/,待管理员在 review_pictures.php 审核后再转存并自动重命名
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
$pendingDir = __DIR__ . '/../pictures_pending';
|
||||
if (!is_dir($pendingDir)) {
|
||||
@mkdir($pendingDir, 0777, true);
|
||||
}
|
||||
|
||||
function sanitizeFileName($name) {
|
||||
$name = preg_replace('/[^A-Za-z0-9_\-\.\(\)\[\]\s]/u', '_', $name);
|
||||
if (strlen($name) > 120) {
|
||||
$ext = pathinfo($name, PATHINFO_EXTENSION);
|
||||
$base = pathinfo($name, PATHINFO_FILENAME);
|
||||
$base = substr($base, 0, 100);
|
||||
$name = $base . ($ext ? ('.' . $ext) : '');
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
function html($s) { return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
|
||||
|
||||
$allowed = ['jpg','jpeg','png','gif','webp'];
|
||||
$maxSize = 10 * 1024 * 1024; // 10MB
|
||||
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
|
||||
|
||||
if (!isset($_FILES['picture'])) {
|
||||
echo '<p>未接收到文件。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 上传错误处理
|
||||
if (!empty($_FILES['picture']['error'])) {
|
||||
$err = (int)$_FILES['picture']['error'];
|
||||
if ($err === UPLOAD_ERR_INI_SIZE || $err === UPLOAD_ERR_FORM_SIZE) {
|
||||
echo '<p>上传失败:文件大小超过服务器限制。请确保图片不超过 10MB。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
echo '<p>上传失败,错误码:' . $err . '。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_uploaded_file($_FILES['picture']['tmp_name'])) {
|
||||
echo '<p>文件上传失败。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = $_FILES['picture'];
|
||||
$origName = $file['name'] ?? 'uploaded_image';
|
||||
$safeName = sanitizeFileName($origName);
|
||||
$ext = strtolower(pathinfo($safeName, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, $allowed)) {
|
||||
echo '<p>仅支持文件类型:jpg / jpeg / png / gif / webp。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 大小限制 10MB
|
||||
$size = (int)($_FILES['picture']['size'] ?? 0);
|
||||
if ($size > $maxSize) {
|
||||
echo '<p>图片大小超过 10MB 限制,投稿失败。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$unique = date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
|
||||
$target = $pendingDir . '/' . $unique;
|
||||
|
||||
if (!move_uploaded_file($file['tmp_name'], $target)) {
|
||||
echo '<p>保存文件失败,请稍后重试。</p><p><a href="../upload_picture.php">返回图片投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$meta = [
|
||||
'original_name' => $origName,
|
||||
'saved_name' => basename($target),
|
||||
'title' => $title,
|
||||
'uploaded_at' => date('c'),
|
||||
'size' => $file['size'] ?? 0,
|
||||
'type' => $file['type'] ?? '',
|
||||
];
|
||||
@file_put_contents($pendingDir . '/' . basename($target) . '.json', json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
|
||||
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
|
||||
echo '<p>投稿成功!图片已进入待审核队列。</p>';
|
||||
if (!empty($title)) {
|
||||
echo '<p>标题:' . html($title) . '</p>';
|
||||
}
|
||||
echo '<p>管理员可前往 <a href="../review_pictures.php">图片审核页面</a> 进行审批。</p>';
|
||||
echo '<p><a href="../upload_picture.php">继续投稿</a> 或 <a href="../index.php">返回首页</a></p>';
|
||||
echo '</div>';
|
||||
?>
|
||||
36
api/upload_text.php
Normal file
36
api/upload_text.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// 接收用户提交的文案,保存到 texts_pending 目录(JSON文件)
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
$pendingDir = __DIR__ . '/../texts_pending';
|
||||
if (!is_dir($pendingDir)) {
|
||||
@mkdir($pendingDir, 0777, true);
|
||||
}
|
||||
|
||||
function html($s){ return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
|
||||
|
||||
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
|
||||
$content = isset($_POST['content']) ? trim($_POST['content']) : '';
|
||||
|
||||
if ($content === '') {
|
||||
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
|
||||
echo '<p>文案内容不能为空。</p><p><a href="../upload_text.php">返回文案投稿页</a></p>';
|
||||
echo '</div>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$name = 'text_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.json';
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'uploaded_at' => date('c'),
|
||||
];
|
||||
@file_put_contents($pendingDir . '/' . $name, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
|
||||
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
|
||||
echo '<p>提交成功!文案已保存到待处理目录。</p>';
|
||||
if ($title !== '') echo '<p>标题:' . html($title) . '</p>';
|
||||
echo '<p>内容:</p><pre style="white-space:pre-wrap;">' . html($content) . '</pre>';
|
||||
echo '<p><a href="../upload_text.php">继续提交</a> 或 <a href="../index.php">返回首页</a></p>';
|
||||
echo '</div>';
|
||||
?>
|
||||
95
api/upload_video.php
Normal file
95
api/upload_video.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// 接收用户投稿的视频,保存到待审核目录 videos_pending
|
||||
// 不直接进入 videos/,待管理员在 review.php 审核后再转存并自动重命名
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
$pendingDir = __DIR__ . '/../videos_pending';
|
||||
if (!is_dir($pendingDir)) {
|
||||
@mkdir($pendingDir, 0777, true);
|
||||
}
|
||||
|
||||
function sanitizeFileName($name) {
|
||||
$name = preg_replace('/[^A-Za-z0-9_\-\.\(\)\[\]\s]/u', '_', $name);
|
||||
// 避免过长
|
||||
if (strlen($name) > 120) {
|
||||
$ext = pathinfo($name, PATHINFO_EXTENSION);
|
||||
$base = pathinfo($name, PATHINFO_FILENAME);
|
||||
$base = substr($base, 0, 100);
|
||||
$name = $base . ($ext ? ('.' . $ext) : '');
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
function html($s) { return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
|
||||
|
||||
$allowed = ['mp4','webm','mov'];
|
||||
$maxSize = 50 * 1024 * 1024; // 50MB
|
||||
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
|
||||
|
||||
if (!isset($_FILES['video'])) {
|
||||
echo '<p>未接收到文件。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 上传错误处理
|
||||
if (!empty($_FILES['video']['error'])) {
|
||||
$err = (int)$_FILES['video']['error'];
|
||||
if ($err === UPLOAD_ERR_INI_SIZE || $err === UPLOAD_ERR_FORM_SIZE) {
|
||||
echo '<p>上传失败:文件大小超过服务器限制。请确保视频不超过 50MB。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
echo '<p>上传失败,错误码:' . $err . '。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_uploaded_file($_FILES['video']['tmp_name'])) {
|
||||
echo '<p>文件上传失败。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = $_FILES['video'];
|
||||
$origName = $file['name'] ?? 'uploaded_video';
|
||||
$safeName = sanitizeFileName($origName);
|
||||
$ext = strtolower(pathinfo($safeName, PATHINFO_EXTENSION));
|
||||
if (!in_array($ext, $allowed)) {
|
||||
echo '<p>仅支持文件类型:mp4 / webm / mov。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 大小限制 50MB
|
||||
$size = (int)($_FILES['video']['size'] ?? 0);
|
||||
if ($size > $maxSize) {
|
||||
echo '<p>视频大小超过 50MB 限制,投稿失败。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 生成不重复的文件名(保留原名作为前缀,防止覆盖)
|
||||
$unique = date('Ymd_His') . '_' . mt_rand(1000,9999) . '.' . $ext;
|
||||
$target = $pendingDir . '/' . $unique;
|
||||
|
||||
if (!move_uploaded_file($file['tmp_name'], $target)) {
|
||||
echo '<p>保存文件失败,请稍后重试。</p><p><a href="../upload.php">返回投稿页</a></p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 可选:记录一个简单的元信息文件
|
||||
$meta = [
|
||||
'original_name' => $origName,
|
||||
'saved_name' => basename($target),
|
||||
'title' => $title,
|
||||
'uploaded_at' => date('c'),
|
||||
'size' => $file['size'] ?? 0,
|
||||
'type' => $file['type'] ?? '',
|
||||
];
|
||||
@file_put_contents($pendingDir . '/' . basename($target) . '.json', json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
|
||||
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
|
||||
echo '<p>投稿成功!文件已进入待审核队列。</p>';
|
||||
if (!empty($title)) {
|
||||
echo '<p>标题:' . html($title) . '</p>';
|
||||
}
|
||||
echo '<p>管理员可前往 <a href="../review.php">审核页面</a> 进行审批。</p>';
|
||||
echo '<p><a href="../upload.php">继续投稿</a> 或 <a href="../index.php">返回首页</a></p>';
|
||||
echo '</div>';
|
||||
?>
|
||||
133
api/videos.php
Normal file
133
api/videos.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
// 代理获取视频地址的接口:从多个来源“随机/顺序”获取 1~N 条视频地址,并返回统一格式
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
// 指定来源功能已取消:统一按优先级尝试全部来源;如需随机请使用 ?random=1
|
||||
// 支持的远程来源(按优先级尝试,默认启用全部并按优先级依次尝试)
|
||||
$endpoints = [
|
||||
'https://api.kuleu.com/api/MP4_xiaojiejie?type=json', // 新增来源(纯视频URL或JSON)
|
||||
'https://v2.xxapi.cn/api/meinv', // 新来源(JSON: {code,data})
|
||||
'https://api.iyuns.com/api/meinv', // 旧来源(JSON: {code,data})
|
||||
'https://api.kuleu.com/api/xjj?type=json', // 新增来源(JSON: {code,data})
|
||||
'https://api.dwo.cc/api/ksvideo?type=json', // 新增来源(JSON: {code,data})
|
||||
'https://v2.api-m.com/api/meinv?type=json', // 新增来源(JSON: {code,data})
|
||||
'https://api.mhimg.cn/api/Sj_girls_video?type=json', // 新增来源(JSON: {code,data})
|
||||
];
|
||||
// 随机获取:默认开启;如需关闭可用 ?random=0
|
||||
$randomParam = $_GET['random'] ?? null;
|
||||
$random = !isset($randomParam) ? true : (intval($randomParam) === 1);
|
||||
$count = intval($_GET['count'] ?? 1);
|
||||
if ($count < 1) $count = 1; if ($count > 5) $count = 5; // 限制最多5条
|
||||
// 是否包含本地视频的开关
|
||||
$includeLocal = intval($_GET['include_local'] ?? 0) === 1;
|
||||
// 本地视频条数上限(当开启包含本地时生效,默认与远程条数相同)
|
||||
$localCount = intval($_GET['local_count'] ?? $count);
|
||||
if ($localCount < 0) $localCount = 0; if ($localCount > 10) $localCount = 10; // 限制一次最多10条本地视频
|
||||
|
||||
function fetch_remote_url($endpoint) {
|
||||
// 使用 curl 更稳妥地请求第三方接口
|
||||
$ch = curl_init($endpoint);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 8,
|
||||
CURLOPT_TIMEOUT => 12,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_USERAGENT => 'VideoFetcher/1.0',
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if ($err) { return null; }
|
||||
$json = json_decode($body, true);
|
||||
$candidate = '';
|
||||
if (is_array($json)) {
|
||||
// 某些接口包含 code 字段,若存在则需为 200
|
||||
if (array_key_exists('code', $json) && intval($json['code']) !== 200) {
|
||||
return null;
|
||||
}
|
||||
// 兼容不同字段名:mp4_video、data、url、mp4、video
|
||||
foreach (['mp4_video','data','url','mp4','video','pic'] as $key) {
|
||||
if (!empty($json[$key]) && is_string($json[$key])) { $candidate = $json[$key]; break; }
|
||||
}
|
||||
} else {
|
||||
// 非JSON:可能直接返回URL
|
||||
$candidate = trim((string)$body);
|
||||
}
|
||||
// 清理反引号和空白
|
||||
$candidate = preg_replace('/[`\s]/', '', (string)$candidate);
|
||||
// 简单校验:必须是 http/https,且 URL 中包含常见视频扩展(允许出现在路径或查询字符串中)
|
||||
if (!$candidate || !preg_match('/^https?:\/\//i', $candidate)) { return null; }
|
||||
if (!preg_match('/\.(mp4|webm|mov)(?![A-Za-z])/i', $candidate)) { return null; }
|
||||
return $candidate;
|
||||
}
|
||||
|
||||
// 远程接口视频列表
|
||||
$remote = [];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$u = null;
|
||||
// 依次尝试多个来源,取第一个成功的(随机模式下,每次尝试顺序打乱)
|
||||
$epOrder = $endpoints;
|
||||
if ($random && count($epOrder) > 1) { shuffle($epOrder); }
|
||||
foreach ($epOrder as $ep) {
|
||||
$u = fetch_remote_url($ep);
|
||||
if ($u) { break; }
|
||||
}
|
||||
if ($u) {
|
||||
$remote[] = [
|
||||
'url' => $u,
|
||||
'title' => '接口视频 ' . ($i + 1),
|
||||
];
|
||||
}
|
||||
}
|
||||
// 随机模式下,对远程列表打乱顺序
|
||||
if ($random && count($remote) > 1) { shuffle($remote); }
|
||||
|
||||
// 同时把本地已保存的视频加入列表(可选)
|
||||
$videosRoot = __DIR__ . '/../videos';
|
||||
$local = [];
|
||||
// 构建本地视频列表,用于开关合并或远程失败时的回退
|
||||
if (is_dir($videosRoot)) {
|
||||
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($videosRoot));
|
||||
foreach ($rii as $file) {
|
||||
if ($file->isFile()) {
|
||||
$ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
|
||||
if (in_array($ext, ['mp4','webm','mov'])) {
|
||||
// 构造相对URL供前端播放
|
||||
$rel = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $file->getPathname()));
|
||||
$local[] = [
|
||||
'url' => $rel,
|
||||
'title' => '本地:' . $file->getFilename()
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
// 本地视频顺序随机并裁剪到指定数量
|
||||
if (count($local) > 1) { shuffle($local); }
|
||||
if ($localCount > 0 && count($local) > $localCount) {
|
||||
$local = array_slice($local, 0, $localCount);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并/回退策略:
|
||||
// 1) 远程成功:
|
||||
// - 如果开启本地,则远程+本地合并并整体随机
|
||||
// - 如果未开启本地,则仅远程
|
||||
// 2) 远程失败:
|
||||
// - 若本地有内容,则仅返回本地随机列表(忽略开关)
|
||||
$list = [];
|
||||
if (!empty($remote)) {
|
||||
$list = $includeLocal ? array_merge($remote, $local) : $remote;
|
||||
if (count($list) > 1 && ($includeLocal || $random)) { shuffle($list); }
|
||||
} else if (!empty($local)) {
|
||||
$list = $local; // 远程不可用时,回退到全部本地随机
|
||||
}
|
||||
|
||||
// 如果仍为空,提供一个后备示例
|
||||
if (empty($list)) {
|
||||
$list[] = [
|
||||
'url' => 'https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4',
|
||||
'title' => '示例视频'
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode(['list' => $list], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
348
assets/script.js
Normal file
348
assets/script.js
Normal file
@@ -0,0 +1,348 @@
|
||||
// 外部脚本文件:轻量的菜单高亮逻辑与占位
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// 菜单点击激活态
|
||||
const links = Array.from(document.querySelectorAll('.menu__link'));
|
||||
links.forEach(link => {
|
||||
link.addEventListener('click', () => {
|
||||
links.forEach(l => l.classList.remove('is-active'));
|
||||
link.classList.add('is-active');
|
||||
});
|
||||
});
|
||||
|
||||
// ===== 视频逻辑 =====
|
||||
const player = document.getElementById('player');
|
||||
const videoWrap = document.getElementById('videoWrap');
|
||||
const videoPanel = document.getElementById('video');
|
||||
const includeLocalToggle = document.getElementById('includeLocalToggle');
|
||||
// 底部工具栏与标题已移除,无需获取相关元素
|
||||
|
||||
if (!player || !videoWrap) return; // 仅在视频区存在时执行
|
||||
|
||||
let playlist = [];
|
||||
let index = 0;
|
||||
let includeLocal = includeLocalToggle ? includeLocalToggle.checked : false;
|
||||
const BUFFER_SIZE = 3; // 预缓存条数
|
||||
|
||||
const loadVideo = (i, autoPlay = false) => {
|
||||
if (!playlist.length) return;
|
||||
index = (i + playlist.length) % playlist.length;
|
||||
const item = playlist[index];
|
||||
player.src = item.url;
|
||||
// 已移除标题展示,无需设置文本
|
||||
player.load();
|
||||
if (videoPanel) videoPanel.style.setProperty('--progress', '0');
|
||||
if (autoPlay) {
|
||||
player.play().catch(() => {});
|
||||
}
|
||||
};
|
||||
|
||||
// 按需拉取一条或多条新视频
|
||||
const fetchOne = async (n = 1) => {
|
||||
try {
|
||||
const url = `api/videos.php?count=${n}&include_local=${includeLocal ? 1 : 0}&local_count=${n}`;
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
const items = Array.isArray(data.list) ? data.list : [];
|
||||
if (items.length) {
|
||||
const existing = new Set(playlist.map(i => i.url));
|
||||
const append = items.filter(it => it && it.url && !existing.has(it.url));
|
||||
playlist = playlist.concat(append);
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略错误
|
||||
}
|
||||
};
|
||||
|
||||
const ensureBuffer = async () => {
|
||||
const ahead = playlist.length - index - 1;
|
||||
if (ahead < BUFFER_SIZE) {
|
||||
await fetchOne(BUFFER_SIZE - ahead);
|
||||
}
|
||||
};
|
||||
|
||||
const next = async () => {
|
||||
await ensureBuffer();
|
||||
if (index + 1 < playlist.length) {
|
||||
loadVideo(index + 1, true);
|
||||
} else if (!playlist.length) {
|
||||
// 仍无数据,尝试拉取
|
||||
await fetchOne(BUFFER_SIZE + 1);
|
||||
if (playlist.length) loadVideo(0, true);
|
||||
}
|
||||
};
|
||||
const prev = async () => {
|
||||
if (index - 1 >= 0) {
|
||||
loadVideo(index - 1, true);
|
||||
}
|
||||
};
|
||||
|
||||
// 鼠标移入显示并播放,移出隐藏并暂停
|
||||
const showVideo = () => {
|
||||
player.classList.add('visible');
|
||||
player.play().catch(() => {});
|
||||
// 用户首次交互后取消静音(可选)
|
||||
if (player.muted) player.muted = false;
|
||||
};
|
||||
const hideVideo = () => {
|
||||
player.pause();
|
||||
player.classList.remove('visible');
|
||||
// 可选:player.currentTime = 0; // 回到开头
|
||||
};
|
||||
videoWrap.addEventListener('mouseenter', showVideo);
|
||||
videoWrap.addEventListener('mouseleave', hideVideo);
|
||||
|
||||
// 页面加载时若鼠标已在视频区域,立即显示
|
||||
if (videoWrap.matches(':hover')) showVideo();
|
||||
|
||||
// 单击下一条,双击上一条(去抖处理)
|
||||
// 按最新需求:不再点击视频进入投稿,而是点击菜单栏“视频”进入投稿
|
||||
let clickTimer = null;
|
||||
videoWrap.addEventListener('click', () => {
|
||||
if (clickTimer) return;
|
||||
clickTimer = setTimeout(() => {
|
||||
clickTimer = null;
|
||||
next();
|
||||
}, 250);
|
||||
});
|
||||
videoWrap.addEventListener('dblclick', () => {
|
||||
if (clickTimer) {
|
||||
clearTimeout(clickTimer);
|
||||
clickTimer = null;
|
||||
}
|
||||
prev();
|
||||
});
|
||||
|
||||
// 自动保存:播放到一半时保存(每个视频仅保存一次)
|
||||
const savedURLs = new Set();
|
||||
const trySaveOnHalf = async () => {
|
||||
const item = playlist[index];
|
||||
if (!item) return;
|
||||
// 本地视频不入库(URL非http/https时跳过保存)
|
||||
if (!/^https?:\/\//i.test(item.url || '')) return;
|
||||
const d = player.duration;
|
||||
const t = player.currentTime;
|
||||
if (!isFinite(d) || d <= 0) return; // 元数据未就绪
|
||||
const reachedHalf = t / d >= 0.5;
|
||||
if (!reachedHalf || savedURLs.has(item.url)) return;
|
||||
try {
|
||||
const res = await fetch('api/save_video.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: item.url, title: item.title || '' }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data && data.success) {
|
||||
savedURLs.add(item.url);
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略保存错误,不影响播放
|
||||
}
|
||||
};
|
||||
player.addEventListener('timeupdate', trySaveOnHalf);
|
||||
player.addEventListener('timeupdate', () => {
|
||||
const d = player.duration;
|
||||
const t = player.currentTime;
|
||||
if (!isFinite(d) || d <= 0) return;
|
||||
const p = Math.max(0, Math.min(1, t / d));
|
||||
if (videoPanel) videoPanel.style.setProperty('--progress', String(p * 360));
|
||||
});
|
||||
|
||||
// 播放结束自动下一条
|
||||
player.addEventListener('ended', () => { next(); });
|
||||
|
||||
// 从后端接口获取视频列表
|
||||
// 初始化:先拉取首条并填充缓存
|
||||
(async () => {
|
||||
await fetchOne(BUFFER_SIZE + 1);
|
||||
if (!playlist.length) {
|
||||
// 无视频可用
|
||||
return;
|
||||
}
|
||||
loadVideo(0, false);
|
||||
// 启动缓冲确保后续播放连续
|
||||
await ensureBuffer();
|
||||
})();
|
||||
|
||||
// 切换本地视频开关:重置播放列表并重新拉取
|
||||
if (includeLocalToggle) {
|
||||
includeLocalToggle.addEventListener('change', async () => {
|
||||
includeLocal = includeLocalToggle.checked;
|
||||
// 重置播放列表
|
||||
playlist = [];
|
||||
index = 0;
|
||||
await fetchOne(BUFFER_SIZE + 1);
|
||||
if (playlist.length) {
|
||||
loadVideo(0, false);
|
||||
await ensureBuffer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 讨论区气泡逻辑 =====
|
||||
const discussionWrap = document.getElementById('discussionWrap');
|
||||
if (discussionWrap) {
|
||||
const fetchAvatar = async () => {
|
||||
try {
|
||||
const r = await fetch('api/head.php');
|
||||
const j = await r.json();
|
||||
return j.url || '';
|
||||
} catch { return ''; }
|
||||
};
|
||||
const fetchText = async () => {
|
||||
try {
|
||||
const r = await fetch('api/text.php'); // 随机来源
|
||||
const j = await r.json();
|
||||
return { text: j.text || '', source: j.source || '' };
|
||||
} catch { return { text: '', source: '' }; }
|
||||
};
|
||||
|
||||
const createBubble = (avatarUrl, text, side = Math.random() < 0.5 ? 'left' : 'right') => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'bubble' + (side === 'right' ? ' right' : '');
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.className = 'avatar';
|
||||
img.src = avatarUrl || 'https://images.unsplash.com/photo-1547425260-76bcadfb4f9b?w=200&h=200&fit=crop';
|
||||
img.alt = '头像';
|
||||
|
||||
const textEl = document.createElement('div');
|
||||
textEl.className = 'bubble__text';
|
||||
textEl.textContent = text || '...';
|
||||
|
||||
item.appendChild(img);
|
||||
item.appendChild(textEl);
|
||||
discussionWrap.appendChild(item);
|
||||
// 滚动到底部
|
||||
discussionWrap.scrollTop = discussionWrap.scrollHeight;
|
||||
|
||||
// 控制条数最多50条
|
||||
const nodes = discussionWrap.querySelectorAll('.bubble');
|
||||
if (nodes.length > 50) {
|
||||
for (let i = 0; i < nodes.length - 50; i++) {
|
||||
discussionWrap.removeChild(nodes[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const savedAvatars = new Set();
|
||||
const savedTexts = new Set();
|
||||
|
||||
const spawn = async () => {
|
||||
const [avatar, textResp] = await Promise.all([fetchAvatar(), fetchText()]);
|
||||
const text = textResp.text;
|
||||
const source = textResp.source;
|
||||
createBubble(avatar, text);
|
||||
// 保存到本地,避免重复
|
||||
try {
|
||||
// 仅保存远程头像(http/https),本地相对路径跳过
|
||||
if (avatar && /^https?:\/\//i.test(avatar) && !savedAvatars.has(avatar)) {
|
||||
savedAvatars.add(avatar);
|
||||
await fetch('api/save_avatar.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url: avatar })
|
||||
});
|
||||
}
|
||||
} catch {}
|
||||
try {
|
||||
const key = text.trim();
|
||||
if (key && !savedTexts.has(key)) {
|
||||
savedTexts.add(key);
|
||||
await fetch('api/save_text.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text: key, source })
|
||||
});
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
// 立即生成一个,然后每5秒生成一次(可在此处调整间隔)
|
||||
spawn();
|
||||
setInterval(spawn, 5000);
|
||||
}
|
||||
|
||||
// ===== 图片区逻辑(淡进淡出,10s刷新,自动保存不清理) =====
|
||||
const pictureWrap = document.getElementById('pictureWrap');
|
||||
const pictureImg = document.getElementById('pictureImg');
|
||||
const galleryPanel = document.getElementById('gallery');
|
||||
if (pictureWrap && pictureImg) {
|
||||
const sources = ['heisi', 'wapmeinvpic', 'baisi', 'meinvpic'];
|
||||
const savedPics = new Set();
|
||||
|
||||
const fetchPicture = async () => {
|
||||
const type = sources[Math.floor(Math.random() * sources.length)];
|
||||
try {
|
||||
const r = await fetch(`api/picture.php?type=${encodeURIComponent(type)}`);
|
||||
const j = await r.json();
|
||||
return { url: j.url || '', source: j.source || type };
|
||||
} catch {
|
||||
return { url: '', source: type };
|
||||
}
|
||||
};
|
||||
|
||||
const showPicture = async () => {
|
||||
// 先淡出
|
||||
pictureImg.classList.remove('visible');
|
||||
const { url, source } = await fetchPicture();
|
||||
if (!url) return; // 拉取失败时跳过本次
|
||||
// 等图片加载完成后再淡入
|
||||
await new Promise(resolve => {
|
||||
pictureImg.onload = () => { resolve(); };
|
||||
pictureImg.onerror = () => { resolve(); };
|
||||
pictureImg.src = url;
|
||||
});
|
||||
// 加载完成但不再自动显示,仅悬停时显示
|
||||
|
||||
// 自动保存(避免重复),后端不做清理
|
||||
try {
|
||||
// 仅保存远程图片(http/https),本地相对路径跳过
|
||||
if (/^https?:\/\//i.test(url) && !savedPics.has(url)) {
|
||||
savedPics.add(url);
|
||||
await fetch('api/save_picture.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url })
|
||||
});
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
|
||||
// 悬停显隐
|
||||
const showPic = () => pictureImg.classList.add('visible');
|
||||
const hidePic = () => pictureImg.classList.remove('visible');
|
||||
pictureWrap.addEventListener('mouseenter', showPic);
|
||||
pictureWrap.addEventListener('mouseleave', hidePic);
|
||||
|
||||
// 页面加载时若鼠标已在图片区域,立即显示
|
||||
if (pictureWrap.matches(':hover')) showPic();
|
||||
|
||||
let picIntervalMs = 10000;
|
||||
let picLastSwap = Date.now();
|
||||
const updatePicProgress = () => {
|
||||
const elapsed = Date.now() - picLastSwap;
|
||||
const p = Math.max(0, Math.min(1, elapsed / picIntervalMs));
|
||||
if (galleryPanel) galleryPanel.style.setProperty('--pic-progress', String(p * 360));
|
||||
requestAnimationFrame(updatePicProgress);
|
||||
};
|
||||
requestAnimationFrame(updatePicProgress);
|
||||
|
||||
(async () => {
|
||||
const { url } = await fetchPicture();
|
||||
if (url) {
|
||||
pictureImg.src = url;
|
||||
picLastSwap = Date.now();
|
||||
if (galleryPanel) galleryPanel.style.setProperty('--pic-progress', '0');
|
||||
if (pictureWrap.matches(':hover')) showPic();
|
||||
}
|
||||
})();
|
||||
setInterval(async () => {
|
||||
const { url } = await fetchPicture();
|
||||
if (url) {
|
||||
pictureImg.src = url;
|
||||
picLastSwap = Date.now();
|
||||
if (galleryPanel) galleryPanel.style.setProperty('--pic-progress', '0');
|
||||
if (pictureWrap.matches(':hover')) showPic();
|
||||
}
|
||||
}, picIntervalMs);
|
||||
}
|
||||
});
|
||||
440
assets/style.css
Normal file
440
assets/style.css
Normal file
@@ -0,0 +1,440 @@
|
||||
/* 外部样式文件:从 index.php 迁移而来 */
|
||||
:root {
|
||||
--red: #e32626;
|
||||
--border: 2px solid var(--red);
|
||||
--gap: 32px;
|
||||
--page-max: 1200px;
|
||||
--radius: 6px;
|
||||
--shadow: 0 6px 14px rgba(226, 38, 38, 0.08);
|
||||
--shadow-hover: 0 8px 20px rgba(226, 38, 38, 0.12);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
||||
'Helvetica Neue', Arial, 'Noto Sans', 'PingFang SC', 'Microsoft YaHei',
|
||||
sans-serif;
|
||||
color: #333;
|
||||
background:
|
||||
radial-gradient(1200px 400px at 10% -20%, #fff5f5 0%, transparent 40%),
|
||||
linear-gradient(#ffffff, #ffffff);
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width: var(--page-max);
|
||||
padding: 16px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* 顶部菜单条 */
|
||||
.menu {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
border: var(--border);
|
||||
background: #fff;
|
||||
min-height: 60px;
|
||||
padding: 10px 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: var(--gap);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 24px rgba(226, 38, 38, 0.08);
|
||||
}
|
||||
|
||||
.menu__logo {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: var(--red);
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.menu__nav {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.menu__link {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
color: var(--red);
|
||||
padding: 8px 14px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--red);
|
||||
background: #fff;
|
||||
transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.menu__link:hover,
|
||||
.menu__link:focus-visible {
|
||||
background: #fff1f1;
|
||||
outline: none;
|
||||
box-shadow: 0 6px 14px rgba(226, 38, 38, 0.15);
|
||||
}
|
||||
|
||||
.menu__link.is-active {
|
||||
background: var(--red);
|
||||
color: #fff;
|
||||
border-color: var(--red);
|
||||
box-shadow: 0 6px 14px rgba(226, 38, 38, 0.18);
|
||||
}
|
||||
|
||||
/* 三列区域 */
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: clamp(180px, 22%, 240px) 1fr clamp(220px, 26%, 300px);
|
||||
gap: var(--gap);
|
||||
}
|
||||
|
||||
.panel {
|
||||
border: var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: #fff;
|
||||
min-height: 380px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
color: var(--red);
|
||||
text-align: center;
|
||||
box-shadow: var(--shadow);
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
.panel:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--shadow-hover);
|
||||
}
|
||||
|
||||
/* 讨论区固定高度并使用内部滚动,不让页面无限增长 */
|
||||
#discussion.panel {
|
||||
align-items: stretch;
|
||||
justify-content: flex-start;
|
||||
height: 380px; /* 与其他面板保持一致高度 */
|
||||
}
|
||||
|
||||
.panel:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 14px 28px rgba(226, 38, 38, 0.1);
|
||||
}
|
||||
|
||||
/* 响应式:窄屏改为纵向排列 */
|
||||
@media (max-width: 992px) {
|
||||
.content { grid-template-columns: 1fr; }
|
||||
.panel { min-height: 220px; }
|
||||
#discussion.panel { height: 240px; }
|
||||
}
|
||||
|
||||
/* ===== 视频区域样式 ===== */
|
||||
.video-wrap {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 4px; /* 边距缩小,减少白边 */
|
||||
}
|
||||
|
||||
#video.panel { position: relative; }
|
||||
#video.panel::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
padding: 2px;
|
||||
border-radius: var(--radius);
|
||||
background: conic-gradient(
|
||||
var(--red) 0deg,
|
||||
var(--red) calc(var(--progress, 0) * 1deg),
|
||||
rgba(226, 38, 38, 0.18) calc(var(--progress, 0) * 1deg),
|
||||
rgba(226, 38, 38, 0.18) 360deg
|
||||
);
|
||||
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
-webkit-mask-composite: xor;
|
||||
mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
mask-composite: exclude;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* 视频面板固定高度,独立于图片面板的高度变化 */
|
||||
#video.panel { align-items: stretch; justify-content: flex-start; height: 380px; overflow: hidden; }
|
||||
|
||||
/* 菜单栏中的“包含本地”控件样式 */
|
||||
.menu__controls {
|
||||
background: #f6f6f6;
|
||||
border: 1px solid var(--red);
|
||||
color: var(--red);
|
||||
padding: 6px 12px;
|
||||
border-radius: 999px;
|
||||
font-size: 13px;
|
||||
box-shadow: 0 6px 14px rgba(226, 38, 38, 0.08);
|
||||
user-select: none;
|
||||
}
|
||||
.menu__controls input[type="checkbox"] { vertical-align: middle; margin-right: 6px; }
|
||||
|
||||
video#player {
|
||||
width: 100%;
|
||||
flex: 1 1 auto;
|
||||
height: 100%; /* 使视频充满可用高度,被“框”包裹 */
|
||||
display: block;
|
||||
border-radius: 6px; /* 圆角减小,进一步减少四角的白边显著程度 */
|
||||
background: #000;
|
||||
object-fit: contain; /* 保持原视频比例 */
|
||||
opacity: 0;
|
||||
transition: opacity 0.8s ease-in-out;
|
||||
}
|
||||
video#player.visible { opacity: 1; }
|
||||
|
||||
/* 顶部提示气泡已移除 */
|
||||
|
||||
/* 工具栏与按钮已移除,根据用户需求隐藏相关样式占位 */
|
||||
|
||||
/* ===== 讨论区样式 ===== */
|
||||
.discussion-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--red) #fff1f1; /* 滑块红 / 轨道浅红 */
|
||||
}
|
||||
/* Webkit 内核滚动条 */
|
||||
.discussion-wrap::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
.discussion-wrap::-webkit-scrollbar-track {
|
||||
background: #fff1f1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.discussion-wrap::-webkit-scrollbar-thumb {
|
||||
background: var(--red);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.discussion-wrap::-webkit-scrollbar-thumb:hover {
|
||||
background: #c53030;
|
||||
}
|
||||
|
||||
.bubble {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
max-width: 92%;
|
||||
animation: fadeIn 0.25s ease;
|
||||
}
|
||||
.bubble.right { flex-direction: row-reverse; margin-left: auto; }
|
||||
|
||||
.avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
flex: 0 0 36px;
|
||||
object-fit: cover;
|
||||
border: 2px solid var(--red);
|
||||
}
|
||||
|
||||
.bubble__text {
|
||||
background: #fff1f1;
|
||||
border: 1px solid var(--red);
|
||||
color: #a81515;
|
||||
padding: 8px 12px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 14px rgba(226, 38, 38, 0.08);
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(6px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
/* ===== 图片区域样式 ===== */
|
||||
#gallery.panel { align-items: stretch; justify-content: flex-start; position: relative; }
|
||||
#gallery.panel::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
padding: 2px;
|
||||
border-radius: var(--radius);
|
||||
background: conic-gradient(
|
||||
var(--red) 0deg,
|
||||
var(--red) calc(var(--pic-progress, 0) * 1deg),
|
||||
rgba(226, 38, 38, 0.18) calc(var(--pic-progress, 0) * 1deg),
|
||||
rgba(226, 38, 38, 0.18) 360deg
|
||||
);
|
||||
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
-webkit-mask-composite: xor;
|
||||
mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
mask-composite: exclude;
|
||||
pointer-events: none;
|
||||
}
|
||||
.picture-wrap {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 4px; /* 同步减少图片区的白边 */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#pictureImg {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 6px; /* 圆角减小以减少角部白边 */
|
||||
box-shadow: 0 10px 22px rgba(226, 38, 38, 0.08);
|
||||
opacity: 0;
|
||||
transition: opacity 0.8s ease-in-out;
|
||||
}
|
||||
#pictureImg.visible { opacity: 1; }
|
||||
|
||||
@media (max-width: 992px) {
|
||||
#gallery.panel { height: 240px; }
|
||||
#video.panel { height: 240px; }
|
||||
}
|
||||
|
||||
/* 移除对视频框悬停效果的覆盖,恢复默认面板的上浮动画 */
|
||||
|
||||
/* ===== 投稿(上传)页面通用样式 ===== */
|
||||
.upload-container {
|
||||
max-width: 980px;
|
||||
margin: 24px auto;
|
||||
padding: 0 16px;
|
||||
}
|
||||
.upload-container h1 {
|
||||
font-size: 20px;
|
||||
color: var(--red);
|
||||
margin: 0 0 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.upload-title {
|
||||
margin: 0 0 16px;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.upload-grid.two {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.upload-grid.video {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 360px;
|
||||
gap: 16px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
@media (max-width: 880px) {
|
||||
.upload-grid.two { grid-template-columns: 1fr; }
|
||||
.upload-grid.video { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.card {
|
||||
border: var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 16px;
|
||||
background: #fff;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.dropzone {
|
||||
border: 2px dashed var(--red);
|
||||
border-radius: var(--radius);
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
background: #fff1f1;
|
||||
color: var(--red);
|
||||
cursor: pointer;
|
||||
box-shadow: var(--shadow);
|
||||
transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
}
|
||||
.dropzone.dragging,
|
||||
.dropzone:hover { background: #ffeaea; border-color: #c11; box-shadow: var(--shadow-hover); }
|
||||
|
||||
.field { display: flex; flex-direction: column; gap: 8px; }
|
||||
.field input[type="text"] {
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--red);
|
||||
border-radius: var(--radius);
|
||||
font-size: 14px;
|
||||
transition: border-color .2s ease;
|
||||
}
|
||||
.field input[type="text"]:focus {
|
||||
border-color: #c53030;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.preview-img {
|
||||
width: 100%;
|
||||
height: 280px;
|
||||
object-fit: contain;
|
||||
border: 1px solid var(--red);
|
||||
border-radius: var(--radius);
|
||||
background: #fafafa;
|
||||
}
|
||||
.video-preview {
|
||||
width: 100%;
|
||||
height: 220px;
|
||||
object-fit: contain;
|
||||
border-radius: var(--radius);
|
||||
background: #000;
|
||||
}
|
||||
.meta {
|
||||
font-size: 12px;
|
||||
color: var(--red);
|
||||
margin-top: 8px;
|
||||
}
|
||||
.errors { color: var(--red); font-size: 13px; min-height: 18px; }
|
||||
.tips { color: var(--red); opacity: .8; font-size: 13px; }
|
||||
|
||||
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
|
||||
|
||||
.btn {
|
||||
background: linear-gradient(135deg, var(--red) 0%, #c53030 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 10px 18px;
|
||||
border-radius: var(--radius);
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: opacity .25s ease, transform .2s ease;
|
||||
}
|
||||
.btn:hover {
|
||||
opacity: .92;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.btn[disabled] {
|
||||
opacity: .5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
color: var(--red);
|
||||
padding: 8px 14px;
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid var(--red);
|
||||
background: #fff;
|
||||
font-size: 14px;
|
||||
transition: background .25s ease, transform .2s ease;
|
||||
}
|
||||
.btn-ghost:hover {
|
||||
background: #fff1f1;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.hidden-input { position: absolute; left: -9999px; }
|
||||
192
index.php
Normal file
192
index.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>摸鱼办</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<script defer src="assets/script.js"></script>
|
||||
<style>
|
||||
:root {
|
||||
--red: #e32626;
|
||||
--border: 2px solid var(--red);
|
||||
--gap: 32px;
|
||||
--page-max: 1200px;
|
||||
--radius: 14px;
|
||||
--card-bg: #ffffff;
|
||||
--text: #2b2b2b;
|
||||
--soft-red: #fff1f1;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
||||
'Helvetica Neue', Arial, 'Noto Sans', 'PingFang SC', 'Microsoft YaHei',
|
||||
sans-serif;
|
||||
color: var(--text);
|
||||
background:
|
||||
radial-gradient(1200px 400px at 10% -20%, #fff5f5 0%, transparent 40%),
|
||||
linear-gradient(#ffffff, #ffffff);
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width: var(--page-max);
|
||||
padding: 16px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* 顶部菜单条 */
|
||||
.menu {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
border: var(--border);
|
||||
background: var(--card-bg);
|
||||
min-height: 60px;
|
||||
padding: 10px 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: var(--gap);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 10px 24px rgba(226, 38, 38, 0.08);
|
||||
backdrop-filter: saturate(180%) blur(6px);
|
||||
}
|
||||
|
||||
.menu__logo {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
color: var(--red);
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.menu__logo::before {
|
||||
content: "★";
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
color: #fff;
|
||||
background: var(--red);
|
||||
border-radius: 6px;
|
||||
margin-right: 6px;
|
||||
box-shadow: 0 4px 10px rgba(230, 38, 38, 0.35);
|
||||
}
|
||||
|
||||
.menu__nav {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.menu__link {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
color: var(--red);
|
||||
padding: 8px 14px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--red);
|
||||
background: #fff;
|
||||
transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.menu__link:hover,
|
||||
.menu__link:focus-visible {
|
||||
background: #fff1f1;
|
||||
outline: none;
|
||||
box-shadow: 0 6px 14px rgba(226, 38, 38, 0.15);
|
||||
}
|
||||
|
||||
.menu__link.is-active {
|
||||
background: var(--red);
|
||||
color: #fff;
|
||||
border-color: var(--red);
|
||||
box-shadow: 0 6px 14px rgba(226, 38, 38, 0.18);
|
||||
}
|
||||
|
||||
/* 三列区域 */
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: clamp(180px, 22%, 240px) 1fr clamp(220px, 26%, 300px);
|
||||
gap: var(--gap);
|
||||
}
|
||||
|
||||
.panel {
|
||||
border: var(--border);
|
||||
border-radius: calc(var(--radius) + 2px);
|
||||
background: var(--card-bg);
|
||||
min-height: 380px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 22px;
|
||||
color: var(--red);
|
||||
text-align: center;
|
||||
box-shadow: 0 10px 22px rgba(226, 38, 38, 0.06);
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.panel__title {
|
||||
font-size: 22px;
|
||||
color: var(--red);
|
||||
margin: 0;
|
||||
letter-spacing: 0.8px;
|
||||
}
|
||||
|
||||
.panel:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 14px 28px rgba(226, 38, 38, 0.1);
|
||||
}
|
||||
|
||||
/* 响应式:窄屏改为纵向排列 */
|
||||
@media (max-width: 992px) {
|
||||
.content { grid-template-columns: 1fr; }
|
||||
.panel { min-height: 220px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">菜单</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">首页</a></li>
|
||||
<li><a class="menu__link" href="upload.php">视频</a></li>
|
||||
<li><a class="menu__link is-active" href="upload_text.php">讨论</a></li>
|
||||
<li><a class="menu__link" href="upload_picture.php">图片</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="menu__controls" title="包含本地已保存视频到播放列表">
|
||||
<label>
|
||||
<input type="checkbox" id="includeLocalToggle" /> 包含本地
|
||||
</label>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<section class="panel" id="video" aria-label="视频区域">
|
||||
<div class="video-wrap" id="videoWrap">
|
||||
<video id="player" preload="metadata" playsinline muted></video>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel" id="discussion" aria-label="讨论区域">
|
||||
<div class="discussion-wrap" id="discussionWrap" aria-live="polite" aria-label="讨论消息列表"></div>
|
||||
</section>
|
||||
<section class="panel" id="gallery" aria-label="图片区域">
|
||||
<div class="picture-wrap" id="pictureWrap" aria-label="自动刷新图片区">
|
||||
<img id="pictureImg" alt="图片" />
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
<!-- 说明:当前为样式占位版本,内容与交互暂未实现。 -->
|
||||
</html>
|
||||
174
review.php
Normal file
174
review.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
// 管理员审核页面:查看 videos_pending 中的文件,执行通过/拒绝
|
||||
session_start();
|
||||
|
||||
$ADMIN_PASSWORD = 'my123123';
|
||||
|
||||
// 退出登录
|
||||
if (isset($_GET['logout'])) {
|
||||
unset($_SESSION['admin_ok']);
|
||||
header('Location: review.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 登录处理
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
|
||||
$pwd = trim($_POST['password'] ?? '');
|
||||
if ($pwd === $ADMIN_PASSWORD) {
|
||||
$_SESSION['admin_ok'] = true;
|
||||
header('Location: review.php');
|
||||
exit;
|
||||
} else {
|
||||
$login_error = '密码错误,请重试';
|
||||
}
|
||||
}
|
||||
|
||||
// 若未登录,显示登录界面
|
||||
if (empty($_SESSION['admin_ok'])) {
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>管理员登录</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.login-card { max-width: 480px; margin: 60px auto; border:2px solid #e33; border-radius:12px; padding:20px; background:#fff; }
|
||||
.login-card h1 { margin:0 0 12px; font-size:20px; }
|
||||
.login-card .field { display:flex; flex-direction:column; gap:8px; }
|
||||
.login-card input { padding:10px 12px; border:1px solid #ddd; border-radius:8px; }
|
||||
.login-card .btn { background:#e33; color:#fff; border:none; padding:10px 18px; border-radius:22px; cursor:pointer; }
|
||||
.login-card .err { color:#c00; font-size:13px; margin-top:8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">审核登录</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="login-card" aria-label="管理员登录">
|
||||
<h1>请输入管理员密码</h1>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<label for="password">密码</label>
|
||||
<input id="password" name="password" type="password" placeholder="输入管理员密码" required />
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<button class="btn" type="submit">登录</button>
|
||||
</div>
|
||||
<?php if (!empty($login_error)): ?>
|
||||
<div class="err"><?php echo htmlspecialchars($login_error); ?></div>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
|
||||
$pendingDir = __DIR__ . '/videos_pending';
|
||||
$files = [];
|
||||
if (is_dir($pendingDir)) {
|
||||
foreach (scandir($pendingDir) as $f) {
|
||||
if ($f === '.' || $f === '..') continue;
|
||||
if (preg_match('/\.(mp4|webm|mov)$/i', $f)) {
|
||||
$files[] = $f;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>视频审核</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.review-page { max-width: 1100px; margin: 24px auto; }
|
||||
.review-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
|
||||
.pwd-box { display:flex; gap:8px; align-items:center; }
|
||||
.pwd-box input { padding:6px 8px; border:1px solid #ddd; border-radius:6px; }
|
||||
.list { display:grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap:12px; }
|
||||
.card { border:2px solid #e33; border-radius:10px; padding:8px; background:#fff; }
|
||||
.card video { width:100%; height:180px; object-fit:cover; border-radius:6px; }
|
||||
.card .meta { font-size: 12px; color:#666; margin-top:6px; }
|
||||
.actions { display:flex; gap:8px; margin-top:8px; }
|
||||
.btn { padding:6px 12px; border:none; border-radius:16px; cursor:pointer; }
|
||||
.btn.approve { background:#2ebd59; color:#fff; }
|
||||
.btn.reject { background:#999; color:#fff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page review-page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">审核</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="review-head">
|
||||
<h1 style="margin:0;font-size:18px;">待审核列表(<?php echo count($files); ?>)</h1>
|
||||
<div class="pwd-box">
|
||||
<a class="menu__link" href="review.php?logout=1">退出登录</a>
|
||||
</div>
|
||||
</div>
|
||||
<section class="list" id="pendingList">
|
||||
<?php if (!$files): ?>
|
||||
<p>当前无待审核视频。</p>
|
||||
<?php else: foreach ($files as $f):
|
||||
$metaPath = $pendingDir . '/' . $f . '.json';
|
||||
$meta = is_file($metaPath) ? json_decode(@file_get_contents($metaPath), true) : [];
|
||||
?>
|
||||
<div class="card" data-file="<?php echo htmlspecialchars($f); ?>">
|
||||
<video src="<?php echo 'videos_pending/' . htmlspecialchars($f); ?>" controls></video>
|
||||
<div class="meta">
|
||||
<div>文件:<?php echo htmlspecialchars($f); ?></div>
|
||||
<?php if (!empty($meta['original_name'])): ?><div>原名:<?php echo htmlspecialchars($meta['original_name']); ?></div><?php endif; ?>
|
||||
<?php if (!empty($meta['title'])): ?><div>标题:<?php echo htmlspecialchars($meta['title']); ?></div><?php endif; ?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn approve">通过</button>
|
||||
<button class="btn reject">拒绝</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
<script>
|
||||
const list = document.getElementById('pendingList');
|
||||
function send(action, file, password) {
|
||||
const fd = new FormData();
|
||||
fd.append('action', action);
|
||||
fd.append('file', file);
|
||||
fd.append('password', password);
|
||||
return fetch('api/review_action.php', { method: 'POST', body: fd }).then(r=>r.json());
|
||||
}
|
||||
list?.addEventListener('click', async (e) => {
|
||||
const btn = e.target.closest('button');
|
||||
if (!btn) return;
|
||||
const card = e.target.closest('.card');
|
||||
const file = card?.dataset?.file;
|
||||
if (!file) return;
|
||||
const action = btn.classList.contains('approve') ? 'approve' : 'reject';
|
||||
btn.disabled = true;
|
||||
const res = await send(action, file, '').catch(()=>({ok:false,msg:'请求失败'}));
|
||||
btn.disabled = false;
|
||||
alert(res.msg || '操作完成');
|
||||
if (res.ok) {
|
||||
card.remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
172
review_pictures.php
Normal file
172
review_pictures.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
// 图片审核页面:查看 pictures_pending 中的文件,执行通过/拒绝
|
||||
session_start();
|
||||
|
||||
$ADMIN_PASSWORD = 'my123123';
|
||||
|
||||
// 退出登录
|
||||
if (isset($_GET['logout'])) {
|
||||
unset($_SESSION['admin_ok']);
|
||||
header('Location: review_pictures.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 登录处理
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
|
||||
$pwd = trim($_POST['password'] ?? '');
|
||||
if ($pwd === $ADMIN_PASSWORD) {
|
||||
$_SESSION['admin_ok'] = true;
|
||||
header('Location: review_pictures.php');
|
||||
exit;
|
||||
} else {
|
||||
$login_error = '密码错误,请重试';
|
||||
}
|
||||
}
|
||||
|
||||
// 若未登录,显示登录界面
|
||||
if (empty($_SESSION['admin_ok'])) {
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>管理员登录 - 图片审核</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.login-card { max-width: 480px; margin: 60px auto; border:2px solid #e33; border-radius:12px; padding:20px; background:#fff; }
|
||||
.login-card h1 { margin:0 0 12px; font-size:20px; }
|
||||
.login-card .field { display:flex; flex-direction:column; gap:8px; }
|
||||
.login-card input { padding:10px 12px; border:1px solid #ddd; border-radius:8px; }
|
||||
.login-card .btn { background:#e33; color:#fff; border:none; padding:10px 18px; border-radius:22px; cursor:pointer; }
|
||||
.login-card .err { color:#c00; font-size:13px; margin-top:8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">审核登录</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="login-card" aria-label="管理员登录">
|
||||
<h1>请输入管理员密码</h1>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<label for="password">密码</label>
|
||||
<input id="password" name="password" type="password" placeholder="输入管理员密码" required />
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<button class="btn" type="submit">登录</button>
|
||||
</div>
|
||||
<?php if (!empty($login_error)): ?>
|
||||
<div class="err"><?php echo htmlspecialchars($login_error); ?></div>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
|
||||
$pendingDir = __DIR__ . '/pictures_pending';
|
||||
$files = [];
|
||||
if (is_dir($pendingDir)) {
|
||||
foreach (scandir($pendingDir) as $f) {
|
||||
if ($f === '.' || $f === '..') continue;
|
||||
if (preg_match('/\.(jpg|jpeg|png|gif|webp)$/i', $f)) {
|
||||
$files[] = $f;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>图片审核</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.review-page { max-width: 1100px; margin: 24px auto; }
|
||||
.review-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
|
||||
.list { display:grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap:12px; }
|
||||
.card { border:2px solid #e33; border-radius:10px; padding:8px; background:#fff; }
|
||||
.card img { width:100%; height:220px; object-fit:contain; border-radius:6px; background:#fafafa; }
|
||||
.card .meta { font-size: 12px; color:#666; margin-top:6px; }
|
||||
.actions { display:flex; gap:8px; margin-top:8px; }
|
||||
.btn { padding:6px 12px; border:none; border-radius:16px; cursor:pointer; }
|
||||
.btn.approve { background:#2ebd59; color:#fff; }
|
||||
.btn.reject { background:#999; color:#fff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page review-page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">图片审核</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
<li><a class="menu__link" href="review_pictures.php?logout=1">退出登录</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="review-head">
|
||||
<h1 style="margin:0;font-size:18px;">待审核图片(<?php echo count($files); ?>)</h1>
|
||||
</div>
|
||||
<section class="list" id="pendingList">
|
||||
<?php if (!$files): ?>
|
||||
<p>当前无待审核图片。</p>
|
||||
<?php else: foreach ($files as $f):
|
||||
$metaPath = $pendingDir . '/' . $f . '.json';
|
||||
$meta = is_file($metaPath) ? json_decode(@file_get_contents($metaPath), true) : [];
|
||||
?>
|
||||
<div class="card" data-file="<?php echo htmlspecialchars($f); ?>">
|
||||
<img src="<?php echo 'pictures_pending/' . htmlspecialchars($f); ?>" alt="待审核图片" />
|
||||
<div class="meta">
|
||||
<div>文件:<?php echo htmlspecialchars($f); ?></div>
|
||||
<?php if (!empty($meta['original_name'])): ?><div>原名:<?php echo htmlspecialchars($meta['original_name']); ?></div><?php endif; ?>
|
||||
<?php if (!empty($meta['title'])): ?><div>标题:<?php echo htmlspecialchars($meta['title']); ?></div><?php endif; ?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn approve">通过</button>
|
||||
<button class="btn reject">拒绝</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
<script>
|
||||
const list = document.getElementById('pendingList');
|
||||
function send(action, file, password) {
|
||||
const fd = new FormData();
|
||||
fd.append('action', action);
|
||||
fd.append('file', file);
|
||||
fd.append('password', password);
|
||||
return fetch('api/review_picture_action.php', { method: 'POST', body: fd }).then(r=>r.json());
|
||||
}
|
||||
list?.addEventListener('click', async (e) => {
|
||||
const btn = e.target.closest('button');
|
||||
if (!btn) return;
|
||||
const card = e.target.closest('.card');
|
||||
const file = card?.dataset?.file;
|
||||
if (!file) return;
|
||||
const action = btn.classList.contains('approve') ? 'approve' : 'reject';
|
||||
btn.disabled = true;
|
||||
const res = await send(action, file, '').catch(()=>({ok:false,msg:'请求失败'}));
|
||||
btn.disabled = false;
|
||||
alert(res.msg || '操作完成');
|
||||
if (res.ok) {
|
||||
card.remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<?php ?>
|
||||
|
||||
180
review_texts.php
Normal file
180
review_texts.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
// 文案审核页面:查看 texts_pending 中的待处理文案,执行通过/拒绝
|
||||
session_start();
|
||||
|
||||
$ADMIN_PASSWORD = 'my123123';
|
||||
|
||||
// 退出登录
|
||||
if (isset($_GET['logout'])) {
|
||||
unset($_SESSION['admin_ok']);
|
||||
header('Location: review_texts.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 登录处理
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) {
|
||||
$pwd = trim($_POST['password'] ?? '');
|
||||
if ($pwd === $ADMIN_PASSWORD) {
|
||||
$_SESSION['admin_ok'] = true;
|
||||
header('Location: review_texts.php');
|
||||
exit;
|
||||
} else {
|
||||
$login_error = '密码错误,请重试';
|
||||
}
|
||||
}
|
||||
|
||||
// 若未登录,显示登录界面
|
||||
if (empty($_SESSION['admin_ok'])) {
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>管理员登录 - 文案审核</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.login-card { max-width: 480px; margin: 60px auto; border:2px solid #e33; border-radius:12px; padding:20px; background:#fff; }
|
||||
.login-card h1 { margin:0 0 12px; font-size:20px; }
|
||||
.login-card .field { display:flex; flex-direction:column; gap:8px; }
|
||||
.login-card input { padding:10px 12px; border:1px solid #ddd; border-radius:8px; }
|
||||
.login-card .btn { background:#e33; color:#fff; border:none; padding:10px 18px; border-radius:22px; cursor:pointer; }
|
||||
.login-card .err { color:#c00; font-size:13px; margin-top:8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">审核登录</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="login-card" aria-label="管理员登录">
|
||||
<h1>请输入管理员密码</h1>
|
||||
<form method="post">
|
||||
<div class="field">
|
||||
<label for="password">密码</label>
|
||||
<input id="password" name="password" type="password" placeholder="输入管理员密码" required />
|
||||
</div>
|
||||
<div style="margin-top:12px;">
|
||||
<button class="btn" type="submit">登录</button>
|
||||
</div>
|
||||
<?php if (!empty($login_error)): ?>
|
||||
<div class="err"><?php echo htmlspecialchars($login_error); ?></div>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
|
||||
$pendingDir = __DIR__ . '/texts_pending';
|
||||
$files = [];
|
||||
if (is_dir($pendingDir)) {
|
||||
foreach (scandir($pendingDir) as $f) {
|
||||
if ($f === '.' || $f === '..') continue;
|
||||
if (preg_match('/\.json$/i', $f)) {
|
||||
$files[] = $f;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>文案审核</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.review-page { max-width: 1100px; margin: 24px auto; }
|
||||
.review-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
|
||||
.list { display:grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap:12px; }
|
||||
.card { border:2px solid #e33; border-radius:10px; padding:12px; background:#fff; }
|
||||
.card h3 { margin:0 0 8px; font-size:16px; }
|
||||
.card pre { white-space:pre-wrap; font-size:13px; color:#333; }
|
||||
.meta { font-size: 12px; color:#666; margin-top:6px; }
|
||||
.actions { display:flex; gap:8px; margin-top:8px; }
|
||||
.btn { padding:6px 12px; border:none; border-radius:16px; cursor:pointer; }
|
||||
.btn.approve { background:#2ebd59; color:#fff; }
|
||||
.btn.reject { background:#999; color:#fff; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page review-page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">文案审核</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
<li><a class="menu__link" href="review_texts.php?logout=1">退出登录</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="review-head">
|
||||
<h1 style="margin:0;font-size:18px;">待审核文案(<?php echo count($files); ?>)</h1>
|
||||
</div>
|
||||
<section class="list" id="pendingList">
|
||||
<?php if (!$files): ?>
|
||||
<p>当前无待审核文案。</p>
|
||||
<?php else: foreach ($files as $f):
|
||||
$metaPath = $pendingDir . '/' . $f;
|
||||
$meta = is_file($metaPath) ? json_decode(@file_get_contents($metaPath), true) : [];
|
||||
$title = !empty($meta['title']) ? $meta['title'] : '(无标题)';
|
||||
$content = !empty($meta['content']) ? $meta['content'] : '';
|
||||
$preview = $content;
|
||||
if (function_exists('mb_substr')) {
|
||||
$preview = mb_substr($content, 0, 200);
|
||||
} else {
|
||||
$preview = substr($content, 0, 200);
|
||||
}
|
||||
?>
|
||||
<div class="card" data-file="<?php echo htmlspecialchars($f); ?>">
|
||||
<h3><?php echo htmlspecialchars($title); ?></h3>
|
||||
<pre><?php echo htmlspecialchars($preview); ?><?php echo (strlen($content) > strlen($preview)) ? '…' : ''; ?></pre>
|
||||
<div class="meta">
|
||||
<div>文件:<?php echo htmlspecialchars($f); ?></div>
|
||||
<?php if (!empty($meta['uploaded_at'])): ?><div>投稿时间:<?php echo htmlspecialchars($meta['uploaded_at']); ?></div><?php endif; ?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn approve">通过</button>
|
||||
<button class="btn reject">拒绝</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
<script>
|
||||
const list = document.getElementById('pendingList');
|
||||
function send(action, file, password) {
|
||||
const fd = new FormData();
|
||||
fd.append('action', action);
|
||||
fd.append('file', file);
|
||||
fd.append('password', password);
|
||||
return fetch('api/review_text_action.php', { method: 'POST', body: fd }).then(r=>r.json());
|
||||
}
|
||||
list?.addEventListener('click', async (e) => {
|
||||
const btn = e.target.closest('button');
|
||||
if (!btn) return;
|
||||
const card = e.target.closest('.card');
|
||||
const file = card?.dataset?.file;
|
||||
if (!file) return;
|
||||
const action = btn.classList.contains('approve') ? 'approve' : 'reject';
|
||||
btn.disabled = true;
|
||||
const res = await send(action, file, '').catch(()=>({ok:false,msg:'请求失败'}));
|
||||
btn.disabled = false;
|
||||
alert(res.msg || '操作完成');
|
||||
if (res.ok) {
|
||||
card.remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<?php ?>
|
||||
131
upload.php
Normal file
131
upload.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
// 投稿页面:允许用户上传视频,上传内容进入待审核目录 videos_pending
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>投稿视频</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">投稿</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="upload-container" aria-label="投稿表单">
|
||||
<h1>上传你想分享的视频</h1>
|
||||
<form class="upload-grid video" action="api/upload_video.php" method="post" enctype="multipart/form-data">
|
||||
<div class="field">
|
||||
<label>选择视频文件(支持 mp4 / webm / mov)</label>
|
||||
<div id="dropzone" class="dropzone" role="button" aria-label="拖拽或点击选择文件">
|
||||
拖拽文件到此处,或点击选择文件
|
||||
</div>
|
||||
<input id="videoFile" class="hidden-input" type="file" name="video" accept="video/mp4,video/webm,video/quicktime" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>标题(可选)</label>
|
||||
<input id="titleInput" type="text" name="title" placeholder="给你的投稿起个标题" />
|
||||
<div class="actions">
|
||||
<button class="btn" type="submit">提交投稿</button>
|
||||
<a href="review.php" style="font-size:12px;color:#666;">管理员审核入口</a>
|
||||
</div>
|
||||
</div>
|
||||
<aside class="card">
|
||||
<video id="preview" class="video-preview" controls style="display:none"></video>
|
||||
<div id="meta" class="meta"></div>
|
||||
<div id="errors" class="errors"></div>
|
||||
</aside>
|
||||
<p class="tips">说明:投稿后文件会进入“待审核”队列,管理员审核通过后才会出现在播放列表中。单个视频大小限制:50MB。</p>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
<script>
|
||||
const dropzone = document.getElementById('dropzone');
|
||||
const fileInput = document.getElementById('videoFile');
|
||||
const preview = document.getElementById('preview');
|
||||
const meta = document.getElementById('meta');
|
||||
const errors = document.getElementById('errors');
|
||||
const titleInput = document.getElementById('titleInput');
|
||||
|
||||
const allowedExt = ['mp4','webm','mov'];
|
||||
const SIZE_LIMIT = 50 * 1024 * 1024; // 50MB
|
||||
|
||||
function formatSize(bytes){
|
||||
if (bytes >= 1024*1024*1024) return (bytes/1024/1024/1024).toFixed(2) + ' GB';
|
||||
if (bytes >= 1024*1024) return (bytes/1024/1024).toFixed(2) + ' MB';
|
||||
if (bytes >= 1024) return (bytes/1024).toFixed(2) + ' KB';
|
||||
return bytes + ' B';
|
||||
}
|
||||
|
||||
function setFile(file){
|
||||
if (!file) return;
|
||||
// 填充到 input
|
||||
const dt = new DataTransfer();
|
||||
dt.items.add(file);
|
||||
fileInput.files = dt.files;
|
||||
|
||||
// 校验扩展名
|
||||
const name = file.name || '';
|
||||
const ext = name.split('.').pop().toLowerCase();
|
||||
errors.textContent = '';
|
||||
if (!allowedExt.includes(ext)) {
|
||||
errors.textContent = '仅支持 mp4 / webm / mov 格式文件';
|
||||
fileInput.value = '';
|
||||
preview.style.display = 'none';
|
||||
preview.removeAttribute('src');
|
||||
meta.textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验大小
|
||||
if (file.size > SIZE_LIMIT) {
|
||||
errors.textContent = '文件过大:超过 50MB 限制';
|
||||
fileInput.value = '';
|
||||
preview.style.display = 'none';
|
||||
preview.removeAttribute('src');
|
||||
meta.textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 自动填充标题
|
||||
if (!titleInput.value) {
|
||||
const base = name.replace(/\.[^.]+$/, '');
|
||||
titleInput.value = base;
|
||||
}
|
||||
|
||||
// 预览视频
|
||||
const url = URL.createObjectURL(file);
|
||||
preview.src = url;
|
||||
preview.style.display = 'block';
|
||||
preview.load();
|
||||
meta.textContent = '文件:' + name + ',大小:' + formatSize(file.size) + (file.type ? ',类型:' + file.type : '');
|
||||
preview.onloadedmetadata = () => {
|
||||
const d = preview.duration;
|
||||
if (isFinite(d) && d > 0) {
|
||||
meta.textContent += ',时长:' + Math.round(d) + ' 秒';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
dropzone.addEventListener('click', () => fileInput.click());
|
||||
dropzone.addEventListener('dragover', (e) => { e.preventDefault(); dropzone.classList.add('dragging'); });
|
||||
dropzone.addEventListener('dragleave', () => dropzone.classList.remove('dragging'));
|
||||
dropzone.addEventListener('drop', (e) => {
|
||||
e.preventDefault(); dropzone.classList.remove('dragging');
|
||||
const file = e.dataTransfer.files?.[0];
|
||||
setFile(file);
|
||||
});
|
||||
fileInput.addEventListener('change', () => {
|
||||
const file = fileInput.files?.[0];
|
||||
setFile(file);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
96
upload_picture.php
Normal file
96
upload_picture.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// 图片投稿页面:允许用户上传图片,保存到 pictures_pending 等待处理/审核
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>图片投稿</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">图片投稿</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="upload-container" aria-label="图片投稿表单">
|
||||
<h1 class="upload-title">提交你的图片</h1>
|
||||
<form id="form" class="upload-grid two" action="api/upload_picture.php" method="post" enctype="multipart/form-data">
|
||||
<div class="card">
|
||||
<div id="drop" class="dropzone" tabindex="0" aria-label="拖拽图片到此或点击选择">
|
||||
<p style="margin:0 0 8px;">拖拽图片到此,或点击选择文件</p>
|
||||
<input id="file" name="picture" type="file" accept="image/*" style="display:none;" />
|
||||
<p class="tips">支持 jpg / jpeg / png / gif / webp</p>
|
||||
</div>
|
||||
<div class="field" style="margin-top:12px;">
|
||||
<label>标题(可选)</label>
|
||||
<input type="text" name="title" id="title" placeholder="给你的图片起个标题" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="card" aria-live="polite">
|
||||
<img id="previewImg" class="preview-img" alt="预览图" />
|
||||
<div class="meta" id="meta">未选择文件</div>
|
||||
<div id="errors" class="errors"></div>
|
||||
<div class="actions">
|
||||
<button id="submitBtn" class="btn" type="submit">提交图片</button>
|
||||
<a class="btn-ghost" href="review_pictures.php" title="管理员审核入口">管理员审核入口</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<p class="tips">说明:提交后图片会保存到“待处理”目录,管理员审核通过后将入库,随后可在本地随机图片中显示。单张图片大小限制:10MB。</p>
|
||||
</main>
|
||||
</div>
|
||||
<script>
|
||||
const drop = document.getElementById('drop');
|
||||
const fileInput = document.getElementById('file');
|
||||
const previewImg = document.getElementById('previewImg');
|
||||
const metaBox = document.getElementById('meta');
|
||||
const titleInput = document.getElementById('title');
|
||||
const errors = document.getElementById('errors');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
const SIZE_LIMIT = 10 * 1024 * 1024; // 10MB
|
||||
function setPreview(file) {
|
||||
if (!file) { previewImg.src = ''; metaBox.textContent = '未选择文件'; return; }
|
||||
const url = URL.createObjectURL(file);
|
||||
previewImg.src = url;
|
||||
const kb = (file.size/1024).toFixed(1);
|
||||
metaBox.textContent = `文件:${file.name} 大小:${kb} KB 类型:${file.type || '未知'}`;
|
||||
// 校验大小
|
||||
if (file.size > SIZE_LIMIT) {
|
||||
errors.textContent = '文件过大:超过 10MB 限制';
|
||||
previewImg.removeAttribute('src');
|
||||
metaBox.textContent = '未选择文件';
|
||||
const dt = new DataTransfer();
|
||||
document.getElementById('file').files = dt.files; // 清空选择
|
||||
submitBtn.disabled = true;
|
||||
return;
|
||||
}
|
||||
errors.textContent = '';
|
||||
submitBtn.disabled = false;
|
||||
if (!titleInput.value) {
|
||||
const base = file.name.replace(/\.[A-Za-z0-9]+$/, '');
|
||||
titleInput.value = base;
|
||||
}
|
||||
}
|
||||
|
||||
drop.addEventListener('click', () => fileInput.click());
|
||||
drop.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); fileInput.click(); } });
|
||||
drop.addEventListener('dragover', (e) => { e.preventDefault(); drop.classList.add('dragging'); });
|
||||
drop.addEventListener('dragleave', () => drop.classList.remove('dragging'));
|
||||
drop.addEventListener('drop', (e) => {
|
||||
e.preventDefault(); drop.classList.remove('dragging');
|
||||
const file = e.dataTransfer.files?.[0];
|
||||
if (file) { fileInput.files = e.dataTransfer.files; setPreview(file); }
|
||||
});
|
||||
fileInput.addEventListener('change', () => { const f = fileInput.files?.[0]; setPreview(f); });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
54
upload_text.php
Normal file
54
upload_text.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// 文案投稿页面:允许用户上传文本内容,保存到 texts_pending 等待处理/审核
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>投稿文案</title>
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<style>
|
||||
.upload-page { max-width: 980px; margin: 24px auto; padding: 20px; border: 2px solid #e33; border-radius: 14px; background:#fff; box-shadow: 0 4px 12px rgba(0,0,0,0.04);}
|
||||
.upload-page h1 { margin: 0 0 16px; font-size: 22px; }
|
||||
.form { display:grid; grid-template-columns: 1fr; gap: 16px; }
|
||||
.field { display:flex; flex-direction:column; gap:8px; }
|
||||
.field input[type="text"], .field textarea { padding: 10px 12px; border:1px solid #ddd; border-radius:8px; }
|
||||
.field textarea { min-height: 160px; resize: vertical; }
|
||||
.actions { display:flex; gap:12px; align-items:center; }
|
||||
.btn { background:#e33; color:#fff; border:none; padding:10px 18px; border-radius:22px; cursor:pointer; }
|
||||
.btn:hover { opacity:.92; }
|
||||
.tips { color:#666; font-size:13px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<header class="menu">
|
||||
<div class="menu__logo">文案投稿</div>
|
||||
<nav aria-label="主菜单">
|
||||
<ul class="menu__nav">
|
||||
<li><a class="menu__link" href="index.php">返回首页</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="upload-page" aria-label="文案投稿表单">
|
||||
<h1>提交你的文案/句子</h1>
|
||||
<form class="form" action="api/upload_text.php" method="post">
|
||||
<div class="field">
|
||||
<label>标题(可选)</label>
|
||||
<input type="text" name="title" placeholder="给你的文案起个标题" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>文案内容</label>
|
||||
<textarea name="content" placeholder="输入你想分享的文案内容" required></textarea>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn" type="submit">提交文案</button>
|
||||
<a class="menu__link" href="review_texts.php" title="管理员审核入口">管理员审核入口</a>
|
||||
</div>
|
||||
<p class="tips">说明:提交后文案会保存到“待处理”目录,后续可按需添加审核或自动入库。</p>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user