Introduction

While a growing number of bloggers are starting to understand that blogging is ubiquitous enough to believe that if someone had something to say, they should say it on their weblog, it presents an interesting challenge for those attempting to follow a conversation throughout the web.

HTML Form Builder

Currently, there are three methods for keeping track of what people are saying about your words. The first is to check your referral logs to see what sites are being used to get to your words, the second is to use Trackbacks and hope your fellow blogger is savvy enough to understand the concept so that you can follow it right on your own web site and the last is to go out there and find it with a search engine like Technorati, Ice Rocket, PubSub or Google Blog Search.

Because referral data is a bit too chaotic and Trackbacks have a technological barrier to entry (not to mention a bit too spammy for our tastes), we’ve been playing around with integrating Google Blog Search results into our web site to serve the role of Trackbacks on Particletree. Thanks to RSS, XSL and a little PHP ingenuity, we can place the results of a URL search of any entry directly on our site without the need to go to another URL.

See It In Action

We’ve implemented this solution here at Particletree. You can see it at the bottom of every post, right under the name of the author, or below as a demo example. Just click on the link that says, “See what other sites are saying about [Entry Title](43) “.

SOMETHING GOES HERE.

The Files

The code in this example requires your server to have PHP and XSL support to run. The package below contains everything you need to get started.

Searchbacks.zip

Implementation

You’ll notice that we went ahead and used this technique inside of our lightbox gone wild script. You could also opt to just put the information underneath the post with the comments. Just follow the steps below, and if you choose the second option then skip the lightbox step.

Download the files and set the variables

Once you download the files, open up the searchbacks folder to find the PHP and XSL files needed. This folder will contain all of the server side code, as well as be the storage location for the cached files. Let’s quickly take a look at those four main files, and see what needs to be changed.

  • searchback-count.php: The purpose of this file is to cache the RSS feed, and to display the count of items inside of the feed. Make sure you set $path (line 25) to the location of the searchbacks folder on your web server, $url (line 5) to the URL of your blog post, and $filename (line 10) to the unique name to save the cached file as.

  • searchback.php: This file pulls the cached RSS file, and displays the results with an XSL template. Set $url (line 3) to the $_GET request, and make sure the cached file name is built the same way you did for searchback-count.php.

  • searchback.xsl and searchback-count.xsl: These are the corresponding XSL files. You do not need to touch these unless you wish to change the markup of the displayed results.

Include searchback-count.php into your blog

To make this file functional, make a link anywhere on your blog with a structure similar to what is shown below:

<a href="/searchbacks/searchback.php?file=<?php echo($_SERVER['SCRIPT_NAME']); ?>" >See what  other sites are saying about <strong>Replacing Trackback With Google Blog Search <? include  $path.'searchbacks/searchback-count.php'; ?></a></strong>

The code above includes searchback-count.php, and links to searchback.php. When the code above is run, the include file will query Google Blog Search, cache the results, and echo out the total amount of matching results. If the user clicks on the link, they will be taken to searchback.php, and the full results will be displayed there.

Include the necessary files

First start with the CSS. Include the searchback file, and also the lightbox file if you plan to use lightbox.

<link rel="stylesheet" type="text/css" media="screen" title="searchback" href="/css/searchback.css" />
<link rel="stylesheet" type="text/css" media="screen" title="lightbox" href="/css/lightbox.css" />

Also, for the lightbox users, be sure to include the JavaScript file.

<script src="/scripts/lightbox.js" type="text/javascript"></script>

For more help on lightbox, be sure to check out Lightbox Gone Wild!

How It Works

Google Blog Search allows any blogger to find out who has linked to a certain post of theirs by typing in the word “link:” followed by the URL of the post. Google Blog Search then shows the results, and offers the results as an RSS feed. So what we’re going to do is query Google Blog Search with the current URL, cache the results every 30 minutes on our own server, and then display the resuls to our readers with XSL. We’ll start by querying Google Blog Search.

Getting the RSS feed from Google Blog Search

In searchback-count.php we find out the Particletree URL with the following two lines:

$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
$url = str_replace('/index.php', '', $url);

If you take the current URL of this page, the variable $url would contain http://particletree.com/features/replacing-trackback-with-google-blog-search/. If you are unsure of what your URL should look like, play around with Google Blog Search until you find the format that yields accurate results for your site. After that, we will then build the URL we wish to send to Goolge Blog Search.

$searchbackUrl = 'http://blogsearch.google.com/blogsearch_feeds?q=link%3A'.
                            $url.
                           '&ie=utf-8&num=100&output=rss';

Cache the RSS

So, we now have a URL we wish to send to Google Blog Search. The next step is to determine if we already have data in cache, or if we need a fresh response from Google. First we determine the filename from the URL, and then pass it into the function.

$filename   = explode('/',$url);
$filename   = $path.'searchbacks/'.$filename[count($filename) - 1].'.rss';

In this case, the trailing slash is taken off, and then the URL is split. By taking the last element in the newly formed array, we are given that title of the post. So, for this entry the filename would be equal to replacing-trackback-with-google-blog-search.rss. Once we’ve determined the filename, check to see if it is in cache.

if(cacheNeedsUpdate($filename)) {
    cacheData($trackbackUrl, $filename);
}function cacheNeedsUpdate($filename) { 
    $ret = true;
    if (file_exists($filename) &&
       (strtotime('-30 minutes') < filemtime($filename))) {
           $ret = false;
    }
    return $ret;
}

