feat: 图标策略升级 + 引擎显隐就地切换 + 前后台一致性;界面美化
按反馈逐条处理: ① 界面美化 - 前台重做:品牌区(logo + 站名 + 副标题)、胶囊式引擎切换、圆角卡片与 悬停浮起、聚焦光晕、合集标签页淡入动画;版心改为 shell 变量 (--pad-x = max(gutter, (100% - wrap)/2)),与顶栏左右边缘严格对齐。 - 后台:表格窄屏可横向滚动、状态胶囊、自定义徽章、图标预览框。 ② 自动更新图标质量差 + 允许自定义图标 - 抓取改为阶梯择优:manifest 512/192 → apple-touch-icon → <link rel=icon> (按 sizes 降序,SVG 视为最高清)→ 第三方聚合服务(favicon.yandex.net 实测 100% 可用;icon.horse 可达时最高 256px)→ 站点自身 /favicon.ico。 - 逐个候选实测像素,达到 120px 即停;候选上限 8 个 + 10s 总预算,避免超时。 - 用 GD 只缩不放,统一存成 128×128 PNG;识别并丢弃第三方服务的 「灰底字母」占位块。 - 新增 sites.icon_custom 列(带幂等迁移):可上传图标或填图标地址; 一旦自定义,「全部更新」只刷新名称、跳过图标。 ③ 后台引擎「可见/不可见」不好用 - 小图标换成内联 SVG(原来用 emoji,跨字体显示成方块)。 - 切换改为 AJAX 原地生效 + 状态胶囊同步,不再点一下就跳页; 所有切换/移动表单都带 p 参数,无 JS 时也能正确回到当前页。 - 修掉一个隐蔽的成因:本站此前完全不发 Cache-Control/Expires/ETag, 浏览器只能自行猜测缓存策略,导致「改完刷新还是旧的」。现在所有动态页 统一发 no-store/no-cache。 ④ deploy/ 与 data/ 误入版本库 - 两目录整目录忽略,部署脚本移出仓库(存 _tooling/),已 git rm --cached。 (历史提交里仍含这些文件,如需彻底抹除需 git filter-repo,待确认。) 附带修复(线上实测驱动) - 服务器侧页面缓存:宝塔「网站加速」Apache(mod_lua) 版是一层基于 memcached 的 30 秒整页缓存,且**读不到 FastCGI 返回的 Cache-Control**,所以 no-store 挡不住它;唯一信号是请求 cookie X_CACHE=1。已在根 .htaccess 用 RequestHeader 在请求侧注入该标记(实测任何访客均 X-Cache: MISS), PHP 侧另发一颗 cookie 作为 Nginx 环境的兜底(BYPASS_PAGE_CACHE 开关)。 - 静态资源改为「长缓存 + 版本号」:asset()/icon_src() 拼 mtime+size, assets/.htaccess 与根 .htaccess 给出 max-age=31536000 immutable。 - 修 absolutize() 未还原 JSON 转义 \/ 导致部分图标 URL 抓不下来的问题。 - 修部署脚本 md5sum 在 Git Bash 下输出 "hash *path" 导致 38 项假「缺失文件」。
This commit is contained in:
+5
-3
@@ -70,8 +70,10 @@ function admin_layout(string $active, string $title, string $body): void
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= e($title) ?> · <?= e(site_name()) ?> 后台</title>
|
||||
<link rel="stylesheet" href="<?= e(url('assets/css/style.css')) ?>">
|
||||
<link rel="stylesheet" href="<?= e(url('assets/css/admin.css')) ?>">
|
||||
<link rel="icon" href="<?= e(asset('favicon.ico')) ?>" sizes="any">
|
||||
<link rel="stylesheet" href="<?= e(asset('assets/css/style.css')) ?>">
|
||||
<link rel="stylesheet" href="<?= e(asset('assets/css/admin.css')) ?>"><?php if (setting('primary_color', '#2F6BF7') !== '#2F6BF7'): ?>
|
||||
<style>:root{--primary:<?= e(setting('primary_color', '#2F6BF7')) ?>}</style><?php endif; ?>
|
||||
</head>
|
||||
<body class="admin">
|
||||
<header class="topbar">
|
||||
@@ -87,7 +89,7 @@ function admin_layout(string $active, string $title, string $body): void
|
||||
</div>
|
||||
</header>
|
||||
<main class="wrap"><?= $body ?></main>
|
||||
<script src="<?= e(url('assets/js/admin.js')) ?>"></script>
|
||||
<script src="<?= e(asset('assets/js/admin.js')) ?>"></script>
|
||||
</body>
|
||||
</html><?php
|
||||
}
|
||||
|
||||
+90
-10
@@ -1,10 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* 简航 SimpleNav —— 后台操作处理(全部 POST + CSRF)
|
||||
* 支持 AJAX:请求带 ajax=1 时返回 JSON(用于列表内原地切换显隐/排序)。
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
require_login();
|
||||
send_no_cache();
|
||||
|
||||
$isAjax = !empty($_POST['ajax']);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: ' . url('admin/'));
|
||||
@@ -21,6 +25,24 @@ if (!empty($_POST['p'])) {
|
||||
function flash(string $m, string $t = 'ok'): void { $_SESSION['flash'] = ['m' => $m, 't' => $t]; }
|
||||
function post_id(): int { return (int)($_POST['id'] ?? 0); }
|
||||
|
||||
/** AJAX 直出 JSON 并结束 */
|
||||
function json_out(array $data): void
|
||||
{
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
/** 读取某表单状态字段的当前值(用于把最新状态回给前端) */
|
||||
function state_of(string $table, int $id, string $col): int
|
||||
{
|
||||
$st = db()->prepare("SELECT {$col} FROM {$table} WHERE id=?");
|
||||
$st->execute([$id]);
|
||||
return (int)$st->fetchColumn();
|
||||
}
|
||||
|
||||
$ajax = null; // 需要在 AJAX 模式下返回的附加数据
|
||||
|
||||
try {
|
||||
switch ($action) {
|
||||
|
||||
@@ -31,22 +53,62 @@ try {
|
||||
$url = norm_url((string)($_POST['url'] ?? ''));
|
||||
$name = trim((string)($_POST['name'] ?? ''));
|
||||
$short = trim((string)($_POST['short_name'] ?? ''));
|
||||
$icon = trim((string)($_POST['icon'] ?? ''));
|
||||
$visible = isset($_POST['is_visible']) ? 1 : 0;
|
||||
if ($url === '' || $gid <= 0) {
|
||||
flash('网址和板块不能为空', 'err');
|
||||
break;
|
||||
}
|
||||
|
||||
$domain = domain_of($url);
|
||||
|
||||
// ---- 图标 ----
|
||||
// icon_auto 勾选 = 允许「全部更新」自动刷新图标(icon_custom=0)
|
||||
// 取消勾选 / 上传文件 / 给地址 = 自定义固定(icon_custom=1)
|
||||
$iconAuto = isset($_POST['icon_auto']);
|
||||
$custom = $iconAuto ? 0 : 1;
|
||||
$iconFile = trim((string)($_POST['icon'] ?? ''));
|
||||
|
||||
$uploaded = !empty($_FILES['icon_file']['tmp_name']) && is_uploaded_file((string)$_FILES['icon_file']['tmp_name']);
|
||||
if ($uploaded) {
|
||||
$bin = (string)@file_get_contents((string)$_FILES['icon_file']['tmp_name']);
|
||||
if ($bin === '' || strlen($bin) > 2 * 1024 * 1024) {
|
||||
flash('图标文件过大或为空(限 2MB)', 'err');
|
||||
} else {
|
||||
$new = save_custom_icon($bin, $domain);
|
||||
if ($new !== '') {
|
||||
$iconFile = $new;
|
||||
$custom = 1;
|
||||
} else {
|
||||
flash('图标文件无法解析,请换一张(PNG / JPG / SVG,建议正方形)', 'err');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$iconUrl = trim((string)($_POST['icon_url'] ?? ''));
|
||||
if ($iconUrl !== '') {
|
||||
$new = download_best_icon([norm_url($iconUrl)], $domain, 1);
|
||||
if ($new !== '') {
|
||||
$iconFile = $new;
|
||||
$custom = 1;
|
||||
} else {
|
||||
flash('自定义图标地址下载失败,请检查地址是否可直接访问', 'err');
|
||||
}
|
||||
}
|
||||
}
|
||||
// 网址换了但没换图标:清掉旧图标,避免张冠李戴
|
||||
if ($iconFile !== '' && $custom === 0 && !is_file(ICON_PATH . '/' . $iconFile)) {
|
||||
$iconFile = '';
|
||||
}
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
if ($id > 0) {
|
||||
$st = $pdo->prepare('UPDATE sites SET group_id=?, url=?, name=?, short_name=?, icon=?, is_visible=?, updated_at=? WHERE id=?');
|
||||
$st->execute([$gid, $url, $name, $short, $icon, $visible, $now, $id]);
|
||||
flash('已保存网站');
|
||||
$st = $pdo->prepare('UPDATE sites SET group_id=?, url=?, name=?, short_name=?, icon=?, icon_custom=?, is_visible=?, updated_at=? WHERE id=?');
|
||||
$st->execute([$gid, $url, $name, $short, $iconFile, $custom, $visible, $now, $id]);
|
||||
flash($custom ? '已保存(图标已锁定,不再自动更新)' : '已保存网站');
|
||||
} else {
|
||||
$max = (int)$pdo->query('SELECT COALESCE(MAX(sort_order),0)+1 FROM sites WHERE group_id=' . $gid)->fetchColumn();
|
||||
$st = $pdo->prepare('INSERT INTO sites (group_id,url,name,short_name,icon,sort_order,is_visible,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?,?)');
|
||||
$st->execute([$gid, $url, $name, $short, $icon, $max, $visible, $now, $now]);
|
||||
flash('已添加网站');
|
||||
$st = $pdo->prepare('INSERT INTO sites (group_id,url,name,short_name,icon,icon_custom,sort_order,is_visible,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?,?,?)');
|
||||
$st->execute([$gid, $url, $name, $short, $iconFile, $custom, $max, $visible, $now, $now]);
|
||||
flash($custom ? '已添加网站(图标已锁定,不再自动更新)' : '已添加网站');
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -56,7 +118,9 @@ try {
|
||||
break;
|
||||
}
|
||||
case 'site_toggle': {
|
||||
$pdo->prepare('UPDATE sites SET is_visible = 1 - is_visible WHERE id=?')->execute([post_id()]);
|
||||
$id = post_id();
|
||||
$pdo->prepare('UPDATE sites SET is_visible = 1 - is_visible WHERE id=?')->execute([$id]);
|
||||
$ajax = ['state' => state_of('sites', $id, 'is_visible')];
|
||||
flash('已切换显示状态');
|
||||
break;
|
||||
}
|
||||
@@ -90,7 +154,9 @@ try {
|
||||
break;
|
||||
}
|
||||
case 'group_toggle': {
|
||||
$pdo->prepare('UPDATE groups SET is_visible = 1 - is_visible WHERE id=?')->execute([post_id()]);
|
||||
$id = post_id();
|
||||
$pdo->prepare('UPDATE groups SET is_visible = 1 - is_visible WHERE id=?')->execute([$id]);
|
||||
$ajax = ['state' => state_of('groups', $id, 'is_visible')];
|
||||
flash('已切换显示状态');
|
||||
break;
|
||||
}
|
||||
@@ -129,7 +195,9 @@ try {
|
||||
break;
|
||||
}
|
||||
case 'engine_toggle': {
|
||||
$pdo->prepare('UPDATE engines SET is_active = 1 - is_active WHERE id=?')->execute([post_id()]);
|
||||
$id = post_id();
|
||||
$pdo->prepare('UPDATE engines SET is_active = 1 - is_active WHERE id=?')->execute([$id]);
|
||||
$ajax = ['state' => state_of('engines', $id, 'is_active')];
|
||||
flash('已切换启用状态');
|
||||
break;
|
||||
}
|
||||
@@ -146,6 +214,7 @@ try {
|
||||
'default_engine' => preg_replace('/[^a-z0-9\-_]/i', '', (string)($_POST['default_engine'] ?? '')),
|
||||
'primary_color' => preg_match('/^#[0-9a-fA-F]{3,8}$/', (string)($_POST['primary_color'] ?? '')) ? $_POST['primary_color'] : '#2F6BF7',
|
||||
'open_blank' => isset($_POST['open_blank']) ? '1' : '0',
|
||||
'icon_services' => isset($_POST['icon_services']) ? '1' : '0',
|
||||
];
|
||||
$st = $pdo->prepare('INSERT INTO settings (k,v) VALUES (?,?) ON CONFLICT(k) DO UPDATE SET v=excluded.v');
|
||||
foreach ($map as $k => $v) { $st->execute([$k, $v]); }
|
||||
@@ -172,9 +241,20 @@ try {
|
||||
flash('未知操作', 'err');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
if ($isAjax) {
|
||||
json_out(['ok' => false, 'msg' => $e->getMessage()]);
|
||||
}
|
||||
flash('操作失败:' . $e->getMessage(), 'err');
|
||||
}
|
||||
|
||||
if ($isAjax) {
|
||||
unset($_SESSION['flash']); // AJAX 不产生页面提示,避免下次进后台弹出过期提示
|
||||
if ($ajax === null) {
|
||||
json_out(['ok' => false, 'msg' => '该操作不支持 AJAX']);
|
||||
}
|
||||
json_out(['ok' => true] + $ajax);
|
||||
}
|
||||
|
||||
header('Location: ' . url($back));
|
||||
exit;
|
||||
|
||||
|
||||
+16
-16
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* 简航 SimpleNav —— 添加/编辑网站时自动抓取元信息(供后台 AJAX 调用)
|
||||
* 返回:{ ok, name, short, icon, url }
|
||||
* 流程:访问网址拿标题 → 解析页面/ manifest 里的高分辨率图标候选 → 择优下载到本地
|
||||
* 返回:{ ok, name, short, icon, icon_url, candidates, url }
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
require_login();
|
||||
send_no_cache();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
@@ -15,22 +17,20 @@ if ($url === '') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$meta = fetch_site_meta($url);
|
||||
$meta = fetch_site_meta($url);
|
||||
$domain = domain_of($meta['final_url'] ?: $url);
|
||||
$iconFile = '';
|
||||
if (!empty($meta['icon'])) {
|
||||
$iconFile = download_icon($meta['icon'], $domain);
|
||||
}
|
||||
if ($iconFile === '' && $domain !== '') {
|
||||
// 兜底再试一次根目录 favicon.ico
|
||||
$iconFile = download_icon('http://' . $domain . '/favicon.ico', $domain);
|
||||
}
|
||||
$iconFile = download_best_icon($meta['icons'], $domain);
|
||||
|
||||
$name = $meta['name'] !== '' ? $meta['name'] : ($meta['title'] !== '' ? $meta['title'] : $domain);
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'url' => $url,
|
||||
'name' => $meta['name'] !== '' ? $meta['name'] : ($meta['title'] !== '' ? $meta['title'] : $domain),
|
||||
'short' => $meta['name'] !== '' ? $meta['name'] : $domain,
|
||||
'icon' => $iconFile,
|
||||
'icon_url' => $iconFile !== '' ? icon_src($iconFile) : '',
|
||||
'ok' => true,
|
||||
'url' => $url,
|
||||
'final_url' => $meta['final_url'],
|
||||
'name' => $name,
|
||||
'short' => $name,
|
||||
'title' => $meta['title'],
|
||||
'icon' => $iconFile,
|
||||
'icon_url' => $iconFile !== '' ? icon_src($iconFile) : '',
|
||||
'candidates' => count($meta['icons']),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
+83
-21
@@ -5,6 +5,7 @@
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
require_login();
|
||||
send_no_cache();
|
||||
|
||||
$pdo = db();
|
||||
$p = isset($_GET['p']) ? (string)$_GET['p'] : 'sites';
|
||||
@@ -26,12 +27,35 @@ function flash_html(?array $f): string
|
||||
return '<div class="' . $cls . '">' . e($f['m']) . '</div>';
|
||||
}
|
||||
|
||||
function toggle_form(string $action, int $id): string
|
||||
/** 眼睛(显示)/ 斜杠眼(隐藏)图标 —— 用内联 SVG,避免 emoji 字体差异导致显示成方块 */
|
||||
function eye_svg(bool $on): string
|
||||
{
|
||||
return '<form method="post" action="' . e(url('admin/actions.php')) . '" class="inline">'
|
||||
. csrf_field() . '<input type="hidden" name="action" value="' . e($action) . '">'
|
||||
$slash = $on ? '' : '<path d="M3 3l18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>';
|
||||
return '<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true" fill="currentColor">'
|
||||
. '<path d="M12 5c-5.5 0-9.6 4.3-11 7 1.4 2.7 5.5 7 11 7s9.6-4.3 11-7c-1.4-2.7-5.5-7-11-7zm0 12a5 5 0 110-10 5 5 0 010 10z"/>'
|
||||
. '<circle cx="12" cy="12" r="2.6"/>'
|
||||
. $slash
|
||||
. '</svg>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 显隐切换按钮:表单自带 ajax=1,前端原地切换、不跳页;
|
||||
* 即使浏览器禁用 JS,表单也会正常提交并回到当前列表页(p 已带上)。
|
||||
*/
|
||||
function toggle_form(string $action, int $id, int $state, string $p = ''): string
|
||||
{
|
||||
$on = $state === 1;
|
||||
return '<form method="post" action="' . e(url('admin/actions.php')) . '" class="inline js-toggle" data-id="' . $id . '">'
|
||||
. csrf_field()
|
||||
. '<input type="hidden" name="action" value="' . e($action) . '">'
|
||||
. '<input type="hidden" name="id" value="' . $id . '">'
|
||||
. '<button class="ico-btn" title="切换显示">' . "\u{1F441}" . '</button></form>';
|
||||
. '<input type="hidden" name="p" value="' . e($p) . '">'
|
||||
. '<input type="hidden" name="ajax" value="1">'
|
||||
. '<button type="submit" class="ico-btn toggle' . ($on ? ' on' : '') . '"'
|
||||
. ' data-on="' . ($on ? '1' : '0') . '"'
|
||||
. ' title="' . ($on ? '当前:显示中(点击隐藏)' : '当前:已隐藏(点击显示)') . '">'
|
||||
. eye_svg($on)
|
||||
. '</button></form>';
|
||||
}
|
||||
|
||||
function move_form(string $action, int $id, string $dir, string $label, string $p): string
|
||||
@@ -48,15 +72,17 @@ ob_start();
|
||||
|
||||
if ($p === 'sites'):
|
||||
$rows = $pdo->query('SELECT s.*, g.name AS gname FROM sites s JOIN groups g ON g.id=s.group_id ORDER BY g.sort_order, g.id, s.sort_order, s.id')->fetchAll();
|
||||
$customCount = 0;
|
||||
foreach ($rows as $rr) { if ((int)($rr['icon_custom'] ?? 0) === 1) { $customCount++; } }
|
||||
?>
|
||||
<?= flash_html($flash) ?>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<h2>新增 / 编辑网站</h2>
|
||||
<button type="button" class="btn ghost" id="btn-update-all" data-url="<?= e(url('admin/update_all.php')) ?>">⟳ 全部更新(图标+名称)</button>
|
||||
<button type="button" class="btn ghost" id="btn-update-all" data-url="<?= e(url('admin/update_all.php')) ?>">⟳ 全部更新(名称 + 自动图标)</button>
|
||||
</div>
|
||||
<form method="post" action="<?= e(url('admin/actions.php')) ?>" class="grid-form" id="site-form">
|
||||
<form method="post" action="<?= e(url('admin/actions.php')) ?>" class="grid-form" id="site-form" enctype="multipart/form-data">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="action" value="site_save">
|
||||
<input type="hidden" name="id" id="f-id" value="0">
|
||||
@@ -74,12 +100,32 @@ if ($p === 'sites'):
|
||||
<button type="button" class="btn ghost" id="btn-fetch" data-url="<?= e(url('admin/fetch_meta.php')) ?>">自动获取</button>
|
||||
</span>
|
||||
</label>
|
||||
<label>网站名称(自动)
|
||||
<label>网站名称(自动抓取)
|
||||
<input type="text" name="name" id="f-name" placeholder="自动抓取">
|
||||
</label>
|
||||
<label>简称(页面显示,手动)
|
||||
<input type="text" name="short_name" id="f-short" placeholder="如:知乎">
|
||||
</label>
|
||||
|
||||
<div class="span2 icon-field">
|
||||
<div class="icon-field-preview">
|
||||
<span class="icon-preview" id="f-icon-preview"><span class="ph">无</span></span>
|
||||
</div>
|
||||
<div class="icon-field-body">
|
||||
<div class="icon-field-title">图标</div>
|
||||
<input type="text" name="icon_url" id="f-icon-url" placeholder="自定义图标图片地址(http/https),留空则用自动获取的">
|
||||
<div class="row icon-row2">
|
||||
<input type="file" name="icon_file" id="f-icon-file" accept="image/png,image/jpeg,image/gif,image/webp,image/svg+xml,image/x-icon,.svg,.ico">
|
||||
<label class="chk"><input type="checkbox" name="icon_auto" id="f-icon-auto" checked> 允许自动更新图标</label>
|
||||
</div>
|
||||
<p class="hint">
|
||||
优先级:<b>上传文件</b> > <b>自定义地址</b> > 「自动获取」抓到的图。<br>
|
||||
选择上传或填写地址后会自动取消勾选「允许自动更新图标」,该网站图标此后不再被「全部更新」覆盖;
|
||||
勾回去即可恢复自动。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="chk"><input type="checkbox" name="is_visible" id="f-visible" checked> 显示</label>
|
||||
<div class="span2 form-actions">
|
||||
<button type="submit" class="btn primary">保存</button>
|
||||
@@ -90,24 +136,31 @@ if ($p === 'sites'):
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-head"><h2>网站列表(<?= count($rows) ?>)</h2></div>
|
||||
<table class="tbl">
|
||||
<div class="card-head">
|
||||
<h2>网站列表(<?= count($rows) ?>)</h2>
|
||||
<span class="hint">其中 <?= $customCount ?> 个使用自定义图标(不会自动更新)</span>
|
||||
</div>
|
||||
<div class="tbl-wrap"><table class="tbl">
|
||||
<thead><tr><th>图标</th><th>简称(展示)</th><th>名称</th><th>网址</th><th>板块</th><th>显示</th><th>排序</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($rows as $r): $label = $r['short_name'] !== '' ? $r['short_name'] : ($r['name'] !== '' ? $r['name'] : domain_of($r['url'])); $src = icon_src($r['icon']); ?>
|
||||
<tr>
|
||||
<td><?php if ($src): ?><img class="mini" src="<?= e($src) ?>" alt=""><?php else: ?><span class="mini letter" style="background:<?= e(letter_color($label)) ?>"><?= e(mb_substr($label, 0, 1)) ?></span><?php endif; ?></td>
|
||||
<td>
|
||||
<?php if ($src): ?><img class="mini" src="<?= e($src) ?>" alt=""><?php else: ?><span class="mini letter" style="background:<?= e(letter_color($label)) ?>"><?= e(mb_substr($label, 0, 1)) ?></span><?php endif; ?>
|
||||
<?php if ((int)($r['icon_custom'] ?? 0) === 1): ?><span class="badge" title="用户自定义图标,不会被自动更新覆盖">自定义</span><?php endif; ?>
|
||||
</td>
|
||||
<td><?= e($label) ?></td>
|
||||
<td class="muted"><?= e($r['name']) ?></td>
|
||||
<td class="muted ell"><a href="<?= e($r['url']) ?>" target="_blank" rel="noopener"><?= e($r['url']) ?></a></td>
|
||||
<td><?= e($r['gname']) ?></td>
|
||||
<td><?= toggle_form('site_toggle', (int)$r['id']) ?></td>
|
||||
<td><?= toggle_form('site_toggle', (int)$r['id'], (int)$r['is_visible']) ?></td>
|
||||
<td class="nowrap"><?= move_form('site_move', (int)$r['id'], 'up', '上移', '') . move_form('site_move', (int)$r['id'], 'down', '下移', '') ?></td>
|
||||
<td class="nowrap">
|
||||
<button type="button" class="ico-btn edit-site"
|
||||
data-id="<?= (int)$r['id'] ?>" data-group="<?= (int)$r['group_id'] ?>"
|
||||
data-url="<?= e($r['url']) ?>" data-name="<?= e($r['name']) ?>"
|
||||
data-short="<?= e($r['short_name']) ?>" data-icon="<?= e($r['icon']) ?>"
|
||||
data-icon-url="<?= e($src) ?>" data-custom="<?= (int)($r['icon_custom'] ?? 0) ?>"
|
||||
data-visible="<?= (int)$r['is_visible'] ?>" title="编辑">✎</button>
|
||||
<form method="post" action="<?= e(url('admin/actions.php')) ?>" class="inline" onsubmit="return confirm('确定删除该网站?');">
|
||||
<?= csrf_field() ?><input type="hidden" name="action" value="site_delete">
|
||||
@@ -118,7 +171,7 @@ if ($p === 'sites'):
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</table></div>
|
||||
</section>
|
||||
<?php
|
||||
|
||||
@@ -143,7 +196,7 @@ elseif ($p === 'groups'): ?>
|
||||
</form>
|
||||
</section>
|
||||
<section class="card">
|
||||
<table class="tbl">
|
||||
<div class="tbl-wrap"><table class="tbl">
|
||||
<thead><tr><th>名称</th><th>展示方式</th><th>网站数</th><th>显示</th><th>排序</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($groups as $g): $cnt = (int)$pdo->query('SELECT COUNT(*) FROM sites WHERE group_id=' . (int)$g['id'])->fetchColumn(); ?>
|
||||
@@ -151,7 +204,7 @@ elseif ($p === 'groups'): ?>
|
||||
<td><?= e($g['name']) ?></td>
|
||||
<td><?= $g['display'] === 'tabs' ? '合集标签页' : '普通网格' ?></td>
|
||||
<td><?= $cnt ?></td>
|
||||
<td><?= toggle_form('group_toggle', (int)$g['id']) ?></td>
|
||||
<td><?= toggle_form('group_toggle', (int)$g['id'], (int)$g['is_visible'], 'groups') ?></td>
|
||||
<td class="nowrap"><?= move_form('group_move', (int)$g['id'], 'up', '上移', 'groups') . move_form('group_move', (int)$g['id'], 'down', '下移', 'groups') ?></td>
|
||||
<td class="nowrap">
|
||||
<button type="button" class="ico-btn edit-group" data-id="<?= (int)$g['id'] ?>" data-name="<?= e($g['name']) ?>" data-display="<?= e($g['display']) ?>" data-visible="<?= (int)$g['is_visible'] ?>">✎</button>
|
||||
@@ -163,7 +216,7 @@ elseif ($p === 'groups'): ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</table></div>
|
||||
</section>
|
||||
<?php
|
||||
|
||||
@@ -187,20 +240,27 @@ elseif ($p === 'engines'): ?>
|
||||
<?php foreach ($SUGGEST_TYPES as $t): ?><option value="<?= e($t) ?>"><?= e($t) ?></option><?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
<label class="chk"><input type="checkbox" name="is_active" id="e-active"> 启用(显示在首页)</label>
|
||||
<label class="chk"><input type="checkbox" name="is_active" id="e-active"> 启用(显示在首页顶部)</label>
|
||||
<div class="span2 form-actions"><button class="btn primary">保存</button><button type="button" class="btn ghost" id="e-reset">清空</button></div>
|
||||
</form>
|
||||
</section>
|
||||
<section class="card">
|
||||
<table class="tbl">
|
||||
<thead><tr><th>名称</th><th>搜索地址</th><th>联想类型</th><th>启用</th><th>排序</th><th>操作</th></tr></thead>
|
||||
<div class="card-head">
|
||||
<h2>搜索引擎列表</h2>
|
||||
<span class="hint">点最右侧「眼睛」图标即在该行原地切换,不会跳页</span>
|
||||
</div>
|
||||
<div class="tbl-wrap"><table class="tbl">
|
||||
<thead><tr><th>名称</th><th>搜索地址</th><th>联想类型</th><th>前台显示</th><th>排序</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($engines as $en): ?>
|
||||
<tr>
|
||||
<td><span style="color:<?= e($en['color']) ?>">■</span> <?= e($en['name']) ?> <span class="muted">(<?= e($en['slug']) ?>)</span></td>
|
||||
<td class="muted ell"><?= e($en['search_url']) ?></td>
|
||||
<td class="muted"><?= e($en['suggest_type']) ?></td>
|
||||
<td><?= $en['is_active'] ? '<span class="ok-dot">已启用</span>' : '<span class="muted">未启用</span>' ?> <?= toggle_form('engine_toggle', (int)$en['id']) ?></td>
|
||||
<td class="nowrap">
|
||||
<span class="state <?= $en['is_active'] ? 'on' : 'off' ?> js-state" data-on-text="已显示" data-off-text="已隐藏"><?= $en['is_active'] ? '已显示' : '已隐藏' ?></span>
|
||||
<?= toggle_form('engine_toggle', (int)$en['id'], (int)$en['is_active'], 'engines') ?>
|
||||
</td>
|
||||
<td class="nowrap"><?= move_form('engine_move', (int)$en['id'], 'up', '上移', 'engines') . move_form('engine_move', (int)$en['id'], 'down', '下移', 'engines') ?></td>
|
||||
<td class="nowrap">
|
||||
<button type="button" class="ico-btn edit-engine"
|
||||
@@ -215,8 +275,8 @@ elseif ($p === 'engines'): ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="hint">提示:联想接口需填写对应平台的地址,解析类型可选 bing_osjson / baidu_sugrec / google_firefox / sogou_ajaj / so360 / ddg。</p>
|
||||
</table></div>
|
||||
<p class="hint">提示:联想接口需填写对应平台的地址,解析类型可选 bing_osjson / baidu_sugrec / google_firefox / sogou_ajaj / so360 / ddg。「前台显示」为该引擎是否出现在首页顶部搜索框上方的切换条里。</p>
|
||||
</section>
|
||||
<?php
|
||||
|
||||
@@ -238,6 +298,8 @@ else: // settings ?>
|
||||
</label>
|
||||
<label>主题色<input type="text" name="primary_color" value="<?= e(setting('primary_color', '#2F6BF7')) ?>"></label>
|
||||
<label class="chk"><input type="checkbox" name="open_blank" <?= setting('open_blank', '1') === '1' ? 'checked' : '' ?>> 搜索结果新窗口打开</label>
|
||||
<label class="chk"><input type="checkbox" name="icon_services" <?= setting('icon_services', '1') === '1' ? 'checked' : '' ?>> 联网搜索高清图标(第三方聚合服务)</label>
|
||||
<p class="hint span2">勾上后,当站点自身没有提供高清图标时,会依次尝试 icon.horse、Yandex 图标服务;关掉则只用站点自己声明的图标。</p>
|
||||
<div class="span2 form-actions"><button class="btn primary">保存设置</button></div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
+22
-15
@@ -1,51 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* 简航 SimpleNav —— 一键“全部更新”(分批)。
|
||||
* 批量刷新每个网站的图标与名称;**保留用户自定义的简称 short_name 不变**。
|
||||
* 批量刷新每个网站的名称与图标;
|
||||
* · **保留** 用户自定义简称 short_name
|
||||
* · **跳过** 用户自定义图标(icon_custom=1)——只刷新名称
|
||||
* 前端按 offset 分批调用,避免一次请求超时。
|
||||
* 返回:{ done, total, offset, updated, failed }
|
||||
* 返回:{ done, total, offset, updated, skipped, failed }
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/_auth.php';
|
||||
require_login();
|
||||
send_no_cache();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
set_time_limit(30);
|
||||
set_time_limit(90);
|
||||
|
||||
$offset = max(0, (int)($_GET['offset'] ?? 0));
|
||||
$limit = min(12, max(1, (int)($_GET['limit'] ?? 6)));
|
||||
$limit = min(12, max(1, (int)($_GET['limit'] ?? 3)));
|
||||
$pdo = db();
|
||||
|
||||
$total = (int)$pdo->query('SELECT COUNT(*) FROM sites')->fetchColumn();
|
||||
$rows = $pdo->query('SELECT id, url FROM sites ORDER BY id LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
|
||||
$rows = $pdo->query('SELECT id, url, icon_custom FROM sites ORDER BY id LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
|
||||
|
||||
$updated = 0;
|
||||
$failed = 0;
|
||||
$skipped = 0;
|
||||
$failed = 0;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$url = norm_url((string)$row['url']);
|
||||
$custom = (int)$row['icon_custom'] === 1;
|
||||
|
||||
$meta = fetch_site_meta($url);
|
||||
$domain = domain_of($meta['final_url'] ?: $url);
|
||||
$name = $meta['name'] !== '' ? $meta['name'] : $meta['title'];
|
||||
$iconFile = '';
|
||||
if (!empty($meta['icon'])) {
|
||||
$iconFile = download_icon($meta['icon'], $domain);
|
||||
}
|
||||
if ($iconFile === '' && $domain !== '') {
|
||||
$iconFile = download_icon('http://' . $domain . '/favicon.ico', $domain);
|
||||
}
|
||||
|
||||
$sets = ['updated_at=?'];
|
||||
$args = [$now];
|
||||
if ($name !== '') { $sets[] = 'name=?'; $args[] = $name; }
|
||||
if ($iconFile !== '') { $sets[] = 'icon=?'; $args[] = $iconFile; }
|
||||
|
||||
if ($custom) {
|
||||
// 用户自定义图标:绝不覆盖
|
||||
$skipped++;
|
||||
} else {
|
||||
$iconFile = download_best_icon($meta['icons'], $domain);
|
||||
if ($iconFile !== '') { $sets[] = 'icon=?'; $args[] = $iconFile; }
|
||||
if ($iconFile !== '' || $name !== '') { $updated++; } else { $failed++; }
|
||||
}
|
||||
// 注意:这里绝不修改 short_name(用户自定义简称)
|
||||
|
||||
$args[] = (int)$row['id'];
|
||||
try {
|
||||
$pdo->prepare('UPDATE sites SET ' . implode(',', $sets) . ' WHERE id=?')->execute($args);
|
||||
if ($iconFile !== '' || $name !== '') { $updated++; } else { $failed++; }
|
||||
} catch (Throwable $e) {
|
||||
$failed++;
|
||||
}
|
||||
@@ -57,5 +63,6 @@ echo json_encode([
|
||||
'total' => $total,
|
||||
'offset' => $next,
|
||||
'updated' => $updated,
|
||||
'skipped' => $skipped,
|
||||
'failed' => $failed,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
Reference in New Issue
Block a user