msgbartop
世界上没有老实人,所谓的老实人是用来欺骗像我这样老实的人!
msgbarbottom

16 6月 11 为WordPress评论链接添加跳转转向

2011年6月16日发表于Int.Ru | 共有:0 人评论

因为垃圾评论太多,午夜客转换程序才一晚上的时间,就有几十条链接涌入午夜客的BLOG。

没办法,所以午夜客只能给评论区增加个跳转。

并使用robots.txt来限制跳转链接的收录。

http://wyk.int.ru/robots.txt

 

User-agent: *
Allow: /
Disallow: /l.php?url=*
Disallow: /wp-admin
Sitemap: http://wyk.int.ru/sitemap.xml

 

具体做法如下,把以下代码复制到一份名为l.php的文件中,保存!

 

<?php
$directGo=FALSE;//是否直接跳转
$errorPage='http://wyk.int.ru/404.html';
$home='http://wyk.int.ru';
$refer= empty($_SERVER['HTTP_REFERER'])?'http://wyk.int.ru':$_SERVER['HTTP_REFERER'];

function printPic($pic)
{
header('Content-Type: image/gif');
switch ($pic)
{
case 'fav':
echo base64_decode('R0lGODlhEAAQAMQfAMrJuFSX3cjk/7TU96TM8/H+/3Ss5+Xkz63R+Gik49fWw5K+7MXb6F2UzE+T2Z/I83qw6MDe+5fE8pvC5lGNypLF+s/q/0iO1ZfL/Xu18U6LzZDA8Vma3JnL/Wec0f///yH5BAEAAB8ALAAAAAAQABAAAAWD4CeOH8OQKFphaYsVRdeqcDWXRGbtVkacogUksSEILJGIRUDYJCCbQSKJQAyqWEFk+iEkEJKN5CEJPxDf0dDANkDaT9QiEeAE7oHEIrW4BBx3gBcTKQYXFxwODokXECmAiRSSHIkpGhQNhB8TDRQaKQ0eACQAAA0jBwqlAAoHrq6rrCEAOw==');
break;
case 'nt':
echo base64_decode('R0lGODlhEAAQAOZ/AADOy8vxudPzuFTVgqfguXXs4HLMdTHDa+j5y5T6xnbqmQDA2ACz1wDb0Ry+yND22bbop4TUxQDvX8/6ywC2yrz01ZL12gDEV3rWfADI6gCkzQDf4T7o4qzpnkr0xQDuxMbytGW/bACaJAClRIjpjQDydADeYQDUzU2wYDa0bPb89v3+/e337wCmN9j33l/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oICQ4OGcgReKV8KjVKNCnIpaixfDJcymZqZlwxyLJRfAaMBmqSnn3U1XyitrZmusXI1ql8vt7gyuLuztTc2McHCw8O9N6u/MMrLzMzGNWoeISvU1dbUIR5ptMeLHBZO4TYWHDcp3DUID1JSDwjcLAgkI4DsQgQjJAgsdSwUEBIaDOgAYoHBgyA6DGggAQIFUOYiOJhwoYGGDQMyatygocGFCQ4iTLpBoEaFDBMkXDDAsiXLCxImZKhQI9ENGik+VHAA4YSJNQRAg5o4AcFBhQ8p/KR5cC4CBQQHokqNioBChBopHqi5UUAFDQIpWLCoQbYsWbEpCNBQgSYIADs=');
}
}

if(!empty($_GET['pic']))
{
printPic($_GET['pic']);
} 

//启用GIP
if (function_exists('ob_gzhandler'))
{
    ob_start('ob_gzhandler');
}
else
{
    ob_start();
}

if(empty($_GET['url']) && empty($_GET['pic']) )
{
    header('Location:'.$errorPage);
       exit();
}
else
{
    $uri=$_SERVER['REQUEST_URI'];
    $url= preg_replace('@\/l\.php\?url=@i','',$uri,1) ;
    $url=preg_replace( '@orz__@','?',$url,1);
    $url =htmlspecialchars(strip_tags($url));
        if(false !==strpos($url,'aHR0cDovL') )
            $url=base64_decode($url);
        $url=(!preg_match("/^http(s)?\:\/\//i", $url))? "http://".$url:$url;

       if(strpos($_SERVER['HTTP_REFERER'],$home)===false)  //非本站引用
       {
        header('Location:'.$errorPage);
        exit();
       }

        if($directGo) //若設定了直接跳转
        {
        header('Location:'.$url);//直接跳转
                exit();
        }

}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>【午夜客博客评论引导专用页】 - Http://Wyk.Int.Ru/ - Powered by 午夜客</title>
<script language="javascript" type="text/javascript" >
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_safari = (userAgent.indexOf('webkit') != -1 || userAgent.indexOf('safari') != -1);
//iframe包含
if (top.location != location) {
    top.location.href = location.href;
}
//复制URL地址
function setCopy(_sTxt){
    if(is_ie) {
        clipboardData.setData('Text',_sTxt);
        alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
    } else {
        prompt("请复制网站地址:",_sTxt);
    }
}

