Skip to content

Commit

Permalink
Reworked xml output code.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 1, 2010
1 parent 2915681 commit 6e1f082
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
72 changes: 44 additions & 28 deletions steamprofile.php
Expand Up @@ -3,6 +3,26 @@

require_once('steamtags.php');

// 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 = htmlentities((string) $v);
print("<$k>$txt</$k>");
} // foreach

if ($name != NULL)
print("</$name>");
} // dump_array_as_xml


// mainline...
if (isset($_REQUEST['user']))
$user = $_REQUEST['user'];
Expand All @@ -11,43 +31,39 @@
$profile = load_steam_profile($user);

if ($profile == NULL)
print("<profile><valid>0</valid></profile>\n");
else
{
print("<profile>");
print("<valid>1</valid>");
foreach ($profile as $k => $v)
{
if (is_array($v))
continue; // we'll do these later.
$txt = htmlentities($v);
print("<$k>$txt</$k>");
} // foreach
print('<profile><valid>0</valid></profile>');
exit(0);
} // if

print("<profile>");
dump_array_as_xml(NULL, $profile);
print("<weblinks>");
foreach ($profile['weblinks'] as $wl)
{
$title = htmlentities($wl['title']);
$url = htmlentities($wl['url']);
print("<weblink><title>$title</title><url>$url</url></weblink>");
} // foreach
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)
{
$appid = htmlentities($g['appid']);
$title = htmlentities($g['title']);
$logourl = htmlentities($g['logourl']);
$storeurl = htmlentities($g['storeurl']);
print(
"<game><appid>$appid</appid><title>$title</title>" .
"<logourl>$logourl</logourl><storeurl>$storeurl</storeurl></game>"
foreach ($profile['gamelist'] as $g)
{
print("<game>");
dump_array_as_xml(NULL, $g);
print("<tags>");
foreach ($g['tags'] as $t)
{
$tag = htmlentities($t);
print("<tag>$tag</tag>");
} // foreach
print("</tags>");
print("</game>");
);
} // foreach
print("</gamelist>");
print("</profile>");
} // else
print("</profile>");

exit(0);
?>
1 change: 1 addition & 0 deletions steamtags.php
Expand Up @@ -53,6 +53,7 @@ function load_steam_profile($user)
$profileurl = steam_base_profile_url(empty($scid) ? $steamid64 : $scid);

$profile = array();
$profile['valid'] = 1;
$profile['nickname'] = (string) $sxe->steamID;
$profile['steamid'] = (string) $steamid64;
$profile['name'] = $scid;
Expand Down

0 comments on commit 6e1f082

Please sign in to comment.