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
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-24-2008, 09:00 PM   #1 (permalink)
The Contributor
 
mortisimus's Avatar
 
Join Date: Sep 2007
Location: London, UK
Posts: 47
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

Last edited by mortisimus : 11-09-2008 at 09:43 AM.
mortisimus is offline  
Reply With Quote
The Following 7 Users Say Thank You to mortisimus For This Useful Post:
argantes (04-24-2009), codefreek (07-29-2009), Mithadriel (11-08-2008), sketchMedia (08-31-2008), Tanax (11-09-2008), Wildhoney (08-25-2008), Yinx (02-09-2009)
Old 08-25-2008, 02:12 PM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
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.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
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, 12:03 PM   #3 (permalink)
The Contributor
 
mortisimus's Avatar
 
Join Date: Sep 2007
Location: London, UK
Posts: 47
Thanks: 4
mortisimus is on a distinguished road
Default

Thanks, updated it.
mortisimus is offline  
Reply With Quote
Old 10-05-2008, 04:24 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Looks cool :D
__________________
Tanax is offline  
Reply With Quote
Old 10-10-2008, 10:57 AM   #5 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
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 Wanderer
 
Join Date: Nov 2008
Posts: 5
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 Wanderer
 
Join Date: Nov 2008
Posts: 5
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: London, UK
Posts: 47
Thanks: 4
mortisimus is on a distinguished road
Default

Cheers
mortisimus is offline  
Reply With Quote
Old 11-21-2008, 08:44 PM   #9 (permalink)
The Visitor
 
Join Date: Nov 2008
Posts: 4
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: 4
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
Old 01-06-2009, 11:06 PM   #11 (permalink)
The Visitor
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Kalle200000 is on a distinguished road
Default

It doesnt work for me.

Quote:
Fatal error: Call to undefined function curl_init() in C:\wamp\www\wow\index.php on line 32
Kalle200000 is offline  
Reply With Quote
Old 01-06-2009, 11:50 PM   #12 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Welcome to the community, Kalle! In order for it to work, you will need to have the cURL module enabled on your server.

To do so, open the following file: C:\wamp\Apache2\bin\php.ini and uncomment the line extension=php_curl.dll (Remove the semi-colon from the start of the line). Don't forget to restart WAMP after doing so.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-07-2009, 07:16 PM   #13 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

An alternative to using curl would be:
PHP Code:
/* $ch = curl_init();
 curl_setopt ($ch, CURLOPT_URL, $url);
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
 curl_setopt ($ch, CURLOPT_USERAGENT,  self::BROWSER);

 $url_string = curl_exec($ch);
 curl_close($ch);*/
$opts = array(
    
'http'=>array(
        
'method'=>"GET",
        
'header'=>"User-Agent: ".self::BROWSER." \r\n"
    
)
);
$url_string file_get_contents($url,false,stream_context_create($opts));
return 
simplexml_load_string($url_string); 
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Yinx (02-12-2009)
Old 03-09-2009, 01:53 PM   #14 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
An alternative to using curl would be:
PHP Code:
/* $ch = curl_init();
 curl_setopt ($ch, CURLOPT_URL, $url);
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
 curl_setopt ($ch, CURLOPT_USERAGENT,  self::BROWSER);

 $url_string = curl_exec($ch);
 curl_close($ch);*/
$opts = array(
    
'http'=>array(
        
'method'=>"GET",
        
'header'=>"User-Agent: ".self::BROWSER." \r\n"
    
)
);
$url_string file_get_contents($url,false,stream_context_create($opts));
return 
simplexml_load_string($url_string); 
But stream context create doesn't work on secured pages, such as for example the guild-login part or the account management page?

Or am I wrong?
__________________
Tanax is offline  
Reply With Quote
Old 03-09-2009, 03:02 PM   #15 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
But stream context create doesn't work on secured pages, such as for example the guild-login part or the account management page?

Or am I wrong?
The stream contexts will work on any of PHPs stream wrappers (file, http, ftp, php, phar, to name a few) provided you give the proper options/parameters.
Salathe is offline  
Reply With Quote
Old 03-09-2009, 08:30 PM   #16 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
The stream contexts will work on any of PHPs stream wrappers (file, http, ftp, php, phar, to name a few) provided you give the proper options/parameters.
Are you sure it works with secured pages(https)?

Check this thread, it's kinda related to this:
Stream problem
__________________
Tanax is offline  
Reply With Quote
Old 03-09-2009, 10:00 PM   #17 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Are you sure it works with secured pages(https)?
Yes, I regularly access remote pages over SSL with cURL and file_get_contents. Provided your server has OpenSSL, there's really not all that much difference between using HTTP and HTTPS (in the context of retrieving web documents with PHP).
Salathe is offline  
Reply With Quote
Old 01-07-2009, 08:22 PM   #18 (permalink)
The Visitor
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Dark Severance is on a distinguished road
Default

This is great. I'm slowly working with it to get what I needed but I'm having a problem.

I love the roster and able to pull information from that to create a guild roster. The issue I'm having is I also want to parse in the Profession information. However that is on the separate character pages themselves. How can I grab both roster and all the character pages from that one guild roster so I can then display them how I want.

You can see what I've sort of been experimenting with here:
http://wow.guildregister.com/sortableTable/roster.php

Or even better due to Armory not updating as much. How could I get a .lua file converted over to XML or some format so I can work with it, similar to what you've done with the Armory page. That would work best since that includes officer notes, guild notes, professions, names, etc.

Example of .lua file is here:
http://wow.guildregister.com/sortabl...erProfiler.lua

Last edited by Dark Severance : 01-07-2009 at 09:06 PM.
Dark Severance is offline  
Reply With Quote
Old 01-07-2009, 09:12 PM   #19 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

have a look at this:
http://fin.instinct.org/lua/
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-08-2009, 08:06 PM   #20 (permalink)
The Visitor
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Dark Severance is on a distinguished road
Default

Unfortunately that doesn't work for me. So continuing to work with what he has done here I have...

I can then sort the xml data and have it display information in a table format (still work in progress) just by adding this to the code:
Code:
$armory = new armory('roster', 'Drenden', 'Priests of Discord', NULL, NULL);
$xml = $armory->pull_xml();

foreach ($xml->guildInfo->guild->members->character as $char) {
  echo "<tr id=\"".$char['name']."\">";
  echo "<td class=\"rightAlign\">".$char['name']."</td>";
  echo "<td>".$char['level']."</td>";
  echo "<td>".$char['class']."</td>";
  echo "<td>".$char['gender']."</td>";
  echo "<td>".$char['race']."</td>";
  echo "<td>".$char['achPoints']."</td>";
  echo "<td>".$char['url']."</td><br />";
  echo "</tr>";
			}
I understand that the following:
Code:
$armory = new armory('roster', 'Drenden', 'Priests of Discord', NULL, NULL);
$xml = $armory->pull_xml();
is broken up into variables that let me define where it's pulling the data. There are two different XML pages, one is 'roster' and the other is 'character'. The second field determines what server: 'Drenden'. The third field indicates the guild name: 'Priests of Discord'. The fourth field indicates specific character name: NULL. The last field is page number, when looking at guild information only used during the 'roster' option.

The problem is the 'character' xml page. There is a lot more information in that page. I could access it for a single character like 'Anastasia' by using the following code:
Code:
$armory = new armory('character', 'Drenden', 'Priests of Discord', 'Anastasia', NULL);
$xml = $armory->pull_xml();
I want to be able to temporarily load all the XML data for the 'roster' page as well as each 'character' page for only those members on that 'roster' page. I tried to do something like:

Load Armory Roster Page
Code:
$armory = new armory('roster', 'Drenden', 'Priests of Discord', NULL, NULL);
$xml = $armory->pull_xml();
Then use access the name variable to create a separate query for each by doing:
Code:
foreach ($xml->guildInfo->guild->members->character as $char) {
$armory = new armory('character', 'Drenden', 'Priests of Discord', $char.['name'], NULL);
$xml = $armory->pull_xml();
		}
Unfortunately that does not seem to work. I'm probably trying to load too much variable information or I have the wrong order of how I can use it. I might be over complicating it too. Step by step I can produce each thing individually, now I'm just trying to combine all the single steps so I can display it all on one page.



Full Code:
Code:
<?php

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://www.wowarmory.com/guild-info.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
		
	  }elseif( $this->query === 'character' ){
		$url = 'http://www.wowarmory.com/character-sheet.xml?r=' . urlencode($this->server) . '&n=' . $this->guildie;
		
		}  

	$ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
	curl_setopt ($ch, CURLOPT_USERAGENT,  self::BROWSER);
	
	$url_string = curl_exec($ch);
	curl_close($ch);
	return simplexml_load_string($url_string);
	
   
 } // end of pull_xml()

} // end class  

$armory = new armory('roster', 'Drenden', 'Priests of Discord', NULL, NULL);
$xml = $armory->pull_xml();

	foreach ($xml->guildInfo->guild->members->character as $char) {
$armory = new armory('character', 'Drenden', 'Priests of Discord', $char['name'], NULL);
$xml = $armory->pull_xml();
		}

foreach ($xml->characterInfo->characterTab->professions->skill as $prof) {
	echo $prof['name'];
}

foreach ($xml->guildInfo->guild->members->character as $char) {
  echo "<tr id=\"".$char['name']."\">";
  echo "<td class=\"rightAlign\">".$char['name']."</td>";
  echo "<td>".$char['level']."</td>";
  echo "<td>".$char['class']."</td>";
  echo "<td>".$char['gender']."</td>";
  echo "<td>".$char['race']."</td>";
  echo "<td>".$char['achPoints']."</td>";
  echo "<td>".$char['url']."</td><br />";
  echo "</tr>";
			}

?>
Dark Severance 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 01:24 AM.

 
     

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