-
Notifications
You must be signed in to change notification settings - Fork 2
/
google-ig-gamercard.php
158 lines (141 loc) · 3.89 KB
/
google-ig-gamercard.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?
$gamertag = urlencode(strtolower(trim($_GET['up_gamertag'])));
if(strlen($gamertag) == 0)
$gamertag = 'analogue';
$url = 'http://gamercard.xbox.com/'.urlencode($gamertag).'.card';
$template_path = 'data/template-google.html';
function GetGamertile($data)
{
preg_match("@<img class=\"XbcgcGamertile\" height=\"64\" width=\"64\" src=\"(.*?)\" />@", $data, $matches);
$gamertile = $matches[1];
if(strpos($gamertile, 'http://') === false)
$gamertile = 'http://gamercard.xbox.com'.$gamertile;
return $gamertile;
}
function GetGamertag($data)
{
preg_match("@\<h3 class=\"XbcGamertag.*?\"><a href=\"http://live.xbox.com/member/.*?\"><span class=\"XbcFLAL\">(.*?)</span></a></h3>@", $data, $matches);
$gamertag = $matches[1];
return $gamertag;
}
function GetSub($data)
{
preg_match("@\<h3 class=\"XbcGamertag(.*?)\"><a href=\"http://live.xbox.com/member/.*?\"><span class=\"XbcFLAL\">.*?</span></a></h3>@", $data, $matches);
$sub = $matches[1];
return $sub;
}
function GetRep($data)
{
$to_find = '/xweb/lib/images/gc_repstars_external_';
$pos = strpos($data, $to_find) + strlen($to_find);
$end = strpos($data, '.', $pos);
$rep = substr($data, $pos, $end - $pos);
return $rep;
}
function GetScore($data)
{
preg_match("@<span class=\"XbcFLAL\"><img alt=\".*?\" src=\".*?\" /></span><span class=\"XbcFRAR\">(.*?)</span>@", $data, $matches);
$score = $matches[1];
return $score;
}
function GetZone($data)
{
preg_match("@<span class=\"XbcFLAL\">Zone</span><span class=\"XbcFRAR\">(.*?)</span>@", $data, $matches);
$zone = $matches[1];
return $zone;
}
function GetGames($data)
{
preg_match("#<div class=\"XbcgcGames\">(.+?)</div>#", $data, $matches);
$html_games = $matches[1];
preg_match_all("#<a href=\"(.+?)\"><img height=\"32\" width=\"32\" title=\"(.+?)\" alt=\"\" src=\"(.+?)\" /></a>#", $html_games, $matches);
//print_r($matches);
unset($games);
$i = 0;
while($matches[1][$i] && $matches[1][$i] && $matches[1][$i])
{
$games[$i]['url'] = $matches[1][$i];
$games[$i]['title'] = $matches[2][$i];
$games[$i]['img'] = $matches[3][$i];
$i++;
}
return $games;
}
function PutHTMLGame($game)
{
if($game['url'] && $game['title'] && $game['img'])
{
$html = '<a href="'.$game['url'].'">';
$html .= '<img height="32" width="32" title="'.$game['title'].'" alt="" src="'.$game['img'].'" />';
$html .= '</a>';
}
return $html;
}
// Récupération des données
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$fichier = curl_exec($ch);
curl_close($ch);
// Tri des infos récupérées
$user['gamertile'] = GetGamertile($fichier);
$user['gamertag'] = GetGamertag($fichier);
$user['sub'] = GetSub($fichier);
$user['rep'] = GetRep($fichier);
$user['score'] = GetScore($fichier);
$user['zone'] = GetZone($fichier);
$user['games'] = GetGames($fichier);
// Affichage en mode debug
if(isset($_GET['debug']))
{
echo "<pre>\n";
echo "MODE DEBUG\n\n";
echo 'Gamertile: '.$user['gamertile'];
echo "\n";
echo 'Subscription: '.$user['sub'];
echo "\n";
echo 'Gamertag: '.$user['gamertag'];
echo "\n";
echo 'Rep: '.$user['rep'];
echo "\n";
echo 'Score: '.$user['score'];
echo "\n";
echo 'Zone: '.$user['zone'];
echo "\n";
echo 'Games: ';
print_r($user['games']);
echo "\n";
echo "</pre>\n";
}
// Affichage en mode release (image)
else
{
$template = file_get_contents($template_path);
$search = array('%SUB%',
'%GAMERTAG_HTML%',
'%GAMERTAG%',
'%GAMERTILE%',
'%REP%',
'%SCORE%',
'%ZONE%',
'%GAME_1%',
'%GAME_2%',
'%GAME_3%',
'%GAME_4%',
'%GAME_5%');
$replace = array($user['sub'],
urlencode($user['gamertag']),
$user['gamertag'],
$user['gamertile'],
$user['rep'],
$user['score'],
$user['zone'],
PutHTMLGame($user['games'][0]),
PutHTMLGame($user['games'][1]),
PutHTMLGame($user['games'][2]),
PutHTMLGame($user['games'][3]),
PutHTMLGame($user['games'][4]));
$html = str_replace($search, $replace, $template);
echo($html);
}
?>