实现wordress文章外链和伪静态跳转

实现wordress文章外链和伪静态跳转

wordpres教程:实现wordress文章外链和伪静态跳转

1、在网根目录下创建goto.php文件,PHP代码如下:

<?php
if(strlen($_SERVER['REQUEST_URI']) > 255 ||
    strpos($_SERVER['REQUEST_URI'], "eval(") ||
	strpos($_SERVER['REQUEST_URI'], "base64")) {
		@header("HTTP/1.1 414 Request-URI Too Long");
		@header("Status: 414 Request-URI Too Long");
		@header("Connection: Close");
		@exit;
}
//通过QUERY_STRING取得完整的传入数据,然后取得url=之后的所有值,兼容性更好
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
//数据处理
if(!empty($t_url)) {
    //判断取值是否加密
    if ($t_url == base64_encode(base64_decode($t_url))) {
        $t_url =  base64_decode($t_url);
    }
    //对取值进行网址校验和判断
    preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$t_url,$matches);
	if($matches){
	    $url=$t_url;
	    $title='页面加载中,请稍候...';
	} else {
	    preg_match('/\./i',$t_url,$matche);
	    if($matche){
	        $url='http://'.$t_url;
	        $title='页面加载中,请稍候...';
	    } else {
	        $url = 'http://'.$_SERVER['HTTP_HOST'];
	        $title='参数错误,正在返回首页...';
	    }
	}
} else {
    $title = '参数缺失,正在返回首页...';
    $url = 'http://'.$_SERVER['HTTP_HOST'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow" />
<noscript><meta http-equiv="refresh" content="1;url='<?php echo $url;?>';"></noscript>
<script>
function link_jump()
{
    //禁止其他网站使用我们的跳转页面
    var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>");
    if (!MyHOST.test(document.referrer)) {
         location.href="http://" + MyHOST;
    }
    location.href="<?php echo $url;?>";
}
//延时1S跳转,可自行修改延时时间
setTimeout(link_jump, 1000);
//延时50S关闭跳转页面,用于文件下载后不会关闭跳转页的问题
setTimeout(function(){window.opener=null;window.close();}, 50000);
</script>
<title><?php echo $title;?></title>
<style type="text/css">
body{background:#555}.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:45%;left:50%;margin-left:-100px;margin-top:2px;color:#000;letter-spacing:1px;font-size:20px;font-family:Arial}.spinner{position:absolute;top:45%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:20px solid rgba(255,0,0,1);-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)}}
</style>
</head>
<body>
<style type="text/css">
html,body {width: 100%;height: 100%;}
.flex-container {width: 100%;height: 100%;position: relative;display: -webkit-box;display: -ms-flexbox;display: flex;-ms-flex-wrap: wrap;flex-wrap: wrap;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;-webkit-box-align: center;-ms-flex-align: center;align-items: center;}
body {background: #000;}
.unit {text-align: center;}
.unit p {margin-top: 120px;margin-left: -30px;font-size: 20px;font-family: 'Lato', sans-serif;text-transform: uppercase;color: #6cc;}
.heart {position: relative;font-size: 0;width: 138px;}
[class*="heart-piece-"] {position: absolute;top: -5px;width: 10px;height: 10px;border-radius: 5px;}
.heart-piece-4 {-webkit-animation: piece-4 1.0s infinite;animation: piece-4 1.0s infinite;}
.heart-piece-3,.heart-piece-5 {-webkit-animation: piece-3 1.0s infinite;animation: piece-3 1.0s infinite;}
.heart-piece-2,.heart-piece-6 {-webkit-animation: piece-2 1.0s infinite;animation: piece-2 1.0s infinite;}
.heart-piece-1,.heart-piece-7 {-webkit-animation: piece-1 1.0s infinite;animation: piece-1 1.0s infinite;}
.heart-piece-0,.heart-piece-8 {-webkit-animation: piece-0 1.0s infinite;animation: piece-0 1.0s infinite;}
.heart-piece-0 {left: 0px;-webkit-animation-delay: 0s;animation-delay: 0s;background-color: #57f1f1;}
.heart-piece-1 {left: 16px;-webkit-animation-delay: 0.05s;animation-delay: 0.05s;background-color: #3ed6d6;}
.heart-piece-2 {left: 32px;-webkit-animation-delay: 0.1s;animation-delay: 0.1s;background-color: #42c3e0;}
.heart-piece-3 {left: 48px;-webkit-animation-delay: 0.15s;animation-delay: 0.15s;background-color: #07ead5;}
.heart-piece-4 {left: 64px;-webkit-animation-delay: 0.2s;animation-delay: 0.2s;background-color: #42c3e0;}
.heart-piece-5 {left: 80px;-webkit-animation-delay: 0.25s;animation-delay: 0.25s;background-color: #07ead5;}
.heart-piece-6 {left: 96px;-webkit-animation-delay: 0.3s;animation-delay: 0.3s;background-color: #42c3e0;}
.heart-piece-7 {left: 112px;-webkit-animation-delay: 0.35s;animation-delay: 0.35s; background-color: #3ed6d6;}
.heart-piece-8 {left: 128px;-webkit-animation-delay: 0.4s;animation-delay: 0.4s;background-color: #57f1f1;}
@-webkit-keyframes piece-4 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% { height: 94px;top: -23px;}}
@keyframes piece-4 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 94px;top: -23px;}}
@-webkit-keyframes piece-3 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 90px;top: -31px;}}
@keyframes piece-3 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 90px;top: -31px;}}
@-webkit-keyframes piece-2 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 80px;top: -37px;}}
@keyframes piece-2 {0%, 10%, 90%, 100% { height: 10px;top: -5px;}45%, 55% {height: 80px;top: -37px;}}
@-webkit-keyframes piece-1 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 60px;top: -31px;}}
@keyframes piece-1 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 60px;top: -31px;}}
@-webkit-keyframes piece-0 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 30px;top: -15px;}}
@keyframes piece-0 {0%, 10%, 90%, 100% {height: 10px;top: -5px;}45%, 55% {height: 30px;top: -15px;}}
</style>
</head>
<body>
	<div class="flex-container">
		<div class="unit">
			<div class="heart">
				<div class="heart-piece-0"></div>
				<div class="heart-piece-1"></div>
				<div class="heart-piece-2"></div>
				<div class="heart-piece-3"></div>
				<div class="heart-piece-4"></div>
				<div class="heart-piece-5"></div>
				<div class="heart-piece-6"></div>
				<div class="heart-piece-7"></div>
				<div class="heart-piece-8"></div>
			</div>
			<p>页面跳转中,请稍候……</p>
		</div>
	</div>
