ColdFusion Pingback
Let me start with small introduction.
What is pingback?
"A pingback is one of three types of linkbacks, methods for Web authors to request notification when somebody links to one of their documents. This enables authors to keep track of who is linking to, or referring to their articles."
That's what Wikipedia says. I say this is nothing more but automation of politeness. When you quote someone's words, it's polite to notify author about it. And if author likes what you said about his work, he will linkback to you (post).
Before Pingback, trackback was developed by SixApart.
Problem was it is prone to spam and requires user's intervention to work.
Very fast after its invention Pingback apeared as simplified & automated version.
As major benefit over trackback, pingback is developed to automate all work:
a) automatically discover pingback server
b) inform server that you quoted its content
c) server checks quote is realy there (if link in valid for exists)
d) upon successful nagotatiaton both parties act in their own custom way (usually log pingback as blog comment)
Don't get me wrong, I don't have anything against trackback, but simply like more how PB works over TB.
More about Trackback vs Pingback you can read on Hixie's blog.
Technically, Pingback is an XML-RPC request sent from Site A to Site B.
So, let's get to code:
Pingback consists of 3 parts: Client, Server and communication protocol.
First, inform everyone that you support pingback and provide URL to server.
This information should be accessable on all your blog pages.
<cfheader name="x-pingback" value="http://#CGI.HTTP_HOST#/pingback/xmlrpc.cfm"/>Client process blog entry and check for external links.
If so, it checks them to see if any of those links has information about pingback server (see above)
text.cfm
<cfscript> pringbackproc = createObject("component","pingback").init(logging=true); variables.targetURI = form.address; variables.xmlrpcserverurl = pringbackproc.discoverPingbackServerUri(url=variables.targetURI); </cfscript>
If linked page supports pingback, then you'll inform it how you are interested about their blogs
<cfscript> //if page supports pingbacks if (comparenocase(variables.xmlrpcserverurl,"false")){ //sends pingback to quoted blog's server variables.structResult = pringbackproc.sendPingback(sourceURI=variables.sourceURI,targetURI=variables.targetURI,contactURI=variables.xmlrpcserverurl); //debug. Ignore ir in production use. if (isDefined("variables.structResult") and isStruct(variables.structResult)){ varaibles.tools.dumpit(var=variables.structResult,isAbort=false); } } </cfscript>
Server components receives and process pingback from external resources.
C: Hello Mr Server, I would like to inform you that your blog has been quotes in my blog!
S: Hi, as soon as I check that blog and verify that I am quoted properly, I'll call you back and inform you about results
pingback.cfc -> pingbackPing
<cfscript> // Sends HTTP request to site that pinged us linea = httpget(pagelinkedfrom); if (!isStruct(linea) or !StructKeyExists(linea,'filecontent')){ arrMessage = [16, 'The source URL does not exist.'];//return xmlError(16, 'The source URL does not exist.'); //this.tools.logit("pingback from " & pagelinkedfrom & " failed 16"); return arrMessage; } strLinkToBody = linea.filecontent; ... //check for site's title matches = REMatch('<title>([^<]*?)</title>', strLinkToBody); title = matches[1]; //should not be more then one title tag present on page //if title is not present, reject call if (len(title) eq 0){ arrMessage = [32, 'We cannot find a title on that page.']; if (this.enableLogging) this.tools.logit("pingback from " & pagelinkedfrom & " failed 32"); return arrMessage; } //check page body to see if link to us is present matches = REMatch("<a[^>]+?" & REEscape(pagelinkedto) & "[^>]*>([^>]+?)</a>", strLinkToBody); // if URL isn't in a link context, issue error and reject call if (arraylen(matches) eq 0){ arrMessage = [0, 'There''s no link to us?.'];//return xmlError(0, 'There''s no link to us?.'); return arrMessage; } //TODO: //When ping is successfully verified DO something here: write in database and/or send some notificaiton to article author //returns message about successful verification return arrMessage; </cfscript>
Voila! That's it!
Full code with working example can be found on http://pingback.riaforge.org.
I would like to thank Wordpress for its open source-ness as well to journurl (http://support.journurl.com/index.cfm?fa=skin.readthread&group=9&thread=245&date=all) for CF implementation of XML-RPC protocol.
Pingback @ RIAFORGE
http://pingback.riaforge.org/
Readings:
VBSEO tutorial
Nice visual presentation
http://www.vbseo.com/linkbacks/
Wordpress tutorial
Well said using simple words
http://www.optiniche.com/blog/117/wordpress-trackback-tutorial/
Wikipedia about linkback
Nice comparison table
http://en.wikipedia.org/wiki/Linkback
June 17th, 2009 - 10:33
HEY!!! Marko’s project is becoming popular, considering that CF & blogging is not so interesting for wide audience
http://www.remotesynthesis.com/post.cfm/coldfusion-open-source-update-june-16-2009
@marko: Please don’t forget us, small men, when you join Ben, Sean, Ray and others
June 17th, 2009 - 21:57
Ben who?
Don’t worry my friend., it’s kinda hard to forget you:)