Beispiel #1
0
        $list->setMaxExtID(intval($_GET['lastID'] + $_GET['range']));
    }
} else {
    if (isset($_GET['lastintID'])) {
        $list->setMinKllID(intval($_GET['lastintID']));
        if (isset($_GET['range'])) {
            $list->setMaxKllID(intval($_GET['lastintID'] + $_GET['range']));
        }
    }
}
if (isset($_GET['startdate'])) {
    $list->setStartDate(gmdate('Y-m-d H:i:s', intval($_GET['startdate'])));
}
if (isset($_GET['enddate'])) {
    $list->setEndDate(gmdate('Y-m-d H:i:s', intval($_GET['enddate'])));
}
header("Content-Type: text/xml");
echo IDFeed::killListToXML($list);
//echo "<!-- ".$timing."\n -->";
//echo "<!-- Finished: ".(microtime(true)-$starttime)." -->";
/**
 * Output generated XML and terminate.
 * 
 * @param SimpleXMLElement $sxe
 */
function show($sxe)
{
    header("Content-Type: text/xml");
    echo $sxe->asXML();
    die;
}
Beispiel #2
0
 /**
  * Recursively add a SimpleXMLElement to another.
  *
  * @param SimpleXMLElement $dest
  * @param SimpleXMLElement $source
  */
 private static function addXMLElement(&$dest, $source)
 {
     $new_dest = $dest->addChild($source->getName(), $source[0]);
     foreach ($source->attributes() as $name => $value) {
         $new_dest->addAttribute($name, $value);
     }
     foreach ($source->children() as $child) {
         IDFeed::addXMLElement($new_dest, $child);
     }
 }
Beispiel #3
0
 /**
  * Really add the kill.
  * @param integer $id If set, use the given id to post this kill.
  * @return integer
  */
 protected function realadd($id = null)
 {
     if ($this->timestamp == "" || !$this->getVictim()->getID() || !$this->victimship->getName() || !$this->solarsystem->getID() || !$this->victimallianceid || !$this->victimcorpid || !$this->getFBPilotID()) {
         return 0;
     }
     // TODO: Redo accounting for ammo (see kill_detail).
     //		// Check slot counts.
     //		$locations = array();
     //		foreach ($this->droppeditems_ as $dest) {
     //			$locations[$dest->getLocationID()] += $dest->getQuantity();
     //		}
     //		foreach ($this->destroyeditems_ as $dest) {
     //			$locations[$dest->getLocationID()] += $dest->getQuantity();
     //		}
     //		$dogma = Cacheable::factory('dogma', $this->victimship->getID());
     //		$lowcount = (int)$dogma->attrib['lowSlots']['value'];
     //		$medcount = (int)$dogma->attrib['medSlots']['value'];
     //		$hicount = (int)$dogma->attrib['hiSlots']['value'];
     //		// Is there anything flyable that has no rig slots?
     //		$rigcount = (int)($dogma->attrib['rigSlots']['value'] ?
     //				$dogma->attrib['rigSlots']['value'] : 3);
     //		$subcount = 5;
     //		if ($lowcount
     //				&& ($locations[1] > $hicount
     //				|| $locations[2] > $medcount
     //				||  $locations[3] > $lowcount
     //				|| $locations[5] > $rigcount)
     //				) {
     //			return 0;
     //		} else if ((!$lowcount && $locations[7])
     //				&& ($locations[7] > $subcount
     //				|| $locations[5] > $rigcount)
     //				) {
     //			return 0;
     //		}
     if ($id == null) {
         $qid = 'null';
     } else {
         $qid = $id;
     }
     if (!$this->dmgtaken) {
         $this->dmgtaken = 0;
     }
     $qry = DBFactory::getDBQuery();
     $sql = "INSERT INTO kb3_kills\n            (kll_id , kll_timestamp , kll_victim_id , kll_all_id , kll_crp_id , kll_ship_id , kll_system_id , kll_fb_plt_id , kll_td_plt_id , kll_points , kll_dmgtaken, kll_external_id, kll_isk_loss, kll_isk_loot)\n            VALUES (" . $qid . ",\n\t\t\tdate_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'),\n            " . $this->victimid . ",\n            " . $this->victimallianceid . ",\n            " . $this->victimcorpid . ",\n            " . $this->victimship->getID() . ",\n            " . $this->solarsystem->getID() . ",\n            " . $this->getFBPilotID() . ",\n\t\t\t" . $this->getTDPilotID() . ",\n            " . $this->calculateKillPoints() . ",\n            " . $this->dmgtaken . ", ";
     if ($this->externalid) {
         $sql .= $this->externalid . ", ";
     } else {
         $sql .= "NULL, ";
     }
     $sql .= $this->getISKLoss() . ", ";
     $sql .= $this->getISKLoot() . " )";
     $qry->autocommit(false);
     if (!$qry->execute($sql)) {
         return $this->rollback($qry);
     }
     if ($id) {
         $this->id = $id;
     } else {
         $this->id = $qry->getInsertID();
     }
     if (!$this->id) {
         return $this->rollback($qry);
     }
     // involved
     $order = 0;
     $invall = array();
     $invcrp = array();
     $involveddsql = 'insert into kb3_inv_detail
                 (ind_kll_id, ind_timestamp, ind_plt_id, ind_sec_status, ind_all_id, ind_crp_id, ind_shp_id, ind_wep_id, ind_order, ind_dmgdone )
                 values ';
     $involvedasql = 'insert into kb3_inv_all
                 (ina_kll_id, ina_all_id, ina_timestamp) values ';
     $involvedcsql = 'insert into kb3_inv_crp
                 (inc_kll_id, inc_crp_id, inc_timestamp) values ';
     $notfirstd = false;
     $notfirsta = false;
     $notfirstc = false;
     // Make sure involved parties are ordered by damage done.
     usort($this->involvedparties_, array('Kill', 'involvedComparator'));
     foreach ($this->involvedparties_ as $inv) {
         $ship = $inv->getShip();
         $weapon = $inv->getWeapon();
         if (!$inv->getPilotID() || !$inv->getAllianceID() || !$inv->getCorpID() || !$ship->getName() || !$weapon->getID()) {
             return $this->rollback();
         }
         if ($notfirstd) {
             $involveddsql .= ", ";
         }
         $involveddsql .= "( " . $this->getID() . ", date_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'), " . $inv->getPilotID() . ", '" . $inv->getSecStatus() . "', " . $inv->getAllianceID() . ", " . $inv->getCorpID() . ", " . $ship->getID() . ", " . $weapon->getID() . ", " . $order++ . ", " . $inv->getDamageDone() . ")";
         $notfirstd = true;
         if (!in_array($inv->getAllianceID(), $invall)) {
             if ($notfirsta) {
                 $involvedasql .= ", ";
             }
             $involvedasql .= "( " . $this->getID() . ", " . $inv->getAllianceID() . ", date_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'))";
             $notfirsta = true;
             $invall[] = $inv->getAllianceID();
         }
         if (!in_array($inv->getCorpID(), $invcrp)) {
             if ($notfirstc) {
                 $involvedcsql .= ", ";
             }
             $involvedcsql .= "( " . $this->getID() . ", " . $inv->getCorpID() . ", date_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'))";
             $notfirstc = true;
             $invcrp[] = $inv->getCorpID();
         }
     }
     if ($notfirstd && !$qry->execute($involveddsql)) {
         return $this->rollback($qry);
     }
     if ($notfirsta && !$qry->execute($involvedasql)) {
         return $this->rollback($qry);
     }
     if ($notfirstc && !$qry->execute($involvedcsql)) {
         return $this->rollback($qry);
     }
     // destroyed
     $notfirstitd = false;
     $itdsql = "insert into kb3_items_destroyed (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id) values ";
     foreach ($this->destroyeditems_ as $dest) {
         $item = $dest->getItem();
         $loc_id = $dest->getLocationID();
         if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id)) {
             trigger_error('error with destroyed item.', E_USER_WARNING);
             var_dump($dest);
             exit;
             continue;
         }
         if ($notfirstitd) {
             $itdsql .= ", ";
         }
         $itdsql .= "( " . $this->getID() . ", " . $item->getID() . ", " . $dest->getQuantity() . ", " . $loc_id . " )";
         $notfirstitd = true;
     }
     if ($notfirstitd && !$qry->execute($itdsql)) {
         return $this->rollback($qry);
     }
     // dropped
     $notfirstitd = false;
     $itdsql = "insert into kb3_items_dropped (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id) values ";
     foreach ($this->droppeditems_ as $dest) {
         $item = $dest->getItem();
         $loc_id = $dest->getLocationID();
         if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id)) {
             trigger_error('error with dropped item.', E_USER_WARNING);
             var_dump($dest);
             exit;
             continue;
         }
         if ($notfirstitd) {
             $itdsql .= ", ";
         }
         $itdsql .= "( " . $this->getID() . ", " . $item->getID() . ", " . $dest->getQuantity() . ", " . $loc_id . " )";
         $notfirstitd = true;
     }
     if ($notfirstitd && !$qry->execute($itdsql)) {
         return $this->rollback($qry);
     }
     $sql = "INSERT INTO kb3_mails (`kll_id`, `kll_timestamp`, `kll_external_id`, `kll_hash`, `kll_modified_time`)" . "VALUES(" . $this->getID() . ", '" . $this->getTimeStamp() . "', ";
     if ($this->externalid) {
         $sql .= $this->externalid . ", ";
     } else {
         $sql .= "NULL, ";
     }
     $sql .= "'" . $qry->escape(IDFeed::getHash($this)) . "', UTC_TIMESTAMP())";
     if (!@$qry->execute($sql)) {
         return $this->rollback($qry);
     }
     //Update cache tables.
     summaryCache::addKill($this);
     $qry->autocommit(true);
     // call the event that we added this mail
     event::call('killmail_added', $this);
     return $this->id;
 }
