Skip to content

Instantly share code, notes, and snippets.

@djekl
Created March 23, 2012 15:01
Show Gist options
  • Save djekl/2171482 to your computer and use it in GitHub Desktop.
Save djekl/2171482 to your computer and use it in GitHub Desktop.
Plain version of XBOX Last Seen Widget
<?php
$user = 'rentedsmile';
$url = 'http://gamercard.xbox.com/en-US/' . rawurlencode($user) . '.card';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$output = curl_exec($ch);
curl_close($ch);
$html = new DOMDocument;
$html->loadHTML($output);
$list = $html->getElementById('PlayedGames');
$imge = $list->getElementsByTagName('img')->item(0)->getAttribute('src');
$name = $list->getElementsByTagName('span')->item(0)->nodeValue;
$date = strtotime($list->getElementsByTagName('span')->item(1)->nodeValue);
$time = (date('dmy',$date)==date('dmy')) ? 'earlier today' : ((date('dmy',$date)==date('dmy',strtotime('yesterday'))) ? 'yesterday' : floor((time()-$date)/86400) . ' days ago');
echo '<img src="' . $imge . '" /><a href="http://live.xbox.com/en-US/MyXbox/Profile?Gamertag=' . $user . '">' . $user . '</a> - Last seen ' . $time . ' playing ' . $name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment