Fredrik Karlström Fredrik Karlström

Socialstats - A Simple Social Bar Without JavaScript

Socialstats is a tiny piece of PHP code that fetches sharing statistics of a certain URL from the most common social networks of today; Facebook, Twitter, LinkedIn and Google Plus. Feedburner support is also included, but commented out by default.
Published by Fredrik Karlström
Last updated

The default looks

Socialstats, horizontal mode

Socialstats, vertical mode

The theme is comparatively easy to configure, with one set of sprites for the images and one line of CSS to change between horizontal and vertical display mode.

The technical talk

The script fetches the JSON data from the corresponding services by parallel cURL execution, parsing out the number of times the provided URL has been shared. The traffic is fairly light, however caution should be exercised on high-traffic websites, as several requests are made each time the script is run.

To configure the script for your own sites usage, configure the $target variable in the first few lines, then proceed to comment out any services you do not wish to include.

Credits

The social media icons are taken from the excellent Designmodo free social bookmarking icon set, and the multiple cURL implementation was guided by Jon Haddad’s blogpost on the topic.

Download Socialstats

» Socialstats 1.1 (tar.gz)

Changelog

  • Version 1.1
    • Added concurrent Google Plus data
    • Example page bundled in tarball
    • Number formatting added

Known issues

For some reason, the Google Plus API does not take domain names without trailing slashes as a valid argument — it returns an error 400. URIs for underpages with or without extensions seems to work without problem.

Comments

The comments feature requires JavaScript execution.

Write a comment

Comment posting temporarily disabled.