-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXboxGamercard.class.php
executable file
·65 lines (46 loc) · 1.81 KB
/
XboxGamercard.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
define('URL_PREFIX', 'http://gamercard.xbox.com/en-US/');
define('URL_AFFIX', '.card');
define('SUBSCRIPTION_GOLD', 'Gold');
define('SUBSCRIPTION_SILVER', 'Silver');
class XboxGamercard {
public $gamertag;
public $avatars;
public $html;
public $subscription;
public $gamerscore;
public $games;
public function __construct($gamertag) {
$this->gamertag = $gamertag;
$this->refresh();
}
public function refresh() {
$url = URL_PREFIX . rawurlencode($this->gamertag) . URL_AFFIX;
$h = file_get_contents($url);
if($h === false) {
throw new Exception("Invalid gamertag or service not available");
}
$this->html = $h;
$this->subscription = stristr($h, "<span class=\"Gold\">") === false ?
SUBSCRIPTION_SILVER : SUBSCRIPTION_GOLD;
$re = '/<img class="GamerPic" width="64" height="64" src="(.+)" alt=".*" /';
preg_match($re, $h, $m);
$this->avatars = array(
'tile' => $m[1],
'body' => "http://avatar.xboxlive.com/avatar/{$this->gamertag}/avatar-body.png",
'large' => "http://avatar.xboxlive.com/avatar/{$this->gamertag}/avatarpic-l.png",
'small' => "http://avatar.xboxlive.com/avatar/{$this->gamertag}/avatarpic-s.png"
);
$this->gamerscore = preg_match('/<div class="Stat">([0-9]+)<\/div>/', $h, $m);
$this->gamerscore = intval($m[1]);
$this->games = array();
$re = '/<img class="Game" width="32" height="32" src="(.+)" alt="(.+)" title="(.+)" \/>/';
preg_match_all($re, $h, $m);
for($i = 0; $i < count($m[1]); $i++ ) {
$this->games[] = array(
'title' => $m[3][$i],
'tile' => $m[1][$i]
);
}
}
}