From 3b00b99a3d1b5f184be19b0bb60168ff528d3e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E8=88=92=E5=90=9B?= <41245552+Lvshujun0918@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:57:09 +0000 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=AD=A3=E6=96=87=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E9=93=BE=E6=8E=A5=E5=8A=A0=E8=B7=B3=E8=BD=AC=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/fun/opt.php | 27 +++++++++++++++++++++++++++ inc/setting/options/OptionBasic.php | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/inc/fun/opt.php b/inc/fun/opt.php index 86aed384..dc6acdca 100755 --- a/inc/fun/opt.php +++ b/inc/fun/opt.php @@ -273,6 +273,33 @@ function pk_go_link($url, $name = '') return $url; } +//开启了内页链接跳转 +if (pk_is_checked('link_go_page')) { + /** + * 内页跳转链接 + * + * @param string $content 修改前的内容 + * @return string 修改后的内容 + * @author lvshujun + * @date 2024-03-19 + */ + function pk_content_addlink($content) { + //匹配链接 + preg_match_all('//',$content,$matches); + if ($matches) { + foreach ($matches[2] as $val) { + if (strpos($val,'://') !== false + && pk_is_cur_site($val) === false + && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)) { + $content = str_replace('href="'.$val.'"', 'href="'.pk_go_link($val).'"', $content); + } + } + } + return $content; + } + add_filter('the_content', 'pk_content_addlink'); +} + //检测链接是否属于本站 function pk_is_cur_site($url) { diff --git a/inc/setting/options/OptionBasic.php b/inc/setting/options/OptionBasic.php index 50a69bd2..ec90e877 100644 --- a/inc/setting/options/OptionBasic.php +++ b/inc/setting/options/OptionBasic.php @@ -54,6 +54,12 @@ function get_fields(): array 'type' => 'switch', 'sdt' => 'false', ], + [ + 'id' => 'link_go_page', + 'label' => __('正文内容链接加跳转', PUOCK), + 'type' => 'switch', + 'sdt' => 'false', + ], [ 'id' => 'use_post_menu', 'label' => __('正文内容侧边目录菜单生成', PUOCK),