</body>
</html>

2、在主题的assets/js文件夹下创建jquery.barrager.js文件,js代码如下:

(function($){$.fn.barrager=function(barrage){barrage=$.extend({close:true,bottom:0,max:10,speed:8,color:"#fff",old_ie_color:"#000000"},barrage||{});var time=new Date().getTime();var barrager_id="barrage_"+time;var id="#"+barrager_id;var div_barrager=$("<div class='barrage' id='"+barrager_id+"'></div>").appendTo($(this));var window_height=$(window).height()-100;var this_height=(window_height>this.height())?this.height():window_height;var window_width=$(window).width()+500;var this_width=(window_width>this.width())?this.width():window_width;var bottom=(barrage.bottom==0)?Math.floor(Math.random()*this_height+40):barrage.bottom;div_barrager.css("bottom",bottom+"px");div_barrager_box=$("<div class='barrage_box cl'></div>").appendTo(div_barrager);if(barrage.img){div_barrager_box.append("<a class='portrait z' href='javascript:;'></a>");var img=$("<img src='' >").appendTo(id+" .barrage_box .portrait");img.attr("src",barrage.img)}div_barrager_box.append(" <div class='z p'></div>");if(barrage.close){div_barrager_box.append(" <div class='close z'></div>")}var content=$("<a title='' href='' target='_blank' rel="noopener noreferrer"></a>").appendTo(id+" .barrage_box .p");content.attr({"href":barrage.href,"id":barrage.id}).empty().append(barrage.info);if(navigator.userAgent.indexOf("MSIE 6.0")>0||navigator.userAgent.indexOf("MSIE 7.0")>0||navigator.userAgent.indexOf("MSIE 8.0")>0){content.css("color",barrage.old_ie_color)}else{content.css("color",barrage.color)}var i=0;div_barrager.css("margin-right",0);$(id).animate({right:this_width},barrage.speed*1000,function(){$(id).remove()});div_barrager_box.mouseover(function(){$(id).stop(true)});div_barrager_box.mouseout(function(){$(id).animate({right:this_width},barrage.speed*1000,function(){$(id).remove()})});$(id+".barrage .barrage_box .close").click(function(){$(id).remove()})};$.fn.barrager.removeAll=function(){$(".barrage").remove()}})(jQuery);$.ajaxSettings.async=false;$.getJSON("https://你的域名/wp-content/themes/ripro/server.php?mode=2",function(data){var looper_time=5000;var items=data;var total=data.length;var run_once=true;var index=0;barrager();function barrager(){if(run_once){looper=setInterval(barrager,looper_time);run_once=false}$("body").barrager(items[index]);index++;if(index==total){clearInterval(looper);return false}}});

3、在主题的functions.php文件加入如下代码:

//文章外链跳转伪静态版
function link_jump($content){
	preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
	if($matches){
	    foreach($matches[2] as $val){
	        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)){
	        $content=str_replace("href=\"$val\"", "href=\"".home_url()."/goto/".base64_encode($val).".html\" rel=\"nofollow\"",$content);
			}
		}
	}
	return $content;
}
add_filter('the_content','link_jump',999);

4、在为静态中加入为静态规则(以Nginx环境为例):

rewrite /goto/(.*).html$ /goto.php?url=$1;

原文链接:https://88hzy.cn/1321.html,转载请注明出处。

0

评论0

请先

显示验证码
没有账号? 注册  忘记密码?