同步插件源代码并补齐标准项目文件

This commit is contained in:
XIGE
2026-11-26 15:25:15 +08:00
parent bb31e0c4dd
commit 384652c551
19 changed files with 6702 additions and 1 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Runtime data, cache and logs
data/
cache/
*.log
# Backups and temporary files
备份/
*.bak
*.tmp
.DS_Store
# Environment and secrets
.env
.env.*
*key*.txt
credentials*.json
# Editor and build artifacts
.idea/
.vscode/
node_modules/
vendor/
dist/
build/

51
CHANGELOG.md Normal file
View File

@@ -0,0 +1,51 @@
# NiceQuote 更新日志
> 本文件记录本插件的所有修改与变化。本次整理(2026-11-22)为规范化记录起点。
## 插件信息
- 名称:NiceQuote
- 版本:2.10.0
- 作者:XIGE
- 说明:文章、独立页面、评论、用户、分类、标签前端引用
## 记录格式约定
每次修改按如下格式在**最上方**追加一条记录(新的在上):
```
## YYYY-MM-DD · 版本号 —— 一句话概述
- 改动点 1
- 改动点 2
- 影响范围 / 注意事项(若有)
- 对应备份:备份/YYYY-MM-DD-修改内容简短说明修改前/
```
## 2026-11-22 · 2.10.0 —— 补齐头部版本与链接
- `Plugin.php` 文件头注释(Typecho 后台插件信息读取的第一段)补齐 `@version 2.10.0`、`@link https://www.shitoucuo.com/`
- 版本号取自本插件更新日志既有版本(类注释中已有同值),后台插件列表版本显示不再为空
- 对应备份:`备份/2026-11-22-补版本和链接修改前/`
## 2026-11-22 · 2.10.0 —— PHP 8.5 弃用变量修复(线上报错)
- `Remote.php` 第 379-380 行:`$http_response_header` 在 PHP 8.5 起被弃用(The predefined locally scoped $http_response_header variable is deprecated),改用 `http_get_last_response_headers()`(PHP 8.4+ 提供)
- 兼容写法:`function_exists('http_get_last_response_headers')` 时用新函数,否则回退旧变量(仅旧版 PHP 执行该分支,不影响 8.5)
- 影响:仅抓取网页解析 content-type 的响应头读取逻辑,功能不变
- 对应备份:`备份/2026-11-22-PHP85响应头弃用修复修改前/`
## 2026-11-22 · 2.10.0 —— 统一作者与链接
- `Plugin.php` 头部 `@author` 统一为「石头厝」
- `@link` 统一为 `https://www.shitoucuo.com/`
- 影响范围:仅头部元信息,不涉及功能代码
- 对应备份:`备份/2026-11-22-统一作者和链接修改前/`
---
## 2026-11-22 · 2.10.0 —— 建立规范化备份与更新日志
- 建立 `备份/` 文件夹并生成本次整理前全量备份 `备份/2026-11-22-规范化整理修改前/`
- 创建本更新日志,作为后续所有修改的记录起点
- 说明:本次仅做规范化整理,未改动插件功能代码

19
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,19 @@
# 贡献指南
欢迎对本项目提出改进建议或提交代码。
## 提交前检查
- 仅提交插件实现代码、静态资源与必要文档;不要提交 `data/`、`cache/`、调试日志、备份目录或 API Key 等敏感信息。
- 变更涉及 Typecho 钩子或 PHP 版本兼容时,请确认兼容 Typecho 1.3 与 PHP 8.5。
- 影响用户配置或后台展示的改动,请同步更新 `README.md` 与 `CHANGELOG.md`。
## 提交流程
1. Fork 仓库并创建功能分支。
2. 完成修改后提交 Pull Request,说明改动目的与影响范围。
3. 重要变更请补充变更记录。
## 问题反馈
请通过仓库 Issue 反馈问题,并附上插件版本、Typecho / PHP 版本与复现步骤。

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 XIGE / 石头厝
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

516
Manage.php Normal file

