Log in |
Adding Trackback to SquishdotAdding Trackback support to SquishdotLast year, the authors of MovableType (a popular CMS oriented to weblogs) came up with the concept of trackback: "[...] it’s a way of recording who has linked to your posts and notifying others that you’ve linked to them" (from hitormiss.org) This article aims to describe a basic implementation of trackback for Squishdot-powered weblogs. Trackback pingsSuppose you wrote an article in your Squishdot based site. Another weblogger read the piece and posted a link to it on her weblog along with some related comments. Here is where trackback enters: in addition to linking to your article, she could ping it. That way, you and your readers would know that another person wrote something about the topic of your posting. Then, trackback, in addition to traditional HTML linking, is another way of communication between weblogs. The Trackback Development weblog at movabletype.org could serve as a working example of this. ImplementationAny trackback-enabled weblog system should be able to:
Receiving and storing pingsA trackback ping is just an HTTP ‘POST’ request to a given URL. According to the official specification, the POSTed variables should be:
Every posting must provide an URL to receive pings. If the Squishdot site is at http://www.example.com/, this URL will be of the form: http://www.example.com/<posting_id>/tb For storing pings, we will use the ubiquitous TinyTablePlus product from Endicor and Shane Hathaway. First of all, create a Folder named ‘trackback’ in the Squishdot root. This will contain the instance of TinyTablePlus and another scripts. Then create an instance of TinyTablePlus and name it ‘trackbackStore’. Type the following in the ‘Columns’ text field: id:int post_id:int url title excerpt blog_name added:datetime Pings will come from Anonymous requests, so anonymous users must be allowed to query the table for both reading and writing. Go to the Security tab of the trackbackStore object and check the boxes in the Anonymous column for "Change TinyTable" and "Query TinyTable Data" permissions. Go back to your site’s root folder and create a new instance of "Script (Python)". Name it ‘tb’. This script will be responsible of receiving the trackback ping, checking the POSTed variables and creating a new row in trackback.trackbackStore if everything is correct. tb (Python Script):
request = container.REQUEST
# ID of pinged posting
post_id = int(context.id)
# POSTed variables dictionary
tbargs = {}
tbargs['blog_name'] = ""
tbargs['title'] = ""
tbargs['excerpt'] = ""
try:
tbargs['url'] = getattr(request,"url")
except:
print context.trackback.responseXML(1,"URL is missing")
return printed
if hasattr(request, "blog_name"):
tbargs['blog_name'] = getattr(request, "blog_name")
if hasattr(request, "title"):
tbargs['title'] = getattr(request, "title")
if hasattr(request, "excerpt"):
tbargs['excerpt'] = getattr(request, "excerpt")
# Store the ping
context.trackback.trackbackStore.setRow(id = len(context.trackback.trackbackStore())+ 1,
post_id = post_id,
url = tbargs['url'],
title = tbargs['title'],
excerpt = tbargs['excerpt'],
blog_name = tbargs['blog_name'],
added = context.ZopeTime())
print context.trackback.responseXML(0,"")
return printed
# ---- * ----
As you may have noticed, this script uses something we haven’t defined yet: context.trackback.responseXML(). That object (a Python Script) will generate the response for the received ping. Ping responses are a little chunk of XML. If we’ve received a "correct" ping, the response will be: <?xml version="1.0" encoding="iso-8859-1"?> <response> <error>0</error> </response> If there’s any error, for instance omitting the ‘url’ variable, this will be the answer: <?xml version="1.0" encoding="iso-8859-1"?> <response> <error>1</error> <message>URL is missing</message> </response> Create an instance of "Script (Python)" inside the trackback folder you created and name it 'responseXML'. This script must accept two input parameters: errorCode and errorMsg. responseXML (Python Script):
container.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
resp = '<?xml version="1.0" encoding="iso-8859-1"?>\n'
resp += '<response>\n'
resp += '<error>' + str(errorCode) + '</error>\n'
if errorMsg != '':
resp += '<message>' + errorMsg + '</message>\n'
resp += '</response>\n'
return resp
# ---- * ----
Displaying pingsIn this section we’ll see how to retrieve and display stored pings for a given post. Each Squishdot site has a particular visual appearance, so the following examples just suggest how to show the data. This DTML snippet will list how many trackback pings were received by each of the postings returned by item_list (a list containing the newest postings, provided by the Squishdot API): <ul> <dtml-in item_list> <li>posting id: <dtml-var id> - tbpings: <dtml-var "_.len(trackback.trackbackStore(post_id=_.int(_['id'])))"> </dtml-in> </ul> If we want to actually fetch and display the list of pings that a given posting
has received, we can write something like this: (let postID be the actual ID of a particular posting) <ul> <dtml-in "trackback.trackback(post_id=postID)"> <li>title: <dtml-var title><br> url: <dtml-var url><br> blogname: <dtml-var blog_name><br> received on: <dtml-var added><br> excerpt: <dtml-var excerpt><br> <dtml-else> No pings for this posting </dtml-in> </ul> Sending PingsActually, you can’t send trackback pings directly from Squishdot. But you can use Matt Croydon's Trackback library (http://www.postneo.com/projects/tblib/). Final RemarksI wrote these scripts to give my weblog (http://jazzido.freezope.org)
trackback support. |