Exemplo n.º 1
0
 function display()
 {
     global $smarty;
     $alls = $corps = $pilots = false;
     if (config::get('cfg_allianceid')) {
         $alls = array();
         foreach (config::get('cfg_allianceid') as $entity) {
             $alliance = new Alliance($entity);
             if ($alliance->getExternalID()) {
                 $url = edkURI::page('alliance_detail', $alliance->getExternalID(), 'all_ext_id');
             } else {
                 $url = edkURI::page('alliance_detail', $alliance->getID(), 'all_id');
             }
             $alls[] = array('id' => $alliance->getID(), 'extid' => $alliance->getExternalID(), 'name' => $alliance->getName(), 'portrait' => $alliance->getPortraitURL(128), 'url' => $url);
         }
     }
     if (config::get('cfg_corpid')) {
         $corps = array();
         foreach (config::get('cfg_corpid') as $entity) {
             $corp = new Corporation($entity);
             if ($corp->getExternalID()) {
                 $url = edkURI::page('corp_detail', $corp->getExternalID(), 'crp_ext_id');
             } else {
                 $url = edkURI::page('corp_detail', $corp->getID(), 'crp_id');
             }
             $corps[] = array('id' => $corp->getID(), 'extid' => $corp->getExternalID(), 'name' => $corp->getName(), 'portrait' => $corp->getPortraitURL(128), 'url' => $url);
         }
     }
     if (config::get('cfg_pilotid')) {
         $pilots = array();
         foreach (config::get('cfg_pilotid') as $entity) {
             $pilot = new Pilot($entity);
             if ($pilot->getExternalID()) {
                 $url = edkURI::page('pilot_detail', $pilot->getExternalID(), 'plt_ext_id');
             } else {
                 $url = edkURI::page('pilot_detail', $pilot->getID(), 'plt_id');
             }
             $pilots[] = array('id' => $pilot->getID(), 'extid' => $pilot->getExternalID(), 'name' => $pilot->getName(), 'portrait' => $pilot->getPortraitURL(128), 'url' => $url);
         }
     }
     $smarty->assignByRef('alliances', $alls);
     $smarty->assignByRef('corps', $corps);
     $smarty->assignByRef('pilots', $pilots);
     return $smarty->fetch(get_tpl('self'));
 }
Exemplo n.º 2
0
 /**
  * @return integer
  */
 function getCorpID()
 {
     return $this->corp_->getID();
 }
Exemplo n.º 3
0
 public static function nameToId($type, $set, $value)
 {
     if ($type == 'nametoid') {
         $api = new API_NametoID();
         $api->setNames($value);
     } else {
         if ($type == 'idtoname') {
             $api = new API_IDtoName();
             $api->setIDs($value);
         }
     }
     $api->fetchXML();
     if ($type == 'nametoid') {
         $char_info = $api->getNameData();
     } else {
         if ($type == 'idtoname') {
             $char_info = $api->getIDData();
         }
     }
     if (isset($char_info[0]['characterID']) && strlen($char_info[0]['characterID']) > 0) {
         $timestamp = gmdate('%Y.%m.%d %H:%i:%s', time());
         if ($set == 'p') {
             $all = Alliance::add('Unknown');
             $crp = Corporation::add('Unknown', $all, $timestamp, 0, false);
             $plt = Pilot::add($char_info[0]['name'], $crp, $timestamp, $char_info[0]['characterID'], false);
             $_POST['option_cfg_pilotid'] = $value = $plt->getID();
             $pilots = config::get('cfg_pilotid');
             $pilots[] = intval($value);
             config::set('cfg_pilotid', $pilots);
             $html = '<input type="text" id="option_cfg_pilotid"' . ' name="option_cfg_pilotid" value="" size="40"' . ' maxlength="64" />';
         } else {
             if ($set == 'c') {
                 $all = Alliance::add('Unknown');
                 $crp = new Corporation();
                 $crp->add($char_info[0]['name'], $all, $timestamp, $char_info[0]['characterID'], false);
                 $_POST['option_cfg_corpid'] = $value = $crp->getID();
                 $corps = config::get('cfg_corpid');
                 $corps[] = intval($value);
                 config::set('cfg_pilotid', $corps);
                 $html = '<input type="text" id="option_cfg_corpid"' . ' name="option_cfg_corpid" value="" size="40"' . ' maxlength="64" />';
             } else {
                 if ($set == 'a') {
                     $all = Alliance::add('Unknown');
                     $_POST['option_cfg_allianceid'] = $value = $all->getID();
                     $alliances = config::get('option_cfg_allianceid');
                     $alliances[] = intval($value);
                     config::set('option_cfg_allianceid', $alliances);
                     $html = '<input type="text" id="option_cfg_allianceid"' . ' name="option_cfg_allianceid" value="" size="40"' . ' maxlength="64" />';
                 }
             }
         }
         return $html;
     } else {
         return $html;
     }
 }
