Skip to content

Latest commit

 

History

History
142 lines (119 loc) · 4.02 KB

steamtags.php

File metadata and controls

142 lines (119 loc) · 4.02 KB
 
1
2
<?php
Jul 1, 2010
Jul 1, 2010
3
4
require_once('database.php');
5
6
7
8
function steam_base_profile_url($user)
{
$profdir = 'profiles';
Jul 5, 2010
Jul 5, 2010
9
if (preg_match('/^[0-9]+$/', $user))
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
{
$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 5, 2010
Jul 5, 2010
38
function load_profile_game_tags(&$profile)
Jul 1, 2010
Jul 1, 2010
39
{
Jul 5, 2010
Jul 5, 2010
40
$gamelist = &$profile['gamelist'];
Jul 1, 2010
Jul 1, 2010
41
$id = $profile['steamid'];
Jul 5, 2010
Jul 5, 2010
42
43
$sql = "select appid, tag from gametags where steamid=$id" .
" and deleted is null order by appid";
Jul 1, 2010
Jul 1, 2010
44
$query = do_dbquery($sql);
Jul 5, 2010
Jul 5, 2010
45
46
47
if ($query === false)
return false;
Jul 1, 2010
Jul 1, 2010
48
49
while ( ($row = db_fetch_array($query)) != false )
{
Jul 5, 2010
Jul 5, 2010
50
if (!isset($gamelist[$row['appid']]))
Jul 1, 2010
Jul 1, 2010
51
continue; // maybe it was a free weekend game they don't own now?
Jul 5, 2010
Jul 5, 2010
52
$gamelist[$row['appid']]['tags'][] = $row['tag'];
Jul 1, 2010
Jul 1, 2010
53
} // while
Jul 5, 2010
Jul 5, 2010
54
55
db_free_result($query);
Jul 1, 2010
Jul 1, 2010
56
return true;
Jul 1, 2010
Jul 1, 2010
57
58
} // load_profile_game_tags
Jul 5, 2010
Jul 5, 2010
59
function load_steam_profile($user, &$isprivate)
60
61
62
63
{
$sxe = url_to_simplexml(steam_profile_url($user));
if ($sxe === false)
{
Jul 1, 2010
Jul 1, 2010
64
//write_error("Couldn't load user profile from Steam Community");
65
66
67
return NULL;
} // if
Jul 5, 2010
Jul 5, 2010
68
69
$isprivate = ($sxe->privacyState != 'public');
if ($isprivate)
70
{
Jul 1, 2010
Jul 1, 2010
71
//write_error("This user's profile is marked private");
72
73
74
75
76
77
78
79
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
80
$profile['valid'] = 1;
Jul 5, 2010
Jul 5, 2010
81
$profile['private'] = 0;
82
83
84
85
86
87
88
89
90
$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
91
$profile['vacbanned'] = (int) $sxe->vacBanned;
92
93
94
95
96
97
98
99
$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
100
101
foreach ($sxe->weblinks as $wl)
{
102
103
104
105
106
107
108
109
110
111
112
$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
113
//write_error("Couldn't load user gamelist from Steam Community");
114
115
116
117
118
119
120
return NULL;
} // if
$gamelist = array();
foreach ($sxe->games->game as $g)
{
Jul 1, 2010
Jul 1, 2010
121
$gamelist[(int) $g->appID] = array(
122
123
124
'appid' => (int) $g->appID,
'title' => (string) $g->name,
'logourl' => (string) $g->logo,
Jul 1, 2010
Jul 1, 2010
125
126
'storeurl' => (string) $g->storeLink,
'tags' => array(),
127
128
129
);
} // foreach
Jul 5, 2010
Jul 5, 2010
130
$profile['gamelist'] = &$gamelist;
131
Jul 1, 2010
Jul 1, 2010
132
133
134
135
136
137
if (!load_profile_game_tags($profile))
{
//write_error("Couldn't load user gametags from our database");
return NULL;
} // if
138
139
140
141
return $profile;
} // load_steam_profile
// end of steamtags.php ...