知更鸟Begin主题外链跳转支持迅雷/FTP等

2015年10月10日原创教程 建站历程511,1742

知更鸟Begin主题外链跳转支持迅雷/FTP等文章源自狐狸影视城-https://fox-studio.net/29131.html

 文章源自狐狸影视城-https://fox-studio.net/29131.html

历史介绍

知更鸟Begin付费主题1.7.1版本中加入了外链跳转的功能,提高访客的浏览体验。文章源自狐狸影视城-https://fox-studio.net/29131.html

外链加入有三个地方,从Setting文件中可以看到:文章源自狐狸影视城-https://fox-studio.net/29131.html

  • 文章中外链跳转
  • 评论者的外链跳转
  • 下载按钮中的外链跳转

评论者的外链加入了下面的属性。搜索引擎不会用这个链接计算网站的PR值。文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. rel='external nofollow'

当然你也可以适当考虑是否加入到其他两个地方。我建议还是默认的好。文章源自狐狸影视城-https://fox-studio.net/29131.html

 文章源自狐狸影视城-https://fox-studio.net/29131.html

询问作者

最初时跳转不支持迅雷连接,点击后无法打开,这让我蛋疼许久。最新一版本的跳转却取消了对迅雷下载连接的支持,并且发现似乎https开头淘宝的超链接也没有了跳转。文章源自狐狸影视城-https://fox-studio.net/29131.html

询问过鸟哥后,得之代码来自张弋博客。遂留言于张弋博客,得到博主的完整源码。文章源自狐狸影视城-https://fox-studio.net/29131.html

具体过程不赘述,其代码原理我也不详,我不是做网站的,也请勿询问我相关专业问题。以下是源码和更改方法,适用于Begin 1.7.1版本文章源自狐狸影视城-https://fox-studio.net/29131.html

特别鸣谢:知更鸟张弋文章源自狐狸影视城-https://fox-studio.net/29131.html

 文章源自狐狸影视城-https://fox-studio.net/29131.html

修改方法

第一步,复制以下代码文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. <?php
  2. $t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
  3. if(!empty($t_url)) {
  4.     preg_match('/(http|https|ftp|thunder):\/\//',$t_url,$matches);
  5.     if($matches){
  6.         $url=$t_url;
  7.         $title='页面加载中,请稍候...';
  8.     } else {
  9.         preg_match('/\./i',$t_url,$matche);
  10.         if($matche){
  11.             $url='http://'.$t_url;
  12.             $title='页面加载中,请稍候...';
  13.         } else {
  14.             $url='http://fox-studio.net/';
  15.             $title='参数错误,正在返回首页...';
  16.         }
  17.     }
  18. else {
  19.     $title='参数缺失,正在返回首页...';
  20.     $url='http://fox-studio.net/';
  21. }
  22. ?>
  23. <html>
  24. <head>
  25. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  26. <meta http-equiv="refresh" content="1;url='<?php echo $url;?>';">
  27. <title><?php echo $title;?></title>
  28. <style>
  29. body{background:#000}.loading{-webkit-animation:fadein 2s;-moz-animation:fadein 2s;-o-animation:fadein 2s;animation:fadein 2s}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-o-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}.spinner-wrapper{position:absolute;top:0;left:0;z-index:300;height:100%;min-width:100%;min-height:100%;background:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:50%;left:50%;margin-left:-90px;margin-top: 2px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:36px;font-family:Arial}.spinner{position:absolute;top:50%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:25px solid rgba(100,100,100,0.2);-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;border-left-color:transparent;border-right-color:transparent;-webkit-animation:spin 1.5s infinite;-moz-animation:spin 1.5s infinite;animation:spin 1.5s infinite}@-webkit-keyframes spin{0%,100%{-webkit-transform:rotate(0deg) scale(1)}50%{-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin{0%,100%{-moz-transform:rotate(0deg) scale(1)}50%{-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin{0%,100%{-o-transform:rotate(0deg) scale(1)}50%{-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin{0%,100%{transform:rotate(0deg) scale(1)}50%{transform:rotate(720deg) scale(0.6)}}
  30. </style>
  31. </head>
  32. <body>
  33. <div class="loading">
  34.   <div class="spinner-wrapper">
  35.     <span class="spinner-text">页面加载中,请稍候...</span>
  36.     <span class="spinner"></span>
  37.   </div>
  38. </div>
  39. </body>
  40. </html>

替换其中 https://fox-studio.net/ 网址为你网站的地址。覆盖主题目录下的 begin/inc/go.html 文件。文章源自狐狸影视城-https://fox-studio.net/29131.html

 文章源自狐狸影视城-https://fox-studio.net/29131.html

第二步,打开 begin/inc/core/setting.php 文件,查找以下内容(在 //外链跳转 下)约959行:文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. function link_to_jump($content){
  2.         preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
  3.         if($matches){
  4.             foreach($matches[2] as $val){
  5.                 if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val) && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)){
  6.                     $content=str_replace("href=\"$val\"""href=\"".get_template_directory_uri()."/inc/go.php?url=$val\" ",$content);
  7.                 }
  8.             }
  9.         }
  10.         return $content;
  11.     }

