Xbox 360 Gamercard WordPress Plugin
I’ve put together a WordPress plugin that will display a customizable XHTML and CSS Xbox 360 gamer card. There are plenty of sites out there that will make good looking gamer cards using image files, but this method will give you complete control over the appearance. It also acts like a gamer card, with a link to your Xbox Live profile and “compare to” links to your five most recently played games, something the image file cards can’t do.
For those of you who want a raw PHP script with the same functionality, I’ve included one farther down in the post.
How the plugin works
The plugin uses cURL, a command line tool for transferring files with URL syntax, to read the contents of your Xbox Live gamer card from http://gamercard.xbox.com/YOURTAG.card into a string, and then uses the PHP function preg_match to perform regular expression matching on that string. The various elements of your gamer card are extracted and then assigned to variables for later output.
The plugin attempts to create a unique text file for each gamertag (gamercard_cache_YOURTAG.txt) for use as a cache in your blog’s root folder automatically. This is done to reduce the number of times the target HTML page must be accessed and parsed and therefore reduce server load and page load time. Some server configurations may not permit the plugin to create this file and you’ll see resultant errors; in this case, you may have to upload a file with that name and perhaps set permissions on the file. You can edit the plugin to adjust how old the cache can grow before the script refreshes the information from gamercard.xbox.com.
Usage
The plugin accepts two arguments: the first is your gamertag; the second, which is optional, toggles whether the recently played games are displayed.
Insert the code:
<?php if (function_exists('gamercard')) gamercard('YOURTAG'); ?>
into a template file wherever you want the gamer card to appear, replacing YOURTAG with your actual Xbox Live gamertag, ex.:
<?php if (function_exists('gamercard')) gamercard('ardamis'); ?>
You can include multiple, different gamer cards on each page.
Customization
To show the recently played games icons, add the “full” argument, ex.:
<?php if (function_exists('gamercard')) gamercard('ardamis', full); ?>
Do whatever you want with the CSS to integrate the gamer card into your site.
Installation
The download includes:
- xbox-gamercard.php (put this in your /plugins/ directory)
- gamercard.css (copy and paste the contents into your theme’s style.css)
- /gc_images/ (optional – put this folder of reputation images in your WordPress theme’s /images/ folder if you want to use them)
The plugin by default now uses the gold stars with transparent background from the ‘mini-card’ in the top navigation of http://www.xbox.com/. The rep image is a transparent .png, however. If you’re worried that people using IE6 will see an ugly rep because of IE6’s lack of support for transparent .png, you may want to edit the plugin to use a different rep image. It’s easy.
a screen shot of the ‘mini-card’ from Xbox.com
The optional ‘gc_images’ folder contains 20 images, one for each reputation rank, to replace the default gamercard gauge. They are based on the gauge used in the smaller, menu bar gamercard on the old http://live.xbox.com/ site, but with transparent backgrounds instead of gray for greater flexibility. You don’t need to use these, of course. I’ve written 3 variables into the plugin if you want to use the official Xbox rep images. Just edit the plugin to replace $navgamerrep in the output with one of the other variables. (Seriously, it’s easy.)
Download (beta 1.3)
Get the files here:
Download the Xbox 360 Gamer Card WordPress Plugin
I’m getting an error message
If your server does not have cURL enabled, you’ll get an error message that reads something like Fatal error: Call to undefined function curl_init() in PATH\wp-content\plugins\xbox-gamercard.php on line 54. The best solution is to ask your host to enable cURL. If that option is unavailable, I’ve provided an alternative that uses the function file_get_contents(), but a number of hosts have disabled the URL retrieving capabilities in file_get_contents() for security reasons. Download the FGC Gamer Card WordPress Plugin only if you’re getting an error message with the regular download.
Can I get this as a WordPress Widget?
Honestly, the plugin is much more flexible than a widget. Widgets are limited to your sidebar, while the plugin can be used in any template. Installing the plugin isn’t very complicated, either. So, in short, there are no plans to adapt this as a widget right now.
How can I use this on a non-WordPress site?
Download the Xbox 360 Gamer Card Stand-alone Script
Just PHP include the xbox-gamercard-standalone.php script wherever you want the card to be displayed, adjusting the path to the reputation images. Add the contents of gamercard.css to your main CSS file, and modify to suit your site.
Be aware that message boards and forums (eg: vBulletin forums) won’t allow you to use PHP as part of your post or signature. In short, don’t expect this method to work anywhere but on your own site.
You can either edit the script to use your gamertag, or call the script with the line:
<?php include 'PATH-TO-SCRIPT/xbox-gamercard-standalone.php?tag=YOURTAG'; ?>
To show the recent games, use:
<?php include 'PATH-TO-SCRIPT/xbox-gamercard-standalone.php?tag=YOURTAG&full=full'; ?>
Obviously, you’ll replace ‘YOURTAG’ with your gamertag. If you have any spaces in your gamertag, replace each space with %20.
Further customization (optional)
A number of neat image and Flash sigs contain way more information than just what’s provided at http://gamercard.xbox.com/YOURTAG.card, but as far as I can tell, it’s all gathered in the same way. If there’s something you’d like added to the script, find a page that contains the information and post a comment about it, or give programming a shot yourself…
View the source code of the target page and locate the data you wish to extract. What we want to do is identify everything but the desired data. Isolate the desired data within the source code of the target page by copying everything from the first character before the data back to and including something unique, such as a div’s id. Paste that into a preg_match line as the first half of the pattern that the script will look for. Follow that with the characters (.+?), a bit of code that represents the data we want to extract. Do not copy the actual desired data from the target page into the modified script. Last, select and copy a few characters immediately after the data, such as the closing div, and paste that after the (.+?). Everything in between the two copied strings—the stuff now represented by the (.+?) characters—will be assigned to a variable.
Credits
Thanks to Constantin Hofstetter for getting me started on this project and to Jeremy at 360gamerCards.com for eliminating the need for the Snoopy script, reducing the process to a single file and otherwise greatly simplifying the whole thing. And thanks to everyone who emailed or posted with error messages and other problems; it’s a better, more robust plugin because of your efforts.
My gamertag is ardamis, should you want to add me to your friends list and give me some positive feedback.
















