1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The MIT License (MIT) |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Robert Sardinia |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
15
|
|
|
* copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use Monolog\Handler\StreamHandler; |
27
|
|
|
use Monolog\Logger; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param $url |
31
|
|
|
* @return SimpleXMLElement|null |
32
|
|
|
*/ |
33
|
|
|
function makeApiRequest($url) |
34
|
|
|
{ |
35
|
|
|
$logger = new Logger('eveApi'); |
36
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
37
|
|
|
try { |
38
|
|
|
// Initialize a new request for this URL |
39
|
|
|
$ch = curl_init($url); |
40
|
|
|
// Set the options for this request |
41
|
|
|
curl_setopt_array($ch, array( |
42
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
43
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
44
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
45
|
|
|
CURLOPT_USERAGENT => 'Dramiel Discord Bot - https://github.com/shibdib/Dramiel', // Useragent |
46
|
|
|
CURLOPT_TIMEOUT => 15, |
47
|
|
|
)); |
48
|
|
|
// Fetch the data from the URL |
49
|
|
|
$data = curl_exec($ch); |
50
|
|
|
// Close the connection |
51
|
|
|
curl_close($ch); |
52
|
|
|
// Return a new SimpleXMLElement based upon the received data |
53
|
|
|
return new SimpleXMLElement($data); |
54
|
|
|
} catch (Exception $e) { |
55
|
|
|
$logger->error('EVE API Error: ' . $e->getMessage()); |
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return mixed|null |
62
|
|
|
*/ |
63
|
|
|
|
64
|
|
|
function serverStatus() |
65
|
|
|
{ |
66
|
|
|
$logger = new Logger('eveApi'); |
67
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
68
|
|
|
try { |
69
|
|
|
// Initialize a new request for this URL |
70
|
|
|
$ch = curl_init('https://api.eveonline.com/server/ServerStatus.xml.aspx'); |
71
|
|
|
// Set the options for this request |
72
|
|
|
curl_setopt_array($ch, array( |
73
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
74
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
75
|
|
|
CURLOPT_TIMEOUT => 8, |
76
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
77
|
|
|
)); |
78
|
|
|
// Fetch the data from the URL |
79
|
|
|
$data = curl_exec($ch); |
80
|
|
|
// Close the connection |
81
|
|
|
curl_close($ch); |
82
|
|
|
|
83
|
|
|
$true = 'true'; |
84
|
|
|
//If server is down return false |
85
|
|
|
if ($data->serverOpen !== 'True') { |
86
|
|
|
return FALSE; |
87
|
|
|
} |
88
|
|
|
//If server is up return true |
89
|
|
|
return $true; |
90
|
|
|
} catch (Exception $e) { |
91
|
|
|
$logger->error('EVE API Error: ' . $e->getMessage()); |
92
|
|
|
return null; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $characterID |
98
|
|
|
* @return mixed |
99
|
|
|
*/ |
100
|
|
|
////Char ID to name via CCP |
101
|
|
View Code Duplication |
function characterName($characterID) |
102
|
|
|
{ |
103
|
|
|
$character = characterDetails($characterID); |
104
|
|
|
$name = (string) $character['name']; |
105
|
|
|
if (null === $name || '' === $name) { // Make sure it's always set. |
106
|
|
|
$url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?ids={$characterID}"; |
107
|
|
|
$xml = makeApiRequest($url); |
108
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
109
|
|
|
$name = $entity->attributes()->name; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
return $name; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $characterName |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
////Character name to ID |
120
|
|
|
/** |
121
|
|
|
* @param string $characterName |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
View Code Duplication |
function characterID($characterName) |
126
|
|
|
{ |
127
|
|
|
$logger = new Logger('eveESI'); |
128
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
129
|
|
|
$characterName = rawurlencode(urldecode($characterName)); |
130
|
|
|
|
131
|
|
|
try { |
132
|
|
|
// Initialize a new request for this URL |
133
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$characterName}&categories=character&language=en-us&strict=true&datasource=tranquility"); |
134
|
|
|
// Set the options for this request |
135
|
|
|
curl_setopt_array($ch, array( |
136
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
137
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
138
|
|
|
CURLOPT_TIMEOUT => 8, |
139
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
140
|
|
|
)); |
141
|
|
|
// Fetch the data from the URL |
142
|
|
|
$data = curl_exec($ch); |
143
|
|
|
// Close the connection |
144
|
|
|
curl_close($ch); |
145
|
|
|
$data = json_decode($data, TRUE); |
146
|
|
|
$id = (int) $data['character'][0]; |
147
|
|
|
|
148
|
|
|
} catch (Exception $e) { |
149
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
150
|
|
|
$url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$characterName}"; |
151
|
|
|
$xml = makeApiRequest($url); |
152
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
153
|
|
|
$id = $entity->attributes()->characterID; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
return $id; |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $characterID |
162
|
|
|
* @return mixed |
163
|
|
|
*/ |
164
|
|
|
////Char ID to char data via CCP |
165
|
|
View Code Duplication |
function characterDetails($characterID) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$logger = new Logger('eveESI'); |
168
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
169
|
|
|
|
170
|
|
|
try { |
171
|
|
|
// Initialize a new request for this URL |
172
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/characters/{$characterID}/"); |
173
|
|
|
// Set the options for this request |
174
|
|
|
curl_setopt_array($ch, array( |
175
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
176
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
177
|
|
|
CURLOPT_TIMEOUT => 8, |
178
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
179
|
|
|
)); |
180
|
|
|
// Fetch the data from the URL |
181
|
|
|
$data = curl_exec($ch); |
182
|
|
|
// Close the connection |
183
|
|
|
curl_close($ch); |
184
|
|
|
$data = json_decode($data, TRUE); |
185
|
|
|
|
186
|
|
|
} catch (Exception $e) { |
187
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
188
|
|
|
return null; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return $data; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param string $systemID |
196
|
|
|
* @return mixed |
197
|
|
|
*/ |
198
|
|
|
////System ID to name via CCP |
199
|
|
View Code Duplication |
function systemName($systemID) |
|
|
|
|
200
|
|
|
{ |
201
|
|
|
$logger = new Logger('eveESI'); |
202
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
203
|
|
|
|
204
|
|
|
try { |
205
|
|
|
// Initialize a new request for this URL |
206
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/universe/systems/{$systemID}/"); |
207
|
|
|
// Set the options for this request |
208
|
|
|
curl_setopt_array($ch, array( |
209
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
210
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
211
|
|
|
CURLOPT_TIMEOUT => 8, |
212
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
213
|
|
|
)); |
214
|
|
|
// Fetch the data from the URL |
215
|
|
|
$data = curl_exec($ch); |
216
|
|
|
// Close the connection |
217
|
|
|
curl_close($ch); |
218
|
|
|
$data = json_decode($data, TRUE); |
219
|
|
|
$name = (string) $data['name']; |
220
|
|
|
|
221
|
|
|
} catch (Exception $e) { |
222
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
223
|
|
|
$url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?ids={$systemID}"; |
224
|
|
|
$xml = makeApiRequest($url); |
225
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
226
|
|
|
$name = $entity->attributes()->name; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
return $name; |
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param string $systemID |
235
|
|
|
* @return mixed |
236
|
|
|
* Return system information |
237
|
|
|
*/ |
238
|
|
|
function systemDetails($systemID) |
239
|
|
|
{ |
240
|
|
|
$logger = new Logger('eveESI'); |
241
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
242
|
|
|
|
243
|
|
|
try { |
244
|
|
|
// Initialize a new request for this URL |
245
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/universe/systems/{$systemID}/"); |
246
|
|
|
// Set the options for this request |
247
|
|
|
curl_setopt_array($ch, array( |
248
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
249
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
250
|
|
|
CURLOPT_TIMEOUT => 8, |
251
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
252
|
|
|
)); |
253
|
|
|
// Fetch the data from the URL |
254
|
|
|
$data = curl_exec($ch); |
255
|
|
|
// Close the connection |
256
|
|
|
curl_close($ch); |
257
|
|
|
$data = json_decode($data, TRUE); |
258
|
|
|
|
259
|
|
|
} catch (Exception $e) { |
260
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
261
|
|
|
return null; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
return $data; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param string $regionID |
269
|
|
|
* @return mixed |
270
|
|
|
* Return region information |
271
|
|
|
*/ |
272
|
|
|
function regionDetails($regionID) |
273
|
|
|
{ |
274
|
|
|
$logger = new Logger('eveESI'); |
275
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
276
|
|
|
|
277
|
|
|
try { |
278
|
|
|
// Initialize a new request for this URL |
279
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/universe/regions/{$regionID}/"); |
280
|
|
|
// Set the options for this request |
281
|
|
|
curl_setopt_array($ch, array( |
282
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
283
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
284
|
|
|
CURLOPT_TIMEOUT => 8, |
285
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
286
|
|
|
)); |
287
|
|
|
// Fetch the data from the URL |
288
|
|
|
$data = curl_exec($ch); |
289
|
|
|
// Close the connection |
290
|
|
|
curl_close($ch); |
291
|
|
|
$data = json_decode($data, TRUE); |
292
|
|
|
|
293
|
|
|
} catch (Exception $e) { |
294
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
295
|
|
|
return null; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
return $data; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @param string $corpName |
303
|
|
|
* @return mixed |
304
|
|
|
*/ |
305
|
|
|
////Corp name to ID |
306
|
|
|
/** |
307
|
|
|
* @param string $corpName |
308
|
|
|
*/ |
309
|
|
View Code Duplication |
function corpID($corpName) |
|
|
|
|
310
|
|
|
{ |
311
|
|
|
$logger = new Logger('eveESI'); |
312
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
313
|
|
|
$corpName = urlencode($corpName); |
314
|
|
|
|
315
|
|
|
try { |
316
|
|
|
// Initialize a new request for this URL |
317
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/search/?categories=corporation&datasource=tranquility&language=en-us&search={$corpName}&strict=true"); |
318
|
|
|
// Set the options for this request |
319
|
|
|
curl_setopt_array($ch, array( |
320
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
321
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
322
|
|
|
CURLOPT_TIMEOUT => 8, |
323
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
324
|
|
|
)); |
325
|
|
|
// Fetch the data from the URL |
326
|
|
|
$data = curl_exec($ch); |
327
|
|
|
// Close the connection |
328
|
|
|
curl_close($ch); |
329
|
|
|
$data = json_decode($data, TRUE); |
330
|
|
|
$id = (int) $data['corporation'][0]; |
331
|
|
|
|
332
|
|
|
} catch (Exception $e) { |
333
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
334
|
|
|
$url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$corpName}"; |
335
|
|
|
$xml = makeApiRequest($url); |
336
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
337
|
|
|
$id = $entity->attributes()->characterID; |
338
|
|
|
} |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
return $id; |
|
|
|
|
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param string $corpID |
347
|
|
|
* @return mixed |
348
|
|
|
*/ |
349
|
|
|
////Corp ID to name via CCP |
350
|
|
View Code Duplication |
function corpName($corpID) |
|
|
|
|
351
|
|
|
{ |
352
|
|
|
$corporation = corpDetails($corpID); |
353
|
|
|
$name = (string) $corporation['corporation_name']; |
354
|
|
|
if (null === $name || '' === $name) { // Make sure it's always set. |
355
|
|
|
$url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?ids={$corpID}"; |
356
|
|
|
$xml = makeApiRequest($url); |
357
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
358
|
|
|
$name = $entity->attributes()->name; |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
return $name; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* @param string $corpID |
367
|
|
|
* @return mixed |
368
|
|
|
*/ |
369
|
|
|
////Corp ID to corp data via CCP |
370
|
|
View Code Duplication |
function corpDetails($corpID) |
|
|
|
|
371
|
|
|
{ |
372
|
|
|
$logger = new Logger('eveESI'); |
373
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
374
|
|
|
|
375
|
|
|
try { |
376
|
|
|
// Initialize a new request for this URL |
377
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/corporations/{$corpID}/"); |
378
|
|
|
// Set the options for this request |
379
|
|
|
curl_setopt_array($ch, array( |
380
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
381
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
382
|
|
|
CURLOPT_TIMEOUT => 8, |
383
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
384
|
|
|
)); |
385
|
|
|
// Fetch the data from the URL |
386
|
|
|
$data = curl_exec($ch); |
387
|
|
|
// Close the connection |
388
|
|
|
curl_close($ch); |
389
|
|
|
$data = json_decode($data, TRUE); |
390
|
|
|
|
391
|
|
|
} catch (Exception $e) { |
392
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
393
|
|
|
return null; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
return $data; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @param string $allianceID |
401
|
|
|
* @return mixed |
402
|
|
|
*/ |
403
|
|
|
////Alliance ID to name via CCP |
404
|
|
View Code Duplication |
function allianceName($allianceID) |
|
|
|
|
405
|
|
|
{ |
406
|
|
|
$logger = new Logger('eveESI'); |
407
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
408
|
|
|
|
409
|
|
|
try { |
410
|
|
|
// Initialize a new request for this URL |
411
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/alliances/{$allianceID}/"); |
412
|
|
|
// Set the options for this request |
413
|
|
|
curl_setopt_array($ch, array( |
414
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
415
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
416
|
|
|
CURLOPT_TIMEOUT => 8, |
417
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
418
|
|
|
)); |
419
|
|
|
// Fetch the data from the URL |
420
|
|
|
$data = curl_exec($ch); |
421
|
|
|
// Close the connection |
422
|
|
|
curl_close($ch); |
423
|
|
|
$data = json_decode($data, TRUE); |
424
|
|
|
$name = (string) $data['alliance_name']; |
425
|
|
|
|
426
|
|
|
} catch (Exception $e) { |
427
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
428
|
|
|
$url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?ids={$allianceID}"; |
429
|
|
|
$xml = makeApiRequest($url); |
430
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
431
|
|
|
$name = $entity->attributes()->name; |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
return $name; |
|
|
|
|
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* @param string $systemName |
440
|
|
|
* @return mixed |
441
|
|
|
*/ |
442
|
|
|
////System name to ID |
443
|
|
View Code Duplication |
function systemID($systemName) |
|
|
|
|
444
|
|
|
{ |
445
|
|
|
$logger = new Logger('eveESI'); |
446
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
447
|
|
|
$systemName = urlencode($systemName); |
448
|
|
|
|
449
|
|
|
try { |
450
|
|
|
// Initialize a new request for this URL |
451
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$systemName}&categories=solarsystem&language=en-us&strict=true&datasource=tranquility"); |
452
|
|
|
// Set the options for this request |
453
|
|
|
curl_setopt_array($ch, array( |
454
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
455
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
456
|
|
|
CURLOPT_TIMEOUT => 8, |
457
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
458
|
|
|
)); |
459
|
|
|
// Fetch the data from the URL |
460
|
|
|
$data = curl_exec($ch); |
461
|
|
|
// Close the connection |
462
|
|
|
curl_close($ch); |
463
|
|
|
$data = json_decode($data, TRUE); |
464
|
|
|
$id = (int) $data['solarsystem'][0]; |
465
|
|
|
|
466
|
|
|
} catch (Exception $e) { |
467
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
468
|
|
|
$url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$systemName}"; |
469
|
|
|
$xml = makeApiRequest($url); |
470
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
471
|
|
|
$id = $entity->attributes()->characterID; |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
return $id; |
|
|
|
|
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @param string $typeID |
480
|
|
|
* @return mixed |
481
|
|
|
*/ |
482
|
|
|
////TypeID to TypeName via CCP |
483
|
|
View Code Duplication |
function apiTypeName($typeID) |
484
|
|
|
{ |
485
|
|
|
$logger = new Logger('eveESI'); |
486
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
487
|
|
|
|
488
|
|
|
try { |
489
|
|
|
// Initialize a new request for this URL |
490
|
|
|
$ch = curl_init("https://esi.tech.ccp.is/latest/universe/types/{$typeID}/"); |
491
|
|
|
// Set the options for this request |
492
|
|
|
curl_setopt_array($ch, array( |
493
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
494
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
495
|
|
|
CURLOPT_TIMEOUT => 8, |
496
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
497
|
|
|
)); |
498
|
|
|
// Fetch the data from the URL |
499
|
|
|
$data = curl_exec($ch); |
500
|
|
|
// Close the connection |
501
|
|
|
curl_close($ch); |
502
|
|
|
$data = json_decode($data, TRUE); |
503
|
|
|
$name = (string) $data['name']; |
504
|
|
|
|
505
|
|
|
} catch (Exception $e) { |
506
|
|
|
$logger->error('EVE ESI Error: ' . $e->getMessage()); |
507
|
|
|
$url = "https://api.eveonline.com/eve/TypeName.xml.aspx?ids={$typeID}"; |
508
|
|
|
$xml = makeApiRequest($url); |
509
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
510
|
|
|
$name = $entity->attributes()->typeName; |
511
|
|
|
} |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
return $name; |
|
|
|
|
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
/** |
518
|
|
|
* @param string $typeName |
519
|
|
|
* @return mixed |
520
|
|
|
*/ |
521
|
|
|
////TypeName to TypeID via fuzz |
522
|
|
|
function apiTypeID($typeName) |
523
|
|
|
{ |
524
|
|
|
$logger = new Logger('eveESI'); |
525
|
|
|
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG)); |
526
|
|
|
$typeName = urlencode($typeName); |
527
|
|
|
try { |
528
|
|
|
// Initialize a new request for this URL |
529
|
|
|
$ch = curl_init("https://www.fuzzwork.co.uk/api/typeid.php?typename={$typeName}"); |
530
|
|
|
// Set the options for this request |
531
|
|
|
curl_setopt_array($ch, array( |
532
|
|
|
CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect |
533
|
|
|
CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data |
534
|
|
|
CURLOPT_TIMEOUT => 8, |
535
|
|
|
CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate |
536
|
|
|
)); |
537
|
|
|
// Fetch the data from the URL |
538
|
|
|
$data = curl_exec($ch); |
539
|
|
|
// Close the connection |
540
|
|
|
curl_close($ch); |
541
|
|
|
$data = json_decode($data, TRUE); |
542
|
|
|
|
543
|
|
|
} catch (Exception $e) { |
544
|
|
|
$logger->error('Fuzzwork Error: ' . $e->getMessage()); |
545
|
|
|
return null; |
546
|
|
|
} |
547
|
|
|
$id = (int) $data['typeID']; |
548
|
|
|
|
549
|
|
|
if (null === $id) { // Make sure it's always set. |
550
|
|
|
$id = 'Unknown'; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
return $id; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
////Char/Object ID to name via CCP |
557
|
|
|
/** |
558
|
|
|
* @param string $moonID |
559
|
|
|
*/ |
560
|
|
|
function apiMoonName($moonID) |
561
|
|
|
{ |
562
|
|
|
$url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?IDs={$moonID}"; |
563
|
|
|
$xml = makeApiRequest($url); |
564
|
|
|
$name = null; |
565
|
|
|
foreach ($xml->result->rowset->row as $entity) { |
566
|
|
|
$name = $entity->attributes()->name; |
567
|
|
|
} |
568
|
|
|
if (null === $name) { // Make sure it's always set. |
569
|
|
|
$name = 'Unknown'; |
570
|
|
|
} |
571
|
|
|
return $name; |
572
|
|
|
} |
573
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: