<?php
// edit by Corgan:
// search for the item ID on blasc
//
// last changes: 01.11.2005 by Corgan
// visit: http://www.seniorenraid.de
include_once(dirname(__FILE__) . '/xmlhelper.php');
include_once(dirname(__FILE__) . '/urlreader.php');
define('ICON_LINK_PLACEHOLDER', '{ITEM_ICON_LINK}');
define('DEFAULT_ICON', 'INV_Misc_QuestionMark');
// The main interface to the Blasc Site
class InfoSite
{
var $xml_helper;
var $colornames;
// Constructor
function InfoSite()
{
$this->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";
}
// 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)
{
// Ignore blank names.
$name = trim($name);
if (empty($name))
{
return null;
}
$item = array('name' => $name);
$item_found = false;
if (file_exists(dirname(__FILE__) . '/../itemlist.xml'))
{
$itemlist = file(dirname(__FILE__) . '/../itemlist.xml');
for ($i=0;$i<count($itemlist);$i++)
{
if (strpos($itemlist[$i], 'name="'.$name.'"') !== false)
{
preg_match('#<wowitem name="(.*?)" id="(.*?)" />#', $itemlist[$i], $itemmatches);
$item_id = $itemmatches[2];
//print $item_id;
break;
} // stristr($itemlist, 'name="'.$name.'"') !== false
} // for ($i=0;$i<count($itemlist);$i++)
}
else
{
}
//-------------------------------------------------------------- edit by corgan begin
if (empty($item_id))
{
$itemstats = "";
$itemBlasc = $name;
$itemBlasc = str_replace(" ","+",stripslashes($itemBlasc));
$filename = "http://www.blasc.de/?f=".$itemBlasc;
$ch = curl_init();
$timeout = 15; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $filename);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// curl_setopt ($ch, CURLOPT_PROXY, 'PROXY-NAME:PROXY-PORT');
$fp = curl_exec($ch);
curl_close($ch);
if (empty($fp)) {
$itemstats .= "cannot open ".$filename;
}
$data2 = $fp;
preg_match("/i=[a-z0-9]*/", $data2, $matches);
preg_match("/icons\/[A-z0-9_-]*\.png/", $data2, $iconmatch);
$itemid = $matches[0];
$iconid = $iconmatch[0];
//get the xml data and output it
$item_id = trim(substr($itemid, 2));
// debug ouput
//print "itemID:" .$itemid . "<br>";
//print "itemID:" . $item_id . "<br>";
//print "Item Name:" . $name . "<br>";
//print "Item Name:" . $itemBlasc . "<br>";
//-------------------------------------------------------------- edit by corgan END
}
$xml_data = itemstats_read_url('http://www.blasc.de/xml/i' . $item_id . '.xml');
// Parse out the name of this item from the XML and check if we have a match
$xml_name = $this->xml_helper->parse($xml_data, 'InventoryName');
if (!empty($xml_name))
{
// If we have a match, grab additional information about this item and break out of this loop.
//$item['name'] = $itemmatches[1];
$item['name'] = $name; // -------->>> edit by corgan
$item['icon'] = $this->xml_helper->parse($xml_data, 'Icon');
$item['link'] = 'http://www.blasc.de/?i='. $item_id;
$item_found = true;
} // if (strcasecmp($item['name'], $xml_name) == 0)
// If a match was found, retrieve additional info about it.
if ($item_found)
{
// Parse out the display html of this item from the XML
$item['html'] = '<div class="wowitemt" style="display:block">'.$this->xml_helper->parse($xml_data, 'display_html').'</div>';
// Extract the item color from the HTML.
preg_match('#<span class="item (.*?)">#s', $item['html'], $match);
$item['color'] = $this->colornames[$match[1]];
$item['html'] = preg_replace('#<span class="item (.*?)">#s', '<span class="'.$item['color'].'">', $item['html']);
// Fix up the html a bit.
$item['html'] = str_replace('<table width="100%">', '<table width="" border="0" cellpadding="0" cellspacing="0">', $item['html']);
$item['html'] = str_replace("tooltip", "wowitemt", $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->parse($xml_data, 'ItemSet');
if (!empty($item_set_id) && ($item_set_id != '0'))
{
// Read the item set page.
$data = itemstats_read_url('http://www.blasc.de/?set=' . $item_set_id);
// Extract the set bonus html from this page.
preg_match('#<table class="liste" width="100%" cellspacing="1">(.*?)</table>#s', $data, $match);
$item_set_bonuses = $match[1];
// Fix up the html a bit
$item_set_bonuses = "<div class='wowitemt' style='display:block'><span class='setbonus'><table width='100%' cellspacing='1'>" . $item_set_bonuses . "</table></span></div>";
$item['html'] .= $item_set_bonuses;
$item['html'] = str_replace('"', "'", $item['html']);
}
// Build the final HTML by merging the template and the data we just prepared.
$template_html = trim(file_get_contents(dirname(__FILE__) . '/../templates/popup.tpl'));
$item['html'] = str_replace('{ITEM_HTML}', $item['html'], $template_html);
}
else
{
include_once(dirname(__FILE__) . '/allakhazam.php');
$allaitems = new InfoSite2;
$item = $allaitems->getItem($name);
}
return $item;
}
}
?>