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

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

<article class="article-page">
<div class="container">
<div class="article-header">
<h1><?php echo htmlspecialchars($article['title']); ?></h1>
<div class="article-meta">
<span>作者：<?php echo htmlspecialchars($article['author'] ?? '网站编辑'); ?></span>
<span>发布时间：<?php echo date('Y-m-d', strtotime($article['create_time'])); ?></span>
<span>阅读：<?php echo intval($article['view'] ?? 0); ?></span>
</div>
</div>
<div class="article-content">
<?php echo $article['content']; ?>
</div>
<?php if($prevArticle || $nextArticle): ?>
<div style="margin-top:40px;padding:20px;background:#f5f5f5;border-radius:8px;font-size:14px;display:flex;justify-content:space-between;">
<?php if($prevArticle): ?>
<a href="<?php echo getUrl('article', $prevArticle['id']); ?>" style="color:#666;">&lt; 上一篇：<?php echo htmlspecialchars($prevArticle['title']); ?></a>
<?php endif; ?>
<?php if($nextArticle): ?>
<a href="<?php echo getUrl('article', $nextArticle['id']); ?>" style="color:#666;">下一篇：<?php echo htmlspecialchars($nextArticle['title']); ?> &gt;</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</article>

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