<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv=Content-Type></meta>
<title>Jean-Marc Liotier's presence</title>
<meta http-equiv="refresh" content="240"></meta>
</head>

<body>

<p>Presence and instant messenging are available from any <a href="http://www.jabber.org/about/overview.shtml">Jabber</a> client including <a href="http://www.google.com/talk/"> Google Talk</a>. Here is my current status :</p>
<ul>
<?php
require("class.jabber.php");

// The source code for my presence indicator is now available for whoever wants
// it. It is made possible by class.jabber.php, a Jabber library for PHP
// (http://cjphp.netflint.net/?section=about). I customized one of the examples
// provided with class.jabber.php
// (http://cjphp.netflint.net/?section=manual&sub=examples). It has many rough
// edges such as the user's name sprinkled across the markup code instead of
// being a proper parameter, or the page's presence being sent to the polled
// account instead of being hidden. And it is quite slow because it queries at
// load time. But I like it better than the example packaged with
// class.jabber.php.
//
// Exemple : http://jim.liotier.org/presence.php
//
// It basically does the job and I am therefore quite sure that there will be
// interested users. So this is the "early" part of "Release Early, Release
// Often". Take that hack, customize it, tweak it and generally improve it...
// And most of all please report back somewhere so that everyone can benefit.
//
// If anything is unclear to you, please be sure to report it to me :
//
// Jean-Marc Liotier
// Mail : jim@liotier.org
// Jabber : jim@jabber.grabeuh.com
// http://jim.liotier.org/
//
// http://serendipity.ruwenzori.net/index.php/2006/02/27/jabber-presence-indicator-in-a-web-page 

$JABBER = new Jabber;

$JABBER->server         "jabber.example.com";
$JABBER->port           5222;
$JABBER->username       "bot_login";
$JABBER->password       "bot_password";
$JABBER->resource       "ClassJabberPHP";

// The script itself knows nothing about the user whose status it checks.
// It is the watcher bot user that has the watched user on his roster. The
// script will return the status of anyone on the watcher bot user's roster.
// That makes it quite flexible because it will work for any number of users.

$JABBER->enable_logging FALSE;
$JABBER->log_filename   'jabber.log';

$JABBER->Connect() or die("Couldn't connect!");
$JABBER->SendAuth() or die("Couldn't authenticate!");

$JABBER->SendPresence("invisible");

$JABBER->CruiseControl(1);  //or more as needed
// Increases page load time !

$JABBER->Disconnect();

function 
Handler_presence_available($message)
{
    global 
$JABBER;
    
$jid $JABBER->GetInfoFromPresenceFrom($message);
    
$presence_status $JABBER->GetInfoFromPresenceStatus($message);
    
$presence_detail $JABBER->GetInfoFromPresenceShow($message);
    print (
"<li><p>Joe User ($jid) is currently online");
    if (
$presence_detail != "") print (" ($presence_detail)");
    print (
".</br>");
    print (
"$presence_status</p>");
}

function 
Handler_presence_unavailable($message)
{
    global 
$JABBER;
    
$jid $JABBER->StripJID($JABBER->GetInfoFromPresenceFrom($message));
    print 
"<p>Joe User is currently offline.</p>";
}

?>
</ul>

</body>
</html>