xml_helper = new XmlHelper(); $this->colornames['q0'] = "greyname"; $this->colornames['q1'] = "whitename"; $this->colornames['q2'] = "greenname"; $this->colornames['q3'] = "bluename"; $this->colornames['q4'] = "purplename"; $this->colornames['q5'] = "orangename"; $this->colornames['q6'] = "redname"; if (!empty($method)) $this->method = $method; } // Cleans up resources used by this object. function close() { $this->xml_helper->close(); } // Attempts to retrieve data for the specified item from Allakhazam. function getItem($name) { global $settings; // Ignore blank names. $tempname = trim($name); if (empty($tempname)) { return null; } // set default value... $item_found = false; $itemid_found = false; $wrongitem = true; $item = array('name' => $name); $item['source'] = '1'; $item['method'] = $this->method; $item['id'] = '-1'; if ($this->method =='id') { $item['method'] = 'id'; $item['source'] = '1'; $item_id = $name; $itemid_found = true; } else { // Perform the search. $data = downloadFile('http://www.buffed.de/?f=' . urlencode($name)); if ($data !== false) { $data = str_replace('?i=', 'i=', $data); // Look for a name match in the search result. if(preg_match_all('#(.*?)(.*?)#s', $data, $matches)) { foreach ($matches[3] as $key => $match) { // Extract the item's name from the match. if (strpos($match, '') !== false) { $tempname = str_replace('', '', $match); $tempname = $tempname . $matches[4][$key]; } else { $tempname = $match; } // now check if this is the item we searched if(strtoupper($name) == strtoupper($tempname)) { $name = $tempname; $item['method'] = 'find'; $item['source'] = '1'; // Extract the item's ID from the match. $item_id = $matches[1][$key]; $itemid_found = true; break; } } } } } if($itemid_found == true) { // Retrieve the XML for this item from Buffed. $xml_data = downloadFile('http://www.buffed.de/xml/i' . $item_id . ".xml"); if ($xml_data !== false) { // ok check if we really got a valid xml file $tempname = $this->xml_helper->fetch($xml_data, 'wowitem/InventoryName'); $tempicon = $this->xml_helper->fetch($xml_data, 'wowitem/Icon'); if ($tempname !== false && $tempicon !== false) { $item['name'] = itemstats_fixname($tempname); $item['id'] = $item_id; $item['icon'] = $tempicon; $item['link'] = 'http://www.buffed.de/?i=' . $item['id']; $item['found'] = '1'; $item_found = true; } } } // If a match was found, retrieve additional info about it. if ($item_found) { $item_parse_failed = false; // Parse out the display html of this item from the XML $item['html'] = $this->xml_helper->fetch($xml_data, 'wowitem/display_html'); if ($item['html'] !== false) { $item['html'] = str_replace("\r", '', $item['html']); $item['html'] = str_replace("\n", '', $item['html']); $item['html'] = '
' . $item['html'] . '
'; // Extract the item color from the HTML. preg_match('#
#s', $item['html'], $match); $item['color'] = $this->colornames[$match[1]]; $item['html'] = preg_replace('#
#s', '', $item['html']); // Fix up the html a bit. $item['html'] = str_replace('', '
', $item['html']); //$item['html'] = str_replace("tooltip", "wowitemt", $item['html']); $item['html'] = str_replace("'", "'", $item['html']); $item['html'] = str_replace('"', "'", $item['html']); $item['html'] = str_replace('', '', $item['html']); // If this is a set, grab the set bonuses and add it to the html. $item_set_id = $this->xml_helper->fetch($xml_data, 'wowitem/ItemSet'); if ($item_set_id !== false && ($item_set_id != '0')) { // Read the item set page. $data = downloadFile('http://www.buffed.de/?set=' . $item_set_id); if($data !== false) { // Extract the set bonus html from this page. preg_match('#

#s', $data, $match); $item_set_bonuses = '
(.*?)
#s', $item_set_bonuses, $match); $item_set_bonuses = '
' . $match[1] . '
'; preg_match_all('#(.*?)#s', $item_set_bonuses, $matches); foreach ($matches[1] as $key => $match) { $tempreplace = '' . $match . ''; $item_set_bonuses = str_replace($matches[0][$key], $tempreplace, $item_set_bonuses); } $item_set_bonuses = str_replace(""; // Fix up the html a bit $item['html'] = str_replace('
', $item_set_bonuses . '', $item['html']); } else { $item_parse_failed = true; } } } else { $item_parse_failed = true; } if ($item_parse_failed === false) { // Build the final HTML by merging the template and the data we just prepared. $template_html = trim(readLocalFile($settings['default_theme_dir'] . '/itemstats/templates/popup.tpl')); $item['html'] = str_replace('{ITEM_HTML}', $item['html'], $template_html); } else { // If Buffed was busy or this item doesn't exist and this item isn't cached yet, create some error html. $item['icon'] = DEFAULT_ICON_BUFFED; $item['color'] = 'greyname'; $item['found'] = '0'; // Read the template html for an item. $template_html = trim(readLocalFile($settings['default_theme_dir'] . '/itemstats/templates/popup-error.tpl')); $item['html'] = str_replace('{INFO_SITE}', 'Buffed', $template_html); } } else { // If Buffed was busy or this item doesn't exist and this item isn't cached yet, create some error html. $item['icon'] = DEFAULT_ICON_BUFFED; $item['color'] = 'greyname'; $item['found'] = '0'; // Read the template html for an item. $template_html = trim(readLocalFile($settings['default_theme_dir'] . '/itemstats/templates/popup-error.tpl')); $item['html'] = str_replace('{INFO_SITE}', 'Buffed', $template_html); } return $item; } } ?>