public function parse($name, $args = array()) { if (trim($name) == '') { return false; } $this->lang = !array_key_exists('lang', $args) ? WHP_LANG : $args['lang']; $this->language->loadLanguage($this->lang); // load the language pack $this->nomats = !array_key_exists('nomats', $args) ? false : $args['nomats']; $cache = new wowhead_cache(); if (!($result = $cache->getCraftable($name, $this->lang))) { $data = $this->_read_url($name, 'craftable'); // accounts for SimpleXML not being able to handle 3 parameters if you're using PHP 5.1 or below. if (!$this->_allowSimpleXMLOptions()) { $data = $this->_removeCData($data); $xml = simplexml_load_string($data, 'SimpleXMLElement'); } else { $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); } if ($xml->error == '') { // build our craft array $this->craft = array('itemid' => $xml->item['id'], 'name' => $xml->item->name, 'search_name' => $name, 'quality' => $xml->item->quality['id'], 'lang' => $this->lang, 'icon' => 'http://static.wowhead.com/images/icons/small/' . strtolower($xml->item->icon) . '.jpg'); // build spell craft array $this->craft_spell = array('reagentof' => $xml->item['id'], 'spellid' => $xml->item->createdBy->spell['id'], 'name' => $xml->item->createdBy->spell['name']); if ($this->nomats == false) { // build reagent array foreach ($xml->item->createdBy->spell->reagent as $reagent) { array_push($this->craft_reagents, array('itemid' => $reagent['id'], 'reagentof' => $xml->item['id'], 'name' => $reagent['name'], 'quantity' => $reagent['count'], 'quality' => $reagent['quality'], 'icon' => 'http://static.wowhead.com/images/icons/small/' . strtolower($reagent['icon']) . '.jpg')); } } } else { $cache->close(); return $this->_notfound($this->language->words['craft'], $name); } if ($this->nomats == false) { $cache->saveCraftable($this->craft, $this->craft_spell, $this->craft_reagents); } else { $cache->saveCraftable($this->craft, $this->craft_spell); } unset($xml); $cache->close(); return $this->_toHTML(); } else { $this->craft = $result; $this->craft_spell = $cache->getCraftableSpell($this->craft['itemid']); if ($this->nomats == false) { $this->craft_reagents = $cache->getCraftableReagents($this->craft['itemid']); } $cache->close(); return $this->_toHTML(); } }