<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-1
 */
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$product = $db->fetch("SELECT * FROM {$db->table('product')} WHERE id = ?", [$id]);
if(empty($product)) { header('Location: /'); exit; }
$channel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id = ?", [$product['channel_id']]);
$litpic = $product['litpic'] ?: $site['template_dir'].'images/nopic.jpg';
$specs = json_decode($product['specs'] ?? '[]', true);
$attrs = json_decode($product['attrs'] ?? '[]', true);
$prevProduct = $db->fetch("SELECT id, title FROM {$db->table('product')} WHERE channel_id = ? AND id < ? AND status = 1 ORDER BY id DESC LIMIT 1", [$product['channel_id'], $id]);
$nextProduct = $db->fetch("SELECT id, title FROM {$db->table('product')} WHERE channel_id = ? AND id > ? AND status = 1 ORDER BY id ASC LIMIT 1", [$product['channel_id'], $id]);
?>
<!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($product['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-product">
<div class="container">
<h1><?php echo htmlspecialchars($product['title']); ?></h1>
</div>
</div>

<div class="breadcrumb">
<div class="container">
<a href="/">首页</a><span>&gt;</span>
<a href="<?php echo getUrl('channel', $product['channel_id']); ?>"><?php echo htmlspecialchars($channel['channel_name'] ?? ''); ?></a><span>&gt;</span>
<?php echo htmlspecialchars($product['title']); ?>
</div>
</div>

<article class="article-page">
<div class="container">
<div class="article-header">
<h1><?php echo htmlspecialchars($product['title']); ?></h1>
<div class="article-meta">
<span>更新时间：<?php echo date('Y-m-d', strtotime($product['update_time'] ?? $product['create_time'])); ?></span>
</div>
</div>
<div style="max-width:900px;margin:0 auto;">
<?php if(!empty($litpic) && $litpic != $site['template_dir'].'images/nopic.jpg'): ?>
<div style="margin-bottom:30px;">
<img src="<?php echo htmlspecialchars($litpic); ?>" alt="<?php echo htmlspecialchars($product['title']); ?>" style="width:100%;border-radius:8px;">
</div>
<?php endif; ?>
<div class="article-content">
<?php if(!empty($product['summary'])): ?>
<p style="font-size:18px;color:#666;margin-bottom:20px;"><?php echo htmlspecialchars($product['summary']); ?></p>
<?php endif; ?>
<?php echo $product['content']; ?>
</div>
<?php if($prevProduct || $nextProduct): ?>
<div style="margin-top:40px;padding:20px;background:#f5f5f5;border-radius:8px;font-size:14px;display:flex;justify-content:space-between;">
<?php if($prevProduct): ?>
<a href="<?php echo getUrl('product', $prevProduct['id']); ?>" style="color:#666;">&lt; 上一篇：<?php echo htmlspecialchars($prevProduct['title']); ?></a>
<?php endif; ?>
<?php if($nextProduct): ?>
<a href="<?php echo getUrl('product', $nextProduct['id']); ?>" style="color:#666;">下一篇：<?php echo htmlspecialchars($nextProduct['title']); ?> &gt;</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
</article>

<?php include __DIR__ . '/../_footer.php'; ?>
</body>
</html>