<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-2
 */
if (!defined('ROOT_PATH')) exit;
$pageInfo = $id>0 ? $db->fetch("SELECT * FROM {$db->table('page')} WHERE id=".intval($id)) : null;
if (!$pageInfo) { $pageInfo = $db->fetch("SELECT * FROM {$db->table('page')} WHERE channel_id=".intval($id)." ORDER BY id DESC LIMIT 1"); }
if (!$pageInfo) { echo '页面不存在'; return; }

$currentChannel = null;
if (!empty($pageInfo['channel_id'])) {
    $currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".intval($pageInfo['channel_id']));
}
if ($currentChannel) {
    $topId = intval($currentChannel['parent_id'])>0 ? intval($currentChannel['parent_id']) : intval($currentChannel['id']);
    $topChannel = intval($currentChannel['parent_id'])>0 ? $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".$topId) : $currentChannel;
    if (!$topChannel) { $topChannel = $currentChannel; }
    $subChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id=".$topId." AND is_show=1 ORDER BY list_order ASC,id ASC");
} else {
    $currentChannel = array(
        'id' => 0,
        'parent_id' => 0,
        'channel_name' => '单页内容',
        'channel_thumb' => ''
    );
    $topChannel = $currentChannel;
    $subChannels = array();
}
$pageTitle = isset($pageInfo['page_title']) && $pageInfo['page_title'] !== '' ? $pageInfo['page_title'] : (isset($currentChannel['channel_name']) ? $currentChannel['channel_name'] : '单页内容');
$pageContent = isset($pageInfo['page_content']) ? $pageInfo['page_content'] : (isset($pageInfo['content']) ? $pageInfo['content'] : '');
$bannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1600/500?random='.max(1, intval($currentChannel['id'])));
$mobileBannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1200/400?random='.max(1, intval($currentChannel['id'])));
?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" /><title><?php echo htmlspecialchars($pageTitle); ?>-<?php echo htmlspecialchars($site['site_name']); ?></title><link href="<?php echo $site['template_dir']; ?>css/style.css" rel="stylesheet" type="text/css" /><link href="<?php echo $site['template_dir']; ?>css/bootstrap.min.css" rel="stylesheet" type="text/css"><script src="<?php echo $site['template_dir']; ?>js/jquery-1.8.3.min.js"></script></head><body><?php include dirname(__FILE__).'/_header.php'; ?><div class="banner_n" style="background:url(<?php echo htmlspecialchars($bannerPic); ?>) no-repeat top center;background-size:cover;"><div class="capitalize"><div class="ad-tit"><?php echo htmlspecialchars($topChannel['channel_name']); ?></div><div class="ad-line"></div></div></div><div class="mbanner"><img src="<?php echo htmlspecialchars($mobileBannerPic); ?>" width="100%" /></div><div class="post"><div class="cont clearfix"><div class="col-md-8 col-sm-12 col-xs-12 nabout_menu"><ul><?php foreach ($subChannels as $sc) { ?><li class="<?php echo intval($sc['id'])==intval($currentChannel['id']) ? 'cur' : ''; ?>"><a href="<?php echo getUrl('channel', intval($sc['id']), isset($sc['channel_dir']) ? $sc['channel_dir'] : ''); ?>"><?php echo htmlspecialchars($sc['channel_name']); ?></a></li><?php } ?></ul></div><div class="col-md-4 col-sm-12 col-xs-12 position hidden-s"><img src="<?php echo $site['template_dir']; ?>images/tb6.png" alt="当前位置" /> <a href="<?php echo getUrl('home'); ?>">首页</a> >> <?php if (!empty($topChannel['id'])) { ?><a href="<?php echo getUrl('channel', intval($topChannel['id']), isset($topChannel['channel_dir']) ? $topChannel['channel_dir'] : ''); ?>"><?php echo htmlspecialchars($topChannel['channel_name']); ?></a><?php } else { ?><span><?php echo htmlspecialchars($topChannel['channel_name']); ?></span><?php } ?></div></div></div><div class="nabout cont"><div class="naboutnr ab_img"><?php echo $pageContent; ?></div></div><?php include dirname(__FILE__).'/_footer.php'; ?></body></html>
