<?php error_reporting(0); ?>
<?php header('Content-Type: application/json'); ?>
<?php include './library/PEAR/Services/JSON.php'; ?>


<?php
// http://www.google.com/talk/service/badge/New

$url = 'http://www.google.com/talk/service/badge/Show?tk=***-INSERT-GOOGLE-TALK-CHATBACK-BADGE-KEY-HERE-***&amp;w=200&amp;h=60';
$contents = file_get_contents($url);

$doc = new DOMDocument();
$doc->loadHTML($contents);

$xpath = new DOMXPath($doc);
$nodes = $xpath->query("//div[@class='r']");
$node = $nodes->item(1);
$s = trim($node->nodeValue);

$pres['jid'] = "***-INSERT-JABBER-ID-HERE-***";
$pres['name'] = "***-INSERT-NAME-HERE-***";

if ($s == 'Offline') {
	$pres['show'] = 'offline';
} elseif ($s == 'Available') {
	$pres['show'] = 'available';
} elseif ($s == 'Away') {
	$pres['show'] = 'away';
} elseif ($s == 'Busy') {
	$pres['show'] = 'dnd';
}


$encoder = new Services_JSON();
$output = $encoder->encode($pres);

?>

<?php print $output; ?>
