<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-1
 */
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if($id > 0) {
    $video = $db->fetch("SELECT * FROM {$db->table('video')} WHERE id = ?", [$id]);
    if(empty($video)) { header('Location: /'); exit; }
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($video['title']); ?> - <?php echo htmlspecialchars($site['site_name']); ?></title>
<link rel="stylesheet" href="<?php echo $site['template_dir']; ?>css/style.css">
</head>
<body>
<?php include __DIR__ . '/_header.php'; ?>
<div class="video-page">
<div class="container">
<div class="video-player">
<video src="<?php echo htmlspecialchars($video['video_path']); ?>" controls poster="<?php echo htmlspecialchars($video['video_cover'] ?? ''); ?>"></video>
</div>
<div class="video-info">
<h1><?php echo htmlspecialchars($video['title']); ?></h1>
<div class="meta">上传时间：<?php echo date('Y-m-d', strtotime($video['create_time'])); ?></div>
<div class="article-content"><?php echo $video['content']; ?></div>
</div>
</div>
</div>
<?php include __DIR__ . '/_footer.php'; ?>
</body>
</html>
<?php
} else {
    $videos = $db->fetchAll("SELECT * FROM {$db->table('video')} WHERE status = 1 ORDER BY create_time DESC LIMIT 20");
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>视频中心 - <?php echo htmlspecialchars($site['site_name']); ?></title>
<link rel="stylesheet" href="<?php echo $site['template_dir']; ?>css/style.css">
</head>
<body>
<?php include __DIR__ . '/_header.php'; ?>
<div class="channel-banner channel-banner-video"><div class="container"><h1>视频中心</h1></div></div>
<div class="video-page">
<div class="container">
<div class="list-grid">
<?php foreach($videos as $v): ?>
<div class="channel-card" style="position:relative;">
<a href="<?php echo getUrl('video', $v['id']); ?>" class="channel-card-img" style="position:relative;">
<img src="<?php echo htmlspecialchars($v['video_cover'] ?? $site['template_dir'].'images/nopic.jpg'); ?>" alt="<?php echo htmlspecialchars($v['title']); ?>">
<div style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.3);">
<svg width="50" height="50" viewBox="0 0 24 24" fill="rgba(255,255,255,0.9)" stroke="none"><polygon points="5 3 19 12 5 21 5 3"/></svg>
</div>
</a>
<div class="channel-card-info"><h3><?php echo htmlspecialchars($v['title']); ?></h3></div>
</div>
<?php endforeach; ?>
</div>
<?php if(empty($videos)): ?><p style="text-align:center;color:#999;padding:60px 0;">暂无视频</p><?php endif; ?>
</div>
</div>
<?php include __DIR__ . '/_footer.php'; ?>
</body>
</html>
<?php } ?>