-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
76 lines (56 loc) · 1.74 KB
/
query.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
<?php
if(isset($_GET['name']) && isset($_GET['type'])) {
$name = $_GET['name'];
$type = $_GET['type'];
$id = processName($name);
switch ($type) {
case 'statsfeed' :
$stats = getKFStatsfeed($id);
generateJSON($stats);
break;
case 'achievements' :
$achievements = getKFAchievements($id);
generateJSON($achievements);
break;
}
}
function processName($name) {
if (preg_match('/[0-9]{17}/', $name)) {
return 'profiles/'.$name;
} else {
return 'id/'.$name;
}
}
function getKFStatsfeed($id) {
$HEAD_URL = 'http://steamcommunity.com/';
$TAIL_URL = '/statsfeed/1250';
$url = $HEAD_URL.$id.$TAIL_URL;
$xml = simplexml_load_file($url) or die ('Error loading XML data');
if ($xml->xpath('error')) {
die('Does not own game');
} else {
foreach($xml->stats->item as $item) {
$stats[(string) $item->APIName] = (string) $item->value;
}
}
return $stats;
}
function getKFAchievements($id) {
$HEAD_URL = 'http://steamcommunity.com/';
$TAIL_URL = '/stats/KillingFloor?tab=achievements&xml=1';
$url = $HEAD_URL.$id.$TAIL_URL;
$xml = simplexml_load_file($url) or die ('Error loading XML data');
if ($xml->xpath('error')) {
die('Does not own game');
} else {
foreach($xml->achievements->achievement as $item) {
$stats[(string) $item->apiname] = array((string) $item->name, (string) $item->iconClosed, (string) $item->description, (string) $item->unlockTimestamp);
}
}
return $stats;
}
function generateJSON($stats) {
header('content-type: application/json');
$json = json_encode($stats);
echo($json);
}