添加并更改了一些新特性,优化网页操作逻辑
This commit is contained in:
1 parent
e09fc8ae6a
commit
c3bfce7afb
11 files changed
+704
-132
No files matched your search
+24
-21
@@ -13,35 +13,38 @@ require_once dirname(__DIR__) . '/includes/layout.php';
|
||||
$pdo = db();
|
||||
$noteText = setting_get('article_note', '');
|
||||
|
||||
// 全部可见文章(按 id 稳定取回,分区顺序取各分区首篇 id 序;分区内置顶 → sort → id)
|
||||
$all = $pdo->query('SELECT id, part, title, summary, pinned, sort, created_at, updated_at
|
||||
FROM articles WHERE enabled = 1 ORDER BY id ASC')->fetchAll();
|
||||
$rows = [];
|
||||
$partOrder = [];
|
||||
// 全部可见文章(先按最后更新时间倒序拉取,保证各分区内均为“更新在前”排序)
|
||||
$all = $pdo->query('SELECT id, part, title, summary, updated_at
|
||||
FROM articles WHERE enabled = 1 ORDER BY updated_at DESC, id DESC')->fetchAll();
|
||||
$byPart = [];
|
||||
foreach ($all as $r) {
|
||||
$part = trim((string)$r['part']);
|
||||
if ($part === '') {
|
||||
$part = '未分类';
|
||||
}
|
||||
if (!isset($byPart[$part])) {
|
||||
$byPart[$part] = [];
|
||||
$partOrder[] = $part;
|
||||
}
|
||||
$byPart[$part][] = $r;
|
||||
}
|
||||
foreach ($partOrder as $part) {
|
||||
$items = $byPart[$part];
|
||||
usort($items, static function (array $a, array $b): int {
|
||||
if ((int)$a['pinned'] !== (int)$b['pinned']) {
|
||||
return (int)$b['pinned'] - (int)$a['pinned'];
|
||||
}
|
||||
if ((int)$a['sort'] !== (int)$b['sort']) {
|
||||
return (int)$a['sort'] <=> (int)$b['sort'];
|
||||
}
|
||||
return (int)$a['id'] <=> (int)$b['id'];
|
||||
});
|
||||
$rows[] = ['part' => $part, 'articles' => $items];
|
||||
// 分区顺序:后台「文章管理」拖出的分区顺序(article_part_order)优先;未配置则按各分区最新更新时间降序
|
||||
$poIdx = [];
|
||||
$poCfg = trim((string)setting_get('article_part_order', ''));
|
||||
if ($poCfg !== '') {
|
||||
foreach (explode(',', $poCfg) as $po) {
|
||||
$po = trim($po);
|
||||
if ($po !== '' && isset($byPart[$po])) $poIdx[$po] = count($poIdx);
|
||||
}
|
||||
}
|
||||
$partKeys = array_keys($byPart);
|
||||
usort($partKeys, static function (string $a, string $b) use ($poIdx, $byPart): int {
|
||||
$ia = $poIdx[$a] ?? PHP_INT_MAX;
|
||||
$ib = $poIdx[$b] ?? PHP_INT_MAX;
|
||||
if ($ia !== $ib) return $ia <=> $ib;
|
||||
// 各分区首篇即最新(SQL 已按 updated_at 倒序)
|
||||
$d = strcmp((string)$byPart[$b][0]['updated_at'], (string)$byPart[$a][0]['updated_at']);
|
||||
return $d !== 0 ? $d : strcmp($a, $b);
|
||||
});
|
||||
$rows = [];
|
||||
foreach ($partKeys as $p) {
|
||||
$rows[] = ['part' => $p, 'articles' => $byPart[$p]];
|
||||
}
|
||||
$total = count($all);
|
||||
// 从库首页“文章区”卡片进入阅读时(?from=nav),顶部返回按钮语义切换
|
||||
|
||||
Reference in new issue
Block a user