Exemplo n.º 4
0
 /**
  * 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;
     }
 }
Exemplo n.º 5
0
 /**
  * Return the raw killmail for this kill.
  *
  * @return string
  */
 function getRawMail()
 {
     if (!is_null($this->mail)) {
         return $this->mail;
     }
     if (config::get('km_cache_enabled') && file_exists(KB_PAGECACHEDIR . "/" . $this->getID() . ".txt")) {
         $this->mail = file_get_contents(KB_PAGECACHEDIR . "/" . $this->getID() . ".txt");
         return $this->mail;
     }
     if (!$this->timestamp) {
         $this->execQuery();
     }
     if (!$this->valid) {
         return "The specified kill ID is not valid.";
     }
     if ($this->isClassified()) {
         return 'Killmail not yet available, try again in ' . round($this->getClassifiedTime() / 3600, 2) . ' hrs.';
     }
     static $locations;
     if (!isset($locations)) {
         $qry = DBFactory::getDBQuery();
         $qry->execute("SELECT itl_flagID, itl_flagText FROM kb3_item_locations");
         while ($row = $qry->getRow()) {
             $locations[$row['itl_flagID']] = $row['itl_flagText'];
         }
     }
     $ship = $this->getVictimShip();
     $shipclass = $ship->getClass();
     if (!$this->getVictimCorpName()) {
         $corp = new Corporation($this->victimcorpid);
         $this->victimcorpname = $corp->getName();
     }
     if (!$this->getVictimAllianceName()) {
         $all = new Alliance($this->victimallianceid);
         $this->victimalliancename = $all->getName();
     }
     if (!$this->getVictimName()) {
         throw new KillException("Invalid mail, victim name blank");
     } else {
         if (!$this->getVictimCorpName()) {
             throw new KillException("Invalid mail, victim corporation blank");
         } else {
             if (!$this->getVictimAllianceName() && !$this->getVictimFactionName()) {
                 throw new KillException("Invalid mail, victim alliance blank");
             } else {
                 if (!$ship->getName()) {
                     throw new KillException("Invalid mail, ship blank");
                 } else {
                     if (!$this->getSystem()->getName()) {
                         throw new KillException("Invalid mail, system blank", ´);
                     }
                 }
             }
         }
     }
     $mail = substr(str_replace('-', '.', $this->getTimeStamp()), 0, 19) . "\r\n\r\n";
     // Starbase (so this is a POS mail)
     if (in_array($shipclass->getID(), array(35, 36, 37, 38))) {
         $mail .= "Corp: " . $this->getVictimCorpName() . "\r\n";
         if ($this->getIsVictimFaction()) {
             $mail .= "Alliance: None\r\n";
         } else {
             $mail .= "Alliance: " . $this->getVictimAllianceName() . "\r\n";
         }
         $mail .= "Faction: " . $this->getVictimFactionName() . "\r\n";
         //$ship = $this->getVictimShip();
         $mail .= "Destroyed: " . $ship->getName() . "\r\n";
         if ($this->getVictimName() == $this->getSystem()->getName()) {
             $mail .= "Moon: Unknown\r\n";
         } else {
             // is the victim's name a moon?
             $moonID = API_Helpers::getMoonID($this->getVictimName());
             if ($moonID) {
                 $mail .= "Moon: " . $this->getVictimName() . "\r\n";
             } else {
                 // try parsing the victim's name in case it's the format
                 // <corporationName> - <moonName>
                 $namePieces = explode(" - ", $this->getVictimName());
                 if (is_array($namePieces) && count($namePieces) > 2) {
                     // remove first part, which is the corp name
                     array_splice($namePieces, 0, 1);
                     $mail .= "Moon: " . implode(" - ", $namePieces) . "\r\n";
                 }
             }
         }
         $mail .= "System: " . $this->getSystem()->getName() . "\r\n";
         $mail .= "Security: " . $this->getSystem()->getSecurity(true) . "\r\n";
         $mail .= "Damage Taken: " . $this->dmgtaken . "\r\n\r\n";
         $mail .= "Involved parties:\r\n\r\n";
     } else {
         $mail .= "Victim: " . $this->getVictimName() . "\r\n";
         $mail .= "Corp: " . $this->getVictimCorpName() . "\r\n";
         if ($this->getIsVictimFaction()) {
             $mail .= "Alliance: None\r\n";
         } else {
             $mail .= "Alliance: " . $this->getVictimAllianceName() . "\r\n";
         }
         $mail .= "Faction: " . $this->getVictimFactionName() . "\r\n";
         //$ship = $this->getVictimShip();
         $mail .= "Destroyed: " . $ship->getName() . "\r\n";
         $system = $this->getSystem();
         $mail .= "System: " . $system->getName() . "\r\n";
         $mail .= "Security: " . $system->getSecurity(true) . "\r\n";
         $mail .= "Damage Taken: " . $this->dmgtaken . "\r\n\r\n";
         $mail .= "Involved parties:\r\n\r\n";
     }
     foreach ($this->involvedparties_ as $inv) {
         /* @var $inv InvolvedParty */
         $pilot = new Pilot($inv->getPilotID());
         $corp = new Corporation($inv->getCorpID());
         $alliance = new Alliance($inv->getAllianceID());
         $weapon = $inv->getWeapon();
         $ship = $inv->getShip();
         if ($ship->getID() != "9999") {
             // Split these into multiple ifs so the error tells us where the
             // problem was.
             if (!$pilot->getName()) {
                 throw new KillException("Invalid mail, invalid involved pilot (ID: " . $pilot->getID() . ")");
             } else {
                 if (!$corp->getName()) {
                     throw new KillException("Invalid mail, invalid involved corporation (ID: " . $corp->getID() . ")");
                 } else {
                     if (!$alliance->getName()) {
                         throw new KillException("Invalid mail, invalid involved alliance (ID: " . $alliance->getID() . ")");
                     } else {
                         if (!$weapon->getName()) {
                             throw new KillException("Invalid mail, invalid involved weapon (ID: " . $weapon->getID() . ")");
                         } else {
                             if (!$ship->getName()) {
                                 throw new KillException("Invalid mail, invalid involved ship (ID: " . $ship->getID() . ")");
                             }
                         }
                     }
                 }
             }
             if ($pilot->getName() == $weapon->getName()) {
                 $name = $pilot->getName() . " / " . $corp->getName();
             } else {
                 $name = $pilot->getName();
             }
             $mail .= "Name: " . $name;
             if ($pilot->getID() == $this->getFBPilotID()) {
                 $mail .= " (laid the final blow)";
             }
             $mail .= "\r\n";
             if ($pilot->getName() != $weapon->getName()) {
                 $mail .= "Security: " . $inv->getSecStatus() . "\r\n";
                 $mail .= "Corp: " . $corp->getName() . "\r\n";
                 if ($alliance->isFaction()) {
                     $mail .= "Alliance: None\r\n";
                     $mail .= "Faction: " . $alliance->getName() . "\r\n";
                 } else {
                     $mail .= "Alliance: " . $alliance->getName() . "\r\n";
                     $mail .= "Faction: None\r\n";
                 }
                 $mail .= "Ship: " . $ship->getName() . "\r\n";
                 $mail .= "Weapon: " . $weapon->getName() . "\r\n";
                 $mail .= "Damage Done: " . $inv->getDamageDone() . "\r\n";
             } else {
                 $mail .= "Damage Done: " . $inv->getDamageDone() . "\r\n";
             }
             $mail .= "\r\n";
         }
     }
     if (count($this->destroyeditems_) > 0) {
         $mail .= "\r\nDestroyed items:\r\n\r\n";
         foreach ($this->destroyeditems_ as $destroyed) {
             $item = $destroyed->getItem();
             $mail .= $item->getName();
             if ($destroyed->getQuantity() > 1) {
                 $mail .= ", Qty: " . $destroyed->getQuantity();
             }
             if ($destroyed->getSingleton() == InventoryFlag::$SINGLETON_COPY) {
                 $mail .= " (Copy)";
             }
             $flagID = InventoryFlag::collapse($destroyed->getLocationID());
             if ($destroyed->getLocationID() == InventoryFlag::$CARGO) {
                 $mail .= " (Cargo)";
             } else {
                 if ($destroyed->getLocationID() == InventoryFlag::$DRONE_BAY) {
                     $mail .= " (Drone Bay)";
                 } else {
                     if ($destroyed->getLocationID() == InventoryFlag::$IMPLANT) {
                         $mail .= " (Implant)";
                     } else {
                         if ($destroyed->getLocationID() == InventoryFlag::$OTHER) {
                             $mail .= " (Other)";
                         }
                     }
                 }
             }
             $mail .= "\r\n";
         }
     }
     if (count($this->droppeditems_) > 0) {
         $mail .= "\r\nDropped items:\r\n\r\n";
         foreach ($this->droppeditems_ as $dropped) {
             $item = $dropped->getItem();
             $mail .= $item->getName();
             if ($dropped->getQuantity() > 1) {
                 $mail .= ", Qty: " . $dropped->getQuantity();
             }
             if ($dropped->getSingleton() == InventoryFlag::$SINGLETON_COPY) {
                 $mail .= " (Copy)";
             }
             if ($dropped->getLocationID() == InventoryFlag::$CARGO) {
                 $mail .= " (Cargo)";
             } else {
                 if ($dropped->getLocationID() == InventoryFlag::$DRONE_BAY) {
                     $mail .= " (Drone Bay)";
                 } else {
                     if ($dropped->getLocationID() == InventoryFlag::$IMPLANT) {
                         $mail .= " (Implant)";
                     } else {
                         if ($dropped->getLocationID() == InventoryFlag::$OTHER) {
                             $mail .= " (Other)";
                         }
                     }
                 }
             }
             $mail .= "\r\n";
         }
     }
     if ($this->id && config::get('km_cache_enabled')) {
         file_put_contents(KB_MAILCACHEDIR . "/" . $this->getID() . ".txt", $mail);
     }
     $this->mail = $mail;
     return $mail;
 }
