drupal提供的Trackback模组其实还不错,他把trackback进来的ping作为匿名用户的comment显示,但标注有trackback和ping的来源,trackback本来就是保存在自己日志上的对别人的post的评价,所以说这样显示也十分合理。
Trackback模组本身其实没有问题,唯一的问题只在于在于显示时把trackback url做成了链接,而不是文字地址,于是常常我们去点那个trackback url,结果返回一个Miss URL,其实只要用右键复制快捷方式就可以了。
来说说我是怎么把它改得更友好一点的:
思路:弹出一个小窗口显示trackback url地址,用url传递地址参数
方法:
1.在template里加入弹出窗口的javascript
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//–>
</script>
2.写一个简单的tburl.aspx文件,用于接收和显示弹出窗口(之所以用asp.net是因为我对php并不熟)
<%@ Import Namespace=”System” %>
<%@ Import Namespace=”System.IO” %>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN” >
<html>
<head>
<title>trackback url</title>
<script language=”C#” runat=”server”>
public string tburl;
private void Page_Load(object sender, System.EventArgs e)
{
if ( Request.QueryString[“q”] != null )
tburl = HttpUtility.HtmlEncode(Request.QueryString[“q”]);
}
</script>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<style type=”text/css”>
<!–
.style1 {font-size: x-small}
–>
</style>
</head>
<body>
<font class=”style1″>引用本文的 trackback 地址:</font>
<br /><input name=’tb’ style=’font-size:10px;width:312px’ onmouseover=’this.select()’ value=<%=tburl%>>
<input type=’button’ value=’复制’ style=’font-size:10px’ onclick=tb.focus();document.execCommand(‘COPY’)>
</body>
</html>
3.在includes/common.inc里加入popuptrackback()方法,”主机地址”改为存放tburl.aspx的地址,我的tburl.aspx的地址在:http://winisp.net/ericfish/blog/tburl.aspx
function popuptrackback($text, $url, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = TRUE) {
if ($url == $_GET[‘q’]) {
if (isset($attributes[‘class’])) {
$attributes[‘class’] .= ‘ active’;
}
else {
$attributes[‘class’] = ‘active’;
}
}
return “<a href=javascript:MM_openBrWindow(‘http://主机地址/tburl.aspx?q=”. _fcksavedurl=”javascript:MM_openBrWindow(‘http://主机地址/tburl.aspx?q=”.” url($url, $query, $fragment, $absolute) .””. drupal_attributes($attributes) .”‘,’AddNewMsg’,’width=400,height=30′)>$text</a>”;
}
4.在module/trackback.module里调用popuptrackback()方法
将原来的:
function trackback_link($type, $node = 0, $main = 0) {
if ($type == ‘system’) {
menu(‘trackback’, t(‘trackback’), trackback_page, 0, MENU_HIDE);
}
elseif ($type == “node”) {
$link = l(t(“trackback url”), “trackback/$node->nid”);
if (!$main) {
$url = url(“node/view/$node->nid”);
$tb_url = url(“trackback/$node->nid”);
$link .= “n<!–n”;
$link .= “<rdf:RDF xmlns:rdf=”http://www.w3.org/1999/02/22-rdf-syntax-ns#” xmlns:dc=”http://purl.org/dc/elements/1.1/” xmlns:trackback=”/n’>http://madskills.com/public/xml/rss/module/trackback/” _fcksavedurl=””>/n’>http://madskills.com/public/xml/rss/module/trackback/”>n”;
$link .= “<rdf:Description rdf:about=”$url” dc:identifier=”$url” dc:title=”$node->title” trackback:ping=”$tb_url” />n”;
$link .= “</rdf:RDF>n”;
$link .= “–>n”;
}
return array($link);
}
}
换成:
function trackback_link($type, $node = 0, $main = 0) {
if ($type == ‘system’) {
menu(‘trackback’, t(‘trackback’), trackback_page, 0, MENU_HIDE);
}
elseif ($type == “node”) {
if (!$main) {
if (!$node) {
$url = url(“node/view/$node->nid”);
$tb_url = url(“trackback/$node->nid”);
$link = l(t(“trackback url”), “trackback/$node->nid”);
$link .= “n<!–n”;
$link .= “<rdf:RDF xmlns:rdf=”http://www.w3.org/1999/02/22-rdf-syntax-ns#” xmlns:dc=”http://purl.org/dc/elements/1.1/” xmlns:trackback=”/n’>http://madskills.com/public/xml/rss/module/trackback/” _fcksavedurl=””>/n’>http://madskills.com/public/xml/rss/module/trackback/”>n”;
$link .= “<rdf:Description rdf:about=”$url” dc:identifier=”$url” dc:title=”$node->title” trackback:ping=”$tb_url” />n”;
$link .= “</rdf:RDF>n”;
$link .= “–>n”;
}
else {
$link = popuptrackback(t(“trackback url”), “trackback/$node->nid”);
}
}
else {
$link = popuptrackback(t(“trackback url”), “trackback/$node->nid”);
}
return array($link);
}
}
Done!