public function fetch($chid, $usid, $apik) { $api_ret = $this->fetch_xml("/char/Notifications.xml.aspx", array("characterID" => $chid, "keyID" => $usid, "vCode" => $apik), 6 * 60 * 60); $this->Message = ""; // if (!$api_ret || !$this->cacheHit) // api does not support partial updates! wtf return $api_ret; if ($this->age < 30 * 60) { $this->Message = "will check for new notifications in " . niceTime(30 * 60 - $this->age); return $api_ret; } // 30 minute timer is just for the first update check, from there on you can check instantly, but that's not very nice... // also, i would have to preserve the initial time, which would be annoying. // try to update with new mails $new_notif = simple_api_retrieve("/char/Notifications.xml.aspx", array("characterID" => $chid, "keyID" => $usid, "vCode" => $apik)); if ($new_notif != null && !$new_notif->error) { // did it work? $api_upd = $new_notif->value; $newMessages = $api_upd->xpath("/eveapi/result/rowset[@name='notifications']/row"); $nm = count($newMessages); if ($nm > 0) { // new mails! $this->Message = "retrieved {$nm} new notification" . ($nm > 1 ? "s" : ""); // merge the old with the new, so it appears like a new one foreach ($this->api->xpath("/eveapi/result/rowset[@name='notifications']/row") as $row) { $newrow = $api_upd->result->rowset->addChild("row"); foreach ($row->attributes() as $name => $value) { $newrow->addAttribute($name, $value); } } $api_upd->cachedUntil = $this->api->cachedUntil; $this->api = $api_upd; } else { $this->Message = "retrieved notifications; no new messages found."; } } else { $this->Message = "api error occured while fetching new notifications."; // didn't work, oh well... } // update the DB with the new list of mails $this->api->currentTime = gmdate("Y-m-d H:i:s"); $this->cache->update($this->api); $this->APIInit($this->cache); return $this->LoadAPI(); }
function idLookup($link, $ids) { global $Db; if (!is_array($ids)) { $ids = array($ids); } else { $ids = array_unique($ids); } $names = array(); // first try to look up cached values in the DB $sql = "SELECT * FROM " . DB_PREFIX . ID_CACHE_TABLE . " WHERE id IN (" . implode(",", $ids) . ")"; $result = mysql_query($sql, $link); if ($result != false) { if (mysql_num_rows($result) > 0) { // add any found to the list while ($row = mysql_fetch_assoc($result)) { $names[$row['id']] = $row['name']; } } mysql_free_result($result); } if (count($names) == count($ids)) { return $names; } // all names were cached! $list = array(); foreach ($ids as $id) { // make a list of ids which were not cached if (!isset($names[$id])) { $list[] = $id; } } $result = simple_api_retrieve('/eve/CharacterName.xml.aspx', array('ids' => implode(",", $list))); if (!$result) { return false; } // get the ids... if ($result->error) { // ccp sucks, look it up by divide and conquer return ass_idLookup($link, $list, $names); } $sql_ins = ""; foreach ($result->value->xpath('//row') as $kvp) { // add them to the array and make an insert query $names[(int) $kvp['characterID']] = (string) $kvp['name']; $sql_ins .= "(" . $kvp['characterID'] . ",'" . addslashes($kvp['name']) . "'),"; } mysql_query("INSERT INTO " . DB_PREFIX . ID_CACHE_TABLE . " (id, name) VALUES " . rtrim($sql_ins, ","), $link); // insert the new values into cache return $names; }
function idLookup($link, $ids) { global $Db; if (!is_array($ids)) { $ids = array($ids); } else { $ids = array_unique($ids); } if (empty($ids)) { return null; } $names = array(); // first try to look up cached values in the DB $result = $Db->selectWhere(ID_CACHE_TABLE, ['id' => ['IN', $ids]]); if ($result != false) { if ($result->rows) { // add any found to the list foreach ($result->results as $row) { $names[$row['id']] = $row['name']; } } } if (count($names) == count($ids)) { return $names; } // all names were cached! $list = array(); foreach ($ids as $id) { // make a list of ids which were not cached if (!isset($names[$id])) { $list[] = $id; } } $result = simple_api_retrieve('/eve/CharacterName.xml.aspx', array('ids' => implode(",", $list))); if (!$result) { return false; } // get the ids... if ($result->error) { return char_idLookup($Db, $list, $names); } $insertStatement = $Db->prepare()->insert(ID_CACHE_TABLE, ["id" => "?", "name" => "?"]); foreach ($result->value->xpath('//row') as $kvp) { // add them to the array and make an insert query $names[(int) $kvp['characterID']] = (string) $kvp['name']; $insertStatement->execute([$kvp['characterID'], $kvp['name']]); } return $names; }