添加并更改了一些新特性,优化网页操作逻辑

This commit is contained in:
MasonLiu committed 2026-09-09 01:30:24 +08:00
1 parent e09fc8ae6a
commit c3bfce7afb
11 files changed
+704 -132

No files matched your search

+47 -13
View File
@@ -70,13 +70,45 @@ foreach ($pdo->query('SELECT * FROM func_tools WHERE enabled = 1 ORDER BY sort A
}
}
// —— 文章区数据(仅已被分发到当前库的文章) ——
// —— 文章区数据(仅分发到当前库;按分类分组,分类内按最后更新时间倒序) ——
$libArts = [];
foreach ($pdo->query('SELECT id, part, title, summary, pinned, sort, created_at, updated_at, board_cats FROM articles WHERE enabled = 1 ORDER BY pinned DESC, sort ASC, id ASC')->fetchAll() as $a) {
foreach ($pdo->query('SELECT id, part, title, summary, updated_at, board_cats FROM articles WHERE enabled = 1 ORDER BY updated_at DESC, id DESC')->fetchAll() as $a) {
if (in_array($catKey, array_map('trim', explode(',', trim((string)($a['board_cats'] ?? '')))), true)) {
$libArts[] = $a;
}
}
// 按分类(part)分组;分类顺序:后台拖出的分区顺序优先,否则按各组最新更新时间降序
$artGroups = [];
foreach ($libArts as $a) {
$p = trim((string)$a['part']);
if ($p === '') $p = '未分类';
if (!isset($artGroups[$p])) {
$artGroups[$p] = ['ts' => (string)$a['updated_at'], 'items' => []];
}
$artGroups[$p]['items'][] = $a;
if (strcmp((string)$a['updated_at'], $artGroups[$p]['ts']) > 0) {
$artGroups[$p]['ts'] = (string)$a['updated_at'];
}
}
$poIdx = [];
$poCfg = trim((string)setting_get('article_part_order', ''));
if ($poCfg !== '') {
foreach (explode(',', $poCfg) as $po) {
$po = trim($po);
if ($po !== '' && isset($artGroups[$po])) $poIdx[$po] = count($poIdx);
}
}
uksort($artGroups, static function ($a, $b) use ($poIdx, $artGroups) {
$ia = $poIdx[$a] ?? PHP_INT_MAX;
$ib = $poIdx[$b] ?? PHP_INT_MAX;
if ($ia !== $ib) return $ia <=> $ib;
$d = strcmp($artGroups[$b]['ts'], $artGroups[$a]['ts']);
return $d !== 0 ? $d : strcmp($a, $b);
});
$artGroupOrder = [];
foreach ($artGroups as $p => $g) {
$artGroupOrder[] = ['p' => $p, 'items' => $g['items']];
}
// —— 外部工具区数据(通用或包含当前库) ——
$extLinks = [];
@@ -282,19 +314,21 @@ layout_head($catName);
<a class="lnx-go" href="article/index.php">前往完整文章库 ›</a>
</div>
<div class="lnx-note st-tip">由后台「文章管理」为文章勾选分发到的库;点击进入阅读页(返回按钮已适配为返回上一页)。</div>
<?php if (!$libArts): ?>
<?php if (!$artGroupOrder): ?>
<div class="lnx-empty">还没有文章分发到本库<span class="st-tip">,可到后台「文章管理」编辑文章并勾选“展示到库首页”</span>。</div>
<?php else: ?>
<div class="lnx-arts">
<?php foreach ($libArts as $ak): ?>
<a class="lnx-art" href="article/index.php?id=<?= (int)$ak['id'] ?>&from=nav&cat=<?= he($catKey) ?>">
<span class="lnx-ab"><?= he((string)$ak['part']) ?></span>
<h4><?= he((string)$ak['title']) ?></h4>
<p><?= he(trim((string)$ak['summary']) !== '' ? (string)$ak['summary'] : '(无摘要)') ?></p>
<time><?= he((string)$ak['created_at']) ?></time>
</a>
<?php endforeach; ?>
</div>
<?php foreach ($artGroupOrder as $ag): ?>
<h4 class="lnx-eg"><?= he($ag['p']) ?></h4>
<div class="lnx-arts">
<?php foreach ($ag['items'] as $ak): ?>
<a class="lnx-art" href="article/index.php?id=<?= (int)$ak['id'] ?>&from=nav&cat=<?= he($catKey) ?>">
<h4><?= he((string)$ak['title']) ?></h4>
<p><?= he(trim((string)$ak['summary']) !== '' ? (string)$ak['summary'] : '(无摘要)') ?></p>
<time>更新于 <?= he((string)$ak['updated_at']) ?></time>
</a>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</section>