public function lookup($url, $groupName, $filename, $isValidCallback, $maxCacheAge = 86400) { if (empty($groupName)) { throw new Exception("Cache group name cannot be empty"); } $cacheResult = new CacheResult(); // Check if a xml file of the person exists and if it is uptodate if ($this->cacheExists($groupName, $filename)) { $cacheAge = $this->getCacheAge($groupName, $filename); if ($cacheAge < $maxCacheAge) { $data = $this->retrieve($groupName, $filename); if (call_user_func($isValidCallback, $data)) { $cacheResult->data = $data; $cacheResult->cacheAge = $cacheAge; $cacheResult->usedCache = true; $cacheResult->oldCache = false; $cacheResult->success = true; } else { unset($data); $this->remove($groupName, $filename); } } } //If no old history file was found or it was invalid try to update it from auno.org if ($cacheResult->success !== true) { $data = xml::getUrl($url, 20); if (call_user_func($isValidCallback, $data)) { $cacheResult->data = $data; $cacheResult->cacheAge = 0; $cacheResult->usedCache = false; $cacheResult->oldCache = false; $cacheResult->success = true; } else { unset($data); } } //If the site was not responding or the data was invalid and a xml file exists get that one if ($cacheResult->success !== true && $this->cacheExists($groupName, $filename)) { $data = $this->retrieve($groupName, $filename); if (call_user_func($isValidCallback, $data)) { $cacheResult->data = $data; $cacheResult->cacheAge = $this->getCacheAge($groupName, $filename); $cacheResult->usedCache = true; $cacheResult->oldCache = true; $cacheResult->success = true; } else { unset($data); $this->remove($groupName, $filename); } } // if a new file was downloaded, save it in the cache if ($cacheResult->usedCache === false) { $this->store($groupName, $filename, $cacheResult->data); } return $cacheResult; }
private function lookup_url($url) { $playerbio = xml::getUrl($url); $xml = new stdClass(); // parsing of the player data $xml->firstname = xml::spliceData($playerbio, '<firstname>', '</firstname>'); $xml->name = xml::spliceData($playerbio, '<nick>', '</nick>'); $xml->lastname = xml::spliceData($playerbio, '<lastname>', '</lastname>'); $xml->level = xml::spliceData($playerbio, '<level>', '</level>'); $xml->breed = xml::spliceData($playerbio, '<breed>', '</breed>'); $xml->gender = xml::spliceData($playerbio, '<gender>', '</gender>'); $xml->faction = xml::spliceData($playerbio, '<faction>', '</faction>'); $xml->profession = xml::spliceData($playerbio, '<profession>', '</profession>'); $xml->prof_title = xml::spliceData($playerbio, '<profession_title>', '</profession_title>'); $xml->ai_rank = xml::spliceData($playerbio, '<defender_rank>', '</defender_rank>'); $xml->ai_level = xml::spliceData($playerbio, '<defender_rank_id>', '</defender_rank_id>'); $xml->guild_id = xml::spliceData($playerbio, '<organization_id>', '</organization_id>'); $xml->guild = xml::spliceData($playerbio, '<organization_name>', '</organization_name>'); $xml->guild_rank = xml::spliceData($playerbio, '<rank>', '</rank>'); $xml->guild_rank_id = xml::spliceData($playerbio, '<rank_id>', '</rank_id>'); return $xml; }
public function lookup($rk_num) { $serverstat = xml::getUrl("http://probes.funcom.com/ao.xml", 30); if ($serverstat == null) { return null; } $data = xml::spliceData($serverstat, "<dimension name=\"d{$rk_num}", "</dimension>"); if (!$data) { return null; } $obj = new ServerStatus(); preg_match("/locked=\"(0|1)\"/i", $data, $tmp); $obj->locked = $tmp[1]; preg_match("/<omni percent=\"([0-9.]+)\"\\/>/i", $data, $tmp); $obj->omni = $tmp[1]; preg_match("/<neutral percent=\"([0-9.]+)\"\\/>/i", $data, $tmp); $obj->neutral = $tmp[1]; preg_match("/<clan percent=\"([0-9.]+)\"\\/>/i", $data, $tmp); $obj->clan = $tmp[1]; preg_match("/<servermanager status=\"([0-9]+)\"\\/>/i", $data, $tmp); $obj->servermanager = $tmp[1]; preg_match("/<clientmanager status=\"([0-9]+)\"\\/>/i", $data, $tmp); $obj->clientmanager = $tmp[1]; preg_match("/<chatserver status=\"([0-9]+)\"\\/>/i", $data, $tmp); $obj->chatserver = $tmp[1]; preg_match("/display-name=\"(.+)\" loadmax/i", $data, $tmp); $obj->name = $tmp[1]; $data = xml::spliceMultiData($data, "<playfield", "/>"); foreach ($data as $hdata) { if (preg_match("/id=\"(.+)\" name=\"(.+)\" status=\"(.+)\" load=\"(.+)\" players=\"(.+)%\"/i", $hdata, $arr)) { $playfield = new stdClass(); $playfield->id = $arr[1]; $playfield->long_name = $arr[2]; $playfield->status = $arr[3]; $playfield->load = $arr[4]; $playfield->percent = $arr[5]; $obj->data[$arr[1]] = $playfield; } } return $obj; }