function generate() { global $smarty; $this->toplist->generate(); $i = 1; $rows = array(); while ($row = $this->toplist->getRow()) { $pilot = Pilot::getByID($row['plt_id']); $uri = edkURI::build(array('a', 'kill_detail', true), array('kll_id', $row['kll_id'], true)); if ($row['plt_externalid']) { $img = imageURL::getURL('Pilot', $row['plt_externalid'], 32); } else { $img = $pilot->getPortraitURL(32); } $ship = Ship::getByID($row['ship']); $shipUri = edkURI::build(array('a', 'invtype', true), array('id', $row['ship'], true)); if ((int) number_format($row["isk"], 0, "", "") > 1000000000) { $isk = number_format($row["isk"] / 1000000000, 2, ".", "") . " b"; } elseif ((int) number_format($row["isk"], 0, "", "") > 1000000) { $isk = number_format($row["isk"] / 1000000, 2, ".", "") . " M"; } else { $isk = number_format($row["isk"], 0, ".", ","); } $rows[] = array('rank' => $i, 'name' => $pilot->getName(), 'uri' => $uri, 'portrait' => $img, 'shipImage' => $ship->getImage(32), 'shipName' => $ship->getName(), 'shipId' => $row['ship'], 'shipURI' => $shipUri, 'isk' => $isk); $i++; } $smarty->assign('tl_name', 'Pilot'); $smarty->assign('tl_type', $this->entity_); $smarty->assignByRef('tl_rows', $rows); return $smarty->fetch(getcwd() . '/mods/most_expensive_toplist/templates/toplisttable_expensive.tpl'); }
function generate() { global $smarty; $this->toplist->generate(); $i = 1; $rows = array(); while ($row = $this->toplist->getRow()) { $pilot = Pilot::getByID($row['plt_id']); if ($row['plt_externalid']) { $uri = edkURI::build(array('a', 'pilot_detail', true), array('plt_ext_id', $row['plt_externalid'], true)); $img = imageURL::getURL('Pilot', $row['plt_externalid'], 32); } else { $uri = edkURI::build(array('a', 'pilot_detail', true), array('plt_id', $row['plt_id'], true)); $img = $pilot->getPortraitURL(32); } $rows[] = array('rank' => $i, 'name' => $pilot->getName(), 'uri' => $uri, 'portrait' => $img, 'count' => $row['cnt']); $i++; } $smarty->assign('tl_name', 'Pilot'); $smarty->assign('tl_type', $this->entity_); $smarty->assignByRef('tl_rows', $rows); return $smarty->fetch(get_tpl('toplisttable')); }
/** * Add a new pilot to the database or update the details of an existing one. * * @param string $name Pilot name * @param Corporation $corp Corporation object for this pilot's corporation * @param string $timestamp time this pilot's corp was updated * @param integer $externalID CCP external id * @param boolean $loadExternals Whether to check for an external ID * @return Pilot */ public static function add($name, $corp, $timestamp, $externalID = 0, $loadExternals = true) { if (!$name) { trigger_error("Attempt to add a pilot with no name. Aborting.", E_USER_ERROR); // If things are going this wrong, it's safer to die and prevent more harm die; } else { if (!$corp->getID()) { trigger_error("Attempt to add a pilot ({$name}) with no corp ({$corp}). Aborting.", E_USER_ERROR); // If things are going this wrong, it's safer to die and prevent more harm die; } } // Check if pilot exists with a non-cached query. $qry = DBFactory::getDBQuery(true); $name = stripslashes($name); // Insert or update a pilot with a cached query to update cache. $qryI = DBFactory::getDBQuery(true); $qry->execute("SELECT * FROM kb3_pilots WHERE plt_name = '" . $qry->escape($name) . "'"); if (!$qry->recordCount()) { $externalID = (int) $externalID; // If no external id is given then look it up. if (!$externalID && $loadExternals) { $myID = new API_NametoID(); $myID->setNames($name); $myID->fetchXML(); $myNames = $myID->getNameData(); $externalID = (int) $myNames[0]['characterID']; } // If we have an external id then check it isn't already in use. // If we find it then update the old corp with the new name and // return. if ($externalID) { $qry->execute("SELECT * FROM kb3_pilots WHERE plt_externalid = " . $externalID); if ($qry->recordCount()) { $row = $qry->getRow(); $pilot = Pilot::getByID($row['plt_id']); $qryI->execute("UPDATE kb3_pilots SET plt_name = '" . $qry->escape($name) . "' WHERE plt_externalid = " . $externalID); if ($qryI->affectedRows() > 0) { Cacheable::delCache($pilot); } $qryI->execute("UPDATE kb3_pilots SET plt_crp_id = " . $corp->getID() . ", plt_updated = " . "date_format( '" . $timestamp . "', '%Y.%m.%d %H:%i:%s') WHERE plt_externalid = " . $externalID . " AND plt_crp_id <> " . $corp->getID() . " AND ( plt_updated < date_format( '" . $timestamp . "', '%Y-%m-%d %H:%i') OR plt_updated is null )"); if ($qryI->affectedRows() > 0) { Cacheable::delCache($pilot); } return $pilot; } } $qry->execute("INSERT INTO kb3_pilots (plt_name, plt_crp_id, " . "plt_externalid, plt_updated) values ('" . $qry->escape($name) . "', " . $corp->getID() . ",\t" . $externalID . ",\n\t\t\t\t\tdate_format( '" . $timestamp . "', '%Y.%m.%d %H:%i:%s'))\n\t\t\t\t\tON DUPLICATE KEY UPDATE plt_crp_id=" . $corp->getID() . ",\n\t\t\t\t\tplt_externalid=" . $externalID . ",\n\t\t\t\t\tplt_updated=date_format( '" . $timestamp . "', '%Y.%m.%d %H:%i:%s')"); return new Pilot($qry->getInsertID(), $externalID, $name, $corp->getID()); } else { // Name found. $row = $qry->getRow(); $id = $row['plt_id']; if (!is_null($row['plt_updated'])) { $updated = strtotime($row['plt_updated'] . " UTC"); } else { $updated = 0; } if ($updated < strtotime($timestamp . " UTC") && $corp->getID() != $row['plt_crp_id']) { $qryI->execute("UPDATE kb3_pilots SET plt_crp_id = " . $corp->getID() . ", plt_updated = '" . $timestamp . "' WHERE plt_name = '" . $qry->escape($name) . "'" . " AND plt_crp_id <> " . $corp->getID() . " AND ( plt_updated < '" . $timestamp . "' OR plt_updated is null )"); } $plt = new Pilot($id, $externalID, $name, $corp); if (!$row['plt_externalid'] && $externalID) { $plt->executed = true; $plt->setCharacterID($externalID); } return $plt; } }
/** * * @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(); }
/** * Generates the menu for the user * @return string */ public static function menu() { $box = new Box('User'); $box->setIcon('menu-item.gif'); if (!user::loggedin()) { $box->addOption('link', 'Login', edkURI::build(array('a', 'login', true))); $box->addOption('link', 'Register', edkURI::build(array('a', 'register', true))); } else { if (user::get('usr_pilot_id')) { $plt = Pilot::getByID((int) user::get('usr_pilot_id')); $box->addOption('link', $plt->getName(), edkURI::build(array('a', 'pilot_detail', true), array('plt_id', $plt->getID(), true))); } $box->addOption('link', 'Logout', edkURI::build(array('a', 'logout', true))); } event::call('user_menu_create', $box); return $box->generate(); }
function involvedSetup() { global $smarty; $fetchExternalIDs = array(); // involved $i = 1; $this->involved = array(); $this->ownKill = false; $invlimit = config::get('kd_involvedlimit'); if (!is_numeric($invlimit)) { $this->nolimit = 1; } foreach ($this->kill->getInvolved() as $inv) { $corp = Corporation::getByID($inv->getCorpID()); $alliance = Alliance::getByID($inv->getAllianceID()); $ship = Ship::getByID($inv->getShipID()); $alliance_name = $alliance->getName(); if (!isset($this->invAllies[$alliance_name])) { $this->invAllies[$alliance_name] = array('quantity' => 1, 'corps' => array()); } else { $this->invAllies[$alliance_name]["quantity"] += 1; } $corp_name = $corp->getName(); if (!isset($this->invAllies[$alliance_name]["corps"][$corp_name])) { $this->invAllies[$alliance_name]["corps"][$corp_name] = 1; } else { $this->invAllies[$alliance_name]["corps"][$corp_name] += 1; } $ship_name = $ship->getName(); if (!isset($this->invShips[$ship_name])) { $this->invShips[$ship_name] = 1; } else { $this->invShips[$ship_name] += 1; } if (in_array($alliance->getID(), config::get('cfg_allianceid'))) { $this->ownKill = true; } else { if (in_array($corp->getID(), config::get('cfg_corpid'))) { $this->ownKill = true; } else { if (in_array($inv->getPilotID(), config::get('cfg_pilotid'))) { $this->ownKill = true; } } } if (!$this->nolimit && $i > $invlimit) { if ($i == $invlimit + 1) { $smarty->assign('limited', true); $smarty->assign('moreInvolved', $this->kill->getInvolvedPartyCount() - $invlimit); $smarty->assign('unlimitURL', '?' . htmlentities($_SERVER['QUERY_STRING']) . '&nolimit'); } } $pilot = Pilot::getByID($inv->getPilotID()); $weapon = Item::getByID($inv->getWeaponID()); $record = array(); $record['shipImage'] = $ship->getImage(64); $record['shipName'] = $ship->getName(); $record['shipID'] = $ship->getID(); if ($ship->getID()) { $record['shipURL'] = edkURI::page('invtype', $ship->getID()); $record['shipClass'] = $ship->getClass()->getName(); } else { $record['shipURL'] = false; $record['shipClass'] = false; } $record['corpURL'] = edkURI::build(array('a', 'corp_detail', true), array('crp_id', $corp->getID(), true)); $record['corpName'] = $corp->getName(); if ($alliance && strcasecmp($alliance->getName(), "None") != 0) { $record['alliURL'] = edkURI::build(array('a', 'alliance_detail', true), array('all_id', $alliance->getID(), true)); } else { $record['alliURL'] = false; } $record['alliName'] = $alliance->getName(); $record['damageDone'] = $inv->getDamageDone(); //detects NPC type things and runs a few conversions (Rats, Towers, Bubbles) $tpilot = $pilot->getName(); if (preg_match("/-/", $tpilot)) { // a tower or bubble. But! Since we have placed the corp name in front of the // item's name, we need to quickly check which base item it was again. $namestart = strripos($tpilot, '-') + 2; //we're interested in the last dash $tpilot = substr($tpilot, $namestart); } if (!$pilot->getID() || $tpilot == $weapon->getName()) { $record['pilotURL'] = edkURI::page('invtype', $weapon->getID()); $record['pilotName'] = $weapon->getName(); $record['secStatus'] = 0; $record['portrait'] = $corp->getPortraitURL(64); $record['externalID'] = $corp->getExternalID(true); if ($record['externalID'] == 0) { $fetchExternalIDs[] = $corp->getName(); } $record['typeID'] = 2; //type number for corporations. $record['pilotURL'] = edkURI::page('invtype', $weapon->getID()); $record['shipImage'] = imageURL::getURL('Ship', $weapon->getID(), 64); $record['shipURL'] = false; $record['shipName'] = $weapon->getName(); $record['weaponURL'] = false; $record['weaponID'] = false; $record['weaponName'] = "Unknown"; } else { if ($pilot->getExternalID(true)) { $record['pilotURL'] = edkURI::build(array('a', 'pilot_detail', true), array('plt_ext_id', $pilot->getExternalID(), true)); } else { $record['pilotURL'] = edkURI::build(array('a', 'pilot_detail', true), array('plt_id', $pilot->getID(), true)); } $record['typeID'] = 1377; //type number for characters. $record['pilotName'] = $pilot->getName(); $record['secStatus'] = $inv->getSecStatus(); $record['portrait'] = $pilot->getPortraitURL(64); $record['externalID'] = $pilot->getExternalID(true); //get the external ID from the pilot class - if not found then add it to a list of pilots //and check the api in bulk if (!$record['externalID']) { $fetchExternalIDs[] = $pilot->getName(); } if ($weapon->getName() != "Unknown" && $weapon->getName() != $ship->getName()) { $record['weaponName'] = $weapon->getName(); $record['weaponID'] = $weapon->getID(); $record['weaponURL'] = edkURI::page('invtype', $weapon->getID()); } else { $record['weaponName'] = "Unknown"; } } $setOtherInvolved = true; if ($inv->getPilotID() == $this->kill->getFBPilotID()) { //Final Blow pilot $this->finalblow = $record; $setOtherInvolved = false; } if ($inv->getPilotID() == $this->kill->getTDPilotID()) { //Top Damage pilot $this->topdamage = $record; $setOtherInvolved = false; } if ($setOtherInvolved) { //other involved pilot $this->involved[] = $record; } ++$i; } //prod CCP for the entire list of names if (count($fetchExternalIDs) > 0) { $names = new API_NametoID(); $names->setNames(implode(',', $fetchExternalIDs)); $names->fetchXML(); $nameIDPair = $names->getNameData(); //fill in the pilot external IDs.. could potentially be slow //but it beats the alternative. Do nothing if no names need loading. if (count($nameIDPair) > 0) { foreach ($nameIDPair as $idpair) { //store the IDs $invovledPilots = $this->kill->getInvolved(); if (isset($this->finalblow)) { $invovledPilots[] = $this->finalblow; } if (isset($this->topdamage)) { $invovledPilots[] = $this->topdamage; } foreach ($invovledPilots as $inv) { $pilot = Cacheable::factory('Pilot', $inv->getPilotID()); $corp = Cacheable::factory('Corporation', $inv->getCorpID()); if ($idpair['name'] == $corp->getName()) { $corp->setExternalID($idpair['characterID']); } else { if ($idpair['name'] == $pilot->getName()) { $pilot->setCharacterID($idpair['characterID']); } } } //as we've already populated the structures for the template //we need to quickly retrofit it. foreach ($this->involved as $inv) { $pname = $inv['pilotName']; $cname = $inv['corpName']; if ($cname == $idpair['name']) { $inv['externalID'] = $idpair['characterID']; } else { if ($pname == $idpair['name']) { $inv['externalID'] = $idpair['characterID']; } } } //same for Final Blow/Top Damage if ($this->finalblow['corpName'] == $idpair['name'] && isset($this->finalblow)) { $this->finalblow['externalID'] = $idpair['characterID']; } else { if ($this->topdamage['pilotName'] == $idpair['name'] && isset($this->topdamage)) { $this->topdamage['externalID'] = $idpair['characterID']; } } } } } }
/** * tries to calculate the CREST hash using the external * ID and some specific kill information */ public function calculateCrestHash() { // we need the external kill ID if (!$this->getExternalID()) { return NULL; } $finalBlowPilotId = $this->getFBPilotID(); $finalBlowPilot = Pilot::getByID($finalBlowPilotId); $victimPilot = $this->getVictim(); $victimShip = $this->getVictimShip(); $time = $this->getTimeStamp(); // check for timestmap existance $defaultTimezone = date_default_timezone_get(); // set UTC as default timezone date_default_timezone_set('UTC'); $timestamp = strtotime($time); // restore default timezone date_default_timezone_set($defaultTimezone); if ($timestamp === FALSE || $timestamp < 0) { return NULL; } // check final blow pilot, victim pilot and victim ship if (!$finalBlowPilot || !$victimPilot || !$victimShip) { return NULL; } // prepare the ship type ID $shipTypeID = $victimShip->getID(); if (!$shipTypeID) { return NULL; } // prepare the victim's characterID $victimCharacterId = $victimPilot->getExternalID(); // make sure this is actually a real character ID; mustn be NULL, mustn't be less than 90M if (!$victimCharacterId || $victimCharacterId < 90000000) { $victimCharacterId = "None"; } // prepare the final blow pilot's characterID $finalBlowCharacterId = $finalBlowPilot->getExternalID(); // make sure this is actually a real character ID; mustn be NULL, mustn't be less than 90M // player characters are above 90M, Drifters are above 3M if (!$finalBlowCharacterId || $finalBlowCharacterId < 3000000) { $finalBlowCharacterId = "None"; } // prepare the timestamp // this should be (unixtime * 10000000) + 116444736000000000 // but let's cut some zeros in order to support 32bit systems $timestamp = $timestamp + 1644473600; $timestamp = '1' . $timestamp . '0000000'; return sha1($victimCharacterId . $finalBlowCharacterId . $shipTypeID . $timestamp); }