Beispiel #4
0
 function Import($name, $id, $key, $flags)
 {
     $output = "";
     // Skip bad keys
     if ($flags & KB_APIKEY_BADAUTH || $flags & KB_APIKEY_EXPIRED || $flags & KB_APIKEY_BADCORP) {
         return;
         // skip bad keys
     }
     // also skip legacy keys now
     if ($flags & KB_APIKEY_LEGACY) {
         return;
     }
     // reduces strain on DB
     if (function_exists("set_time_limit") && !ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $lastdatakillid = 1;
     $currentdatakillid = 0;
     $logsource = "New XML";
     // Load new XML
     $output = "<i>Downloading latest XML file for {$name}</i><br><br>";
     $accts = new API_Account();
     $characters = $accts->fetch($id, $key);
     $posted = array();
     $skipped = array();
     foreach ($characters as $char) {
         $output .= "Processing " . $char['characterName'] . "<br><br>";
         $currentkill = 0;
         $lastkill = -1;
         while ($lastkill != $currentkill) {
             $lastkill = $currentkill;
             $args = array("characterID" => $char['characterID']);
             if ($lastkill) {
                 $args["beforeKillID"] = $lastkill;
             }
             if ($flags & KB_APIKEY_CORP) {
                 $killLog = $this->CallAPI("corp", "KillLog", $args, $id, $key);
             } else {
                 if ($flags & KB_APIKEY_CHAR) {
                     $killLog = $this->CallAPI("char", "KillLog", $args, $id, $key);
                 } else {
                     $output .= "<div class='block-header2'>Key does not have access to KillLog</div>";
                     break;
                 }
             }
             if ($this->getError() === null) {
                 // Get oldest kill
                 $currentkill = 0;
                 $sxe = simplexml_load_string($this->pheal->xml);
                 foreach ($sxe->result->rowset->row as $row) {
                     if ($currentkill < (int) $row['killID']) {
                         $currentkill = (int) $row['killID'];
                     }
                 }
             }
             if ($this->getError() !== null) {
                 if ($this->getError() == 120 && $this->pheal->xml) {
                     // Check if we just need to skip back a few kills
                     // i.e. first page of kills is already fetched.
                     $pos = strpos($this->pheal->xml, "Expected beforeKillID [");
                     if ($pos) {
                         $pos += 23;
                         $pos2 = strpos($this->pheal->xml, "]", $pos);
                         $currentkill = (int) substr($this->pheal->xml, $pos, $pos2 - $pos);
                     }
                 } else {
                     if (!$posted && !$skipped) {
                         // Something went wrong and no kills were found.
                         $qry = DBFactory::getDBQuery();
                         $logtype = "Cron Job";
                         $qry->execute("insert into kb3_apilog\tvalues( '" . KB_SITE . "', '" . addslashes($name) . "'," . "0, " . "0, " . "0, " . "0, " . "0, '" . "Error','" . "Cron Job','" . $this->getError() . "', " . "UTC_TIMESTAMP() )");
                         $output .= "<div class='block-header2'>" . $this->getMessage() . "</div>";
                         break;
                     } else {
                         // We found kills!
                         $qry = DBFactory::getDBQuery();
                         $logtype = "Cron Job";
                         $qry->execute("insert into kb3_apilog values( '" . KB_SITE . "', '" . addslashes($name) . "'," . count($posted) . "," . "0 ," . count($skipped) . "," . "0 ," . (count($posted) + count($skipped)) . ",'" . "New XML','" . "Cron Job','" . ($this->getError() == 119 ? 0 : $this->getError()) . "', " . "UTC_TIMESTAMP() )");
                         break;
                     }
                 }
             }
             $feedfetch = new IDFeed();
             $feedfetch->setXML($this->pheal->xml);
             $feedfetch->setLogName("API");
             $feedfetch->read();
             $posted = array_merge($posted, $feedfetch->getPosted());
             $skipped = array_merge($skipped, $feedfetch->getSkipped());
             $output .= "<div class='block-header2'>" . count($posted) . " kill" . (count($posted) == 1 ? "" : "s") . " posted, " . count($skipped) . " skipped from feed: " . $id . ".<br></div>";
             if (count($posted)) {
                 $output .= "<div class='block-header2'>Posted</div>\n";
                 foreach ($posted as $killid) {
                     $output .= "<div><a href='" . edkURI::page('kill_detail', $killid[2], 'kll_id') . "'>Kill " . $killid[0] . "</a></div>";
                 }
             }
         }
     }
     return $output;
 }
Beispiel #5
0
/**
 * @param boolean $trusted Depreciated.
*/
function getIDFeed($id, $url, $trusted, $lastkill)
{
    // Just in case, check for empty urls.
    if (empty($url)) {
        return '';
    }
    $qry2 = new DBQuery();
    $feedfetch = new IDFeed();
    $feedfetch->setID();
    $feedfetch->setAllKills(1);
    if (!$lastkill) {
        $feedfetch->setStartDate(time() - 60 * 60 * 24 * 7);
    } else {
        $feedfetch->setStartKill($lastkill + 1, true);
    }
    if ($feedfetch->read($url) !== false) {
        $posted = count($feedfetch->getPosted());
        $skipped = count($feedfetch->getSkipped());
        $duplicate = count($feedfetch->getDuplicate());
        if (strrpos(strtolower($url), 'zkillboard')) {
            $newKillID = $feedfetch->getLastReturned();
        } else {
            $newKillID = $feedfetch->getLastInternalReturned();
        }
        if ($newKillID > $lastkill) {
            $qry2->execute("UPDATE kb3_feeds SET feed_lastkill=" . intval($newKillID) . ", feed_updated=NOW()\n\t\t\t\tWHERE feed_kbsite = '" . KB_SITE . "' AND feed_id = {$id}");
        }
        printlog($posted . " kills were posted, " . $duplicate . " duplicate kills and " . $skipped . " were skipped.");
        printlog("Last kill ID returned was {$newKillID}");
        if ($feedfetch->getParseMessages()) {
            foreach ($feedfetch->getParseMessages() as $msg) {
                printlog($msg);
            }
        }
    } else {
        if (!$val['lastkill']) {
            printlog("Start time = " . date('YmdHi', time() - 60 * 60 * 24 * 7));
        } else {
            if ($val['apikills']) {
                printlog("Start kill = " . $val['lastkill']);
            }
        }
        printlog("Error reading feed: " . $feedfetch->errormsg());
    }
    printlog("Fetch url: " . $feedfetch->getFullURL());
}