<?php
/**
 * 2026企业CMS - 默认模板新闻列表页
 */
$pageDescription = '最新新闻资讯、行业动态';
$breadcrumbItems = [['title' => '新闻资讯']];
$urlPattern = (get_setting('url_mode',1)==1) ? '?p=news&page=%d' : '/news/%d.html';
$pagination = paginate($total, $page, $pageSize, $urlPattern);
?>
<?php echo breadcrumb($breadcrumbItems); ?>

<div class="main-content">
    <div class="container" style="display:flex;gap:30px;">
        <div style="flex:1;">
            <h2 class="section-title" style="text-align:left;">新闻资讯</h2>
            
            <?php if (empty($articles)): ?>
            <div style="text-align:center;padding:60px;color:#999;">暂无文章</div>
            <?php else: ?>
            <div class="article-list">
                <?php foreach ($articles as $a): ?>
                <div class="article-item">
                    <?php if ($a['cover_image']): ?>
                    <div class="article-thumb">
                        <a href="<?php echo cms_url('article', ['slug' => $a['slug']]); ?>">
                            <img src="<?php echo $a['cover_image']; ?>" alt="<?php echo xss_clean($a['title']); ?>">
                        </a>
                    </div>
                    <?php endif; ?>
                    <div class="article-info">
                        <div class="article-title">
                            <a href="<?php echo cms_url('article', ['slug' => $a['slug']]); ?>"><?php echo xss_clean($a['title']); ?></a>
                        </div>
                        <div class="article-summary"><?php echo xss_clean(str_cut($a['summary'] ?: strip_tags($a['content']), 150)); ?></div>
                        <div class="article-meta">
                            <span><?php echo date('Y-m-d', strtotime($a['published_at'] ?: $a['created_at'])); ?></span>
                            <span style="margin-left:15px;">浏览：<?php echo $a['views']; ?></span>
                            <?php if ($a['is_top']): ?><span style="color:#e74c3c;margin-left:10px;">[置顶]</span><?php endif; ?>
                            <?php if ($a['is_recommend']): ?><span style="color:#2c82e0;margin-left:10px;">[推荐]</span><?php endif; ?>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
            
            <?php if ($totalPage > 1): ?>
            <div class="pagination">
                <?php if ($page > 1): ?><a href="<?php echo cms_url('news', ['page' => $page-1]); ?>">上一页</a><?php endif; ?>
                <?php for ($i=max(1,$page-2); $i<=min($totalPage,$page+2); $i++): ?>
                    <?php if ($i == $page): ?><span class="current"><?php echo $i; ?></span>
                    <?php else: ?><a href="<?php echo cms_url('news', ['page' => $i]); ?>"><?php echo $i; ?></a>
                    <?php endif; ?>
                <?php endfor; ?>
                <?php if ($page < $totalPage): ?><a href="<?php echo cms_url('news', ['page' => $page+1]); ?>">下一页</a><?php endif; ?>
            </div>
            <?php endif; ?>
            <?php endif; ?>
        </div>
        
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="widget">
                <h3 class="widget-title">文章分类</h3>
                <ul style="list-style:none;">
                    <?php $cats = db_query("SELECT * FROM `categories` WHERE `status`=1 ORDER BY `sort_order` ASC"); ?>
                    <li style="padding:8px 0;"><a href="<?php echo cms_url('news'); ?>">全部</a></li>
                    <?php foreach ($cats as $cat): ?>
                    <li style="padding:8px 0;border-bottom:1px solid #eee;">
                        <a href="<?php echo cms_url('news', ['category' => $cat['slug']]); ?>"><?php echo xss_clean($cat['name']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
            
            <div class="widget">
                <h3 class="widget-title">热门文章</h3>
                <ul style="list-style:none;">
                    <?php $hotArticles = db_query("SELECT `title`,`slug` FROM `articles` WHERE `status`=1 ORDER BY `views` DESC LIMIT 8"); ?>
                    <?php foreach ($hotArticles as $ha): ?>
                    <li style="padding:8px 0;border-bottom:1px solid #eee;">
                        <a href="<?php echo cms_url('article', ['slug' => $ha['slug']]); ?>"><?php echo xss_clean($ha['title']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
    </div>
</div>
