@@ -12,7 +12,9 @@ discard block |
||
| 12 | 12 | public function __construct($dbc = null) { |
| 13 | 13 | $Connection = new Connection($dbc); |
| 14 | 14 | $this->db = $Connection->db(); |
| 15 | - if ($this->db === null) die('Error: No DB connection.'); |
|
| 15 | + if ($this->db === null) { |
|
| 16 | + die('Error: No DB connection.'); |
|
| 17 | + } |
|
| 16 | 18 | } |
| 17 | 19 | |
| 18 | 20 | /** |
@@ -124,7 +126,9 @@ discard block |
||
| 124 | 126 | $sth->closeCursor(); |
| 125 | 127 | if (count($row) > 0) { |
| 126 | 128 | return $row; |
| 127 | - } else return array(); |
|
| 129 | + } else { |
|
| 130 | + return array(); |
|
| 131 | + } |
|
| 128 | 132 | } |
| 129 | 133 | |
| 130 | 134 | public function checkSchedule($ident) { |
@@ -160,7 +164,9 @@ discard block |
||
| 160 | 164 | $Common = new Common(); |
| 161 | 165 | $check_date = new Datetime($date); |
| 162 | 166 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 163 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 167 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 168 | + return array(); |
|
| 169 | + } |
|
| 164 | 170 | $url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym'); |
| 165 | 171 | $json = $Common->getData($url); |
| 166 | 172 | |
@@ -187,7 +193,9 @@ discard block |
||
| 187 | 193 | */ |
| 188 | 194 | |
| 189 | 195 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance'); |
| 190 | - } else return array(); |
|
| 196 | + } else { |
|
| 197 | + return array(); |
|
| 198 | + } |
|
| 191 | 199 | } |
| 192 | 200 | |
| 193 | 201 | /** |
@@ -202,7 +210,9 @@ discard block |
||
| 202 | 210 | date_default_timezone_set($globalTimezone); |
| 203 | 211 | $check_date = new Datetime($date); |
| 204 | 212 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 205 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 213 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 214 | + return array(); |
|
| 215 | + } |
|
| 206 | 216 | $url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign; |
| 207 | 217 | $json = $Common->getData($url); |
| 208 | 218 | $parsed_json = json_decode($json); |
@@ -215,7 +225,9 @@ discard block |
||
| 215 | 225 | $arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'}; |
| 216 | 226 | |
| 217 | 227 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet'); |
| 218 | - } else return array(); |
|
| 228 | + } else { |
|
| 229 | + return array(); |
|
| 230 | + } |
|
| 219 | 231 | } |
| 220 | 232 | |
| 221 | 233 | /** |
@@ -226,7 +238,9 @@ discard block |
||
| 226 | 238 | private function getRyanair($callsign) { |
| 227 | 239 | $Common = new Common(); |
| 228 | 240 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 229 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 241 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 242 | + return array(); |
|
| 243 | + } |
|
| 230 | 244 | $url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/"; |
| 231 | 245 | $post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}'; |
| 232 | 246 | $headers = array('Content-Type: application/json','Content-Length: ' . strlen($post)); |
@@ -240,8 +254,12 @@ discard block |
||
| 240 | 254 | $departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'}; |
| 241 | 255 | $arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'}; |
| 242 | 256 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair'); |
| 243 | - } else return array(); |
|
| 244 | - } else return array(); |
|
| 257 | + } else { |
|
| 258 | + return array(); |
|
| 259 | + } |
|
| 260 | + } else { |
|
| 261 | + return array(); |
|
| 262 | + } |
|
| 245 | 263 | } |
| 246 | 264 | |
| 247 | 265 | /** |
@@ -252,7 +270,9 @@ discard block |
||
| 252 | 270 | private function getSwiss($callsign) { |
| 253 | 271 | $Common = new Common(); |
| 254 | 272 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 255 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 273 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 274 | + return array(); |
|
| 275 | + } |
|
| 256 | 276 | $url = "http://www.world-of-swiss.com/fr/routenetwork.json"; |
| 257 | 277 | $json = $Common->getData($url); |
| 258 | 278 | $parsed_json = json_decode($json); |
@@ -272,8 +292,12 @@ discard block |
||
| 272 | 292 | } |
| 273 | 293 | if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) { |
| 274 | 294 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss'); |
| 275 | - } else return array(); |
|
| 276 | - } else return array(); |
|
| 295 | + } else { |
|
| 296 | + return array(); |
|
| 297 | + } |
|
| 298 | + } else { |
|
| 299 | + return array(); |
|
| 300 | + } |
|
| 277 | 301 | } |
| 278 | 302 | |
| 279 | 303 | /** |
@@ -287,12 +311,18 @@ discard block |
||
| 287 | 311 | $Common = new Common(); |
| 288 | 312 | $check_date = new Datetime($date); |
| 289 | 313 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
| 290 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 291 | - if ($globalBritishAirwaysKey == '') return array(); |
|
| 314 | + if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) { |
|
| 315 | + return array(); |
|
| 316 | + } |
|
| 317 | + if ($globalBritishAirwaysKey == '') { |
|
| 318 | + return array(); |
|
| 319 | + } |
|
| 292 | 320 | $url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json"; |
| 293 | 321 | $headers = array('Client-Key: '.$globalBritishAirwaysKey); |
| 294 | 322 | $json = $Common->getData($url,'get','',$headers); |
| 295 | - if ($json == '') return array(); |
|
| 323 | + if ($json == '') { |
|
| 324 | + return array(); |
|
| 325 | + } |
|
| 296 | 326 | $parsed_json = json_decode($json); |
| 297 | 327 | $flights = $parsed_json->{'FlightsResponse'}; |
| 298 | 328 | if (count($flights) > 0) { |
@@ -301,7 +331,9 @@ discard block |
||
| 301 | 331 | $departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'})); |
| 302 | 332 | $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'})); |
| 303 | 333 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways'); |
| 304 | - } else return array(); |
|
| 334 | + } else { |
|
| 335 | + return array(); |
|
| 336 | + } |
|
| 305 | 337 | } |
| 306 | 338 | |
| 307 | 339 | /** |
@@ -315,19 +347,27 @@ discard block |
||
| 315 | 347 | $Common = new Common(); |
| 316 | 348 | $check_date = new Datetime($date); |
| 317 | 349 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
| 318 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 319 | - if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array(); |
|
| 350 | + if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) { |
|
| 351 | + return array(); |
|
| 352 | + } |
|
| 353 | + if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') { |
|
| 354 | + return array(); |
|
| 355 | + } |
|
| 320 | 356 | $url = "https://api.lufthansa.com/v1/oauth/token"; |
| 321 | 357 | $post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials'); |
| 322 | 358 | $data = $Common->getData($url,'post',$post); |
| 323 | 359 | $parsed_data = json_decode($data); |
| 324 | - if (!isset($parsed_data->{'access_token'})) return array(); |
|
| 360 | + if (!isset($parsed_data->{'access_token'})) { |
|
| 361 | + return array(); |
|
| 362 | + } |
|
| 325 | 363 | $token = $parsed_data->{'access_token'}; |
| 326 | 364 | |
| 327 | 365 | $url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d'); |
| 328 | 366 | $headers = array('Authorization: Bearer '.$token,'Accept: application/json'); |
| 329 | 367 | $json = $Common->getData($url,'get','',$headers); |
| 330 | - if ($json == '') return array(); |
|
| 368 | + if ($json == '') { |
|
| 369 | + return array(); |
|
| 370 | + } |
|
| 331 | 371 | $parsed_json = json_decode($json); |
| 332 | 372 | if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) { |
| 333 | 373 | $DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'}; |
@@ -335,7 +375,9 @@ discard block |
||
| 335 | 375 | $ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'}; |
| 336 | 376 | $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
| 337 | 377 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
| 338 | - } else return array(); |
|
| 378 | + } else { |
|
| 379 | + return array(); |
|
| 380 | + } |
|
| 339 | 381 | } |
| 340 | 382 | |
| 341 | 383 | /** |
@@ -349,14 +391,20 @@ discard block |
||
| 349 | 391 | $Common = new Common(); |
| 350 | 392 | $check_date = new Datetime($date); |
| 351 | 393 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
| 352 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 353 | - if ($globalTransaviaKey == '') return array(); |
|
| 394 | + if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) { |
|
| 395 | + return array(); |
|
| 396 | + } |
|
| 397 | + if ($globalTransaviaKey == '') { |
|
| 398 | + return array(); |
|
| 399 | + } |
|
| 354 | 400 | $url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
| 355 | 401 | //$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
| 356 | 402 | $headers = array('apikey: '.$globalTransaviaKey); |
| 357 | 403 | $json = $Common->getData($url,'get','',$headers); |
| 358 | 404 | //echo 'result : '.$json; |
| 359 | - if ($json == '') return array(); |
|
| 405 | + if ($json == '') { |
|
| 406 | + return array(); |
|
| 407 | + } |
|
| 360 | 408 | $parsed_json = json_decode($json); |
| 361 | 409 | |
| 362 | 410 | if (isset($parsed_json->{'data'}[0])) { |
@@ -365,7 +413,9 @@ discard block |
||
| 365 | 413 | $ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'}; |
| 366 | 414 | $arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'})); |
| 367 | 415 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia'); |
| 368 | - } else return array(); |
|
| 416 | + } else { |
|
| 417 | + return array(); |
|
| 418 | + } |
|
| 369 | 419 | } |
| 370 | 420 | |
| 371 | 421 | /** |
@@ -376,7 +426,9 @@ discard block |
||
| 376 | 426 | public function getTunisair($callsign) { |
| 377 | 427 | $Common = new Common(); |
| 378 | 428 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 379 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 429 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 430 | + return array(); |
|
| 431 | + } |
|
| 380 | 432 | $url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp"; |
| 381 | 433 | $data = $Common->getData($url); |
| 382 | 434 | $table = $Common->table2array($data); |
@@ -397,7 +449,9 @@ discard block |
||
| 397 | 449 | $Common = new Common(); |
| 398 | 450 | $check_date = new Datetime($date); |
| 399 | 451 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 400 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 452 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 453 | + return array(); |
|
| 454 | + } |
|
| 401 | 455 | $final_date = str_replace('/','%2F',$check_date->format('d/m/Y')); |
| 402 | 456 | $url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB"; |
| 403 | 457 | $data = $Common->getData($url); |
@@ -407,8 +461,11 @@ discard block |
||
| 407 | 461 | $DepartureAirportIata = str_replace('flightOri=','',$result[0]); |
| 408 | 462 | preg_match('/flightDest=[A-Z]{3}/',$data,$result); |
| 409 | 463 | $ArrivalAirportIata = str_replace('flightDest=','',$result[0]); |
| 410 | - if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling'); |
|
| 411 | - else return array(); |
|
| 464 | + if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') { |
|
| 465 | + return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling'); |
|
| 466 | + } else { |
|
| 467 | + return array(); |
|
| 468 | + } |
|
| 412 | 469 | } |
| 413 | 470 | return array(); |
| 414 | 471 | } |
@@ -423,7 +480,9 @@ discard block |
||
| 423 | 480 | $Common = new Common(); |
| 424 | 481 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 425 | 482 | $check_date = new Datetime($date); |
| 426 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 483 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 484 | + return array(); |
|
| 485 | + } |
|
| 427 | 486 | $url = "https://www.iberia.com/web/flightDetail.do"; |
| 428 | 487 | $post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB'); |
| 429 | 488 | $data = $Common->getData($url,'post',$post); |
@@ -440,7 +499,9 @@ discard block |
||
| 440 | 499 | $arrivalTime = trim(str_replace(' lunes','',str_replace(' ','',$flight[5][1]))); |
| 441 | 500 | if ($arrivalTime == 'Hora estimada de llegada') { |
| 442 | 501 | $arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[5][2]))),0,5); |
| 443 | - } else $arrivalTime = substr($arrivalTime,0,5); |
|
| 502 | + } else { |
|
| 503 | + $arrivalTime = substr($arrivalTime,0,5); |
|
| 504 | + } |
|
| 444 | 505 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia'); |
| 445 | 506 | } |
| 446 | 507 | } |
@@ -458,7 +519,9 @@ discard block |
||
| 458 | 519 | $Common = new Common(); |
| 459 | 520 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 460 | 521 | $check_date = new Datetime($date); |
| 461 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 522 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 523 | + return array(); |
|
| 524 | + } |
|
| 462 | 525 | $url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y'); |
| 463 | 526 | $data = $Common->getData($url); |
| 464 | 527 | if ($data != '') { |
@@ -474,7 +537,9 @@ discard block |
||
| 474 | 537 | $departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5); |
| 475 | 538 | $arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5); |
| 476 | 539 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance'); |
| 477 | - } else return array(); |
|
| 540 | + } else { |
|
| 541 | + return array(); |
|
| 542 | + } |
|
| 478 | 543 | } |
| 479 | 544 | |
| 480 | 545 | |
@@ -494,7 +559,9 @@ discard block |
||
| 494 | 559 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 495 | 560 | $check_date = new Datetime($date); |
| 496 | 561 | $url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y'); |
| 497 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 562 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 563 | + return array(); |
|
| 564 | + } |
|
| 498 | 565 | $data = $Common->getData($url); |
| 499 | 566 | if ($data != '') { |
| 500 | 567 | $table = $Common->text2array($data); |
@@ -518,7 +585,9 @@ discard block |
||
| 518 | 585 | $check_date = new Datetime($date); |
| 519 | 586 | $url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302"; |
| 520 | 587 | //http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber"; |
| 521 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 588 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 589 | + return array(); |
|
| 590 | + } |
|
| 522 | 591 | $data = $Common->getData($url); |
| 523 | 592 | if ($data != '') { |
| 524 | 593 | //echo $data; |
@@ -608,7 +677,9 @@ discard block |
||
| 608 | 677 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 609 | 678 | $url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees"; |
| 610 | 679 | //$check_date = new Datetime($date); |
| 611 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 680 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 681 | + return array(); |
|
| 682 | + } |
|
| 612 | 683 | $post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1'); |
| 613 | 684 | $data = $Common->getData($url,'post',$post); |
| 614 | 685 | if ($data != '') { |
@@ -640,11 +711,15 @@ discard block |
||
| 640 | 711 | $airline_icao = substr($callsign, 0, 3); |
| 641 | 712 | } |
| 642 | 713 | } |
| 643 | - if ($airline_icao == '') return array(); |
|
| 714 | + if ($airline_icao == '') { |
|
| 715 | + return array(); |
|
| 716 | + } |
|
| 644 | 717 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 645 | 718 | $url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol; |
| 646 | 719 | //$check_date = new Datetime($date); |
| 647 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 720 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 721 | + return array(); |
|
| 722 | + } |
|
| 648 | 723 | $data = $Common->getData($url); |
| 649 | 724 | if ($data != '') { |
| 650 | 725 | $table = $Common->table2array($data); |
@@ -687,7 +762,9 @@ discard block |
||
| 687 | 762 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 688 | 763 | $url= "http://fr.flightaware.com/live/flight/".$callsign; |
| 689 | 764 | //$check_date = new Datetime($date); |
| 690 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 765 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 766 | + return array(); |
|
| 767 | + } |
|
| 691 | 768 | $data = $Common->getData($url); |
| 692 | 769 | if ($data != '') { |
| 693 | 770 | $table = $Common->table2array($data); |
@@ -736,16 +813,22 @@ discard block |
||
| 736 | 813 | */ |
| 737 | 814 | private function getAirCanada($callsign,$date = 'NOW') { |
| 738 | 815 | $Common = new Common(); |
| 739 | - if (class_exists("DomDocument") === FALSE) return array(); |
|
| 816 | + if (class_exists("DomDocument") === FALSE) { |
|
| 817 | + return array(); |
|
| 818 | + } |
|
| 740 | 819 | date_default_timezone_set('UTC'); |
| 741 | 820 | $check_date = new Datetime($date); |
| 742 | 821 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 743 | 822 | $url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249"; |
| 744 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 823 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 824 | + return array(); |
|
| 825 | + } |
|
| 745 | 826 | $data = $Common->getData($url); |
| 746 | 827 | $dom = new DomDocument(); |
| 747 | 828 | $dom->loadXML($data); |
| 748 | - if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array(); |
|
| 829 | + if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) { |
|
| 830 | + return array(); |
|
| 831 | + } |
|
| 749 | 832 | $departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0); |
| 750 | 833 | if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) { |
| 751 | 834 | $DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
@@ -754,7 +837,9 @@ discard block |
||
| 754 | 837 | $ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
| 755 | 838 | $arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
| 756 | 839 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada'); |
| 757 | - } else return array(); |
|
| 840 | + } else { |
|
| 841 | + return array(); |
|
| 842 | + } |
|
| 758 | 843 | } |
| 759 | 844 | |
| 760 | 845 | /** |
@@ -768,7 +853,9 @@ discard block |
||
| 768 | 853 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 769 | 854 | $check_date = new Datetime($date); |
| 770 | 855 | $url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&"; |
| 771 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 856 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 857 | + return array(); |
|
| 858 | + } |
|
| 772 | 859 | $data = $Common->getData($url); |
| 773 | 860 | if ($data != '') { |
| 774 | 861 | $table = $Common->table2array($data); |
@@ -797,7 +884,9 @@ discard block |
||
| 797 | 884 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 798 | 885 | $check_date = new Datetime($date); |
| 799 | 886 | $url= "http://www.airberlin.com/en-US/site/aims.php"; |
| 800 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 887 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 888 | + return array(); |
|
| 889 | + } |
|
| 801 | 890 | $post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier); |
| 802 | 891 | $data = $Common->getData($url,'post',$post); |
| 803 | 892 | //echo $data; |
@@ -807,11 +896,19 @@ discard block |
||
| 807 | 896 | if ($data != '') { |
| 808 | 897 | $table = $Common->table2array($data); |
| 809 | 898 | $flight = $table; |
| 810 | - if (isset($flight[5][4])) $departureTime = $flight[5][4]; |
|
| 811 | - else $departureTime = ''; |
|
| 812 | - if (isset($flight[5][2])) $departureAirport = $flight[5][2]; |
|
| 813 | - else $departureAirport = ''; |
|
| 814 | - } else return array(); |
|
| 899 | + if (isset($flight[5][4])) { |
|
| 900 | + $departureTime = $flight[5][4]; |
|
| 901 | + } else { |
|
| 902 | + $departureTime = ''; |
|
| 903 | + } |
|
| 904 | + if (isset($flight[5][2])) { |
|
| 905 | + $departureAirport = $flight[5][2]; |
|
| 906 | + } else { |
|
| 907 | + $departureAirport = ''; |
|
| 908 | + } |
|
| 909 | + } else { |
|
| 910 | + return array(); |
|
| 911 | + } |
|
| 815 | 912 | $post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB'); |
| 816 | 913 | $data = $Common->getData($url,'post',$post); |
| 817 | 914 | if ($data != '') { |
@@ -824,10 +921,14 @@ discard block |
||
| 824 | 921 | $arrivalTime = ''; |
| 825 | 922 | $arrivalAirport = ''; |
| 826 | 923 | } |
| 827 | - } else return array(); |
|
| 924 | + } else { |
|
| 925 | + return array(); |
|
| 926 | + } |
|
| 828 | 927 | $url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner'; |
| 829 | 928 | $json = $Common->getData($url); |
| 830 | - if ($json == '') return array(); |
|
| 929 | + if ($json == '') { |
|
| 930 | + return array(); |
|
| 931 | + } |
|
| 831 | 932 | $parsed_json = json_decode($json); |
| 832 | 933 | $airports = $parsed_json->{'suggestList'}; |
| 833 | 934 | if (count($airports) > 0) { |
@@ -842,7 +943,9 @@ discard block |
||
| 842 | 943 | } |
| 843 | 944 | if (isset($DepartureAirportIata)) { |
| 844 | 945 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin'); |
| 845 | - } else return array(); |
|
| 946 | + } else { |
|
| 947 | + return array(); |
|
| 948 | + } |
|
| 846 | 949 | } |
| 847 | 950 | |
| 848 | 951 | |
@@ -850,7 +953,9 @@ discard block |
||
| 850 | 953 | public function fetchSchedule($ident,$date = 'NOW') { |
| 851 | 954 | global $globalSchedulesSources, $globalSchedulesFetch, $globalOffline; |
| 852 | 955 | //$Common = new Common(); |
| 853 | - if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) return array(); |
|
| 956 | + if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) { |
|
| 957 | + return array(); |
|
| 958 | + } |
|
| 854 | 959 | $airline_icao = ''; |
| 855 | 960 | if (!is_numeric(substr($ident, 0, 3))) |
| 856 | 961 | { |
@@ -1078,14 +1183,21 @@ discard block |
||
| 1078 | 1183 | default: |
| 1079 | 1184 | // Randomly use a generic function to get hours |
| 1080 | 1185 | if (strlen($airline_icao) == 2) { |
| 1081 | - if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware'); |
|
| 1186 | + if (!isset($globalSchedulesSources)) { |
|
| 1187 | + $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware'); |
|
| 1188 | + } |
|
| 1082 | 1189 | if (count($globalSchedulesSources) > 0) { |
| 1083 | 1190 | $rand = mt_rand(0,count($globalSchedulesSources)-1); |
| 1084 | 1191 | $source = $globalSchedulesSources[$rand]; |
| 1085 | - if ($source == 'flightmapper') return $this->getFlightMapper($ident); |
|
| 1086 | - elseif ($source == 'costtotravel') return $this->getCostToTravel($ident); |
|
| 1192 | + if ($source == 'flightmapper') { |
|
| 1193 | + return $this->getFlightMapper($ident); |
|
| 1194 | + } elseif ($source == 'costtotravel') { |
|
| 1195 | + return $this->getCostToTravel($ident); |
|
| 1196 | + } |
|
| 1087 | 1197 | //elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date); |
| 1088 | - elseif ($source == 'flightaware') return $this->getFlightAware($ident); |
|
| 1198 | + elseif ($source == 'flightaware') { |
|
| 1199 | + return $this->getFlightAware($ident); |
|
| 1200 | + } |
|
| 1089 | 1201 | } |
| 1090 | 1202 | } |
| 1091 | 1203 | } |
@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | public function __construct($dbc = null) { |
| 10 | 10 | $Connection = new Connection($dbc); |
| 11 | 11 | $this->db = $Connection->db(); |
| 12 | - if ($this->db === null) die('Error: No DB connection. (Image)'); |
|
| 12 | + if ($this->db === null) { |
|
| 13 | + die('Error: No DB connection. (Image)'); |
|
| 14 | + } |
|
| 13 | 15 | } |
| 14 | 16 | |
| 15 | 17 | /** |
@@ -24,7 +26,9 @@ discard block |
||
| 24 | 26 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
| 25 | 27 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
| 26 | 28 | $reg = $registration; |
| 27 | - if (($reg == '' || $reg == 'NA') && $aircraft_icao != '') $reg = $aircraft_icao.$airline_icao; |
|
| 29 | + if (($reg == '' || $reg == 'NA') && $aircraft_icao != '') { |
|
| 30 | + $reg = $aircraft_icao.$airline_icao; |
|
| 31 | + } |
|
| 28 | 32 | $reg = trim($reg); |
| 29 | 33 | $query = "SELECT spotter_image.image, spotter_image.image_thumbnail, spotter_image.image_source, spotter_image.image_source_website,spotter_image.image_copyright, spotter_image.registration |
| 30 | 34 | FROM spotter_image |
@@ -32,9 +36,13 @@ discard block |
||
| 32 | 36 | $sth = $this->db->prepare($query); |
| 33 | 37 | $sth->execute(array(':registration' => $reg)); |
| 34 | 38 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 35 | - if (!empty($result)) return $result; |
|
| 36 | - elseif ($registration != '' && ($aircraft_icao != '' || $airline_icao != '')) return $this->getSpotterImage('',$aircraft_icao,$airline_icao); |
|
| 37 | - else return array(); |
|
| 39 | + if (!empty($result)) { |
|
| 40 | + return $result; |
|
| 41 | + } elseif ($registration != '' && ($aircraft_icao != '' || $airline_icao != '')) { |
|
| 42 | + return $this->getSpotterImage('',$aircraft_icao,$airline_icao); |
|
| 43 | + } else { |
|
| 44 | + return array(); |
|
| 45 | + } |
|
| 38 | 46 | } |
| 39 | 47 | |
| 40 | 48 | /** |
@@ -77,8 +85,11 @@ discard block |
||
| 77 | 85 | public function getExifCopyright($url) { |
| 78 | 86 | $exif = exif_read_data($url); |
| 79 | 87 | $copyright = ''; |
| 80 | - if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright']; |
|
| 81 | - elseif (isset($exif['copyright'])) $copyright = $exif['copyright']; |
|
| 88 | + if (isset($exif['COMPUTED']['copyright'])) { |
|
| 89 | + $copyright = $exif['COMPUTED']['copyright']; |
|
| 90 | + } elseif (isset($exif['copyright'])) { |
|
| 91 | + $copyright = $exif['copyright']; |
|
| 92 | + } |
|
| 82 | 93 | if ($copyright != '') { |
| 83 | 94 | $copyright = str_replace('Copyright ','',$copyright); |
| 84 | 95 | $copyright = str_replace('© ','',$copyright); |
@@ -96,17 +107,27 @@ discard block |
||
| 96 | 107 | public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '') |
| 97 | 108 | { |
| 98 | 109 | global $globalDebug,$globalAircraftImageFetch, $globalOffline; |
| 99 | - if ((isset($globalAircraftImageFetch) && $globalAircraftImageFetch === FALSE) || (isset($globalOffline) && $globalOffline === TRUE)) return ''; |
|
| 110 | + if ((isset($globalAircraftImageFetch) && $globalAircraftImageFetch === FALSE) || (isset($globalOffline) && $globalOffline === TRUE)) { |
|
| 111 | + return ''; |
|
| 112 | + } |
|
| 100 | 113 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
| 101 | 114 | $registration = trim($registration); |
| 102 | 115 | //getting the aircraft image |
| 103 | - if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...'; |
|
| 104 | - elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
|
| 105 | - elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
|
| 116 | + if ($globalDebug && $registration != '') { |
|
| 117 | + echo 'Try to find an aircraft image for '.$registration.'...'; |
|
| 118 | + } elseif ($globalDebug && $aircraft_icao != '') { |
|
| 119 | + echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
|
| 120 | + } elseif ($globalDebug && $airline_icao != '') { |
|
| 121 | + echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
|
| 122 | + } |
|
| 106 | 123 | $image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao); |
| 107 | - if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
|
| 124 | + if ($registration == '' && $aircraft_icao != '') { |
|
| 125 | + $registration = $aircraft_icao.$airline_icao; |
|
| 126 | + } |
|
| 108 | 127 | if ($image_url['original'] != '') { |
| 109 | - if ($globalDebug) echo 'Found !'."\n"; |
|
| 128 | + if ($globalDebug) { |
|
| 129 | + echo 'Found !'."\n"; |
|
| 130 | + } |
|
| 110 | 131 | $query = "INSERT INTO spotter_image (registration, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:registration,:image,:image_thumbnail,:copyright,:source,:source_website)"; |
| 111 | 132 | try { |
| 112 | 133 | $sth = $this->db->prepare($query); |
@@ -115,7 +136,9 @@ discard block |
||
| 115 | 136 | echo $e->getMessage()."\n"; |
| 116 | 137 | return "error"; |
| 117 | 138 | } |
| 118 | - } elseif ($globalDebug) echo "Not found :'(\n"; |
|
| 139 | + } elseif ($globalDebug) { |
|
| 140 | + echo "Not found :'(\n"; |
|
| 141 | + } |
|
| 119 | 142 | return "success"; |
| 120 | 143 | } |
| 121 | 144 | |
@@ -128,7 +151,9 @@ discard block |
||
| 128 | 151 | public function addMarineImage($mmsi,$imo = '',$name = '') |
| 129 | 152 | { |
| 130 | 153 | global $globalDebug,$globalMarineImageFetch, $globalOffline; |
| 131 | - if ((isset($globalMarineImageFetch) && !$globalMarineImageFetch) || (isset($globalOffline) && $globalOffline === TRUE)) return ''; |
|
| 154 | + if ((isset($globalMarineImageFetch) && !$globalMarineImageFetch) || (isset($globalOffline) && $globalOffline === TRUE)) { |
|
| 155 | + return ''; |
|
| 156 | + } |
|
| 132 | 157 | $mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); |
| 133 | 158 | $imo = filter_var($imo,FILTER_SANITIZE_STRING); |
| 134 | 159 | $name = filter_var($name,FILTER_SANITIZE_STRING); |
@@ -138,16 +163,22 @@ discard block |
||
| 138 | 163 | $identity = $Marine->getIdentity($mmsi); |
| 139 | 164 | if (isset($identity[0]['mmsi'])) { |
| 140 | 165 | $imo = $identity[0]['imo']; |
| 141 | - if ($identity[0]['ship_name'] != '') $name = $identity[0]['ship_name']; |
|
| 166 | + if ($identity[0]['ship_name'] != '') { |
|
| 167 | + $name = $identity[0]['ship_name']; |
|
| 168 | + } |
|
| 142 | 169 | } |
| 143 | 170 | } |
| 144 | 171 | unset($Marine); |
| 145 | 172 | |
| 146 | 173 | //getting the aircraft image |
| 147 | - if ($globalDebug && $name != '') echo 'Try to find an vessel image for '.$name.'...'; |
|
| 174 | + if ($globalDebug && $name != '') { |
|
| 175 | + echo 'Try to find an vessel image for '.$name.'...'; |
|
| 176 | + } |
|
| 148 | 177 | $image_url = $this->findMarineImage($mmsi,$imo,$name); |
| 149 | 178 | if ($image_url['original'] != '') { |
| 150 | - if ($globalDebug) echo 'Found !'."\n"; |
|
| 179 | + if ($globalDebug) { |
|
| 180 | + echo 'Found !'."\n"; |
|
| 181 | + } |
|
| 151 | 182 | $query = "INSERT INTO marine_image (mmsi,imo,name, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:mmsi,:imo,:name,:image,:image_thumbnail,:copyright,:source,:source_website)"; |
| 152 | 183 | try { |
| 153 | 184 | $sth = $this->db->prepare($query); |
@@ -156,7 +187,9 @@ discard block |
||
| 156 | 187 | echo $e->getMessage()."\n"; |
| 157 | 188 | return "error"; |
| 158 | 189 | } |
| 159 | - } elseif ($globalDebug) echo "Not found :'(\n"; |
|
| 190 | + } elseif ($globalDebug) { |
|
| 191 | + echo "Not found :'(\n"; |
|
| 192 | + } |
|
| 160 | 193 | return "success"; |
| 161 | 194 | } |
| 162 | 195 | |
@@ -171,41 +204,85 @@ discard block |
||
| 171 | 204 | { |
| 172 | 205 | global $globalAircraftImageSources, $globalIVAO, $globalAircraftImageCheckICAO, $globalVA; |
| 173 | 206 | $Spotter = new Spotter($this->db); |
| 174 | - if (!isset($globalIVAO)) $globalIVAO = FALSE; |
|
| 207 | + if (!isset($globalIVAO)) { |
|
| 208 | + $globalIVAO = FALSE; |
|
| 209 | + } |
|
| 175 | 210 | $aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING); |
| 176 | 211 | if ($aircraft_registration != '' && $aircraft_registration != 'NA' && (!isset($globalVA) || $globalVA !== TRUE)) { |
| 177 | - if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 212 | + if (strpos($aircraft_registration,'/') !== false) { |
|
| 213 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 214 | + } |
|
| 178 | 215 | $aircraft_registration = urlencode(trim($aircraft_registration)); |
| 179 | 216 | $aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration); |
| 180 | - if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name']; |
|
| 181 | - else $aircraft_name = ''; |
|
| 182 | - if (isset($aircraft_info[0]['aircraft_icao'])) $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
|
| 183 | - else $aircraft_icao = ''; |
|
| 184 | - if (isset($aircraft_info[0]['airline_icao'])) $airline_icao = $aircraft_info[0]['airline_icao']; |
|
| 185 | - else $airline_icao = ''; |
|
| 217 | + if (isset($aircraft_info[0]['aircraft_name'])) { |
|
| 218 | + $aircraft_name = $aircraft_info[0]['aircraft_name']; |
|
| 219 | + } else { |
|
| 220 | + $aircraft_name = ''; |
|
| 221 | + } |
|
| 222 | + if (isset($aircraft_info[0]['aircraft_icao'])) { |
|
| 223 | + $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
|
| 224 | + } else { |
|
| 225 | + $aircraft_icao = ''; |
|
| 226 | + } |
|
| 227 | + if (isset($aircraft_info[0]['airline_icao'])) { |
|
| 228 | + $airline_icao = $aircraft_info[0]['airline_icao']; |
|
| 229 | + } else { |
|
| 230 | + $airline_icao = ''; |
|
| 231 | + } |
|
| 186 | 232 | } elseif ($aircraft_icao != '') { |
| 187 | 233 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_icao); |
| 188 | - if (isset($aircraft_info[0]['type'])) $aircraft_name = $aircraft_info[0]['type']; |
|
| 189 | - else $aircraft_name = ''; |
|
| 234 | + if (isset($aircraft_info[0]['type'])) { |
|
| 235 | + $aircraft_name = $aircraft_info[0]['type']; |
|
| 236 | + } else { |
|
| 237 | + $aircraft_name = ''; |
|
| 238 | + } |
|
| 190 | 239 | $aircraft_registration = $aircraft_icao; |
| 191 | - } else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 240 | + } else { |
|
| 241 | + return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 242 | + } |
|
| 192 | 243 | unset($Spotter); |
| 193 | - if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
|
| 244 | + if (!isset($globalAircraftImageSources)) { |
|
| 245 | + $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
|
| 246 | + } |
|
| 194 | 247 | foreach ($globalAircraftImageSources as $source) { |
| 195 | 248 | $source = strtolower($source); |
| 196 | - if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao); |
|
| 197 | - if ($source == 'planespotters' && !$globalIVAO && extension_loaded('simplexml')) $images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name); |
|
| 198 | - if ($source == 'flickr' && extension_loaded('simplexml')) $images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name); |
|
| 199 | - if ($source == 'bing') $images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name); |
|
| 200 | - if ($source == 'deviantart' && extension_loaded('simplexml')) $images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name); |
|
| 201 | - if ($source == 'wikimedia') $images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name); |
|
| 202 | - if ($source == 'jetphotos' && !$globalIVAO && class_exists("DomDocument")) $images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name); |
|
| 203 | - if ($source == 'planepictures' && !$globalIVAO && class_exists("DomDocument")) $images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name); |
|
| 204 | - if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name); |
|
| 205 | - if ($source == 'customsources') $images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name); |
|
| 206 | - if (isset($images_array) && $images_array['original'] != '') return $images_array; |
|
| 207 | - } |
|
| 208 | - if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) return $this->findAircraftImage($aircraft_icao); |
|
| 249 | + if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') { |
|
| 250 | + $images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao); |
|
| 251 | + } |
|
| 252 | + if ($source == 'planespotters' && !$globalIVAO && extension_loaded('simplexml')) { |
|
| 253 | + $images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name); |
|
| 254 | + } |
|
| 255 | + if ($source == 'flickr' && extension_loaded('simplexml')) { |
|
| 256 | + $images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name); |
|
| 257 | + } |
|
| 258 | + if ($source == 'bing') { |
|
| 259 | + $images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name); |
|
| 260 | + } |
|
| 261 | + if ($source == 'deviantart' && extension_loaded('simplexml')) { |
|
| 262 | + $images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name); |
|
| 263 | + } |
|
| 264 | + if ($source == 'wikimedia') { |
|
| 265 | + $images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name); |
|
| 266 | + } |
|
| 267 | + if ($source == 'jetphotos' && !$globalIVAO && class_exists("DomDocument")) { |
|
| 268 | + $images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name); |
|
| 269 | + } |
|
| 270 | + if ($source == 'planepictures' && !$globalIVAO && class_exists("DomDocument")) { |
|
| 271 | + $images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name); |
|
| 272 | + } |
|
| 273 | + if ($source == 'airportdata' && !$globalIVAO) { |
|
| 274 | + $images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name); |
|
| 275 | + } |
|
| 276 | + if ($source == 'customsources') { |
|
| 277 | + $images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name); |
|
| 278 | + } |
|
| 279 | + if (isset($images_array) && $images_array['original'] != '') { |
|
| 280 | + return $images_array; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) { |
|
| 284 | + return $this->findAircraftImage($aircraft_icao); |
|
| 285 | + } |
|
| 209 | 286 | return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
| 210 | 287 | } |
| 211 | 288 | |
@@ -225,7 +302,9 @@ discard block |
||
| 225 | 302 | //$imo = filter_var($imo,FILTER_SANITIZE_STRING); |
| 226 | 303 | $name = filter_var($name,FILTER_SANITIZE_STRING); |
| 227 | 304 | $name = trim($name); |
| 228 | - if (strlen($name) < 4) return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 305 | + if (strlen($name) < 4) { |
|
| 306 | + return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 307 | + } |
|
| 229 | 308 | /* |
| 230 | 309 | $Marine = new Marine($this->db); |
| 231 | 310 | if ($imo == '' || $name == '') { |
@@ -237,15 +316,29 @@ discard block |
||
| 237 | 316 | } |
| 238 | 317 | unset($Marine); |
| 239 | 318 | */ |
| 240 | - if (!isset($globalMarineImageSources)) $globalMarineImageSources = array('wikimedia','deviantart','flickr','bing'); |
|
| 319 | + if (!isset($globalMarineImageSources)) { |
|
| 320 | + $globalMarineImageSources = array('wikimedia','deviantart','flickr','bing'); |
|
| 321 | + } |
|
| 241 | 322 | foreach ($globalMarineImageSources as $source) { |
| 242 | 323 | $source = strtolower($source); |
| 243 | - if ($source == 'flickr') $images_array = $this->fromFlickr('marine',$mmsi,$name); |
|
| 244 | - if ($source == 'bing') $images_array = $this->fromBing('marine',$mmsi,$name); |
|
| 245 | - if ($source == 'deviantart') $images_array = $this->fromDeviantart('marine',$mmsi,$name); |
|
| 246 | - if ($source == 'wikimedia') $images_array = $this->fromWikimedia('marine',$mmsi,$name); |
|
| 247 | - if ($source == 'customsources') $images_array = $this->fromCustomSource('marine',$mmsi,$name); |
|
| 248 | - if (isset($images_array) && $images_array['original'] != '') return $images_array; |
|
| 324 | + if ($source == 'flickr') { |
|
| 325 | + $images_array = $this->fromFlickr('marine',$mmsi,$name); |
|
| 326 | + } |
|
| 327 | + if ($source == 'bing') { |
|
| 328 | + $images_array = $this->fromBing('marine',$mmsi,$name); |
|
| 329 | + } |
|
| 330 | + if ($source == 'deviantart') { |
|
| 331 | + $images_array = $this->fromDeviantart('marine',$mmsi,$name); |
|
| 332 | + } |
|
| 333 | + if ($source == 'wikimedia') { |
|
| 334 | + $images_array = $this->fromWikimedia('marine',$mmsi,$name); |
|
| 335 | + } |
|
| 336 | + if ($source == 'customsources') { |
|
| 337 | + $images_array = $this->fromCustomSource('marine',$mmsi,$name); |
|
| 338 | + } |
|
| 339 | + if (isset($images_array) && $images_array['original'] != '') { |
|
| 340 | + return $images_array; |
|
| 341 | + } |
|
| 249 | 342 | } |
| 250 | 343 | return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
| 251 | 344 | } |
@@ -268,7 +361,9 @@ discard block |
||
| 268 | 361 | $url= 'http://www.planespotters.net/Aviation_Photos/search.php?reg='.$aircraft_registration.'&output=rss'; |
| 269 | 362 | } |
| 270 | 363 | $data = $Common->getData($url); |
| 271 | - if (substr($data, 0, 5) != "<?xml") return false; |
|
| 364 | + if (substr($data, 0, 5) != "<?xml") { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 272 | 367 | if ($xml = simplexml_load_string($data)) { |
| 273 | 368 | if (isset($xml->channel->item)) { |
| 274 | 369 | $image_url = array(); |
@@ -307,7 +402,9 @@ discard block |
||
| 307 | 402 | $url= 'http://backend.deviantart.com/rss.xml?type=deviation&q="'.urlencode($name).'"'; |
| 308 | 403 | } |
| 309 | 404 | $data = $Common->getData($url); |
| 310 | - if (substr($data, 0, 5) != "<?xml") return false; |
|
| 405 | + if (substr($data, 0, 5) != "<?xml") { |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 311 | 408 | if ($xml = simplexml_load_string($data)) { |
| 312 | 409 | if (isset($xml->channel->item->link)) { |
| 313 | 410 | $image_url = array(); |
@@ -411,14 +508,22 @@ discard block |
||
| 411 | 508 | public function fromFlickr($type,$registration,$name='') { |
| 412 | 509 | $Common = new Common(); |
| 413 | 510 | if ($type == 'aircraft') { |
| 414 | - if ($name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.','.urlencode($name); |
|
| 415 | - else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',aircraft'; |
|
| 511 | + if ($name != '') { |
|
| 512 | + $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.','.urlencode($name); |
|
| 513 | + } else { |
|
| 514 | + $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',aircraft'; |
|
| 515 | + } |
|
| 416 | 516 | } elseif ($type == 'marine') { |
| 417 | - if ($name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags=ship,'.urlencode($name); |
|
| 418 | - else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',ship'; |
|
| 517 | + if ($name != '') { |
|
| 518 | + $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags=ship,'.urlencode($name); |
|
| 519 | + } else { |
|
| 520 | + $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',ship'; |
|
| 521 | + } |
|
| 419 | 522 | } |
| 420 | 523 | $data = $Common->getData($url); |
| 421 | - if (substr($data, 0, 5) != "<?xml") return false; |
|
| 524 | + if (substr($data, 0, 5) != "<?xml") { |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 422 | 527 | if ($xml = simplexml_load_string($data)) { |
| 423 | 528 | if (isset($xml->channel->item)) { |
| 424 | 529 | $original_url = trim((string)$xml->channel->item->enclosure->attributes()->url); |
@@ -461,13 +566,21 @@ discard block |
||
| 461 | 566 | public function fromBing($type,$aircraft_registration,$aircraft_name='') { |
| 462 | 567 | global $globalImageBingKey; |
| 463 | 568 | $Common = new Common(); |
| 464 | - if (!isset($globalImageBingKey) || $globalImageBingKey == '') return false; |
|
| 569 | + if (!isset($globalImageBingKey) || $globalImageBingKey == '') { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 465 | 572 | if ($type == 'aircraft') { |
| 466 | - if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27'; |
|
| 467 | - else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27'; |
|
| 573 | + if ($aircraft_name != '') { |
|
| 574 | + $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27'; |
|
| 575 | + } else { |
|
| 576 | + $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27'; |
|
| 577 | + } |
|
| 468 | 578 | } elseif ($type == 'marine') { |
| 469 | - if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.urlencode($aircraft_name).'%20%2Bship%20-site:flickr.com%27'; |
|
| 470 | - else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Bship%20-site:flickr.com%27'; |
|
| 579 | + if ($aircraft_name != '') { |
|
| 580 | + $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.urlencode($aircraft_name).'%20%2Bship%20-site:flickr.com%27'; |
|
| 581 | + } else { |
|
| 582 | + $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Bship%20-site:flickr.com%27'; |
|
| 583 | + } |
|
| 471 | 584 | } |
| 472 | 585 | $headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey)); |
| 473 | 586 | $data = $Common->getData($url,'get','',$headers); |
@@ -523,17 +636,25 @@ discard block |
||
| 523 | 636 | public function fromWikimedia($type,$registration,$name='') { |
| 524 | 637 | $Common = new Common(); |
| 525 | 638 | if ($type == 'aircraft') { |
| 526 | - if ($name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20'.urlencode($name); |
|
| 527 | - else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft'; |
|
| 639 | + if ($name != '') { |
|
| 640 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20'.urlencode($name); |
|
| 641 | + } else { |
|
| 642 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft'; |
|
| 643 | + } |
|
| 528 | 644 | } elseif ($type == 'marine') { |
| 529 | - if ($name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.urlencode($name).'%20ship"'; |
|
| 530 | - else return false; |
|
| 645 | + if ($name != '') { |
|
| 646 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.urlencode($name).'%20ship"'; |
|
| 647 | + } else { |
|
| 648 | + return false; |
|
| 649 | + } |
|
| 531 | 650 | } |
| 532 | 651 | $data = $Common->getData($url); |
| 533 | 652 | $result = json_decode($data); |
| 534 | 653 | if (isset($result->query->search[0]->title)) { |
| 535 | 654 | $fileo = $result->query->search[0]->title; |
| 536 | - if (substr($fileo,-3) == 'pdf') return false; |
|
| 655 | + if (substr($fileo,-3) == 'pdf') { |
|
| 656 | + return false; |
|
| 657 | + } |
|
| 537 | 658 | $file = urlencode($fileo); |
| 538 | 659 | $url2 = 'https://commons.wikimedia.org/w/api.php?action=query&format=json&continue&iilimit=500&prop=imageinfo&iiprop=user|url|size|mime|sha1|timestamp&iiurlwidth=200%27&titles='.$file; |
| 539 | 660 | $data2 = $Common->getData($url2); |
@@ -604,18 +725,27 @@ discard block |
||
| 604 | 725 | $image_url = array(); |
| 605 | 726 | $image_url['thumbnail'] = $url_thumbnail; |
| 606 | 727 | $image_url['original'] = $url; |
| 607 | - if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
|
| 608 | - else $exifCopyright = ''; |
|
| 609 | - if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
|
| 610 | - elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
|
| 611 | - else $image_url['copyright'] = $source['source_website']; |
|
| 728 | + if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) { |
|
| 729 | + $exifCopyright = $this->getExifCopyright($url); |
|
| 730 | + } else { |
|
| 731 | + $exifCopyright = ''; |
|
| 732 | + } |
|
| 733 | + if ($exifCopyright != '') { |
|
| 734 | + $image_url['copyright'] = $exifCopyright; |
|
| 735 | + } elseif (isset($source['copyright'])) { |
|
| 736 | + $image_url['copyright'] = $source['copyright']; |
|
| 737 | + } else { |
|
| 738 | + $image_url['copyright'] = $source['source_website']; |
|
| 739 | + } |
|
| 612 | 740 | $image_url['source_website'] = $source['source_website']; |
| 613 | 741 | $image_url['source'] = $source['source']; |
| 614 | 742 | return $image_url; |
| 615 | 743 | } |
| 616 | 744 | } |
| 617 | 745 | return false; |
| 618 | - } else return false; |
|
| 746 | + } else { |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 619 | 749 | if (!empty($globalMarineImageCustomSources) && $type == 'marine') { |
| 620 | 750 | $customsources = array(); |
| 621 | 751 | if (!isset($globalMarineImageCustomSources[0])) { |
@@ -640,18 +770,27 @@ discard block |
||
| 640 | 770 | $image_url = array(); |
| 641 | 771 | $image_url['thumbnail'] = $url_thumbnail; |
| 642 | 772 | $image_url['original'] = $url; |
| 643 | - if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
|
| 644 | - else $exifCopyright = ''; |
|
| 645 | - if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
|
| 646 | - elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
|
| 647 | - else $image_url['copyright'] = $source['source_website']; |
|
| 773 | + if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) { |
|
| 774 | + $exifCopyright = $this->getExifCopyright($url); |
|
| 775 | + } else { |
|
| 776 | + $exifCopyright = ''; |
|
| 777 | + } |
|
| 778 | + if ($exifCopyright != '') { |
|
| 779 | + $image_url['copyright'] = $exifCopyright; |
|
| 780 | + } elseif (isset($source['copyright'])) { |
|
| 781 | + $image_url['copyright'] = $source['copyright']; |
|
| 782 | + } else { |
|
| 783 | + $image_url['copyright'] = $source['source_website']; |
|
| 784 | + } |
|
| 648 | 785 | $image_url['source_website'] = $source['source_website']; |
| 649 | 786 | $image_url['source'] = $source['source']; |
| 650 | 787 | return $image_url; |
| 651 | 788 | } |
| 652 | 789 | } |
| 653 | 790 | return false; |
| 654 | - } else return false; |
|
| 791 | + } else { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 655 | 794 | } |
| 656 | 795 | } |
| 657 | 796 | |