/
steamprofile.php
92 lines (78 loc) · 4.11 KB
/
steamprofile.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
<?php
header('Content-type: application/xml; charset=UTF-8');
require_once('steamtags.php');
// !!! FIXME: there has got to be a better way to do this. Maybe move to
// !!! FIXME: the formal XML writer classes.
$xmlents = array('"','&','&','<','>',' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ');
$htmlents = array('"','&','&','<','>',' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ');
function xml_entities($str)
{
global $xmlents, $htmlents;
$str = htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8');
$str = str_replace($htmlents, $xmlents, $str);
$str = str_ireplace($htmlents, $xmlents, $str);
return $str;
} // xml_entities
// This only dumps scalar items, because we usually want to tweak the
// child array output.
function dump_array_as_xml($name, $a)
{
if ($name != NULL)
print("<$name>");
foreach ($a as $k => $v)
{
if (is_array($v))
continue; // we'll do these later.
$txt = xml_entities((string) $v);
print("<$k>$txt</$k>");
} // foreach
if ($name != NULL)
print("</$name>");
} // dump_array_as_xml
// mainline...
session_start();
if (!isset($_SESSION['steamid']))
{
print('<profile><steamid>0</steamid></profile>');
exit(0);
} // if
$steamid = $_SESSION['steamid'];
$profile = load_steam_profile($steamid, $isprivate);
if ($isprivate)
{
print("<profile><steamid>$steamid</steamid><valid>1</valid><private>1</private></profile>");
exit(0);
} // if
else if ($profile == NULL)
{
print("<profile><steamid>$steamid</steamid><valid>0</valid></profile>");
exit(0);
} // if
print("<profile>");
dump_array_as_xml(NULL, $profile);
print("<weblinks>");
foreach ($profile['weblinks'] as $wl)
{
print("<weblink>");
dump_array_as_xml(NULL, $wl);
print("</weblink>");
} // foreach
print("</weblinks>");
print("<gamelist>");
foreach ($profile['gamelist'] as $g)
{
print("<game>");
dump_array_as_xml(NULL, $g);
print("<tags>");
foreach ($g['tags'] as $t)
{
$tag = xml_entities($t);
print("<tag>$tag</tag>");
} // foreach
print("</tags>");
print("</game>");
} // foreach
print("</gamelist>");
print("</profile>");
exit(0);
?>