Ejemplo n.º 1
0
 /**
  *
  * @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();
 }
Ejemplo n.º 2
0
function fetchImage($id, $type = 'Character', $size = 128, $ext = "jpg")
{
    include_once 'kbconfig.php';
    require_once 'common/includes/globals.php';
    require_once "common/includes/class.cachehandler.php";
    $url = 'http://' . IMG_SERVER . "/" . $type . "/" . $id . "_" . $size . "." . $ext;
    if (function_exists('curl_init')) {
        // in case of a dead eve server we only want to wait 2 seconds
        @ini_set('default_socket_timeout', 2);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
        // CURLOPT_FOLLOWLOCATION doesn't work if safe mode or open_basedir is set
        // For pilots we should try from oldportraits.eveonline.com if the main server doesn't have them.
        //if($type != 'Character') curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        $file = curl_exec($ch);
        //list($header, $file) = explode("\n\n", $file, 2);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($http_code != 200) {
            if ($type == 'Character') {
                $url = "http://oldportraits.eveonline.com/Character/" . $id . "_" . $size . "." . $ext;
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                $file = curl_exec($ch);
                $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                if ($http_code != 200) {
                    $file = file_get_contents("img/1_{$size}.jpg");
                }
            } else {
                if ($type == 'Alliance') {
                    $file = file_get_contents("img/alliances/default.png");
                } else {
                    if ($type == 'Corporation') {
                        $file = file_get_contents("img/corps/default.png");
                    } else {
                        show404();
                    }
                }
            }
        }
        curl_close($ch);
    } else {
        require_once 'common/includes/class.httprequest.php';
        // in case of a dead eve server we only want to wait 2 seconds
        @ini_set('default_socket_timeout', 2);
        // try alternative access via fsockopen
        // happens if allow_url_fopen wrapper is false
        $http = new http_request($url);
        $file = $http->get_content();
        $http_code = $http->get_http_code();
        if ($http_code != 200) {
            if ($type == 'Character') {
                $url = "http://oldportraits.eveonline.com/Character/" . $id . "_" . $size . "." . $ext;
                $http = new http_request($url);
                $file = $http->get_content();
                $http_code = $http->get_http_code();
                if ($http_code != 200) {
                    $file = file_get_contents("img/1_{$size}.jpg");
                }
            } else {
                if ($type == 'Alliance') {
                    $file = file_get_contents("img/alliances/default.png");
                } else {
                    if ($type == 'Corporation') {
                        $file = file_get_contents("img/corps/default.png");
                    } else {
                        show404();
                    }
                }
            }
        }
    }
    if ($img = @imagecreatefromstring($file)) {
        CacheHandler::put($id . '_' . $size . '.' . $ext, $file, 'img');
    }
    return $img;
}