Free display of ICQ, Jabber, Skype and MRA statuses on the site



It may be necessary to add to the site a display of the current network status of contacts of various messaging services. Most often, this can be found on business card sites or to display the availability of an online support operator. You can use official or informal services for this, which, as a rule, provide more design options, different themes with pictures. But what if we have an original site and the default images do not fit into its style? We'll have to either invent our own bike, which is unlikely to be better than existing ones, or borrow ideas from ready-made solutions and adapt them to our needs. We will go the second way.

To begin with, we define our tasks:
- if possible, use official status determination services
- if they are absent, you can resort to outsiders
- the method should be as simple as possible, without surplus (you can always expand it later)
- so that the page does not hang at the time of the request, we will make a buffer.

We will consider 4 main methods using ICQ, Jabber, Skype as an example and MRA. The rest can be done in a similar way.

Verification will be done using php. Create a file “status.php” and add its execution to the scheduler every 5 minutes. The status will be saved in a separate file.

In my case, each protocol has its own file, for example “icq.s”. Because I saved not only the status text, but also the picture, then part of the html code is written in two lines. In order not to tear out paragraphs on the page of the site later, I decided to simply insert the desired piece in a specific place on the page:


It will be possible to record arbitrarily large and complex designs.



ICQ Status


We will use the official status check service. It also has its drawbacks, it works strange. For example, he gives the status “Away” only when the contact has the status “Invisible”. In other cases, except offline, the contact is always displayed "Online". Therefore, if you set the status “Away” in the client, it will still be displayed as “Online”. But this is not a reason to refuse, we will use the official service, as was stated in the tasks.

Do not forget to allow the display of status on sites in the client. There are many ways to determine status, but they use the same address for verification:

http://status.icq.com/online.gif?icq=ТУТ_ВАШ_UIN

Depending on the current ICQ status, the address of the given image will take the following values:

http://status.icq.com/0/online0.gif - Away
http://status.icq.com/0/online1.gif - Online и все остальные
http://status.icq.com/0/online2.gif - Offline

Depending on the number in the picture name, the status will be determined. We will get the “Location” header from the server’s response and grab this number from there. And only then with the help of switch we set what will be given as status. The design is as follows:

try {
    $a = @get_headers('http://status.icq.com/online.gif?icq=ТУТ_ВАШ_UIN');
    foreach($a as $Header) { if (is_int(strpos($Header, 'Location'))) { $Status = substr($Header, -5, 1); } }
    switch ($Status){
        case '0': $icqstatus = ''; break;
        case '1': $icqstatus = ''; break;
        case '2': $icqstatus = ''; break;
        default: $icqstatus = ''; break;
    }
} catch (Exception $e){}

The variable "icqstatus" stores the current status. If the service does not work, then the status is “Offline”. Now write this status to the file buffer:

$f=fopen('/home/mysite/icq.s','w');
fwrite($f,$icqstatus);
fclose($f);

Please note that you must specify the full path to the file on the server.
As I wrote above, to display the status in the right place on the page, insert:



UPD: changes on the ICQ site
Now, instead of the three options, only “online” or “offline” remained. Change the code as follows:

View working option
Depending on the current ICQ status, the address of the given image will take the following values:

http://status.icq.com/0/online1.gif - Online

All other values ​​will mean Offline. So we write:

try {
    $a = @get_headers('http://status.icq.com/online.gif?icq=ТУТ_ВАШ_UIN');
    foreach($a as $Header) { if (is_int(strpos($Header, 'Location'))) { $Status = substr($Header, -5, 1); } }
    switch ($Status){
        case '1': $icqstatus = ''; break;
        default: $icqstatus = ''; break;
    }
} catch (Exception $e){}

The rest is as usual.



Skype status


There is an official Skype status check service. Unlike ICQ, we have a great opportunity to get an answer in the form of a status text. We use the following link for this:

http://mystatus.skype.com/ВАШ_НИК.txt

Do not forget to allow the display of status on sites in the client. Depending on the current status of Skype, we get the following values:

Online
Away
Do Not Disturb
Offline

All that remains for us is how to get the contents of the text file without any additional gestures, it is already kosher and does not contain anything superfluous.

try {
    $a = @file_get_contents("http://mystatus.skype.com/ВАШ_НИК.txt");
    switch($a) {
        case 'Online': $skypestatus = ''; break;
        case 'Away': case 'Do Not Disturb': $skypestatus = ''; break;
        case 'Offline': $skypestatus = ''; break;
        default: $skypestatus = ''; break;
    }
} catch (Exception $e){}

And according to tradition, we will write the received status from the “skypestatus” variable to a file:

$f=fopen('/home/mysite/skype.s','w');
fwrite($f,$skypestatus);
fclose($f);

In the right place on the site, we’ll print:




Jabber Status


This is just the case when we can not do without using third-party services. There are no standard methods for determining the network status of Jabber. But there are kind people. The truth is more complicated.

At first I used this service http://web-apps.ru/jabber-presence/ and for a long time it worked perfectly. But recently I went offline for a week and had to look for alternatives, one of which was http://presence.jabberfr.org/ . We will use it.

We go to the page of the French service, write our JID and select "Your status (text)" below. A generated address will appear even lower, by which the status will be determined.

http://presence.jabberfr.org/ТУТ_ДЛИННЫЙ_ХЭШ_НАШЕГО_JID/text-en.txt

