NewHome/index.php
2026-09-06 15:20:48 +08:00

147 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* index.php —— 首页区(最前置页面)
* 结构Hero 展示栏 / 名言条 / 四大板块 / 页脚
*/
$P = '';
require_once __DIR__ . '/includes/layout.php';
$siteName = setting_get('site_name', '知识导航站');
$siteSlogan = setting_get('site_slogan', '');
$heroBg = setting_get('hero_bg', ''); // 后台自定义顶部背景(纯色 / CSS 渐变)
$lastUpdated = setting_get('last_updated', '');
if ($lastUpdated === '') {
$lastUpdated = '暂无更新记录';
}
// 名言:服务端随机一条 + 全量池(供点击格言本身切换)
$quoteFile = DATA_DIR . '/quota.txt';
$quotes = [];
if (is_file($quoteFile)) {
$raw = @file($quoteFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (is_array($raw)) {
foreach ($raw as $ln) {
$ln = trim($ln);
if ($ln !== '' && strpos($ln, '#') !== 0) {
$quotes[] = $ln;
}
}
}
}
$quoteText = $quotes ? $quotes[array_rand($quotes)] : '知识就是力量。';
// 四大板块(按后台排序输出)
$cats = db()->query('SELECT * FROM categories ORDER BY sort ASC, id ASC')->fetchAll();
// 首页快捷站点(后台配置,新标签页跳转本域名其它网站)
$quickLinks = db()->query('SELECT * FROM quick_links WHERE enabled = 1 ORDER BY sort ASC, id ASC')->fetchAll();
$catLink = [
'popular' => 'nav.php?cat=popular',
'red' => 'nav.php?cat=red',
'blue' => 'nav.php?cat=blue',
'tool' => 'func/index.php',
'article' => 'article/index.php',
];
$catIcon = [
'popular' => '📖',
'red' => '⚔️',
'blue' => '🛡️',
'tool' => '🧰',
'article' => '📚',
];
$catHint = [
'popular' => '入门·科普·前沿',
'red' => '攻防演练资源',
'blue' => '防御·应急·溯源',
'tool' => '进入功能区',
'article' => '进入文章库',
];
layout_head('');
?>
<!-- Hero 顶部展示栏 -->
<header class="hero"<?php if ($heroBg !== ''): ?> style="background:<?= he($heroBg) ?>"<?php endif; ?>>
<div class="wrap hero-inner">
<div class="hero-top">
<div class="brand">
<?php layout_logo_img('logo', $siteName); ?>
<div>
<div class="site-name"><?= he($siteName) ?></div>
<?php if ($siteSlogan !== ''): ?>
<div class="site-slogan"><?= he($siteSlogan) ?></div>
<?php endif; ?>
</div>
</div>
<div class="hero-meta">
<div class="hm-row"><span>当前时间&nbsp;</span><span class="val js-clock">--</span></div>
<div class="hm-row"><span>上次更新&nbsp;</span><span class="val"><?= he($lastUpdated) ?></span></div>
</div>
</div>
<div class="weather-box">
<iframe width="800" height="150" src="https://i.tianqi.com/?c=code&a=getcode&id=48&num=6&icon=1" frameborder="0"></iframe>
</div>
</div>
</header>
<!-- 名言条 -->
<div class="quote-bar">
<div class="wrap quote-inner">
<span class="quote-mark"></span>
<span class="quote-text js-quote" data-current="0" title="点击换一条"><?= he($quoteText) ?></span>
<span class="quote-mark"></span>
</div>
<div class="quote-pool js-quote-pool">
<?php foreach ($quotes as $q): ?>
<span><?= he($q) ?></span>
<?php endforeach; ?>
</div>
</div>
<!-- 四大板块区 -->
<section class="board-section">
<div class="wrap">
<?php if ($quickLinks): ?>
<div class="quick-strip">
<?php foreach ($quickLinks as $ql):
$qIcon = trim((string)($ql['icon'] ?? ''));
$qIcon = $qIcon !== '' ? $qIcon : '🔗';
$qNote = trim((string)($ql['note'] ?? ''));
?>
<a class="quick-chip" href="<?= he((string)$ql['url']) ?>" target="_blank" rel="noopener noreferrer"<?php if ($qNote !== ''): ?> data-note="<?= he($qNote) ?>"<?php endif; ?>>
<span class="q-icon"><?= site_icon($qIcon, '') ?></span>
<span><?= he((string)$ql['name']) ?></span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="boards js-boards">
<!-- 展开说明浮层(不参与布局,不可点击) -->
<div class="board-panel js-board-panel" aria-hidden="true">
<div class="board-panel-title js-board-panel-title"></div>
<div class="board-panel-desc js-board-panel-desc"></div>
</div>
<?php foreach ($cats as $c):
$k = (string)$c['key'];
$href = $catLink[$k] ?? 'index.php';
$bIcon = trim((string)($c['icon'] ?? ''));
$bIcon = $bIcon !== '' ? $bIcon : ($catIcon[$k] ?? '●');
$hint = $catHint[$k] ?? '进入';
?>
<a class="board-card js-board-card" href="<?= he($href) ?>"
data-name="<?= he($c['name']) ?>" data-desc="<?= he((string)$c['description']) ?>">
<span class="board-icon"><?= site_icon($bIcon, '') ?></span>
<span class="board-name"><?= he($c['name']) ?></span>
<span class="board-hint"><?= he($hint) ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
</section>
<?php layout_theme_fab(); ?>
<?php layout_footer(); ?>
<script src="assets/js/common.js"></script>
</body>
</html>