Created
October 4, 2010 07:34
-
-
Save gizzmo/609351 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Blizzard to Wowhead converter | |
* | |
* Converts Blizzard's talent string and class id into Wowhead's (shorter) talent string | |
* | |
* @author Gizzmo <[email protected]> | |
* | |
* @param string|int $class Blizzard's class id or class name | |
* @param string $build Blizzard's build string | |
* @param boolean $to_url return a Wowhead talent URL | |
* @return string Wowhead's talent string | |
* @return string Wowhead's talent url | |
*/ | |
function b2w($class, $build, $to_url = false) | |
{ | |
// For language support | |
$warrior = 'warrior'; | |
$paladin = 'paladin'; | |
$hunter = 'hunter'; | |
$rogue = 'rogue'; | |
$priest = 'priest'; | |
$death_knight = 'death knight'; | |
$shaman = 'shaman'; | |
$mage = 'mage'; | |
$warlock = 'warlock'; | |
$druid = 'druid'; | |
// Blizzard and wowhead have different order for the classes witch result in different ids | |
$blizzard_classes = array(null,$warrior,$paladin,$hunter,$rogue,$priest,$death_knight,$shaman,$mage,$warlock,null,$druid); | |
$wowhead_classes = array($druid,$hunter,$mage,$paladin,$priest,$rogue,$shaman,$warlock,$warrior,$death_knight); | |
// Tree count order by wowhead order | |
$tree_counts = array( | |
array(20, 22, 21), // druid | |
array(19, 19, 20), // hunter | |
array(21, 21, 19), // mage | |
array(20, 20, 20), // paladin | |
array(21, 20, 21), // priest | |
array(19, 19, 19), // rogue | |
array(19, 19, 19), // shaman | |
array(18, 19, 19), // warlock | |
array(20, 21, 20), // warrior | |
array(20, 20, 19) // death knight | |
); | |
// The string of which wowhead uses to encode their string | |
$encrypt_string = '0zMcmVokRsaqbdrfwihuGINALpTjnyxtgevElBCDFHJKOPQSUWXYZ123456789Z'; | |
// Clean up the class | |
$class = trim($class); | |
// We are assuming the id number privided is the blizzard class id | |
if (is_numeric($class)) | |
$class = $blizzard_classes[$class]; | |
// Now just convert the name to class id | |
foreach ($wowhead_classes as $i => $wowhead_class) | |
{ | |
if (strtolower($class) == strtolower($wowhead_class)) | |
{ | |
$class_id = $i; | |
break; | |
} | |
} | |
// Check to make sure the class id is set | |
if (!isset($class_id)) | |
trigger_error('The provided class is invalid.', E_USER_ERROR); | |
// Check to make sure the build string is the correct length | |
if (strlen($build) != array_sum($tree_counts[$class_id])) | |
trigger_error('The provided build string is not the correct length for the provided class.', E_USER_ERROR); | |
// Now break the build string down into the different trees | |
$build_trees = array( | |
substr($build,0,$tree_counts[$class_id][0]), | |
substr($build,$tree_counts[$class_id][0],$tree_counts[$class_id][1]), | |
substr($build,$tree_counts[$class_id][0]+$tree_counts[$class_id][1],$tree_counts[$class_id][2]) | |
); | |
// Start the string with the class | |
$string = $encrypt_string[$class_id*3]; | |
// Loop though each tree to encode it | |
foreach ($build_trees as $cur_tree) | |
{ | |
$etree = ''; | |
$b = rtrim($cur_tree, '0'); | |
for ($i=0; $i<strlen($b); $i++) | |
{ | |
$tens = intval($b[$i]); | |
$ones = (++$i == strlen($b))? 0: intval($b[$i]); | |
$etree .= $encrypt_string[$tens*6 + $ones]; | |
} | |
$string .= (strlen($b)==strlen($cur_tree))? $etree: $etree.$encrypt_string[62]; | |
} | |
// Remove any extra Z's | |
$string = rtrim($string, $encrypt_string[62]); | |
// Return the wowhead talent url? | |
if ($to_url) | |
$string = 'http://www.wowhead.com/talent#'.$string; | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment