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->getNPC($name, $this->lang))) { // not found in cache $result = $this->getNPCInfo($name); if (!$result) { // not found $cache->close(); return $this->_notFound($this->language->words['npc'], $name); } else { // see if they want to display a map as well if (array_key_exists('map', $args)) { if (!($sql_map = $cache->getZone($args['map']['name'], $this->lang))) { $mapinfo = $this->getZoneMap($args['map']['name']); if (!$mapinfo) { $cache->close(); return $this->_notFound($this->language->words['zone'], $name); } else { if (!file_exists($this->images_path . $mapinfo['map']) && WHP_TRANSFER_MAP == true) { // file doesn't exist, so transfer it locally $this->transferImage($mapinfo['map']); } $cache->saveZone($mapinfo); $mapinfo['x'] = $args['map']['x']; $mapinfo['y'] = $args['map']['y']; $cache->saveNPC($result); $cache->close(); return $this->mapHTML($result, $mapinfo); } } else { if (!file_exists($this->images_path . $sql_map['map']) && WHP_TRANSFER_MAP == true) { // file doesn't exist, so transfer it locally $this->transferImage($sql_map['map']); } $sql_map['x'] = $args['map']['x']; $sql_map['y'] = $args['map']['y']; $cache->saveNPC($result); $cache->close(); return $this->mapHTML($result, $sql_map); } } else { // found, save it and display $cache->saveNPC($result); $cache->close(); return $this->generateHTML($result, 'npc'); } } } else { if (array_key_exists('map', $args)) { $mapinfo = $cache->getZone($args['map']['name'], $this->lang); if (!file_exists($this->images_path . $mapinfo['map']) && WHP_TRANSFER_MAP == true) { // file doesn't exist, so transfer it locally $this->transferImage($mapinfo['map']); } $mapinfo['x'] = $args['map']['x']; $mapinfo['y'] = $args['map']['y']; $cache->close(); return $this->mapHTML($result, $mapinfo); } else { $cache->close(); return $this->generateHTML($result, 'npc'); } } }