I had to create gamercard_cache_tag.txt and place it in the blog root myself, otherwise it threw up a load of errors. Did you mean to leave it upto the user to create the file? Might want to stick that in the instructions if you did
Thanks for pointing this out, Dan.
There will be some server configurations that don’t allow the plugin to create the cache file. In these situations, yes, you’ll have to create and upload an appropriately named text file. I’ve edited the post to reflect this.
For those who want to display their gamercard in the sidebar there is a way to do it – check out my tutorial at http://mordani.com/blogs/rohit/...
Edit: Rohit is referring to including a third-party image file gamer card via a WordPress widget
Excellent plugin! I’m glad someone has made a gamercard plugin that’s not for sidebar widgets. Sidebar widgets/modules suck.
I am having a problem with the plugin. I uploaded everything an after putting the code in e.g. sidebar.php i get this:
Fatal error: Call to undefined function curl_init() in /mnt/am2/06/736/00000000/htdocs/blog/wp-content/plugins/xbox-gamercard.php on line 54
A “Fatal error: Call to undefined function curl_init()” message means that your server doesn’t have cURL enabled.
Create a file called phpinfo.php that contains the following code:
Upload it to your site and load it in a browser. You should see a section called “curl” and within that an indication that CURL Support is Enabled. If you don’t see this, then you can ask your hosting company to enable it.
Is there any chance of having this work locally? Live is ok, but locally i get an error:
Fatal error: Call to undefined function curl_init() in C:\xampplite\htdocs\wordpresstest\wp-content\plugins\xbox-gamercard.php on line 54
If you’re using XAMPP Lite, you could step up to the full version, which I believe supports cURL out-of-the-box. But I’ve updated the post to add an alternative plugin that uses the function file_get_contents() instead of cURL.
thanks, working fine for me
Looks good! I’m glad you’ve gotten some use out of my changes! I’m working on a Leaderboard script right now, so shoot me an email if you’re interested. I’ve been working alot on an overhaul for 360gamercards.com to turn it into a community site using Dragonfly CMS, so I will be releasing a beta module for that which should be easily portable over to PHP/POST/Whatever-Nuke. I also have a basic script that can be used on any site. Generally for best functionality a database should be used for storing the gamertags you want on the leaderboard, etc, but I am going to integrate some config variables in the script to utilize a list in the script instead.
The plugin is great! Thank you
But there’s one minor problem: It doesn’t update the gamerscore and “played games” every hour (I installed the plugin with your default options). Is this a known problem/bug?
Whoops. Nice catch, Martin. I had put an extra zero in the timeout. It was refreshing the cache every 10 hours, instead. It’s fixed now.
Is this still working? I have issues with it but it may be with my server more than anything. cURL is enabled, but when I run it the gamercard cache file only gets the hard coded fields such as time, $tag populated. All the lines that are supposed to be retrieved from xbox.com are blank???
Hey I would like to get your thoughts on this ardamis, over at http://www.mygamercard.net they have a new gamercard with a small icon in the upper corner that shows wheater or not the user is on Xbox LIVE or offline and if they are offline for how long. What do you think the possibility is to add something like this to your mod.
I know a very little about php, I took what you have done here and made two joomla mods for my site one for a login sig if the user is logged in it will show them there card and the other is a who’s online card that shows a small card for each member on our website. But it would be great if when you went to the members section of the site or if they are on our website it would also show if they are on LIVE or not.
What do you think ardamis?
is there any info on the previous post, i was trying to get xboxlive current status included and outputed by the script/plugin but to no joy, and possibly motto.. thanks for any help… great plugin btw thanks
I’ll look into adding an online/offline indicator. Can you point me to a publicly accessible page that has your online/offline status? I know the info is available if you are signed into the Xbox Live site, but I don’t know where to find it without signing in.
well i an online/offline status can be found here http://live.xbox.com/en-GB/profile/profile.aspx?pp=0&GamerTag=ardamis
but for some reason if i replace your tag with mine i dont get that option(but then again why would you want to look at your own status. i did try to includ it myself but iam a n00b with this.
i tried this
preg_match(’#(.+?)#’,$in, $status1);
thanks
hoticeuk
oops didnt work sorry
preg_match('#<h4 class="XbcLiveText">(.+?)</h4></td>#',$in, $status1);Hey ardamis,
How does this plugin get the data? Is it looking at images? I have been looking at the code trying to find out where it’s pulling the data from it’s over my head, I’m a graphic designer, I’m shit at coding lol. If this code is looking to images for data could we use the images from bungie’s site to query whether or not a user is online or off line?
h**p://www.bungie.net/images/FriendIconOnline.gif
h**p://www.bungie.net/images/FriendIconOffline.gif
Great script! I’m using the standalone version and just wondering if it’s possible to modify it to display the smaller (32×32) gamer tile? Also, is there any reason why I wouldn’t get the recently played games icons? I have forced the ‘full’ setting. Thanks.
Presto-X: the plugin gets the code of the entire page at http://gamercard.xbox.com/ardamis.card (your gamercard), then pulls out various useful lines.
It can get the code from any publicly accessible page. The problem is that there doesn’t seem to be any such publicly accessible page that contains a gamer’s Xbox Live online/offline status.
Simply having the path to an image doesn’t help us determine anything – we would need a page that includes that path only under certain circumstances.
island76: There should be a way to use the 32×32 image. I’ll look into it. I’ll also make sure the full setting works for me.
i found Gamercad-Lib on sourceforge. this works the same way as yours with preg_match and cURL this script displays current status, which gets its info from
("http://live.xbox.com/es-ES/profile/profile.aspx?pp=0&GamerTag=". $tag);i hope this helps, i tried to integrate part of their code into yours but no joy.Hey hoticeuk thanks for the info, although the script is suspect lol it asks for your XBOX Live email and password hmmm I’m going to look at the code to make sure it’s not emailing that info home. That would suck! lol I have seen that done with World of Warcraft php website addons NOT cool at all. The thing I like about ardamis system it’s very clean coding and uses only one php file not 3. Great work ardamis!
hehe i couldnt agree more ardamis is the best script for a gamercard i have seen, good for integrating into a website, i never tried to run the script from sourceforge i quickly read through the code, looking for the target page for info. thanks for the heads up.
Hey hoticeuk, the code from Gamercad-Lib looks legit but it would not work on my server setup
I’m going to look at their code and see how they got the other features working.
yeh i have tried tweaking their code but was also unable to get it to work on my setup. their coding is more complex and abit out of my league, good luck let me know if anyone figures this one out admin@hotfrost.org
ardamis, great plugin!
hoticeuk was right. If you go to http://live.xbox.com/en-US/profile/profile.aspx?pp=0&GamerTag=GAMERTAG and replace GAMERTAG with a real tag the page shows if the person is online. If the person is offline it doesn’t show anything however. I might have to mess around and see if I can scrape the status out for use with your script!
[...] Xbox 360 Gamercard by Oliver Baty for the ‘Trophy Fish’ in the footer [...]
Can someone please help!
I get this problem:
Warning: fopen(./gamercard_cache_MASTERBEEF77.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 70
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 71
Warning: file(./gamercard_cache_MASTERBEEF77.txt) [function.file]: failed to open stream: No such file or directory in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 73
Warning: array_map() [function.array-map]: Argument #2 should be an array in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 74
Warning: fopen(./gamercard_cache_MASTERBEEF77.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 99
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 100
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 101
It looks like your server doesn’t allow the plugin to read from and write to the cache text file. When I have some time, I’ll make a version that doesn’t use a cache.
Ah, fantastic plugin! I didn’t want a gaudy image, and this was just what I needed.
However, for your plugin version for servers that have CURL disabled, the image paths for the xbox rep aren’t working anymore. XBOX has changed them, and it results in a 404.
I ended up changing it in the php file itself, but figured I’d let you know about it to fix it so it will work fine for others.
I think I’ve fixed both versions of the plugin. Thanks.
Ahh this is just what I was looking for, plus it comes in wordpress flavour as an added bonus. I already have my gamertag on my site, but I think i would prefer using this code. great plugin ardamis.
Hi and thx for this plugin:) This is what i need.
But how can i change the size or the number of the playedgames images?
Hi Ardamis,
I was wondering if there is a way to get the current game or most current game played.
Very good job man
.
Great plugin ardamis.
cheesus: The played games images and links are taken from the gamercard as a single line of code, so there’s no easy way to configure the plugin to selectively display X number of images. However, you could probably edit the plugin to put a div element around the images, then use CSS to give that div a fixed width and height and give the overflow declaration a value of hidden. By adjusting the spacing before and between the images, you could probably push some of them outside the div, and in doing so, hide them from view.
William: The plugin could be edited to display any information that is publicly available – in other words, information that you can see without logging into your Xbox Live account at http://www.xbox.com. Lots of information, like online/offline status, is only visible after you’ve logged in. For security reasons, I’m not going to make the plugin log anyone in.
Great plugin, thank you!
But I noticed it doesn’t get displayed correctly in Opera.
Maybe you could take a look into this.
Thanks again, great work!
Hmmm. It looks fine to me in Opera. I’d be happy to tweak the CSS if you can get me a screenshot.
[...] the image or flash in your web site and it’ll display in real time. There’s also a WordPress plugin that uses a slightly hacky method of using regular expressions on the official Xbox [...]
I got it working fine in Firefox, also seemed to appear fine in Opera!
Hi there I just wanted to say thanks for this plugin, and that it works fine for me.
Cheers!
I’m having the same problem as Jamie above – I’ve tried creating a blank text file in the blog root called gamercard_cache_tag.txt but that doesn’t help either
The gamer card loads ok right at the bottom but how do I fix those errors? Any suggestions? Cheers.
[...] got a nice new widget in my sidebar that displays my Gamertag details, it’s simply called the Xbox 360 Gamercard Wordpress plugin. It doesn’t come as a widget, so I’m using another plugin to use it as a widget, [...]
yey! this is awesome! thanks!
[...] found this nice Wordpress plugin by Oliver Baty which allows you to include your Xbox Live game card somewhere [...]
Great plugin! I changed the plugin a bit so I didn’t have to include php code into my blog entries/pages if I wanted to show my game card. My modification works as a filter. I also had problems with curl so I used fopen before I saw you had a version with file_get_contents(). If you want to have a look at my modifications you’ll find them here: http://oyvindhauge.com/blog/2008/07/31/xbox-360-gamercard-wordpress-plugin/. Cheers
Hey, first of all, THANK YOU for a superb script/plugin, seriously, thank you.
I am sadly however having a problem. A design for my personal blog the Gamercard worked fine on my localhost install, but when moved over to my online server, for some reason images aren’t showing up anymore.
Here are some screenshots so you can see.
http://sulcalibur.com/gallery/Gamercard%20-%20Working.png
http://sulcalibur.com/gallery/Gamercard%20Not%20Working.png
It seems to work, just no images showing up.
Any help would be great. Also I tryed both versions of the script too
I’m now getting these errors…
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/.boccacclo/sulcalibur/http/www.sulcalibur.com/wp-content/plugins/xbox-gamercard-fgc.php on line 79
Warning: file_get_contents(http://gamercard.xbox.com/Sulcalibur.card) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/.boccacclo/sulcalibur/http/www.sulcalibur.com/wp-content/plugins/xbox-gamercard-fgc.php on line 79
I’m hosted with Dreamhost if that makes any difference???
I tried both versions. The main plugin I get no images and the CSS is a little messed up, and with the other one (the fgc one) I get the errors mentioned before.
I from Russia.
I apologize for my bad English language: (
Has casually seen site http://www.360gamercards.com is an excellent site, I want to make at myself in Russia too such site. I have downloaded script provided by Ardamis and it works for me well, but I can not make page of a site as at (www.360gamercards.com) that it was possible to choose different GamerCаrd
You could not help or give me a code which at is on the main pages http://www.360gamercards.com that I too could choose different GamerCаrd. I on a site shall use WordPress. If you will help me, to you I shall be very grateful.
Thank.
I’m sorry, but I can’t help you with your site. The site at
http://www.360gamercards.com isn’t mine, and I’m not sure how it creates the
image files.
My plugin uses HTML and CSS because I did not want to use images.
Good luck.
Stan – Send me an email and I will help you get set up. My email is:
jeremy [dot] d [dot] coleman [at] gmail [dot] com
Oliver – If you could either email this message to Stan, or send me his email, I would greatly appreciate it.
Hey, thanks for this, always wanted something liek this and didn’t know that there was a plugin like that
Anyway, does it look good on my site? At the top?
First off, thanks for this script ardamis!
Stan – easiest way will be to create different .css docs and store them somewhere. Then in the homepage, tell the .css link to grab the css file the user has chosen.
For those that are interested, this widget works perfectly in the sidebar of the default theme. I added the recommended PHP to the top of the sidebar.php file. You will then notice that the Gamer Tag is just a tiny bit too big and overhangs the right edge of the page just a hair. I tweaked the style.css as follows:
The above was shifted just a little to the left…
It fits very nicely. Thank you for a great piece of code!!
Can you tell me if this script could be used in a phpBB forum? I’m currently using the gamertags form mygamertag.net on my xbox website, but I want to be able to create my own images instead of the default ones that mygamercard.net use.
With some customization, it should work on any website where PHP can be processed. It won’t work in a phpBB forum signature, for example, because PHP isn’t allowed there, but it would work embedded in the template files.
I want to delete every link in this code, (ex. clicking on the gamertag or recently played:, directs you to xbox.com).
Now ive got to the point that i can’t seem to find the link of that ‘recently played’ thing. (i just want to delete the link, not the images or whatsoever)
Sorry for my bad english tho, hope you’ll understand
The plugin grabs a block of code that includes both the links and the images of the recently played games. You could probably edit the plugin to strip out the links, but I’m no longer actively developing it, so you’re kinda on your own if you want different functionality.
great plugin mate
Hey, found a slight bug which can be fixed… The preg_match() lines do not include parenthesis and my gamertag link hash has parenthesis, so it did not show the “full” version appropiately. And where I had it made my sidebar look awkward. Basically it added a when none of the data was being retrieved properly.
So, in order to fix the issue I changed the current:
preg_match(’#.+?)#’,$in, $gamesa);
To:
preg_match(’#(\(\).+?)#’,$in, $gamesa);
Which appears to fix the issue… Sorry if it’s not the proper regular expression, but it works!
they should make these for wow gamers
Hey! Love the plugin. But… “Append the contents of gamercard.css to your theme’s style.css” How do I do that? Thanks in advance!
Should mention that my theme’s style.css is empty…
Hmm, the Wordpress theme’s style.css file shouldn’t be empty. Something’s wrong there. There must be a CSS file for that theme somewhere. I’d suggest just pasting the contents of gamercard.css into the bottom of whatever CSS file you can find.
Ey! It works now… Have a special made template. There were like 10 CSS. Thanks!
Searched for hours for a java/php plug-in to do this…found yours. Thank you truly for your wonderful work…exactly what I was looking for! Works great.
Wow, great plug-in, Artemis! Just what my readers (some of them, anyway) have been asking for! I’d like to set this up on my demo site but don’t know whether it’s been updated to play nice with Wordpress 2.7. (Many of my other plug-ins don’t, which is why I’m asking.)
uh…Ardamis; not Artemis (sorry ’bout that!)
I’m glad you like the plugin.
It seems to work fine with WordPress 2.7, and it’s not really very
heavily dependent on WordPress to begin with, so I don’t expect that
upgrades would break the plugin.
Fatal error: Call to undefined function: get_bloginfo() in /home/www/mygamergrid.com/includes/xbox-gamercard.php on line 133
I am getting the above error, i am also struggling to get this plugin working, not sure why
, please help, thanks
Jamie
Okay I was wondering if some can help me I trying to get this to function as I downloaded the non worpress file I can get the script to run an display my game tag name my gamerscore an name but I can see no background image. also how can I mave that java code thats on http://www.360gamercards.com thanks
Awesome plugin, I’ve been looking around for something like this for ages. I look forward to tinkering with the design of my gamercard
excellent code, very easy to customise and works nicely, no issues at all.