A Simple Joomla Module to Display the Number of Tweets for the Current Page

At itoctopus, we like to share our extensions for the benefit of the Joomla users and the Joomla ecosystem. One of the extensions we have developed recently is a module that displays the number of Tweets for the current page on a Joomla website.

The module is super simple. All you need to do is to assign it to the menu item and position of your choice, and you will see the magic happens (e.g. the number of tweets for the current page will appear).

You can download the module here. The module is compatible with Joomla 2.5 and Joomla 3.x. The module is less than 2 KB in size (uncompressed) and does not contain any hidden links (it is a practice that we, at itoctopus, strongly oppose).

How does the module work?

Note: You don’t have to read this to get the module to work. The module will work just by installing it and assigning it to the appropriate menu item and module position. The below is just a technical information for those who really like to know how the module gets the number of tweets.

The module first gets the current page using the JURI::current() Joomla function, which is then passed as a GET parameter to the following URL: http://urls.api.twitter.com/1/urls/count.json.

For example, if the current URL is http://www.yourjoomlawebsite.com, then the following URL will be grabbed using curl (we use curl and not file_get_contents because the latter function will not work if allow_url_fopen is set to 0):
http://urls.api.twitter.com/1/urls/count.json?url=http://www.yourjoomlawebsite.com. The aforementioned URL will return the following json response:

{"count":0,"url":"http:\/\/www.yourjoomlawebsite.com\/"}

The above means that the page has been tweeted 0 times (in this case the module will not display anything). Note that the module will both try the www and the non-www variations of any page and will get the total number of tweets for both variations.

What if the module doesn’t work?

If the module doesn’t work then most likely the curl library is not installed on top of your PHP installation. You should contact your host to do that for you. You can also modify the code to use file_get_contents instead of using curl functions, provided allow_url_fopen is set to 1 in your php.ini file.

How to change the module’s layout?

You can change the module’s layout by copying the file modules/mod_tweets/mod_tweets.php to the file templates/your-template-name/html/mod_tweets/default.php and then making your modifications there.

Are there any caveats?

Since we are using curl, then the module can slow down the whole website if Twitter takes a long time to get back to us with the json result. Contact us if you are experiencing any of these issues on your website and we’ll help you fix it.

Now for the usual disclaimer: Although we have developed the module ourselves and installed it on many of our clients’ websites, we cannot be held accountable/responsible for any direct/indirect issues that the module can cause to your Joomla website.

If you need help with the installation of the module, or if you want help modifying it, then please contact us. Please note that our fees apply.

No comments yet.

Leave a comment