// connect to sql $cache = new wowhead_cache(); if ($id == null) { echo 'Faction ID not given.'; exit; } if ($mode == 'tooltip') { if (!($result = $cache->getFaction($id, $lang, true))) { $cache->close(); echo 'Faction "' . $id . '" not found in cache.'; exit; } else { echo stripslashes($result['tooltip']); } } elseif ($mode == 'rewards') { if (!($result = $cache->getFactionRewards($id, $lang))) { // gotta build the html $data = readURL(getDomain($lang) . '?faction=' . $id, false); $rLine = getRewardLine($data); if (!$rLine) { return false; } else { $items = array('hated' => array(), 'hostile' => array(), 'unfriendly' => array(), 'neutral' => array(), 'friendly' => array(), 'honored' => array(), 'revered' => array(), 'exalted' => array()); // loop through the results and extract each item while (preg_match("#\\{id:([0-9]{1,10}),name:'[0-9@]{1}(.+?)',(.+?),sourcemore:\\[\\{t:([0-9]{1,2}),ti:([0-9]{1,10}),n:'(.+?)',z:([0-9]{1,10})\\}\\],classs:([0-9]{1,2}),subclass:(.+?),standing:(.+?)}#", $rLine, $match)) { // gotta query wowhead for every item (this could take a while) $iData = readURL(getDomain($lang) . '?item=' . (string) $match[1] . '&xml'); if (!$iData) { return false; } $xml = simplexml_load_string($iData, 'SimpleXMLElement', LIBXML_NOCDATA);