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


<?php
// http://msdn.microsoft.com/en-us/library/bb936691.aspx

$url = 'http://messenger.services.live.com/users/***-INSERT-WINDOWS-LIVE-ID-HERE-***/presence/';
$contents = file_get_contents($url);

$decoder = new Services_JSON();
$obj = $decoder->decode($contents);

$pres['windows_live_id'] = "***-INSERT-WINDOWS-LIVE-ID-HERE-***";
//$pres['name'] = $obj->displayName;
$pres['name'] = "***-INSERT-NAME-HERE-***";

if ($obj->status == 'Offline') {
	$pres['show'] = 'offline';
} elseif ($obj->status == 'Online') {
	$pres['show'] = 'available';
} elseif ($obj->status == 'Away') {
	$pres['show'] = 'away';
} elseif ($obj->status == 'Idle') {
	$pres['show'] = 'away';
} elseif ($obj->status == 'BeRightBack') {
	$pres['show'] = 'away';
} elseif ($obj->status == 'Busy') {
	$pres['show'] = 'dnd';
} elseif ($obj->status == 'OnThePhone') {
	$pres['show'] = 'dnd';
} elseif ($obj->status == 'OutToLunch') {
	$pres['show'] = 'away';
}


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

?>

<?php print $output; ?>