Exemplo n.º 6
0
 /**
  * Start constructing the page.
  * Prepare all the shared variables such as dates and check alliance ID.
  *
  */
 function start()
 {
     $this->page = new Page('Corporation details');
     $this->scl_id = (int) edkURI::getArg('scl_id');
     $this->crp_id = (int) edkURI::getArg('crp_id');
     if (!$this->crp_id) {
         $this->crp_external_id = (int) edkURI::getArg('crp_ext_id');
         if (!$this->crp_external_id) {
             $id = (int) edkURI::getArg('id', 1);
             // True for NPC corps too, but NPC alliances recorded as corps
             // fail here. Use Jedi mind tricks?
             if ($id > 1000000) {
                 $this->crp_external_id = $id;
             } else {
                 $this->crp_id = $id;
             }
         }
     }
     $this->view = preg_replace('/[^a-zA-Z0-9_-]/', '', edkURI::getArg('view', 2));
     if ($this->view) {
         $this->page->addHeader('<meta name="robots" content="noindex, nofollow" />');
     }
     if (!$this->crp_id) {
         if ($this->crp_external_id) {
             $this->corp = new Corporation($this->crp_external_id, true);
             $this->crp_id = $this->corp->getID();
         } else {
             $html = 'That corporation does not exist.';
             $this->page->setContent($html);
             $this->page->generate();
             exit;
         }
     } else {
         $this->corp = Cacheable::factory('Corporation', $this->crp_id);
         $this->crp_external_id = $this->corp->getExternalID();
     }
     if ($this->crp_external_id) {
         $this->page->addHeader("<link rel='canonical' href='" . edkURI::build(array('crp_ext_id', $this->crp_external_id, true)) . "' />");
     } else {
         $this->page->addHeader("<link rel='canonical' href='" . edkURI::build(array('crp_id', $this->crp_id, true)) . "' />");
     }
     $this->alliance = $this->corp->getAlliance();
     if ($this->view) {
         $this->year = (int) edkURI::getArg('y', 3);
         $this->month = (int) edkURI::getArg('m', 4);
     } else {
         $this->year = (int) edkURI::getArg('y', 2);
         $this->month = (int) edkURI::getArg('m', 3);
     }
     if (!$this->month) {
         $this->month = kbdate('m');
     }
     if (!$this->year) {
         $this->year = kbdate('Y');
     }
     if ($this->month == 12) {
         $this->nmonth = 1;
         $this->nyear = $this->year + 1;
     } else {
         $this->nmonth = $this->month + 1;
         $this->nyear = $this->year;
     }
     if ($this->month == 1) {
         $this->pmonth = 12;
         $this->pyear = $this->year - 1;
     } else {
         $this->pmonth = $this->month - 1;
         $this->pyear = $this->year;
     }
     $this->monthname = kbdate("F", strtotime("2000-" . $this->month . "-2"));
 }