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
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-24-2008, 10:00 PM   #1 (permalink)
The Contributor
 
mortisimus's Avatar
 
Join Date: Sep 2007
Location: United Kingdom
Posts: 41
Thanks: 4
mortisimus is on a distinguished road
Default World of Warcraft Armory xml Grabber with cURL

Ok, I ran across this a little while ago and since I spent a lot of time looking for this, I thought I would share this with all you guys here that want it.

PHP Code:
class armory {

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

 public 
$query;
 public 
$server;
 public 
$guild;
 public 
$guildie;
 public 
$page;

public function 
__construct $query$server$guild$guildie$page ) {
    
$this->query $query;
    
$this->server $server;
    
$this->guild $guild;
    
$this->guildie $guildie;
    
$this->page $page;
 } 
// end of __construct()

public function pull_xml() {

    
// change the first part of the $url to the armory link that you need
    
if( $this->query === 'roster' ){
        
$url 'http://eu.wowarmory.com/guild-info.xml?r=' urlencode($this->server) . '&n=' urlencode($this->guild) . '&p=' $this->page;
        
      }elseif( 
$this->query === 'character' ){
        
$url 'http://eu.wowarmory.com/character-sheet.xml?r=' urlencode($this->server) . '&n=' $this->guildie;
        
        }  

    
$ch curl_init();
    
curl_setopt ($chCURLOPT_URL$url);
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt ($chCURLOPT_CONNECTTIMEOUT15);
    
curl_setopt ($chCURLOPT_USERAGENT,  self::BROWSER);
    
    
$url_string curl_exec($ch);
    
curl_close($ch);
    return 
simplexml_load_string($url_string);
    
   
 } 
// end of pull_xml()

// end class 
And then to use it:

PHP Code:
Syntax:
$armory = new armory( [character or roster] , realm , [guild name or NULL] , character name , [page number (guilds only) or NULL];

Example:
$armory = new armory(characterhellscreamNULLmortisimusNULL);
$xml $armory->pull_xml(); 
Then you could var_dump($xml) to see all the options you can pull from the armory.

Another example (to get the name):
PHP Code:
$armory = new armory(characterhellscreamNULLmortisimusNULL);
$xml $armory->pull_xml();
echo 
$xml->characterInfo->character['name']; 
Which will get the value of the name in the character tag, contained in the characterInfo tag in the xml file from the armory or in short, the characters name

All simple stuff but it helped me out.

The World of Warcraft Armory - EU
The World of Warcraft Armory - US
__________________
LONG time talkphp member. Short time poster :-)

Last edited by mortisimus : 11-09-2008 at 09:43 AM.
Send a message via Skype™ to mortisimus
mortisimus is offline  
Reply With Quote
The Following 4 Users Say Thank You to mortisimus For This Useful Post:
Mithadriel (11-08-2008), sketchMedia (08-31-2008), Tanax (11-09-2008), Wildhoney (08-25-2008)
Old 08-25-2008, 03:12 PM   #2 (permalink)
The Frequenter
Advanced Programmer Top Contributor Good Samaritan 
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
sketchMedia is on a distinguished road
Default

Thanks, I wrote something similar not long ago for a guild website i was developing. In my case I used armory to populate the guild roster in the DB.

One thing i did notice about your code:
PHP Code:
$url_string curl_exec($ch); 
return 
simplexml_load_string($url_string); 
     
curl_close($ch); 
The curl_close is defined after the return, thus it is never fired and resources never freed.

This is the correct code:
PHP Code:
$url_string curl_exec($ch); 
curl_close($ch); 

return 
simplexml_load_string($url_string); 
Also
PHP Code:
curl_setopt ($chCURLOPT_USERAGENT,  armory::BROWSER); 
may aswell be:
PHP Code:
curl_setopt ($chCURLOPT_USERAGENT,  self::BROWSER); 
Just in case you wish to change the name of your class.
__________________
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Mithadriel (11-08-2008)
Old 08-26-2008, 01:03 PM   #3 (permalink)
The Contributor
 
mortisimus's Avatar
 
Join Date: Sep 2007
Location: United Kingdom
Posts: 41
Thanks: 4
mortisimus is on a distinguished road
Default