Now we need to add the presence.jabberfr.org service to the roster. It will appear in the contact list and will have the same status as yours. To enable the status display using the link generated above, we will send a message to the bot with the text "visible" without quotes.

Depending on the current status of Jabber, we have the following values:

Available
Away
Not available
Do not disturb
Free for chat
Offline

If the status is “Invisible”, the last used status will be shown before hiding.
We realize the display of the received status on our website. Also, as in the case of Skype, we get just a text file. In addition to status, it contains nothing more.

try {
    $a = @file_get_contents('http://presence.jabberfr.org/ТУТ_ДЛИННЫЙ_ХЭШ_НАШЕГО_JID/text-en.txt');
    switch ($a){
        case 'Available': case 'Free for chat': $jabberstatus = ''; break;
        case 'Away': case 'Not available': case 'Do not disturb': $jabberstatus = ''; break;
        case 'Offline': $jabberstatus = ''; break;
        default: $jabberstatus = ''; break;
    }
} catch (Exception $e){}

The jabberstatus variable contains the current status. Let's write it to the jabber.s file:

$f=fopen('/home/mysite/jabber.s','w');
fwrite($f,$jabberstatus);
fclose($f);

In the right place on the site, display the status:



UPD: alternative option
Since Now the French service has fallen, I decided that it’s better to write an alternative, i.e. http://web-apps.ru/jabber-presence/ . Our domestic friend. One of them will work.

View working option
We go to the page http://web-apps.ru/jabber-presence/ and read the description. For the lazy, I’ll write everything in steps.

Add web-apps-presence@jabber.ru to our roster. After adding, a message with a brief help will come. We will need to remember the contents of the “html-string” items: the first at the jabber address, the second at its md5 hash. In the example, just the second option will be used.

http://web-apps.ru/jabber-presence/html/xid/ТУТ_ДЛИННЫЙ_ХЭШ_НАШЕГО_JID

Now we write a message in the bot’s message containing only the number 1. We get the answer that the status display is turned on.
Next, we set the type of displayed status, we only need the text. To do this, send the following message to the bot in PM:

set html=%{status}

Depending on the current status of Jabber, we have the following values:

available
away
xa
dnd
chat

If the status is “Invisible”, the last used status will be shown before hiding. We equate all other cases to offline.
We realize the display of the received status on our website.

try {
    $a = @file_get_contents('http://web-apps.ru/jabber-presence/html/xid/ТУТ_ДЛИННЫЙ_ХЭШ_НАШЕГО_JID');
    switch ($a){
        case 'available': case 'chat': $jabberstatus = ''; break;
        case 'away': case 'xa': case 'dnd': $jabberstatus = ''; break;
        default: $jabberstatus = ''; break;
    }
} catch (Exception $e){}

The rest is as usual.



MRA Status


This is Mail.ru Agent. Again we will use the official Mail.ru Agent status checking service. Like ICQ, we are given the opportunity to display only a picture, without a status text:

http://status.mail.ru/?АДРЕС_ПОЧТЫ

Because all images have one address and all of the same size, you have to come up with something else. You can find out their weight, but this is not the best way. Let's make a knight's move, that is, we’ll just determine the md5 hash of the image. We also get three types of statuses:

0318014f28082ac7f2806171029266ef - Online, Free for chat, Do not disturb
89d1bfcdbf238e7faa6aeb278c27b676 - Away
a46f044e175e9b1b28c8d9a9f66f4495 - Offline, Invisible

After defining the hash with a familiar construction, we set the status:

try {
    $a = @md5(file_get_contents("http://status.mail.ru/?АДРЕС_ПОЧТЫ"));
    switch($a) {
        case '0318014f28082ac7f2806171029266ef': $mrastatus = ''; break;
        case '89d1bfcdbf238e7faa6aeb278c27b676': $mrastatus = ''; break;
        case 'a46f044e175e9b1b28c8d9a9f66f4495': $mrastatus = ''; break;
        default: $mrastatus = ''; break;
    }
} catch (Exception $e){}

We write the received MRA status to a file:

$f=fopen('/home/mysite/mra.s','w');
fwrite($f,$mrastatus);
fclose($f);

And in the right place we will display the status:



You can check how this works here http://damaks.me/ . There is a lot of work, I’ll try to stay online longer so that I can personally see this action.


Other protocols


Similarly, we can check the current network status of other protocols. If there is an official service, then use it; if not, then use alternative ones. Here are 4 different methods, at least one of which is suitable for other protocols.

Vkontakte status
We get the status (you can use either a numeric id or an alias):

try {
    $ch = curl_init('https://api.vkontakte.ru/method/getProfiles?uids=ТУТ_ВАШ_ID&fields=online');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result=curl_exec($ch);
    curl_close($ch);
    $a = substr($result, -4, 1);
    switch ($a){
        case '1': $vkstatus = ''; break;
        case '0': $vkstatus = ''; break;
        default: $vkstatus = ''; break;
    }
} catch (Exception $e){}

We write it to the file:

$f=fopen('/home/mysite/vk.s','w');
fwrite($f,$vkstatus);
fclose($f);

And where you need to output:




PS


I found different ways of displaying statuses on different resources, I just can’t remember exactly. Moreover, the same descriptions are found many times. If the source is known, I will add to the post. If you have any comments / suggestions, I will listen with pleasure.

Also popular now: