TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-15-2007, 02:42 AM   #1 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default XBL Gamercard Fetching Class

Found this at simes.org. It's a class for fetching Xbox Live Gamertags. Pretty neat. I haven't looked through the entire code yet to see if there's stuff that needs to be fixed, etc. I'm new to OOP in PHP5, but this looks like it was written for PHP4. Someone correct me if I'm wrong. Enjoy.

PHP Code:
<?php
class GamerCard
{
    var 
$memberType;

    var 
$tag;
    var 
$rep;
    var 
$score;
    var 
$zone;

    var 
$recentlyPlayed;

    var 
$gamerPictureUrl;


}

function 
error_handler($errno$errstr)
{
}

function 
getGamerCard($gamerTag)
{
    
$url "http://gamercard.xbox.com/" urlencode($gamerTag) . ".card";
    
// Grab the gamercard - the card HTML is not valid xml (the base tag is not closed) 
    // but the "body" tag and its contents are a valid xml doc so we throw away the contents of the "head" tag. 
    // We don't need them anyway.
    
//    $request = new HTTPRequest($url);
//    $cardHTML = $request->DownloadToString();
    
set_error_handler("error_handler");
    
$cardHTML file_get_contents($url);
    
restore_error_handler();
    if (
$cardHTML == false)
    {
        return 
"";
    }
    
$tmp preg_split("/<\/head>/"$cardHTML);
    
$tmp preg_split("/<\/html>/"$tmp[1]);
    
$cardHTML preg_replace(array("@<script[^>]*?>.*?</script>@si""@<noscript[^>]*?>.*?</noscript>@si"), array(""""), $tmp[0]); // Strip SCRIPT tags - not valid XML


    
$xml domxml_open_mem("<?xml version='1.0' standalone='yes'?>" $cardHTML);
    if (!
$xml)
    {
        print 
"Error parsing XML";
        exit;
    }

    
$root $xml->document_element();
    
$xpath $xml->xpath_new_context();

    
$card = new GamerCard();
    
$card->tag $gamerTag;

// Membership type (Gold/Silver)

    
$elems $xml->get_elements_by_tagname("h3");
    foreach(
$elems as $elem)
    {
        
$class $elem->get_attribute("class");

        if (
$class == "XbcGamertagGold")
            
$card->memberType "Gold";
        else if (
$class == "XbcGamertagSilver")
            
$card->memberType "Silver";
    }

// Gamer picture
    
$obj $xpath->xpath_eval('//img[@class="XbcgcGamertile"]');
    
$nodeset $obj->nodeset;

    
$card->gamerPictureUrl $nodeset[0]->get_attribute("src");

// Gamerscore

    
$obj $xpath->xpath_eval('//span[preceding-sibling::span/img[@alt="Gamerscore"]]');
    
$nodeset $obj->nodeset;
    
$card->score $nodeset[0]->get_content();

// Rep

    
$obj $xpath->xpath_eval('//span[preceding-sibling::span="Rep"]/img');
    
$nodeset $obj->nodeset;

    
$url $nodeset[0]->get_attribute("src");
    
$tmp preg_split("/[._]/"$url);
    
$card->rep $tmp[3];

// Zone

    
$obj $xpath->xpath_eval('//span[preceding-sibling::span="Zone"]');
    
$nodeset $obj->nodeset;
    
$card->zone $nodeset[0]->get_content();

// Recently Played

    
$obj $xpath->xpath_eval('//div[@class="XbcgcGames"]//img');
    
$nodeset $obj->nodeset;
    
    foreach(
$nodeset as $node)
    {
        
$card->recentlyPlayed[] = $node->get_attribute("title");
    }

    return 
$card;
}

?>
obolus is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:09 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design