/** * Get an image. * * Returns an image resource or false on failure. Fetches the image from * CCP if needed. * @param integer $id * @param integer $size * @return resource Image resource or false on failure. */ static function get($id, $size = 64) { $id = (int) $id; $size = (int) $size; if ($size != 32 && $size != 64) { return false; } if (!$id) { return imagecreatefromjpeg("img/portrait_0_{$size}.jpg"); } // If it's in the cache then read it from there. if (CacheHandler::exists("{$id}_{$size}.png", "img")) { return imagecreatefrompng(CacheHandler::getInternal("{$id}_{$size}.png", "img")); } else { $img = self::fetchImage($id, $size); imagepng($img, CacheHandler::getInternal("{$id}_{$size}.png", "img")); return $img ? $img : imagecreatefromjpeg("img/portrait_0_{$size}.jpg"); } }
/** * Return the URL for the alliance's portrait. If the alliance has a * portrait in the board's img/alliances directory, that portrait will be * used * * @param integer $size The desired portrait size. * @return string URL for a portrait. */ function getPortraitURL($size = 128) { if (isset($this->imgurl[$size])) { return $this->imgurl[$size]; } if (file_exists("img/alliances/" . $this->getUnique() . ".png")) { if ($size == 128) { $this->imgurl[$size] = IMG_HOST . "/img/alliances/" . $this->getUnique() . ".png"; } else { if (CacheHandler::exists($this->getUnique() . "_{$size}.png", 'img')) { $this->imgurl[$size] = KB_HOST . "/" . CacheHandler::getExternal($this->getUnique() . "_{$size}.png", 'img'); } else { $this->imgurl[$size] = KB_HOST . '/?a=thumb&type=alliance&id=' . $this->getUnique() . '&size=' . $size; } } $this->putCache(); } else { if ($this->getExternalID()) { $this->imgurl[$size] = imageURL::getURL('Alliance', $this->getExternalID(), $size); $this->putCache(); } else { $this->imgurl[$size] = imageURL::getURL('Alliance', 1, $size); } } return $this->imgurl[$size]; }
// If we still don't have an external ID then just use the internal for names. if (!$plt_ext_id) { $plt_ext_id = $plt_id; } if (!$pilot->exists()) { errorPic('That pilot doesnt exist.'); } $corp = $pilot->getCorp(); $alliance = $corp->getAlliance(); // we dont generate pictures for non-members if (array_search($alliance->getID(), config::get('cfg_allianceid')) === false && !array_search($corp->getID(), config::get('cfg_corpid')) === false && !array_search($pilot->getID(), config::get('cfg_pilotid')) === false) { errorPic('Invalid pilot'); } $id = abs(crc32($sig_name)); // check for cached version if (file_exists(CacheHandler::exists("{$plt_ext_id}_sig_{$id}.jpg", 'img'))) { // cache files for 120 minutes if (time() - CacheHandler::age("{$plt_ext_id}_sig_{$id}.jpg", 'img') < 120 * 60 || lastKill($plt_id) > 120 * 60) { if (isset($_SERVER['HTTP_IF_NONE_MATCH']) || isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header($_SERVER["SERVER_PROTOCOL"] . " 304 Not Modified"); die; } else { header('Content-Type: image/jpeg'); readfile(CacheHandler::get("{$plt_ext_id}_sig_{$id}.jpg", 'img')); die; } } } $pid = $pilot->getExternalID(); $cachePath = $pilot->getPortraitPath(256); $thumb = new thumb($pid, 256);
/** * * @param KillList $killList * @return string KillList as XML */ public static function killListToXML($killList) { global $idfeedversion; $qry = DBFactory::getDBQuery(); $date = gmdate('Y-m-d H:i:s'); $xml = "<?xml version='1.0' encoding='UTF-8'?>\n\t\t<eveapi version='2' edkapi='" . $idfeedversion . "'>\n\t\t</eveapi>"; $sxe = new SimpleXMLElement($xml); // Let's start making the xml. $sxe->addChild('currentTime', $date); $result = $sxe->addChild('result'); $kills = $result->addChild('rowset'); $kills->addAttribute('name', 'kills'); $kills->addAttribute('key', 'killID'); $kills->addAttribute('columns', 'killID,solarSystemID,killTime,moonID,hash,trust'); $count = 0; $timing = ''; while ($kill = $killList->getKill()) { if (config::get('km_cache_enabled') && CacheHandler::exists($kill->getID() . ".xml", 'mails')) { $cachedRow = new SimpleXMLElement(CacheHandler::get($kill->getID() . ".xml", 'mails')); IDFeed::addXMLElement($kills, $cachedRow); continue; } $count++; if ($kill->isClassified()) { continue; } //$kill = Kill::getByID($kill->getID()); $row = $kills->addChild('row'); $row->addAttribute('killID', intval($kill->getExternalID())); $row->addAttribute('killInternalID', intval($kill->getID())); $row->addAttribute('solarSystemID', $kill->getSystem()->getExternalID()); $row->addAttribute('killTime', $kill->getTimeStamp()); $row->addAttribute('moonID', '0'); $row->addAttribute('hash', bin2hex(IDFeed::getHash($kill, true))); $row->addAttribute('trust', 3); $victim = Pilot::getByID($kill->getVictimID()); $victimCorp = Corporation::getByID($kill->getVictimCorpID()); $victimAlliance = Alliance::getByID($kill->getVictimAllianceID()); $victimrow = $row->addChild('victim'); if ($victim->getName() == $kill->getVictimShipName()) { $victimrow->addAttribute('characterID', "0"); $victimrow->addAttribute('characterName', ""); } else { $victimrow->addAttribute('characterID', $victim->getExternalID()); $victimrow->addAttribute('characterName', $victim->getName()); } $victimrow->addAttribute('corporationID', $victimCorp->getExternalID()); $victimrow->addAttribute('corporationName', $victimCorp->getName()); if ($victimAlliance->isFaction()) { $victimrow->addAttribute('allianceID', 0); $victimrow->addAttribute('allianceName', ''); $victimrow->addAttribute('factionID', $victimAlliance->getFactionID()); $victimrow->addAttribute('factionName', $victimAlliance->getName()); } else { $victimrow->addAttribute('allianceID', $victimAlliance->getExternalID()); $victimrow->addAttribute('allianceName', $victimAlliance->getName()); $victimrow->addAttribute('factionID', 0); $victimrow->addAttribute('factionName', ''); } $victimrow->addAttribute('damageTaken', $kill->getDamageTaken()); $victimrow->addAttribute('shipTypeID', $kill->getVictimShipExternalID()); $involved = $row->addChild('rowset'); $involved->addAttribute('name', 'attackers'); $involved->addAttribute('columns', 'characterID,characterName,corporationID,corporationName,allianceID,allianceName,factionID,factionName,securityStatus,damageDone,finalBlow,weaponTypeID,shipTypeID'); $sql = "SELECT ind_sec_status, ind_all_id, ind_crp_id,\n\t\t\t\tind_shp_id, ind_wep_id, ind_order, ind_dmgdone, plt_id, plt_name,\n\t\t\t\tplt_externalid, crp_name, crp_external_id,\n\t\t\t\twtype.typeName AS wep_name FROM kb3_inv_detail\n\t\t\t\tJOIN kb3_pilots ON (plt_id = ind_plt_id)\n\t\t\t\tJOIN kb3_corps ON (crp_id = ind_crp_id)\n\t\t\t\tJOIN kb3_invtypes wtype ON (ind_wep_id = wtype.typeID)\n\t\t\t\tWHERE ind_kll_id = " . $kill->getID() . " ORDER BY ind_order ASC"; $qry->execute($sql); while ($inv = $qry->getRow()) { $invrow = $involved->addChild('row'); if (strpos($inv['plt_name'], '- ') !== false) { $inv['plt_name'] = substr($inv['plt_name'], strpos($inv['plt_name'], '- ') + 2); } else { if (strpos($inv['plt_name'], '#') !== false) { $name = explode("#", $inv['plt_name']); $inv['plt_name'] = $name[3]; } } if ($inv['plt_name'] == $inv['wep_name']) { $invrow->addAttribute('characterID', 0); $invrow->addAttribute('characterName', ""); $invrow->addAttribute('weaponTypeID', 0); $invrow->addAttribute('shipTypeID', $inv['ind_wep_id']); } else { $invrow->addAttribute('characterID', $inv['plt_externalid']); $invrow->addAttribute('characterName', $inv['plt_name']); $invrow->addAttribute('weaponTypeID', $inv['ind_wep_id']); $invrow->addAttribute('shipTypeID', $inv['ind_shp_id']); } $invrow->addAttribute('corporationID', $inv['crp_external_id']); $invrow->addAttribute('corporationName', $inv['crp_name']); $invAlliance = Alliance::getByID($inv['ind_all_id']); if ($invAlliance->isFaction()) { $invrow->addAttribute('allianceID', 0); $invrow->addAttribute('allianceName', ''); $invrow->addAttribute('factionID', $invAlliance->getFactionID()); $invrow->addAttribute('factionName', $invAlliance->getName()); } else { if (strcasecmp($invAlliance->getName(), "None") == 0) { $invrow->addAttribute('allianceID', 0); $invrow->addAttribute('allianceName', ""); } else { $invrow->addAttribute('allianceID', $invAlliance->getExternalID()); $invrow->addAttribute('allianceName', $invAlliance->getName()); } $invrow->addAttribute('factionID', 0); $invrow->addAttribute('factionName', ''); } $invrow->addAttribute('securityStatus', number_format($inv['ind_sec_status'], 1)); $invrow->addAttribute('damageDone', $inv['ind_dmgdone']); if ($inv['plt_id'] == $kill->getFBPilotID()) { $final = 1; } else { $final = 0; } $invrow->addAttribute('finalBlow', $final); } $sql = "SELECT * FROM kb3_items_destroyed WHERE itd_kll_id = " . $kill->getID(); $qry->execute($sql); $qry2 = DBFactory::getDBQuery(); $sql = "SELECT * FROM kb3_items_dropped WHERE itd_kll_id = " . $kill->getID(); $qry2->execute($sql); if ($qry->recordCount() || $qry2->recordCount()) { $items = $row->addChild('rowset'); $items->addAttribute('name', 'items'); $items->addAttribute('columns', 'typeID,flag,qtyDropped,qtyDestroyed, singleton'); while ($iRow = $qry->getRow()) { $itemRow = $items->addChild('row'); $itemRow->addAttribute('typeID', $iRow['itd_itm_id']); $itemRow->addAttribute('flag', $iRow['itd_itl_id']); if ($iRow['itd_itl_id'] == -1) { $itemRow->addAttribute('singleton', 2); } else { $itemRow->addAttribute('singleton', 0); } $itemRow->addAttribute('qtyDropped', 0); $itemRow->addAttribute('qtyDestroyed', $iRow['itd_quantity']); } while ($iRow = $qry2->getRow()) { $itemRow = $items->addChild('row'); $itemRow->addAttribute('typeID', $iRow['itd_itm_id']); $itemRow->addAttribute('flag', $iRow['itd_itl_id']); if ($iRow['itd_itl_id'] == -1) { $itemRow->addAttribute('singleton', 2); } else { $itemRow->addAttribute('singleton', 0); } $itemRow->addAttribute('qtyDropped', $iRow['itd_quantity']); $itemRow->addAttribute('qtyDestroyed', 0); } } if (config::get('km_cache_enabled')) { CacheHandler::put($kill->getID() . ".xml", $row->asXML(), 'mails'); } $timing .= $kill->getID() . ": " . (microtime(true) - $starttime) . "<br />"; } $sxe->addChild('cachedUntil', $date); return $sxe->asXML(); }
function goType($type, $id, $size = 64, $imghost = "") { if ($size != 32 && $size != 64 && $size != 24 && $size != 48 && !($type == "ship" && ($size == 256 || ($size = 512)))) { show404(); } if ($id == 0) { if ($size == 32 || $size == 64 || $size == 128 || $size == 256) { header("Location: {$imghost}img/portrait_0_{$size}.jpg"); } else { header("Location: {$imghost}img/portrait_0_64.jpg"); } die; } define('KB_CACHEDIR', 'cache'); require_once "common/includes/class.cachehandler.php"; // If it's in the cache then read it from there. if (CacheHandler::exists("{$id}_{$size}.png", "img")) { expiryHeaders("png", CacheHandler::getInternal("{$id}_{$size}.png", "img")); readfile(CacheHandler::getInternal("{$id}_{$size}.png", "img")); die; } //TODO: add an optional memcache backed by the filecache //Ships are available at 256 and 512 if ($type == 'ship' && $size > 64) { $img = fetchImage($id, "Render", $size, "png"); } else { if ($size > 32) { if (CacheHandler::exists("{$id}_64.png", "img")) { $img = imagecreatefrompng(CacheHandler::getInternal("{$id}_64.png", "img")); } else { $img = fetchImage($id, "InventoryType", 64, "png"); } if ($img && $size != 64) { resize($size, 64, $img, CacheHandler::getInternal("{$id}_{$size}.png", "img")); } } else { if (CacheHandler::exists("{$id}_32.png", "img")) { $img = imagecreatefrompng(CacheHandler::getInternal("{$id}_32.png", "img")); } else { $img = fetchImage($id, "InventoryType", 32, "png"); } if ($img && $size != 32) { resize($size, 32, $img, CacheHandler::getInternal("{$id}_{$size}.png", "img")); } } } if (!$img) { show404(); } expiryHeaders("png", CacheHandler::getInternal("{$id}_{$size}.png", "img")); readfile(CacheHandler::getInternal("{$id}_{$size}.png", "img")); die; }
function genCorp() { $source = 'img/corps/' . $this->id . '.png'; // id matches an npc image. if (file_exists($source)) { $img = imagecreatefrompng($source); } else { if (CacheHandler::exists($this->id . '_128.png', $this->thumbDir)) { $img = imagecreatefrompng(CacheHandler::getInternal($this->id . '_128.png', $this->thumbDir)); } else { $img = $this->fetchImage('Corporation', 128); if ($this->size == 128 && $img) { return true; } } } if ($img) { $newimg = imagecreatetruecolor($this->size, $this->size); $color = imagecolortransparent($newimg, imagecolorallocatealpha($newimg, 0, 0, 0, 127)); imagefill($newimg, 0, 0, $color); imagesavealpha($newimg, true); $oldx = imagesx($img); $oldy = imagesy($img); imagecopyresampled($newimg, $img, 0, 0, 0, 0, $this->size, $this->size, $oldx, $oldy); $this->thumb = CacheHandler::getInternal($this->id . '_' . $this->size . '.png', $this->thumbDir); imagepng($newimg, $this->thumb); } else { return false; } return true; }