t('WoW Head')); } function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } /** * Implementation of lootz_hook_filter_description(). */ function lootz_wowhead_filter_description() { return t('Converts [item] tags to links/tooltips of the configured item database (WoW Head is the default).', array('!url' => WOWHEAD_BASE_URL)); } /** * Implementation of lootz_hook_filter_tips(). */ function lootz_wowhead_filter_tips() { return t('You can include [item][/item] tags to automatically link the items to WoWHead. Either use the Item ID ([item]1234[/item]) or the exact name ([item]Earthwarden[/item])', array('!url' => WOWHEAD_BASE_URL)); } /** * Implementation of lootz_hook_id_lookup(). */ function lootz_wowhead_id_lookup($name) { $name = ucwords($name); $url = WOWHEAD_BASE_URL . '/' . WOWHEAD_SEARCH_NAME . drupal_urlencode($name) ."#items:0-2+1"; $page = file_get_contents($url); // Check to see if it's a search page. if (preg_match('/

Search Results for/', $page, $m)) { // Find the id of an exact match, or a match with escaped quotes. $escaped = preg_quote(addslashes($name)); $pattern = "/\[([0-9]+)\]=\{name_enus\:'(" . $name . "|" . $escaped . ")'/i"; if (preg_match_all($pattern, $page, $m)) { if ($m[1][1]!="") {return check_plain($m[1][1]);} else {return check_plain($m[0][1]);} } } else { // You're on the right page already! if (preg_match('/typeId: ([0-9]+)/', $page, $m)) { return check_plain($m[1]); } } return FALSE; } /** * Implementation of lootz_hook_name_lookup(). */ function lootz_wowhead_name_lookup($id) { // Grab search results. $url = WOWHEAD_BASE_URL . '/' . WOWHEAD_SEARCH_ID . $id; $page = file_get_contents($url); // Search for the name which is next to the id 4677, name: 'Veteran Cloak'. if (preg_match("/(.*) - Item/", $page, $m)) { return check_plain($m[1]); } return $id; } /** * Implementation of lootz_hook_quality_lookup(). */ function lootz_wowhead_quality_lookup($id, $name) { // Pattern: <b class=q4>Earthwarden</b> $url = WOWHEAD_BASE_URL . '/' . WOWHEAD_SEARCH_ID . $id; if ($url!="http://www.wowhead.com/?item=") { $result = get_web_page($url); $page = $result['content']; if (preg_match("/name_enus:'".$name."',quality:([0-9]{1})/", $page, $m)) { switch ($m[1]) { case '1' : // 1: common $quality = 'common'; break; case '2' : // 2: uncommon $quality = 'uncommon'; break; case '3' : // 3: rare $quality = 'rare'; break; case '4' : // 4: epic $quality = 'epic'; break; case '5' : // 5: legendary $quality = 'legendary'; break; case '6' : // 6: artifact? $quality = 'artifact'; break; case '7' : // 7: bind to account $quality = 'bind_to_account'; break; default: $quality = FALSE; } } return $quality; } else { returN FALSE; } } /** * Implementation of lootz_hook_link_item(). */ function lootz_wowhead_link_item($name, $id) { $url = WOWHEAD_BASE_URL . '/' . WOWHEAD_SEARCH_ID . $id; return theme('lootz_link_item', $url, $name, $id); } /** * Implementation of lootz_hook_init(). */ function lootz_wowhead_init() { // Include the external js. drupal_set_html_head('<script type="text/javascript" src="' . WOWHEAD_JS_LIBRARY . '"></script>'."\n"); }