This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
Spell/Quest XML & Name Queries?
Post Reply
Return to board index
Post by
Lockslap
This is speaking from a purely PHP coder standpoint. As I'm sure you're aware, I am developing/have developed a "mod" for phpBB3 that allows the item links from Wowhead to be used on their site by using the BBCode. Its working great, and I have thanked you guys many times for providing the tools by which to develop PHP scripts (ie XML listings of your pages).
My script works by using the following format:
When it sees it will take the text in between and then find what they're looking for by going to:
http://www.wowhead.com/?item=<name>&xml
, where <name> is the name of the item.
Then by using the XML page you provide it will get the necessary information it needs (properly formatted name, quality, and item id) and display it in the form of a tag that is so familiar in WoW.
The problem arises when I attempt to try and search for spells using the:
http://www.wowhead.com/?spell=<name>&xml
format, with the problem being that the XML pages do not exist. Also, linking an spell by its name also does not work, rather it must be linked by its id. I was wondering if it was possible to add this functionality so that we may be able to create scripts that can link spells, quests, etc., I'm not sure if its possible due to how the site was coded.
I have developed a way to do the methods described above using your search page. However, this method is terribly slow and would take an unnecessary amount of time when linking numerous spells on a single post of the forums. I am trying to create my scripts so that they use the least amount of bandwidth from you guys as possible.
Any help/feedback would be greatly appreciated. I just hope I explained things clearly; I'm generally not good at explaining things.
Thanks,
craCkpot aka. Lockslap
Edit: I realize that I could just parse page to get the info I needed, without the need for XML. The only problem that I see is that it could cause several problems depending on what quest/spell is being queried.
Post by
tecnobrat
This is just me offering some suggestions ... you will probably want to wait for an official answer from Skosiris / Malgayne on if they plan to make any changes to the XML
If you are planning on parsing XML anyways, you could use the XML to get the item quality/name/id for items, and then simply build links like:
<a class="q6" href="
http://www.wowhead.com/?item=192
">Martin Thunder</a>
Then use our powered script to power the actual tooltip.
Quests you can just make the user do:
Fel Embers
Fel Embers
Which would just translate to:
<a href="
http://www.wowhead.com/?quest=9494
">Fel Embers</a>
I know the quest tooltips wouldn't be as graceful as you would like .. but it would work.
Oh, and
http://www.wowhead.com/?item=192&power
and
http://www.wowhead.com/?quest=9494&power
, might be able to help a little. However quest name is still not searchable that way. But this would allow you to change them to:
9494
Post by
pelf
Man... I wish I was still an admin on some WoW-related site so I could have fun setting all of this up. I almost want to put up some forums that nobody uses just to do it for the sake of doing it.
Post by
Lockslap
Tecnobrat, what you described above is exactly what my script does for items. Its located
here
. I would just like the same functionality as I have for items, but for quests/spells. The whole point of my script is to give the functionality of Spellstrike Pants and it will get all of the information it needs on its own. Thereby, the user doesn't have to goto Wowhead or wherever and get the ID of the item/quest/spell, it is all gathered on its own and then added to a MySQL database where it is saved for later use.
I was unaware of the '&power' tag, I may be able to use that for some functionality until I get a response from your developers.
Thanks for the reply!!
Post by
tecnobrat
Not a problem, glad I could help somewhat :)
Post by
Lockslap
Quick update! I have added quest functionality using {questid} syntax. You can check it out
here
, pretty nice if I do say so myself!!!
Post by
25321
This post was from a user who has deleted their account.
Post by
Lockslap
i would really love to see this as well, and as for the info the xml creates at which you are afraid will to to much, the possibility to get the spell/quest id with the /?item=martin+tunder&xml because then indeed by the &powered you can get the tooltip, what we want is that users can simply search quests/spells by name and have no need to go find it on wowhead.
best regards Mylon
I have written a method of getting quests and spells by using Wowhead's built in search. Basically, I just search for the name their looking for (quest or spell) and then my script will read in the resulting search page and get the info it needs. It wasn't really that difficult once I studied the search page's source a little bit.
Here's the code:
// attempts to find a quest by its name by using wowhead's search
function whp_find_by_search($name, $type = 'quest', $rank = '')
{
if ($type != 'quest' && $type != 'spell')
return false;
if ($type == 'spell')
$matches = array();
// we'll use cURL to query wowhead
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, whp_generate_domain() . '/?search=' . urlencode(utf8_encode($name)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1); // include headers in case we get redirected
$data = curl_exec($curl);
curl_close($curl);
if (preg_match('#Location: /\?' . $type . '=(.+?)\n#s', $data, $match))
{
// for searches with only one result
return array(1 => $match, 2 => ucwords(strtolower($name)));
}
else
{
// i'm sure there's a more efficient way to do this, but i can't think of one at the moment
// so back off!!!! =D
if ($type == 'spell')
{
$the_line = whp_get_ability_line($data);
$pattern = '#id:({1,10}),name:\'\@(.+?)\'#s';
}
elseif ($type == 'quest')
{
$the_line = $data;
$pattern = '#<a href="/\?quest=({1,10})">(.+?)</a>#s';
}
// then we'll use preg_match to find any matches
while (preg_match($pattern, $the_line, $match))
{
// do we have a match?
if (strtolower($match) == strtolower($name))
{
if ($type == 'quest')
{
return $match;
break;
}
elseif ($type == 'spell')
{
// try to get the max rank of the spell
array_push($matches, $match);
$the_line = str_replace($match, '', $the_line);
}
}
else
{
// remove the found entry to prevent a never ending loop
$the_line = str_replace($match, '', $the_line);
}
}
// now return the rank they asked for
if ($type == 'spell' && $rank != '')
{
if ((int)$rank <= sizeof($matches))
return $matches;
else
return false;
}
elseif ($type == 'spell' && $rank == '')
{
// otherwise give them max rank (if it has a rank)
return $matches;
}
}
return false;
}
function whp_get_ability_line($data)
{
$parts = explode(chr(10), $data);
foreach ($parts as $line)
{
if (strpos($line, "new Listview({template: 'spell', id: 'abilities'") !== false)
return $line;
}
return false;
}
$name is the name of the quest/spell their looking for.
$type is either "quest" or "spell"
$rank is the rank of the spell they wish to get.
If they're looking for a quest it will get the first match it finds using regular expressions. If they're looking for a spell it will get all of the spells that it finds a match for. Then if $rank is set it will get that rank (by using an array where $rank - 1 is the index of the array with the corresponding spell), if no rank is given it will return the highest rank it has (sizeof(array) - 1). If the spell or quest immediately redirects to the spell/quest's page on wowhead then the script will read the headers returned and then look for the "Location:" header which will contain the link to the quest/spell's page and thereby the ID that I need.
Keep in mind this code is developed to work in my script for using Wowhead tooltips on a phpBB3 forum. With some changes, it could be made to work in basically anything. My script currently works by using a quest's or spell's name and then being linked, and I will be uploading the newest version shortly.
I hope this helps.
Post by
Unbarc
I have written a method of getting quests and spells by using Wowhead's built in search. Basically, I just search for the name their looking for (quest or spell) and then my script will read in the resulting search page and get the info it needs. It wasn't really that difficult once I studied the search page's source a little bit.
...
Awesome, thanks for sharing! I've been tinkering with one for my custom
Smarty
-based site; I got a plugin to work for automatically gathering item info, but have been struggling a bit on the quest/spell part.
I'm also working on a credits page for my site, I'll be sure to add you to it once I get this implemented.
Post by
Lockslap
I have written a method of getting quests and spells by using Wowhead's built in search. Basically, I just search for the name their looking for (quest or spell) and then my script will read in the resulting search page and get the info it needs. It wasn't really that difficult once I studied the search page's source a little bit.
...
Awesome, thanks for sharing! I've been tinkering with one for my custom
Smarty
-based site; I got a plugin to work for automatically gathering item info, but have been struggling a bit on the quest/spell part.
I'm also working on a credits page for my site, I'll be sure to add you to it once I get this implemented.
Yeah the functions I posted above took me a couple of hours to write. Most of the time being spent studying the source code from the search results that Wowhead gives, and then figuring out the best/fastest way to extract the information that I needed (the quest/spell's ID and a properly formatted name). After that everything went pretty smoothly. The function actually worked after writing the entire thing, I was shocked.
I had to tweak it a little bit after finding out that when you search for something that has only one result (I used 'Feral Charge') it will redirect you to the spell/quest's page. Hence why the
curl_setopt($curl, CURLOPT_HEADER, 1); so I can see the headers that are being sent back.
Probably the most difficult portion of the script was extracting the line of Javascript that had all of the abilities listed on it, rather than all of the results. After that, it was smooth sailing.
I like your website, it looks really nice. I have never personally used Smarty, but have done my reading on it in the past.
Good luck to you, I hope you can put the functions to good use!!! If it gives you any troubles or if you come up with a more efficient way, please let me know.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.