24.9.12

jek2kdotcom » Blog Archive » Building a custom Skype-me button with status icon

jek2kdotcom » Blog Archive » Building a custom Skype-me button with status icon

Building a custom Skype-me button with status icon

a simple PHP solution

I’m not a big fan of Skype and I usually don’t use it. However, in a recent project, I was asked to add a “Skype Me” button in the contacts section of a client’s website.

I guess you all know Skype provides a bunch of free buttons and even an online wizard to build custom buttons. This works pretty good, except it only allows to use the default Skype buttons and icons and images are PNGs.

What to do then if you need to use custom-designed buttons? Or if you’re targeting IE6 and have no transparent-PNGs support? I scored 2 on 2, having both those problems.
So I decided to search for some Skype documentation and build a script myself.

Some basic information on creating custom Skype buttons and links can be found here. This explains how to code links, but still doesn’t address my problem. Then I found some more in-depth documentation on building web-services and apps interacting with Skype, that can be downloaded from here.

This way I found out that you can call a remote Skype URL, passing in your username and some parameters, to retrieve a status button, a status code or a status string.

The numeric status code is easier to use. Here’s a short list of numeric codes and their meaning:
  • 0 – unknown
  • 1 – offline
  • 2 – online
  • 3 – away
  • 4 – not available
  • 5 – do not disturb
  • 6 – invisible
  • 7 – skype me
Then I coded a short PHP script to take advantage of this function and retrieve the status code for a given Skype username.

01function getSkypeStatus($username) {
02    $remote_status = fopen ('http://mystatus.skype.com/'.$username.'.num', 'r');
03    if (!$remote_status) {
04        return '0';
05        exit;
06    }
07    while (!feof ($remote_status)) {
08        $value = fgets ($remote_status, 1024);
09        return trim($value);
10    }
11    fclose($remote_status);
12}    

Half of the job was done. Now I needed to link each code to a custom-designed status icon.

1function getSkypeStatusIcon($username) {
2    $status = getSkypeStatus($username);
3    // change the path of the icons folder to match your site
4    echo '<img src="/skype-icons/'.$status.'.jpg" alt="call '.$username.'" />';
5}

So that calling the PHP function with the desired username…

1getSkypeStatusIcon('nicolovolpato');

…returns the necessary HTML code for the icon image.

1<img src="/skype-icons/1.jpg" alt="call nicolovolpato" />

Of course I had then to go back to Photoshop and design my custom icons. I simply named the files like the status codes, where 1.jpg is the icon for offline, 2.jpg is the icon for online and so on.

I’ve tested this script using my Skype account and other accounts and seems pretty reliable. This is not the only method and I’m pretty sure this is not even the best method available, but it’s just the solution I have found to this problem and wanted to share it.

Download the source code (4k ZIP)