Skip to content

Latest commit

 

History

History
132 lines (112 loc) · 3.79 KB

steamtags.php

File metadata and controls

132 lines (112 loc) · 3.79 KB
 
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
<?php
function steam_base_profile_url($user)
{
$profdir = 'profiles';
if (preg_match('/^[0-9]+$/i', $user))
{
$basedir = $profdir;
$id = $user;
} // if
else
{
$basedir = 'id';
$id = $user;
} // else
return "http://steamcommunity.com/$basedir/$id";
} // steam_base_profile_url
function steam_profile_url($user)
{
return steam_base_profile_url($user) . "?xml=1";
} // steam_profile_url
function steam_gamelist_url($user)
{
return steam_base_profile_url($user) . "/games?tab=all&xml=1";
} // steam_gamelist_url
function url_to_simplexml($url)
{
return simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
} // url_to_simplexml
Jul 1, 2010
Jul 1, 2010
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function load_profile_game_tags($profile)
{
$gamelist = $profile['gamelist'];
$id = $profile['steamid'];
$sql = "select appid, tag from gametags where steamid=$id order by appid";
$query = do_dbquery($sql);
while ( ($row = db_fetch_array($query)) != false )
{
$game = $gamelist[$row['appid']];
if (!isset($game))
continue; // maybe it was a free weekend game they don't own now?
$game['tags'][] = $row['tag'];
} // while
} // load_profile_game_tags
51
52
53
54
55
function load_steam_profile($user)
{
$sxe = url_to_simplexml(steam_profile_url($user));
if ($sxe === false)
{
Jul 1, 2010
Jul 1, 2010
56
//write_error("Couldn't load user profile from Steam Community");
57
58
59
60
61
return NULL;
} // if
if ($sxe->privacyState != 'public')
{
Jul 1, 2010
Jul 1, 2010
62
//write_error("This user's profile is marked private");
63
64
65
66
67
68
69
70
return NULL;
} // if
$scid = (string) $sxe->customURL; // Steam Community ID.
$steamid64 = (string) $sxe->steamID64;
$profileurl = steam_base_profile_url(empty($scid) ? $steamid64 : $scid);
$profile = array();
Jul 1, 2010
Jul 1, 2010
71
$profile['valid'] = 1;
72
73
74
75
76
77
78
79
80
$profile['nickname'] = (string) $sxe->steamID;
$profile['steamid'] = (string) $steamid64;
$profile['name'] = $scid;
$profile['profileurl'] = $profileurl;
$profile['onlinestate'] = (string) $sxe->onlineState;
$profile['statemsg'] = (string) $sxe->stateMessage;
$profile['avatarurl_small'] = (string) $sxe->avatarIcon;
$profile['avatarurl_medium'] = (string) $sxe->avatarMedium;
$profile['avatarurl_large'] = (string) $sxe->avatarFull;
Jul 1, 2010
Jul 1, 2010
81
$profile['vacbanned'] = (int) $sxe->vacBanned;
82
83
84
85
86
87
88
89
$profile['membersince'] = (string) $sxe->memberSince;
$profile['rating'] = (int) $sxe->steamRating;
$profile['hoursplayed_2weeks'] = (int) $sxe->hoursPlayed2Wk;
$profile['headline'] = (string) $sxe->headline;
$profile['location'] = (string) $sxe->location;
$profile['realname'] = (string) $sxe->realname;
$profile['summary'] = (string) $sxe->summary;
$profile['weblinks'] = array();
Jul 1, 2010
Jul 1, 2010
90
91
foreach ($sxe->weblinks as $wl)
{
92
93
94
95
96
97
98
99
100
101
102
$profile['weblinks'][] = array(
'title' => (string) $wl->weblink->title,
'url' => (string) $wl->weblink->link
);
} // foreach
// We've grabbed the profile data, now get the game list for the user...
$sxe = url_to_simplexml(steam_gamelist_url($user));
if ($sxe === false)
{
Jul 1, 2010
Jul 1, 2010
103
//write_error("Couldn't load user gamelist from Steam Community");
104
105
106
107
108
109
110
return NULL;
} // if
$gamelist = array();
foreach ($sxe->games->game as $g)
{
Jul 1, 2010
Jul 1, 2010
111
$gamelist[(int) $g->appID] = array(
112
113
114
'appid' => (int) $g->appID,
'title' => (string) $g->name,
'logourl' => (string) $g->logo,
Jul 1, 2010
Jul 1, 2010
115
116
'storeurl' => (string) $g->storeLink,
'tags' => array(),
117
118
119
120
121
);
} // foreach
$profile['gamelist'] = $gamelist;
Jul 1, 2010
Jul 1, 2010
122
123
124
125
126
127
if (!load_profile_game_tags($profile))
{
//write_error("Couldn't load user gametags from our database");
return NULL;
} // if
128
129
130
131
return $profile;
} // load_steam_profile
// end of steamtags.php ...