/** * Parses itemset bbcode * @access public **/ 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); $cache = new wowhead_cache(); if (!($result = $cache->getItemset($name, $this->lang))) { if (!is_numeric($name)) { $data = $this->_read_url($name, 'itemset', false); if (!preg_match('#Location: /\\?itemset=([\\-0-9]{1,10})#s', $data, $match)) { // didn't find the redirect header, so we'll have to look in the search page $summary = $this->summaryLine($data); if (!preg_match('#id:([\\-0-9]{1,10}),name:#s', $summary, $match)) { $cache->close(); return $this->_notFound($this->language->words['itemset'], $name); } } } // we now have the set id, and can query wowhead for the info we need $this->setid = is_numeric($name) ? $name : $match[1]; $data = $this->_read_url($this->setid, 'itemset', false); // if they used ID rather than name, then we must get the name if (is_numeric($name)) { if (!preg_match('#name: \'(.+?)\'};#s', $this->nameLine($data), $match)) { $cache->close(); return $this->_notFound($this->language->words['itemset'], $name); } else { $found_name = stripslashes($match[1]); } } $this->itemset = array('setid' => $this->setid, 'name' => is_numeric($name) ? $found_name : $name, 'search_name' => $name, 'lang' => $this->lang); $summary = $this->summaryLine($data); while (preg_match('#\\[\\[([0-9]{1,10})\\]\\]#s', $summary, $match)) { $data = $this->_read_url($match[1]); if (trim($data) == '' || empty($data)) { return false; } // 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 == '') { // add the results to our item array array_push($this->itemset_items, array('setid' => $this->setid, 'itemid' => (int) $xml->item['id'], 'name' => (string) $xml->item->name, 'quality' => (int) $xml->item->quality['id'], 'icon' => 'http://static.wowhead.com/images/icons/small/' . strtolower($xml->item->icon) . '.jpg')); } else { return false; } unset($xml); // strip what it found so we don't get an endless loop $summary = str_replace($match[0], '', $summary); } $cache->saveItemset($this->itemset, $this->itemset_items); $cache->close(); return $this->toHTML(); } else { $this->itemset = $result; $this->itemset_items = $cache->getItemsetReagents($this->itemset['setid']); $cache->close(); return $this->toHTML(); } }