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),