Trackback is a much-valued feature by people who run weblogs. It allows one site to tell another site "Hey I am pointing to you.". The name of a blog, its URL, a title and an excerpt of the blog post will be sent from the origin blog to the specified wiki page automatically. Therefore the wiki page has to "offer" a trackback URL. See below, how one can enable this feature for Tavi.
Affected files:
The script is made available under the GNU General Public License [1].
<?php
// $Id: trackback.php,v 1.2 2003-10-24 00:35:24+02 urs_gehrig Exp urs_gehrig $
// Trackback for wiki pages. Add [[Trackback]] to the a specific wiki page.
// Trackback - reply
function trackback_response($error = 0, $error_message = '') {
if ($error) {
echo '<?xml version="1.0" encoding="iso-8859-1"?'.">\n";
echo "<response>\n";
echo "<error>1</error>\n";
echo "<message>$error_message</message>\n";
echo "</response>";
} else {
echo '<?xml version="1.0" encoding="iso-8859-1"?'.">\n";
echo "<response>\n";
echo "<error>0</error>\n";
echo "</response>";
}
die();
}
// Called by lib/defaults.php
function action_trackback() {
global $pagestore, $Admin, $TbTbl;
$use_trackback = 1;
$time_difference = 0;
if (strlen($_REQUEST['url']) > 0) {
$tbID = $_REQUEST['page'];
$url = $_REQUEST['url'];
$title = $_REQUEST['title'];
$excerpt = $_REQUEST['excerpt'];
$blog_name = $_REQUEST['blog_name'];
}
// Add to database
if (!$use_trackback) {
trackback_response(1, 'Sorry, this wiki does not allow you to trackback its posts.');
}
$url = addslashes($url);
$title = strip_tags($title);
$title = (strlen($title) > 255) ? substr($title, 0, 252) . '...' : $title;
$excerpt = strip_tags($excerpt);
$excerpt = (strlen($excerpt) > 255) ? substr($excerpt, 0, 252) . '...' : $excerpt;
$blog_name = htmlspecialchars($blog_name);
$blog_name = (strlen($blog_name) > 255) ? substr($blog_name, 0, 252) . '...' : $blog_name;
$comment = '<trackback />';
$comment .= "<b>$title</b><br />$excerpt";
$author = addslashes($blog_name);
$email = '';
$user_domain = gethostbyaddr($_SERVER['REMOTE_ADDR'] );
$now = date('Y-m-d H:i:s', (time() + ($time_difference * 3600)));
$author = addslashes($author);
$timestamp = $now;
$query = sprintf("INSERT INTO %s VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s' , '%s', 'NORMAL', 'false' );",
$TbTbl,
$tbID,
$timestamp,
$title,
$author,
$email,
$url,
$ip,
$comment
);
$q1 = $pagestore->dbh->query($query );
if (!$q1) {
die ("There is an error with the database.");
} else
trackback_response(0);
}
}
?>
$ViewMacroEngine = array(
//...
'Trackback' => 'view_macro_trackback'
);
$ActionList = array(
//...
'trackback' => array('action/trackback.php', 'action_trackback', '')
);
$TbTbl = $DBTablePrefix . 'comments'; // Wiki trackback/pingback table
// Trackback read from Database
function view_macro_trackback() {
global $ScriptBase, $pagestore, $LkTbl, $PgTbl, $TbTbl;
$text = '';
$query = sprintf("SELECT * FROM %s WHERE timestamp > 0 AND entry_id = '%s' ORDER BY timestamp ASC, entry_id;",
$TbTbl,
$_GET['page']
);
$q1 = $pagestore->dbh->query($query );
$tb = sprintf("%s?page=%s&action=trackback", $ScriptBase, $_GET['page'] );
$text .= sprintf("<p>Trackbacks on <em>%s</em></p><ol>\n", $tb );
while(($result = $pagestore->dbh->result($q1))) {
if(preg_match('|<trackback />|', $result[8])) {
$text .= sprintf("<li>by %s @ %s, %s</li>\n",
(isset($result[6]) ? "<a href=\"".$result[6]."\" title=\"\" target=\"_self\">".$result[4]."</a>" : $result[4] ),
$result[2],
$result[8]
);
}
}
$text .= "</ol>\n";
$text .= <<<TB
<!--
<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="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="$tb"
dc:identifier="$tb"
dc:title="{$_GET['page']}"
trackback:ping="$tb" />
</rdf:RDF>
-->
TB;
return $text;
}
The table is called comments because it is not only meant to take trackback-comments but also pingbacks. Trackbacks will be differentiated from pingbacks in the body field by separatnig them with an xml tag: <trackback /> or <pingback />
CREATE TABLE tavi_comments (
id int(11) NOT NULL auto_increment,
entry_id varchar(50) default NULL,
timestamp datetime default NULL,
title varchar(150) default NULL,
author varchar(80) default NULL,
email varchar(200) default NULL,
url varchar(200) default NULL,
ip varchar(15) default NULL,
body text,
type varchar(100) default 'regular',
subscribed enum('true','false') NOT NULL default 'true',
PRIMARY KEY (id),
FULLTEXT KEY body (body)
) TYPE=MyISAM;
INSERT INTO tavi_comments VALUES (24, 'SandBoxTrackback', '2003-10-24 00:27:12', 'Tavi is now supporting trackbacks
to wiki pages...', 'Example Blog', '', 'http://example.com/blog', '', '<trackback /><b>Tavi
is now supporting</b><br />... wiki pages [..]', 'NORMAL', 'false');