The cacheNeedsUpdate() function will always return true unless the cached file already exists and it has been less than 30 minutes since the last update. Assuming an update to the cache is needed, we call cacheData().

function cacheData($location, $filename) {
    $input = new DomDocument();
    $input->load($location);
    $input->save($filename);
}

The parameter $location is set to the $searchbackUrl we set above, and $filename is the name of the file we wish to save to.

Display the results

The last step is to display the results. You can attach any XSL file to the saved RSS file and display them however you like. For this tutorial, we have two XSL files. One just displays the count of items in the RSS feed. The other displays the entire feed in an ordered list. Both can be called using the following function:

function displaySearchbacks($xslFile, $xmlFile) {
    $xsl = new DomDocument();
    $xsl->load($xslFile);
    $input = new DomDocument();
    $input->load($xmlFile);
    $proc = new XsltProcessor();
    $proc->importStylesheet($xsl);
    echo (substr($proc->transformToXML($input) ,21));
}

displaySearchbacks() takes a valid XSL and XML file, and transforms them. From here you can display the results on your page, or in a lightbox.

Benefits

  • Fight spam: We can rely on the big boys to fight spam for us. There is a much better chance that Google can filter spam better than smaller companies.

  • No barrier: We no longer rely on another blog setting up a trackback to us for us to see it.

  • Multiple services: This technique is not limited to Google Blog Search. We can integrate it with Ice Rocket, Technorati, etc. It can become quite elaborate.

  • Conversation: Creates a higher chance that the person you are talking about in your post will hear what you have to say. Currently, the highest guarantee is by commenting on their blog, and this provides an alternative.

Limitations

This technique suffers from a few limitations, all of which are acceptable from our point of view. First, an outside service is needed, so your information is dependant on them. Second, most blog search engines will pick up links to you, such as del.icio.us links or sidebar links. These links aren’t necessarily ‘talking’ about you — they are just linking to you. Third, and probably fixable, is the fact that the searchback sometimes picks up 0 links, so until the next caching cycle it will show 0 incoming links.

HTML Form Builder
Ryan Campbell

Replacing Trackback with Blog Search by Ryan Campbell

This entry was posted 5 years ago and was filed under Features.
Comments are currently closed.

· 18 Comments! ·

  1. troy · 5 years ago

    I love you guys! I’ve been wanting a nice little RSS/XSL script for weeks.

  2. Jonic · 5 years ago

    That is amazingly clever… I especially like the fact that now you don’t need to rely on your visitor having the technical knowhow to trackback you. Google does it all for you!

  3. drazin · 5 years ago

    cool…i will attempt to do this at some point…only to assure myself that noone reads my site and noone cares….thanks for making it possible to show all that to everyone.

  4. Blair · 5 years ago

    ‘Tis funny. I was thinking about nearly this very thing on the way to work this morning — how to follow a meme or idea as it travels the internet, moving across the blog “networks,” getting posted on various sites, etc., all the while picking up additional (sometimes dead-ended) commentary and additional information along the way.

  5. Lawrence Meckan / Absalom Media · 5 years ago

    Yet another useful and novel solution to the dilemma of trackbacks.

  6. George Papadakis · 5 years ago

    Well thought and executed Ryan.

  7. Frank · 5 years ago

    What can I say, thats pretty awesome..hehe hey if you guys have some time, maybe you could give my blog some traffic cause its really dead…like literally….I have no comments.. well ill ttyl..

  8. nate · 5 years ago

    What would be even more fabulous (since I’m a lazy SOB), is if it was made into a plugin for the fashionable WordPress system.

    I could eat that up.

  9. Julian Schrader · 5 years ago

    Thanks - just thought about techniques to replace trackbacks some days ago. That’s cool!

  10. Ben · 5 years ago

    Hi Ryan,

    Great article. I’ve been a big supporter of trackback, and wrote some articles on a C# implementation with referrer checking to combat spam, but I have to say that this method is better. I’ll be converting to this asap. Watch out for the ASP.NET example soon for all you who aren’t in the PHP school!

  11. Watson Soma · 5 years ago

    Everyone needs a hug.

  12. Alex Neri · 5 years ago

    Nice solution! Thank you guys!

  13. Pedram · 5 years ago

    Yey… I never liked trackbacks to begin with ;-)

  14. Pedram · 5 years ago

    Btw… The searchback.zip is incomplete, it has no css and the code isn’t complete. It’s not particularly right either.. there’s a repeated reference to $path which is not set. I could rewrite this as an extension of the object of the dependent extension if anyone wants.

  15. Xavier Badosa · 4 years ago

    Cool but… is it legal? Could Google consider it an “abuse of service”?

    http://www.google.com/intl/en/terms_of_service.html

    Section Personal Use Only “You may not take the results from a Google search and reformat and display them.”

    The text “Powered by Google Blog Search” may not be enough…

    Anyone from Google out there?

  16. Brandon Hall · 4 years ago

    Great idea, but doesn’t it take away the idea of trackbacks completely?

  17. morganusvitus · 4 years ago

    The site looks great ! Thanks for all your help ( past, present and future !)

  18. Mauricio Pastrana · 3 years ago

    Must now be dead!

    check it out, under “See this in action”, you get sent to this URL: http://particletree.com/trackbacks/trackback.php?file=%3C?php%20echo($_SERVER'SCRIPT_NAME');%20?%3E

    -mp