refactor: 外链中转拆为内置插件 neatstudio.link-tracker
- 插件承载全部逻辑:redirects 迁移(hasTable 兼容旧库)、Redirect 模型、UrlRedirector、/go 路由+控制器、Filament 外链中转资源 - 核心只留 hook 接入点: - tracked_url() 助手走 link.redirect 过滤器(评论正文/作者网址/友链模板统一调用) - 正文外链改写移到插件的 post.rendered 过滤器(优先级 20,晚于会员付费过滤) - 停用插件:链接恢复直连、内容不受影响;后台「管理 → 外链中转」查看点击量/启停 - 测试更新为插件上下文(含无过滤器降级断言);97 通过
This commit is contained in:
@@ -46,31 +46,7 @@ class PostContentRenderer
|
||||
$html = app(\App\Blog\Support\PluginManager::class)->applyFilters('post.rendered', $html, $post);
|
||||
|
||||
// 兜底:任何情况下不把裸 [paid] 标签输出到页面(如会员插件被停用时)
|
||||
$html = preg_replace('/\[(\/?paid)\]/i', '', $html);
|
||||
|
||||
// 外链中转:站外链接改写为 /go/{hash}(点击统计/拦截)
|
||||
return $this->rewriteExternalLinks($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把正文里的站外 <a href> 改写为 /go 中转地址(站内/相对/锚点/mailto 不变)。
|
||||
*/
|
||||
private function rewriteExternalLinks(string $html): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/<a\s+([^>]*?href=["\'])([^"\']+)(["\'][^>]*)>(.*?)<\/a>/is',
|
||||
function (array $m): string {
|
||||
$url = html_entity_decode(trim($m[2]));
|
||||
$go = go_url($url);
|
||||
|
||||
if ($go === $url) {
|
||||
return $m[0];
|
||||
}
|
||||
|
||||
return '<a '.$m[1].e($go).$m[3].'>'.$m[4].'</a>';
|
||||
},
|
||||
$html
|
||||
);
|
||||
return preg_replace('/\[(\/?paid)\]/i', '', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user