NewHome/index.php

172 lines
6.4 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 渐变)
// 首页顶部组件模式weather=天气(默认) / info=访客信息 / blank=空白精简
$heroMode = setting_get('hero_mode', 'weather');
if (!in_array($heroMode, ['weather', 'info', 'blank'], true)) {
$heroMode = 'weather';
}
$visitor = [];
if ($heroMode === 'info') {
$visitor = visitor_brief();
}
$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<?= $heroMode === 'blank' ? ' hero-slim' : '' ?>"<?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>
<?php if ($heroMode === 'weather'): ?>
<!-- 天气模式(默认):第三方天气条 -->
<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>
<?php elseif ($heroMode === 'info'): ?>
<!-- 访客信息模式IP / 浏览器 / 系统 / 内核 / 屏幕 / 语言 -->
<div class="visitor-box js-visitor-box">
<div class="vb-grid">
<div class="vb-cell"><span>访问者 IP</span><b><?= he((string)($visitor['ip'] ?? '未知')) ?></b></div>
<div class="vb-cell"><span>浏览器</span><b><?= he((string)($visitor['browser'] ?? '未知')) ?></b></div>
<div class="vb-cell"><span>操作系统</span><b><?= he((string)($visitor['os'] ?? '未知')) ?></b></div>
<div class="vb-cell"><span>内核 / 渲染引擎</span><b><?= he((string)($visitor['kernel'] ?? '未知')) ?></b></div>
<div class="vb-cell"><span>屏幕分辨率</span><b class="js-vscreen">--</b></div>
<div class="vb-cell"><span>系统语言</span><b class="js-vlang">--</b></div>
</div>
</div>
<?php endif; ?>
</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-tile" href="<?= he((string)$ql['url']) ?>" target="_blank" rel="noopener noreferrer" title="<?= he($qNote !== '' ? $qNote : (string)$ql['name']) ?>">
<span class="q-tile-ic"><?= site_icon($qIcon, '') ?></span>
<span class="q-tile-b">
<b><?= he((string)$ql['name']) ?></b>
<?php if ($qNote !== ''): ?><small><?= he($qNote) ?></small><?php endif; ?>
</span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="boards">
<?php foreach ($cats as $c):
$k = (string)$c['key'];
$href = $catLink[$k] ?? 'index.php';
$bIcon = trim((string)($c['icon'] ?? ''));
$bIcon = $bIcon !== '' ? $bIcon : ($catIcon[$k] ?? '●');
$descTxt = trim((string)($c['description'] ?? ''));
if ($descTxt === '') {
$descTxt = $catHint[$k] ?? '';
}
?>
<a class="board-card" href="<?= he($href) ?>" title="<?= he($c['name']) ?><?= he($descTxt) ?>">
<span class="board-icon"><?= site_icon($bIcon, '') ?></span>
<span class="board-name"><?= he($c['name']) ?></span>
<!-- 说明文案直接常显(原悬停展开浮层已取消) -->
<span class="board-hint"><?= he($descTxt) ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
</section>
<?php layout_theme_fab(); ?>
<?php layout_footer(); ?>
<script src="assets/js/common.js"></script>
</body>
</html>