1 | <?php |
---|
2 | // Report all PHP errors (bitwise 63 may be used in PHP 3) |
---|
3 | @error_reporting(E_ALL ^ E_NOTICE); |
---|
4 | define ("APIVERSION", "V3.3"); |
---|
5 | |
---|
6 | // |
---|
7 | // Eve-Dev API Killmail parser by Captain Thunk! (ISK donations are all gratefully received) |
---|
8 | // |
---|
9 | |
---|
10 | require_once( "common/includes/class.kill.php" ); |
---|
11 | require_once( "common/includes/class.parser.php" ); |
---|
12 | require_once('common/includes/class.pilot.php'); |
---|
13 | require_once('common/includes/class.corp.php'); |
---|
14 | require_once('common/includes/class.alliance.php'); |
---|
15 | require_once( "common/includes/db.php" ); |
---|
16 | require_once('common/includes/class.apicache.php'); |
---|
17 | |
---|
18 | $ApiCache = new ApiCache(KB_SITE); |
---|
19 | |
---|
20 | // Checks for configuration of files and folders |
---|
21 | if (!file_exists("cache/api")) |
---|
22 | { |
---|
23 | if (!mkdir("cache/api", 0777)) |
---|
24 | { |
---|
25 | // creating folder failed - spam something about that |
---|
26 | echo "Failed to create folder 'cache/api' you should create the folder yourself and set chmod 777"; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | // ********************************************************************************************************************************************** |
---|
31 | // **************** API KillLog - /corp/Killlog.xml.aspx **************** |
---|
32 | // ********************************************************************************************************************************************** |
---|
33 | |
---|
34 | class API_KillLog |
---|
35 | { |
---|
36 | function Import($keystring, $typestring, $keyindex) |
---|
37 | { |
---|
38 | $this->mailcount_ = 0; |
---|
39 | $this->ignoredmails_ = 0; |
---|
40 | $this->malformedmails_ = 0; |
---|
41 | $this->verified_ = 0; |
---|
42 | $this->totalmails_ = 0; |
---|
43 | $this->errorcode_ = 0; |
---|
44 | $this->Output_ = ""; |
---|
45 | $this->isContainer = false; |
---|
46 | $this->hasdownloaded_ = false; |
---|
47 | $this->errortext_ = ""; |
---|
48 | $this->CachedUntil_ = ""; |
---|
49 | $this->killmailExists_ = false; |
---|
50 | |
---|
51 | // reduces strain on DB |
---|
52 | if(function_exists("set_time_limit")) |
---|
53 | set_time_limit(0); |
---|
54 | |
---|
55 | $this->API_IgnoreFriendPos_ = config::get('API_IgnoreFriendPos'); |
---|
56 | $this->API_IgnoreEnemyPos_ = config::get('API_IgnoreEnemyPos'); |
---|
57 | $this->API_IgnoreNPC_ = config::get('API_IgnoreNPC'); |
---|
58 | $this->API_IgnoreCorpFF_ = config::get('API_IgnoreCorpFF'); |
---|
59 | $this->API_IgnoreAllianceFF_ = config::get('API_IgnoreAllianceFF'); |
---|
60 | $this->API_NoSpam_ = config::get('API_NoSpam'); |
---|
61 | $this->API_CacheTime_ = ApiCache::get('API_CachedUntil_' . $keyindex); |
---|
62 | $this->API_UseCaching_ = config::get('API_UseCache'); |
---|
63 | $this->API_CCPErrorCorrecting = config::get('API_CCPErrorCorrecting'); |
---|
64 | $this->keyindex_ = $keyindex; |
---|
65 | |
---|
66 | |
---|
67 | // Initialise for error correcting and missing itemID resolution |
---|
68 | $this->myIDName = new API_IDtoName(); |
---|
69 | $this->myNameID = new API_NametoID(); |
---|
70 | |
---|
71 | $lastdatakillid = 1; |
---|
72 | $currentdatakillid = 0; |
---|
73 | |
---|
74 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
75 | if ($this->API_CacheTime_ == "") |
---|
76 | { |
---|
77 | $this->API_CacheTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
78 | } |
---|
79 | |
---|
80 | if (is_file(getcwd().'/cache/api/'.config::get('API_Name_'.$keyindex).'_KillLog.xml')) |
---|
81 | $cacheexists = true; |
---|
82 | else |
---|
83 | $cacheexists = false; |
---|
84 | |
---|
85 | // if API_UseCache = 1 (off) then don't use cache |
---|
86 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($this->API_CacheTime_) > 0) || ($this->API_UseCaching_ == 1) || !$cacheexists ) |
---|
87 | { |
---|
88 | // Load new XML |
---|
89 | $logsource = "New XML"; |
---|
90 | $this->Output_ .= "<i>Downloading latest XML file for " . config::get('API_Name_'.$keyindex) . "</i><br><br>"; |
---|
91 | $data = '<myxml thunkage="1">'; |
---|
92 | do { |
---|
93 | $data .= $this->loaddata($currentdatakillid, $keystring, $typestring); |
---|
94 | $lastdatakillid = $currentdatakillid; |
---|
95 | $currentdatakillid = $this->getlastkillid($data); |
---|
96 | } while ( $lastdatakillid != $currentdatakillid ); |
---|
97 | $data .= '</myxml>'; |
---|
98 | |
---|
99 | if ( ( $this->API_UseCaching_ ) == 0 )//&& ( $this->iscronjob_ == false ) ) |
---|
100 | { |
---|
101 | // save the file if no errors have occurred |
---|
102 | if ($this->errorcode_ == 0) |
---|
103 | { |
---|
104 | $file = fopen(getcwd().'/cache/api/'.config::get('API_Name_'.$keyindex).'_KillLog.xml', 'w+'); |
---|
105 | fwrite($file, $data); |
---|
106 | fclose($file); |
---|
107 | //chmod the file so it can be altered by cronjobs in future |
---|
108 | @chmod(getcwd().'/cache/api/'.config::get('API_Name_'.$keyindex).'_KillLog.xml',0666); |
---|
109 | } |
---|
110 | } |
---|
111 | } else { |
---|
112 | // re-use cached XML |
---|
113 | $this->Output_ .= "<i>Using cached XML file for " . config::get('API_Name_'.$keyindex) . "</i><br><br>"; |
---|
114 | $logsource = "Cache"; |
---|
115 | |
---|
116 | if ($fp = @fopen(getcwd().'/cache/api/'.config::get('API_Name_'.$keyindex).'_KillLog.xml', 'r')) { |
---|
117 | $data = fread($fp, filesize(getcwd().'/cache/api/'.config::get('API_Name_'.$keyindex).'_KillLog.xml')); |
---|
118 | fclose($fp); |
---|
119 | } else { |
---|
120 | return "<i>error loading cached file ".config::get('API_Name_'.$keyindex)."_KillLog.xml</i><br><br>"; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | $xml_parser = xml_parser_create(); |
---|
125 | xml_set_object ( $xml_parser, $this ); |
---|
126 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
127 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
128 | |
---|
129 | if (!xml_parse($xml_parser, $data, true)) |
---|
130 | return $this->Output_ .= "<i>Error getting XML data from api.eve-online.com</i><br><br>"; |
---|
131 | |
---|
132 | if ( strlen($data) == 28 ) |
---|
133 | return $this->Output_ .= "<i>Error contacting api.eve-online.com</i><br><br>"; |
---|
134 | |
---|
135 | xml_parser_free($xml_parser); |
---|
136 | |
---|
137 | if ( ($this->hasdownloaded_ == false) && ($this->errortext_ != "") ) |
---|
138 | { |
---|
139 | $this->Output_ .= "<font color = \"#FF0000\">".$this->errortext_ . "</font><br>"; |
---|
140 | $logsource = "Error"; |
---|
141 | } |
---|
142 | |
---|
143 | if ($this->mailcount_) |
---|
144 | $this->Output_ .= "<div class=block-header2>".$this->mailcount_." kills, " . $this->malformedmails_ . " malformed, " . $this->ignoredmails_ . " ignored and " . $this->verified_ . " verified from feed: " . config::get('API_Name_'.$keyindex) . " which contained ".$this->totalmails_." mails.<br></div>"; |
---|
145 | else |
---|
146 | $this->Output_ .= "<div class=block-header2>No kills added, ". $this->malformedmails_ . " malformed, " . $this->ignoredmails_." ignored and " . $this->verified_ . " verified from feed: " . config::get('API_Name_'.$keyindex) . " which contained ".$this->totalmails_." mails.<br></div>"; |
---|
147 | |
---|
148 | // Write to kb3_apilog |
---|
149 | $qry = new DBQuery(); |
---|
150 | if ($this->iscronjob_) |
---|
151 | $logtype = "Cron Job"; |
---|
152 | else |
---|
153 | $logtype = "Manual"; |
---|
154 | |
---|
155 | $qry->execute( "insert into kb3_apilog values( '" . KB_SITE . "', '" |
---|
156 | . config::get('API_Name_'.$keyindex) . "'," |
---|
157 | . $this->mailcount_ . "," |
---|
158 | . $this->malformedmails_ . "," |
---|
159 | . $this->ignoredmails_ . "," |
---|
160 | . $this->verified_ . "," |
---|
161 | . $this->totalmails_ . ",'" |
---|
162 | . $logsource . "','" |
---|
163 | . $logtype . "',now() )" ); |
---|
164 | |
---|
165 | return $this->Output_; |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | function startElement($parser, $name, $attribs) |
---|
170 | { |
---|
171 | if($this->killmailExists_ && ($name != "ROW" || !is_numeric($attribs['KILLID']))) return; |
---|
172 | else $this->killmailExists_ = false; |
---|
173 | if ($name == "ROWSET") |
---|
174 | { |
---|
175 | //echo $this->rowsetCounter_ . " "; |
---|
176 | if (($this->pname_ == "") && ($this->typeid_ != "0")) |
---|
177 | { |
---|
178 | $this->isContainer = true; |
---|
179 | // this is to catch containers that spawn a new rowset so are missed off loot |
---|
180 | if ($this->qtydropped_ !=0) |
---|
181 | { |
---|
182 | // dropped items |
---|
183 | $this->droppeditems_['typeid'][] = $this->typeid_; |
---|
184 | $this->droppeditems_['qty'][] = $this->qtydropped_; |
---|
185 | //if ($this->isContainer) |
---|
186 | //{ |
---|
187 | // $this->droppeditems_['flag'][] = -1; |
---|
188 | //} else { |
---|
189 | $this->droppeditems_['flag'][] = $this->itemFlag_; |
---|
190 | //} |
---|
191 | } |
---|
192 | if ($this->qtydestroyed_ != 0) |
---|
193 | { |
---|
194 | // destroyed items |
---|
195 | $this->destroyeditems_['typeid'][] =$this->typeid_; |
---|
196 | $this->destroyeditems_['qty'][] = $this->qtydestroyed_; |
---|
197 | // if ($this->isContainer) |
---|
198 | //{ |
---|
199 | // $this->destroyeditems_['flag'][] = -1; |
---|
200 | //} else { |
---|
201 | $this->destroyeditems_['flag'][] = $this->itemFlag_; |
---|
202 | //} |
---|
203 | } |
---|
204 | $this->typeid_ = 0; |
---|
205 | $this->itemFlag_ = 0; |
---|
206 | $this->qtydropped_ = 0; |
---|
207 | $this->qtydestroyed_ = 0; |
---|
208 | } |
---|
209 | // goes after so container itself doesn't count as "(in countainer) |
---|
210 | |
---|
211 | } |
---|
212 | |
---|
213 | if (count($attribs)) |
---|
214 | { |
---|
215 | foreach ($attribs as $k => $v) |
---|
216 | { |
---|
217 | switch ($k) |
---|
218 | { |
---|
219 | case "CHARACTERID": |
---|
220 | $this->charid_ = $v; |
---|
221 | break; |
---|
222 | case "CHARACTERNAME": |
---|
223 | $this->pname_ = $v; |
---|
224 | |
---|
225 | // Error Correction is on (0 = on, 1 = off(I know, just don't ask)) |
---|
226 | if ( $this->API_CCPErrorCorrecting == 0 ) |
---|
227 | { |
---|
228 | if ( ($this->charid_ != "0" ) && (strlen($this->pname_) == 0) ) |
---|
229 | { |
---|
230 | // name is blank but ID is valid - convert ID into name |
---|
231 | $this->myIDName->clear(); |
---|
232 | $this->myIDName->setIDs($this->charid_); |
---|
233 | $this->Output_ .= $this->myIDName->fetchXML(); |
---|
234 | $myNames = $this->myIDName->getIDData(); |
---|
235 | $this->pname_ = $myNames[0]['name']; |
---|
236 | } |
---|
237 | } |
---|
238 | break; |
---|
239 | case "CORPORATIONID": |
---|
240 | $this->corporationID_ = $v; |
---|
241 | break; |
---|
242 | case "CORPORATIONNAME": |
---|
243 | $this->corporation_ = $v; |
---|
244 | |
---|
245 | // Error Correction is on (0 = on, 1 = off(I know, just don't ask)) |
---|
246 | if ( $this->API_CCPErrorCorrecting == 0 ) |
---|
247 | { |
---|
248 | if ( ($this->corporationID_ != "0" ) && (strlen($this->corporation_) == 0) ) |
---|
249 | { // name is blank but ID is valid - convert ID into name |
---|
250 | $this->myIDName->clear(); |
---|
251 | $this->myIDName->setIDs($this->corporationID_); |
---|
252 | $this->Output_ .= $this->myIDName->fetchXML(); |
---|
253 | $myNames = $this->myIDName->getIDData(); |
---|
254 | $this->corporation_ = $myNames[0]['name']; |
---|
255 | } |
---|
256 | } |
---|
257 | break; |
---|
258 | case "ALLIANCEID": |
---|
259 | $this->allianceID_ = $v; |
---|
260 | break; |
---|
261 | case "ALLIANCENAME": |
---|
262 | $this->alliance_ = $v; |
---|
263 | |
---|
264 | // Error Correction is on (0 = on, 1 = off(I know, just don't ask)) |
---|
265 | //if ( $this->API_CCPErrorCorrecting == 0 ) |
---|
266 | // conditional branch removed - ALWAYS fix alliance name bugs |
---|
267 | { |
---|
268 | if ( ($this->allianceID_ != "0" ) && (strlen($this->alliance_) == 0) ) |
---|
269 | { // name is blank but ID is valid - convert ID into name |
---|
270 | $this->myIDName->clear(); |
---|
271 | $this->myIDName->setIDs($this->allianceID_); |
---|
272 | $this->Output_ .= $this->myIDName->fetchXML(); |
---|
273 | $myNames = $this->myIDName->getIDData(); |
---|
274 | $this->alliance_ = $myNames[0]['name']; |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | if (strlen($this->alliance_) == 0) |
---|
279 | $this->alliance_ = "NONE"; |
---|
280 | break; |
---|
281 | case "DAMAGETAKEN": |
---|
282 | $this->damagetaken_ = $v; |
---|
283 | break; |
---|
284 | case "DAMAGEDONE": |
---|
285 | $this->damagedone_ = $v; |
---|
286 | break; |
---|
287 | case "SHIPTYPEID": |
---|
288 | if ($v == 0) |
---|
289 | { |
---|
290 | $this->shipname_ = "Unknown"; |
---|
291 | } else { |
---|
292 | $this->shipname_ = gettypeIDname($v); |
---|
293 | } |
---|
294 | break; |
---|
295 | case "FINALBLOW": |
---|
296 | $this->finalblow_ = $v; |
---|
297 | break; |
---|
298 | case "SECURITYSTATUS": |
---|
299 | //$this->security_ = $v; |
---|
300 | $this->security_ = round($v,2); // allows number to pass with strict settings (number is usually much longer than 5 chars as defined in DB) |
---|
301 | break; |
---|
302 | case "WEAPONTYPEID": |
---|
303 | $this->weapon_ = gettypeIDname($v); |
---|
304 | break; |
---|
305 | // for items |
---|
306 | case "TYPEID": |
---|
307 | $this->typeid_ = gettypeIDname($v); |
---|
308 | |
---|
309 | // Missing Item correction |
---|
310 | if ($this->typeid_ == "") |
---|
311 | { |
---|
312 | $this->myIDName->clear(); |
---|
313 | $this->myIDName->setIDs($v); |
---|
314 | $this->Output_ .= $this->myIDName->fetchXML(); |
---|
315 | $myNames = $this->myIDName->getIDData(); |
---|
316 | //$this->typeid_ = "Item missing from DB: " . $myNames[0]['name']; |
---|
317 | $this->typeid_ = $myNames[0]['name']; |
---|
318 | } |
---|
319 | break; |
---|
320 | case "FLAG": |
---|
321 | $this->itemFlag_ = $v; |
---|
322 | break; |
---|
323 | case "QTYDROPPED": |
---|
324 | $this->qtydropped_ = $v; |
---|
325 | break; |
---|
326 | case "QTYDESTROYED": |
---|
327 | $this->qtydestroyed_ = $v; |
---|
328 | break; |
---|
329 | |
---|
330 | // for system/kill mail details (start of mail) |
---|
331 | case "KILLID": |
---|
332 | // print mail here - this will miss the last mail but it can be caught on exit. This weird way of doing things prevents falling foul |
---|
333 | // of the CCP API cargo bug - using function, avoids the repetition |
---|
334 | if ($this->beforekillid_ != 0) |
---|
335 | { |
---|
336 | $this->parseendofmail(); |
---|
337 | } |
---|
338 | $this->killid_ = $v; // added v2.6 for help tracing erroneous mails |
---|
339 | $this->totalmails_++; // Count total number of mails in XML feed |
---|
340 | if ($this->isKillIDVerified($v) != null) |
---|
341 | { |
---|
342 | $this->killmailExists_ = true; |
---|
343 | unset($this->destroyeditems_ ); |
---|
344 | unset($this->droppeditems_); |
---|
345 | $this->beforekillid_ = 0; |
---|
346 | return; |
---|
347 | } else { |
---|
348 | $this->killmailExists_ = false; |
---|
349 | $this->beforekillid_ = $v; |
---|
350 | } |
---|
351 | break; |
---|
352 | case "SOLARSYSTEMID": // convert to system name and fetch system security - DONE |
---|
353 | $sql = 'select sys.sys_name, sys.sys_sec from kb3_systems sys where sys.sys_eve_id = '.$v; |
---|
354 | |
---|
355 | $qry = new DBQuery(); |
---|
356 | $qry->execute($sql); |
---|
357 | $row = $qry->getRow(); |
---|
358 | |
---|
359 | $this->systemname_ = $row['sys_name']; |
---|
360 | $mysec = $row['sys_sec']; |
---|
361 | if ($mysec <= 0) |
---|
362 | $this->systemsecurity_ = number_format(0.0, 1); |
---|
363 | else |
---|
364 | $this->systemsecurity_ = number_format(round($mysec, 1), 1); |
---|
365 | break; |
---|
366 | case "MOONID": // only given with POS related stuff - unanchored mods however, do not have a moonid. |
---|
367 | $this->moonid_ = $v; |
---|
368 | |
---|
369 | $this->moonname_ = getMoonName($v); |
---|
370 | // Missing Moon DB correction |
---|
371 | if (($this->moonname_ == "") && ($this->moonid_ != 0)) |
---|
372 | { |
---|
373 | $this->myIDName->clear(); |
---|
374 | $this->myIDName->setIDs($v); |
---|
375 | $this->Output_ .= $this->myIDName->fetchXML(); |
---|
376 | $myNames = $this->myIDName->getIDData(); |
---|
377 | //$this->typeid_ = "Item missing from DB: " . $myNames[0]['name']; |
---|
378 | $this->moonname_ = $myNames[0]['name']; |
---|
379 | } |
---|
380 | break; |
---|
381 | case "KILLTIME": // Time Kill took place |
---|
382 | $this->killtime_ = $v; |
---|
383 | break; |
---|
384 | case "FACTIONID": // Faction ID |
---|
385 | $this->factionid_ = $v; |
---|
386 | break; |
---|
387 | case "FACTIONNAME": // Faction Name |
---|
388 | if ( $v == "" ) { |
---|
389 | $this->factionname_ = "NONE"; |
---|
390 | } else { |
---|
391 | $this->factionname_ = $v; |
---|
392 | } |
---|
393 | break; |
---|
394 | case "CODE": // error code |
---|
395 | $this->errorcode_ .= $v; |
---|
396 | break; |
---|
397 | } |
---|
398 | } |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | function endElement($parser, $name) |
---|
403 | { |
---|
404 | if($this->killmailExists_) return; |
---|
405 | switch ($name) |
---|
406 | { |
---|
407 | case "ROWSET": |
---|
408 | $this->isContainer = false; |
---|
409 | break; |
---|
410 | case "VICTIM": |
---|
411 | $this->hasdownloaded_ = true; |
---|
412 | // if no name is given and moonid != 0 then replace name with corp name for parsing - would lookup the moonid but we don't have that in database - replace shipname as "Unknown" this allows parsing to complete |
---|
413 | if ($this->moonid_ != 0 && $this->pname_ == "") |
---|
414 | { |
---|
415 | $this->pname_ = $this->moonname_; |
---|
416 | //$this->shipname_ = "Unknown"; // this is done else mail will not parse |
---|
417 | $this->isposkill_ = true; |
---|
418 | } elseif (($this->moonid_ == 0) && ($this->pname_ == "") && ($this->charid_ != 0)) { |
---|
419 | // catches unanchored POS modules - as moon is unknown, we will use system name instead |
---|
420 | $this->pname_ = $this->systemname_; |
---|
421 | $this->isposkill_ = true; |
---|
422 | } else { |
---|
423 | $this->isposkill_ = false; |
---|
424 | } |
---|
425 | // print victim header |
---|
426 | $this->killmail_ = substr(str_replace('-', '.' , $this->killtime_), 0, 16) . "\r\n\r\n"; |
---|
427 | if ($this->isposkill_ == false ) |
---|
428 | $this->killmail_ .= "Victim: ".$this->pname_ . "\r\n"; // This line would not appear on a POS mail |
---|
429 | $this->killmail_ .= "Corp: ".$this->corporation_ . "\r\n"; |
---|
430 | $this->killmail_ .= "Alliance: ".$this->alliance_ . "\r\n"; |
---|
431 | $this->killmail_ .= "Faction: ".$this->factionname_ . "\r\n"; |
---|
432 | $this->killmail_ .= "Destroyed: ".$this->shipname_ . "\r\n"; |
---|
433 | if ($this->isposkill_ == true ) |
---|
434 | $this->killmail_ .= "Moon: ".$this->moonname_ . "\r\n"; // This line does appear on a POS mail |
---|
435 | $this->killmail_ .= "System: ".$this->systemname_ . "\r\n"; |
---|
436 | $this->killmail_ .= "Security: ".$this->systemsecurity_ . "\r\n"; |
---|
437 | $this->killmail_ .= "Damage Taken: ".$this->damagetaken_ . "\r\n\r\n"; |
---|
438 | $this->killmail_ .= "Involved parties:\r\n\r\n"; |
---|
439 | |
---|
440 | if ( config::get('API_Update') == 0 ) |
---|
441 | { |
---|
442 | // update Victim portrait while we're here |
---|
443 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $this->pname_ . '"'; |
---|
444 | |
---|
445 | $qry = new DBQuery(); |
---|
446 | $qry->execute($sql); |
---|
447 | $row = $qry->getRow(); |
---|
448 | if ($qry->recordCount() != 0) |
---|
449 | { |
---|
450 | $pilot_id = $row['plt_id']; |
---|
451 | $pilot_external_id = $row['plt_externalid']; |
---|
452 | |
---|
453 | if ( $pilot_external_id == 0 && $pilot_id != 0) |
---|
454 | { |
---|
455 | // update DB with ID |
---|
456 | $qry->execute("update kb3_pilots set plt_externalid = " . intval($this->charid_) . " |
---|
457 | where plt_id = " . $pilot_id); |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | // update crp_external_id |
---|
463 | Update_CorpID($this->corporation_, $this->corporationID_); |
---|
464 | // update all_external_id |
---|
465 | if ($this->allianceID_ != 0) |
---|
466 | Update_AllianceID($this->alliance_, $this->allianceID_); |
---|
467 | |
---|
468 | // set victim corp and alliance for FF check |
---|
469 | $this->valliance_ = $this->alliance_; |
---|
470 | $this->vcorp_ = $this->corporation_; |
---|
471 | |
---|
472 | // now clear these |
---|
473 | //$this->killtime_ = ""; |
---|
474 | $this->pname_ = ""; |
---|
475 | $this->alliance_ = ""; |
---|
476 | $this->factionname_ = ""; |
---|
477 | $this->corporation_ = ""; |
---|
478 | $this->destroyed_ = 0; |
---|
479 | $this->systemname_ = ""; |
---|
480 | $this->systemsecurity_ = 0; |
---|
481 | $this->damagetaken_ = 0; |
---|
482 | $this->charid_ = 0; |
---|
483 | $this->moonid_ = 0; |
---|
484 | $this->mooname_ = 0; |
---|
485 | $this->corporationID_ = 0; |
---|
486 | $this->allianceID_ = 0; |
---|
487 | break; |
---|
488 | case "ROW": |
---|
489 | if ( $this->typeid_ != "0" ) |
---|
490 | { |
---|
491 | // it's cargo |
---|
492 | if ($this->qtydropped_ !=0) |
---|
493 | { |
---|
494 | // dropped items |
---|
495 | $this->droppeditems_['typeid'][] = $this->typeid_; |
---|
496 | $this->droppeditems_['qty'][] = $this->qtydropped_; |
---|
497 | if ($this->isContainer) |
---|
498 | { |
---|
499 | $this->droppeditems_['flag'][] = -1; |
---|
500 | } else { |
---|
501 | $this->droppeditems_['flag'][] = $this->itemFlag_; |
---|
502 | } |
---|
503 | } |
---|
504 | if ($this->qtydestroyed_ != 0) |
---|
505 | { |
---|
506 | // destroyed items |
---|
507 | $this->destroyeditems_['typeid'][] = $this->typeid_; |
---|
508 | $this->destroyeditems_['qty'][] = $this->qtydestroyed_; |
---|
509 | if ($this->isContainer) |
---|
510 | { |
---|
511 | $this->destroyeditems_['flag'][] = -1; |
---|
512 | } else { |
---|
513 | $this->destroyeditems_['flag'][] = $this->itemFlag_; |
---|
514 | } |
---|
515 | } |
---|
516 | $this->typeid_ = 0; |
---|
517 | $this->itemFlag_ = 0; |
---|
518 | $this->qtydropped_ = 0; |
---|
519 | $this->qtydestroyed_ = 0; |
---|
520 | } |
---|
521 | // using corporation_ not pname_ as NPCs don't have a name *** CHANGED to corporationID 16/03/2009 to catch 'sleeper' NPCs |
---|
522 | if ($this->corporationID_ != 0) |
---|
523 | { |
---|
524 | // it's an attacker |
---|
525 | $this->attackerslist_['name'][] = $this->pname_; |
---|
526 | $this->attackerslist_['finalblow'][] = $this->finalblow_; |
---|
527 | $this->attackerslist_['security'][] = $this->security_; |
---|
528 | $this->attackerslist_['corporation'][] = $this->corporation_; |
---|
529 | $this->attackerslist_['alliance'][] = $this->alliance_; |
---|
530 | $this->attackerslist_['faction'][] = $this->factionname_; |
---|
531 | $this->attackerslist_['shiptypeid'][] = $this->shipname_; |
---|
532 | $this->attackerslist_['weapon'][] = $this->weapon_; |
---|
533 | $this->attackerslist_['damagedone'][] = $this->damagedone_; |
---|
534 | |
---|
535 | if ( config::get('API_Update') == 0 ) |
---|
536 | { |
---|
537 | // update Attacker portrait while we're here |
---|
538 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $this->pname_ . '"'; |
---|
539 | |
---|
540 | $qry = new DBQuery(); |
---|
541 | $qry->execute($sql); |
---|
542 | $row = $qry->getRow(); |
---|
543 | if ($qry->recordCount() != 0) |
---|
544 | { |
---|
545 | $pilot_id = $row['plt_id']; |
---|
546 | $pilot_external_id = $row['plt_externalid']; |
---|
547 | |
---|
548 | if ( $pilot_external_id == 0 && $pilot_id != 0 ) |
---|
549 | { |
---|
550 | // update DB with ID |
---|
551 | $qry->execute("update kb3_pilots set plt_externalid = " . intval($this->charid_) . " |
---|
552 | where plt_id = " . $pilot_id); |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | |
---|
557 | // update crp_external_id |
---|
558 | Update_CorpID($this->corporation_, $this->corporationID_); |
---|
559 | // update all_external_id |
---|
560 | if ($this->allianceID_ != 0) |
---|
561 | Update_AllianceID($this->alliance_, $this->allianceID_); |
---|
562 | |
---|
563 | $this->pname_ = ""; |
---|
564 | $this->finalblow_ = 0; |
---|
565 | $this->security_ = 0; |
---|
566 | $this->alliance_ = ""; |
---|
567 | $this->factionname_ = ""; |
---|
568 | $this->corporation_ = ""; |
---|
569 | $this->shipname_ = 0; |
---|
570 | $this->weapon_ = 0; |
---|
571 | $this->damagedone_ = 0; |
---|
572 | $this->charid_ = 0; |
---|
573 | $this->corporationID_ = 0; |
---|
574 | $this->allianceID_ = 0; |
---|
575 | } |
---|
576 | break; |
---|
577 | case "RESULT": |
---|
578 | // reset beforekillid to allow processing of more chunks of data I've placed into $data |
---|
579 | $this->beforekillid_ = 0; |
---|
580 | |
---|
581 | // does last killmail |
---|
582 | if ($this->hasdownloaded_) |
---|
583 | { |
---|
584 | // catch to prevent processing without any mails |
---|
585 | $this->parseendofmail(); |
---|
586 | } |
---|
587 | break; |
---|
588 | case "MYXML": |
---|
589 | // end of data xml, process cachedtime here |
---|
590 | //$ApiCache->set('API_CachedUntil_' . $this->keyindex_, $this->cachetext_); |
---|
591 | break; |
---|
592 | case "ERROR": // Error Message |
---|
593 | if ($this->errortext_ == "") |
---|
594 | { |
---|
595 | $this->errortext_ .= $this->characterDataValue; |
---|
596 | } |
---|
597 | break; |
---|
598 | case "CURRENTTIME": |
---|
599 | $this->CurrentTime_ = $this->characterDataValue; |
---|
600 | break; |
---|
601 | case "CACHEDUNTIL": |
---|
602 | // kill log can be several xml sheets stuck together, we only want the first CachedUntil_ |
---|
603 | if ($this->CachedUntil_ == "") |
---|
604 | { |
---|
605 | // Do not save cache key if this is an error sheet |
---|
606 | $this->CachedUntil_ = $this->characterDataValue; |
---|
607 | ApiCache::set('API_CachedUntil_' . $this->keyindex_, $this->CachedUntil_); |
---|
608 | } |
---|
609 | break; |
---|
610 | } |
---|
611 | } |
---|
612 | |
---|
613 | function characterData($parser, $data) |
---|
614 | { |
---|
615 | $this->characterDataValue = $data; |
---|
616 | } |
---|
617 | |
---|
618 | function parseendofmail() |
---|
619 | { |
---|
620 | // print attacks |
---|
621 | $attackercounter = count($this->attackerslist_['name']); |
---|
622 | // sort array into descending damage |
---|
623 | if ($attackercounter != 0 ) |
---|
624 | { |
---|
625 | array_multisort($this->attackerslist_['damagedone'], SORT_NUMERIC, SORT_DESC, |
---|
626 | $this->attackerslist_['name'], SORT_ASC, SORT_STRING, |
---|
627 | $this->attackerslist_['finalblow'], SORT_NUMERIC, SORT_DESC, |
---|
628 | $this->attackerslist_['security'], SORT_NUMERIC, SORT_DESC, |
---|
629 | $this->attackerslist_['corporation'], SORT_ASC, SORT_STRING, |
---|
630 | $this->attackerslist_['alliance'], SORT_ASC, SORT_STRING, |
---|
631 | $this->attackerslist_['faction'], SORT_ASC, SORT_STRING, |
---|
632 | $this->attackerslist_['shiptypeid'], SORT_ASC, SORT_STRING, |
---|
633 | $this->attackerslist_['weapon'], SORT_ASC, SORT_STRING ); |
---|
634 | } |
---|
635 | |
---|
636 | // Initialise some flags to use |
---|
637 | $hasplayersonmail = false; |
---|
638 | $this->corpFF_ = true; |
---|
639 | $this->allianceFF_ = true; |
---|
640 | $poswasfriendly = false; |
---|
641 | |
---|
642 | // catch for victim being in no alliance |
---|
643 | if ($this->valliance_ == "NONE") |
---|
644 | $this->allianceFF_ = false; |
---|
645 | |
---|
646 | for ($attackerx = 0; $attackerx < $attackercounter; $attackerx++) |
---|
647 | { |
---|
648 | // if NPC (name will be "") then set pname_ as corporation_ for mail parsing |
---|
649 | if ($this->attackerslist_['name'][$attackerx] == "") |
---|
650 | { |
---|
651 | // fix for Sleepers ("Unknown") |
---|
652 | if ($this->attackerslist_['corporation'][$attackerx] == "") |
---|
653 | { |
---|
654 | $npccorpname = "Unknown"; |
---|
655 | } else { |
---|
656 | $npccorpname = $this->attackerslist_['corporation'][$attackerx]; |
---|
657 | } |
---|
658 | $this->killmail_ .= "Name: ".$this->attackerslist_['shiptypeid'][$attackerx] ." / ".$npccorpname."\r\n"; |
---|
659 | $this->killmail_ .= "Damage Done: ".$this->attackerslist_['damagedone'][$attackerx]."\r\n"; |
---|
660 | $this->corpFF_ = false; |
---|
661 | $this->allianceFF_ = false; |
---|
662 | } else { |
---|
663 | $hasplayersonmail = true; |
---|
664 | $this->killmail_ .= "Name: ".$this->attackerslist_['name'][$attackerx]; |
---|
665 | if ($this->attackerslist_['finalblow'][$attackerx] == 1) |
---|
666 | { |
---|
667 | $this->killmail_ .= " (laid the final blow)"; |
---|
668 | } |
---|
669 | $this->killmail_ .= "\r\n"; |
---|
670 | |
---|
671 | $this->killmail_ .= "Security: ".$this->attackerslist_['security'][$attackerx]."\r\n"; |
---|
672 | $this->killmail_ .= "Corp: ".$this->attackerslist_['corporation'][$attackerx]."\r\n"; |
---|
673 | $this->killmail_ .= "Alliance: ".$this->attackerslist_['alliance'][$attackerx]."\r\n"; |
---|
674 | $this->killmail_ .= "Faction: ".$this->attackerslist_['faction'][$attackerx]."\r\n"; |
---|
675 | $this->killmail_ .= "Ship: ".$this->attackerslist_['shiptypeid'][$attackerx]."\r\n"; |
---|
676 | $this->killmail_ .= "Weapon: ".$this->attackerslist_['weapon'][$attackerx]."\r\n"; |
---|
677 | $this->killmail_ .= "Damage Done: ".$this->attackerslist_['damagedone'][$attackerx]."\r\n"; |
---|
678 | |
---|
679 | // set Friendly Fire matches |
---|
680 | if ($this->attackerslist_['alliance'][$attackerx] != $this->valliance_) |
---|
681 | $this->allianceFF_ = false; |
---|
682 | if ($this->attackerslist_['corporation'][$attackerx] != $this->vcorp_) |
---|
683 | $this->corpFF_ = false; |
---|
684 | } |
---|
685 | $this->killmail_ .= "\r\n"; |
---|
686 | } //end for next loop |
---|
687 | |
---|
688 | // clear attackerslist |
---|
689 | $this->attackerslist_ = array(); |
---|
690 | |
---|
691 | if (count($this->destroyeditems_['qty']) != 0) |
---|
692 | { |
---|
693 | $this->killmail_ .= "\r\nDestroyed items:\r\n\r\n"; |
---|
694 | |
---|
695 | $counter = count($this->destroyeditems_['qty']); |
---|
696 | for ($x = 0; $x < $counter; $x++) |
---|
697 | { |
---|
698 | if ($this->destroyeditems_['qty'][$x] > 1) |
---|
699 | { |
---|
700 | // show quantity |
---|
701 | $this->killmail_ .= $this->destroyeditems_['typeid'][$x].", Qty: ".$this->destroyeditems_['qty'][$x]; |
---|
702 | } else { |
---|
703 | // just the one |
---|
704 | $this->killmail_ .= $this->destroyeditems_['typeid'][$x]; |
---|
705 | } |
---|
706 | |
---|
707 | if ($this->destroyeditems_['flag'][$x] == 5) { |
---|
708 | $this->killmail_ .= " (Cargo)"; |
---|
709 | } elseif ($this->destroyeditems_['flag'][$x] == 87) { |
---|
710 | $this->killmail_ .= " (Drone Bay)"; |
---|
711 | } elseif ($this->destroyeditems_['flag'][$x] == -1) |
---|
712 | { |
---|
713 | $this->killmail_ .= " (In Container)"; |
---|
714 | } |
---|
715 | $this->killmail_ .= "\r\n"; |
---|
716 | } |
---|
717 | } |
---|
718 | |
---|
719 | if (count($this->droppeditems_['qty']) != 0) |
---|
720 | { |
---|
721 | $this->killmail_ .= "\r\nDropped items:\r\n\r\n"; |
---|
722 | |
---|
723 | $counter = count($this->droppeditems_['qty']); |
---|
724 | for ($x = 0; $x < $counter; $x++) |
---|
725 | { |
---|
726 | if ($this->droppeditems_['qty'][$x] > 1) |
---|
727 | { |
---|
728 | // show quantity |
---|
729 | $this->killmail_ .= $this->droppeditems_['typeid'][$x].", Qty: ".$this->droppeditems_['qty'][$x]; |
---|
730 | } else { |
---|
731 | // just the one |
---|
732 | $this->killmail_ .= $this->droppeditems_['typeid'][$x]; |
---|
733 | } |
---|
734 | |
---|
735 | if ($this->droppeditems_['flag'][$x] == 5) |
---|
736 | { |
---|
737 | $this->killmail_ .= " (Cargo)"; |
---|
738 | } elseif ($this->droppeditems_['flag'][$x] == 87) |
---|
739 | { |
---|
740 | $this->killmail_ .= " (Drone Bay)"; |
---|
741 | } elseif ($this->droppeditems_['flag'][$x] == -1) |
---|
742 | { |
---|
743 | $this->killmail_ .= " (In Container)"; |
---|
744 | } |
---|
745 | $this->killmail_ .= "\r\n"; |
---|
746 | } |
---|
747 | } |
---|
748 | |
---|
749 | // If ignoring friendly POS Structures |
---|
750 | if ($this->isposkill_) { |
---|
751 | // is board an alliance board? |
---|
752 | if ( ALLIANCE_ID == 0) |
---|
753 | { |
---|
754 | // no it's set as a corp |
---|
755 | $thiscorp = new Corporation(CORP_ID); |
---|
756 | if ( $this->vcorp_ == $thiscorp->getName() ) |
---|
757 | $poswasfriendly = true; |
---|
758 | } else { |
---|
759 | // yes it's an Alliance board |
---|
760 | $thisalliance = new Alliance(ALLIANCE_ID); |
---|
761 | if ( $this->valliance_ == $thisalliance->getName() ) |
---|
762 | $poswasfriendly = true; |
---|
763 | } |
---|
764 | } |
---|
765 | |
---|
766 | if ( ( $this->API_IgnoreFriendPos_ == 0 ) && ( $poswasfriendly ) && ( $this->isposkill_ ) ) |
---|
767 | { |
---|
768 | if ( ( $this->API_NoSpam_ == 0 ) && ( $this->iscronjob_ ) ) |
---|
769 | { |
---|
770 | // do not write to $this->Output_ |
---|
771 | } else { |
---|
772 | $this->Output_ .= "Killmail ID:".$this->killid_." containing friendly POS structure has been ignored.<br>"; |
---|
773 | } |
---|
774 | $this->ignoredmails_++; |
---|
775 | } elseif ( ( $this->API_IgnoreEnemyPos_ == 0 ) && ( !$poswasfriendly ) && ( $this->isposkill_ ) ) |
---|
776 | { |
---|
777 | if ( ( $this->API_NoSpam_ == 0 ) && ( $this->iscronjob_ ) ) |
---|
778 | { |
---|
779 | // do not write to $this->Output_ |
---|
780 | } else { |
---|
781 | $this->Output_ .= "Killmail ID:".$this->killid_." containing enemy POS structure been ignored.<br>"; |
---|
782 | } |
---|
783 | $this->ignoredmails_++; |
---|
784 | } elseif ( ( $this->API_IgnoreNPC_ == 0 ) && ($hasplayersonmail == false) ) |
---|
785 | { |
---|
786 | if ( ( $this->API_NoSpam_ == 0 ) && ( $this->iscronjob_ ) ) |
---|
787 | { |
---|
788 | // do not write to $this->Output_ |
---|
789 | } else { |
---|
790 | $this->Output_ .= "Killmail ID:".$this->killid_." containing only NPCs has been ignored.<br>"; |
---|
791 | } |
---|
792 | $this->ignoredmails_++; |
---|
793 | } elseif ( ( $this->API_IgnoreCorpFF_ == 0 ) && ($this->corpFF_ == true ) ) |
---|
794 | { |
---|
795 | if ( ( $this->API_NoSpam_ == 0 ) && ( $this->iscronjob_ ) ) |
---|
796 | { |
---|
797 | // do not write to $this->Output_ |
---|
798 | } else { |
---|
799 | $this->Output_ .= "Killmail ID:".$this->killid_." containing corporation friendly fire has been ignored.<br>"; |
---|
800 | } |
---|
801 | $this->ignoredmails_++; |
---|
802 | } elseif ( ( $this->API_IgnoreAllianceFF_ == 0 ) && ($this->allianceFF_ == true ) ) |
---|
803 | { |
---|
804 | if ( ( $this->API_NoSpam_ == 0 ) && ( $this->iscronjob_) ) |
---|
805 | { |
---|
806 | // do not write to $this->Output_ |
---|
807 | } else { |
---|
808 | $this->Output_ .= "Killmail ID:".$this->killid_." containing alliance friendly fire has been ignored.<br>"; |
---|
809 | } |
---|
810 | $this->ignoredmails_++; |
---|
811 | } else { |
---|
812 | $this->postimportmail(); |
---|
813 | } |
---|
814 | |
---|
815 | // clear destroyed/dropped arrays |
---|
816 | unset($this->destroyeditems_ ); |
---|
817 | unset($this->droppeditems_); |
---|
818 | } |
---|
819 | |
---|
820 | function postimportmail() |
---|
821 | { |
---|
822 | if ( ( isset( $this->killmail_ ) ) && ( !$this->killmailExists_ ) ) |
---|
823 | { |
---|
824 | $parser = new Parser( $this->killmail_ ); |
---|
825 | //$killid = $parser->parse( true ); |
---|
826 | |
---|
827 | if (config::get('filter_apply')) |
---|
828 | { |
---|
829 | $filterdate = config::get('filter_date'); |
---|
830 | $year = substr($this->killmail_, 0, 4); |
---|
831 | $month = substr($this->killmail_, 5, 2); |
---|
832 | $day = substr($this->killmail_, 8, 2); |
---|
833 | $killstamp = mktime(0, 0, 0, $month, $day, $year); |
---|
834 | if ($killstamp < $filterdate) |
---|
835 | { |
---|
836 | $killid = -3; |
---|
837 | } |
---|
838 | else |
---|
839 | { |
---|
840 | $killid = $parser->parse(true); |
---|
841 | } |
---|
842 | } else { |
---|
843 | $killid = $parser->parse(true); |
---|
844 | } |
---|
845 | |
---|
846 | if ( $killid == 0 || $killid == -1 || $killid == -2 || $killid == -3 ) |
---|
847 | { |
---|
848 | if ( $killid == 0 ) |
---|
849 | { |
---|
850 | $this->Output_ .= "Killmail ID:".$this->killid_." is malformed.<br>"; |
---|
851 | $this->malformedmails_++; |
---|
852 | |
---|
853 | if ($errors = $parser->getError()) |
---|
854 | { |
---|
855 | foreach ($errors as $error) |
---|
856 | { |
---|
857 | $this->Output_ .= 'Error: '.$error[0]; |
---|
858 | if ($error[1]) |
---|
859 | { |
---|
860 | $this->Output_ .= ' The text lead to this error was: "'.$error[1].'"<br>'; |
---|
861 | } |
---|
862 | } |
---|
863 | |
---|
864 | //if ( $this->iscronjob_ ) |
---|
865 | //{ |
---|
866 | // $this->Output_ .= $this->killmail_; // experimental - output the killmail as the API Parser understood it |
---|
867 | //} else { |
---|
868 | // $this->Output_ .= str_replace("\r\n", "<br>", $this->killmail_); |
---|
869 | //} |
---|
870 | $this->Output_ .= '<br/>'; |
---|
871 | } |
---|
872 | } |
---|
873 | if ($killid == -3) |
---|
874 | { |
---|
875 | $filterdate = kbdate("j F Y", config::get("filter_date")); |
---|
876 | //$html = "Killmail older than $filterdate ignored."; |
---|
877 | $this->Output_ .= "Killmail ID:".$this->killid_. " has been ignored as mails before $filterdate are restricted.<br>"; |
---|
878 | $this->ignoredmails_++; |
---|
879 | } |
---|
880 | |
---|
881 | if ( $killid == -2 ) |
---|
882 | { |
---|
883 | $this->Output_ .= "Killmail ID:".$this->killid_. " is not related to ".KB_TITLE.".<br>"; |
---|
884 | $this->ignoredmails_++; |
---|
885 | } |
---|
886 | // Killmail exists - as we're here and the mail was posted, it is not a verified mail, so verify it now. |
---|
887 | if ( $killid == -1 ) |
---|
888 | { |
---|
889 | if ( ( $this->API_NoSpam_ == 0 ) && ( $this->iscronjob_ ) ) |
---|
890 | { |
---|
891 | // do not write to $this->Output_ |
---|
892 | } else { |
---|
893 | // $this->Output_ .= "Killmail already exists <a href=\"?a=kill_detail&kll_id=".$parser->dupeid_."\">here</a>.<br>"; |
---|
894 | // write API KillID to kb3_kills killID column row $parser->dupeid_ |
---|
895 | $this->VerifyKill($this->killid_, $parser->dupeid_); |
---|
896 | $this->verified_++; |
---|
897 | } |
---|
898 | } |
---|
899 | } else { |
---|
900 | $qry = new DBQuery(); |
---|
901 | $qry->execute( "insert into kb3_log values( ".$killid.", '".KB_SITE."','API ".APIVERSION."',now() )" ); |
---|
902 | $this->Output_ .= "API Killmail ID:".$this->killid_. " successfully imported <a href=\"?a=kill_detail&kll_id=".$killid."\">here</a> as KB ID:". $killid ."<br>"; |
---|
903 | |
---|
904 | // Now place killID (API) into killboard row $killid |
---|
905 | $this->VerifyKill($this->killid_, $killid); |
---|
906 | |
---|
907 | // mail forward |
---|
908 | event::call('killmail_imported', $this); |
---|
909 | |
---|
910 | // For testing purposes |
---|
911 | //$this->Output_ .= str_replace("\r\n", "<br>", $this->killmail_); |
---|
912 | |
---|
913 | if ( file_exists("common/includes/class.comments.php") ) |
---|
914 | require_once( "common/includes/class.comments.php" ); |
---|
915 | if (class_exists('Comments') && config::get('API_Comment')) { // for the Eve-Dev Comment Class |
---|
916 | $comments = new Comments($killid); |
---|
917 | $comments->addComment("Captain Thunks API " . APIVERSION, config::get('API_Comment')); |
---|
918 | } |
---|
919 | $this->mailcount_++; |
---|
920 | } |
---|
921 | } |
---|
922 | } |
---|
923 | |
---|
924 | function loaddata($refid, $keystring, $typestring) |
---|
925 | { |
---|
926 | $url = "http://api.eve-online.com/" . $typestring . "/KillLog.xml.aspx"; |
---|
927 | |
---|
928 | if ($refid != 0) |
---|
929 | $keystring .= '&beforeKillID=' . $refid; |
---|
930 | |
---|
931 | $path = '/' . $typestring . '/Killlog.xml.aspx'; |
---|
932 | $fp = fsockopen("api.eve-online.com", 80); |
---|
933 | |
---|
934 | if (!$fp) |
---|
935 | { |
---|
936 | $this->Output_ .= "Could not connect to API URL"; |
---|
937 | } else { |
---|
938 | // request the xml |
---|
939 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
940 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
941 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
942 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
943 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
944 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
945 | fputs ($fp, $keystring."\r\n"); |
---|
946 | |
---|
947 | // retrieve contents |
---|
948 | $contents = ""; |
---|
949 | while (!feof($fp)) |
---|
950 | { |
---|
951 | $contents .= fgets($fp); |
---|
952 | } |
---|
953 | |
---|
954 | // close connection |
---|
955 | fclose($fp); |
---|
956 | |
---|
957 | $start = strpos($contents, "?>"); |
---|
958 | if ($start !== FALSE) |
---|
959 | { |
---|
960 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
961 | } |
---|
962 | } |
---|
963 | return $contents; |
---|
964 | } |
---|
965 | |
---|
966 | function mystrripos($haystack, $needle, $offset=0) |
---|
967 | { |
---|
968 | if($offset<0) |
---|
969 | { |
---|
970 | $temp_cut = strrev( substr( $haystack, 0, abs($offset) ) ); |
---|
971 | } else { |
---|
972 | $temp_cut = strrev( substr( $haystack, $offset ) ); |
---|
973 | } |
---|
974 | $pos = strlen($haystack) - (strpos($temp_cut, strrev($needle)) + $offset + strlen($needle)); |
---|
975 | if ($pos == strlen($haystack)) { $pos = 0; } |
---|
976 | |
---|
977 | if(strpos($temp_cut, strrev($needle))===false) |
---|
978 | { |
---|
979 | return false; |
---|
980 | } else return $pos; |
---|
981 | } |
---|
982 | |
---|
983 | function getlastkillid($data) |
---|
984 | { |
---|
985 | $mylastkillid = 0; |
---|
986 | $startpoint = intval; |
---|
987 | $endpoint = intval; |
---|
988 | |
---|
989 | $startpoint = $this->mystrripos($data, 'row killID="'); |
---|
990 | if ( $startpoint != "0" ) |
---|
991 | { |
---|
992 | $startpoint = $startpoint + 12; |
---|
993 | $endpoint = strpos($data, '"', $startpoint); |
---|
994 | $mylength = $endpoint-$startpoint; |
---|
995 | $mylastkillid = substr($data, $startpoint, $mylength); |
---|
996 | } |
---|
997 | return $mylastkillid; |
---|
998 | } |
---|
999 | |
---|
1000 | function getAllianceName($v) |
---|
1001 | { |
---|
1002 | $alliancenamereturn = ""; |
---|
1003 | |
---|
1004 | $counter = count($this->alliancearray_['Name']); |
---|
1005 | for ($x = 0; $x < $counter; $x++) |
---|
1006 | { |
---|
1007 | if ($this->alliancearray_['allianceID'][$x] == $v) |
---|
1008 | $alliancenamereturn = $this->alliancearray_['Name'][$x]; |
---|
1009 | } |
---|
1010 | |
---|
1011 | return $alliancenamereturn; |
---|
1012 | } |
---|
1013 | |
---|
1014 | function VerifyKill($killid, $mailid) |
---|
1015 | { |
---|
1016 | $qry = new DBQuery(); |
---|
1017 | $qry->execute( "UPDATE `kb3_kills` SET `kll_external_id` = '" . $killid . "' WHERE `kb3_kills`.`kll_id` =" . $mailid . " LIMIT 1" ); |
---|
1018 | } |
---|
1019 | |
---|
1020 | function isKillIDVerified($killid) |
---|
1021 | { |
---|
1022 | $qry = new DBQuery(); |
---|
1023 | $qry->execute( "SELECT * FROM `kb3_kills` WHERE `kll_external_id` =" . $killid ); |
---|
1024 | $row = $qry->getRow(); |
---|
1025 | return $row['kll_external_id']; |
---|
1026 | } |
---|
1027 | } |
---|
1028 | |
---|
1029 | // ********************************************************************************************************************************************** |
---|
1030 | // **************** API Char list - /account/Characters.xml.aspx **************** |
---|
1031 | // ********************************************************************************************************************************************** |
---|
1032 | |
---|
1033 | class APIChar |
---|
1034 | { |
---|
1035 | function fetchChars($apistring) |
---|
1036 | { |
---|
1037 | $data = $this->loaddata($apistring); |
---|
1038 | |
---|
1039 | $xml_parser = xml_parser_create(); |
---|
1040 | xml_set_object ( $xml_parser, $this ); |
---|
1041 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1042 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1043 | |
---|
1044 | if (!xml_parse($xml_parser, $data, true)) |
---|
1045 | return "<i>Error getting XML data from api.eve-online.com/account/Characters.xml.aspx </i><br><br>"; |
---|
1046 | |
---|
1047 | xml_parser_free($xml_parser); |
---|
1048 | |
---|
1049 | // add any characters not already in the kb |
---|
1050 | $numchars = count($this->chars_); |
---|
1051 | for ( $x = 0; $x < $numchars; $x++ ) |
---|
1052 | { |
---|
1053 | // check if chars eveid exists in kb |
---|
1054 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $this->chars_[$x]['Name'] . '"'; |
---|
1055 | |
---|
1056 | $qry = new DBQuery(); |
---|
1057 | $qry->execute($sql); |
---|
1058 | if ($qry->recordCount() != 0) |
---|
1059 | { |
---|
1060 | // pilot is in kb db, check he has his char id |
---|
1061 | $row = $qry->getRow(); |
---|
1062 | |
---|
1063 | $pilot_id = $row['plt_id']; |
---|
1064 | $pilot_external_id = $row['plt_externalid']; |
---|
1065 | |
---|
1066 | if ( $pilot_external_id == 0 && $pilot_id != 0 ) |
---|
1067 | { |
---|
1068 | // update DB with ID |
---|
1069 | $qry->execute("update kb3_pilots set plt_externalid = " . intval($this->chars_[$x]['charID']) . " |
---|
1070 | where plt_id = " . $pilot_id); |
---|
1071 | } |
---|
1072 | } else { |
---|
1073 | // pilot is not in DB |
---|
1074 | |
---|
1075 | // Set Corp |
---|
1076 | $pilotscorp = new Corporation(); |
---|
1077 | $pilotscorp->lookup($this->chars_[$x]['corpName']); |
---|
1078 | // Check Corp was set, if not, add the Corp |
---|
1079 | if ( !$pilotscorp->getID() ) |
---|
1080 | { |
---|
1081 | $ialliance = new Alliance(); |
---|
1082 | $ialliance->add('NONE'); |
---|
1083 | $pilotscorp->add($this->chars_[$x]['corpName'], $ialliance, gmdate("Y-m-d H:i:s")); |
---|
1084 | } |
---|
1085 | $ipilot = new Pilot(); |
---|
1086 | $ipilot->add($this->chars_[$x]['Name'], $pilotscorp, gmdate("Y-m-d H:i:s")); |
---|
1087 | $ipilot->setCharacterID(intval($this->chars_[$x]['charID'])); |
---|
1088 | } |
---|
1089 | } |
---|
1090 | |
---|
1091 | return $this->chars_; |
---|
1092 | } |
---|
1093 | |
---|
1094 | function startElement($parser, $name, $attribs) |
---|
1095 | { |
---|
1096 | global $character; |
---|
1097 | |
---|
1098 | if ($name == "ROW") |
---|
1099 | { |
---|
1100 | if (count($attribs)) |
---|
1101 | { |
---|
1102 | foreach ($attribs as $k => $v) |
---|
1103 | { |
---|
1104 | switch ($k) |
---|
1105 | { |
---|
1106 | case "NAME": |
---|
1107 | $character['Name'] = $v; |
---|
1108 | break; |
---|
1109 | case "CORPORATIONNAME": |
---|
1110 | $character['corpName'] = $v; |
---|
1111 | break; |
---|
1112 | case "CHARACTERID": |
---|
1113 | $character['charID'] = $v; |
---|
1114 | break; |
---|
1115 | case "CORPORATIONID": |
---|
1116 | $character['corpID'] = $v; |
---|
1117 | break; |
---|
1118 | } |
---|
1119 | } |
---|
1120 | } |
---|
1121 | } |
---|
1122 | } |
---|
1123 | |
---|
1124 | function endElement($parser, $name) |
---|
1125 | { |
---|
1126 | global $character; |
---|
1127 | |
---|
1128 | if ($name == "ROW") |
---|
1129 | { |
---|
1130 | $this->chars_[] = $character; |
---|
1131 | $character = array(); |
---|
1132 | unset($character); |
---|
1133 | } |
---|
1134 | } |
---|
1135 | |
---|
1136 | function characterData($parser, $data) |
---|
1137 | { |
---|
1138 | // nothing |
---|
1139 | } |
---|
1140 | |
---|
1141 | function loaddata($apistring) |
---|
1142 | { |
---|
1143 | $path = '/account/Characters.xml.aspx'; |
---|
1144 | $fp = fsockopen("api.eve-online.com", 80); |
---|
1145 | |
---|
1146 | if (!$fp) |
---|
1147 | { |
---|
1148 | echo "Error", "Could not connect to API URL<br>"; |
---|
1149 | } else { |
---|
1150 | // request the xml |
---|
1151 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
1152 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
1153 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
1154 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
1155 | fputs ($fp, "Content-Length: " . strlen($apistring) . "\r\n"); |
---|
1156 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
1157 | fputs ($fp, $apistring."\r\n"); |
---|
1158 | |
---|
1159 | // retrieve contents |
---|
1160 | $contents = ""; |
---|
1161 | while (!feof($fp)) |
---|
1162 | { |
---|
1163 | $contents .= fgets($fp); |
---|
1164 | } |
---|
1165 | |
---|
1166 | // close connection |
---|
1167 | fclose($fp); |
---|
1168 | |
---|
1169 | $start = strpos($contents, "?>"); |
---|
1170 | if ($start != false) |
---|
1171 | { |
---|
1172 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
1173 | } |
---|
1174 | } |
---|
1175 | return $contents; |
---|
1176 | } |
---|
1177 | } |
---|
1178 | |
---|
1179 | // ********************************************************************************************************************************************** |
---|
1180 | // **************** API Alliance list - /eve/AllianceList.xml.aspx **************** |
---|
1181 | // ********************************************************************************************************************************************** |
---|
1182 | |
---|
1183 | class AllianceAPI |
---|
1184 | { |
---|
1185 | function getCachedUntil() |
---|
1186 | { |
---|
1187 | return $this->CachedUntil_; |
---|
1188 | } |
---|
1189 | |
---|
1190 | function getCurrentTime() |
---|
1191 | { |
---|
1192 | return $this->CurrentTime_; |
---|
1193 | } |
---|
1194 | |
---|
1195 | |
---|
1196 | function initXML() |
---|
1197 | { |
---|
1198 | global $myalliancelist; |
---|
1199 | |
---|
1200 | $data = LoadGlobalData('/eve/AllianceList.xml.aspx'); |
---|
1201 | |
---|
1202 | $xml_parser = xml_parser_create(); |
---|
1203 | xml_set_object ( $xml_parser, $this ); |
---|
1204 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1205 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1206 | |
---|
1207 | if (!xml_parse($xml_parser, $data, true)) |
---|
1208 | return false; |
---|
1209 | |
---|
1210 | xml_parser_free($xml_parser); |
---|
1211 | return true; |
---|
1212 | } |
---|
1213 | |
---|
1214 | function fetchalliances($overide=false) |
---|
1215 | { |
---|
1216 | global $myalliancelist; |
---|
1217 | |
---|
1218 | if (!isset($this->alliances_)) |
---|
1219 | $this->initXML($overide); |
---|
1220 | |
---|
1221 | return $myalliancelist; |
---|
1222 | } |
---|
1223 | |
---|
1224 | function startElement($parser, $name, $attribs) |
---|
1225 | { |
---|
1226 | global $myalliancelist, $alliancedetail, $membercorps, $membercorp, $iscorpsection; |
---|
1227 | |
---|
1228 | if ($name == "ROW") |
---|
1229 | { |
---|
1230 | if (count($attribs)) |
---|
1231 | { |
---|
1232 | foreach ($attribs as $k => $v) |
---|
1233 | { |
---|
1234 | switch ($k) |
---|
1235 | { |
---|
1236 | case "NAME": |
---|
1237 | $alliancedetail['allianceName'] = $v; |
---|
1238 | break; |
---|
1239 | case "SHORTNAME": |
---|
1240 | $alliancedetail['shortName'] = $v; |
---|
1241 | break; |
---|
1242 | case "ALLIANCEID": |
---|
1243 | $alliancedetail['allianceID'] = $v; |
---|
1244 | break; |
---|
1245 | case "EXECUTORCORPID": |
---|
1246 | $alliancedetail['executorCorpID'] = $v; |
---|
1247 | break; |
---|
1248 | case "MEMBERCOUNT": |
---|
1249 | $alliancedetail['memberCount'] = $v; |
---|
1250 | break; |
---|
1251 | case "STARTDATE": |
---|
1252 | if (!$iscorpsection) |
---|
1253 | { |
---|
1254 | $alliancedetail['startDate'] = $v; |
---|
1255 | } else { |
---|
1256 | $membercorp['startDate'] = $v; |
---|
1257 | $membercorps[] = $membercorp; |
---|
1258 | } |
---|
1259 | break; |
---|
1260 | case "CORPORATIONID": |
---|
1261 | $membercorp['corporationID'] = $v; |
---|
1262 | $iscorpsection = true; |
---|
1263 | break; |
---|
1264 | } |
---|
1265 | } |
---|
1266 | } |
---|
1267 | } |
---|
1268 | } |
---|
1269 | |
---|
1270 | function endElement($parser, $name) |
---|
1271 | { |
---|
1272 | global $myalliancelist, $alliancedetail, $membercorps, $membercorp, $iscorpsection; |
---|
1273 | global $tempvalue; |
---|
1274 | |
---|
1275 | if ($name == "CURRENTTIME") |
---|
1276 | $this->CurrentTime_ = $tempvalue; |
---|
1277 | if ($name == "CACHEDUNTIL") |
---|
1278 | { |
---|
1279 | if (config::get('API_extendedtimer_alliancelist') == 0) |
---|
1280 | { |
---|
1281 | $this->CachedUntil_ = date("Y-m-d H:i:s", (strtotime($this->CurrentTime_)) + 85500); |
---|
1282 | } else { |
---|
1283 | $this->CachedUntil_ = $tempvalue; |
---|
1284 | } |
---|
1285 | ApiCache::set('API_eve_AllianceList' , $this->CachedUntil_); |
---|
1286 | } |
---|
1287 | |
---|
1288 | switch ($name) |
---|
1289 | { |
---|
1290 | case "ROWSET": |
---|
1291 | if ($alliancedetail['allianceName'] != "" && $alliancedetail['allianceID'] != "0") |
---|
1292 | { |
---|
1293 | $myalliancelist['Name'][] = $alliancedetail['allianceName']; |
---|
1294 | $myalliancelist['allianceID'][] = $alliancedetail['allianceID']; |
---|
1295 | } |
---|
1296 | $alliancedetail['memberCorps'] = $membercorps; |
---|
1297 | $this->alliances_[] = $alliancedetail; |
---|
1298 | |
---|
1299 | $alliancedetail['allianceName'] = ""; |
---|
1300 | $alliancedetail['shortName'] = ""; |
---|
1301 | $alliancedetail['allianceID'] = ""; |
---|
1302 | $alliancedetail['executorCorpID'] = ""; |
---|
1303 | $alliancedetail['memberCount'] = ""; |
---|
1304 | $alliancedetail['startDate'] = ""; |
---|
1305 | $alliancedetail['memberCorps'] = array(); |
---|
1306 | $membercorps = array(); |
---|
1307 | $membercorp = array(); |
---|
1308 | unset($alliancedetail['memberCorps']); |
---|
1309 | unset($membercorps); |
---|
1310 | unset($membercorp); |
---|
1311 | $iscorpsection = false; |
---|
1312 | break; |
---|
1313 | } |
---|
1314 | } |
---|
1315 | |
---|
1316 | function characterData($parser, $data) |
---|
1317 | { |
---|
1318 | global $tempvalue; |
---|
1319 | |
---|
1320 | $tempvalue = $data; |
---|
1321 | } |
---|
1322 | |
---|
1323 | function updatealliancetable() |
---|
1324 | { |
---|
1325 | if (!isset($this->alliances_)) |
---|
1326 | $this->initXML(); |
---|
1327 | |
---|
1328 | if (!isset($this->alliances_)) |
---|
1329 | return false; |
---|
1330 | |
---|
1331 | $qry = new DBQuery(); |
---|
1332 | $qry->execute("DROP TABLE IF EXISTS `kb3_all_corp`;"); |
---|
1333 | $qry->execute("CREATE TABLE kb3_all_corp ( |
---|
1334 | all_id bigint(3) unsigned default '0', |
---|
1335 | corp_id bigint(3) unsigned default '0', |
---|
1336 | all_name varchar(200) default NULL |
---|
1337 | ) "); |
---|
1338 | |
---|
1339 | $alliances = $this->alliances_; |
---|
1340 | |
---|
1341 | foreach ($alliances as $arraykey => $arrayvalue) |
---|
1342 | { |
---|
1343 | $tempally = $arrayvalue; |
---|
1344 | |
---|
1345 | foreach ($tempally as $key => $value) |
---|
1346 | { |
---|
1347 | switch ($key) |
---|
1348 | { |
---|
1349 | case "allianceName": |
---|
1350 | $allyname = $value; |
---|
1351 | break; |
---|
1352 | case "allianceID": |
---|
1353 | $allyid = $value; |
---|
1354 | break; |
---|
1355 | case "memberCorps": |
---|
1356 | $allycorps = $value; |
---|
1357 | $q=''; |
---|
1358 | foreach ($allycorps as $corpkey => $corpvalue) |
---|
1359 | { |
---|
1360 | $tempcorp = $corpvalue; |
---|
1361 | foreach ($tempcorp as $tempkey => $tempvalue) |
---|
1362 | { |
---|
1363 | switch ($tempkey) |
---|
1364 | { |
---|
1365 | case "corporationID": |
---|
1366 | $q.="(".$allyid.",".$tempvalue.",'".slashfix($allyname)."'),"; |
---|
1367 | break; |
---|
1368 | } |
---|
1369 | } |
---|
1370 | } |
---|
1371 | if (strlen($q)>0) |
---|
1372 | $qry->execute("INSERT INTO kb3_all_corp values ".substr($q,0,strlen($q)-1)); |
---|
1373 | break; |
---|
1374 | } |
---|
1375 | } |
---|
1376 | } |
---|
1377 | return true; |
---|
1378 | } |
---|
1379 | |
---|
1380 | function LocateAlliance($name) |
---|
1381 | { |
---|
1382 | if (!isset($this->alliances_)) |
---|
1383 | $this->initXML(); |
---|
1384 | |
---|
1385 | if (!isset($this->alliances_)) |
---|
1386 | return false; |
---|
1387 | |
---|
1388 | $alliances = $this->alliances_; |
---|
1389 | |
---|
1390 | foreach ($alliances as $arraykey => $arrayvalue) |
---|
1391 | { |
---|
1392 | $tempally = $arrayvalue; |
---|
1393 | |
---|
1394 | foreach ($tempally as $key => $value) |
---|
1395 | { |
---|
1396 | switch ($key) |
---|
1397 | { |
---|
1398 | case "allianceName": |
---|
1399 | //return $tempally; |
---|
1400 | if ( $value == $name ) |
---|
1401 | { |
---|
1402 | return $tempally; |
---|
1403 | } |
---|
1404 | break; |
---|
1405 | } |
---|
1406 | } |
---|
1407 | } |
---|
1408 | return false; |
---|
1409 | } |
---|
1410 | |
---|
1411 | function LocateAllianceID($id) |
---|
1412 | { |
---|
1413 | if (!isset($this->alliances_)) |
---|
1414 | $this->initXML(); |
---|
1415 | |
---|
1416 | if (!isset($this->alliances_)) |
---|
1417 | return false; |
---|
1418 | |
---|
1419 | $alliances = $this->alliances_; |
---|
1420 | |
---|
1421 | foreach ($alliances as $arraykey => $arrayvalue) |
---|
1422 | { |
---|
1423 | $tempally = $arrayvalue; |
---|
1424 | |
---|
1425 | foreach ($tempally as $key => $value) |
---|
1426 | { |
---|
1427 | switch ($key) |
---|
1428 | { |
---|
1429 | case "allianceID": |
---|
1430 | //return $tempally; |
---|
1431 | if ( $value == $id ) |
---|
1432 | { |
---|
1433 | return $tempally; |
---|
1434 | } |
---|
1435 | break; |
---|
1436 | } |
---|
1437 | } |
---|
1438 | } |
---|
1439 | return false; |
---|
1440 | } |
---|
1441 | |
---|
1442 | function UpdateAlliances($andCorps = false) |
---|
1443 | { |
---|
1444 | if (!isset($this->alliances_)) |
---|
1445 | $this->initXML(); |
---|
1446 | |
---|
1447 | if (!isset($this->alliances_)) |
---|
1448 | return false; |
---|
1449 | |
---|
1450 | if ($andCorps) |
---|
1451 | { |
---|
1452 | // Remove every single corp in the Killboard DB from their current Alliance |
---|
1453 | $db = new DBQuery(true); |
---|
1454 | $db->execute("UPDATE kb3_corps |
---|
1455 | SET crp_all_id = 14"); |
---|
1456 | } |
---|
1457 | |
---|
1458 | $alliances = $this->alliances_; |
---|
1459 | $alliance = new Alliance(); |
---|
1460 | $tempMyCorp = new Corporation(); |
---|
1461 | $myCorpAPI = new API_CorporationSheet(); |
---|
1462 | |
---|
1463 | $NumberOfAlliances = 0; |
---|
1464 | $NumberOfCorps = 0; |
---|
1465 | $NumberOfAlliancesAdded = 0; // we won't know this |
---|
1466 | $NumberOfCorpsAdded = 0; |
---|
1467 | |
---|
1468 | foreach ($alliances as $arraykey => $arrayvalue) |
---|
1469 | { |
---|
1470 | $tempally = $arrayvalue; |
---|
1471 | $NumberOfAlliances++; |
---|
1472 | |
---|
1473 | foreach ($tempally as $key => $value) |
---|
1474 | { |
---|
1475 | switch ($key) |
---|
1476 | { |
---|
1477 | case "allianceName": |
---|
1478 | $alliance->add($value); |
---|
1479 | break; |
---|
1480 | case "memberCorps": |
---|
1481 | // if $andCorps = true then add each and every single corp to the evekb db - resolving each name (expect this to be slow) |
---|
1482 | // WARNING: Processing 5000+ corps this way is extremely slow and is almost guaranteed not to complete |
---|
1483 | if ($andCorps) |
---|
1484 | { |
---|
1485 | foreach ($value as $tempcorp) |
---|
1486 | { |
---|
1487 | $NumberOfCorps++; |
---|
1488 | |
---|
1489 | $myCorpAPI->setCorpID($tempcorp["corporationID"]); |
---|
1490 | $result .= $myCorpAPI->fetchXML(); |
---|
1491 | |
---|
1492 | //$NumberOfCorpsAdded++; |
---|
1493 | $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , gmdate("Y-m-d H:i:s")); |
---|
1494 | |
---|
1495 | } |
---|
1496 | |
---|
1497 | } |
---|
1498 | break; |
---|
1499 | } |
---|
1500 | } |
---|
1501 | } |
---|
1502 | $returnarray["NumAlliances"] = $NumberOfAlliances; |
---|
1503 | $returnarray["NumCorps"] = $NumberOfCorps; |
---|
1504 | $returnarray["NumAlliancesAdded"] = $NumberOfAlliancesAdded; |
---|
1505 | $returnarray["NumCorpsAdded"] = $NumberOfCorpsAdded; |
---|
1506 | return $returnarray; |
---|
1507 | |
---|
1508 | } |
---|
1509 | } |
---|
1510 | |
---|
1511 | // ********************************************************************************************************************************************** |
---|
1512 | // **************** API Conquerable Station/Outpost list - /eve/ConquerableStationList.xml.aspx **************** |
---|
1513 | // ********************************************************************************************************************************************** |
---|
1514 | |
---|
1515 | class API_ConquerableStationList |
---|
1516 | { |
---|
1517 | function getCachedUntil() |
---|
1518 | { |
---|
1519 | return $this->CachedUntil_; |
---|
1520 | } |
---|
1521 | |
---|
1522 | function getCurrentTime() |
---|
1523 | { |
---|
1524 | return $this->CurrentTime_; |
---|
1525 | } |
---|
1526 | |
---|
1527 | function getStations() |
---|
1528 | { |
---|
1529 | return $this->Stations_; |
---|
1530 | } |
---|
1531 | |
---|
1532 | function fetchXML() |
---|
1533 | { |
---|
1534 | $data = LoadGlobalData('/eve/ConquerableStationList.xml.aspx'); |
---|
1535 | |
---|
1536 | $xml_parser = xml_parser_create(); |
---|
1537 | xml_set_object ( $xml_parser, $this ); |
---|
1538 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1539 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1540 | |
---|
1541 | if (!xml_parse($xml_parser, $data, true)) |
---|
1542 | return "<i>Error getting XML data from api.eve-online.com/eve/ConquerableStationList.xml.aspx </i><br><br>"; |
---|
1543 | |
---|
1544 | xml_parser_free($xml_parser); |
---|
1545 | |
---|
1546 | return $this->html; |
---|
1547 | } |
---|
1548 | |
---|
1549 | function startElement($parser, $name, $attribs) |
---|
1550 | { |
---|
1551 | global $Station; |
---|
1552 | |
---|
1553 | if ($name == "ROW") |
---|
1554 | { |
---|
1555 | if (count($attribs)) |
---|
1556 | { |
---|
1557 | foreach ($attribs as $k => $v) |
---|
1558 | { |
---|
1559 | switch ($k) |
---|
1560 | { |
---|
1561 | case "STATIONID": |
---|
1562 | $Station['stationID'] = $v; |
---|
1563 | break; |
---|
1564 | case "STATIONNAME": |
---|
1565 | $Station['stationName'] = $v; |
---|
1566 | break; |
---|
1567 | case "STATIONTYPEID": |
---|
1568 | $Station['stationTypeID'] = $v; |
---|
1569 | break; |
---|
1570 | case "SOLARSYSTEMID": |
---|
1571 | $Station['solarSystemID'] = $v; |
---|
1572 | break; |
---|
1573 | case "CORPORATIONID": |
---|
1574 | $Station['corporationID'] = $v; |
---|
1575 | break; |
---|
1576 | case "CORPORATIONNAME": |
---|
1577 | $Station['corporationName'] = $v; |
---|
1578 | break; |
---|
1579 | } |
---|
1580 | } |
---|
1581 | } |
---|
1582 | } |
---|
1583 | } |
---|
1584 | |
---|
1585 | function endElement($parser, $name) |
---|
1586 | { |
---|
1587 | global $Station; |
---|
1588 | global $tempvalue; |
---|
1589 | |
---|
1590 | if ($name == "CURRENTTIME") |
---|
1591 | $this->CurrentTime_ = $tempvalue; |
---|
1592 | if ($name == "CACHEDUNTIL") |
---|
1593 | { |
---|
1594 | if (config::get('API_extendedtimer_conq') == 0) |
---|
1595 | { |
---|
1596 | $this->CachedUntil_ = date("Y-m-d H:i:s", (strtotime($this->CurrentTime_)) + 85500); |
---|
1597 | } else { |
---|
1598 | $this->CachedUntil_ = $tempvalue; |
---|
1599 | } |
---|
1600 | ApiCache::set('API_eve_ConquerableStationList' , $this->CachedUntil_); |
---|
1601 | } |
---|
1602 | |
---|
1603 | if ($name == "ROW") |
---|
1604 | { |
---|
1605 | $this->Stations_[] = $Station; |
---|
1606 | $Station = array(); |
---|
1607 | unset($Station); |
---|
1608 | } |
---|
1609 | } |
---|
1610 | |
---|
1611 | function characterData($parser, $data) |
---|
1612 | { |
---|
1613 | global $tempvalue; |
---|
1614 | |
---|
1615 | $tempvalue = $data; |
---|
1616 | } |
---|
1617 | } |
---|
1618 | |
---|
1619 | // ********************************************************************************************************************************************** |
---|
1620 | // **************** API Error list - /eve/ErrorList.xml.aspx **************** |
---|
1621 | // ********************************************************************************************************************************************** |
---|
1622 | |
---|
1623 | class API_ErrorList |
---|
1624 | { |
---|
1625 | function getCachedUntil() |
---|
1626 | { |
---|
1627 | return $this->CachedUntil_; |
---|
1628 | } |
---|
1629 | |
---|
1630 | function getCurrentTime() |
---|
1631 | { |
---|
1632 | return $this->CurrentTime_; |
---|
1633 | } |
---|
1634 | |
---|
1635 | function getErrorList() |
---|
1636 | { |
---|
1637 | return $this->Error_; |
---|
1638 | } |
---|
1639 | |
---|
1640 | function fetchXML() |
---|
1641 | { |
---|
1642 | $data = LoadGlobalData('/eve/ErrorList.xml.aspx'); |
---|
1643 | |
---|
1644 | $xml_parser = xml_parser_create(); |
---|
1645 | xml_set_object ( $xml_parser, $this ); |
---|
1646 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1647 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1648 | |
---|
1649 | if (!xml_parse($xml_parser, $data, true)) |
---|
1650 | return "<i>Error getting XML data from api.eve-online.com/eve/ErrorList.xml.aspx </i><br><br>"; |
---|
1651 | |
---|
1652 | xml_parser_free($xml_parser); |
---|
1653 | |
---|
1654 | return $this->html; |
---|
1655 | } |
---|
1656 | |
---|
1657 | function startElement($parser, $name, $attribs) |
---|
1658 | { |
---|
1659 | global $ErrorData; |
---|
1660 | |
---|
1661 | if ($name == "ROW") |
---|
1662 | { |
---|
1663 | if (count($attribs)) |
---|
1664 | { |
---|
1665 | foreach ($attribs as $k => $v) |
---|
1666 | { |
---|
1667 | switch ($k) |
---|
1668 | { |
---|
1669 | case "ERRORCODE": |
---|
1670 | $ErrorData['errorCode'] = $v; |
---|
1671 | break; |
---|
1672 | case "ERRORTEXT": |
---|
1673 | $ErrorData['errorText'] = $v; |
---|
1674 | break; |
---|
1675 | } |
---|
1676 | } |
---|
1677 | } |
---|
1678 | } |
---|
1679 | } |
---|
1680 | |
---|
1681 | function endElement($parser, $name) |
---|
1682 | { |
---|
1683 | global $ErrorData; |
---|
1684 | global $tempvalue; |
---|
1685 | |
---|
1686 | if ($name == "CURRENTTIME") |
---|
1687 | $this->CurrentTime_ = $tempvalue; |
---|
1688 | if ($name == "CACHEDUNTIL") |
---|
1689 | { |
---|
1690 | $this->CachedUntil_ = $tempvalue; |
---|
1691 | ApiCache::set('API_eve_ErrorList' , $tempvalue); |
---|
1692 | } |
---|
1693 | |
---|
1694 | if ($name == "ROW") |
---|
1695 | { |
---|
1696 | $this->Error_[] = $ErrorData; |
---|
1697 | $ErrorData = array(); |
---|
1698 | unset($ErrorData); |
---|
1699 | } |
---|
1700 | } |
---|
1701 | |
---|
1702 | function characterData($parser, $data) |
---|
1703 | { |
---|
1704 | global $tempvalue; |
---|
1705 | |
---|
1706 | $tempvalue = $data; |
---|
1707 | } |
---|
1708 | } |
---|
1709 | |
---|
1710 | // ********************************************************************************************************************************************** |
---|
1711 | // **************** API Jumps list - /map/Jumps.xml.aspx **************** |
---|
1712 | // ********************************************************************************************************************************************** |
---|
1713 | |
---|
1714 | class API_Jumps |
---|
1715 | { |
---|
1716 | function getCachedUntil() |
---|
1717 | { |
---|
1718 | return $this->CachedUntil_; |
---|
1719 | } |
---|
1720 | |
---|
1721 | function getCurrentTime() |
---|
1722 | { |
---|
1723 | return $this->CurrentTime_; |
---|
1724 | } |
---|
1725 | |
---|
1726 | function getDataTime() |
---|
1727 | { |
---|
1728 | return $this->DataTime_; |
---|
1729 | } |
---|
1730 | |
---|
1731 | function getJumps() |
---|
1732 | { |
---|
1733 | return $this->Jumps_; |
---|
1734 | } |
---|
1735 | |
---|
1736 | function fetchXML() |
---|
1737 | { |
---|
1738 | $data = LoadGlobalData('/map/Jumps.xml.aspx'); |
---|
1739 | |
---|
1740 | $xml_parser = xml_parser_create(); |
---|
1741 | xml_set_object ( $xml_parser, $this ); |
---|
1742 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1743 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1744 | |
---|
1745 | if (!xml_parse($xml_parser, $data, true)) |
---|
1746 | return "<i>Error getting XML data from api.eve-online.com/map/Jumps.xml.aspx </i><br><br>"; |
---|
1747 | |
---|
1748 | xml_parser_free($xml_parser); |
---|
1749 | |
---|
1750 | return $this->html; |
---|
1751 | } |
---|
1752 | |
---|
1753 | function startElement($parser, $name, $attribs) |
---|
1754 | { |
---|
1755 | global $JumpData; |
---|
1756 | |
---|
1757 | if ($name == "ROW") |
---|
1758 | { |
---|
1759 | if (count($attribs)) |
---|
1760 | { |
---|
1761 | foreach ($attribs as $k => $v) |
---|
1762 | { |
---|
1763 | switch ($k) |
---|
1764 | { |
---|
1765 | case "SOLARSYSTEMID": |
---|
1766 | $JumpData['solarSystemID'] = $v; |
---|
1767 | break; |
---|
1768 | case "SHIPJUMPS": |
---|
1769 | $JumpData['shipJumps'] = $v; |
---|
1770 | break; |
---|
1771 | } |
---|
1772 | } |
---|
1773 | } |
---|
1774 | } |
---|
1775 | } |
---|
1776 | |
---|
1777 | function endElement($parser, $name) |
---|
1778 | { |
---|
1779 | global $JumpData; |
---|
1780 | global $tempvalue; |
---|
1781 | |
---|
1782 | if ($name == "CURRENTTIME") |
---|
1783 | $this->CurrentTime_ = $tempvalue; |
---|
1784 | if ($name == "DATATIME") |
---|
1785 | $this->DataTime_ = $tempvalue; |
---|
1786 | if ($name == "CACHEDUNTIL") |
---|
1787 | { |
---|
1788 | $this->CachedUntil_ = $tempvalue; |
---|
1789 | ApiCache::set('API_map_Jumps' , $tempvalue); |
---|
1790 | } |
---|
1791 | |
---|
1792 | if ($name == "ROW") |
---|
1793 | { |
---|
1794 | $this->Jumps_[] = $JumpData; |
---|
1795 | $JumpData = array(); |
---|
1796 | unset($JumpData); |
---|
1797 | } |
---|
1798 | } |
---|
1799 | |
---|
1800 | function characterData($parser, $data) |
---|
1801 | { |
---|
1802 | global $tempvalue; |
---|
1803 | |
---|
1804 | $tempvalue = $data; |
---|
1805 | } |
---|
1806 | } |
---|
1807 | |
---|
1808 | // ********************************************************************************************************************************************** |
---|
1809 | // **************** API Kills list - /map/Kills.xml.aspx **************** |
---|
1810 | // ********************************************************************************************************************************************** |
---|
1811 | |
---|
1812 | class API_Kills |
---|
1813 | { |
---|
1814 | function getCachedUntil() |
---|
1815 | { |
---|
1816 | return $this->CachedUntil_; |
---|
1817 | } |
---|
1818 | |
---|
1819 | function getCurrentTime() |
---|
1820 | { |
---|
1821 | return $this->CurrentTime_; |
---|
1822 | } |
---|
1823 | |
---|
1824 | function getDataTime() |
---|
1825 | { |
---|
1826 | return $this->DataTime_; |
---|
1827 | } |
---|
1828 | |
---|
1829 | function getkills() |
---|
1830 | { |
---|
1831 | return $this->kills_; |
---|
1832 | } |
---|
1833 | |
---|
1834 | function fetchXML() |
---|
1835 | { |
---|
1836 | $data = LoadGlobalData('/map/Kills.xml.aspx'); |
---|
1837 | |
---|
1838 | $xml_parser = xml_parser_create(); |
---|
1839 | xml_set_object ( $xml_parser, $this ); |
---|
1840 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1841 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1842 | |
---|
1843 | if (!xml_parse($xml_parser, $data, true)) |
---|
1844 | return "<i>Error getting XML data from api.eve-online.com/map/Kills.xml.aspx </i><br><br>"; |
---|
1845 | |
---|
1846 | xml_parser_free($xml_parser); |
---|
1847 | |
---|
1848 | return $this->html; |
---|
1849 | } |
---|
1850 | |
---|
1851 | function startElement($parser, $name, $attribs) |
---|
1852 | { |
---|
1853 | global $KillsData; |
---|
1854 | |
---|
1855 | if ($name == "ROW") |
---|
1856 | { |
---|
1857 | if (count($attribs)) |
---|
1858 | { |
---|
1859 | foreach ($attribs as $k => $v) |
---|
1860 | { |
---|
1861 | switch ($k) |
---|
1862 | { |
---|
1863 | case "SOLARSYSTEMID": |
---|
1864 | $KillsData['solarSystemID'] = $v; |
---|
1865 | break; |
---|
1866 | case "SHIPKILLS": |
---|
1867 | $KillsData['shipKills'] = $v; |
---|
1868 | break; |
---|
1869 | case "FACTIONKILLS": |
---|
1870 | $KillsData['factionKills'] = $v; |
---|
1871 | break; |
---|
1872 | case "PODKILLS": |
---|
1873 | $KillsData['podKills'] = $v; |
---|
1874 | break; |
---|
1875 | } |
---|
1876 | } |
---|
1877 | } |
---|
1878 | } |
---|
1879 | } |
---|
1880 | |
---|
1881 | function endElement($parser, $name) |
---|
1882 | { |
---|
1883 | global $KillsData; |
---|
1884 | global $tempvalue; |
---|
1885 | |
---|
1886 | if ($name == "CURRENTTIME") |
---|
1887 | $this->CurrentTime_ = $tempvalue; |
---|
1888 | if ($name == "DATATIME") |
---|
1889 | $this->DataTime_ = $tempvalue; |
---|
1890 | if ($name == "CACHEDUNTIL") |
---|
1891 | { |
---|
1892 | $this->CachedUntil_ = $tempvalue; |
---|
1893 | ApiCache::set('API_map_Kills' , $tempvalue); |
---|
1894 | } |
---|
1895 | |
---|
1896 | if ($name == "ROW") |
---|
1897 | { |
---|
1898 | $this->kills_[] = $KillsData; |
---|
1899 | $KillsData = array(); |
---|
1900 | unset($KillsData); |
---|
1901 | } |
---|
1902 | } |
---|
1903 | |
---|
1904 | function characterData($parser, $data) |
---|
1905 | { |
---|
1906 | global $tempvalue; |
---|
1907 | |
---|
1908 | $tempvalue = $data; |
---|
1909 | } |
---|
1910 | } |
---|
1911 | |
---|
1912 | // ********************************************************************************************************************************************** |
---|
1913 | // **************** API Alliance Sovereignty - /map/Sovereignty.xml.aspx **************** |
---|
1914 | // ********************************************************************************************************************************************** |
---|
1915 | |
---|
1916 | class API_Sovereignty |
---|
1917 | { |
---|
1918 | function getCachedUntil() |
---|
1919 | { |
---|
1920 | return $this->CachedUntil_; |
---|
1921 | } |
---|
1922 | |
---|
1923 | function getCurrentTime() |
---|
1924 | { |
---|
1925 | return $this->CurrentTime_; |
---|
1926 | } |
---|
1927 | |
---|
1928 | function getDataTime() |
---|
1929 | { |
---|
1930 | return $this->DataTime_; |
---|
1931 | } |
---|
1932 | |
---|
1933 | function getSovereignty() |
---|
1934 | { |
---|
1935 | return $this->Sovereignty_; |
---|
1936 | } |
---|
1937 | |
---|
1938 | function fetchXML() |
---|
1939 | { |
---|
1940 | $data = LoadGlobalData('/map/Sovereignty.xml.aspx'); |
---|
1941 | |
---|
1942 | $xml_parser = xml_parser_create(); |
---|
1943 | xml_set_object ( $xml_parser, $this ); |
---|
1944 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
1945 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
1946 | |
---|
1947 | if (!xml_parse($xml_parser, $data, true)) |
---|
1948 | return "<i>Error getting XML data from api.eve-online.com/map/Sovereignty.xml.aspx </i><br><br>"; |
---|
1949 | |
---|
1950 | xml_parser_free($xml_parser); |
---|
1951 | |
---|
1952 | return $this->html; |
---|
1953 | } |
---|
1954 | |
---|
1955 | function startElement($parser, $name, $attribs) |
---|
1956 | { |
---|
1957 | global $SovereigntyData; |
---|
1958 | |
---|
1959 | if ($name == "ROW") |
---|
1960 | { |
---|
1961 | if (count($attribs)) |
---|
1962 | { |
---|
1963 | foreach ($attribs as $k => $v) |
---|
1964 | { |
---|
1965 | switch ($k) |
---|
1966 | { |
---|
1967 | case "SOLARSYSTEMID": |
---|
1968 | $SovereigntyData['solarSystemID'] = $v; |
---|
1969 | break; |
---|
1970 | case "ALLIANCEID": |
---|
1971 | $SovereigntyData['allianceID'] = $v; |
---|
1972 | break; |
---|
1973 | case "CONSTELLATIONSOVEREIGNTY": |
---|
1974 | $SovereigntyData['constellationSovereignty'] = $v; |
---|
1975 | break; |
---|
1976 | case "SOVEREIGNTYLEVEL": |
---|
1977 | $SovereigntyData['sovereigntyLevel'] = $v; |
---|
1978 | break; |
---|
1979 | case "FACTIONID": |
---|
1980 | $SovereigntyData['factionID'] = $v; |
---|
1981 | break; |
---|
1982 | case "SOLARSYSTEMNAME": |
---|
1983 | $SovereigntyData['solarSystemName'] = $v; |
---|
1984 | break; |
---|
1985 | } |
---|
1986 | } |
---|
1987 | } |
---|
1988 | } |
---|
1989 | } |
---|
1990 | |
---|
1991 | function endElement($parser, $name) |
---|
1992 | { |
---|
1993 | global $SovereigntyData; |
---|
1994 | global $tempvalue; |
---|
1995 | |
---|
1996 | if ($name == "CURRENTTIME") |
---|
1997 | $this->CurrentTime_ = $tempvalue; |
---|
1998 | if ($name == "DATATIME") |
---|
1999 | $this->DataTime_ = $tempvalue; |
---|
2000 | if ($name == "CACHEDUNTIL") |
---|
2001 | { |
---|
2002 | if (config::get('API_extendedtimer_sovereignty') == 0) |
---|
2003 | { |
---|
2004 | $this->CachedUntil_ = date("Y-m-d H:i:s", (strtotime($this->CurrentTime_)) + 85500); |
---|
2005 | } else { |
---|
2006 | $this->CachedUntil_ = $tempvalue; |
---|
2007 | } |
---|
2008 | ApiCache::set('API_map_Sovereignty' , $this->CachedUntil_); |
---|
2009 | } |
---|
2010 | |
---|
2011 | if ($name == "ROW") |
---|
2012 | { |
---|
2013 | $this->Sovereignty_[] = $SovereigntyData; |
---|
2014 | $SovereigntyData = array(); |
---|
2015 | unset($SovereigntyData); |
---|
2016 | } |
---|
2017 | } |
---|
2018 | |
---|
2019 | function characterData($parser, $data) |
---|
2020 | { |
---|
2021 | global $tempvalue; |
---|
2022 | |
---|
2023 | $tempvalue = $data; |
---|
2024 | } |
---|
2025 | |
---|
2026 | function getSystemDetails($sysname) |
---|
2027 | { |
---|
2028 | if (!isset($this->Sovereignty_)) |
---|
2029 | $this->fetchXML(); |
---|
2030 | |
---|
2031 | if (!isset($this->Sovereignty_)) |
---|
2032 | return false; |
---|
2033 | |
---|
2034 | $Sov = $this->Sovereignty_; |
---|
2035 | |
---|
2036 | foreach ($Sov as $myTempData) |
---|
2037 | { |
---|
2038 | if ($myTempData['solarSystemName'] == $sysname) |
---|
2039 | return $myTempData; |
---|
2040 | } |
---|
2041 | |
---|
2042 | return; |
---|
2043 | } |
---|
2044 | |
---|
2045 | function getSystemIDDetails($sysID) |
---|
2046 | { |
---|
2047 | if (!isset($this->Sovereignty_)) |
---|
2048 | $this->fetchXML(); |
---|
2049 | |
---|
2050 | if (!isset($this->Sovereignty_)) |
---|
2051 | return false; |
---|
2052 | |
---|
2053 | //echo var_dump($this->Sovereignty_); |
---|
2054 | |
---|
2055 | $Sov = $this->Sovereignty_; |
---|
2056 | |
---|
2057 | foreach ($Sov as $myTempData) |
---|
2058 | { |
---|
2059 | if ($myTempData['solarSystemID'] == $sysID) |
---|
2060 | return $myTempData; |
---|
2061 | } |
---|
2062 | |
---|
2063 | return false; |
---|
2064 | } |
---|
2065 | } |
---|
2066 | |
---|
2067 | // ********************************************************************************************************************************************** |
---|
2068 | // **************** API Reference Types - /eve/RefTypes.xml.aspx **************** |
---|
2069 | // ********************************************************************************************************************************************** |
---|
2070 | |
---|
2071 | class API_RefTypes |
---|
2072 | { |
---|
2073 | function getCachedUntil() |
---|
2074 | { |
---|
2075 | return $this->CachedUntil_; |
---|
2076 | } |
---|
2077 | |
---|
2078 | function getCurrentTime() |
---|
2079 | { |
---|
2080 | return $this->CurrentTime_; |
---|
2081 | } |
---|
2082 | |
---|
2083 | function getRefTypes() |
---|
2084 | { |
---|
2085 | return $this->RefTypes_; |
---|
2086 | } |
---|
2087 | |
---|
2088 | function fetchXML() |
---|
2089 | { |
---|
2090 | $data = LoadGlobalData('/eve/RefTypes.xml.aspx'); |
---|
2091 | |
---|
2092 | $xml_parser = xml_parser_create(); |
---|
2093 | xml_set_object ( $xml_parser, $this ); |
---|
2094 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
2095 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
2096 | |
---|
2097 | if (!xml_parse($xml_parser, $data, true)) |
---|
2098 | return "<i>Error getting XML data from api.eve-online.com/eve/RefTypes.xml.aspx </i><br><br>"; |
---|
2099 | |
---|
2100 | xml_parser_free($xml_parser); |
---|
2101 | |
---|
2102 | return $this->html; |
---|
2103 | } |
---|
2104 | |
---|
2105 | function startElement($parser, $name, $attribs) |
---|
2106 | { |
---|
2107 | global $RefTypeData; |
---|
2108 | |
---|
2109 | if ($name == "ROW") |
---|
2110 | { |
---|
2111 | if (count($attribs)) |
---|
2112 | { |
---|
2113 | foreach ($attribs as $k => $v) |
---|
2114 | { |
---|
2115 | switch ($k) |
---|
2116 | { |
---|
2117 | case "REFTYPEID": |
---|
2118 | $RefTypeData['refTypeID'] = $v; |
---|
2119 | break; |
---|
2120 | case "REFTYPENAME": |
---|
2121 | $RefTypeData['refTypeName'] = $v; |
---|
2122 | break; |
---|
2123 | } |
---|
2124 | } |
---|
2125 | } |
---|
2126 | } |
---|
2127 | } |
---|
2128 | |
---|
2129 | function endElement($parser, $name) |
---|
2130 | { |
---|
2131 | global $RefTypeData; |
---|
2132 | global $tempvalue; |
---|
2133 | |
---|
2134 | if ($name == "CURRENTTIME") |
---|
2135 | $this->CurrentTime_ = $tempvalue; |
---|
2136 | if ($name == "CACHEDUNTIL") |
---|
2137 | { |
---|
2138 | $this->CachedUntil_ = $tempvalue; |
---|
2139 | ApiCache::set('API_eve_RefTypes' , $tempvalue); |
---|
2140 | } |
---|
2141 | |
---|
2142 | if ($name == "ROW") |
---|
2143 | { |
---|
2144 | $this->RefTypes_[] = $RefTypeData; |
---|
2145 | $RefTypeData = array(); |
---|
2146 | unset($RefTypeData); |
---|
2147 | } |
---|
2148 | } |
---|
2149 | |
---|
2150 | function characterData($parser, $data) |
---|
2151 | { |
---|
2152 | global $tempvalue; |
---|
2153 | |
---|
2154 | $tempvalue = $data; |
---|
2155 | } |
---|
2156 | } |
---|
2157 | |
---|
2158 | // ********************************************************************************************************************************************** |
---|
2159 | // **************** API Faction War Systems - /map/FacWarSystems.xml.aspx **************** |
---|
2160 | // ********************************************************************************************************************************************** |
---|
2161 | |
---|
2162 | class API_FacWarSystems |
---|
2163 | { |
---|
2164 | function getCachedUntil() |
---|
2165 | { |
---|
2166 | return $this->CachedUntil_; |
---|
2167 | } |
---|
2168 | |
---|
2169 | function getCurrentTime() |
---|
2170 | { |
---|
2171 | return $this->CurrentTime_; |
---|
2172 | } |
---|
2173 | |
---|
2174 | function getFacWarSystems() |
---|
2175 | { |
---|
2176 | return $this->FacWarSystems_; |
---|
2177 | } |
---|
2178 | |
---|
2179 | function fetchXML() |
---|
2180 | { |
---|
2181 | $data = LoadGlobalData('/map/FacWarSystems.xml.aspx'); |
---|
2182 | |
---|
2183 | $xml_parser = xml_parser_create(); |
---|
2184 | xml_set_object ( $xml_parser, $this ); |
---|
2185 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
2186 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
2187 | |
---|
2188 | if (!xml_parse($xml_parser, $data, true)) |
---|
2189 | return "<i>Error getting XML data from api.eve-online.com/map/FacWarSystems.xml.aspx </i><br><br>"; |
---|
2190 | |
---|
2191 | xml_parser_free($xml_parser); |
---|
2192 | |
---|
2193 | return $this->FacWarSystems_; |
---|
2194 | } |
---|
2195 | |
---|
2196 | function startElement($parser, $name, $attribs) |
---|
2197 | { |
---|
2198 | global $FacWarSystem; |
---|
2199 | |
---|
2200 | if ($name == "ROW") |
---|
2201 | { |
---|
2202 | if (count($attribs)) |
---|
2203 | { |
---|
2204 | foreach ($attribs as $k => $v) |
---|
2205 | { |
---|
2206 | switch ($k) |
---|
2207 | { |
---|
2208 | case "SOLARSYSTEMID": |
---|
2209 | $FacWarSystem['solarSystemID'] = $v; |
---|
2210 | break; |
---|
2211 | case "SOLARSYSTEMNAME": |
---|
2212 | $FacWarSystem['solarSystemName'] = $v; |
---|
2213 | break; |
---|
2214 | case "OCCUPYINGFACTIONID": |
---|
2215 | $FacWarSystem['occupyingFactionID'] = $v; |
---|
2216 | break; |
---|
2217 | case "OCCUPYINGFACTIONNAME": |
---|
2218 | $FacWarSystem['occupyingFactionName'] = $v; |
---|
2219 | break; |
---|
2220 | case "CONTESTED": |
---|
2221 | $FacWarSystem['contested'] = $v; |
---|
2222 | break; |
---|
2223 | } |
---|
2224 | } |
---|
2225 | } |
---|
2226 | } |
---|
2227 | } |
---|
2228 | |
---|
2229 | function endElement($parser, $name) |
---|
2230 | { |
---|
2231 | global $FacWarSystem; |
---|
2232 | global $tempvalue; |
---|
2233 | |
---|
2234 | if ($name == "CURRENTTIME") |
---|
2235 | $this->CurrentTime_ = $tempvalue; |
---|
2236 | if ($name == "CACHEDUNTIL") |
---|
2237 | { |
---|
2238 | if (config::get('API_extendedtimer_facwarsystems') == 0) |
---|
2239 | { |
---|
2240 | $this->CachedUntil_ = date("Y-m-d H:i:s", (strtotime($this->CurrentTime_)) + 85500); |
---|
2241 | } else { |
---|
2242 | $this->CachedUntil_ = $tempvalue; |
---|
2243 | } |
---|
2244 | ApiCache::set('API_map_FacWarSystems' , $this->CachedUntil_); |
---|
2245 | } |
---|
2246 | |
---|
2247 | if ($name == "ROW") |
---|
2248 | { |
---|
2249 | $this->FacWarSystems_[] = $FacWarSystem; |
---|
2250 | $FacWarSystem = array(); |
---|
2251 | unset($FacWarSystem); |
---|
2252 | } |
---|
2253 | } |
---|
2254 | |
---|
2255 | function characterData($parser, $data) |
---|
2256 | { |
---|
2257 | global $tempvalue; |
---|
2258 | |
---|
2259 | $tempvalue = $data; |
---|
2260 | } |
---|
2261 | } |
---|
2262 | |
---|
2263 | // ********************************************************************************************************************************************** |
---|
2264 | // **************** API Standings - /corp & char/Standings.xml.aspx **************** |
---|
2265 | // ********************************************************************************************************************************************** |
---|
2266 | class API_Standings |
---|
2267 | { |
---|
2268 | function getCachedUntil() |
---|
2269 | { |
---|
2270 | return $this->CachedUntil_; |
---|
2271 | } |
---|
2272 | |
---|
2273 | function getCurrentTime() |
---|
2274 | { |
---|
2275 | return $this->CurrentTime_; |
---|
2276 | } |
---|
2277 | |
---|
2278 | // boolean value - sets between char/corp |
---|
2279 | function isUser($value) |
---|
2280 | { |
---|
2281 | $this->isUser_ = $value; |
---|
2282 | } |
---|
2283 | |
---|
2284 | function setAPIKey($key) |
---|
2285 | { |
---|
2286 | $this->API_apiKey_ = $key; |
---|
2287 | } |
---|
2288 | |
---|
2289 | function setUserID($uid) |
---|
2290 | { |
---|
2291 | $this->API_userID_ = $uid; |
---|
2292 | } |
---|
2293 | |
---|
2294 | function setCharacterID($cid) |
---|
2295 | { |
---|
2296 | $this->API_characterID_ = $cid; |
---|
2297 | } |
---|
2298 | |
---|
2299 | function getCharacters() |
---|
2300 | { |
---|
2301 | return $this->Characters_; |
---|
2302 | } |
---|
2303 | function getCorporations() |
---|
2304 | { |
---|
2305 | return $this->Corporations_; |
---|
2306 | } |
---|
2307 | function getAlliances() |
---|
2308 | { |
---|
2309 | return $this->Alliances_; |
---|
2310 | } |
---|
2311 | function getAgents() |
---|
2312 | { |
---|
2313 | return $this->Agents_; |
---|
2314 | } |
---|
2315 | function getNPCCorporations() |
---|
2316 | { |
---|
2317 | return $this->NPCCorporations_; |
---|
2318 | } |
---|
2319 | function getFactions() |
---|
2320 | { |
---|
2321 | return $this->Factions_; |
---|
2322 | } |
---|
2323 | function getAllianceCorporations() |
---|
2324 | { |
---|
2325 | return $this->AllianceCorporations_; |
---|
2326 | } |
---|
2327 | function getAliianceAlliances() |
---|
2328 | { |
---|
2329 | return $this->AliianceAlliances_; |
---|
2330 | } |
---|
2331 | |
---|
2332 | function fetchXML() |
---|
2333 | { |
---|
2334 | $this->isAllianceStandings_ = false; |
---|
2335 | $this->isCorporationStandings_ = false; |
---|
2336 | |
---|
2337 | if ($this->isUser_) |
---|
2338 | { |
---|
2339 | // is a player feed - take details from logged in user |
---|
2340 | if (user::get('usr_pilot_id')) |
---|
2341 | { |
---|
2342 | $myEveCharAPI = new API_CharacterSheet(); |
---|
2343 | $this->html .= $myEveCharAPI->fetchXML(); |
---|
2344 | |
---|
2345 | $skills = $myEveCharAPI->getSkills(); |
---|
2346 | |
---|
2347 | $this->connections_ = 0; |
---|
2348 | $this->diplomacy_ = 0; |
---|
2349 | |
---|
2350 | foreach ((array)$skills as $myTempData) |
---|
2351 | { |
---|
2352 | if ($myTempData['typeID'] == "3359") |
---|
2353 | $this->connections_ = $myTempData['Level']; |
---|
2354 | if ($myTempData['typeID'] == "3357") |
---|
2355 | $this->diplomacy_ = $myTempData['Level']; |
---|
2356 | } |
---|
2357 | |
---|
2358 | $myKeyString = "userID=" . $this->API_userID_ . "&apiKey=" . $this->API_apiKey_ . "&characterID=" . $this->API_characterID_; |
---|
2359 | |
---|
2360 | $data = $this->loaddata($myKeyString, "char"); |
---|
2361 | } else { |
---|
2362 | return "You are not logged in."; |
---|
2363 | } |
---|
2364 | |
---|
2365 | } else { |
---|
2366 | // is a corp feed |
---|
2367 | $myKeyString = "userID=" . $this->API_userID_ . "&apiKey=" . $this->API_apiKey_ . "&characterID=" . $this->API_characterID_; |
---|
2368 | $data = $this->loaddata($myKeyString, "corp"); |
---|
2369 | } |
---|
2370 | |
---|
2371 | $xml_parser = xml_parser_create(); |
---|
2372 | xml_set_object ( $xml_parser, $this ); |
---|
2373 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
2374 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
2375 | |
---|
2376 | if (!xml_parse($xml_parser, $data, true)) |
---|
2377 | return "<i>Error getting XML data from api.eve-online.com/Standings.xml.aspx </i><br><br>"; |
---|
2378 | |
---|
2379 | xml_parser_free($xml_parser); |
---|
2380 | |
---|
2381 | // sort the arrays (in descending order of standing) |
---|
2382 | $this->Factions_ = $this->mysortarray($this->Factions_); |
---|
2383 | $this->Characters_ = $this->mysortarray($this->Characters_); |
---|
2384 | $this->Corporations_ = $this->mysortarray($this->Corporations_); |
---|
2385 | $this->Alliances_ = $this->mysortarray($this->Alliances_); |
---|
2386 | $this->Agents_ = $this->mysortarray($this->Agents_); |
---|
2387 | $this->NPCCorporations_ = $this->mysortarray($this->NPCCorporations_); |
---|
2388 | $this->AllianceCorporations_ = $this->mysortarray($this->AllianceCorporations_); |
---|
2389 | $this->AllianceAlliances_ = $this->mysortarray($this->AliianceAlliances_); |
---|
2390 | |
---|
2391 | return $this->html; |
---|
2392 | } |
---|
2393 | |
---|
2394 | function mysortarray($arraydata) |
---|
2395 | { |
---|
2396 | if (count($arraydata) != 0 ) |
---|
2397 | { |
---|
2398 | foreach ((array)$arraydata as $key => $row) { |
---|
2399 | $standing[$key] = $row['Standing']; |
---|
2400 | $name[$key] = $row['Name']; |
---|
2401 | $id[$key] = $row['ID']; |
---|
2402 | } |
---|
2403 | |
---|
2404 | array_multisort($standing, SORT_DESC, $name, SORT_ASC, $id, SORT_ASC, $arraydata); |
---|
2405 | |
---|
2406 | $standing = array(); |
---|
2407 | unset($standing); |
---|
2408 | $name = array(); |
---|
2409 | unset($name); |
---|
2410 | $id = array(); |
---|
2411 | unset($id); |
---|
2412 | |
---|
2413 | return $arraydata; |
---|
2414 | } |
---|
2415 | } |
---|
2416 | |
---|
2417 | function startElement($parser, $name, $attribs) |
---|
2418 | { |
---|
2419 | |
---|
2420 | if ($name == "CORPORATIONSTANDINGS") |
---|
2421 | { |
---|
2422 | $this->isAllianceStandings_ = false; |
---|
2423 | $this->isCorporationStandings_ = true; |
---|
2424 | } |
---|
2425 | if ($name == "STANDINGSTO") |
---|
2426 | { |
---|
2427 | $this->StandingsTo_ = true; // used to determine if/when to apply diplomacy/connections bonus |
---|
2428 | } |
---|
2429 | if ($name == "STANDINGSFROM") |
---|
2430 | { |
---|
2431 | $this->StandingsTo_ = false; |
---|
2432 | } |
---|
2433 | if ($name == "ALLIANCESTANDINGS") |
---|
2434 | { |
---|
2435 | $this->isAllianceStandings_ = true; |
---|
2436 | $this->isCorporationStandings_ = false; |
---|
2437 | } |
---|
2438 | |
---|
2439 | if ($name == "ROWSET") // In this If statement we set booleans to ultimately determine where the data in the next If statement is stored |
---|
2440 | { |
---|
2441 | if (count($attribs)) |
---|
2442 | { |
---|
2443 | foreach ($attribs as $k => $v) |
---|
2444 | { |
---|
2445 | switch ($k) |
---|
2446 | { |
---|
2447 | case "NAME": |
---|
2448 | switch ($v) |
---|
2449 | { |
---|
2450 | // bitwise or numeric flag would be better and more concise - but fuck it! |
---|
2451 | case "characters": // can only be personal/corp |
---|
2452 | $this->isCharacters_ = true; |
---|
2453 | $this->isCorporations_ = false; |
---|
2454 | $this->isAlliances_ = false; |
---|
2455 | $this->isAgents_ = false; |
---|
2456 | $this->isNPCCorporations_ = false; |
---|
2457 | $this->isFactions_ = false; |
---|
2458 | $this->isAllianceCorporations_ = false; |
---|
2459 | $this->isAllianceAlliances_ = false; |
---|
2460 | break; |
---|
2461 | case "corporations": // can be either personal/corp or alliance |
---|
2462 | $this->isCharacters_ = false; |
---|
2463 | $this->isCorporations_ = false; |
---|
2464 | $this->isAlliances_ = false; |
---|
2465 | $this->isAgents_ = false; |
---|
2466 | $this->isNPCCorporations_ = false; |
---|
2467 | $this->isFactions_ = false; |
---|
2468 | $this->isAllianceCorporations_ = false; |
---|
2469 | $this->isAllianceAlliances_ = false; |
---|
2470 | |
---|
2471 | if (!$this->isAllianceStandings_) // then it is personal/corp |
---|
2472 | { |
---|
2473 | $this->isCorporations_ = true; |
---|
2474 | } else { // then it is alliance |
---|
2475 | $this->isAllianceCorporations_ = true; |
---|
2476 | } |
---|
2477 | break; |
---|
2478 | case "alliances": // can be either personal/corp or alliance |
---|
2479 | $this->isCharacters_ = false; |
---|
2480 | $this->isCorporations_ = false; |
---|
2481 | $this->isAlliances_ = false; |
---|
2482 | $this->isAgents_ = false; |
---|
2483 | $this->isNPCCorporations_ = false; |
---|
2484 | $this->isFactions_ = false; |
---|
2485 | $this->isAllianceCorporations_ = false; |
---|
2486 | $this->isAllianceAlliances_ = false; |
---|
2487 | |
---|
2488 | if (!$this->isAllianceStandings_) // then it is personal/corp |
---|
2489 | { |
---|
2490 | $this->isAlliances_ = true; |
---|
2491 | } else { // then it is alliance |
---|
2492 | $this->isAllianceAlliances_ = true; |
---|
2493 | } |
---|
2494 | break; |
---|
2495 | case "agents": // can only be personal/corp |
---|
2496 | $this->isCharacters_ = false; |
---|
2497 | $this->isCorporations_ = false; |
---|
2498 | $this->isAlliances_ = false; |
---|
2499 | $this->isAgents_ = true; |
---|
2500 | $this->isNPCCorporations_ = false; |
---|
2501 | $this->isFactions_ = false; |
---|
2502 | $this->isAllianceCorporations_ = false; |
---|
2503 | $this->isAllianceAlliances_ = false; |
---|
2504 | break; |
---|
2505 | case "NPCCorporations": // can only be personal/corp |
---|
2506 | $this->isCharacters_ = false; |
---|
2507 | $this->isCorporations_ = false; |
---|
2508 | $this->isAlliances_ = false; |
---|
2509 | $this->isAgents_ = false; |
---|
2510 | $this->isNPCCorporations_ = true; |
---|
2511 | $this->isFactions_ = false; |
---|
2512 | $this->isAllianceCorporations_ = false; |
---|
2513 | $this->isAllianceAlliances_ = false; |
---|
2514 | break; |
---|
2515 | case "factions": // can only be personal/corp |
---|
2516 | $this->isCharacters_ = false; |
---|
2517 | $this->isCorporations_ = false; |
---|
2518 | $this->isAlliances_ = false; |
---|
2519 | $this->isAgents_ = false; |
---|
2520 | $this->isNPCCorporations_ = false; |
---|
2521 | $this->isFactions_ = true; |
---|
2522 | $this->isAllianceCorporations_ = false; |
---|
2523 | $this->isAllianceAlliances_ = false; |
---|
2524 | break; |
---|
2525 | } |
---|
2526 | break; |
---|
2527 | } |
---|
2528 | } |
---|
2529 | } |
---|
2530 | } |
---|
2531 | |
---|
2532 | if ($name == "ROW") |
---|
2533 | { |
---|
2534 | global $tempdata; |
---|
2535 | |
---|
2536 | if (count($attribs)) |
---|
2537 | { |
---|
2538 | foreach ($attribs as $k => $v) |
---|
2539 | { |
---|
2540 | switch ($k) |
---|
2541 | { |
---|
2542 | case "TOID": |
---|
2543 | $tempdata['ID'] = $v; |
---|
2544 | break; |
---|
2545 | case "FROMID": |
---|
2546 | $tempdata['ID'] = $v; |
---|
2547 | break; |
---|
2548 | case "TONAME": |
---|
2549 | $tempdata['Name'] = $v; |
---|
2550 | break; |
---|
2551 | case "FROMNAME": |
---|
2552 | $tempdata['Name'] = $v; |
---|
2553 | break; |
---|
2554 | case "STANDING": |
---|
2555 | // use flags determined in previous If... to load the correct array[] |
---|
2556 | if ($this->isUser_ && !$this->StandingsTo_) |
---|
2557 | { |
---|
2558 | // set standings bonus where applicable |
---|
2559 | // calculate bonus |
---|
2560 | if ($v >= 0) // Connections |
---|
2561 | $tempdata['Standing'] = number_format($v + ((10 - $v) * (0.04 * $this->connections_)), 2, '.', ''); |
---|
2562 | else // Diplomacy |
---|
2563 | $tempdata['Standing'] = number_format($v + ((10 - $v) * (0.04 * $this->diplomacy_)), 2, '.', ''); |
---|
2564 | } else { |
---|
2565 | $tempdata['Standing'] = $v; |
---|
2566 | } |
---|
2567 | |
---|
2568 | // check that 'Name' isn't empty as this means the value was reset |
---|
2569 | if ($tempdata['Name'] != "") |
---|
2570 | { |
---|
2571 | if ($this->isCharacters_) { |
---|
2572 | $this->Characters_[] = $tempdata; |
---|
2573 | } elseif ($this->isCorporations_) { |
---|
2574 | $this->Corporations_[] = $tempdata; |
---|
2575 | } elseif ($this->isAlliances_ ) { |
---|
2576 | $this->Alliances_[] = $tempdata; |
---|
2577 | } elseif ($this->isAgents_) { |
---|
2578 | $this->Agents_[] = $tempdata; |
---|
2579 | } elseif ($this->isNPCCorporations_) { |
---|
2580 | $this->NPCCorporations_[] = $tempdata; |
---|
2581 | } elseif ($this->isFactions_) { |
---|
2582 | $this->Factions_[] = $tempdata; |
---|
2583 | } elseif ($this->isAllianceCorporations_) { |
---|
2584 | $this->AllianceCorporations_[] = $tempdata; |
---|
2585 | } elseif ($this->isAllianceAlliances_) { |
---|
2586 | $this->AllianceAlliances_[] = $tempdata; |
---|
2587 | } |
---|
2588 | } |
---|
2589 | |
---|
2590 | $tempdata = array(); |
---|
2591 | unset($tempdata); |
---|
2592 | break; |
---|
2593 | } |
---|
2594 | } |
---|
2595 | } |
---|
2596 | } |
---|
2597 | } |
---|
2598 | |
---|
2599 | function endElement($parser, $name) |
---|
2600 | { |
---|
2601 | |
---|
2602 | if ($name == "CURRENTTIME") |
---|
2603 | $this->CurrentTime_ = $this->characterDataValue; |
---|
2604 | if ($name == "CACHEDUNTIL") |
---|
2605 | { |
---|
2606 | $this->CachedUntil_ = $this->characterDataValue; |
---|
2607 | ApiCache::set( $this->API_characterID_ . '_Standings' , $this->characterDataValue); |
---|
2608 | } |
---|
2609 | } |
---|
2610 | |
---|
2611 | function characterData($parser, $data) |
---|
2612 | { |
---|
2613 | $this->characterDataValue = $data; |
---|
2614 | } |
---|
2615 | |
---|
2616 | function loaddata($keystring, $typestring) |
---|
2617 | { |
---|
2618 | $configvalue = $this->API_characterID_ . '_Standings'; |
---|
2619 | |
---|
2620 | $CachedTime = ApiCache::get($configvalue); |
---|
2621 | $UseCaching = config::get('API_UseCache'); |
---|
2622 | |
---|
2623 | $url = "http://api.eve-online.com/" . $typestring . "/Standings.xml.aspx" . $keystring; |
---|
2624 | $path = "/" . $typestring . "/Standings.xml.aspx"; |
---|
2625 | |
---|
2626 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
2627 | if ($CachedTime == "") |
---|
2628 | { |
---|
2629 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
2630 | } |
---|
2631 | |
---|
2632 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
2633 | $cacheexists = true; |
---|
2634 | else |
---|
2635 | $cacheexists = false; |
---|
2636 | |
---|
2637 | |
---|
2638 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists )// if API_UseCache = 1 (off) then don't use cache |
---|
2639 | { |
---|
2640 | $fp = fsockopen("api.eve-online.com", 80); |
---|
2641 | |
---|
2642 | if (!$fp) |
---|
2643 | { |
---|
2644 | $this->Output_ .= "Could not connect to API URL"; |
---|
2645 | } else { |
---|
2646 | // request the xml |
---|
2647 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
2648 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
2649 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
2650 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
2651 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
2652 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
2653 | fputs ($fp, $keystring."\r\n"); |
---|
2654 | |
---|
2655 | // retrieve contents |
---|
2656 | $contents = ""; |
---|
2657 | while (!feof($fp)) |
---|
2658 | { |
---|
2659 | $contents .= fgets($fp); |
---|
2660 | } |
---|
2661 | |
---|
2662 | // close connection |
---|
2663 | fclose($fp); |
---|
2664 | |
---|
2665 | $start = strpos($contents, "?>"); |
---|
2666 | if ($start !== FALSE) |
---|
2667 | { |
---|
2668 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
2669 | } |
---|
2670 | |
---|
2671 | if ($UseCaching == 0) // Save the file if we're caching (0 = true in Thunks world) |
---|
2672 | { |
---|
2673 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
2674 | fwrite($file, $contents); |
---|
2675 | fclose($file); |
---|
2676 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
2677 | } |
---|
2678 | } |
---|
2679 | } else { |
---|
2680 | // re-use cached XML |
---|
2681 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
2682 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
2683 | fclose($fp); |
---|
2684 | } else { |
---|
2685 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
2686 | } |
---|
2687 | } |
---|
2688 | return $contents; |
---|
2689 | } |
---|
2690 | } |
---|
2691 | |
---|
2692 | // ********************************************************************************************************************************************** |
---|
2693 | // **************** API Character Sheet - char/CharacterSheet.xml.aspx **************** |
---|
2694 | // ********************************************************************************************************************************************** |
---|
2695 | // Incomplete - Does not read Certificates or Roles |
---|
2696 | class API_CharacterSheet |
---|
2697 | { |
---|
2698 | function getCachedUntil() |
---|
2699 | { |
---|
2700 | return $this->CachedUntil_; |
---|
2701 | } |
---|
2702 | |
---|
2703 | function getCurrentTime() |
---|
2704 | { |
---|
2705 | return $this->CurrentTime_; |
---|
2706 | } |
---|
2707 | |
---|
2708 | function getSkills() |
---|
2709 | { |
---|
2710 | return $this->Skills_; |
---|
2711 | } |
---|
2712 | |
---|
2713 | // array 1-5 based on implant slot position. 6-10 don't seem to appear, presumably because Hardwirings do not affect skill training. |
---|
2714 | function getImplants() |
---|
2715 | { |
---|
2716 | return $this->Implant_; |
---|
2717 | } |
---|
2718 | |
---|
2719 | function getIntelligence() |
---|
2720 | { |
---|
2721 | return $this->Intelligence_; |
---|
2722 | } |
---|
2723 | |
---|
2724 | function getMemory() |
---|
2725 | { |
---|
2726 | return $this->Memory_; |
---|
2727 | } |
---|
2728 | |
---|
2729 | function getCharisma() |
---|
2730 | { |
---|
2731 | return $this->Charisma_; |
---|
2732 | } |
---|
2733 | |
---|
2734 | function getPerception() |
---|
2735 | { |
---|
2736 | return $this->Perception_; |
---|
2737 | } |
---|
2738 | |
---|
2739 | function getWillpower() |
---|
2740 | { |
---|
2741 | return $this->Willpower_; |
---|
2742 | } |
---|
2743 | function getCharacterID() |
---|
2744 | { |
---|
2745 | return $this->CharacterID_; |
---|
2746 | } |
---|
2747 | function getName() |
---|
2748 | { |
---|
2749 | return $this->Name_; |
---|
2750 | } |
---|
2751 | function getRace() |
---|
2752 | { |
---|
2753 | return $this->Race_; |
---|
2754 | } |
---|
2755 | function getBloodLine() |
---|
2756 | { |
---|
2757 | return $this->BloodLine_; |
---|
2758 | } |
---|
2759 | function getGender() |
---|
2760 | { |
---|
2761 | return $this->Gender_; |
---|
2762 | } |
---|
2763 | function getCorporationName() |
---|
2764 | { |
---|
2765 | return $this->CorporationName_; |
---|
2766 | } |
---|
2767 | function getCorporationID() |
---|
2768 | { |
---|
2769 | return $this->CorporationID_; |
---|
2770 | } |
---|
2771 | function getCloneName() |
---|
2772 | { |
---|
2773 | return $this->CloneName_; |
---|
2774 | } |
---|
2775 | function getCloneSkillPoints() |
---|
2776 | { |
---|
2777 | return $this->CloneSkillPoints_; |
---|
2778 | } |
---|
2779 | function getBalance() |
---|
2780 | { |
---|
2781 | return $this->Balance_; |
---|
2782 | } |
---|
2783 | function fetchXML() |
---|
2784 | { |
---|
2785 | // is a player feed - take details from logged in user |
---|
2786 | if (user::get('usr_pilot_id')) |
---|
2787 | { |
---|
2788 | require_once('class.pilot.php'); |
---|
2789 | $plt = new pilot(user::get('usr_pilot_id')); |
---|
2790 | $usersname = $plt->getName(); |
---|
2791 | |
---|
2792 | $this->CharName_ = $usersname; // $this->CharName_ is used later for config key value for caching |
---|
2793 | |
---|
2794 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $usersname . '"'; |
---|
2795 | |
---|
2796 | $qry = new DBQuery(); |
---|
2797 | $qry->execute($sql); |
---|
2798 | $row = $qry->getRow(); |
---|
2799 | |
---|
2800 | $pilot_id = $row['plt_id']; |
---|
2801 | $API_charID = $row['plt_externalid']; |
---|
2802 | |
---|
2803 | if ( $pilot_id == 0 ) |
---|
2804 | { |
---|
2805 | return "Something went wrong with finiding pilots external ID<br>"; |
---|
2806 | } |
---|
2807 | |
---|
2808 | $newsql = 'SELECT userID , apiKey FROM kb3_api_user WHERE charID = "' . $API_charID . '"'; |
---|
2809 | $qry->execute($newsql); |
---|
2810 | $userrow = $qry->getRow(); |
---|
2811 | |
---|
2812 | $API_userID = $userrow['userID']; |
---|
2813 | $API_apiKey = $userrow['apiKey']; |
---|
2814 | |
---|
2815 | $myKeyString = "userID=" . $API_userID . "&apiKey=" . $API_apiKey . "&characterID=" . $API_charID; |
---|
2816 | |
---|
2817 | $data = $this->loaddata($myKeyString); |
---|
2818 | } else { |
---|
2819 | return "You are not logged in."; |
---|
2820 | } |
---|
2821 | |
---|
2822 | $xml_parser = xml_parser_create(); |
---|
2823 | xml_set_object ( $xml_parser, $this ); |
---|
2824 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
2825 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
2826 | |
---|
2827 | if (!xml_parse($xml_parser, $data, true)) |
---|
2828 | return "<i>Error getting XML data from api.eve-online.com/CharacterSheet.xml.aspx </i><br><br>"; |
---|
2829 | |
---|
2830 | xml_parser_free($xml_parser); |
---|
2831 | |
---|
2832 | return $this->html; |
---|
2833 | } |
---|
2834 | |
---|
2835 | function startElement($parser, $name, $attribs) |
---|
2836 | { |
---|
2837 | if ($name == "ROW") |
---|
2838 | { |
---|
2839 | global $tempdata; |
---|
2840 | |
---|
2841 | if (count($attribs)) |
---|
2842 | { |
---|
2843 | foreach ($attribs as $k => $v) |
---|
2844 | { |
---|
2845 | switch ($k) |
---|
2846 | { |
---|
2847 | case "TYPEID": |
---|
2848 | $tempdata['typeID'] = $v; |
---|
2849 | $tempdata['SkillName'] = gettypeIDname($v); |
---|
2850 | $tempdata['GroupID'] = getgroupID($v); |
---|
2851 | $tempdata['GroupName'] = getgroupIDname($tempdata['GroupID']); |
---|
2852 | $tempdata['Rank'] = gettypeIDrank($v); |
---|
2853 | break; |
---|
2854 | case "SKILLPOINTS": |
---|
2855 | $tempdata['SkillPoints'] = $v; |
---|
2856 | break; |
---|
2857 | case "LEVEL": |
---|
2858 | $tempdata['Level'] = $v; |
---|
2859 | |
---|
2860 | $this->Skills_[] = $tempdata; |
---|
2861 | |
---|
2862 | $tempdata = array(); |
---|
2863 | unset($tempdata); |
---|
2864 | break; |
---|
2865 | case "UNPUBLISHED": // unused skill eg. Black Market Trading |
---|
2866 | $tempdata = array(); |
---|
2867 | unset($tempdata); |
---|
2868 | break; |
---|
2869 | } |
---|
2870 | } |
---|
2871 | } |
---|
2872 | } |
---|
2873 | } |
---|
2874 | |
---|
2875 | function endElement($parser, $name) |
---|
2876 | { |
---|
2877 | // Player Details |
---|
2878 | if ($name == "CHARACTERID") |
---|
2879 | $this->CharacterID_ = $this->characterDataValue; |
---|
2880 | if ($name == "NAME") |
---|
2881 | $this->Name_ = $this->characterDataValue; |
---|
2882 | if ($name == "RACE") |
---|
2883 | $this->Race_ = $this->characterDataValue; |
---|
2884 | if ($name == "BLOODLINE") |
---|
2885 | $this->BloodLine_ = $this->characterDataValue; |
---|
2886 | if ($name == "GENDER") |
---|
2887 | $this->Gender_ = $this->characterDataValue; |
---|
2888 | if ($name == "CORPORATIONNAME") |
---|
2889 | $this->CorporationName_ = $this->characterDataValue; |
---|
2890 | if ($name == "CORPORATIONID") |
---|
2891 | $this->CorporationID_ = $this->characterDataValue; |
---|
2892 | if ($name == "CLONENAME") |
---|
2893 | $this->CloneName_ = $this->characterDataValue; |
---|
2894 | if ($name == "CLONESKILLPOINTS") |
---|
2895 | $this->CloneSkillPoints_ = $this->characterDataValue; |
---|
2896 | if ($name == "BALANCE") |
---|
2897 | $this->Balance_ = $this->characterDataValue; |
---|
2898 | |
---|
2899 | // Augmentations |
---|
2900 | if ($name == "AUGMENTATORNAME") |
---|
2901 | $tempaug['Name'] = $this->characterDataValue; |
---|
2902 | if ($name == "AUGMENTATORVALUE") |
---|
2903 | $tempaug['Value'] = $this->characterDataValue; |
---|
2904 | |
---|
2905 | if ($name == "PERCEPTIONBONUS") |
---|
2906 | { |
---|
2907 | $this->Implant_[1] = $tempaug; |
---|
2908 | |
---|
2909 | $tempaug = array(); |
---|
2910 | unset($tempaug); |
---|
2911 | } |
---|
2912 | if ($name == "MEMORYBONUS") |
---|
2913 | { |
---|
2914 | $this->Implant_[2] = $tempaug; |
---|
2915 | |
---|
2916 | $tempaug = array(); |
---|
2917 | unset($tempaug); |
---|
2918 | } |
---|
2919 | if ($name == "WILLPOWERBONUS") |
---|
2920 | { |
---|
2921 | $this->Implant_[3] = $tempaug; |
---|
2922 | |
---|
2923 | $tempaug = array(); |
---|
2924 | unset($tempaug); |
---|
2925 | } |
---|
2926 | if ($name == "INTELLIGENCEBONUS") |
---|
2927 | { |
---|
2928 | $this->Implant_[4] = $tempaug; |
---|
2929 | |
---|
2930 | $tempaug = array(); |
---|
2931 | unset($tempaug); |
---|
2932 | } |
---|
2933 | if ($name == "CHARISMABONUS") |
---|
2934 | { |
---|
2935 | $this->Implant_[5] = $tempaug; |
---|
2936 | |
---|
2937 | $tempaug = array(); |
---|
2938 | unset($tempaug); |
---|
2939 | } |
---|
2940 | |
---|
2941 | // Attributes |
---|
2942 | if ($name == "INTELLIGENCE") |
---|
2943 | $this->Intelligence_ = $this->characterDataValue; |
---|
2944 | if ($name == "MEMORY") |
---|
2945 | $this->Memory_ = $this->characterDataValue; |
---|
2946 | if ($name == "CHARISMA") |
---|
2947 | $this->Charisma_ = $this->characterDataValue; |
---|
2948 | if ($name == "PERCEPTION") |
---|
2949 | $this->Perception_ = $this->characterDataValue; |
---|
2950 | if ($name == "WILLPOWER") |
---|
2951 | $this->Willpower_ = $this->characterDataValue; |
---|
2952 | |
---|
2953 | if ($name == "CURRENTTIME") |
---|
2954 | $this->CurrentTime_ = $this->characterDataValue; |
---|
2955 | if ($name == "CACHEDUNTIL") |
---|
2956 | { |
---|
2957 | $this->CachedUntil_ = $this->characterDataValue; |
---|
2958 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
2959 | ApiCache::set( $this->CharName_ . '_CharacterSheet' , $this->characterDataValue); |
---|
2960 | } |
---|
2961 | } |
---|
2962 | |
---|
2963 | function characterData($parser, $data) |
---|
2964 | { |
---|
2965 | $this->characterDataValue = $data; |
---|
2966 | } |
---|
2967 | |
---|
2968 | function loaddata($keystring) |
---|
2969 | { |
---|
2970 | $configvalue = $this->CharName_ . '_CharacterSheet'; |
---|
2971 | |
---|
2972 | $CachedTime = ApiCache::get($configvalue); |
---|
2973 | $UseCaching = config::get('API_UseCache'); |
---|
2974 | |
---|
2975 | $url = "http://api.eve-online.com/char/CharacterSheet.xml.aspx" . $keystring; |
---|
2976 | |
---|
2977 | $path = '/char/CharacterSheet.xml.aspx'; |
---|
2978 | |
---|
2979 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
2980 | if ($CachedTime == "") |
---|
2981 | { |
---|
2982 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
2983 | } |
---|
2984 | |
---|
2985 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
2986 | $cacheexists = true; |
---|
2987 | else |
---|
2988 | $cacheexists = false; |
---|
2989 | |
---|
2990 | // if API_UseCache = 1 (off) then don't use cache |
---|
2991 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists ) |
---|
2992 | { |
---|
2993 | $fp = fsockopen("api.eve-online.com", 80); |
---|
2994 | |
---|
2995 | if (!$fp) |
---|
2996 | { |
---|
2997 | $this->Output_ .= "Could not connect to API URL"; |
---|
2998 | } else { |
---|
2999 | // request the xml |
---|
3000 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
3001 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
3002 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
3003 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
3004 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
3005 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
3006 | fputs ($fp, $keystring."\r\n"); |
---|
3007 | |
---|
3008 | // retrieve contents |
---|
3009 | $contents = ""; |
---|
3010 | while (!feof($fp)) |
---|
3011 | { |
---|
3012 | $contents .= fgets($fp); |
---|
3013 | } |
---|
3014 | |
---|
3015 | // close connection |
---|
3016 | fclose($fp); |
---|
3017 | |
---|
3018 | $start = strpos($contents, "?>"); |
---|
3019 | if ($start !== FALSE) |
---|
3020 | { |
---|
3021 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
3022 | } |
---|
3023 | |
---|
3024 | // Save the file if we're caching (0 = true in Thunks world) |
---|
3025 | if ($UseCaching == 0) |
---|
3026 | { |
---|
3027 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
3028 | fwrite($file, $contents); |
---|
3029 | fclose($file); |
---|
3030 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
3031 | } |
---|
3032 | } |
---|
3033 | } else { |
---|
3034 | // re-use cached XML |
---|
3035 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
3036 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
3037 | fclose($fp); |
---|
3038 | } else { |
---|
3039 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
3040 | } |
---|
3041 | } |
---|
3042 | return $contents; |
---|
3043 | } |
---|
3044 | } |
---|
3045 | |
---|
3046 | // ********************************************************************************************************************************************** |
---|
3047 | // **************** API Skill Training Sheet - char/SkillInTraining.xml.aspx **************** |
---|
3048 | // ********************************************************************************************************************************************** |
---|
3049 | class API_SkillInTraining |
---|
3050 | { |
---|
3051 | |
---|
3052 | function getSkillInTraining() |
---|
3053 | { |
---|
3054 | return $this->SkillInTraining_; |
---|
3055 | } |
---|
3056 | |
---|
3057 | function getCurrentTQTime() |
---|
3058 | { |
---|
3059 | return $this->CurrentTQTime_; |
---|
3060 | } |
---|
3061 | |
---|
3062 | function getTrainingEndTime() |
---|
3063 | { |
---|
3064 | return $this->TrainingEndTime_; |
---|
3065 | } |
---|
3066 | |
---|
3067 | function getTrainingStartTime() |
---|
3068 | { |
---|
3069 | return $this->TrainingStartTime_; |
---|
3070 | } |
---|
3071 | |
---|
3072 | function getTrainingTypeID() |
---|
3073 | { |
---|
3074 | return $this->TrainingTypeID_; |
---|
3075 | } |
---|
3076 | |
---|
3077 | function getTrainingStartSP() |
---|
3078 | { |
---|
3079 | return $this->TrainingStartSP_; |
---|
3080 | } |
---|
3081 | |
---|
3082 | function getTrainingDestinationSP() |
---|
3083 | { |
---|
3084 | return $this->TrainingDestinationSP_; |
---|
3085 | } |
---|
3086 | |
---|
3087 | function getTrainingToLevel() |
---|
3088 | { |
---|
3089 | return $this->TrainingToLevel_; |
---|
3090 | } |
---|
3091 | |
---|
3092 | function getCachedUntil() |
---|
3093 | { |
---|
3094 | return $this->CachedUntil_; |
---|
3095 | } |
---|
3096 | |
---|
3097 | function getCurrentTime() |
---|
3098 | { |
---|
3099 | return $this->CurrentTime_; |
---|
3100 | } |
---|
3101 | |
---|
3102 | function getSPTrained() |
---|
3103 | { |
---|
3104 | return $this->SPTrained_; |
---|
3105 | } |
---|
3106 | |
---|
3107 | function getTrainingTimeRemaining() |
---|
3108 | { |
---|
3109 | return $this->TrainingTimeRemaining_; |
---|
3110 | } |
---|
3111 | |
---|
3112 | function fetchXML() |
---|
3113 | { |
---|
3114 | // is a player feed - take details from logged in user |
---|
3115 | if (user::get('usr_pilot_id')) |
---|
3116 | { |
---|
3117 | require_once('class.pilot.php'); |
---|
3118 | $plt = new pilot(user::get('usr_pilot_id')); |
---|
3119 | $usersname = $plt->getName(); |
---|
3120 | |
---|
3121 | $this->CharName_ = $usersname; |
---|
3122 | |
---|
3123 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $usersname . '"'; |
---|
3124 | |
---|
3125 | $qry = new DBQuery(); |
---|
3126 | $qry->execute($sql); |
---|
3127 | $row = $qry->getRow(); |
---|
3128 | |
---|
3129 | $pilot_id = $row['plt_id']; |
---|
3130 | $API_charID = $row['plt_externalid']; |
---|
3131 | |
---|
3132 | if ( $pilot_id == 0 ) |
---|
3133 | { |
---|
3134 | return "Something went wrong with finiding pilots external ID<br>"; |
---|
3135 | } |
---|
3136 | |
---|
3137 | $newsql = 'SELECT userID , apiKey FROM kb3_api_user WHERE charID = "' . $API_charID . '"'; |
---|
3138 | $qry->execute($newsql); |
---|
3139 | $userrow = $qry->getRow(); |
---|
3140 | |
---|
3141 | $API_userID = $userrow['userID']; |
---|
3142 | $API_apiKey = $userrow['apiKey']; |
---|
3143 | |
---|
3144 | $myKeyString = "userID=" . $API_userID . "&apiKey=" . $API_apiKey . "&characterID=" . $API_charID; |
---|
3145 | |
---|
3146 | $data = $this->loaddata($myKeyString); |
---|
3147 | } else { |
---|
3148 | return "You are not logged in."; |
---|
3149 | } |
---|
3150 | |
---|
3151 | $xml_parser = xml_parser_create(); |
---|
3152 | xml_set_object ( $xml_parser, $this ); |
---|
3153 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
3154 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
3155 | |
---|
3156 | if (!xml_parse($xml_parser, $data, true)) |
---|
3157 | return "<i>Error getting XML data from api.eve-online.com/SkillInTraining.xml.aspx </i><br><br>"; |
---|
3158 | |
---|
3159 | xml_parser_free($xml_parser); |
---|
3160 | |
---|
3161 | // Calculate Time Training remaining and amount of SP Done |
---|
3162 | if ($this->SkillInTraining_ == 1) |
---|
3163 | { |
---|
3164 | $trainingleft = $this->TrainingEndTime_; |
---|
3165 | |
---|
3166 | $now = time(); |
---|
3167 | $gmmktime = gmmktime(); |
---|
3168 | $finaltime = $gmmktime - $now; |
---|
3169 | |
---|
3170 | $year = (int)substr($trainingleft, 0, 4); |
---|
3171 | $month = (int)substr($trainingleft, 5, 2); |
---|
3172 | $day = (int)substr($trainingleft, 8, 2); |
---|
3173 | $hour = (int)substr($trainingleft, 11, 2) + (($finaltime > 0) ? floor($finaltime / 60 / 60) : 0); //2007-06-22 16:47:50 |
---|
3174 | $minute = (int)substr($trainingleft, 14, 2); |
---|
3175 | $second = (int)substr($trainingleft, 17, 2); |
---|
3176 | |
---|
3177 | $difference = gmmktime($hour, $minute, $second, $month, $day, $year) - $now; |
---|
3178 | $timedone = $difference; |
---|
3179 | if ($difference >= 1) |
---|
3180 | { |
---|
3181 | $days = floor($difference/86400); |
---|
3182 | $difference = $difference - ($days*86400); |
---|
3183 | $hours = floor($difference/3600); |
---|
3184 | $difference = $difference - ($hours*3600); |
---|
3185 | $minutes = floor($difference/60); |
---|
3186 | $difference = $difference - ($minutes*60); |
---|
3187 | $seconds = $difference; |
---|
3188 | $this->TrainingTimeRemaining_ = "$days Days, $hours Hours, $minutes Minutes and $seconds Seconds."; |
---|
3189 | } else { |
---|
3190 | $this->TrainingTimeRemaining_ = "Done !"; |
---|
3191 | } |
---|
3192 | |
---|
3193 | // Calculate SP done by using the ratio gained from Time spent training so far. |
---|
3194 | $finaltime = strtotime($this->TrainingEndTime_) - strtotime($this->TrainingStartTime_); // in seconds |
---|
3195 | $ratio = 1 - ($timedone / $finaltime); |
---|
3196 | $this->SPTrained_ = ($this->TrainingDestinationSP_ - $this->TrainingStartSP_) * $ratio; |
---|
3197 | } |
---|
3198 | |
---|
3199 | return $this->html; // should be empty, but keeping just incase - errors are returned by Text so worth looking anyway. |
---|
3200 | } |
---|
3201 | |
---|
3202 | function startElement($parser, $name, $attribs) |
---|
3203 | { |
---|
3204 | // Nothing to do here |
---|
3205 | } |
---|
3206 | |
---|
3207 | function endElement($parser, $name) |
---|
3208 | { |
---|
3209 | // Details |
---|
3210 | if ($name == "SKILLINTRAINING") |
---|
3211 | $this->SkillInTraining_ = $this->characterDataValue; |
---|
3212 | if ($name == "CURRENTTQTIME") |
---|
3213 | $this->CurrentTQTime_ = $this->characterDataValue; |
---|
3214 | if ($name == "TRAININGENDTIME") |
---|
3215 | $this->TrainingEndTime_ = $this->characterDataValue; |
---|
3216 | if ($name == "TRAININGSTARTTIME") |
---|
3217 | $this->TrainingStartTime_ = $this->characterDataValue; |
---|
3218 | if ($name == "TRAININGTYPEID") |
---|
3219 | $this->TrainingTypeID_ = $this->characterDataValue; |
---|
3220 | if ($name == "TRAININGSTARTSP") |
---|
3221 | $this->TrainingStartSP_ = $this->characterDataValue; |
---|
3222 | if ($name == "TRAININGDESTINATIONSP") |
---|
3223 | $this->TrainingDestinationSP_ = $this->characterDataValue; |
---|
3224 | if ($name == "TRAININGTOLEVEL") |
---|
3225 | $this->TrainingToLevel_ = $this->characterDataValue; |
---|
3226 | |
---|
3227 | if ($name == "CURRENTTIME") |
---|
3228 | $this->CurrentTime_ = $this->characterDataValue; |
---|
3229 | if ($name == "CACHEDUNTIL") |
---|
3230 | { |
---|
3231 | $this->CachedUntil_ = $this->characterDataValue; |
---|
3232 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
3233 | ApiCache::set( $this->CharName_ . '_SkillInTraining' , $this->characterDataValue); |
---|
3234 | } |
---|
3235 | } |
---|
3236 | |
---|
3237 | function characterData($parser, $data) |
---|
3238 | { |
---|
3239 | $this->characterDataValue = $data; |
---|
3240 | } |
---|
3241 | |
---|
3242 | function loaddata($keystring) |
---|
3243 | { |
---|
3244 | $configvalue = $this->CharName_ . '_SkillInTraining'; |
---|
3245 | |
---|
3246 | $CachedTime = ApiCache::get($configvalue); |
---|
3247 | $UseCaching = config::get('API_UseCache'); |
---|
3248 | |
---|
3249 | $url = "http://api.eve-online.com/char/SkillInTraining.xml.aspx" . $keystring; |
---|
3250 | |
---|
3251 | $path = '/char/SkillInTraining.xml.aspx'; |
---|
3252 | |
---|
3253 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
3254 | if ($CachedTime == "") |
---|
3255 | { |
---|
3256 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
3257 | } |
---|
3258 | |
---|
3259 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
3260 | $cacheexists = true; |
---|
3261 | else |
---|
3262 | $cacheexists = false; |
---|
3263 | |
---|
3264 | // if API_UseCache = 1 (off) then don't use cache |
---|
3265 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists ) |
---|
3266 | { |
---|
3267 | $fp = fsockopen("api.eve-online.com", 80); |
---|
3268 | |
---|
3269 | if (!$fp) |
---|
3270 | { |
---|
3271 | $this->Output_ .= "Could not connect to API URL"; |
---|
3272 | } else { |
---|
3273 | // request the xml |
---|
3274 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
3275 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
3276 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
3277 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
3278 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
3279 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
3280 | fputs ($fp, $keystring."\r\n"); |
---|
3281 | |
---|
3282 | // retrieve contents |
---|
3283 | $contents = ""; |
---|
3284 | while (!feof($fp)) |
---|
3285 | { |
---|
3286 | $contents .= fgets($fp); |
---|
3287 | } |
---|
3288 | |
---|
3289 | // close connection |
---|
3290 | fclose($fp); |
---|
3291 | |
---|
3292 | $start = strpos($contents, "?>"); |
---|
3293 | if ($start !== FALSE) |
---|
3294 | { |
---|
3295 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
3296 | } |
---|
3297 | |
---|
3298 | // Save the file if we're caching (0 = true in Thunks world) |
---|
3299 | if ($UseCaching == 0) |
---|
3300 | { |
---|
3301 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
3302 | fwrite($file, $contents); |
---|
3303 | fclose($file); |
---|
3304 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
3305 | } |
---|
3306 | } |
---|
3307 | } else { |
---|
3308 | // re-use cached XML |
---|
3309 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
3310 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
3311 | fclose($fp); |
---|
3312 | } else { |
---|
3313 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
3314 | } |
---|
3315 | } |
---|
3316 | return $contents; |
---|
3317 | } |
---|
3318 | } |
---|
3319 | |
---|
3320 | // ********************************************************************************************************************************************** |
---|
3321 | // **************** API StarbaseList - /corp/StarbaseList.xml.aspx **************** |
---|
3322 | // ********************************************************************************************************************************************** |
---|
3323 | class API_StarbaseList |
---|
3324 | { |
---|
3325 | function getCachedUntil() |
---|
3326 | { |
---|
3327 | return $this->CachedUntil_; |
---|
3328 | } |
---|
3329 | |
---|
3330 | function getCurrentTime() |
---|
3331 | { |
---|
3332 | return $this->CurrentTime_; |
---|
3333 | } |
---|
3334 | |
---|
3335 | function setAPIKey($key) |
---|
3336 | { |
---|
3337 | $this->API_apiKey_ = $key; |
---|
3338 | } |
---|
3339 | |
---|
3340 | function setUserID($uid) |
---|
3341 | { |
---|
3342 | $this->API_userID_ = $uid; |
---|
3343 | } |
---|
3344 | |
---|
3345 | function setCharacterID($cid) |
---|
3346 | { |
---|
3347 | $this->API_charID_ = $cid; |
---|
3348 | } |
---|
3349 | |
---|
3350 | function getStarbases() |
---|
3351 | { |
---|
3352 | return $this->Starbase_; |
---|
3353 | } |
---|
3354 | |
---|
3355 | function fetchXML() |
---|
3356 | { |
---|
3357 | // is a player feed - take details from logged in user |
---|
3358 | if (user::get('usr_pilot_id')) |
---|
3359 | { |
---|
3360 | require_once('class.pilot.php'); |
---|
3361 | $plt = new pilot(user::get('usr_pilot_id')); |
---|
3362 | $usersname = $plt->getName(); |
---|
3363 | |
---|
3364 | $this->CharName_ = $usersname; |
---|
3365 | |
---|
3366 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $usersname . '"'; |
---|
3367 | |
---|
3368 | $qry = new DBQuery(); |
---|
3369 | $qry->execute($sql); |
---|
3370 | $row = $qry->getRow(); |
---|
3371 | |
---|
3372 | $pilot_id = $row['plt_id']; |
---|
3373 | $API_charID = $row['plt_externalid']; |
---|
3374 | |
---|
3375 | if ( $pilot_id == 0 ) |
---|
3376 | { |
---|
3377 | return "Something went wrong with finiding pilots external ID<br>"; |
---|
3378 | } |
---|
3379 | |
---|
3380 | $newsql = 'SELECT userID , apiKey FROM kb3_api_user WHERE charID = "' . $API_charID . '"'; |
---|
3381 | $qry->execute($newsql); |
---|
3382 | $userrow = $qry->getRow(); |
---|
3383 | |
---|
3384 | $API_userID = $userrow['userID']; |
---|
3385 | $API_apiKey = $userrow['apiKey']; |
---|
3386 | |
---|
3387 | $myKeyString = "userID=" . $API_userID . "&apiKey=" . $API_apiKey . "&characterID=" . $API_charID; |
---|
3388 | |
---|
3389 | $data = $this->loaddata($myKeyString); |
---|
3390 | } else { |
---|
3391 | if ($this->API_userID_ != "" && $this->API_apiKey_ != "" && $this->API_charID_ != "") |
---|
3392 | { |
---|
3393 | $myKeyString = "userID=" . $this->API_userID_ . "&apiKey=" . $this->API_apiKey_ . "&characterID=" . $this->API_charID_; |
---|
3394 | $this->CharName_ = $this->API_charID_; |
---|
3395 | $data = $this->loaddata($myKeyString); |
---|
3396 | } else { |
---|
3397 | return "You are not logged in and have not set API details."; |
---|
3398 | } |
---|
3399 | } |
---|
3400 | |
---|
3401 | $xml_parser = xml_parser_create(); |
---|
3402 | xml_set_object ( $xml_parser, $this ); |
---|
3403 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
3404 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
3405 | |
---|
3406 | if (!xml_parse($xml_parser, $data, true)) |
---|
3407 | return "<i>Error getting XML data from api.eve-online.com/StarbaseList.xml.aspx </i><br><br>"; |
---|
3408 | |
---|
3409 | xml_parser_free($xml_parser); |
---|
3410 | |
---|
3411 | return $this->html; // should be empty, but keeping just incase - errors are returned by Text so worth looking anyway. |
---|
3412 | } |
---|
3413 | |
---|
3414 | function startElement($parser, $name, $attribs) |
---|
3415 | { |
---|
3416 | if ($name == "ROW") |
---|
3417 | { |
---|
3418 | global $tempdata; |
---|
3419 | |
---|
3420 | if (count($attribs)) |
---|
3421 | { |
---|
3422 | foreach ($attribs as $k => $v) |
---|
3423 | { |
---|
3424 | switch ($k) |
---|
3425 | { |
---|
3426 | case "ITEMID": |
---|
3427 | $tempdata['itemID'] = $v; |
---|
3428 | break; |
---|
3429 | case "TYPEID": |
---|
3430 | $tempdata['typeID'] = $v; |
---|
3431 | $tempdata['typeName'] = gettypeIDname($v); |
---|
3432 | break; |
---|
3433 | case "LOCATIONID": |
---|
3434 | $tempdata['locationID'] = $v; |
---|
3435 | $sql = 'select sys.sys_name, sys.sys_sec from kb3_systems sys where sys.sys_eve_id = '.$v; |
---|
3436 | |
---|
3437 | $qry = new DBQuery(); |
---|
3438 | $qry->execute($sql); |
---|
3439 | $row = $qry->getRow(); |
---|
3440 | |
---|
3441 | $tempdata['locationName'] = $row['sys_name']; |
---|
3442 | $mysec = $row['sys_sec']; |
---|
3443 | if ($mysec <= 0) |
---|
3444 | $tempdata['locationSec'] = number_format(0.0, 1); |
---|
3445 | else |
---|
3446 | $tempdata['locationSec'] = number_format(round($mysec, 1), 1); |
---|
3447 | break; |
---|
3448 | case "MOONID": |
---|
3449 | $tempdata['moonID'] = $v; |
---|
3450 | $tempmoon = getMoonName($v); |
---|
3451 | |
---|
3452 | if ($tempmoon == "") |
---|
3453 | { |
---|
3454 | // Use API IDtoName to get Moon Name. |
---|
3455 | $this->myIDName = new API_IDtoName(); |
---|
3456 | $this->myIDName->clear(); |
---|
3457 | $this->myIDName->setIDs($v); |
---|
3458 | $this->Output_ .= $this->myIDName->fetchXML(); |
---|
3459 | $myNames = $this->myIDName->getIDData(); |
---|
3460 | $tempdata['moonName'] = $myNames[0]['name']; |
---|
3461 | } else { |
---|
3462 | $tempdata['moonName'] = $tempmoon; |
---|
3463 | } |
---|
3464 | break; |
---|
3465 | case "STATE": |
---|
3466 | $tempdata['state'] = $v; |
---|
3467 | break; |
---|
3468 | case "STATETIMESTAMP": |
---|
3469 | $tempdata['stateTimestamp'] = $v; |
---|
3470 | break; |
---|
3471 | case "ONLINETIMESTAMP": |
---|
3472 | $tempdata['onlineTimestamp'] = $v; |
---|
3473 | $this->Starbase_[] = $tempdata; |
---|
3474 | |
---|
3475 | $tempdata = array(); |
---|
3476 | unset($tempdata); |
---|
3477 | break; |
---|
3478 | } |
---|
3479 | } |
---|
3480 | } |
---|
3481 | } |
---|
3482 | } |
---|
3483 | |
---|
3484 | function endElement($parser, $name) |
---|
3485 | { |
---|
3486 | // Details |
---|
3487 | if ($name == "ERROR") |
---|
3488 | $this->html .= $this->characterDataValue; |
---|
3489 | if ($name == "CURRENTTIME") |
---|
3490 | $this->CurrentTime_ = $this->characterDataValue; |
---|
3491 | if ($name == "CACHEDUNTIL") |
---|
3492 | { |
---|
3493 | $this->CachedUntil_ = $this->characterDataValue; |
---|
3494 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
3495 | ApiCache::set( $this->CharName_ . '_StarbaseList' , $this->characterDataValue); |
---|
3496 | } |
---|
3497 | } |
---|
3498 | |
---|
3499 | function characterData($parser, $data) |
---|
3500 | { |
---|
3501 | $this->characterDataValue = $data; |
---|
3502 | } |
---|
3503 | |
---|
3504 | function loaddata($keystring) |
---|
3505 | { |
---|
3506 | $configvalue = $this->CharName_ . '_StarbaseList'; |
---|
3507 | |
---|
3508 | $CachedTime = ApiCache::get($configvalue); |
---|
3509 | $UseCaching = config::get('API_UseCache'); |
---|
3510 | |
---|
3511 | $url = "http://api.eve-online.com/corp/StarbaseList.xml.aspx" . $keystring; |
---|
3512 | |
---|
3513 | $path = '/corp/StarbaseList.xml.aspx'; |
---|
3514 | |
---|
3515 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
3516 | if ($CachedTime == "") |
---|
3517 | { |
---|
3518 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
3519 | } |
---|
3520 | |
---|
3521 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
3522 | $cacheexists = true; |
---|
3523 | else |
---|
3524 | $cacheexists = false; |
---|
3525 | |
---|
3526 | // if API_UseCache = 1 (off) then don't use cache |
---|
3527 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists ) |
---|
3528 | { |
---|
3529 | $fp = fsockopen("api.eve-online.com", 80); |
---|
3530 | |
---|
3531 | if (!$fp) |
---|
3532 | { |
---|
3533 | $this->Output_ .= "Could not connect to API URL"; |
---|
3534 | } else { |
---|
3535 | // request the xml |
---|
3536 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
3537 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
3538 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
3539 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
3540 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
3541 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
3542 | fputs ($fp, $keystring."\r\n"); |
---|
3543 | |
---|
3544 | // retrieve contents |
---|
3545 | $contents = ""; |
---|
3546 | while (!feof($fp)) |
---|
3547 | { |
---|
3548 | $contents .= fgets($fp); |
---|
3549 | } |
---|
3550 | |
---|
3551 | // close connection |
---|
3552 | fclose($fp); |
---|
3553 | |
---|
3554 | $start = strpos($contents, "?>"); |
---|
3555 | if ($start !== FALSE) |
---|
3556 | { |
---|
3557 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
3558 | } |
---|
3559 | |
---|
3560 | // Save the file if we're caching (0 = true in Thunks world) |
---|
3561 | if ($UseCaching == 0) |
---|
3562 | { |
---|
3563 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
3564 | fwrite($file, $contents); |
---|
3565 | fclose($file); |
---|
3566 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
3567 | } |
---|
3568 | } |
---|
3569 | } else { |
---|
3570 | // re-use cached XML |
---|
3571 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
3572 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
3573 | fclose($fp); |
---|
3574 | } else { |
---|
3575 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
3576 | } |
---|
3577 | } |
---|
3578 | return $contents; |
---|
3579 | } |
---|
3580 | } |
---|
3581 | |
---|
3582 | // ********************************************************************************************************************************************** |
---|
3583 | // **************** API StarbaseDetail - /corp/StarbaseDetail.xml.aspx **************** |
---|
3584 | // ********************************************************************************************************************************************** |
---|
3585 | class API_StarbaseDetail |
---|
3586 | { |
---|
3587 | function getCachedUntil() |
---|
3588 | { |
---|
3589 | return $this->CachedUntil_; |
---|
3590 | } |
---|
3591 | |
---|
3592 | function getCurrentTime() |
---|
3593 | { |
---|
3594 | return $this->CurrentTime_; |
---|
3595 | } |
---|
3596 | |
---|
3597 | function setAPIKey($key) |
---|
3598 | { |
---|
3599 | $this->API_apiKey_ = $key; |
---|
3600 | } |
---|
3601 | |
---|
3602 | function setUserID($uid) |
---|
3603 | { |
---|
3604 | $this->API_userID_ = $uid; |
---|
3605 | } |
---|
3606 | |
---|
3607 | function setCharacterID($cid) |
---|
3608 | { |
---|
3609 | $this->API_charID_ = $cid; |
---|
3610 | } |
---|
3611 | |
---|
3612 | function setitemID($itemID) |
---|
3613 | { |
---|
3614 | $this->API_itemID_ = $itemID; |
---|
3615 | } |
---|
3616 | function getFuel() |
---|
3617 | { |
---|
3618 | return $this->Fuel_; |
---|
3619 | } |
---|
3620 | function getState() |
---|
3621 | { |
---|
3622 | return $this->State_; |
---|
3623 | } |
---|
3624 | function getstateTimestamp() |
---|
3625 | { |
---|
3626 | return $this->stateTimestamp_; |
---|
3627 | } |
---|
3628 | function getonlineTimestamp() |
---|
3629 | { |
---|
3630 | return $this->onlineTimestamp_; |
---|
3631 | } |
---|
3632 | function getusageFlags() |
---|
3633 | { |
---|
3634 | return $this->usageFlags_; |
---|
3635 | } |
---|
3636 | function getdeployFlags() |
---|
3637 | { |
---|
3638 | return $this->deployFlags_; |
---|
3639 | } |
---|
3640 | function getallowCorporationMembers() |
---|
3641 | { |
---|
3642 | return $this->allowCorporationMembers_; |
---|
3643 | } |
---|
3644 | function getallowAllianceMembers() |
---|
3645 | { |
---|
3646 | return $this->allowAllianceMembers_; |
---|
3647 | } |
---|
3648 | function getclaimSovereignty() |
---|
3649 | { |
---|
3650 | return $this->claimSovereignty_; |
---|
3651 | } |
---|
3652 | function getonStandingDrop() |
---|
3653 | { |
---|
3654 | return $this->onStandingDrop_; |
---|
3655 | } |
---|
3656 | function getonStatusDrop() |
---|
3657 | { |
---|
3658 | return $this->onStatusDrop_; |
---|
3659 | } |
---|
3660 | function getonAggression() |
---|
3661 | { |
---|
3662 | return $this->onAggression_; |
---|
3663 | } |
---|
3664 | function getonCorporationWar() |
---|
3665 | { |
---|
3666 | return $this->onCorporationWar_; |
---|
3667 | } |
---|
3668 | |
---|
3669 | |
---|
3670 | function fetchXML() |
---|
3671 | { |
---|
3672 | // is a player feed - take details from logged in user |
---|
3673 | if (user::get('usr_pilot_id')) |
---|
3674 | { |
---|
3675 | require_once('class.pilot.php'); |
---|
3676 | $plt = new pilot(user::get('usr_pilot_id')); |
---|
3677 | $usersname = $plt->getName(); |
---|
3678 | |
---|
3679 | $this->CharName_ = $usersname; |
---|
3680 | |
---|
3681 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $usersname . '"'; |
---|
3682 | |
---|
3683 | $qry = new DBQuery(); |
---|
3684 | $qry->execute($sql); |
---|
3685 | $row = $qry->getRow(); |
---|
3686 | |
---|
3687 | $pilot_id = $row['plt_id']; |
---|
3688 | $API_charID = $row['plt_externalid']; |
---|
3689 | |
---|
3690 | if ( $pilot_id == 0 ) |
---|
3691 | { |
---|
3692 | return "Something went wrong with finding pilots external ID<br>"; |
---|
3693 | } |
---|
3694 | |
---|
3695 | $newsql = 'SELECT userID , apiKey FROM kb3_api_user WHERE charID = "' . $API_charID . '"'; |
---|
3696 | $qry->execute($newsql); |
---|
3697 | $userrow = $qry->getRow(); |
---|
3698 | |
---|
3699 | $API_userID = $userrow['userID']; |
---|
3700 | $API_apiKey = $userrow['apiKey']; |
---|
3701 | |
---|
3702 | $myKeyString = "userID=" . $API_userID . "&apiKey=" . $API_apiKey . "&characterID=" . $API_charID . "&itemID=" . $this->API_itemID_; |
---|
3703 | |
---|
3704 | $data = $this->loaddata($myKeyString); |
---|
3705 | } else { |
---|
3706 | if (($this->API_userID_ != "") && ($this->API_apiKey_ != "") && ($this->API_charID_ != "") && ($this->API_itemID_ != "")) |
---|
3707 | { |
---|
3708 | $myKeyString = "userID=" . $this->API_userID_ . "&apiKey=" . $this->API_apiKey_ . "&characterID=" . $this->API_charID_ . "&itemID=" . $this->API_itemID_; |
---|
3709 | $this->CharName_ = $this->API_charID_; |
---|
3710 | $data = $this->loaddata($myKeyString); |
---|
3711 | } else { |
---|
3712 | return "You are not logged in and have not set API details."; |
---|
3713 | } |
---|
3714 | } |
---|
3715 | |
---|
3716 | $xml_parser = xml_parser_create(); |
---|
3717 | xml_set_object ( $xml_parser, $this ); |
---|
3718 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
3719 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
3720 | |
---|
3721 | if (!xml_parse($xml_parser, $data, true)) |
---|
3722 | return "<i>Error getting XML data from api.eve-online.com/StarbaseDetail.xml.aspx </i><br><br>"; |
---|
3723 | |
---|
3724 | xml_parser_free($xml_parser); |
---|
3725 | |
---|
3726 | return $this->html; // should be empty, but keeping just incase - errors are returned by Text so worth looking anyway. |
---|
3727 | } |
---|
3728 | |
---|
3729 | function startElement($parser, $name, $attribs) |
---|
3730 | { |
---|
3731 | if ($name == "ROW") |
---|
3732 | { |
---|
3733 | global $tempdata; |
---|
3734 | |
---|
3735 | if (count($attribs)) |
---|
3736 | { |
---|
3737 | foreach ($attribs as $k => $v) |
---|
3738 | { |
---|
3739 | switch ($k) |
---|
3740 | { |
---|
3741 | case "TYPEID": |
---|
3742 | $fueldata['typeID'] = $v; |
---|
3743 | $fueldata['typeName'] = gettypeIDname($v); |
---|
3744 | break; |
---|
3745 | case "QUANTITY": |
---|
3746 | $fueldata['quantity'] = $v; |
---|
3747 | $this->Fuel_[] = $fueldata; |
---|
3748 | |
---|
3749 | $fueldata = array(); |
---|
3750 | unset($fueldata); |
---|
3751 | break; |
---|
3752 | } |
---|
3753 | } |
---|
3754 | } |
---|
3755 | } |
---|
3756 | |
---|
3757 | if ($name == "ONSTANDINGDROP") |
---|
3758 | { |
---|
3759 | if (count($attribs)) |
---|
3760 | { |
---|
3761 | foreach ($attribs as $k => $v) |
---|
3762 | { |
---|
3763 | switch ($k) |
---|
3764 | { |
---|
3765 | case "ENABLED": |
---|
3766 | $this->onStandingDrop_['enabled'] = $v; |
---|
3767 | break; |
---|
3768 | case "STANDING": |
---|
3769 | $this->onStandingDrop_['standing'] = $v; |
---|
3770 | break; |
---|
3771 | } |
---|
3772 | } |
---|
3773 | } |
---|
3774 | } |
---|
3775 | |
---|
3776 | if ($name == "ONSTATUSDROP") |
---|
3777 | { |
---|
3778 | if (count($attribs)) |
---|
3779 | { |
---|
3780 | foreach ($attribs as $k => $v) |
---|
3781 | { |
---|
3782 | switch ($k) |
---|
3783 | { |
---|
3784 | case "ENABLED": |
---|
3785 | $this->onStatusDrop_['enabled'] = $v; |
---|
3786 | break; |
---|
3787 | case "STANDING": |
---|
3788 | $this->onStatusDrop_['standing'] = $v; |
---|
3789 | break; |
---|
3790 | } |
---|
3791 | } |
---|
3792 | } |
---|
3793 | } |
---|
3794 | |
---|
3795 | if ($name == "ONAGGRESSION") |
---|
3796 | { |
---|
3797 | if (count($attribs)) |
---|
3798 | { |
---|
3799 | foreach ($attribs as $k => $v) |
---|
3800 | { |
---|
3801 | switch ($k) |
---|
3802 | { |
---|
3803 | case "ENABLED": |
---|
3804 | $this->onAggression_['enabled'] = $v; |
---|
3805 | break; |
---|
3806 | } |
---|
3807 | } |
---|
3808 | } |
---|
3809 | } |
---|
3810 | |
---|
3811 | if ($name == "ONCORPORATIONWAR") |
---|
3812 | { |
---|
3813 | if (count($attribs)) |
---|
3814 | { |
---|
3815 | foreach ($attribs as $k => $v) |
---|
3816 | { |
---|
3817 | switch ($k) |
---|
3818 | { |
---|
3819 | case "ENABLED": |
---|
3820 | $this->onCorporationWar_['enabled'] = $v; |
---|
3821 | break; |
---|
3822 | } |
---|
3823 | } |
---|
3824 | } |
---|
3825 | } |
---|
3826 | } |
---|
3827 | |
---|
3828 | function endElement($parser, $name) |
---|
3829 | { |
---|
3830 | // Details |
---|
3831 | if ($name == "ERROR") |
---|
3832 | $this->html .= $this->characterDataValue; |
---|
3833 | |
---|
3834 | if ($name == "STATE") |
---|
3835 | $this->State_ .= $this->characterDataValue; |
---|
3836 | if ($name == "STATETIMESTAMP") |
---|
3837 | $this->stateTimestamp_ .= $this->characterDataValue; |
---|
3838 | if ($name == "ONLINETIMESTAMP") |
---|
3839 | $this->onlineTimestamp_ .= $this->characterDataValue; |
---|
3840 | |
---|
3841 | // General Settings |
---|
3842 | if ($name == "USAGEFLAGS") |
---|
3843 | $this->usageFlags_ .= $this->characterDataValue; |
---|
3844 | if ($name == "DEPLOYFLAGS") |
---|
3845 | $this->deployFlags_ .= $this->characterDataValue; |
---|
3846 | if ($name == "ALLOWCORPORATIONMEMBERS") |
---|
3847 | $this->allowCorporationMembers_ .= $this->characterDataValue; |
---|
3848 | if ($name == "ALLOWALLIANCEMEMBERS") |
---|
3849 | $this->allowAllianceMembers_ .= $this->characterDataValue; |
---|
3850 | if ($name == "CLAIMSOVEREIGNTY") |
---|
3851 | $this->claimSovereignty_ .= $this->characterDataValue; |
---|
3852 | |
---|
3853 | if ($name == "CURRENTTIME") |
---|
3854 | $this->CurrentTime_ = $this->characterDataValue; |
---|
3855 | if ($name == "CACHEDUNTIL") |
---|
3856 | { |
---|
3857 | $this->CachedUntil_ = $this->characterDataValue; |
---|
3858 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
3859 | ApiCache::set( $this->API_itemID_ . '_StarbaseDetail' , $this->characterDataValue); |
---|
3860 | } |
---|
3861 | } |
---|
3862 | |
---|
3863 | function characterData($parser, $data) |
---|
3864 | { |
---|
3865 | $this->characterDataValue = $data; |
---|
3866 | } |
---|
3867 | |
---|
3868 | function loaddata($keystring) |
---|
3869 | { |
---|
3870 | $configvalue = $this->API_itemID_ . '_StarbaseDetail'; |
---|
3871 | |
---|
3872 | $CachedTime = ApiCache::get($configvalue); |
---|
3873 | $UseCaching = config::get('API_UseCache'); |
---|
3874 | |
---|
3875 | $url = "http://api.eve-online.com/corp/StarbaseDetail.xml.aspx" . $keystring; |
---|
3876 | |
---|
3877 | $path = '/corp/StarbaseDetail.xml.aspx'; |
---|
3878 | |
---|
3879 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
3880 | if ($CachedTime == "") |
---|
3881 | { |
---|
3882 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
3883 | } |
---|
3884 | |
---|
3885 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
3886 | $cacheexists = true; |
---|
3887 | else |
---|
3888 | $cacheexists = false; |
---|
3889 | |
---|
3890 | // if API_UseCache = 1 (off) then don't use cache |
---|
3891 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists ) |
---|
3892 | { |
---|
3893 | $fp = fsockopen("api.eve-online.com", 80); |
---|
3894 | |
---|
3895 | if (!$fp) |
---|
3896 | { |
---|
3897 | $this->Output_ .= "Could not connect to API URL"; |
---|
3898 | } else { |
---|
3899 | // request the xml |
---|
3900 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
3901 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
3902 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
3903 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
3904 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
3905 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
3906 | fputs ($fp, $keystring."\r\n"); |
---|
3907 | |
---|
3908 | // retrieve contents |
---|
3909 | $contents = ""; |
---|
3910 | while (!feof($fp)) |
---|
3911 | { |
---|
3912 | $contents .= fgets($fp); |
---|
3913 | } |
---|
3914 | |
---|
3915 | // close connection |
---|
3916 | fclose($fp); |
---|
3917 | |
---|
3918 | $start = strpos($contents, "?>"); |
---|
3919 | if ($start !== FALSE) |
---|
3920 | { |
---|
3921 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
3922 | } |
---|
3923 | |
---|
3924 | // Save the file if we're caching (0 = true in Thunks world) |
---|
3925 | if ($UseCaching == 0) |
---|
3926 | { |
---|
3927 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
3928 | fwrite($file, $contents); |
---|
3929 | fclose($file); |
---|
3930 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
3931 | } |
---|
3932 | } |
---|
3933 | } else { |
---|
3934 | // re-use cached XML |
---|
3935 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
3936 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
3937 | fclose($fp); |
---|
3938 | } else { |
---|
3939 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
3940 | } |
---|
3941 | } |
---|
3942 | return $contents; |
---|
3943 | } |
---|
3944 | } |
---|
3945 | |
---|
3946 | // ********************************************************************************************************************************************** |
---|
3947 | // **************** API Corporation Sheet - /corp/CorporationSheet.xml.aspx **************** |
---|
3948 | // ********************************************************************************************************************************************** |
---|
3949 | // INCOMPLETE - MISSING CORP DIVISIONS AND WALLET DIVISIONS |
---|
3950 | class API_CorporationSheet |
---|
3951 | { |
---|
3952 | function getCachedUntil() |
---|
3953 | { |
---|
3954 | return $this->CachedUntil_; |
---|
3955 | } |
---|
3956 | |
---|
3957 | function getCurrentTime() |
---|
3958 | { |
---|
3959 | return $this->CurrentTime_; |
---|
3960 | } |
---|
3961 | |
---|
3962 | function setAPIKey($key) |
---|
3963 | { |
---|
3964 | $this->API_apiKey_ = $key; |
---|
3965 | } |
---|
3966 | |
---|
3967 | function setUserID($uid) |
---|
3968 | { |
---|
3969 | $this->API_userID_ = $uid; |
---|
3970 | } |
---|
3971 | |
---|
3972 | function setCharacterID($cid) |
---|
3973 | { |
---|
3974 | $this->API_charID_ = $cid; |
---|
3975 | } |
---|
3976 | |
---|
3977 | function setCorpID($corpid) |
---|
3978 | { |
---|
3979 | $this->API_corpID_ = $corpid; |
---|
3980 | } |
---|
3981 | |
---|
3982 | function getAllianceID() |
---|
3983 | { |
---|
3984 | return $this->allianceID_; |
---|
3985 | } |
---|
3986 | |
---|
3987 | function getAllianceName() |
---|
3988 | { |
---|
3989 | return $this->allianceName_; |
---|
3990 | } |
---|
3991 | |
---|
3992 | function getCorporationID() |
---|
3993 | { |
---|
3994 | return $this->corporationID_; |
---|
3995 | } |
---|
3996 | |
---|
3997 | function getCorporationName() |
---|
3998 | { |
---|
3999 | return $this->corporationName_; |
---|
4000 | } |
---|
4001 | |
---|
4002 | function getTicker() |
---|
4003 | { |
---|
4004 | return $this->ticker_; |
---|
4005 | } |
---|
4006 | |
---|
4007 | function getCeoID() |
---|
4008 | { |
---|
4009 | return $this->ceoID_; |
---|
4010 | } |
---|
4011 | |
---|
4012 | function getCeoName() |
---|
4013 | { |
---|
4014 | return $this->ceoName_; |
---|
4015 | } |
---|
4016 | |
---|
4017 | function getStationID() |
---|
4018 | { |
---|
4019 | return $this->stationID_; |
---|
4020 | } |
---|
4021 | |
---|
4022 | function getStationName() |
---|
4023 | { |
---|
4024 | return $this->stationName_; |
---|
4025 | } |
---|
4026 | |
---|
4027 | function getDescription() |
---|
4028 | { |
---|
4029 | return $this->description_; |
---|
4030 | } |
---|
4031 | |
---|
4032 | function getUrl() |
---|
4033 | { |
---|
4034 | return $this->url_; |
---|
4035 | } |
---|
4036 | |
---|
4037 | function getLogo() |
---|
4038 | { |
---|
4039 | return $this->logo_; |
---|
4040 | } |
---|
4041 | |
---|
4042 | function getTaxRate() |
---|
4043 | { |
---|
4044 | return $this->taxRate_; |
---|
4045 | } |
---|
4046 | |
---|
4047 | function getMemberCount() |
---|
4048 | { |
---|
4049 | return $this->memberCount_; |
---|
4050 | } |
---|
4051 | |
---|
4052 | function getMemberLimit() |
---|
4053 | { |
---|
4054 | return $this->memberLimit_; |
---|
4055 | } |
---|
4056 | |
---|
4057 | function getShares() |
---|
4058 | { |
---|
4059 | return $this->shares_; |
---|
4060 | } |
---|
4061 | |
---|
4062 | function fetchXML() |
---|
4063 | { |
---|
4064 | // is a player feed - take details from logged in user |
---|
4065 | if ($this->API_corpID_ != "") |
---|
4066 | { |
---|
4067 | $myKeyString = "corporationID=" . $this->API_corpID_; |
---|
4068 | $this->CharName_ = $this->API_corpID_; |
---|
4069 | $data = $this->loaddata($myKeyString); |
---|
4070 | |
---|
4071 | } elseif (user::get('usr_pilot_id')) { |
---|
4072 | require_once('class.pilot.php'); |
---|
4073 | $plt = new pilot(user::get('usr_pilot_id')); |
---|
4074 | $usersname = $plt->getName(); |
---|
4075 | |
---|
4076 | $this->CharName_ = $usersname; |
---|
4077 | |
---|
4078 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $usersname . '"'; |
---|
4079 | |
---|
4080 | $qry = new DBQuery(); |
---|
4081 | $qry->execute($sql); |
---|
4082 | $row = $qry->getRow(); |
---|
4083 | |
---|
4084 | $pilot_id = $row['plt_id']; |
---|
4085 | $API_charID = $row['plt_externalid']; |
---|
4086 | |
---|
4087 | if ( $pilot_id == 0 ) |
---|
4088 | { |
---|
4089 | return "Something went wrong with finding pilots external ID<br>"; |
---|
4090 | } |
---|
4091 | |
---|
4092 | $newsql = 'SELECT userID , apiKey FROM kb3_api_user WHERE charID = "' . $API_charID . '"'; |
---|
4093 | $qry->execute($newsql); |
---|
4094 | $userrow = $qry->getRow(); |
---|
4095 | |
---|
4096 | $API_userID = $userrow['userID']; |
---|
4097 | $API_apiKey = $userrow['apiKey']; |
---|
4098 | |
---|
4099 | $myKeyString = "userID=" . $API_userID . "&apiKey=" . $API_apiKey . "&characterID=" . $API_charID; |
---|
4100 | |
---|
4101 | $data = $this->loaddata($myKeyString); |
---|
4102 | } else { |
---|
4103 | if (($this->API_userID_ != "") && ($this->API_apiKey_ != "") && ($this->API_charID_ != "")) |
---|
4104 | { |
---|
4105 | $myKeyString = "userID=" . $this->API_userID_ . "&apiKey=" . $this->API_apiKey_ . "&characterID=" . $this->API_charID_; |
---|
4106 | $this->CharName_ = $this->API_charID_; |
---|
4107 | $data = $this->loaddata($myKeyString); |
---|
4108 | } else { |
---|
4109 | return "You are not logged in and have not set API details."; |
---|
4110 | } |
---|
4111 | } |
---|
4112 | |
---|
4113 | $xml_parser = xml_parser_create(); |
---|
4114 | xml_set_object ( $xml_parser, $this ); |
---|
4115 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
4116 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
4117 | |
---|
4118 | if (!xml_parse($xml_parser, $data, true)) |
---|
4119 | return "<i>Error getting XML data from api.eve-online.com/CorporationSheet.xml.aspx </i><br><br>"; |
---|
4120 | |
---|
4121 | xml_parser_free($xml_parser); |
---|
4122 | |
---|
4123 | return $this->html; // should be empty, but keeping just incase - errors are returned by Text so worth looking anyway. |
---|
4124 | } |
---|
4125 | |
---|
4126 | function startElement($parser, $name, $attribs) |
---|
4127 | { |
---|
4128 | $this->characterDataValue = ""; |
---|
4129 | |
---|
4130 | if ($name == "DESCRIPTION") |
---|
4131 | { |
---|
4132 | $this->DataIsDescription = true; |
---|
4133 | //$this->characterDataValue = ""; |
---|
4134 | } else { |
---|
4135 | $this->DataIsDescription = false; |
---|
4136 | } |
---|
4137 | } |
---|
4138 | |
---|
4139 | function endElement($parser, $name) |
---|
4140 | { |
---|
4141 | // Details |
---|
4142 | switch ($name) |
---|
4143 | { |
---|
4144 | case "ERROR": |
---|
4145 | $this->html .= $this->characterDataValue; |
---|
4146 | break; |
---|
4147 | case "CORPORATIONID": |
---|
4148 | $this->corporationID_ = $this->characterDataValue; |
---|
4149 | break; |
---|
4150 | case "CORPORATIONNAME": |
---|
4151 | $this->corporationName_ = $this->characterDataValue; |
---|
4152 | break; |
---|
4153 | case "TICKER": |
---|
4154 | $this->ticker_ = $this->characterDataValue; |
---|
4155 | break; |
---|
4156 | case "CEOID": |
---|
4157 | $this->ceoID_ = $this->characterDataValue; |
---|
4158 | break; |
---|
4159 | case "CEONAME": |
---|
4160 | $this->ceoName_ = $this->characterDataValue; |
---|
4161 | break; |
---|
4162 | case "STATIONID": |
---|
4163 | $this->stationID_ = $this->characterDataValue; |
---|
4164 | break; |
---|
4165 | case "STATIONNAME": |
---|
4166 | $this->stationName_ = $this->characterDataValue; |
---|
4167 | break; |
---|
4168 | case "DESCRIPTION": |
---|
4169 | $this->description_ = $this->characterDataValue; |
---|
4170 | break; |
---|
4171 | case "URL": |
---|
4172 | $this->url_ = $this->characterDataValue; |
---|
4173 | break; |
---|
4174 | case "ALLIANCEID": |
---|
4175 | $this->allianceID_ = $this->characterDataValue; |
---|
4176 | break; |
---|
4177 | case "ALLIANCENAME": |
---|
4178 | $this->allianceName_ = $this->characterDataValue; |
---|
4179 | break; |
---|
4180 | case "TAXRATE": |
---|
4181 | $this->taxRate_ = $this->characterDataValue; |
---|
4182 | break; |
---|
4183 | case "MEMBERCOUNT": |
---|
4184 | $this->memberCount_ = $this->characterDataValue; |
---|
4185 | break; |
---|
4186 | case "MEMBERLIMIT": |
---|
4187 | $this->memberLimit_ = $this->characterDataValue; |
---|
4188 | break; |
---|
4189 | case "SHARES": |
---|
4190 | $this->shares_ = $this->characterDataValue; |
---|
4191 | break; |
---|
4192 | |
---|
4193 | case "GRAPHICID": |
---|
4194 | $this->logo_["graphicID"] = $this->characterDataValue; |
---|
4195 | break; |
---|
4196 | case "SHAPE1": |
---|
4197 | $this->logo_["shape1"] = $this->characterDataValue; |
---|
4198 | break; |
---|
4199 | case "SHAPE2": |
---|
4200 | $this->logo_["shape2"] = $this->characterDataValue; |
---|
4201 | break; |
---|
4202 | case "SHAPE3": |
---|
4203 | $this->logo_["shape3"] = $this->characterDataValue; |
---|
4204 | break; |
---|
4205 | case "COLOR1": |
---|
4206 | $this->logo_["colour1"] = $this->characterDataValue; |
---|
4207 | break; |
---|
4208 | case "COLOR2": |
---|
4209 | $this->logo_["colour2"] = $this->characterDataValue; |
---|
4210 | break; |
---|
4211 | case "COLOR3": |
---|
4212 | $this->logo_["colour3"] = $this->characterDataValue; |
---|
4213 | break; |
---|
4214 | } |
---|
4215 | |
---|
4216 | if ($name == "CURRENTTIME") |
---|
4217 | $this->CurrentTime_ = $this->characterDataValue; |
---|
4218 | if ($name == "CACHEDUNTIL") |
---|
4219 | { |
---|
4220 | $this->CachedUntil_ = $this->characterDataValue; |
---|
4221 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
4222 | ApiCache::set( $this->CharName_ . '_CorporationSheet' , $this->characterDataValue); |
---|
4223 | } |
---|
4224 | } |
---|
4225 | |
---|
4226 | function characterData($parser, $data) |
---|
4227 | { |
---|
4228 | // This is a fix for some hosts that strip "<" and ">" from the API XML when it's put into a string. I have no idea why this happens, where or how - but this puts them back |
---|
4229 | if ($this->DataIsDescription) |
---|
4230 | { |
---|
4231 | if ( $data == "<" ) |
---|
4232 | { |
---|
4233 | $this->tagsareworking = true; |
---|
4234 | } |
---|
4235 | |
---|
4236 | if (!$this->tagsareworking) |
---|
4237 | { |
---|
4238 | if ( ($data == "br") || ($data == "b") || ($data == "/a") || ($data == "/b") || ($data == "/font") || (substr($data,0,4)== "font") || (substr($data,0,6)== "a href")) |
---|
4239 | { |
---|
4240 | $data = "<" .$data.">"; |
---|
4241 | } |
---|
4242 | } |
---|
4243 | $this->characterDataValue .= $data; |
---|
4244 | } else { |
---|
4245 | $this->characterDataValue = $data; |
---|
4246 | } |
---|
4247 | |
---|
4248 | |
---|
4249 | //echo $data; |
---|
4250 | } |
---|
4251 | |
---|
4252 | function loaddata($keystring) |
---|
4253 | { |
---|
4254 | $configvalue = $this->CharName_ . '_CorporationSheet'; |
---|
4255 | |
---|
4256 | $CachedTime = ApiCache::get($configvalue); |
---|
4257 | $UseCaching = config::get('API_UseCache'); |
---|
4258 | |
---|
4259 | $url = "http://api.eve-online.com/corp/CorporationSheet.xml.aspx" . $keystring; |
---|
4260 | |
---|
4261 | $path = '/corp/CorporationSheet.xml.aspx'; |
---|
4262 | |
---|
4263 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
4264 | if ($CachedTime == "") |
---|
4265 | { |
---|
4266 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
4267 | } |
---|
4268 | |
---|
4269 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
4270 | $cacheexists = true; |
---|
4271 | else |
---|
4272 | $cacheexists = false; |
---|
4273 | |
---|
4274 | // if API_UseCache = 1 (off) then don't use cache |
---|
4275 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists ) |
---|
4276 | { |
---|
4277 | $fp = fsockopen("api.eve-online.com", 80); |
---|
4278 | |
---|
4279 | if (!$fp) |
---|
4280 | { |
---|
4281 | $this->Output_ .= "Could not connect to API URL"; |
---|
4282 | } else { |
---|
4283 | // request the xml |
---|
4284 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
4285 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
4286 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
4287 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
4288 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
4289 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
4290 | fputs ($fp, $keystring."\r\n"); |
---|
4291 | |
---|
4292 | // retrieve contents |
---|
4293 | $contents = ""; |
---|
4294 | while (!feof($fp)) |
---|
4295 | { |
---|
4296 | $contents .= fgets($fp); |
---|
4297 | } |
---|
4298 | |
---|
4299 | // close connection |
---|
4300 | fclose($fp); |
---|
4301 | |
---|
4302 | $start = strpos($contents, "?>"); |
---|
4303 | if ($start !== FALSE) |
---|
4304 | { |
---|
4305 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
4306 | } |
---|
4307 | |
---|
4308 | // Save the file if we're caching (0 = true in Thunks world) |
---|
4309 | if ($UseCaching == 0) |
---|
4310 | { |
---|
4311 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
4312 | fwrite($file, $contents); |
---|
4313 | fclose($file); |
---|
4314 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
4315 | } |
---|
4316 | } |
---|
4317 | } else { |
---|
4318 | // re-use cached XML |
---|
4319 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
4320 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
4321 | fclose($fp); |
---|
4322 | } else { |
---|
4323 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
4324 | } |
---|
4325 | } |
---|
4326 | return $contents; |
---|
4327 | } |
---|
4328 | } |
---|
4329 | // ********************************************************************************************************************************************** |
---|
4330 | // **************** API Name -> ID Conversion /eve/CharacterID.xml.aspx **************** |
---|
4331 | // ********************************************************************************************************************************************** |
---|
4332 | class API_NametoID |
---|
4333 | { |
---|
4334 | function getCachedUntil() |
---|
4335 | { |
---|
4336 | return $this->CachedUntil_; |
---|
4337 | } |
---|
4338 | |
---|
4339 | function getCurrentTime() |
---|
4340 | { |
---|
4341 | return $this->CurrentTime_; |
---|
4342 | } |
---|
4343 | |
---|
4344 | function setNames($names) |
---|
4345 | { |
---|
4346 | $this->API_Names_ = $names; |
---|
4347 | } |
---|
4348 | function getNameData() |
---|
4349 | { |
---|
4350 | return $this->NameData_; |
---|
4351 | } |
---|
4352 | |
---|
4353 | function clear() |
---|
4354 | { |
---|
4355 | $this->NameData_ = array(); |
---|
4356 | unset($this->NameData_); |
---|
4357 | } |
---|
4358 | |
---|
4359 | function fetchXML() |
---|
4360 | { |
---|
4361 | if ($this->API_Names_ != "") |
---|
4362 | { |
---|
4363 | $myKeyString = "names=" . $this->API_Names_; |
---|
4364 | $data = $this->loaddata($myKeyString); |
---|
4365 | } else { |
---|
4366 | return "No Names have been input."; |
---|
4367 | } |
---|
4368 | |
---|
4369 | $xml_parser = xml_parser_create(); |
---|
4370 | xml_set_object ( $xml_parser, $this ); |
---|
4371 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
4372 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
4373 | |
---|
4374 | if (!xml_parse($xml_parser, $data, true)) |
---|
4375 | return "<i>Error getting XML data from api.eve-online.com/CharacterID.xml.aspx </i><br><br>"; |
---|
4376 | |
---|
4377 | xml_parser_free($xml_parser); |
---|
4378 | |
---|
4379 | return $this->html; // should be empty, but keeping just incase - errors are returned by Text so worth looking anyway. |
---|
4380 | } |
---|
4381 | |
---|
4382 | function startElement($parser, $name, $attribs) |
---|
4383 | { |
---|
4384 | global $NameData; |
---|
4385 | |
---|
4386 | if ($name == "ROW") |
---|
4387 | { |
---|
4388 | if (count($attribs)) |
---|
4389 | { |
---|
4390 | foreach ($attribs as $k => $v) |
---|
4391 | { |
---|
4392 | switch ($k) |
---|
4393 | { |
---|
4394 | case "NAME": |
---|
4395 | $NameData['name'] = $v; |
---|
4396 | break; |
---|
4397 | case "CHARACTERID": |
---|
4398 | $NameData['characterID'] = $v; |
---|
4399 | break; |
---|
4400 | } |
---|
4401 | } |
---|
4402 | } |
---|
4403 | } |
---|
4404 | } |
---|
4405 | |
---|
4406 | function endElement($parser, $name) |
---|
4407 | { |
---|
4408 | global $NameData; |
---|
4409 | |
---|
4410 | // Details |
---|
4411 | if ($name == "ERROR") |
---|
4412 | $this->html .= $this->characterDataValue; |
---|
4413 | |
---|
4414 | if ($name == "ROW") |
---|
4415 | { |
---|
4416 | $this->NameData_[] = $NameData; |
---|
4417 | $NameData = array(); |
---|
4418 | unset($NameData); |
---|
4419 | } |
---|
4420 | |
---|
4421 | if ($name == "CURRENTTIME") |
---|
4422 | $this->CurrentTime_ = $this->characterDataValue; |
---|
4423 | if ($name == "CACHEDUNTIL") // cache not needed for this process |
---|
4424 | { |
---|
4425 | $this->CachedUntil_ = $this->characterDataValue; |
---|
4426 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
4427 | //ApiCache::set( $this->CharName_ . 'CharacterID' , $this->characterDataValue); |
---|
4428 | } |
---|
4429 | } |
---|
4430 | |
---|
4431 | function characterData($parser, $data) |
---|
4432 | { |
---|
4433 | $this->characterDataValue = $data; |
---|
4434 | } |
---|
4435 | |
---|
4436 | function loaddata($keystring) |
---|
4437 | { |
---|
4438 | $url = "http://api.eve-online.com/eve/CharacterID.xml.aspx" . $keystring; |
---|
4439 | |
---|
4440 | $path = '/eve/CharacterID.xml.aspx'; |
---|
4441 | |
---|
4442 | |
---|
4443 | $fp = fsockopen("api.eve-online.com", 80); |
---|
4444 | |
---|
4445 | if (!$fp) |
---|
4446 | { |
---|
4447 | $this->Output_ .= "Could not connect to API URL"; |
---|
4448 | } else { |
---|
4449 | // request the xml |
---|
4450 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
4451 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
4452 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
4453 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
4454 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
4455 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
4456 | fputs ($fp, $keystring."\r\n"); |
---|
4457 | |
---|
4458 | // retrieve contents |
---|
4459 | $contents = ""; |
---|
4460 | while (!feof($fp)) |
---|
4461 | { |
---|
4462 | $contents .= fgets($fp); |
---|
4463 | } |
---|
4464 | |
---|
4465 | // close connection |
---|
4466 | fclose($fp); |
---|
4467 | |
---|
4468 | $start = strpos($contents, "?>"); |
---|
4469 | if ($start !== FALSE) |
---|
4470 | { |
---|
4471 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
4472 | } |
---|
4473 | } |
---|
4474 | |
---|
4475 | return $contents; |
---|
4476 | } |
---|
4477 | } |
---|
4478 | // ********************************************************************************************************************************************** |
---|
4479 | // **************** API ID -> Name Conversion /eve/CharacterID.xml.aspx **************** |
---|
4480 | // ********************************************************************************************************************************************** |
---|
4481 | class API_IDtoName |
---|
4482 | { |
---|
4483 | function getCachedUntil() |
---|
4484 | { |
---|
4485 | return $this->CachedUntil_; |
---|
4486 | } |
---|
4487 | |
---|
4488 | function getCurrentTime() |
---|
4489 | { |
---|
4490 | return $this->CurrentTime_; |
---|
4491 | } |
---|
4492 | |
---|
4493 | function setIDs($IDs) |
---|
4494 | { |
---|
4495 | $this->API_IDs_ = $IDs; |
---|
4496 | } |
---|
4497 | function getIDData() |
---|
4498 | { |
---|
4499 | return $this->NameData_; |
---|
4500 | } |
---|
4501 | |
---|
4502 | function clear() |
---|
4503 | { |
---|
4504 | $this->NameData_ = array(); |
---|
4505 | unset($this->NameData_); |
---|
4506 | } |
---|
4507 | |
---|
4508 | function fetchXML() |
---|
4509 | { |
---|
4510 | if ($this->API_IDs_ != "") |
---|
4511 | { |
---|
4512 | $myKeyString = "ids=" . $this->API_IDs_; |
---|
4513 | $data = $this->loaddata($myKeyString); |
---|
4514 | } else { |
---|
4515 | return "No IDs have been input."; |
---|
4516 | } |
---|
4517 | |
---|
4518 | $xml_parser = xml_parser_create(); |
---|
4519 | xml_set_object ( $xml_parser, $this ); |
---|
4520 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
4521 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
4522 | |
---|
4523 | if (!xml_parse($xml_parser, $data, true)) |
---|
4524 | return "<i>Error getting XML data from api.eve-online.com/CharacterName.xml.aspx </i><br><br>"; |
---|
4525 | |
---|
4526 | xml_parser_free($xml_parser); |
---|
4527 | |
---|
4528 | return $this->html; // should be empty, but keeping just incase - errors are returned by Text so worth looking anyway. |
---|
4529 | } |
---|
4530 | |
---|
4531 | function startElement($parser, $name, $attribs) |
---|
4532 | { |
---|
4533 | global $NameData; |
---|
4534 | |
---|
4535 | if ($name == "ROW") |
---|
4536 | { |
---|
4537 | if (count($attribs)) |
---|
4538 | { |
---|
4539 | foreach ($attribs as $k => $v) |
---|
4540 | { |
---|
4541 | switch ($k) |
---|
4542 | { |
---|
4543 | case "NAME": |
---|
4544 | $NameData['name'] = $v; |
---|
4545 | break; |
---|
4546 | case "CHARACTERID": |
---|
4547 | $NameData['characterID'] = $v; |
---|
4548 | break; |
---|
4549 | } |
---|
4550 | } |
---|
4551 | } |
---|
4552 | } |
---|
4553 | } |
---|
4554 | |
---|
4555 | function endElement($parser, $name) |
---|
4556 | { |
---|
4557 | global $NameData; |
---|
4558 | |
---|
4559 | // Details |
---|
4560 | if ($name == "ERROR") |
---|
4561 | $this->html .= $this->characterDataValue; |
---|
4562 | |
---|
4563 | if ($name == "ROW") |
---|
4564 | { |
---|
4565 | $this->NameData_[] = $NameData; |
---|
4566 | $NameData = array(); |
---|
4567 | unset($NameData); |
---|
4568 | } |
---|
4569 | |
---|
4570 | if ($name == "CURRENTTIME") |
---|
4571 | $this->CurrentTime_ = $this->characterDataValue; |
---|
4572 | if ($name == "CACHEDUNTIL") // cache not needed for this process |
---|
4573 | { |
---|
4574 | $this->CachedUntil_ = $this->characterDataValue; |
---|
4575 | //ApiCache::set('API_eve_RefTypes' , $this->characterDataValue); |
---|
4576 | //ApiCache::set( $this->CharName_ . 'CharacterID' , $this->characterDataValue); |
---|
4577 | } |
---|
4578 | } |
---|
4579 | |
---|
4580 | function characterData($parser, $data) |
---|
4581 | { |
---|
4582 | $this->characterDataValue = $data; |
---|
4583 | } |
---|
4584 | |
---|
4585 | function loaddata($keystring) |
---|
4586 | { |
---|
4587 | $url = "http://api.eve-online.com/eve/CharacterName.xml.aspx" . $keystring; |
---|
4588 | |
---|
4589 | $path = '/eve/CharacterName.xml.aspx'; |
---|
4590 | |
---|
4591 | |
---|
4592 | $fp = fsockopen("api.eve-online.com", 80); |
---|
4593 | |
---|
4594 | if (!$fp) |
---|
4595 | { |
---|
4596 | $this->Output_ .= "Could not connect to API URL"; |
---|
4597 | } else { |
---|
4598 | // request the xml |
---|
4599 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
4600 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
4601 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
4602 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
4603 | fputs ($fp, "Content-Length: " . strlen($keystring) . "\r\n"); |
---|
4604 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
4605 | fputs ($fp, $keystring."\r\n"); |
---|
4606 | |
---|
4607 | // retrieve contents |
---|
4608 | $contents = ""; |
---|
4609 | while (!feof($fp)) |
---|
4610 | { |
---|
4611 | $contents .= fgets($fp); |
---|
4612 | } |
---|
4613 | |
---|
4614 | // close connection |
---|
4615 | fclose($fp); |
---|
4616 | |
---|
4617 | $start = strpos($contents, "?>"); |
---|
4618 | if ($start !== FALSE) |
---|
4619 | { |
---|
4620 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
4621 | } |
---|
4622 | } |
---|
4623 | |
---|
4624 | return $contents; |
---|
4625 | } |
---|
4626 | } |
---|
4627 | |
---|
4628 | // ********************************************************************************************************************************************** |
---|
4629 | // **************** API Server Status - /server/ServerStatus.xml.aspx **************** |
---|
4630 | // ********************************************************************************************************************************************** |
---|
4631 | |
---|
4632 | class API_ServerStatus |
---|
4633 | { |
---|
4634 | function getCachedUntil() |
---|
4635 | { |
---|
4636 | return $this->CachedUntil_; |
---|
4637 | } |
---|
4638 | |
---|
4639 | function getCurrentTime() |
---|
4640 | { |
---|
4641 | return $this->CurrentTime_; |
---|
4642 | } |
---|
4643 | |
---|
4644 | function getserverOpen() |
---|
4645 | { |
---|
4646 | return $this->serverOpen_; |
---|
4647 | } |
---|
4648 | |
---|
4649 | function getonlinePlayers() |
---|
4650 | { |
---|
4651 | return $this->onlinePlayers_; |
---|
4652 | } |
---|
4653 | |
---|
4654 | function fetchXML() |
---|
4655 | { |
---|
4656 | $data = LoadGlobalData('/server/ServerStatus.xml.aspx'); |
---|
4657 | |
---|
4658 | $xml_parser = xml_parser_create(); |
---|
4659 | xml_set_object ( $xml_parser, $this ); |
---|
4660 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
4661 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
4662 | |
---|
4663 | if (!xml_parse($xml_parser, $data, true)) |
---|
4664 | return "<i>Error getting XML data from api.eve-online.com/server/ServerStatus.xml.aspx</i><br><br>"; |
---|
4665 | |
---|
4666 | xml_parser_free($xml_parser); |
---|
4667 | |
---|
4668 | return $this->html; |
---|
4669 | } |
---|
4670 | |
---|
4671 | function startElement($parser, $name, $attribs) |
---|
4672 | { |
---|
4673 | // nothing to do here... |
---|
4674 | } |
---|
4675 | |
---|
4676 | function endElement($parser, $name) |
---|
4677 | { |
---|
4678 | global $tempvalue; |
---|
4679 | |
---|
4680 | if ($name == "CURRENTTIME") |
---|
4681 | $this->CurrentTime_ = $tempvalue; |
---|
4682 | if ($name == "SERVEROPEN") |
---|
4683 | $this->serverOpen_ = $tempvalue; |
---|
4684 | if ($name == "ONLINEPLAYERS") |
---|
4685 | $this->onlinePlayers_ = $tempvalue; |
---|
4686 | if ($name == "CACHEDUNTIL") |
---|
4687 | { |
---|
4688 | $this->CachedUntil_ = $tempvalue; |
---|
4689 | ApiCache::set( 'API_server_ServerStatus' , $tempvalue); |
---|
4690 | } |
---|
4691 | } |
---|
4692 | |
---|
4693 | function characterData($parser, $data) |
---|
4694 | { |
---|
4695 | global $tempvalue; |
---|
4696 | |
---|
4697 | $tempvalue = $data; |
---|
4698 | } |
---|
4699 | } |
---|
4700 | |
---|
4701 | // ********************************************************************************************************************************************** |
---|
4702 | // ********************************************************************************************************************************************** |
---|
4703 | // **************** GENERIC FUNCTIONS **************** |
---|
4704 | // ********************************************************************************************************************************************** |
---|
4705 | // ********************************************************************************************************************************************** |
---|
4706 | |
---|
4707 | // ********************************************************************************************************************************************** |
---|
4708 | // **************** Load Generic XML **************** |
---|
4709 | // ********************************************************************************************************************************************** |
---|
4710 | |
---|
4711 | // loads a generic XML sheet that requires no API Login as such |
---|
4712 | function LoadGlobalData($path) |
---|
4713 | { |
---|
4714 | $temppath = substr($path, 0, strlen($path) - 14); |
---|
4715 | $configvalue = "API" . str_replace("/", "_", $temppath); |
---|
4716 | |
---|
4717 | $CachedTime = ApiCache::get($configvalue); |
---|
4718 | $UseCaching = config::get('API_UseCache'); |
---|
4719 | |
---|
4720 | // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. |
---|
4721 | if ($CachedTime == "") |
---|
4722 | { |
---|
4723 | $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. |
---|
4724 | } |
---|
4725 | |
---|
4726 | if (is_file(getcwd().'/cache/api/'.$configvalue.'.xml')) |
---|
4727 | $cacheexists = true; |
---|
4728 | else |
---|
4729 | $cacheexists = false; |
---|
4730 | |
---|
4731 | if ((strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0) || ($UseCaching == 1) || !$cacheexists )// if API_UseCache = 1 (off) then don't use cache |
---|
4732 | { |
---|
4733 | $fp = fsockopen("api.eve-online.com", 80); |
---|
4734 | |
---|
4735 | if (!$fp) |
---|
4736 | { |
---|
4737 | echo "Error", "Could not connect to API URL<br>"; |
---|
4738 | } else { |
---|
4739 | // request the xml |
---|
4740 | fputs ($fp, "POST " . $path . " HTTP/1.0\r\n"); |
---|
4741 | fputs ($fp, "Host: api.eve-online.com\r\n"); |
---|
4742 | fputs ($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); |
---|
4743 | fputs ($fp, "User-Agent: PHPApi\r\n"); |
---|
4744 | fputs ($fp, "Content-Length: 0\r\n"); |
---|
4745 | fputs ($fp, "Connection: close\r\n\r\n"); |
---|
4746 | fputs ($fp, "\r\n"); |
---|
4747 | |
---|
4748 | // retrieve contents |
---|
4749 | $contents = ""; |
---|
4750 | while (!feof($fp)) |
---|
4751 | { |
---|
4752 | $contents .= fgets($fp); |
---|
4753 | } |
---|
4754 | |
---|
4755 | // close connection |
---|
4756 | fclose($fp); |
---|
4757 | |
---|
4758 | $start = strpos($contents, "?>"); |
---|
4759 | if ($start != false) |
---|
4760 | { |
---|
4761 | $contents = substr($contents, $start + strlen("\r\n\r\n")); |
---|
4762 | } |
---|
4763 | |
---|
4764 | // Save the file if we're caching (0 = true in Thunks world) |
---|
4765 | if ( $UseCaching == 0 ) |
---|
4766 | { |
---|
4767 | $file = fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'w+'); |
---|
4768 | fwrite($file, $contents); |
---|
4769 | fclose($file); |
---|
4770 | @chmod(getcwd().'/cache/api/'.$configvalue.'.xml',0666); |
---|
4771 | } |
---|
4772 | } |
---|
4773 | } else { |
---|
4774 | // re-use cached XML |
---|
4775 | if ($fp = @fopen(getcwd().'/cache/api/'.$configvalue.'.xml', 'r')) { |
---|
4776 | $contents = fread($fp, filesize(getcwd().'/cache/api/'.$configvalue.'.xml')); |
---|
4777 | fclose($fp); |
---|
4778 | } else { |
---|
4779 | return "<i>error loading cached file ".$configvalue.".xml</i><br><br>"; |
---|
4780 | } |
---|
4781 | } |
---|
4782 | return $contents; |
---|
4783 | } |
---|
4784 | |
---|
4785 | // ********************************************************************************************************************************************** |
---|
4786 | // **************** Convert ID -> Name **************** |
---|
4787 | // ********************************************************************************************************************************************** |
---|
4788 | function gettypeIDname($id) |
---|
4789 | { |
---|
4790 | $sql = 'select inv.typeName from kb3_invtypes inv where inv.typeID = ' . $id; |
---|
4791 | |
---|
4792 | $qry = new DBQuery(); |
---|
4793 | $qry->execute($sql); |
---|
4794 | $row = $qry->getRow(); |
---|
4795 | |
---|
4796 | return $row['typeName']; |
---|
4797 | } |
---|
4798 | |
---|
4799 | // ********************************************************************************************************************************************** |
---|
4800 | // **************** Get GroupID from ID **************** |
---|
4801 | // ********************************************************************************************************************************************** |
---|
4802 | function getgroupID($id) |
---|
4803 | { |
---|
4804 | $sql = 'select inv.groupID from kb3_invtypes inv where inv.typeID = ' . $id; |
---|
4805 | |
---|
4806 | $qry = new DBQuery(); |
---|
4807 | $qry->execute($sql); |
---|
4808 | $row = $qry->getRow(); |
---|
4809 | |
---|
4810 | return $row['groupID']; |
---|
4811 | } |
---|
4812 | |
---|
4813 | // ********************************************************************************************************************************************** |
---|
4814 | // **************** Convert groupID -> groupName **************** |
---|
4815 | // ********************************************************************************************************************************************** |
---|
4816 | function getgroupIDname($id) |
---|
4817 | { |
---|
4818 | $sql = 'select itt.itt_name from kb3_item_types itt where itt.itt_id = ' . $id; |
---|
4819 | |
---|
4820 | $qry = new DBQuery(); |
---|
4821 | $qry->execute($sql); |
---|
4822 | $row = $qry->getRow(); |
---|
4823 | |
---|
4824 | return $row['itt_name']; |
---|
4825 | } |
---|
4826 | |
---|
4827 | // ********************************************************************************************************************************************** |
---|
4828 | // **************** Get Skill Rank from ID **************** |
---|
4829 | // ********************************************************************************************************************************************** |
---|
4830 | function gettypeIDrank($id) |
---|
4831 | { |
---|
4832 | $sql = 'select att.value from kb3_dgmtypeattributes att where att.typeID = ' . $id . ' and att.attributeID = 275'; |
---|
4833 | |
---|
4834 | $qry = new DBQuery(); |
---|
4835 | $qry->execute($sql); |
---|
4836 | $row = $qry->getRow(); |
---|
4837 | |
---|
4838 | return $row['value']; |
---|
4839 | } |
---|
4840 | |
---|
4841 | // ********************************************************************************************************************************************** |
---|
4842 | // **************** Convert MoonID -> MoonName **************** |
---|
4843 | // ********************************************************************************************************************************************** |
---|
4844 | function getMoonName($id) |
---|
4845 | { |
---|
4846 | if ($id != 0) |
---|
4847 | { |
---|
4848 | $sql = 'select moon.itemID, moon.itemName from kb3_moons moon where moon.itemID = '.$id; |
---|
4849 | |
---|
4850 | $qry = new DBQuery(); |
---|
4851 | $qry->execute($sql); |
---|
4852 | $row = $qry->getRow(); |
---|
4853 | |
---|
4854 | return $row['itemName']; |
---|
4855 | } else { |
---|
4856 | return "Unknown"; |
---|
4857 | } |
---|
4858 | } |
---|
4859 | |
---|
4860 | // ********************************************************************************************************************************************** |
---|
4861 | // **************** Find Thunky **************** |
---|
4862 | // ********************************************************************************************************************************************** |
---|
4863 | function FindThunk() |
---|
4864 | { // round about now would probably be a good time for apologising about my sense of humour :oD |
---|
4865 | $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "Captain Thunk"'; |
---|
4866 | |
---|
4867 | $qry = new DBQuery(); |
---|
4868 | $qry->execute($sql); |
---|
4869 | $row = $qry->getRow(); |
---|
4870 | |
---|
4871 | $pilot_id = $row['plt_id']; |
---|
4872 | $pilot_charid = $row['plt_externalid']; |
---|
4873 | |
---|
4874 | if ( $pilot_id != 0 ) { |
---|
4875 | return '<a href="?a=pilot_detail&plt_id=' . $pilot_id . '" ><font size="2">Captain Thunk</font></a>'; |
---|
4876 | } else { |
---|
4877 | return "Captain Thunk"; |
---|
4878 | } |
---|
4879 | } |
---|
4880 | |
---|
4881 | // ********************************************************************************************************************************************** |
---|
4882 | // **************** Update CCP CorpID **************** |
---|
4883 | // ********************************************************************************************************************************************** |
---|
4884 | function Update_CorpID($corpName, $corpID) |
---|
4885 | { |
---|
4886 | if ( (strlen($corpName) != 0) && ($corpID != 0) ) |
---|
4887 | { |
---|
4888 | $qry = new DBQuery(); |
---|
4889 | $qry->execute( "SELECT * FROM `kb3_corps` WHERE `crp_name` = '" . slashfix($corpName) . "'"); |
---|
4890 | |
---|
4891 | if ($qry->recordCount() != 0) |
---|
4892 | { |
---|
4893 | $row = $qry->getRow(); |
---|
4894 | if ($row['crp_external_id'] == NULL) |
---|
4895 | { |
---|
4896 | $qry->execute("update kb3_corps set crp_external_id = " . $corpID . " where `crp_id` = " . $row['crp_id']); |
---|
4897 | } |
---|
4898 | } |
---|
4899 | } |
---|
4900 | } |
---|
4901 | |
---|
4902 | // ********************************************************************************************************************************************** |
---|
4903 | // **************** Update CCP AllianceID **************** |
---|
4904 | // ********************************************************************************************************************************************** |
---|
4905 | function Update_AllianceID($allianceName, $allianceID) |
---|
4906 | { |
---|
4907 | if ( ($allianceName != "NONE") && ($allianceID != 0) ) |
---|
4908 | { |
---|
4909 | $qry = new DBQuery(); |
---|
4910 | $qry->execute( "SELECT * FROM `kb3_alliances` WHERE `all_name` = '" . slashfix($allianceName) . "'"); |
---|
4911 | |
---|
4912 | if ($qry->recordCount() != 0) |
---|
4913 | { |
---|
4914 | $row = $qry->getRow(); |
---|
4915 | if ($row['all_external_id'] == NULL) |
---|
4916 | { |
---|
4917 | $qry->execute("update kb3_alliances set all_external_id = " . $allianceID . " where `all_id` = " . $row['all_id']); |
---|
4918 | } |
---|
4919 | } |
---|
4920 | } |
---|
4921 | } |
---|
4922 | |
---|
4923 | // ********************************************************************************************************************************************** |
---|
4924 | // **************** Convert GMT Timestamp to local time **************** |
---|
4925 | // ********************************************************************************************************************************************** |
---|
4926 | function ConvertTimestamp($timeStampGMT) |
---|
4927 | { |
---|
4928 | if (!config::get('API_ConvertTimestamp')) |
---|
4929 | { |
---|
4930 | // set gmt offset |
---|
4931 | $gmoffset = (strtotime(date("M d Y H:i:s")) - strtotime(gmdate("M d Y H:i:s"))); |
---|
4932 | //if (!config::get('API_ForceDST')) |
---|
4933 | //$gmoffset = $gmoffset + 3600; |
---|
4934 | |
---|
4935 | $cachetime = date("Y-m-d H:i:s", strtotime($timeStampGMT) + $gmoffset); |
---|
4936 | } else { |
---|
4937 | $cachetime = $timeStampGMT; |
---|
4938 | } |
---|
4939 | |
---|
4940 | return $cachetime; |
---|
4941 | } |
---|
4942 | ?> |
---|