Steam XML Parser

As mentioned in a previous post, I’ve developed a WordPress plug-in to display a user’s Steam Stats as a widget. It’s available for download here. However, this does no good to anyone without a WordPress-based-site and I wanted to make the source freely available. As such, I’ve included it below. Valve provides Steam profiles as an XML feed which can be parsed and formatted according to a developer’s needs. To personalize the script, simply edit the URL following the “$profileURL” variable.

<?php
/* Steam Community Widget
*/	
 
	//Variables. Edit Profile URL to match the link to your personal Steam Community Page.
		$ProfileURL = 'http://steamcommunity.com/profiles/76561197970479548/';
		$xml = simplexml_load_file($ProfileURL . '?xml=1');
 
			//Begin Widget Content
					echo '<p><strong>SteamID:</strong> ';
					echo $xml->steamID . '<br /><strong>Member since:</strong> ';
					echo $xml->memberSince . '<br /><strong>Steam Rating:</strong> ';
					echo $xml->steamRating . '<br /><strong>Playing time:</strong> ';
					echo $xml->hoursPlayed2Wk . " hrs past 2 weeks</p>";
					for($i = 0; $i < 4; $i++){
						if ($xml->mostPlayedGames->mostPlayedGame[$i]->gameLink != "") {
							echo '<p><a href="' . $xml->mostPlayedGames->mostPlayedGame[$i]->gameLink . '"><img src="' . $xml->mostPlayedGames->mostPlayedGame[$i]->gameIcon . '" /></a> ' . $xml->mostPlayedGames->mostPlayedGame[$i]->gameName . ' ' . $xml->mostPlayedGames->mostPlayedGame[$i]->hoursPlayed . ' hrs</p>';
						}
					}
				echo '<p><a href="' . $ProfileURL . 'games">View all games</a></p><p align="center"><em>&copy ' . date(Y) . ' <a href="http://nicholaspier.com">nicholaspier.com</a></em></p>';
			//End Widget Content
?>

8 replies on “Steam XML Parser”

  1. My pleasure. I couldn’t find one that did what I wanted so I just made my own 😀 ! Hope you enjoy it, do what you want with the source code

  2. Hi I was just wondering if you can call this plugin directly, as I am not really using sidebars on my site.

    How do i go about calling it on it’s own?

    cheers!

  3. The plugin is designed as a widget. I could redesign it where you’d enter text like <-- steamstats --> in a page or post like other plugins. However I don’t really have a need to redesign it. If you’d like it modified and are willing to paypal me like $15-20, I’d make the changes and send you a custom copy of the plugin.

  4. Cheers! I was just about to embark on a similar quest … thanks for releasing the code. I first saw a forum post of yours that said it was a WordPress plugin, and I was dreading going through the source and de-tangling it from WP.

    Right now I’m rewriting my WP blog from scratch in CodeIgniter so this is a huge help.

    Thanks!

  5. Hi,

    This is really cool but doesn’t do quite what I’m after. I want a plugin for my site that would show the status for our steam group members that are currently online (parses out the offline members) and shows what game they are in, etc. I keep trying to do it and failing miserably.

    Do you have something like this?

    Thanks

Comments are closed.