替换为:文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. function link_to_jump($content){
  2.     preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
  3.     if($matches){
  4.         foreach($matches[2] as $val){
  5.             if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
  6.                 $content=str_replace("href=\"$val\"""href=\"".get_stylesheet_directory_uri()."/inc/go.php?url=$val\" ",$content);
  7.             }
  8.         }
  9.     }
  10.     return $content;
  11. }

只是删去了其中以下内容,我我也看不懂是啥意思。自己摸索的。文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. && !preg_match('/(ed2k|thunder|Flashget|flashget|qqdl):\/\//i',$val)

我是在子主题中修改的这些文件。所以其中的文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. get_template_directory_uri()

改成了文章源自狐狸影视城-https://fox-studio.net/29131.html

  1. get_stylesheet_directory_uri()

好了,现在去试试外链的跳转吧。效果如本站外链所示。文章源自狐狸影视城-https://fox-studio.net/29131.html

提供几个样例地址测试:文章源自狐狸影视城-https://fox-studio.net/29131.html

淘宝的https开头:https://item.taobao.com/item.htm?id=522217129671文章源自狐狸影视城-https://fox-studio.net/29131.html

迅雷thunder开头的:文章源自狐狸影视城-https://fox-studio.net/29131.html

thunder://QUFmdHA6Ly95Z2R5ODp5Z2R5OEB5MjAxLmR5Z29kLm9yZzo4MDM4L1vpmLPlhYnnlLXlvbF3d3cueWdkeTguY29tXS7nvo7lm73pmJ/plb8yLkJELjcyMHAu5Zu96Iux5Y+M6K+tLuS4reiLseWPjOWtl+W5lS5ta3ZaWg==文章源自狐狸影视城-https://fox-studio.net/29131.html

FTP连接:ftp://ftp.pku.edu.cn/文章源自狐狸影视城-https://fox-studio.net/29131.html

百度网盘长链接:http://pan.baidu.com/share/link?shareid=3496202812&uk=2100613190文章源自狐狸影视城-https://fox-studio.net/29131.html

 文章源自狐狸影视城-https://fox-studio.net/29131.html

关于子主题的创建请查阅:知更鸟 Begin 自定义子主题修正缩略图文章源自狐狸影视城-https://fox-studio.net/29131.html

weinxin
千年骚狐
  • 本文由 发表于 2015年10月10日
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
评论:5   其中:访客  2   博主  3   引用   1
    • 司文雨轩
      司文雨轩 0

      狐哥,其他的主题可以实现吗?我用的是鸟哥的“响应式主题:Ality

      • 醉兔
        醉兔 0

        狐哥,第一段代码第三行错误了,有两个词重复了【if(!emptyempty($t_url)) {】,我试了好几次终于解决了,谢谢啊

          • 千年骚狐
            千年骚狐

            @ 醉兔 感谢提醒,已修复。源代码都没有错误,可能是复制时候搞错了吧。

        • 来自外部的引用: 1

        匿名

        发表评论

        匿名网友 填写信息

        :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

        确定