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

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

<section class="list-page">
<div class="container">
<?php
$albums = array();
if(!empty($image['albums'])) {
    $albums = json_decode($image['albums'], true) ?: array();
}
// albums为空时用litpic当封面
if(empty($albums) && !empty($image['litpic'])) {
    $albums = array($image['litpic']);
}
?>
<?php if(!empty($albums)): ?>
<div class="image-detail-albums">
<?php foreach($albums as $img): ?>
<div class="album-item">
<img src="<?php echo htmlspecialchars($img); ?>" alt="<?php echo htmlspecialchars($image['title']); ?>">
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div style="text-align:center;padding:60px 0;color:#999;">暂无图片</div>
<?php endif; ?>
</div>
</section>
<?php include __DIR__ . '/_footer.php'; ?>
</body>
</html>