首页 » 日记 » 正文内容
11个月前 寻梦xunm 166 日记
有的时候想要文章中链接地址点击后跳转到一个中转页面,可以通过下面代码实现。
function xmurl($obj){
    if (strpos($obj, "data-fancybox") == false) {
        $site = Helper::options()->index;
        $obj = preg_replace_callback('/<a\b([^>]+?)\bhref="((?!' . addcslashes($site, '/._-+=#?&') . ').*?)"([^>]*?)>/i', function($matches){
            $matches[2] = $matches[2];
            return "<a{$matches[1]}href=".Helper::options()->themeUrl .'/xmurl.php?url='.$matches[2] . "{$matches[3]} target=\"_blank\" rel=\"nofollow noopener\">";
        }, $obj);
      }
      return $obj; }
在内容页面使用
<?php echo xmurl($this->content); ?>
在模板文件加中添加一个名为xmurl.php文件后添加下面代码,具体美化代码自行找一个就行。
<!DOCTYPE HTML>
<html lang=zh-cn>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
    <meta name=author content="寻梦xunm">
    <title>网站外部链接跳转提示</title>
    <style type="text/css">
.xm-body{
    padding: 10px;
border-radius: 6px;
background: aliceblue;
}
.xm-title{
background: #38b351;
color: white;
text-align: center;
padding: 15px 5px;
margin-top: 10px;
border-radius: 6px 6px 0 0;
}

.xm-tishi{
color: #f40707;
margin-bottom: 10px;
font-size: 14px;
position: relative;
padding: 0 15px;
font-weight: 600;
}
.xm-tishi::before {

    content: '';
    position: absolute;
    top: 10%;
    bottom: 10%;
    left: 0;
    width: 6px;
    border-radius: 6px;
    background: #00CFFF;

}
.xm-miaos{
    font-size: 14px;
color: #777;
margin-top: 20px;
margin-bottom: 20px;
color: #666;
}
.xm-miaos a{
    color: #1e48c6;
}
.xm-anniu{
    margin-bottom: 10px;
    font-size: 14px;
}
.xm-foot{
text-align: center;
margin-bottom: 10px;
color: #2d2d2d;
background: #d5d5d5;
padding: 15px 5px;
border-radius: 0 0 6px 6px;
}
</style>
</head>
<body>
    <div class="xm-title">网站外部链接跳转提示</div>
    <div class="xm-body">
     <div class="xm-tishi">您点击了一个外部链接,点击下面的链接可能使您离开本站。 本站不保证链接的安全性,请谨慎访问,注意防止感染病毒或上当受骗。</div>
     <div class="xm-miaos"> 
           您访问的链接是: <a href="<?php echo $_GET["url"]; ?>"><?php echo $_GET["url"]; ?></a>
    </div> 

        <div class="xm-anniu">
            我不想访问了,<a href="/">返回首页页面</a>,<span style="color:red;">知道危险依然坚持,</span> <a href="<?php echo $_GET["url"]; ?>">继续坚持前往</a>。
        </div>
    </div>
    <div class="xm-foot">© <?php echo date('Y',time()) ?> 本站网络安全宣传办</div>
</body>
</html>
0 赞 or 打赏
喜欢就打赏一点
微信 支付宝
已有0 条评论,0 个点赞
隐私

Q Q:1340326824

vipshiyi@qq.com

QQ群:422720328

生活所迫,再见了苦逼的BUG们,以后有缘在会吧。