Social Statistics module released

I've been working on it for a few days now, but its finally released. Social Statistics is being used on this site and can be found on any page on an enabled site in a block. It provides pluggable statistics for (currently) 3 major Social Networking websites; Del.icio.us, Digg and Ma.gnolia. It currently boasts caching of statistics for a configurable amount of time, AHAH retrieval of statistics which are not cached (thus not slowing down page loads) and an API to make the project extendible to anybody who cares to add a Social Network to the mixture!

The core module consists, mostly, of a few menu callbacks and an API. This API allows the user to enable any number of enabled modules to add their contribution to the block. The 3 enabled sites all have an XML based API, but each does things slightly differently - hence my choice in using them as examples of the module as a whole.

You can find this module over in the Drupal Projects section.

[adsense:468x60:4496506397]

Del.icio.us

Del.icio.us is probably the most simple of the modules. You may notice that every bookmark in Del.icio.us has a 32 character code on the end of it which looks uncannily like and MD5. Thats quite a coincidence because it IS an MD5 - of the target URL. You may also notice it has an RSS feed too. All this module needs to do is go out there and grab the RSS feed for the current URL and, assuming the server returned a "200 OK" status (rather than 503 or 404, etc) then you can go ahead and parse the XML. Easy!

[adsense:468x60:4496506397]

Ma.gnolia

This is almost the same as Del.icio.us, but has a few key differences. Firstly, their API isn't as public as Del.icio.us - you need to sign up and activate a key for your account. This is the feature which caused me to add the 'settings' operation to the Social Statistics API which allows you to tag extra fields onto the settings page. The other difference is that you don't access by URL, you post data to them and they then return the XML. The Ma.gnolia API is far neater and more organised in my opinion, compared to Del.icio.us - however their servers are a LOT slower (at least from my location).

Digg

Digg was possibly the hardest to integrate mainly due to a lack of coherence in their API. It feels like something which has evolved rather than grown in a planned and methodical way. For starters, there is a different URL to submit a new Digg compared to the URL which is required to Digg and existing item (this URL I have yet to decode, so the module currently just sends you to the Digg page for that item). For the first two, the title of the statistic links you to the post page. For Digg, you don't know if you're submitting or digging until you have got the statistic data from the server and, as this is done using AHAH, there is no way to know this at page load time unless the statistics have been previously loaded into cache. This is why the Digg item sometimes has its link on the value and sometimes on the title. I would appreciate thoughts on how to improve this.

AHAH Data Retrieval

The problem I faced during development was that if a particular service was taking its time responding with data, it held up the page load time until it had served up its reply. This isn't really ideal - even with caching, you still had to wait for the initial or updated value. I looked at jQuery and some drupal core commands, such as drupal_http_request, and was pleasantly surprised at how easy it was. Things are certainly much more interesting with jQuery!

If a statistic is cached (using Drupal's internal caching mechanism) then that data is served up straight into the block, however if it is not available, then a template entry is added with an animated "ajax loading" style GIF which I generated using a fantastic and free website; http://ajaxload.info/. The function also adds a single line of jQuery which calls a function included with the module which fires off a background HTTP post back to the website. This post induces another one of the Social Statistics API operations, the 'count' which litterally returns the value - nothing else at all. This value is then cross-faded with the animation using jQuery (ok, I might have got carried away there).

Theming

There are quite a few theme functions provided, so if you dont like the way its lays out its data by default, you should be able to quite easily override it.

More modules?

I would love to have this project gain a repository of extra social networks. I have personally looked into Stumble Upon, but cannot find a way to get it to return any statistic about the URL in question (favourites, likes, dislikes, etc). Does anyone know of a way?