<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-2
 */
if (!defined('ROOT_PATH')) exit;
$currentChannel = null;
if ($module == 'channel' || $module == 'page' || $module == 'article' || $module == 'product' || $module == 'image' || $module == 'download' || $module == 'video' || $module == 'recruit') {
    if ($module == 'channel') { $currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".intval($id)); }
}
if (!$currentChannel && $module=='channel' && $id>0) $currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".intval($id));
if (!$currentChannel) $currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".intval($id));
if (!$currentChannel) { $currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE is_show=1 ORDER BY list_order ASC,id ASC LIMIT 1"); }
if (!$currentChannel || !is_array($currentChannel)) {
    $currentChannel = array(
        'id' => 0,
        'parent_id' => 0,
        'channel_type' => 1,
        'channel_name' => '栏目列表',
        'channel_thumb' => '',
        'channel_dir' => ''
    );
}
$parentId = isset($currentChannel['parent_id']) ? intval($currentChannel['parent_id']) : 0;
$topId = $parentId>0 ? $parentId : intval($currentChannel['id']);
$topChannel = $parentId>0 ? $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".$parentId) : $currentChannel;
if (!$topChannel || !is_array($topChannel)) {
    $topChannel = $currentChannel;
}
$subChannels = $topId > 0 ? $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id=".$topId." AND is_show=1 ORDER BY list_order ASC,id ASC") : array();
$page = isset($_GET['page']) ? max(1,intval($_GET['page'])) : 1;
$pagesize = 12;
$offset = ($page-1)*$pagesize;
$list = array(); $total = 0;
$ids = array(intval($currentChannel['id']));
$children = intval($currentChannel['id']) > 0 ? $db->fetchAll("SELECT id FROM {$db->table('channel')} WHERE parent_id=".intval($currentChannel['id'])." AND is_show=1") : array();
foreach($children as $c){ $ids[] = intval($c['id']); }
$idSql = implode(',', $ids);
$ctype = intval($currentChannel['channel_type']);
if ($ctype==1) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('article')} WHERE channel_id IN ($idSql) AND status=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('article')} WHERE channel_id IN ($idSql) AND status=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
elseif ($ctype==2) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('product')} WHERE channel_id IN ($idSql) AND status=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('product')} WHERE channel_id IN ($idSql) AND status=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
elseif ($ctype==4) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('image')} WHERE channel_id IN ($idSql) AND status=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('image')} WHERE channel_id IN ($idSql) AND status=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
elseif ($ctype==5) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('download')} WHERE channel_id IN ($idSql) AND status=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('download')} WHERE channel_id IN ($idSql) AND status=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
elseif ($ctype==7) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('video')} WHERE channel_id IN ($idSql) AND status=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('video')} WHERE channel_id IN ($idSql) AND status=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
elseif ($ctype==8) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('guestbook')} WHERE is_show=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('guestbook')} WHERE is_show=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
elseif ($ctype==9) { $row=$db->fetch("SELECT COUNT(*) c FROM {$db->table('recruit')} WHERE channel_id IN ($idSql) AND status=1"); $total=intval($row['c']); $list=$db->fetchAll("SELECT * FROM {$db->table('recruit')} WHERE channel_id IN ($idSql) AND status=1 ORDER BY create_time DESC LIMIT $offset,$pagesize"); }
$pages = $total>0 ? ceil($total/$pagesize) : 1;
$bannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1600/500?random='.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='.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($currentChannel['channel_name']); ?>-<?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(__DIR__).'/_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="postcon 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> >> <a href="<?php echo getUrl('channel', intval($topChannel['id']), isset($topChannel['channel_dir']) ? $topChannel['channel_dir'] : ''); ?>"><?php echo htmlspecialchars($topChannel['channel_name']); ?></a></div></div></div>
<?php if ($ctype==1) { ?><div class="news"><?php foreach ($list as $n) { $ts = is_numeric($n['create_time']) ? intval($n['create_time']) : strtotime($n['create_time']); ?><div class="newslist"><div class="cont"><a href="<?php echo getUrl('article', intval($n['id'])); ?>"><div class="newsdate"><p><?php echo date('m-d',$ts); ?></p><span><?php echo date('Y',$ts); ?></span></div><div class="newscon"><div class="newsbt"><?php echo htmlspecialchars($n['title']); ?></div><div class="newsms"><?php echo htmlspecialchars(msubstr(strip_tags($n['content']),0,100)); ?></div></div></a></div></div><?php } ?></div><?php }
elseif ($ctype==2 || $ctype==4 || $ctype==7 || $ctype==9) { ?><div class="npro cont"><div class="npronr clearfix"><?php foreach ((is_array($list) ? $list : array()) as $r) { if (!is_array($r)) continue; $itemId = isset($r['id']) ? intval($r['id']) : 0; $url = '#'; if ($ctype==2) $url=getUrl('product',$itemId); elseif ($ctype==4) $url=getUrl('image',$itemId); elseif ($ctype==7) $url=getUrl('video',$itemId); elseif ($ctype==9) $url=getUrl('recruit',$itemId); $itemTitle = isset($r['title']) ? $r['title'] : (isset($r['name']) ? $r['name'] : ''); $itemCover = !empty($r['litpic']) ? $r['litpic'] : (!empty($r['video_cover']) ? $r['video_cover'] : 'https://picsum.photos/600/500?random='.$itemId); ?><div class="npronr_list"><a href="<?php echo $url; ?>"><div class="proimg"><img src="<?php echo htmlspecialchars($itemCover); ?>" alt="<?php echo htmlspecialchars($itemTitle); ?>"/></div><div class="protit"><?php echo htmlspecialchars($itemTitle); ?></div></a></div><?php } ?></div></div><?php }
elseif ($ctype==5) { ?><div class="news"><div class="cont"><?php foreach ($list as $r) { $summary = ''; if (!empty($r['content'])) { $summary = msubstr(strip_tags($r['content']),0,100); } elseif (!empty($r['file_path'])) { $summary = $r['file_path']; } ?><div class="newslist"><div class="cont"><a href="<?php echo getUrl('download', intval($r['id'])); ?>"><div class="newsdate"><p>下</p><span>载</span></div><div class="newscon"><div class="newsbt"><?php echo htmlspecialchars($r['title']); ?></div><div class="newsms"><?php echo htmlspecialchars($summary !== '' ? $summary : '点击查看下载详情'); ?></div></div></a></div></div><?php } ?></div></div><?php }
elseif ($ctype==8) { ?><div class="ncontact cont"><div class="nmessagenr"><ul><?php foreach ($list as $g) { ?><li style="width:100%;margin:0 0 15px 0;float:none;background:#f7f7f7;padding:15px;border-radius:6px;"><strong><?php echo htmlspecialchars($g['name']); ?></strong><div style="color:#999;margin:6px 0;"> <?php echo htmlspecialchars(is_numeric($g['create_time']) ? date('Y-m-d H:i',$g['create_time']) : $g['create_time']); ?> </div><div><?php echo nl2br(htmlspecialchars($g['content'])); ?></div></li><?php } ?></ul></div></div><?php }
if ($pages>1) { ?><div class="pagebar"><div class="pagination"><?php if($page>1){ ?><a class="page-item page-link hidden-sm" href="?m=channel&id=<?php echo intval($currentChannel['id']); ?>&page=1">首页</a><a class="page-item page-link st" href="?m=channel&id=<?php echo intval($currentChannel['id']); ?>&page=<?php echo $page-1; ?>">&lt;&lt;</a><?php } for($i=1;$i<=$pages;$i++){ ?><a href="?m=channel&id=<?php echo intval($currentChannel['id']); ?>&page=<?php echo $i; ?>" class="page-num <?php echo $i==$page?'page-num-current':''; ?>"><?php echo $i; ?></a><?php } if($page<$pages){ ?><a class="page-item page-link st" href="?m=channel&id=<?php echo intval($currentChannel['id']); ?>&page=<?php echo $page+1; ?>">&gt;&gt;</a><a class="page-item page-link hidden-sm" href="?m=channel&id=<?php echo intval($currentChannel['id']); ?>&page=<?php echo $pages; ?>">尾页</a><?php } ?></div></div><?php }
include dirname(__DIR__).'/_footer.php'; ?></body></html>
