Files
SimpleNav/admin/fetch_meta.php
T
laoyang 6e83cc3ecc feat: 简航 SimpleNav 个人网站导航系统(PHP + SQLite)
- 前台:搜索引擎切换+联想下拉、网格板块(常用/工具)、合集标签页
- 后台:初始化/登录、网站/板块/引擎增删改、上下移排序
- 添加网站自动抓取名称与图标(存储于服务器),支持自定义简称
- 一键全部更新(批量刷新图标+名称,保留自定义简称)
- 搜索联想服务端代理(必应/百度/谷歌/搜狗/360/DuckDuckGo)
- 零依赖:原生 CSS/JS,PDO SQLite
2026-09-28 15:48:35 +08:00

37 lines
1.2 KiB
PHP

<?php
/**
* 简航 SimpleNav —— 添加/编辑网站时自动抓取元信息(供后台 AJAX 调用)
* 返回:{ ok, name, short, icon, url }
*/
declare(strict_types=1);
require_once __DIR__ . '/_auth.php';
require_login();
header('Content-Type: application/json; charset=utf-8');
$url = isset($_GET['url']) ? norm_url((string)$_GET['url']) : '';
if ($url === '') {
echo json_encode(['ok' => false, 'msg' => '缺少网址'], JSON_UNESCAPED_UNICODE);
exit;
}
$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);
}
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) : '',
], JSON_UNESCAPED_UNICODE);