<?php

if (!defined('MEDIAWIKI')) {
    
highlight_file(__FILE__);
}

require_once(
"$IP/extensions/WoWItem/includes/wowiteminfobase.class");

/**
  * This class will parse the xml feed from WowHead's World of Warcraft website to retrieve item  
  *    information and display it in an popup window.
  *
  */
wfWoWItem_RegisterClass('wowhead', array('head'));
class 
wowhead
{

//*******************************************************************************************************************************  
    
var $usedb 0;                                 // 0 will not use a db, 1 will use a db for faster page loading.
    
var $showpuicon 1;                          // display icon in popup?
    
var $init true;
    var 
$itemInfo;
    var 
$parent;

    function 
__construct()
    {
        
$url 'http://www.wowhead.com/';
        
$search $url '?search=%s';
        
$stats $url '?item=%s';
        
$icons 'http://static.wowhead.com/images/icons/large/';
        
$this->parent = new wowiteminfobase(__CLASS__$url$search$stats$icons);
        
//echo 'Initialized';
    
}

    function 
getiteminfo($itemnumber$img false)
    {
        if (!
is_numeric($itemnumber))
        {
            
$itemnumber $this->getitemid($itemnumber); 
            if (!
$itemnumber && preg_match('((.*) of (.*))'$itemnumber$matches)) {
                
$itemnumber $this->getitemid(trim($matches[1]));
            }
        }
        
$tmpitem $this->parent->getCachedItemInfo($itemnumber);
        if (
$tmpitem) {
            
$this->parent->saveItemInfo($this$tmpitem$itemnumber);
        }
        
$itemhtml = array(
            
'top' => '<div class="wowitem"><span class="iname"><span class="%s">%s</span></span><br />' "\n",
        );

        if (
$this->items[$itemnumber]) {
//            echo 'Found<br />';
            
$results $this->items[$itemnumber];
        } else {
            
$output = array();
            
$itemid $itemnumber;
            
$page itemstats_read_url(sprintf($this->parent->stats$itemid));
            
$begin false;
    
//        $rawData = str_replace("\n", "", $page);
            
foreach(explode("\n"$page) AS $rawData) {
                if (
preg_match('(<div id=".*?" class="tooltip" style=".*?">)'$rawData$matches)) {
                    
$begin true;
                    continue;
                }
                if (
$begin) {
                    
$begin false;
                    
preg_match('(<b class="q(.*?)">(.*?)</b>)'$rawData$nameMatches);
                    
$popquality $nameMatches[1];
                    
$output['item_name'] = $nameMatches[2];
    
//                $itemhtml['slot'] = $matches[3];
                    
$itemhtml['stats'] = preg_replace('(<b class="q(.*?)">(.*?)</b><br />)'""preg_replace("(</t[dh]>)""<br />"preg_replace('((Binds.*?)<)''$1<br /><'$rawData)));
                    
$itemhtml['stats'] = preg_replace('(</*t[rdh].*?>)'''$itemhtml['stats']);
                    
$itemhtml['stats'] = preg_replace('(</*table.*?>)'''$itemhtml['stats']);
                    
$itemhtml['stats'] = preg_replace('(</*tbody.*?>)'''$itemhtml['stats']);
                    
$itemhtml['stats'] = str_ireplace('<br />'"%y"$itemhtml['stats']);
                    
$itemhtml['stats'] = str_ireplace('<br>'"%y"$itemhtml['stats']);
                    
$itemhtml['stats'] = preg_replace('((%y){3,})'''$itemhtml['stats']);
                    
$itemhtml['stats'] = str_replace('%y''<br />'$itemhtml['stats']);
                    
$itemhtml['stats'] = str_replace('/?spell='$this->parent->url '?spell='$itemhtml['stats']);
                    
$itemhtml['stats'] .= '<br /><br />Item display is courtesy <a href="'$this->parent->url .'">'substr(str_replace('http://'''$this->parent->url), 0, -1) .'</a>';
                }
                if (
preg_match('(ge\(\'ic'$itemid .'\'\)\.appendChild\(Icon\.create\(\'(.*?)\', .*?, .*?, .*?, .*?\)\);)'$rawData$matches)) {
                    
$output['icon'] = $this->parent->icons strtolower($matches[1]) . '.jpg';
                }
            }
            switch (
$popquality)
            {
                case 
"0":
                    
$style "greyname";
                    break;
                case 
"1":
                    
$style "whitename";
                    break;
                case 
"2":
                    
$style "greenname";
                    break;
                case 
"3":
                    
$style "bluename";
                    break;
                case 
"4":
                    
$style "purplename";
                    break;
                case 
"5":
                    
$style "orangename";
                    break;
                case 
"6":
                    
$style "redname";
                    break;
                case 
"7":
                    
$style "goldname";
                    break;
                default:
                    
$style "greyname";
                    break;
            }
        
            
$itemhtml['top'] = sprintf($itemhtml['top'], $style$output['item_name']);
            
$i 1;
            
$stats = array();
    
    
//        unset($itemhtml['stats'], $itemhtml['otherstats']);
            
$itemhtml['bottom'] = '</div>' "\n";
    
            
$results['itemnumber'] = $itemnumber;
            
$results['itemname'] = $output['item_name'];
            
$results['itemquality'] = $style;
            
$results['itemhtml'] = implode("\n"$itemhtml);
            
$temp = array();
            foreach (
explode("\n"$results['itemhtml']) AS $i => $line) {
                
$temp[$i] = trim($line);
            }
            
$results['itemhtml'] = implode($temp);
            
$results['itemicon'] = $output['icon'];
    
            
$results['itemicon'] = $this->addIconLocal($results['itemicon']);
        }
        if (
$img == '__IMG__') {
            
$results['displayitemhtml'] = str_replace('<span class="iname">''<img style="float: left" src="'.$results['itemicon'].'">' '<span class="iname">'$results['itemhtml']);
        } else if (
is_string($img)) {
            
$results['displayitemhtml'] = str_replace('<span class="iname">''<img style="float: left" src="'.$img.'">' '<span class="iname">'$results['itemhtml']);
        } else {
            
$results['displayitemhtml'] = $results['itemhtml'];
        }

        
$this->parent->saveItemInfo($this$results$itemnumber);
        return 
$results['itemname'] == "" false $results;
    }

    function 
showpopup($itemnumber$img=""$received="")
    {
        
$iteminfo    $this->getiteminfo($itemnumber);
        
$popname   $iteminfo['itemname'];
        
$popquality    $iteminfo['itemquality'];
                
        if (
$img)
        {
            if (
$img == "__IMG__") {
                
$icon $iteminfo['itemicon'];
            } else {
                
$icon $img;
            }
            
$pophtml "<img src='" $icon "' border=0 width='50' height='50'>" $iteminfo['displayitemhtml']; 
        }
        else
        {
            
$pophtml $iteminfo['displayitemhtml'];
        }
        
        if (
$iteminfo['itemname'] == "")
        {
         
             
$error "<span
                          onmouseover='return overlib(\""
rawurlencode('<span class="iname">Item not found!</span>') ."\", CAPTION, \"ERROR\", FGCOLOR, \"#FFFFFF\", CGCOLOR, \"#FF0000\", AUTOSTATUS);'
                          onmouseout='nd();'>Item Not Found</a>"
;
             return 
false;
             break;
          
        }
        if (
$received != "")
        {
            
$pophtml .= "<div class='wowitem'><span class='sm'><br> Looted by: " $received "</span></div>";
        }

        
$mypoptable sprintf($this->parent->wrappersprintf($this->parent->stats$iteminfo['itemnumber']), rawurlencode($pophtml), $style);

        if (
$img == "")
        {
            
$mypoptable .= '[' $popname ']';
        }
        else
        {
            if (
$img == "__IMG__")
            {
               
$mypoptable .= "<img src='" $iteminfo['itemicon'] . "' border=0>";  
            }
            else
            {
               
$mypoptable .= "<img src='" $img "' border=0>"
            }
        }
        
        
$mypoptable .= '</a>';

        return 
$mypoptable;
    }
    
    function 
getitemid($wowitemname)
    {
        
$search urlencode(trim($wowitemname));
        
$page itemstats_read_url(sprintf($this->parent->search$search));
        foreach(
explode("\n"$page) AS $line) {
            
$line trim($line);
            if (
preg_match('(var g_pageInfo = \{type: .*?, typeId: (.*?), name: \'.*?\'\};)'$line$matches)) {
                
$itemid $matches[1];
            } elseif (
preg_match('(<div class="listview-void"><a href="/\?item=(.*?)">.*?</a>)'$line$matches)) {
                
$itemid $matches[1];
            }
            if (
$wowitemname == "Minor Healthstone") {
                
file_put_contents("debug.txt"print_r($matchestrue) . "\n" $page);
            }
//            if ($line == '["'. urldecode($search) .'"],') break;
        
}
        return 
$itemid;
    }
    
    function 
addIconLocal($icon) {
        return 
$this->parent->addIconLocal($icon);
    }
}

?>

Warning: require_once(/extensions/WoWItem/includes/wowiteminfobase.class) [function.require-once]: failed to open stream: No such file or directory in /home/.aardvarkkiln/theraven/sites/wowkoe.com/test/wiki/extensions/WoWItem/includes/sites/wowhead.php on line 7

Fatal error: require_once() [function.require]: Failed opening required '/extensions/WoWItem/includes/wowiteminfobase.class' (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.aardvarkkiln/theraven/sites/wowkoe.com/test/wiki/extensions/WoWItem/includes/sites/wowhead.php on line 7