File diff suppressed because it is too large Load Diff

1228
Plugin.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +1,43 @@
# NiceQuote
# NiceQuote(前端引用插件)
> 仓库:`NiceQuote` · 类型:Typecho 插件 · 版本:`2.10.0` · 作者:XIGE / 石头厝
支持在前端引用文章、独立页面、评论、用户、分类与标签的 Typecho 插件。本仓库仅包含插件实现代码与静态资源,不包含运行时缓存、备份或环境配置。
## 功能
- 前端引用:文章、独立页面、评论、用户、分类、标签。
- 提供远程抓取与内容解析能力,并对 PHP 8.5 做了兼容处理(响应头读取改用 `http_get_last_response_headers()`,旧版 PHP 自动回退)。
- 后台管理面板与前端渲染分离,管理逻辑与渲染逻辑分别位于 `Manage.php`、`Renderer.php`。
- 完整版本与修复记录见 [CHANGELOG.md](CHANGELOG.md)。
## 目录结构
- `Plugin.php` —— 插件入口、钩子注册与元数据
- `Manage.php` —— 后台管理面板
- `Remote.php` —— 远程内容抓取与响应处理
- `Renderer.php` —— 引用内容渲染
- `Scanner.php` —— 内容扫描与解析
- `post.php` —— 前端引用入口
- `assets/` —— 后台与卡片样式/脚本
- `img/` —— 分类、标签等图标资源
> 运行时生成的 `cache/` 目录不随仓库分发。
## 安装与使用
1. 将本仓库目录复制到 Typecho 站点的 `usr/plugins/NiceQuote/`。
2. 在 Typecho 后台「插件」管理中启用插件。
3. 按插件设置页配置引用方式,并在文章或页面中使用对应的引用入口。
## 开发与贡献
详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
## 授权
授权条款见 [LICENSE](LICENSE)(MIT License)。第三方组件版权归各自作者所有。
## 变更记录
详见 [CHANGELOG.md](CHANGELOG.md)。

839
Remote.php Normal file

File diff suppressed because it is too large Load Diff

632
Renderer.php Normal file

File diff suppressed because it is too large Load Diff

505
Scanner.php Normal file

File diff suppressed because it is too large Load Diff

716
assets/admin.css Normal file

File diff suppressed because it is too large Load Diff

1137
assets/admin.js Normal file

File diff suppressed because it is too large Load Diff

185
assets/card.css Normal file
View File