Thanks, updated it.
__________________
LONG time talkphp member. Short time poster :-)
Send a message via Skype™ to mortisimus
mortisimus is offline  
Reply With Quote
Old 10-05-2008, 05:24 PM   #4 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 683
Thanks: 85
Tanax is on a distinguished road
Default

Looks cool :D
__________________
Tanax is offline  
Reply With Quote
Old 10-10-2008, 11:57 AM   #5 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 445
Thanks: 49
ReSpawN is on a distinguished road
Default

Pretty good, but I don't play WoW. ;) Non the less, good share.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 11-08-2008, 09:07 PM   #6 (permalink)
The Visitor
 
Join Date: Nov 2008
Posts: 4
Thanks: 2
Mithadriel is on a distinguished road
Default

Great contribution, really simple to follow and takes a whole lot of headache out of querying the armory!

Managed to get information on characters with no problems but hit a snag when trying to query guild info. Noticed a wee typo on the example above:

PHP Code:
// change the first part of the $url to the armory link that you need
    
if( $this->query === 'roster' ){
        
$url 'http://eu.wowarmory.com.com/guild-info.xml?r=' $this->server '&n=' $this->guild '&p=' $this->page

Remove the spurious .com and everything works as expected :)

p.s excuse the thread necromancy ... figured this was worth it though.
Mithadriel is offline  
Reply With Quote
Old 11-08-2008, 09:32 PM   #7 (permalink)
The Visitor
 
Join Date: Nov 2008
Posts: 4
Thanks: 2
Mithadriel is on a distinguished road
Default

Just also noticed, for guilds or server names with spaces the above code breaks. This very slightly modified version should be fine as it converts the whitespace to '+' which is how blizz formats it.

PHP Code:
public function pull_xml() {

    
// change the first part of the $url to the armory link that you need
    
if( $this->query === 'roster' ){
        
$url 'http://eu.wowarmory.com/guild-info.xml?r=' urlencode($this->server) . '&n=' urlencode($this->guild) . '&p=' $this->page;
        
      }elseif( 
$this->query === 'character' ){
        
$url 'http://eu.wowarmory.com/character-sheet.xml?r=' urlencode($this->server) . '&n=' $this->guildie;
        
        } 
Mithadriel is offline  
Reply With Quote
The Following User Says Thank You to Mithadriel For This Useful Post:
mortisimus (11-09-2008)
Old 11-09-2008, 09:43 AM   #8 (permalink)
The Contributor
 
mortisimus's Avatar
 
Join Date: Sep 2007
Location: United Kingdom
Posts: 41
Thanks: 4
mortisimus is on a distinguished road
Default

Cheers
__________________
LONG time talkphp member. Short time poster :-)
Send a message via Skype™ to mortisimus
mortisimus is offline  
Reply With Quote
Old 11-21-2008, 08:44 PM   #9 (permalink)
The Visitor
 
Join Date: Nov 2008
Posts: 2
Thanks: 0
TheMuffinMan is on a distinguished road
Default

Ok quick question for you PHP folks. :)

I have managed to get this "working" for a guild roster.

I get to this point...
PHP Code:
$armory = new armory('roster''Dawnbringer''Fates Defiance''Bberrymuffin'NULL);
$xml $armory->pull_xml();
echo 
$xml->guildInfo->guild->members->character['name']; 
Now I have the XML, and the "character" tag repeats for every member in the guild.

My question is, how do you look through all of the character elements of the members element to get the information on each character?

My PHP skills aren't the best in the world, sorry if this is a dumb question!

Thanks in advance for any help!
TheMuffinMan is offline  
Reply With Quote
Old 11-21-2008, 09:12 PM   #10 (permalink)
The Visitor
 
Join Date: Nov 2008
Posts: 2
Thanks: 0
TheMuffinMan is on a distinguished road
Default

Ok I figured it out (should have googled first haha!)

PHP Code:
foreach ($xml->guildInfo->guild->members->character as $char) {
    echo 
$char['name'] . "<br>";


Anyone know how I can go about sorting this array of arrays for the ['name']?
TheMuffinMan is offline  
Reply With Quote
Reply



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:03 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0