function mybookmark(title,url){

                    var title=title?title:document.title;
                    var url=url?url:document.location.href;
                    if(document.all)
                    window.external.AddFavorite( url, title);

                    else if (window.sidebar)
                    window.sidebar.addPanel(title, url,"");

                    else if( window.opera && window.print )
                    {
                    var mbm = document.createElement('a');
                    mbm.setAttribute('rel','sidebar');
                    mbm.setAttribute('href',url);
                    mbm.setAttribute('title',title);
                    mbm.click();
                    }

                    }

</script>
<style type="text/css">
* { word-break: break-all; word-wrap: break-word; }
body, th, td, input, select, textarea, button { font: 12px/1.5em Verdana, "Lucida Grande",Arial, Helvetica,sans-serif; }
body, h1, h2, h3, h4, h5, h6, p, ul, dl, dt, dd, form, fieldset { margin: 0; padding: 0; }
h1, h2, h3, h4, h5, h6 { font-size: 1em; }
ul li { list-style: none; }
a {color: #2C629E; text-decoration: none; }
a:hover { text-decoration: underline; }
a img { border: none; }
.link_td { text-align:right;width: 100%; height: 26px; border-bottom: 1px solid #DDD; background: #EEE; padding-left:1em; font-size:12px; }
.link_td a { color: #333; }
textarea { border: 1px solid #ddd; overflow: auto; }
.t_input { padding: 3px 2px; border: 1px solid #ddd; line-height: 16px; }
</style>
</head>

<body scroll="no">
<div id="append_parent"><iframe id="ajaxframe" name="ajaxframe" width="0" height="0" marginwidth="0" frameborder="0" src="about:blank"></iframe></div>
<div id="ajaxwaitid"></div>

<table border="0" cellPadding="0" cellSpacing="0" height="100%" width="100%">
<tr>
<td height="26" class="link_td">

您正在浏览的网站是:<img src="l.php?pic=nt" align="absmiddle"> <a target="_blank" href="<?php echo $url; ?> "><?php echo $url; ?></a> (<a href="javascript:;" onclick="javascript:setCopy('<?php echo $url; ?>');return false;">复制</a>)<span class="pipe">&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;</span>
<img src="l.php?pic=back" align="absmiddle"> <a href="<?php echo $refer; ?>">返回</a> <span class="pipe">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;</span>
<img src="l.php?pic=fav" align="absmiddle"> <a href="#" onclick="javascript:mybookmark('午夜客 【Www.Wyk.Int.Ru】','http://Wyk.Int.Ru/');return false;" title="把 午夜客 【Www.Wyk.Int.Ru】添加到收藏夹">收藏本站</a>

</td>
</tr>
<tr>
<td>
<iframe id="url_mainframe" frameborder="0" scrolling="yes" name="main" src="<?php echo $url; ?>" style="height: 100%; visibility: inherit; width: 100%; z-index: 1;overflow: visible;"></iframe>
</td>
</tr>
</table>
</body>
</html>

 

 

然后上传到网站的根目录下!JS文件可以直接另存午夜客的JS文件 Http://wyk.int.ru/quicktags.js

然后打开你Wordpress模板文件夹中的functions.php。

在最后一个 ?> 或适当的地方添加以下代码(放的位置具体视你的WP模板而定)

 

//comments link redirect
add_filter(‘get_comment_author_link’, ‘add_redirect_comment_link’, 5);
add_filter(‘comment_text’, ‘add_redirect_comment_link’, 99);
function add_redirect_comment_link($text = ”)
{
$text=str_replace(‘href=”http://’, ‘href=”‘.get_option(‘home’).’/l.php?url=’, $text);
$text=str_replace(“href=’http://”, “href='”.get_option(‘home’).”/l.php?url=”, $text);
return $text;
}

 

最后保存更改,刷新你的网站看一下吧。

最后你要在你的网站根目录下的robots.txt中添加

 

Disallow: /l.php?url=*

 

告诉蜘蛛们不要收录这个链接后的东东!

PS:如果你想连你文章中的链接也如评论链接那样跳转的话,你可以打开Wordpress文件

/wp-includes/js/quicktags.js

找到

function edInsertLink(d,c,b)

替换成:

function edInsertLink(d,c,b){if(!b){b=”http://”}if(!edCheckOpenTags(c)){var a=prompt(quicktagsL10n.enterURL,b);if(a){ a=a.replace(‘http://’,”);a=a.replace(‘?’,’orz__’); edButtons[c].tagStart='<a target=”_blank” href=”http://wyk.int.ru/l.php?url=’+a+'”>’; edInsertTag(d,c)}}else{edInsertTag(d,c)}}

万事大吉!

最后提醒一句,请把午夜客的网址链接 http://wyk.int.ru 替换成你自己的域名后再进行哟!

原文地址:http://ihacklog.com/php/wordpress/wpskills/wordpress-commont-author-link-redirect.html

 

您的留言

*