@@ -0,0 +1,185 @@
/*
* NiceQuote 2.5 卡片样式
*
* 三种使用场景共用一份:
* 1. 内嵌模式(inline):卡片直接写在正文里,字号、字体、行高全部继承站点主题;
* 2. iframe 模式:body.nq-standalone 下的独立文档,需要自带字体与配色;
* 3. 后台预览:同样走 iframe。
*
* 卡片均为「标题 + 摘要 + 日期」三行结构,不显示左侧缩略图。
*
* 所有类名都以 nq- 开头,不会和主题的 .quote / .card 撞车。
*/
.nq-card {
--nq-bg: rgba(127, 127, 127, .07);
--nq-line: rgba(127, 127, 127, .26);
--nq-thumb: rgba(127, 127, 127, .14);
--nq-muted: rgba(127, 127, 127, .95);
position: relative;
display: flex;
align-items: center;
gap: 12px;
box-sizing: border-box;
margin: 1.1em 0;
padding: 12px 14px;
border: 1px solid var(--nq-line);
border-radius: var(--nq-radius, 10px);
background: var(--nq-bg);
color: inherit;
font-size: inherit;
line-height: 1.5;
text-decoration: none;
transition: border-color .18s ease, background .18s ease;
}
.nq-card:hover,
.nq-card:focus-visible {
border-color: var(--nq-accent, #c0580c);
outline: none;
}
/* 外部链接卡片没有缩略图,回到单列三行 */
.nq-card.nq-url {
display: block;
}
/* 用户引用靠左:主题常给引用块设 text-align 居中,这里强制回左对齐 */
.nq-card.nq-user {
text-align: left;
}
.nq-body {
flex: 1 1 auto;
display: flex;
flex-direction: column;
gap: 3px;
min-width: 0;
}
.nq-url .nq-body {
gap: 4px;
}
.nq-title {
display: block;
color: var(--nq-accent, #c0580c);
font-weight: 500;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
line-clamp: 1;
word-break: break-word;
}
/* 外部链接没有缩略图占位,标题给两行 */
.nq-url .nq-title {
-webkit-line-clamp: 2;
line-clamp: 2;
}
.nq-desc {
display: -webkit-box;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
font-size: .92em;
opacity: .82;
word-break: break-word;
}
.nq-meta {
overflow: hidden;
color: var(--nq-muted);
font-size: .8em;
white-space: nowrap;
text-overflow: ellipsis;
}
.nq-missing {
display: inline-block;
padding: 2px 8px;
border: 1px dashed var(--nq-line, rgba(127, 127, 127, .4));
border-radius: 6px;
opacity: .7;
font-size: .9em;
}
/* ---------- 连续多张引用:并作一条纵向列表 ---------- */
/* 不加序号、不加「引用 N 篇」标题,只留卡片之间的间距 */
.nq-list {
--nq-line: rgba(127, 127, 127, .26);
--nq-muted: rgba(127, 127, 127, .95);
display: flex;
flex-direction: column;
gap: 8px;
margin: 1.2em 0;
padding: 0;
font-size: inherit;
line-height: 1.5;
}
.nq-list .nq-card {
margin: 0;
}
.nq-list .nq-frame {
margin: 0;
}
/* 明确指定配色时,卡片自己扛起背景与文字色 */
.nq-card.nq-skin-dark {
--nq-bg: rgba(24, 24, 24, .92);
--nq-line: rgba(255, 255, 255, .16);
--nq-thumb: rgba(255, 255, 255, .1);
--nq-muted: rgba(255, 255, 255, .62);
color: #e4e4e4;
}
.nq-card.nq-skin-light {
--nq-bg: rgba(255, 255, 255, .94);
--nq-line: rgba(0, 0, 0, .12);
--nq-thumb: rgba(0, 0, 0, .06);
--nq-muted: rgba(0, 0, 0, .55);
color: #333;
}
/* iframe 独立文档 */
body.nq-standalone {
margin: 0;
padding: 0;
overflow: hidden;
background: transparent;
color: #333;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
"Hiragino Sans GB", "Microsoft YaHei", sans-serif;
font-size: 15px;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
body.nq-standalone .nq-card {
margin: 0;
}
body.nq-standalone[data-skin="auto"] {
--nq-bg: #fff;
--nq-line: rgba(0, 0, 0, .12);
--nq-thumb: rgba(0, 0, 0, .06);
--nq-muted: rgba(0, 0, 0, .55);
background: #fff;
}
body.nq-standalone[data-skin="dark"] {
--nq-bg: #191919;
--nq-line: rgba(255, 255, 255, .16);
--nq-thumb: rgba(255, 255, 255, .1);
--nq-muted: rgba(255, 255, 255, .62);
background: #191919;
color: #e4e4e4;
}
body.nq-standalone[data-skin="light"] {
--nq-bg: #fff;
--nq-line: rgba(0, 0, 0, .12);
--nq-muted: rgba(0, 0, 0, .55);
background: #fff;
color: #333;
}
@media (prefers-color-scheme: dark) {
body.nq-standalone[data-skin="auto"] {
--nq-bg: #191919;
--nq-line: rgba(255, 255, 255, .16);
--nq-thumb: rgba(255, 255, 255, .1);
--nq-muted: rgba(255, 255, 255, .62);
background: #191919;
color: #e4e4e4;
}
}
@media (max-width: 480px) {
.nq-card {
gap: 10px;
padding: 10px 12px;
}
}

598
assets/manage.css Normal file

File diff suppressed because it is too large Load Diff

77
assets/manage.js Normal file
View File

@@ -0,0 +1,77 @@
/*
* NiceQuote 后台「引用管理」
*
* 只做两件事:危险操作二次确认、深色模式跟随。
* 其余(筛选、分页、修改、删除)都是普通链接 / 表单 + 302,不依赖脚本。
*/
(function () {
'use strict';
/* ---------- 深色跟随 ----------
* NewAdmin 的 .dark 加在 #newadmin 上,而面板页的内容不在它的子树里,
* 光靠 CSS 祖先选择器吃不到,这里读一次类名把 .nq-dark 补到 .nq-adm 上。 */
(function () {
var root = document.querySelector('.nq-adm');
if (!root) {
return;
}
function isDark() {
var admin = document.getElementById('newadmin');
if (admin && /(^|\s)dark(\s|$)/.test(admin.className)) {
return true;
}
if (document.documentElement.classList.contains('dark')
|| document.body.classList.contains('dark')) {
return true;
}
if (admin) {
return false;
}
try {
return window.matchMedia('(prefers-color-scheme: dark)').matches;
} catch (e) {
return false;
}
}
function sync() {
root.classList.toggle('nq-dark', isDark());
}
sync();
var admin = document.getElementById('newadmin');
if (admin && window.MutationObserver) {
new MutationObserver(sync).observe(admin, { attributes: true, attributeFilter: ['class'] });
}
try {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', sync);
} catch (e) {
// 老浏览器没有 addEventListener,忽略
}
})();
/* ---------- 危险操作二次确认 ---------- */
document.addEventListener('submit', function (event) {
var form = event.target;
if (!form || form.tagName !== 'FORM') {
return;
}
var message = form.getAttribute('data-confirm');
if (message && !window.confirm(message)) {
event.preventDefault();
}
});
})();

25
img/cate.svg Normal file
View File

@@ -0,0 +1,25 @@
<?xml version="1.0" ?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 120 120" id="Layer_1" version="1.1" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style type="text/css">
.st0{fill:#E5707E;}
.st1{opacity:0.1;}
.st2{fill:#F9C83B;}
</style>
<path class="st0" d="M99.3,60.4c0,4.7-0.9,9.3-3.2,13.3c-4,6.9,3.3,17.6,2.3,20.5c-1,2.8-18-4.4-22.9-2.6 c-5.2,1.9-10.3,2.6-16.4,2.6c-22.2,0-40.3-15.1-40.3-33.8s18-33.8,40.3-33.8S99.3,41.7,99.3,60.4z"/>
<path class="st1" d="M77.9,90.7c-5.2,1.9-10.3,2.6-16.4,2.6c-22.2,0-40.3-15.1-40.3-33.8c0-13.8,9.9-25.7,24.1-31 c-15.5,4.7-26.5,17.2-26.5,31.8c0,18.7,18,33.8,40.3,33.8c6,0,11.2-0.7,16.4-2.6c4.9-1.8,21.9,5.5,22.9,2.6c0-0.1,0-0.1,0.1-0.2 C93.3,93.6,81.9,89.3,77.9,90.7z"/>
<g class="st1">
<polygon points="57.9,44.7 62.1,51.9 70.2,53.7 64.2,59.5 65.5,68.2 57.9,64.3 50.3,68.2 51.7,59.8 45.6,53.7 53.9,51.8 "/>
<g>
<polygon points="37.7,51.5 40.6,56.6 46.4,57.9 42.1,62 43.1,68.2 37.7,65.4 32.2,68.2 33.3,62.2 28.9,57.9 34.8,56.6 "/>
<polygon points="78.1,51.5 81.1,56.6 86.9,57.9 82.6,62 83.6,68.2 78.1,65.4 72.7,68.2 73.8,62.2 69.4,57.9 75.3,56.6 "/>

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
img/none.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

21
img/tag.svg Normal file
View File

@@ -0,0 +1,21 @@
<?xml version="1.0" ?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 120 120" id="Layer_1" version="1.1" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style type="text/css">
.st0{fill:#9FD8DF;}
.st1{opacity:0.1;}
.st2{fill:#FF7171;}
</style>
<g>
<path class="st0" d="M60.9,29.8L35.8,18.9c-5.3-2.3-11.4,0.6-13,6.2l-7.2,26.4c-0.4,1.6-0.3,3.2,0.4,4.7l21.6,45.2 c1.2,2.6,4.3,3.6,6.9,2.4l39-18.7c2.6-1.2,3.6-4.3,2.4-6.9L64.3,33C63.6,31.6,62.4,30.4,60.9,29.8z M38.3,40.6 c-2.9,1.4-6.3,0.2-7.7-2.7c-1.4-2.9-0.2-6.3,2.7-7.7s6.3-0.2,7.7,2.7C42.4,35.8,41.1,39.3,38.3,40.6z"/>
<g class="st1">
<path d="M84.8,82.6l-39,18.7c-2.6,1.2-5.6,0.1-6.9-2.4L17.3,53.7c-0.7-1.5-0.8-3.1-0.4-4.7l7.2-26.4c0.1-0.2,0.1-0.4,0.2-0.6 c-0.7,0.9-1.2,1.9-1.5,3.1l-7.2,26.4c-0.4,1.6-0.3,3.2,0.4,4.7l21.6,45.2c1.2,2.6,4.3,3.6,6.9,2.4l39-18.7 c1.5-0.7,2.5-2.1,2.8-3.6C85.9,81.9,85.4,82.3,84.8,82.6z"/>
</g>

After

Width:  |  Height:  |  Size: 2.0 KiB

66
post.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
/**
* iframe 独立渲染页
*
* 由 Plugin::route() 校验参数后 include,也可单独访问:
* /index.php?NiceQuote=post&qid=1
* /index.php?NiceQuote=url&qurl=https%3A%2F%2Fexample.com%2Fpost
*
* @package NiceQuote
*/
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
require_once __DIR__ . '/Renderer.php';
$nqOptions = \TypechoPlugin\NiceQuote\Plugin::options();
$nqType = isset($nqType) ? (string) $nqType : strtolower((string) \Typecho\Request::getInstance()->get('NiceQuote'));
$nqId = isset($nqId) ? (int) $nqId : (int) \Typecho\Request::getInstance()->get('qid');
$nqUrl = isset($nqUrl) ? (string) $nqUrl : (string) \Typecho\Request::getInstance()->get('qurl');
$nqHtml = \TypechoPlugin\NiceQuote\Renderer::render($nqType, $nqId, $nqOptions, $nqUrl);
$nqCss = $nqOptions['pluginUrl'] . '/assets/card.css?v=' . $nqOptions['version'];
$nqTitle = \TypechoPlugin\NiceQuote\Renderer::plain($nqType, $nqId, $nqUrl);
$nqTitle = null === $nqTitle ? 'NiceQuote' : strip_tags($nqTitle);
?>
<!DOCTYPE html>
<html lang="zh-CN" style="--nq-accent:<?php echo $nqOptions['accent']; ?>;--nq-radius:<?php echo $nqOptions['radius']; ?>px">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title><?php echo htmlspecialchars($nqTitle, ENT_QUOTES, 'UTF-8'); ?></title>
<link rel="stylesheet" href="<?php echo htmlspecialchars($nqCss, ENT_QUOTES, 'UTF-8'); ?>">
</head>
<body class="nq-standalone" data-skin="<?php echo $nqOptions['skin']; ?>">
<?php echo $nqHtml; ?>
<script>
(function () {
if (window.parent === window) {
return;
}
var body = document.body;
function send() {
var height = Math.ceil(body.getBoundingClientRect().height);
window.parent.postMessage({ nqHeight: height }, '*');
}
window.addEventListener('load', send);
window.addEventListener('resize', send);
if (window.ResizeObserver) {
new ResizeObserver(send).observe(body);
}
send();
})();
</script>
</body>
</html>