Example #1
0
 /**
  * Add a new alliance to the database or update the details of an
  * existing alliance.
  *
  * @param string $name An alliance name for this object.
  * @param integer $externalid External ID if known.
  * @return type
  */
 static function add($name, $externalid = 0, $shortname = '', $executor_id = null, $member_count = 0, $start_date = null)
 {
     $qry = DBFactory::getDBQuery();
     $name = stripslashes($name);
     $qry->execute("select all_id, all_name, all_external_id" . " from kb3_alliances where all_name = '" . $qry->escape($name) . "'");
     if (!$qry->recordCount()) {
         $externalid = (int) $externalid;
         if (!$externalid && strcasecmp($name, 'None') != 0) {
             $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 alliance with the new name
         // then return.
         if ($externalid) {
             $qry->execute("SELECT * FROM kb3_alliances WHERE all_external_id = " . $externalid);
             if ($qry->recordCount() > 0) {
                 $row = $qry->getRow();
                 $qry->execute("UPDATE kb3_alliances SET all_name = '" . $qry->escape($name) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tall_short_name = '" . $qry->escape($shortname) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tall_executor_id = '" . $qry->escape($executor_id) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tall_member_count = '" . $qry->escape($member_count) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tall_start_date = '" . $qry->escape($start_date) . "'" . " WHERE all_external_id = " . $externalid);
                 $all = Cacheable::factory('Alliance', (int) $qry->getInsertID());
             } else {
                 $qry->execute("insert into kb3_alliances " . "(all_id, all_name, all_external_id) values " . "(null, '" . $qry->escape($name) . "', " . $externalid . ")");
             }
         } else {
             $qry->execute("insert into kb3_alliances " . "(all_id, all_name) values " . "(null, '" . $qry->escape($name) . "')");
         }
         $all = Alliance::getByID($qry->getInsertID());
         $all->name = $name;
         $all->externalid = (int) $externalid;
         $all->executed = true;
     } else {
         $row = $qry->getRow();
         $all = Alliance::getByID((int) $row['all_id']);
         $all->name = $row['all_name'];
         $all->externalid = (int) $row['all_external_id'];
         $all->executed = true;
     }
     return $all;
 }
Example #2
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;
     }
 }
Example #3
0
    /**
     * Add a new corporation to the database or update the details of an existing one.
     *
     * @param string $name The name of the new corporation.
     * @param Alliance $alliance The alliance this corporation belongs to.
     * @param string $timestamp The timestamp the corporation's details were updated.
     * @param integer $externalid The external CCP ID for the corporation.
     * @param boolean $loadExternals Whether to fetch unknown information from the API.
     * @return Corporation
     */
    static function add($name, $alliance, $timestamp, $externalid = 0, $loadExternals = true)
    {
        if (!$name) {
            trigger_error("Attempt to add a corporation 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 (!$alliance->getID()) {
                trigger_error("Attempt to add a corporation with no alliance. Aborting.", E_USER_ERROR);
                // If things are going this wrong, it's safer to die and prevent more harm
                die;
            }
        }
        $name = stripslashes($name);
        $externalid = (int) $externalid;
        $qry = DBFactory::getDBQuery(true);
        $qry->execute("select * from kb3_corps\n\t\t               where crp_name = '" . $qry->escape($name) . "'");
        // If the corp name is not present in the db add it.
        if (!$qry->recordCount()) {
            // 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_corps WHERE crp_external_id = " . $externalid);
                if ($qry->recordCount()) {
                    $row = $qry->getRow();
                    $qry->execute("UPDATE kb3_corps SET crp_name = '" . $qry->escape($name) . "' WHERE crp_external_id = " . $externalid);
                    $crp = Corporation::getByID((int) $row['crp_id']);
                    Cacheable::delCache($crp);
                    $crp->name = $name;
                    $crp->externalid = $row['crp_external_id'];
                    if (!is_null($row['crp_updated'])) {
                        $crp->updated = strtotime($row['crp_updated'] . " UTC");
                    } else {
                        $crp->updated = null;
                    }
                    // Now check if the alliance needs to be updated.
                    if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) {
                        $sql = 'update kb3_corps
									   set crp_all_id = ' . $alliance->getID() . ', ';
                        $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id;
                        $qry->execute($sql);
                        $crp->alliance = $alliance;
                    }
                    return $crp;
                }
            }
            // Neither corp name or external id was found so add this corp as new
            if ($externalid) {
                $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_external_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ", " . $externalid . ", date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))");
            } else {
                $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ",date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))");
            }
            $crp = Corporation::getByID((int) $qry->getInsertID());
            $crp->name = $name;
            $crp->externalid = (int) $externalid;
            $crp->alliance = $alliance->getID();
            $crp->updated = strtotime(preg_replace("/\\./", "-", $timestamp) . " UTC");
            return $crp;
        } else {
            $row = $qry->getRow();
            $crp = Corporation::getByID((int) $row['crp_id']);
            $crp->name = $row['crp_name'];
            $crp->externalid = (int) $row['crp_external_id'];
            $crp->alliance = $row['crp_all_id'];
            if (!is_null($row['crp_updated'])) {
                $crp->updated = strtotime($row['crp_updated'] . " UTC");
            } else {
                $crp->updated = null;
            }
            if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) {
                $sql = 'update kb3_corps set crp_all_id = ' . $alliance->getID() . ', ';
                $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id;
                $qry->execute($sql);
                $crp->alliance = $alliance;
            }
            if (!$crp->externalid && $externalid) {
                $crp->setExternalID((int) $externalid);
            }
            return $crp;
        }
        return false;
    }
Example #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;
     }
 }
Example #5
0
 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']) . '&amp;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'];
                     }
                 }
             }
         }
     }
 }