@@ -8,7 +8,9 @@ discard block |
||
| 8 | 8 | public function __construct($dbc = null) { |
| 9 | 9 | $Connection = new Connection($dbc); |
| 10 | 10 | $this->db = $Connection->db(); |
| 11 | - if ($this->db === null) die('Error: No DB connection. (SpotterLive)'); |
|
| 11 | + if ($this->db === null) { |
|
| 12 | + die('Error: No DB connection. (SpotterLive)'); |
|
| 13 | + } |
|
| 12 | 14 | } |
| 13 | 15 | |
| 14 | 16 | |
@@ -30,7 +32,9 @@ discard block |
||
| 30 | 32 | if (isset($filter[0]['source'])) { |
| 31 | 33 | $filters = array_merge($filters,$filter); |
| 32 | 34 | } |
| 33 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
| 35 | + if (is_array($globalFilter)) { |
|
| 36 | + $filter = array_merge($filter,$globalFilter); |
|
| 37 | + } |
|
| 34 | 38 | $filter_query_join = ''; |
| 35 | 39 | $filter_query_where = ''; |
| 36 | 40 | foreach($filters as $flt) { |
@@ -129,8 +133,11 @@ discard block |
||
| 129 | 133 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 130 | 134 | $filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
| 131 | 135 | } |
| 132 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
| 133 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
| 136 | + if ($filter_query_where == '' && $where) { |
|
| 137 | + $filter_query_where = ' WHERE'; |
|
| 138 | + } elseif ($filter_query_where != '' && $and) { |
|
| 139 | + $filter_query_where .= ' AND'; |
|
| 140 | + } |
|
| 134 | 141 | if ($filter_query_where != '') { |
| 135 | 142 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
| 136 | 143 | } |
@@ -173,9 +180,13 @@ discard block |
||
| 173 | 180 | $orderby_query = ' '.$search_orderby_array[$sort]['sql']; |
| 174 | 181 | } |
| 175 | 182 | } |
| 176 | - if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC'; |
|
| 183 | + if ($orderby_query == '') { |
|
| 184 | + $orderby_query = ' ORDER BY date DESC'; |
|
| 185 | + } |
|
| 177 | 186 | |
| 178 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 187 | + if (!isset($globalLiveInterval)) { |
|
| 188 | + $globalLiveInterval = '200'; |
|
| 189 | + } |
|
| 179 | 190 | if ($globalDBdriver == 'mysql') { |
| 180 | 191 | //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
| 181 | 192 | $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query; |
@@ -199,7 +210,9 @@ discard block |
||
| 199 | 210 | global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap2DAircraftsLimit; |
| 200 | 211 | date_default_timezone_set('UTC'); |
| 201 | 212 | $filter_query = $this->getFilter($filter,true,true); |
| 202 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 213 | + if (!isset($globalLiveInterval)) { |
|
| 214 | + $globalLiveInterval = '200'; |
|
| 215 | + } |
|
| 203 | 216 | if ($globalDBdriver == 'mysql') { |
| 204 | 217 | if (isset($globalArchive) && $globalArchive === TRUE) { |
| 205 | 218 | // $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
@@ -263,14 +276,22 @@ discard block |
||
| 263 | 276 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 264 | 277 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 265 | 278 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 266 | - if ($minlong != '' && $minlat != '' && $maxlong != '' && $maxlat != '') $usecoord = true; |
|
| 279 | + if ($minlong != '' && $minlat != '' && $maxlong != '' && $maxlat != '') { |
|
| 280 | + $usecoord = true; |
|
| 281 | + } |
|
| 267 | 282 | } |
| 268 | 283 | $id = filter_var($id,FILTER_SANITIZE_STRING); |
| 269 | 284 | $filter_query = $this->getFilter($filter,true,true); |
| 270 | 285 | |
| 271 | - if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200'; |
|
| 272 | - if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300'; |
|
| 273 | - if ($limit == 0 || $limit == '') $limit = $globalMap3DAircraftsLimit; |
|
| 286 | + if (!isset($globalLiveInterval) || $globalLiveInterval == '') { |
|
| 287 | + $globalLiveInterval = '200'; |
|
| 288 | + } |
|
| 289 | + if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') { |
|
| 290 | + $globalMap3DAircraftsLimit = '300'; |
|
| 291 | + } |
|
| 292 | + if ($limit == 0 || $limit == '') { |
|
| 293 | + $limit = $globalMap3DAircraftsLimit; |
|
| 294 | + } |
|
| 274 | 295 | if ($globalDBdriver == 'mysql') { |
| 275 | 296 | if (isset($globalArchive) && $globalArchive === TRUE) { |
| 276 | 297 | /* |
@@ -283,26 +304,42 @@ discard block |
||
| 283 | 304 | FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date"; |
| 284 | 305 | //if ($limit > 0) $query .= " LIMIT ".$limit; |
| 285 | 306 | $query .= ") l ON l.flightaware_id = spotter_archive.flightaware_id "; |
| 286 | - if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 287 | - if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id "; |
|
| 307 | + if ($usecoord) { |
|
| 308 | + $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 309 | + } |
|
| 310 | + if ($id != '') { |
|
| 311 | + $query .= "OR spotter_archive.flightaware_id = :id "; |
|
| 312 | + } |
|
| 288 | 313 | $query .= "UNION |
| 289 | 314 | SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
| 290 | 315 | FROM spotter_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date"; |
| 291 | - if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")"; |
|
| 292 | - if ($id != '') $query .= " OR spotter_live.flightaware_id = :id"; |
|
| 316 | + if ($usecoord) { |
|
| 317 | + $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")"; |
|
| 318 | + } |
|
| 319 | + if ($id != '') { |
|
| 320 | + $query .= " OR spotter_live.flightaware_id = :id"; |
|
| 321 | + } |
|
| 293 | 322 | //if ($limit > 0) $query .= " LIMIT ".$limit; |
| 294 | 323 | $query .= ") AS spotter |
| 295 | 324 | WHERE latitude <> '0' AND longitude <> '0' |
| 296 | 325 | ORDER BY flightaware_id, date"; |
| 297 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 326 | + if ($limit > 0) { |
|
| 327 | + $query .= " LIMIT ".$limit; |
|
| 328 | + } |
|
| 298 | 329 | } else { |
| 299 | 330 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
| 300 | 331 | FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date "; |
| 301 | - if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 302 | - if ($id != '') $query .= "OR spotter_live.flightaware_id = :id "; |
|
| 332 | + if ($usecoord) { |
|
| 333 | + $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 334 | + } |
|
| 335 | + if ($id != '') { |
|
| 336 | + $query .= "OR spotter_live.flightaware_id = :id "; |
|
| 337 | + } |
|
| 303 | 338 | $query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
| 304 | 339 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
| 305 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 340 | + if ($limit > 0) { |
|
| 341 | + $query .= " LIMIT ".$limit; |
|
| 342 | + } |
|
| 306 | 343 | } |
| 307 | 344 | } else { |
| 308 | 345 | if (isset($globalArchive) && $globalArchive === TRUE) { |
@@ -320,29 +357,47 @@ discard block |
||
| 320 | 357 | FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date"; |
| 321 | 358 | //if ($limit > 0) $query .= " ORDER BY spotter_live.date ASC LIMIT ".$limit; |
| 322 | 359 | $query .= ") l ON l.flightaware_id = spotter_archive.flightaware_id "; |
| 323 | - if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 324 | - if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id "; |
|
| 360 | + if ($usecoord) { |
|
| 361 | + $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 362 | + } |
|
| 363 | + if ($id != '') { |
|
| 364 | + $query .= "OR spotter_archive.flightaware_id = :id "; |
|
| 365 | + } |
|
| 325 | 366 | $query .= "UNION |
| 326 | 367 | SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
| 327 | 368 | FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date"; |
| 328 | - if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")"; |
|
| 329 | - if ($id != '') $query .= " OR spotter_live.flightaware_id = :id"; |
|
| 369 | + if ($usecoord) { |
|
| 370 | + $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")"; |
|
| 371 | + } |
|
| 372 | + if ($id != '') { |
|
| 373 | + $query .= " OR spotter_live.flightaware_id = :id"; |
|
| 374 | + } |
|
| 330 | 375 | //if ($limit > 0) $query .= " ORDER BY date ASC LIMIT ".$limit; |
| 331 | 376 | $query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' "; |
| 332 | 377 | $query .= "ORDER BY flightaware_id, date"; |
| 333 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 378 | + if ($limit > 0) { |
|
| 379 | + $query .= " LIMIT ".$limit; |
|
| 380 | + } |
|
| 334 | 381 | } else { |
| 335 | 382 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
| 336 | 383 | FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date "; |
| 337 | - if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 338 | - if ($id != '') $query .= "OR spotter_live.flightaware_id = :id "; |
|
| 384 | + if ($usecoord) { |
|
| 385 | + $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
| 386 | + } |
|
| 387 | + if ($id != '') { |
|
| 388 | + $query .= "OR spotter_live.flightaware_id = :id "; |
|
| 389 | + } |
|
| 339 | 390 | $query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
| 340 | 391 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
| 341 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 392 | + if ($limit > 0) { |
|
| 393 | + $query .= " LIMIT ".$limit; |
|
| 394 | + } |
|
| 342 | 395 | } |
| 343 | 396 | } |
| 344 | 397 | $query_values = array(); |
| 345 | - if ($id != '') $query_values = array(':id' => $id); |
|
| 398 | + if ($id != '') { |
|
| 399 | + $query_values = array(':id' => $id); |
|
| 400 | + } |
|
| 346 | 401 | try { |
| 347 | 402 | $sth = $this->db->prepare($query); |
| 348 | 403 | $sth->execute($query_values); |
@@ -369,9 +424,15 @@ discard block |
||
| 369 | 424 | $id = filter_var($id,FILTER_SANITIZE_STRING); |
| 370 | 425 | $filter_query = $this->getFilter($filter,true,true); |
| 371 | 426 | |
| 372 | - if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200'; |
|
| 373 | - if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300'; |
|
| 374 | - if ($limit == 0 || $limit == '') $limit = $globalMap3DAircraftsLimit; |
|
| 427 | + if (!isset($globalLiveInterval) || $globalLiveInterval == '') { |
|
| 428 | + $globalLiveInterval = '200'; |
|
| 429 | + } |
|
| 430 | + if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') { |
|
| 431 | + $globalMap3DAircraftsLimit = '300'; |
|
| 432 | + } |
|
| 433 | + if ($limit == 0 || $limit == '') { |
|
| 434 | + $limit = $globalMap3DAircraftsLimit; |
|
| 435 | + } |
|
| 375 | 436 | if ($globalDBdriver == 'mysql') { |
| 376 | 437 | if (isset($globalArchive) && $globalArchive === TRUE) { |
| 377 | 438 | $query = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration |
@@ -382,13 +443,17 @@ discard block |
||
| 382 | 443 | $query .= ") AS spotter |
| 383 | 444 | WHERE latitude <> '0' AND longitude <> '0' |
| 384 | 445 | ORDER BY flightaware_id, date"; |
| 385 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 446 | + if ($limit > 0) { |
|
| 447 | + $query .= " LIMIT ".$limit; |
|
| 448 | + } |
|
| 386 | 449 | } else { |
| 387 | 450 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
| 388 | 451 | FROM spotter_live'.$filter_query.' spotter_live.flightaware_id = :id '; |
| 389 | 452 | $query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
| 390 | 453 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
| 391 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 454 | + if ($limit > 0) { |
|
| 455 | + $query .= " LIMIT ".$limit; |
|
| 456 | + } |
|
| 392 | 457 | } |
| 393 | 458 | } else { |
| 394 | 459 | if (isset($globalArchive) && $globalArchive === TRUE) { |
@@ -404,13 +469,17 @@ discard block |
||
| 404 | 469 | FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id"; |
| 405 | 470 | $query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' "; |
| 406 | 471 | $query .= "ORDER BY flightaware_id, date"; |
| 407 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 472 | + if ($limit > 0) { |
|
| 473 | + $query .= " LIMIT ".$limit; |
|
| 474 | + } |
|
| 408 | 475 | } else { |
| 409 | 476 | $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
| 410 | 477 | FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id "; |
| 411 | 478 | $query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
| 412 | 479 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
| 413 | - if ($limit > 0) $query .= " LIMIT ".$limit; |
|
| 480 | + if ($limit > 0) { |
|
| 481 | + $query .= " LIMIT ".$limit; |
|
| 482 | + } |
|
| 414 | 483 | } |
| 415 | 484 | } |
| 416 | 485 | $query_values = array(); |
@@ -437,7 +506,9 @@ discard block |
||
| 437 | 506 | global $globalDBdriver, $globalLiveInterval; |
| 438 | 507 | $filter_query = $this->getFilter($filter,true,true); |
| 439 | 508 | |
| 440 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 509 | + if (!isset($globalLiveInterval)) { |
|
| 510 | + $globalLiveInterval = '200'; |
|
| 511 | + } |
|
| 441 | 512 | if ($globalDBdriver == 'mysql') { |
| 442 | 513 | //$query = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query; |
| 443 | 514 | $query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
@@ -468,7 +539,9 @@ discard block |
||
| 468 | 539 | { |
| 469 | 540 | global $globalDBdriver, $globalLiveInterval,$globalMap2DAircraftsLimit; |
| 470 | 541 | $Spotter = new Spotter($this->db); |
| 471 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 542 | + if (!isset($globalLiveInterval)) { |
|
| 543 | + $globalLiveInterval = '200'; |
|
| 544 | + } |
|
| 472 | 545 | $filter_query = $this->getFilter($filter); |
| 473 | 546 | |
| 474 | 547 | if (is_array($coord)) { |
@@ -476,7 +549,9 @@ discard block |
||
| 476 | 549 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 477 | 550 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 478 | 551 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 479 | - } else return array(); |
|
| 552 | + } else { |
|
| 553 | + return array(); |
|
| 554 | + } |
|
| 480 | 555 | if ($globalDBdriver == 'mysql') { |
| 481 | 556 | $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query; |
| 482 | 557 | } else { |
@@ -502,7 +577,9 @@ discard block |
||
| 502 | 577 | { |
| 503 | 578 | global $globalDBdriver, $globalLiveInterval, $globalArchive,$globalMap2DAircraftsLimit; |
| 504 | 579 | $Spotter = new Spotter($this->db); |
| 505 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 580 | + if (!isset($globalLiveInterval)) { |
|
| 581 | + $globalLiveInterval = '200'; |
|
| 582 | + } |
|
| 506 | 583 | $filter_query = $this->getFilter($filter,true,true); |
| 507 | 584 | |
| 508 | 585 | if (is_array($coord)) { |
@@ -510,7 +587,9 @@ discard block |
||
| 510 | 587 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 511 | 588 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 512 | 589 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 513 | - } else return array(); |
|
| 590 | + } else { |
|
| 591 | + return array(); |
|
| 592 | + } |
|
| 514 | 593 | if ($globalDBdriver == 'mysql') { |
| 515 | 594 | if (isset($globalArchive) && $globalArchive === TRUE) { |
| 516 | 595 | $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
@@ -765,11 +844,15 @@ discard block |
||
| 765 | 844 | //$query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
| 766 | 845 | if ($globalDBdriver == 'mysql') { |
| 767 | 846 | $query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
| 768 | - if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
|
| 847 | + if ($liveinterval) { |
|
| 848 | + $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
|
| 849 | + } |
|
| 769 | 850 | $query .= ' ORDER BY date'; |
| 770 | 851 | } else { |
| 771 | 852 | $query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
| 772 | - if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
|
| 853 | + if ($liveinterval) { |
|
| 854 | + $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
|
| 855 | + } |
|
| 773 | 856 | $query .= ' ORDER BY date'; |
| 774 | 857 | } |
| 775 | 858 | |
@@ -864,7 +947,9 @@ discard block |
||
| 864 | 947 | $i++; |
| 865 | 948 | $j++; |
| 866 | 949 | if ($j == 30) { |
| 867 | - if ($globalDebug) echo "."; |
|
| 950 | + if ($globalDebug) { |
|
| 951 | + echo "."; |
|
| 952 | + } |
|
| 868 | 953 | try { |
| 869 | 954 | |
| 870 | 955 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
@@ -1239,7 +1324,9 @@ discard block |
||
| 1239 | 1324 | { |
| 1240 | 1325 | return false; |
| 1241 | 1326 | } |
| 1242 | - } else return ''; |
|
| 1327 | + } else { |
|
| 1328 | + return ''; |
|
| 1329 | + } |
|
| 1243 | 1330 | |
| 1244 | 1331 | if ($longitude != '') |
| 1245 | 1332 | { |
@@ -1247,7 +1334,9 @@ discard block |
||
| 1247 | 1334 | { |
| 1248 | 1335 | return false; |
| 1249 | 1336 | } |
| 1250 | - } else return ''; |
|
| 1337 | + } else { |
|
| 1338 | + return ''; |
|
| 1339 | + } |
|
| 1251 | 1340 | |
| 1252 | 1341 | if ($waypoints != '') |
| 1253 | 1342 | { |
@@ -1263,14 +1352,18 @@ discard block |
||
| 1263 | 1352 | { |
| 1264 | 1353 | return false; |
| 1265 | 1354 | } |
| 1266 | - } else $altitude = 0; |
|
| 1355 | + } else { |
|
| 1356 | + $altitude = 0; |
|
| 1357 | + } |
|
| 1267 | 1358 | if ($altitude_real != '') |
| 1268 | 1359 | { |
| 1269 | 1360 | if (!is_numeric($altitude_real)) |
| 1270 | 1361 | { |
| 1271 | 1362 | return false; |
| 1272 | 1363 | } |
| 1273 | - } else $altitude_real = 0; |
|
| 1364 | + } else { |
|
| 1365 | + $altitude_real = 0; |
|
| 1366 | + } |
|
| 1274 | 1367 | |
| 1275 | 1368 | if ($heading != '') |
| 1276 | 1369 | { |
@@ -1278,7 +1371,9 @@ discard block |
||
| 1278 | 1371 | { |
| 1279 | 1372 | return false; |
| 1280 | 1373 | } |
| 1281 | - } else $heading = 0; |
|
| 1374 | + } else { |
|
| 1375 | + $heading = 0; |
|
| 1376 | + } |
|
| 1282 | 1377 | |
| 1283 | 1378 | if ($groundspeed != '') |
| 1284 | 1379 | { |
@@ -1286,9 +1381,13 @@ discard block |
||
| 1286 | 1381 | { |
| 1287 | 1382 | return false; |
| 1288 | 1383 | } |
| 1289 | - } else $groundspeed = 0; |
|
| 1384 | + } else { |
|
| 1385 | + $groundspeed = 0; |
|
| 1386 | + } |
|
| 1290 | 1387 | date_default_timezone_set('UTC'); |
| 1291 | - if ($date == '') $date = date("Y-m-d H:i:s", time()); |
|
| 1388 | + if ($date == '') { |
|
| 1389 | + $date = date("Y-m-d H:i:s", time()); |
|
| 1390 | + } |
|
| 1292 | 1391 | |
| 1293 | 1392 | |
| 1294 | 1393 | $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
@@ -1333,14 +1432,24 @@ discard block |
||
| 1333 | 1432 | $arrival_airport_country = ''; |
| 1334 | 1433 | |
| 1335 | 1434 | |
| 1336 | - if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL; |
|
| 1337 | - if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL; |
|
| 1338 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
|
| 1339 | - if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
|
| 1435 | + if ($squawk == '' || $Common->isInteger($squawk) === false ) { |
|
| 1436 | + $squawk = NULL; |
|
| 1437 | + } |
|
| 1438 | + if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) { |
|
| 1439 | + $verticalrate = NULL; |
|
| 1440 | + } |
|
| 1441 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) { |
|
| 1442 | + $groundspeed = 0; |
|
| 1443 | + } |
|
| 1444 | + if ($heading == '' || $Common->isInteger($heading) === false ) { |
|
| 1445 | + $heading = 0; |
|
| 1446 | + } |
|
| 1340 | 1447 | |
| 1341 | 1448 | $query = ''; |
| 1342 | 1449 | if ($globalArchive) { |
| 1343 | - if ($globalDebug) echo '-- Delete previous data -- '; |
|
| 1450 | + if ($globalDebug) { |
|
| 1451 | + echo '-- Delete previous data -- '; |
|
| 1452 | + } |
|
| 1344 | 1453 | $query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;'; |
| 1345 | 1454 | } |
| 1346 | 1455 | |
@@ -1357,10 +1466,14 @@ discard block |
||
| 1357 | 1466 | return "error : ".$e->getMessage(); |
| 1358 | 1467 | } |
| 1359 | 1468 | if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) { |
| 1360 | - if ($globalDebug) echo '(Add to Spotter archive : '; |
|
| 1469 | + if ($globalDebug) { |
|
| 1470 | + echo '(Add to Spotter archive : '; |
|
| 1471 | + } |
|
| 1361 | 1472 | $SpotterArchive = new SpotterArchive($this->db); |
| 1362 | 1473 | $result = $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $altitude_real,$heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country); |
| 1363 | - if ($globalDebug) echo $result.')'; |
|
| 1474 | + if ($globalDebug) { |
|
| 1475 | + echo $result.')'; |
|
| 1476 | + } |
|
| 1364 | 1477 | } elseif ($globalDebug && $putinarchive !== true) { |
| 1365 | 1478 | echo '(Not adding to archive)'; |
| 1366 | 1479 | } elseif ($globalDebug && $noarchive === true) { |
@@ -6,7 +6,9 @@ discard block |
||
| 6 | 6 | public function __construct($dbc = null) { |
| 7 | 7 | $Connection = new Connection($dbc); |
| 8 | 8 | $this->db = $Connection->db; |
| 9 | - if ($this->db === null) die('Error: No DB connection. (SpotterArchive)'); |
|
| 9 | + if ($this->db === null) { |
|
| 10 | + die('Error: No DB connection. (SpotterArchive)'); |
|
| 11 | + } |
|
| 10 | 12 | } |
| 11 | 13 | |
| 12 | 14 | /** |
@@ -29,7 +31,9 @@ discard block |
||
| 29 | 31 | if (isset($filter[0]['source'])) { |
| 30 | 32 | $filters = array_merge($filters,$filter); |
| 31 | 33 | } |
| 32 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
| 34 | + if (is_array($globalFilter)) { |
|
| 35 | + $filter = array_merge($filter,$globalFilter); |
|
| 36 | + } |
|
| 33 | 37 | $filter_query_join = ''; |
| 34 | 38 | $filter_query_where = ''; |
| 35 | 39 | foreach($filters as $flt) { |
@@ -121,8 +125,11 @@ discard block |
||
| 121 | 125 | } |
| 122 | 126 | $filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_archive_output.flightaware_id"; |
| 123 | 127 | } |
| 124 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
| 125 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
| 128 | + if ($filter_query_where == '' && $where) { |
|
| 129 | + $filter_query_where = ' WHERE'; |
|
| 130 | + } elseif ($filter_query_where != '' && $and) { |
|
| 131 | + $filter_query_where .= ' AND'; |
|
| 132 | + } |
|
| 126 | 133 | if ($filter_query_where != '') { |
| 127 | 134 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
| 128 | 135 | } |
@@ -136,10 +143,17 @@ discard block |
||
| 136 | 143 | if ($over_country == '') { |
| 137 | 144 | $Spotter = new Spotter($this->db); |
| 138 | 145 | $data_country = $Spotter->getCountryFromLatitudeLongitude($latitude,$longitude); |
| 139 | - if (!empty($data_country)) $country = $data_country['iso2']; |
|
| 140 | - else $country = ''; |
|
| 141 | - } else $country = $over_country; |
|
| 142 | - if ($airline_type === NULL) $airline_type =''; |
|
| 146 | + if (!empty($data_country)) { |
|
| 147 | + $country = $data_country['iso2']; |
|
| 148 | + } else { |
|
| 149 | + $country = ''; |
|
| 150 | + } |
|
| 151 | + } else { |
|
| 152 | + $country = $over_country; |
|
| 153 | + } |
|
| 154 | + if ($airline_type === NULL) { |
|
| 155 | + $airline_type =''; |
|
| 156 | + } |
|
| 143 | 157 | |
| 144 | 158 | //if ($country == '') echo "\n".'************ UNKNOW COUNTRY ****************'."\n"; |
| 145 | 159 | //else echo "\n".'*/*/*/*/*/*/*/ Country : '.$country.' */*/*/*/*/*/*/*/*/'."\n"; |
@@ -678,7 +692,9 @@ discard block |
||
| 678 | 692 | $additional_query .= "(spotter_archive_output.pilot_name like '%".$q_item."%') OR "; |
| 679 | 693 | $additional_query .= "(spotter_archive_output.ident like '%".$q_item."%') OR "; |
| 680 | 694 | $translate = $Translation->ident2icao($q_item); |
| 681 | - if ($translate != $q_item) $additional_query .= "(spotter_archive_output.ident like '%".$translate."%') OR "; |
|
| 695 | + if ($translate != $q_item) { |
|
| 696 | + $additional_query .= "(spotter_archive_output.ident like '%".$translate."%') OR "; |
|
| 697 | + } |
|
| 682 | 698 | $additional_query .= "(spotter_archive_output.highlight like '%".$q_item."%')"; |
| 683 | 699 | $additional_query .= ")"; |
| 684 | 700 | } |
@@ -858,7 +874,9 @@ discard block |
||
| 858 | 874 | date_default_timezone_set($globalTimezone); |
| 859 | 875 | $datetime = new DateTime(); |
| 860 | 876 | $offset = $datetime->format('P'); |
| 861 | - } else $offset = '+00:00'; |
|
| 877 | + } else { |
|
| 878 | + $offset = '+00:00'; |
|
| 879 | + } |
|
| 862 | 880 | if ($date_array[1] != "") { |
| 863 | 881 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
| 864 | 882 | $date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); |
@@ -1112,9 +1130,13 @@ discard block |
||
| 1112 | 1130 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
| 1113 | 1131 | } |
| 1114 | 1132 | } |
| 1115 | - if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
|
| 1133 | + if ($sincedate != '') { |
|
| 1134 | + $query .= "AND date > '".$sincedate."' "; |
|
| 1135 | + } |
|
| 1116 | 1136 | $query .= "GROUP BY c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
| 1117 | - if ($limit) $query .= " LIMIT 0,10"; |
|
| 1137 | + if ($limit) { |
|
| 1138 | + $query .= " LIMIT 0,10"; |
|
| 1139 | + } |
|
| 1118 | 1140 | |
| 1119 | 1141 | |
| 1120 | 1142 | $sth = $this->db->prepare($query); |
@@ -1158,9 +1180,13 @@ discard block |
||
| 1158 | 1180 | $query .= "AND s.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
| 1159 | 1181 | } |
| 1160 | 1182 | } |
| 1161 | - if ($sincedate != '') $query .= "AND s.date > '".$sincedate."' "; |
|
| 1183 | + if ($sincedate != '') { |
|
| 1184 | + $query .= "AND s.date > '".$sincedate."' "; |
|
| 1185 | + } |
|
| 1162 | 1186 | $query .= "GROUP BY o.airline_icao,c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
| 1163 | - if ($limit) $query .= " LIMIT 0,10"; |
|
| 1187 | + if ($limit) { |
|
| 1188 | + $query .= " LIMIT 0,10"; |
|
| 1189 | + } |
|
| 1164 | 1190 | |
| 1165 | 1191 | |
| 1166 | 1192 | $sth = $this->db->prepare($query); |
@@ -1382,8 +1408,11 @@ discard block |
||
| 1382 | 1408 | if($row['registration'] != "") |
| 1383 | 1409 | { |
| 1384 | 1410 | $image_array = $Image->getSpotterImage($row['registration']); |
| 1385 | - if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
|
| 1386 | - else $temp_array['image_thumbnail'] = ''; |
|
| 1411 | + if (isset($image_array[0]['image_thumbnail'])) { |
|
| 1412 | + $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
|
| 1413 | + } else { |
|
| 1414 | + $temp_array['image_thumbnail'] = ''; |
|
| 1415 | + } |
|
| 1387 | 1416 | } |
| 1388 | 1417 | $temp_array['registration_count'] = $row['registration_count']; |
| 1389 | 1418 | $aircraft_array[] = $temp_array; |
@@ -1442,7 +1471,9 @@ discard block |
||
| 1442 | 1471 | date_default_timezone_set($globalTimezone); |
| 1443 | 1472 | $datetime = new DateTime(); |
| 1444 | 1473 | $offset = $datetime->format('P'); |
| 1445 | - } else $offset = '+00:00'; |
|
| 1474 | + } else { |
|
| 1475 | + $offset = '+00:00'; |
|
| 1476 | + } |
|
| 1446 | 1477 | if ($globalDBdriver == 'mysql') { |
| 1447 | 1478 | $query = "SELECT HOUR(CONVERT_TZ(spotter_archive_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
| 1448 | 1479 | FROM spotter_archive_output".$filter_query." spotter_archive_output.owner_name = :owner |
@@ -36,7 +36,9 @@ discard block |
||
| 36 | 36 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 37 | 37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 38 | 38 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 39 | - if ($getheaders) curl_setopt($ch, CURLOPT_HEADER, 1); |
|
| 39 | + if ($getheaders) { |
|
| 40 | + curl_setopt($ch, CURLOPT_HEADER, 1); |
|
| 41 | + } |
|
| 40 | 42 | curl_setopt($ch,CURLOPT_ENCODING , "gzip"); |
| 41 | 43 | //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
| 42 | 44 | // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0'); |
@@ -45,8 +47,11 @@ discard block |
||
| 45 | 47 | } else { |
| 46 | 48 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 47 | 49 | } |
| 48 | - if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 49 | - else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 50 | + if ($timeout == '') { |
|
| 51 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 52 | + } else { |
|
| 53 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 54 | + } |
|
| 50 | 55 | //curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
| 51 | 56 | if ($type == 'post') { |
| 52 | 57 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
@@ -59,7 +64,9 @@ discard block |
||
| 59 | 64 | } else { |
| 60 | 65 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
| 61 | 66 | } |
| 62 | - } elseif ($type != 'get' && $type != '') curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); |
|
| 67 | + } elseif ($type != 'get' && $type != '') { |
|
| 68 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); |
|
| 69 | + } |
|
| 63 | 70 | if ($headers != '') { |
| 64 | 71 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| 65 | 72 | } |
@@ -103,8 +110,9 @@ discard block |
||
| 103 | 110 | private function curlResponseHeaderCallback($ch, $headerLine) { |
| 104 | 111 | global $curl_cookies; |
| 105 | 112 | $curl_cookies = array(); |
| 106 | - if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) |
|
| 107 | - $curl_cookies[] = $cookie; |
|
| 113 | + if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) { |
|
| 114 | + $curl_cookies[] = $cookie; |
|
| 115 | + } |
|
| 108 | 116 | return strlen($headerLine); // Needed by curl |
| 109 | 117 | } |
| 110 | 118 | |
@@ -116,7 +124,9 @@ discard block |
||
| 116 | 124 | curl_setopt($ch, CURLOPT_URL, $url); |
| 117 | 125 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 118 | 126 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 119 | - if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 127 | + if ($referer != '') { |
|
| 128 | + curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 129 | + } |
|
| 120 | 130 | if (isset($globalForceIPv4) && $globalForceIPv4) { |
| 121 | 131 | if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){ |
| 122 | 132 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
@@ -128,7 +138,9 @@ discard block |
||
| 128 | 138 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
| 129 | 139 | curl_setopt($ch, CURLOPT_FILE, $fp); |
| 130 | 140 | curl_exec($ch); |
| 131 | - if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch); |
|
| 141 | + if (curl_errno($ch) && $globalDebug) { |
|
| 142 | + echo 'Download error: '.curl_error($ch); |
|
| 143 | + } |
|
| 132 | 144 | curl_close($ch); |
| 133 | 145 | fclose($fp); |
| 134 | 146 | } |
@@ -136,12 +148,16 @@ discard block |
||
| 136 | 148 | public static function gunzip($in_file,$out_file_name = '') { |
| 137 | 149 | //echo $in_file.' -> '.$out_file_name."\n"; |
| 138 | 150 | $buffer_size = 4096; // read 4kb at a time |
| 139 | - if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); |
|
| 151 | + if ($out_file_name == '') { |
|
| 152 | + $out_file_name = str_replace('.gz', '', $in_file); |
|
| 153 | + } |
|
| 140 | 154 | if ($in_file != '' && file_exists($in_file)) { |
| 141 | 155 | // PHP version of Ubuntu use gzopen64 instead of gzopen |
| 142 | - if (function_exists('gzopen')) $file = gzopen($in_file,'rb'); |
|
| 143 | - elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb'); |
|
| 144 | - else { |
|
| 156 | + if (function_exists('gzopen')) { |
|
| 157 | + $file = gzopen($in_file,'rb'); |
|
| 158 | + } elseif (function_exists('gzopen64')) { |
|
| 159 | + $file = gzopen64($in_file,'rb'); |
|
| 160 | + } else { |
|
| 145 | 161 | echo 'gzopen not available'; |
| 146 | 162 | die; |
| 147 | 163 | } |
@@ -157,11 +173,14 @@ discard block |
||
| 157 | 173 | public static function bunzip2($in_file,$out_file_name = '') { |
| 158 | 174 | //echo $in_file.' -> '.$out_file_name."\n"; |
| 159 | 175 | $buffer_size = 4096; // read 4kb at a time |
| 160 | - if ($out_file_name == '') $out_file_name = str_replace('.bz2', '', $in_file); |
|
| 176 | + if ($out_file_name == '') { |
|
| 177 | + $out_file_name = str_replace('.bz2', '', $in_file); |
|
| 178 | + } |
|
| 161 | 179 | if ($in_file != '' && file_exists($in_file)) { |
| 162 | 180 | // PHP version of Ubuntu use gzopen64 instead of gzopen |
| 163 | - if (function_exists('bzopen')) $file = bzopen($in_file,'rb'); |
|
| 164 | - else { |
|
| 181 | + if (function_exists('bzopen')) { |
|
| 182 | + $file = bzopen($in_file,'rb'); |
|
| 183 | + } else { |
|
| 165 | 184 | echo 'bzopen not available'; |
| 166 | 185 | die; |
| 167 | 186 | } |
@@ -180,10 +199,16 @@ discard block |
||
| 180 | 199 | * @return array array of the tables in HTML page |
| 181 | 200 | */ |
| 182 | 201 | public function table2array($data) { |
| 183 | - if (!is_string($data)) return array(); |
|
| 184 | - if ($data == '') return array(); |
|
| 202 | + if (!is_string($data)) { |
|
| 203 | + return array(); |
|
| 204 | + } |
|
| 205 | + if ($data == '') { |
|
| 206 | + return array(); |
|
| 207 | + } |
|
| 185 | 208 | $html = str_get_html($data); |
| 186 | - if ($html === false) return array(); |
|
| 209 | + if ($html === false) { |
|
| 210 | + return array(); |
|
| 211 | + } |
|
| 187 | 212 | $tabledata=array(); |
| 188 | 213 | foreach($html->find('tr') as $element) |
| 189 | 214 | { |
@@ -218,7 +243,9 @@ discard block |
||
| 218 | 243 | */ |
| 219 | 244 | public function text2array($data) { |
| 220 | 245 | $html = str_get_html($data); |
| 221 | - if ($html === false) return array(); |
|
| 246 | + if ($html === false) { |
|
| 247 | + return array(); |
|
| 248 | + } |
|
| 222 | 249 | $tabledata=array(); |
| 223 | 250 | foreach($html->find('p') as $element) |
| 224 | 251 | { |
@@ -239,7 +266,9 @@ discard block |
||
| 239 | 266 | * @return Float Distance in $unit |
| 240 | 267 | */ |
| 241 | 268 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 242 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
| 269 | + if ($lat == $latc && $lon == $lonc) { |
|
| 270 | + return 0; |
|
| 271 | + } |
|
| 243 | 272 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
| 244 | 273 | if ($unit == "km") { |
| 245 | 274 | return round($dist * 1.609344); |
@@ -285,7 +314,9 @@ discard block |
||
| 285 | 314 | $dX = $latc - $lat; |
| 286 | 315 | $dY = $lonc - $lon; |
| 287 | 316 | $azimuth = rad2deg(atan2($dY,$dX)); |
| 288 | - if ($azimuth < 0) return $azimuth+360; |
|
| 317 | + if ($azimuth < 0) { |
|
| 318 | + return $azimuth+360; |
|
| 319 | + } |
|
| 289 | 320 | return $azimuth; |
| 290 | 321 | } |
| 291 | 322 | |
@@ -299,10 +330,16 @@ discard block |
||
| 299 | 330 | public function withinThreshold ($timeDifference, $distance) { |
| 300 | 331 | $x = abs($timeDifference); |
| 301 | 332 | $d = abs($distance); |
| 302 | - if ($x == 0 || $d == 0) return true; |
|
| 333 | + if ($x == 0 || $d == 0) { |
|
| 334 | + return true; |
|
| 335 | + } |
|
| 303 | 336 | // may be due to Internet jitter; distance is realistic |
| 304 | - if ($x < 0.7 && $d < 2000) return true; |
|
| 305 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
| 337 | + if ($x < 0.7 && $d < 2000) { |
|
| 338 | + return true; |
|
| 339 | + } else { |
|
| 340 | + return $d/$x < 1500*0.27778; |
|
| 341 | + } |
|
| 342 | + // 1500 km/h max |
|
| 306 | 343 | } |
| 307 | 344 | |
| 308 | 345 | |
@@ -354,11 +391,17 @@ discard block |
||
| 354 | 391 | |
| 355 | 392 | public function convertDM($coord,$latlong) { |
| 356 | 393 | if ($latlong == 'latitude') { |
| 357 | - if ($coord < 0) $NSEW = 'S'; |
|
| 358 | - else $NSEW = 'N'; |
|
| 394 | + if ($coord < 0) { |
|
| 395 | + $NSEW = 'S'; |
|
| 396 | + } else { |
|
| 397 | + $NSEW = 'N'; |
|
| 398 | + } |
|
| 359 | 399 | } else { |
| 360 | - if ($coord < 0) $NSEW = 'W'; |
|
| 361 | - else $NSEW = 'E'; |
|
| 400 | + if ($coord < 0) { |
|
| 401 | + $NSEW = 'W'; |
|
| 402 | + } else { |
|
| 403 | + $NSEW = 'E'; |
|
| 404 | + } |
|
| 362 | 405 | } |
| 363 | 406 | $coord = abs($coord); |
| 364 | 407 | $deg = floor($coord); |
@@ -368,11 +411,17 @@ discard block |
||
| 368 | 411 | } |
| 369 | 412 | public function convertDMS($coord,$latlong) { |
| 370 | 413 | if ($latlong == 'latitude') { |
| 371 | - if ($coord < 0) $NSEW = 'S'; |
|
| 372 | - else $NSEW = 'N'; |
|
| 414 | + if ($coord < 0) { |
|
| 415 | + $NSEW = 'S'; |
|
| 416 | + } else { |
|
| 417 | + $NSEW = 'N'; |
|
| 418 | + } |
|
| 373 | 419 | } else { |
| 374 | - if ($coord < 0) $NSEW = 'W'; |
|
| 375 | - else $NSEW = 'E'; |
|
| 420 | + if ($coord < 0) { |
|
| 421 | + $NSEW = 'W'; |
|
| 422 | + } else { |
|
| 423 | + $NSEW = 'E'; |
|
| 424 | + } |
|
| 376 | 425 | } |
| 377 | 426 | $coord = abs($coord); |
| 378 | 427 | $deg = floor($coord); |
@@ -416,7 +465,9 @@ discard block |
||
| 416 | 465 | public function hex2str($hex) { |
| 417 | 466 | $str = ''; |
| 418 | 467 | $hexln = strlen($hex); |
| 419 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 468 | + for($i=0;$i<$hexln;$i+=2) { |
|
| 469 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 470 | + } |
|
| 420 | 471 | return $str; |
| 421 | 472 | } |
| 422 | 473 | |
@@ -453,8 +504,11 @@ discard block |
||
| 453 | 504 | $b = $lat2 - $lat1; |
| 454 | 505 | $c = -($a*$lat1+$b*$lon1); |
| 455 | 506 | $d = $a*$lat3+$b*$lon3+$c; |
| 456 | - if ($d > -$approx && $d < $approx) return true; |
|
| 457 | - else return false; |
|
| 507 | + if ($d > -$approx && $d < $approx) { |
|
| 508 | + return true; |
|
| 509 | + } else { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 458 | 512 | } |
| 459 | 513 | |
| 460 | 514 | public function array_merge_noappend() { |
@@ -513,7 +567,9 @@ discard block |
||
| 513 | 567 | return $result; |
| 514 | 568 | } |
| 515 | 569 | $handle = @opendir('./locale'); |
| 516 | - if ($handle === false) return $result; |
|
| 570 | + if ($handle === false) { |
|
| 571 | + return $result; |
|
| 572 | + } |
|
| 517 | 573 | while (false !== ($file = readdir($handle))) { |
| 518 | 574 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
| 519 | 575 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -584,8 +640,9 @@ discard block |
||
| 584 | 640 | $error = false; |
| 585 | 641 | if ($fp_out = gzopen($dest, $mode)) { |
| 586 | 642 | if ($fp_in = fopen($source,'rb')) { |
| 587 | - while (!feof($fp_in)) |
|
| 588 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 643 | + while (!feof($fp_in)) { |
|
| 644 | + gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 645 | + } |
|
| 589 | 646 | fclose($fp_in); |
| 590 | 647 | } else { |
| 591 | 648 | $error = true; |
@@ -594,14 +651,17 @@ discard block |
||
| 594 | 651 | } else { |
| 595 | 652 | $error = true; |
| 596 | 653 | } |
| 597 | - if ($error) |
|
| 598 | - return false; |
|
| 599 | - else |
|
| 600 | - return $dest; |
|
| 654 | + if ($error) { |
|
| 655 | + return false; |
|
| 656 | + } else { |
|
| 657 | + return $dest; |
|
| 658 | + } |
|
| 601 | 659 | } |
| 602 | 660 | |
| 603 | 661 | public function remove_accents($string) { |
| 604 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
| 662 | + if ( !preg_match('/[\x80-\xff]/', $string) ) { |
|
| 663 | + return $string; |
|
| 664 | + } |
|
| 605 | 665 | $chars = array( |
| 606 | 666 | // Decompositions for Latin-1 Supplement |
| 607 | 667 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -725,7 +785,9 @@ discard block |
||
| 725 | 785 | $ip = gethostbyname($host); |
| 726 | 786 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
| 727 | 787 | $r = @socket_connect($s, $ip, $port); |
| 728 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
| 788 | + if (!socket_set_nonblock($s)) { |
|
| 789 | + echo "Unable to set nonblock on socket\n"; |
|
| 790 | + } |
|
| 729 | 791 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
| 730 | 792 | return $s; |
| 731 | 793 | } |
@@ -770,18 +832,22 @@ discard block |
||
| 770 | 832 | //NOTE: use a trailing slash for folders!!! |
| 771 | 833 | //see http://bugs.php.net/bug.php?id=27609 |
| 772 | 834 | //see http://bugs.php.net/bug.php?id=30931 |
| 773 | - if ($path{strlen($path)-1}=='/') // recursively return a temporary file path |
|
| 835 | + if ($path{strlen($path)-1}=='/') { |
|
| 836 | + // recursively return a temporary file path |
|
| 774 | 837 | return $this->is__writable($path.uniqid(mt_rand()).'.tmp'); |
| 775 | - else if (is_dir($path)) |
|
| 776 | - return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp'); |
|
| 838 | + } else if (is_dir($path)) { |
|
| 839 | + return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp'); |
|
| 840 | + } |
|
| 777 | 841 | // check tmp file for read/write capabilities |
| 778 | 842 | $rm = file_exists($path); |
| 779 | 843 | $f = @fopen($path, 'a'); |
| 780 | - if ($f===false) |
|
| 781 | - return false; |
|
| 844 | + if ($f===false) { |
|
| 845 | + return false; |
|
| 846 | + } |
|
| 782 | 847 | fclose($f); |
| 783 | - if (!$rm) |
|
| 784 | - unlink($path); |
|
| 848 | + if (!$rm) { |
|
| 849 | + unlink($path); |
|
| 850 | + } |
|
| 785 | 851 | return true; |
| 786 | 852 | } |
| 787 | 853 | |
@@ -797,7 +863,9 @@ discard block |
||
| 797 | 863 | * @return Array Coordinate of the route |
| 798 | 864 | */ |
| 799 | 865 | public function greatcircle($begin_lat,$begin_lon,$end_lat,$end_lon,$nbpts = 20, $offset = 10) { |
| 800 | - if ($nbpts <= 2) return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 866 | + if ($nbpts <= 2) { |
|
| 867 | + return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 868 | + } |
|
| 801 | 869 | $sx = deg2rad($begin_lon); |
| 802 | 870 | $sy = deg2rad($begin_lat); |
| 803 | 871 | $ex = deg2rad($end_lon); |
@@ -806,7 +874,9 @@ discard block |
||
| 806 | 874 | $h = $sy - $ey; |
| 807 | 875 | $z = pow(sin($h/2.0),2) + cos($sy)*cos($ey)*pow(sin($w/2.0),2); |
| 808 | 876 | $g = 2.0*asin(sqrt($z)); |
| 809 | - if ($g == M_PI || is_nan($g)) return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 877 | + if ($g == M_PI || is_nan($g)) { |
|
| 878 | + return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 879 | + } |
|
| 810 | 880 | $first_pass = array(); |
| 811 | 881 | $delta = 1.0/($nbpts-1); |
| 812 | 882 | for ($i =0; $i < $nbpts; ++$i) { |
@@ -18,7 +18,9 @@ discard block |
||
| 18 | 18 | public function __construct($dbc = null) { |
| 19 | 19 | $Connection = new Connection($dbc); |
| 20 | 20 | $this->db = $Connection->db; |
| 21 | - if ($this->db === null) die('Error: No DB connection. (ATC)'); |
|
| 21 | + if ($this->db === null) { |
|
| 22 | + die('Error: No DB connection. (ATC)'); |
|
| 23 | + } |
|
| 22 | 24 | } |
| 23 | 25 | |
| 24 | 26 | /** |
@@ -33,20 +35,27 @@ discard block |
||
| 33 | 35 | if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { |
| 34 | 36 | if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { |
| 35 | 37 | foreach($globalStatsFilters[$globalFilterName] as $source) { |
| 36 | - if (isset($source['source'])) $filter['source'][] = $source['source']; |
|
| 38 | + if (isset($source['source'])) { |
|
| 39 | + $filter['source'][] = $source['source']; |
|
| 40 | + } |
|
| 37 | 41 | } |
| 38 | 42 | } else { |
| 39 | 43 | $filter = $globalStatsFilters[$globalFilterName]; |
| 40 | 44 | } |
| 41 | 45 | } |
| 42 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
| 46 | + if (is_array($globalFilter)) { |
|
| 47 | + $filter = array_merge($filter,$globalFilter); |
|
| 48 | + } |
|
| 43 | 49 | $filter_query_join = ''; |
| 44 | 50 | $filter_query_where = ''; |
| 45 | 51 | if (isset($filter['source']) && !empty($filter['source'])) { |
| 46 | 52 | $filter_query_where = " WHERE format_source IN ('".implode("','",$filter['source'])."')"; |
| 47 | 53 | } |
| 48 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
| 49 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
| 54 | + if ($filter_query_where == '' && $where) { |
|
| 55 | + $filter_query_where = ' WHERE'; |
|
| 56 | + } elseif ($filter_query_where != '' && $and) { |
|
| 57 | + $filter_query_where .= ' AND'; |
|
| 58 | + } |
|
| 50 | 59 | $filter_query = $filter_query_join.$filter_query_where; |
| 51 | 60 | return $filter_query; |
| 52 | 61 | } |
@@ -133,7 +142,9 @@ discard block |
||
| 133 | 142 | $info = str_replace('^','<br />',$info); |
| 134 | 143 | $info = str_replace('&sect;','',$info); |
| 135 | 144 | $info = str_replace('"','',$info); |
| 136 | - if ($type == '') $type = NULL; |
|
| 145 | + if ($type == '') { |
|
| 146 | + $type = NULL; |
|
| 147 | + } |
|
| 137 | 148 | $query = "INSERT INTO atc (ident,frequency,latitude,longitude,atc_range,info,atc_lastseen,type,ivao_id,ivao_name,format_source,source_name) VALUES (:ident,:frequency,:latitude,:longitude,:range,:info,:date,:type,:ivao_id,:ivao_name,:format_source,:source_name)"; |
| 138 | 149 | $query_values = array(':ident' => $ident,':frequency' => $frequency,':latitude' => $latitude,':longitude' => $longitude,':range' => $range,':info' => $info,':date' => $date,':ivao_id' => $ivao_id,':ivao_name' => $ivao_name, ':type' => $type,':format_source' => $format_source,':source_name' => $source_name); |
| 139 | 150 | try { |
@@ -164,7 +175,9 @@ discard block |
||
| 164 | 175 | $info = str_replace('^','<br />',$info); |
| 165 | 176 | $info = str_replace('&sect;','',$info); |
| 166 | 177 | $info = str_replace('"','',$info); |
| 167 | - if ($type == '') $type = NULL; |
|
| 178 | + if ($type == '') { |
|
| 179 | + $type = NULL; |
|
| 180 | + } |
|
| 168 | 181 | $query = "UPDATE atc SET frequency = :frequency,latitude = :latitude,longitude = :longitude,atc_range = :range,info = :info,atc_lastseen = :date,type = :type,ivao_id = :ivao_id,ivao_name = :ivao_name WHERE ident = :ident AND format_source = :format_source AND source_name = :source_name"; |
| 169 | 182 | $query_values = array(':ident' => $ident,':frequency' => $frequency,':latitude' => $latitude,':longitude' => $longitude,':range' => $range,':info' => $info,':date' => $date,':ivao_id' => $ivao_id,':ivao_name' => $ivao_name, ':type' => $type,':format_source' => $format_source,':source_name' => $source_name); |
| 170 | 183 | try { |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | public function __construct($dbc = null) { |
| 14 | 14 | $Connection = new Connection($dbc); |
| 15 | 15 | $this->db = $Connection->db; |
| 16 | - if ($this->db === null) die('Error: No DB connection. (MarineArchive)'); |
|
| 16 | + if ($this->db === null) { |
|
| 17 | + die('Error: No DB connection. (MarineArchive)'); |
|
| 18 | + } |
|
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | /** |
@@ -36,7 +38,9 @@ discard block |
||
| 36 | 38 | if (isset($filter[0]['source'])) { |
| 37 | 39 | $filters = array_merge($filters,$filter); |
| 38 | 40 | } |
| 39 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
| 41 | + if (is_array($globalFilter)) { |
|
| 42 | + $filter = array_merge($filter,$globalFilter); |
|
| 43 | + } |
|
| 40 | 44 | $filter_query_join = ''; |
| 41 | 45 | $filter_query_where = ''; |
| 42 | 46 | foreach($filters as $flt) { |
@@ -82,8 +86,11 @@ discard block |
||
| 82 | 86 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 83 | 87 | $filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
| 84 | 88 | } |
| 85 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
| 86 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
| 89 | + if ($filter_query_where == '' && $where) { |
|
| 90 | + $filter_query_where = ' WHERE'; |
|
| 91 | + } elseif ($filter_query_where != '' && $and) { |
|
| 92 | + $filter_query_where .= ' AND'; |
|
| 93 | + } |
|
| 87 | 94 | if ($filter_query_where != '') { |
| 88 | 95 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
| 89 | 96 | } |
@@ -129,9 +136,14 @@ discard block |
||
| 129 | 136 | if ($over_country == '') { |
| 130 | 137 | $Marine = new Marine($this->db); |
| 131 | 138 | $data_country = $Marine->getCountryFromLatitudeLongitude($latitude,$longitude); |
| 132 | - if (!empty($data_country)) $country = $data_country['iso2']; |
|
| 133 | - else $country = ''; |
|
| 134 | - } else $country = $over_country; |
|
| 139 | + if (!empty($data_country)) { |
|
| 140 | + $country = $data_country['iso2']; |
|
| 141 | + } else { |
|
| 142 | + $country = ''; |
|
| 143 | + } |
|
| 144 | + } else { |
|
| 145 | + $country = $over_country; |
|
| 146 | + } |
|
| 135 | 147 | |
| 136 | 148 | //$country = $over_country; |
| 137 | 149 | // Route is not added in marine_archive |
@@ -661,7 +673,9 @@ discard block |
||
| 661 | 673 | $additional_query .= "(marine_archive_output.pilot_name like '%".$q_item."%') OR "; |
| 662 | 674 | $additional_query .= "(marine_archive_output.ident like '%".$q_item."%') OR "; |
| 663 | 675 | $translate = $Translation->ident2icao($q_item); |
| 664 | - if ($translate != $q_item) $additional_query .= "(marine_archive_output.ident like '%".$translate."%') OR "; |
|
| 676 | + if ($translate != $q_item) { |
|
| 677 | + $additional_query .= "(marine_archive_output.ident like '%".$translate."%') OR "; |
|
| 678 | + } |
|
| 665 | 679 | $additional_query .= "(marine_archive_output.highlight like '%".$q_item."%')"; |
| 666 | 680 | $additional_query .= ")"; |
| 667 | 681 | } |
@@ -879,7 +893,9 @@ discard block |
||
| 879 | 893 | date_default_timezone_set($globalTimezone); |
| 880 | 894 | $datetime = new DateTime(); |
| 881 | 895 | $offset = $datetime->format('P'); |
| 882 | - } else $offset = '+00:00'; |
|
| 896 | + } else { |
|
| 897 | + $offset = '+00:00'; |
|
| 898 | + } |
|
| 883 | 899 | |
| 884 | 900 | |
| 885 | 901 | if ($date_array[1] != "") |
@@ -1165,9 +1181,13 @@ discard block |
||
| 1165 | 1181 | $query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
| 1166 | 1182 | } |
| 1167 | 1183 | } |
| 1168 | - if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
|
| 1184 | + if ($sincedate != '') { |
|
| 1185 | + $query .= "AND date > '".$sincedate."' "; |
|
| 1186 | + } |
|
| 1169 | 1187 | $query .= "GROUP BY c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
| 1170 | - if ($limit) $query .= " LIMIT 0,10"; |
|
| 1188 | + if ($limit) { |
|
| 1189 | + $query .= " LIMIT 0,10"; |
|
| 1190 | + } |
|
| 1171 | 1191 | |
| 1172 | 1192 | |
| 1173 | 1193 | $sth = $this->db->prepare($query); |
@@ -1213,9 +1233,13 @@ discard block |
||
| 1213 | 1233 | $query .= "AND s.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
| 1214 | 1234 | } |
| 1215 | 1235 | } |
| 1216 | - if ($sincedate != '') $query .= "AND s.date > '".$sincedate."' "; |
|
| 1236 | + if ($sincedate != '') { |
|
| 1237 | + $query .= "AND s.date > '".$sincedate."' "; |
|
| 1238 | + } |
|
| 1217 | 1239 | $query .= "GROUP BY o.airline_icao,c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
| 1218 | - if ($limit) $query .= " LIMIT 0,10"; |
|
| 1240 | + if ($limit) { |
|
| 1241 | + $query .= " LIMIT 0,10"; |
|
| 1242 | + } |
|
| 1219 | 1243 | |
| 1220 | 1244 | |
| 1221 | 1245 | $sth = $this->db->prepare($query); |
@@ -59,7 +59,9 @@ discard block |
||
| 59 | 59 | try { |
| 60 | 60 | $GeoidClass = new GeoidHeight(); |
| 61 | 61 | } catch(Exception $e) { |
| 62 | - if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n"; |
|
| 62 | + if ($globalDebug) { |
|
| 63 | + echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n"; |
|
| 64 | + } |
|
| 63 | 65 | $GeoidClass = FALSE; |
| 64 | 66 | } |
| 65 | 67 | } |
@@ -78,7 +80,9 @@ discard block |
||
| 78 | 80 | $dbc = $this->db; |
| 79 | 81 | $this->all_flights[$id]['schedule_check'] = true; |
| 80 | 82 | if ($globalSchedulesFetch) { |
| 81 | - if ($globalDebug) echo 'Getting schedule info...'."\n"; |
|
| 83 | + if ($globalDebug) { |
|
| 84 | + echo 'Getting schedule info...'."\n"; |
|
| 85 | + } |
|
| 82 | 86 | $Spotter = new Spotter($dbc); |
| 83 | 87 | $Schedule = new Schedule($dbc); |
| 84 | 88 | $Translation = new Translation($dbc); |
@@ -89,7 +93,9 @@ discard block |
||
| 89 | 93 | if ($Schedule->checkSchedule($operator) == 0) { |
| 90 | 94 | $schedule = $Schedule->fetchSchedule($operator); |
| 91 | 95 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 92 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 96 | + if ($globalDebug) { |
|
| 97 | + echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 98 | + } |
|
| 93 | 99 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
| 94 | 100 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
| 95 | 101 | // Should also check if route schedule = route from DB |
@@ -98,7 +104,9 @@ discard block |
||
| 98 | 104 | $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
| 99 | 105 | if (trim($airport_icao) != '') { |
| 100 | 106 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
| 101 | - if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
| 107 | + if ($globalDebug) { |
|
| 108 | + echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
| 109 | + } |
|
| 102 | 110 | } |
| 103 | 111 | } |
| 104 | 112 | } |
@@ -107,20 +115,30 @@ discard block |
||
| 107 | 115 | $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
| 108 | 116 | if (trim($airport_icao) != '') { |
| 109 | 117 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
| 110 | - if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
| 118 | + if ($globalDebug) { |
|
| 119 | + echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
| 120 | + } |
|
| 111 | 121 | } |
| 112 | 122 | } |
| 113 | 123 | } |
| 114 | 124 | $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
| 115 | 125 | } |
| 116 | - } else $scheduleexist = true; |
|
| 117 | - } else $scheduleexist = true; |
|
| 126 | + } else { |
|
| 127 | + $scheduleexist = true; |
|
| 128 | + } |
|
| 129 | + } else { |
|
| 130 | + $scheduleexist = true; |
|
| 131 | + } |
|
| 118 | 132 | // close connection, at least one way will work ? |
| 119 | 133 | if ($scheduleexist) { |
| 120 | - if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
| 134 | + if ($globalDebug) { |
|
| 135 | + echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
| 136 | + } |
|
| 121 | 137 | $sch = $Schedule->getSchedule($operator); |
| 122 | 138 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
| 123 | - if ($this->all_flights[$id]['addedSpotter'] == 1) $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']); |
|
| 139 | + if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
| 140 | + $Spotter->updateLatestScheduleSpotterData($this->all_flights[$id]['id'],$sch['departure_airport_icao'],$sch['departure_airport_time'],$sch['arrival_airport_icao'],$sch['arrival_airport_time']); |
|
| 141 | + } |
|
| 124 | 142 | } |
| 125 | 143 | $Spotter->db = null; |
| 126 | 144 | $Schedule->db = null; |
@@ -140,14 +158,18 @@ discard block |
||
| 140 | 158 | |
| 141 | 159 | public function checkAll() { |
| 142 | 160 | global $globalDebug, $globalNoImport; |
| 143 | - if ($globalDebug) echo "Update last seen flights data...\n"; |
|
| 161 | + if ($globalDebug) { |
|
| 162 | + echo "Update last seen flights data...\n"; |
|
| 163 | + } |
|
| 144 | 164 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 145 | 165 | foreach ($this->all_flights as $key => $flight) { |
| 146 | 166 | if (isset($this->all_flights[$key]['id'])) { |
| 147 | 167 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
| 148 | 168 | $Spotter = new Spotter($this->db); |
| 149 | 169 | $real_arrival = $this->arrival($key); |
| 150 | - if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 170 | + if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) { |
|
| 171 | + $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 172 | + } |
|
| 151 | 173 | } |
| 152 | 174 | } |
| 153 | 175 | } |
@@ -155,24 +177,32 @@ discard block |
||
| 155 | 177 | |
| 156 | 178 | public function arrival($key) { |
| 157 | 179 | global $globalClosestMinDist, $globalDebug; |
| 158 | - if ($globalDebug) echo 'Update arrival...'."\n"; |
|
| 180 | + if ($globalDebug) { |
|
| 181 | + echo 'Update arrival...'."\n"; |
|
| 182 | + } |
|
| 159 | 183 | $Spotter = new Spotter($this->db); |
| 160 | 184 | $airport_icao = ''; |
| 161 | 185 | $airport_time = ''; |
| 162 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 186 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') { |
|
| 187 | + $globalClosestMinDist = 50; |
|
| 188 | + } |
|
| 163 | 189 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 164 | 190 | $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
| 165 | 191 | if (isset($closestAirports[0])) { |
| 166 | 192 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
| 167 | 193 | $airport_icao = $closestAirports[0]['icao']; |
| 168 | 194 | $airport_time = $this->all_flights[$key]['datetime']; |
| 169 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 195 | + if ($globalDebug) { |
|
| 196 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 197 | + } |
|
| 170 | 198 | } elseif (count($closestAirports) > 1 && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
| 171 | 199 | foreach ($closestAirports as $airport) { |
| 172 | 200 | if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
| 173 | 201 | $airport_icao = $airport['icao']; |
| 174 | 202 | $airport_time = $this->all_flights[$key]['datetime']; |
| 175 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 203 | + if ($globalDebug) { |
|
| 204 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 205 | + } |
|
| 176 | 206 | break; |
| 177 | 207 | } |
| 178 | 208 | } |
@@ -180,14 +210,20 @@ discard block |
||
| 180 | 210 | $airport_icao = $closestAirports[0]['icao']; |
| 181 | 211 | $airport_time = $this->all_flights[$key]['datetime']; |
| 182 | 212 | } else { |
| 183 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 213 | + if ($globalDebug) { |
|
| 214 | + echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 215 | + } |
|
| 184 | 216 | } |
| 185 | 217 | } else { |
| 186 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 218 | + if ($globalDebug) { |
|
| 219 | + echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 220 | + } |
|
| 187 | 221 | } |
| 188 | 222 | |
| 189 | 223 | } else { |
| 190 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 224 | + if ($globalDebug) { |
|
| 225 | + echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 226 | + } |
|
| 191 | 227 | } |
| 192 | 228 | return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
| 193 | 229 | } |
@@ -197,7 +233,9 @@ discard block |
||
| 197 | 233 | public function del() { |
| 198 | 234 | global $globalDebug, $globalNoImport, $globalNoDB; |
| 199 | 235 | // Delete old infos |
| 200 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
| 236 | + if ($globalDebug) { |
|
| 237 | + echo 'Delete old values and update latest data...'."\n"; |
|
| 238 | + } |
|
| 201 | 239 | |
| 202 | 240 | foreach ($this->all_flights as $key => $flight) { |
| 203 | 241 | if (isset($flight['lastupdate'])) { |
@@ -212,22 +250,30 @@ discard block |
||
| 212 | 250 | global $globalDebug, $globalNoImport, $globalNoDB; |
| 213 | 251 | // Delete old infos |
| 214 | 252 | if (isset($this->all_flights[$key]['id'])) { |
| 215 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 253 | + if ($globalDebug) { |
|
| 254 | + echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 255 | + } |
|
| 216 | 256 | if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
| 217 | 257 | $real_arrival = $this->arrival($key); |
| 218 | 258 | $Spotter = new Spotter($this->db); |
| 219 | 259 | $SpotterLive = new SpotterLive($this->db); |
| 220 | 260 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 221 | 261 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
| 222 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 262 | + if ($globalDebug && $result != 'success') { |
|
| 263 | + echo '!!! ERROR : '.$result."\n"; |
|
| 264 | + } |
|
| 223 | 265 | $this->all_flights[$key]['putinarchive'] = true; |
| 224 | 266 | $result = $SpotterLive->addLiveSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['aircraft_icao'], $this->all_flights[$key]['departure_airport'], $this->all_flights[$key]['arrival_airport'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['waypoints'], $this->all_flights[$key]['altitude'],$this->all_flights[$key]['altitude_real'], $this->all_flights[$key]['heading'], $this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'], $this->all_flights[$key]['departure_airport_time'], $this->all_flights[$key]['arrival_airport_time'], $this->all_flights[$key]['squawk'],$this->all_flights[$key]['route_stop'],$this->all_flights[$key]['hex'],$this->all_flights[$key]['putinarchive'],$this->all_flights[$key]['registration'],$this->all_flights[$key]['pilot_id'],$this->all_flights[$key]['pilot_name'], $this->all_flights[$key]['verticalrate'], $this->all_flights[$key]['noarchive'], $this->all_flights[$key]['ground'],$this->all_flights[$key]['format_source'],$this->all_flights[$key]['source_name'],$this->all_flights[$key]['over_country']); |
| 225 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 267 | + if ($globalDebug && $result != 'success') { |
|
| 268 | + echo '!!! ERROR : '.$result."\n"; |
|
| 269 | + } |
|
| 226 | 270 | } |
| 227 | 271 | $Spotter->db = null; |
| 228 | 272 | $SpotterLive->db = null; |
| 229 | 273 | } |
| 230 | - if ($globalDebug) echo "\n"; |
|
| 274 | + if ($globalDebug) { |
|
| 275 | + echo "\n"; |
|
| 276 | + } |
|
| 231 | 277 | } |
| 232 | 278 | unset($this->all_flights[$key]); |
| 233 | 279 | } |
@@ -235,9 +281,13 @@ discard block |
||
| 235 | 281 | public function add($line) { |
| 236 | 282 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval, $GeoidClass, $globalArchive; |
| 237 | 283 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
| 238 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.01'; |
|
| 239 | - if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000; |
|
| 240 | -/* |
|
| 284 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
| 285 | + $globalCoordMinChange = '0.01'; |
|
| 286 | + } |
|
| 287 | + if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') { |
|
| 288 | + $globalAircraftMaxUpdate = 3000; |
|
| 289 | + } |
|
| 290 | + /* |
|
| 241 | 291 | $Spotter = new Spotter(); |
| 242 | 292 | $dbc = $Spotter->db; |
| 243 | 293 | $SpotterLive = new SpotterLive($dbc); |
@@ -259,19 +309,28 @@ discard block |
||
| 259 | 309 | // SBS format is CSV format |
| 260 | 310 | if(is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
| 261 | 311 | //print_r($line); |
| 262 | - if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']); |
|
| 312 | + if (isset($line['hex'])) { |
|
| 313 | + $line['hex'] = strtoupper($line['hex']); |
|
| 314 | + } |
|
| 263 | 315 | if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && substr($line['hex'],0,1) != '~' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { |
| 264 | 316 | |
| 265 | 317 | // Increment message number |
| 266 | 318 | if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) { |
| 267 | 319 | $current_date = date('Y-m-d'); |
| 268 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
| 269 | - else $source = ''; |
|
| 270 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 320 | + if (isset($line['source_name'])) { |
|
| 321 | + $source = $line['source_name']; |
|
| 322 | + } else { |
|
| 323 | + $source = ''; |
|
| 324 | + } |
|
| 325 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
| 326 | + $source = $line['format_source']; |
|
| 327 | + } |
|
| 271 | 328 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
| 272 | 329 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
| 273 | 330 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
| 274 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 331 | + } else { |
|
| 332 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 333 | + } |
|
| 275 | 334 | } |
| 276 | 335 | |
| 277 | 336 | /* |
@@ -287,23 +346,38 @@ discard block |
||
| 287 | 346 | //$this->db = $dbc; |
| 288 | 347 | |
| 289 | 348 | //$hex = trim($line['hex']); |
| 290 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 291 | - else $id = trim($line['id']); |
|
| 349 | + if (!isset($line['id'])) { |
|
| 350 | + $id = trim($line['hex']); |
|
| 351 | + } else { |
|
| 352 | + $id = trim($line['id']); |
|
| 353 | + } |
|
| 292 | 354 | |
| 293 | 355 | if (!isset($this->all_flights[$id])) { |
| 294 | - if ($globalDebug) echo 'New flight...'."\n"; |
|
| 356 | + if ($globalDebug) { |
|
| 357 | + echo 'New flight...'."\n"; |
|
| 358 | + } |
|
| 295 | 359 | $this->all_flights[$id] = array(); |
| 296 | 360 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 297 | 361 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '','coordinates' => 0)); |
| 298 | - if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 362 | + if (isset($globalDaemon) && $globalDaemon === FALSE) { |
|
| 363 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 364 | + } |
|
| 299 | 365 | if (!isset($line['id'])) { |
| 300 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
| 301 | -// if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
| 366 | + if (!isset($globalDaemon)) { |
|
| 367 | + $globalDaemon = TRUE; |
|
| 368 | + } |
|
| 369 | + // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
| 302 | 370 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
| 303 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 371 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 372 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 373 | + } |
|
| 304 | 374 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 305 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 306 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 375 | + } else { |
|
| 376 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 377 | + } |
|
| 378 | + if ($globalAllFlights !== FALSE) { |
|
| 379 | + $dataFound = true; |
|
| 380 | + } |
|
| 307 | 381 | } |
| 308 | 382 | if (isset($line['source_type']) && $line['source_type'] != '') { |
| 309 | 383 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
@@ -325,12 +399,20 @@ discard block |
||
| 325 | 399 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
| 326 | 400 | } |
| 327 | 401 | $Spotter->db = null; |
| 328 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 329 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 402 | + if ($globalDebugTimeElapsed) { |
|
| 403 | + echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 404 | + } |
|
| 405 | + if ($aircraft_icao != '') { |
|
| 406 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 407 | + } |
|
| 330 | 408 | } |
| 331 | 409 | } |
| 332 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 333 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
| 410 | + if ($globalAllFlights !== FALSE) { |
|
| 411 | + $dataFound = true; |
|
| 412 | + } |
|
| 413 | + if ($globalDebug) { |
|
| 414 | + echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
| 415 | + } |
|
| 334 | 416 | } |
| 335 | 417 | if (isset($line['id']) && !isset($line['hex'])) { |
| 336 | 418 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => '')); |
@@ -339,7 +421,9 @@ discard block |
||
| 339 | 421 | $icao = $line['aircraft_icao']; |
| 340 | 422 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 341 | 423 | $Spotter = new Spotter($this->db); |
| 342 | - if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao]; |
|
| 424 | + if (isset($Spotter->aircraft_correct_icaotype[$icao])) { |
|
| 425 | + $icao = $Spotter->aircraft_correct_icaotype[$icao]; |
|
| 426 | + } |
|
| 343 | 427 | $Spotter->db = null; |
| 344 | 428 | } |
| 345 | 429 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao)); |
@@ -349,15 +433,24 @@ discard block |
||
| 349 | 433 | $Spotter = new Spotter($this->db); |
| 350 | 434 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
| 351 | 435 | $Spotter->db = null; |
| 352 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 436 | + if ($aircraft_icao != '') { |
|
| 437 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 438 | + } |
|
| 353 | 439 | } |
| 354 | 440 | } |
| 355 | 441 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { |
| 356 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
| 357 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
| 358 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
| 359 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
| 360 | - if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 442 | + if ($line['aircraft_type'] == 'PARA_GLIDER') { |
|
| 443 | + $aircraft_icao = 'GLID'; |
|
| 444 | + } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') { |
|
| 445 | + $aircraft_icao = 'UHEL'; |
|
| 446 | + } elseif ($line['aircraft_type'] == 'TOW_PLANE') { |
|
| 447 | + $aircraft_icao = 'TOWPLANE'; |
|
| 448 | + } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') { |
|
| 449 | + $aircraft_icao = 'POWAIRC'; |
|
| 450 | + } |
|
| 451 | + if (isset($aircraft_icao)) { |
|
| 452 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 453 | + } |
|
| 361 | 454 | } |
| 362 | 455 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
| 363 | 456 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
@@ -367,8 +460,11 @@ discard block |
||
| 367 | 460 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
| 368 | 461 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 369 | 462 | } else { |
| 370 | - if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 371 | - elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 463 | + if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
| 464 | + echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 465 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
| 466 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 467 | + } |
|
| 372 | 468 | /* |
| 373 | 469 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']); |
| 374 | 470 | print_r($this->all_flights[$id]); |
@@ -377,16 +473,22 @@ discard block |
||
| 377 | 473 | return ''; |
| 378 | 474 | } |
| 379 | 475 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
| 380 | - if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n"; |
|
| 476 | + if ($globalDebug) { |
|
| 477 | + echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n"; |
|
| 478 | + } |
|
| 381 | 479 | return ''; |
| 382 | 480 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) { |
| 383 | - if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n"; |
|
| 481 | + if ($globalDebug) { |
|
| 482 | + echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!\n"; |
|
| 483 | + } |
|
| 384 | 484 | return ''; |
| 385 | 485 | } elseif (!isset($line['datetime'])) { |
| 386 | 486 | date_default_timezone_set('UTC'); |
| 387 | 487 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
| 388 | 488 | } else { |
| 389 | - if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!"; |
|
| 489 | + if ($globalDebug) { |
|
| 490 | + echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!"; |
|
| 491 | + } |
|
| 390 | 492 | return ''; |
| 391 | 493 | } |
| 392 | 494 | |
@@ -407,30 +509,48 @@ discard block |
||
| 407 | 509 | |
| 408 | 510 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
| 409 | 511 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 410 | - if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n"; |
|
| 512 | + if ($globalDebug) { |
|
| 513 | + echo '---!!!! New ident, reset aircraft data...'."\n"; |
|
| 514 | + } |
|
| 411 | 515 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 412 | 516 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 413 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 414 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 415 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 517 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 518 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 519 | + } elseif (isset($line['id'])) { |
|
| 520 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 521 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 522 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 523 | + } |
|
| 416 | 524 | } else { |
| 417 | 525 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
| 418 | 526 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 419 | 527 | $timeelapsed = microtime(true); |
| 420 | 528 | $Spotter = new Spotter($this->db); |
| 421 | 529 | $fromsource = NULL; |
| 422 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 423 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 424 | - elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
|
| 425 | - elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
|
| 426 | - elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
|
| 530 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') { |
|
| 531 | + $fromsource = $globalAirlinesSource; |
|
| 532 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') { |
|
| 533 | + $fromsource = 'vatsim'; |
|
| 534 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') { |
|
| 535 | + $fromsource = 'ivao'; |
|
| 536 | + } elseif (isset($globalVATSIM) && $globalVATSIM) { |
|
| 537 | + $fromsource = 'vatsim'; |
|
| 538 | + } elseif (isset($globalIVAO) && $globalIVAO) { |
|
| 539 | + $fromsource = 'ivao'; |
|
| 540 | + } |
|
| 427 | 541 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource,$this->all_flights[$id]['source_type']); |
| 428 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 542 | + if ($globalDebug && $result != 'success') { |
|
| 543 | + echo '!!! ERROR : '.$result."\n"; |
|
| 544 | + } |
|
| 429 | 545 | $Spotter->db = null; |
| 430 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 546 | + if ($globalDebugTimeElapsed) { |
|
| 547 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 548 | + } |
|
| 431 | 549 | } |
| 432 | 550 | } |
| 433 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 551 | + } else { |
|
| 552 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 553 | + } |
|
| 434 | 554 | |
| 435 | 555 | /* |
| 436 | 556 | if (!isset($line['id'])) { |
@@ -440,7 +560,9 @@ discard block |
||
| 440 | 560 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 441 | 561 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 442 | 562 | */ |
| 443 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 563 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 564 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 565 | + } |
|
| 444 | 566 | |
| 445 | 567 | //$putinarchive = true; |
| 446 | 568 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
@@ -458,7 +580,9 @@ discard block |
||
| 458 | 580 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 459 | 581 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 460 | 582 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
| 461 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 583 | + if ($globalDebugTimeElapsed) { |
|
| 584 | + echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 585 | + } |
|
| 462 | 586 | } |
| 463 | 587 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
| 464 | 588 | $timeelapsed = microtime(true); |
@@ -472,7 +596,9 @@ discard block |
||
| 472 | 596 | $Translation->db = null; |
| 473 | 597 | } |
| 474 | 598 | $Spotter->db = null; |
| 475 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 599 | + if ($globalDebugTimeElapsed) { |
|
| 600 | + echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 601 | + } |
|
| 476 | 602 | } |
| 477 | 603 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 478 | 604 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
@@ -481,9 +607,13 @@ discard block |
||
| 481 | 607 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
| 482 | 608 | } |
| 483 | 609 | } |
| 484 | - if (!isset($globalFork)) $globalFork = TRUE; |
|
| 610 | + if (!isset($globalFork)) { |
|
| 611 | + $globalFork = TRUE; |
|
| 612 | + } |
|
| 485 | 613 | if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 486 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
| 614 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) { |
|
| 615 | + $this->get_Schedule($id,trim($line['ident'])); |
|
| 616 | + } |
|
| 487 | 617 | } |
| 488 | 618 | } |
| 489 | 619 | } |
@@ -501,9 +631,13 @@ discard block |
||
| 501 | 631 | $speed = $speed*3.6; |
| 502 | 632 | if ($speed < 1000) { |
| 503 | 633 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
| 504 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
|
| 634 | + if ($globalDebug) { |
|
| 635 | + echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
|
| 636 | + } |
|
| 505 | 637 | } else { |
| 506 | - if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
|
| 638 | + if ($globalDebug) { |
|
| 639 | + echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
|
| 640 | + } |
|
| 507 | 641 | } |
| 508 | 642 | } |
| 509 | 643 | } |
@@ -512,13 +646,21 @@ discard block |
||
| 512 | 646 | |
| 513 | 647 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 514 | 648 | if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) { |
| 515 | - if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
|
| 649 | + if ($globalDebug) { |
|
| 650 | + echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
|
| 651 | + } |
|
| 516 | 652 | return false; |
| 517 | 653 | } |
| 518 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 519 | - else unset($timediff); |
|
| 520 | - if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 521 | - else unset($timediff_archive); |
|
| 654 | + if (isset($this->all_flights[$id]['time_last_coord'])) { |
|
| 655 | + $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 656 | + } else { |
|
| 657 | + unset($timediff); |
|
| 658 | + } |
|
| 659 | + if (isset($this->all_flights[$id]['time_last_archive_coord'])) { |
|
| 660 | + $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 661 | + } else { |
|
| 662 | + unset($timediff_archive); |
|
| 663 | + } |
|
| 522 | 664 | if ($this->tmd > 5 |
| 523 | 665 | || (isset($line['format_source']) |
| 524 | 666 | && $line['format_source'] == 'airwhere' |
@@ -554,21 +696,32 @@ discard block |
||
| 554 | 696 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 555 | 697 | $this->all_flights[$id]['putinarchive'] = true; |
| 556 | 698 | if ($this->tmd > 5 && $this->all_flights[$id]['putinarchive'] == true) { |
| 557 | - if ($globalDebug) echo "\n".' Update Initial data ! '."\n"; |
|
| 699 | + if ($globalDebug) { |
|
| 700 | + echo "\n".' Update Initial data ! '."\n"; |
|
| 701 | + } |
|
| 558 | 702 | $updateinitial = true; |
| 559 | 703 | } |
| 560 | 704 | $this->tmd = 0; |
| 561 | 705 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 562 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 706 | + if ($globalDebug) { |
|
| 707 | + echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 708 | + } |
|
| 563 | 709 | $timeelapsed = microtime(true); |
| 564 | 710 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 565 | 711 | $Spotter = new Spotter($this->db); |
| 566 | 712 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
| 567 | - if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
| 568 | - else $this->all_flights[$id]['over_country'] = ''; |
|
| 713 | + if (!empty($all_country)) { |
|
| 714 | + $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
| 715 | + } else { |
|
| 716 | + $this->all_flights[$id]['over_country'] = ''; |
|
| 717 | + } |
|
| 569 | 718 | $Spotter->db = null; |
| 570 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 571 | - if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
| 719 | + if ($globalDebugTimeElapsed) { |
|
| 720 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 721 | + } |
|
| 722 | + if ($globalDebug) { |
|
| 723 | + echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
| 724 | + } |
|
| 572 | 725 | } |
| 573 | 726 | } |
| 574 | 727 | $this->all_flights[$id]['time_last_archive_coord'] = time(); |
@@ -614,7 +767,9 @@ discard block |
||
| 614 | 767 | */ |
| 615 | 768 | } |
| 616 | 769 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 617 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 770 | + if ($line['longitude'] > 180) { |
|
| 771 | + $line['longitude'] = $line['longitude'] - 360; |
|
| 772 | + } |
|
| 618 | 773 | //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
| 619 | 774 | if (!isset($this->all_flights[$id]['archive_longitude'])) { |
| 620 | 775 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
@@ -643,7 +798,9 @@ discard block |
||
| 643 | 798 | */ |
| 644 | 799 | } |
| 645 | 800 | if ($globalDaemon === TRUE && isset($updateinitial) && $updateinitial && $this->all_flights[$id]['addedSpotter'] == 1) { |
| 646 | - if ($globalDebug) echo "\n".'>>> Update initial data !'."\n"; |
|
| 801 | + if ($globalDebug) { |
|
| 802 | + echo "\n".'>>> Update initial data !'."\n"; |
|
| 803 | + } |
|
| 647 | 804 | unset($updateinitial); |
| 648 | 805 | $SpotterArchive = new SpotterArchive(); |
| 649 | 806 | $SpotterArchive->deleteSpotterArchiveTrackDataByID($this->all_flights[$id]['id']); |
@@ -661,7 +818,9 @@ discard block |
||
| 661 | 818 | } |
| 662 | 819 | } |
| 663 | 820 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 664 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 821 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) { |
|
| 822 | + $dataFound = true; |
|
| 823 | + } |
|
| 665 | 824 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
| 666 | 825 | } |
| 667 | 826 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
@@ -683,35 +842,53 @@ discard block |
||
| 683 | 842 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 684 | 843 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 685 | 844 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 686 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 687 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 688 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 845 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 846 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 847 | + } elseif (isset($line['id'])) { |
|
| 848 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 849 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 850 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 851 | + } |
|
| 852 | + } |
|
| 853 | + if ($line['ground'] != 1) { |
|
| 854 | + $line['ground'] = 0; |
|
| 689 | 855 | } |
| 690 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 691 | 856 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
| 692 | 857 | //$dataFound = true; |
| 693 | 858 | } |
| 694 | 859 | if (isset($line['squawk']) && $line['squawk'] != '') { |
| 695 | 860 | if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
| 696 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
|
| 861 | + if ($this->all_flights[$id]['squawk'] != $line['squawk']) { |
|
| 862 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 863 | + } |
|
| 697 | 864 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
| 698 | 865 | $highlight = ''; |
| 699 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 700 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 701 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 866 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
| 867 | + $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 868 | + } |
|
| 869 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
| 870 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 871 | + } |
|
| 872 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
| 873 | + $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 874 | + } |
|
| 702 | 875 | if ($highlight != '') { |
| 703 | 876 | $timeelapsed = microtime(true); |
| 704 | 877 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 705 | 878 | $Spotter = new Spotter($this->db); |
| 706 | 879 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
| 707 | 880 | $Spotter->db = null; |
| 708 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 881 | + if ($globalDebugTimeElapsed) { |
|
| 882 | + echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 883 | + } |
|
| 709 | 884 | } |
| 710 | 885 | //$putinarchive = true; |
| 711 | 886 | //$highlight = ''; |
| 712 | 887 | } |
| 713 | 888 | |
| 714 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 889 | + } else { |
|
| 890 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 891 | + } |
|
| 715 | 892 | //$dataFound = true; |
| 716 | 893 | } |
| 717 | 894 | |
@@ -724,19 +901,27 @@ discard block |
||
| 724 | 901 | } |
| 725 | 902 | } |
| 726 | 903 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
| 727 | - if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true; |
|
| 904 | + if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) { |
|
| 905 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 906 | + } |
|
| 728 | 907 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
| 729 | 908 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
| 730 | 909 | //$dataFound = true; |
| 731 | 910 | //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
| 732 | 911 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) { |
| 733 | 912 | if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 734 | - if ($globalDebug) echo '--- Reset because of altitude'."\n"; |
|
| 913 | + if ($globalDebug) { |
|
| 914 | + echo '--- Reset because of altitude'."\n"; |
|
| 915 | + } |
|
| 735 | 916 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 736 | 917 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 737 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 738 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 739 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 918 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 919 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 920 | + } elseif (isset($line['id'])) { |
|
| 921 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 922 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 923 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 924 | + } |
|
| 740 | 925 | } |
| 741 | 926 | } |
| 742 | 927 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude'])); |
@@ -747,22 +932,32 @@ discard block |
||
| 747 | 932 | } |
| 748 | 933 | |
| 749 | 934 | if (isset($line['heading']) && $line['heading'] != '') { |
| 750 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 935 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) { |
|
| 936 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 937 | + } |
|
| 751 | 938 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
| 752 | 939 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
| 753 | 940 | //$dataFound = true; |
| 754 | 941 | } elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { |
| 755 | 942 | $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
| 756 | 943 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
| 757 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 758 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
| 944 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) { |
|
| 945 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 946 | + } |
|
| 947 | + if ($globalDebug) { |
|
| 948 | + echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
| 949 | + } |
|
| 759 | 950 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 760 | 951 | // If not enough messages and ACARS set heading to 0 |
| 761 | 952 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
| 762 | 953 | } |
| 763 | - if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 764 | - elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 765 | - elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinUpdate) $dataFound = false; |
|
| 954 | + if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) { |
|
| 955 | + $dataFound = false; |
|
| 956 | + } elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) { |
|
| 957 | + $dataFound = false; |
|
| 958 | + } elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinUpdate) { |
|
| 959 | + $dataFound = false; |
|
| 960 | + } |
|
| 766 | 961 | |
| 767 | 962 | // print_r($this->all_flights[$id]); |
| 768 | 963 | //gets the callsign from the last hour |
@@ -779,23 +974,38 @@ discard block |
||
| 779 | 974 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
| 780 | 975 | if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
| 781 | 976 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 782 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 977 | + if ($globalDebug) { |
|
| 978 | + echo "Check if aircraft is already in DB..."; |
|
| 979 | + } |
|
| 783 | 980 | $timeelapsed = microtime(true); |
| 784 | 981 | $SpotterLive = new SpotterLive($this->db); |
| 785 | 982 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'aircraftjson' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
| 786 | 983 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
| 787 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 984 | + if ($globalDebugTimeElapsed) { |
|
| 985 | + echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 986 | + } |
|
| 788 | 987 | } elseif (isset($line['id'])) { |
| 789 | 988 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
| 790 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 989 | + if ($globalDebugTimeElapsed) { |
|
| 990 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 991 | + } |
|
| 791 | 992 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
| 792 | 993 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
| 793 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 794 | - } else $recent_ident = ''; |
|
| 994 | + if ($globalDebugTimeElapsed) { |
|
| 995 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 996 | + } |
|
| 997 | + } else { |
|
| 998 | + $recent_ident = ''; |
|
| 999 | + } |
|
| 795 | 1000 | $SpotterLive->db=null; |
| 796 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 797 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 798 | - } else $recent_ident = ''; |
|
| 1001 | + if ($globalDebug && $recent_ident == '') { |
|
| 1002 | + echo " Not in DB.\n"; |
|
| 1003 | + } elseif ($globalDebug && $recent_ident != '') { |
|
| 1004 | + echo " Already in DB.\n"; |
|
| 1005 | + } |
|
| 1006 | + } else { |
|
| 1007 | + $recent_ident = ''; |
|
| 1008 | + } |
|
| 799 | 1009 | } else { |
| 800 | 1010 | $recent_ident = ''; |
| 801 | 1011 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
@@ -803,7 +1013,9 @@ discard block |
||
| 803 | 1013 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 804 | 1014 | if($recent_ident == "") |
| 805 | 1015 | { |
| 806 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
| 1016 | + if ($globalDebug) { |
|
| 1017 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
| 1018 | + } |
|
| 807 | 1019 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 808 | 1020 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 809 | 1021 | //adds the spotter data for the archive |
@@ -847,10 +1059,18 @@ discard block |
||
| 847 | 1059 | |
| 848 | 1060 | if (!$ignoreImport) { |
| 849 | 1061 | $highlight = ''; |
| 850 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 851 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 852 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 853 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1062 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
| 1063 | + $highlight = 'Squawk 7500 : Hijack'; |
|
| 1064 | + } |
|
| 1065 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
| 1066 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 1067 | + } |
|
| 1068 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
| 1069 | + $highlight = 'Squawk 7700 : Emergency'; |
|
| 1070 | + } |
|
| 1071 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 1072 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1073 | + } |
|
| 854 | 1074 | $timeelapsed = microtime(true); |
| 855 | 1075 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 856 | 1076 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
@@ -858,28 +1078,43 @@ discard block |
||
| 858 | 1078 | $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']); |
| 859 | 1079 | $Spotter->db = null; |
| 860 | 1080 | if ($globalDebug) { |
| 861 | - if (isset($result['error'])) echo 'Error: '.$result['error']."\n"; |
|
| 862 | - else echo 'Success'; |
|
| 1081 | + if (isset($result['error'])) { |
|
| 1082 | + echo 'Error: '.$result['error']."\n"; |
|
| 1083 | + } else { |
|
| 1084 | + echo 'Success'; |
|
| 1085 | + } |
|
| 863 | 1086 | } |
| 864 | 1087 | if (count($result) > 1) { |
| 865 | 1088 | // ':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type, |
| 866 | - if ($this->all_flights[$id]['aircraft_icao'] == '') $this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao']; |
|
| 867 | - if ($this->all_flights[$id]['registration'] == '') $this->all_flights[$id]['registration'] = $result[':registration']; |
|
| 1089 | + if ($this->all_flights[$id]['aircraft_icao'] == '') { |
|
| 1090 | + $this->all_flights[$id]['aircraft_icao'] = $result[':aircraft_icao']; |
|
| 1091 | + } |
|
| 1092 | + if ($this->all_flights[$id]['registration'] == '') { |
|
| 1093 | + $this->all_flights[$id]['registration'] = $result[':registration']; |
|
| 1094 | + } |
|
| 868 | 1095 | } |
| 869 | 1096 | } |
| 870 | 1097 | } |
| 871 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1098 | + if ($globalDebugTimeElapsed) { |
|
| 1099 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1100 | + } |
|
| 872 | 1101 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 873 | 1102 | |
| 874 | 1103 | // Add source stat in DB |
| 875 | 1104 | $Stats = new Stats($this->db); |
| 876 | 1105 | if (!empty($this->stats)) { |
| 877 | - if ($globalDebug) echo 'Add source stats : '; |
|
| 1106 | + if ($globalDebug) { |
|
| 1107 | + echo 'Add source stats : '; |
|
| 1108 | + } |
|
| 878 | 1109 | foreach($this->stats as $date => $data) { |
| 879 | 1110 | foreach($data as $source => $sourced) { |
| 880 | 1111 | //print_r($sourced); |
| 881 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 882 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 1112 | + if (isset($sourced['polar'])) { |
|
| 1113 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 1114 | + } |
|
| 1115 | + if (isset($sourced['hist'])) { |
|
| 1116 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 1117 | + } |
|
| 883 | 1118 | if (isset($sourced['msg'])) { |
| 884 | 1119 | if (time() - $sourced['msg']['date'] > 10) { |
| 885 | 1120 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -892,13 +1127,17 @@ discard block |
||
| 892 | 1127 | unset($this->stats[$date]); |
| 893 | 1128 | } |
| 894 | 1129 | } |
| 895 | - if ($globalDebug) echo 'Done'."\n"; |
|
| 1130 | + if ($globalDebug) { |
|
| 1131 | + echo 'Done'."\n"; |
|
| 1132 | + } |
|
| 896 | 1133 | |
| 897 | 1134 | } |
| 898 | 1135 | $Stats->db = null; |
| 899 | 1136 | } |
| 900 | 1137 | $this->del(); |
| 901 | - } elseif ($globalDebug) echo 'Ignore data'."\n"; |
|
| 1138 | + } elseif ($globalDebug) { |
|
| 1139 | + echo 'Ignore data'."\n"; |
|
| 1140 | + } |
|
| 902 | 1141 | //$ignoreImport = false; |
| 903 | 1142 | $this->all_flights[$id]['addedSpotter'] = 1; |
| 904 | 1143 | //print_r($this->all_flights[$id]); |
@@ -915,7 +1154,9 @@ discard block |
||
| 915 | 1154 | */ |
| 916 | 1155 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
| 917 | 1156 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 918 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 1157 | + if ($globalDebug) { |
|
| 1158 | + echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 1159 | + } |
|
| 919 | 1160 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 920 | 1161 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 921 | 1162 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
@@ -924,7 +1165,9 @@ discard block |
||
| 924 | 1165 | $SpotterLive->db=null; |
| 925 | 1166 | } |
| 926 | 1167 | } |
| 927 | - if ($globalDebug) echo " Done\n"; |
|
| 1168 | + if ($globalDebug) { |
|
| 1169 | + echo " Done\n"; |
|
| 1170 | + } |
|
| 928 | 1171 | $this->last_delete = time(); |
| 929 | 1172 | } |
| 930 | 1173 | } else { |
@@ -951,11 +1194,17 @@ discard block |
||
| 951 | 1194 | //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
| 952 | 1195 | if ($globalDebug) { |
| 953 | 1196 | if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
| 954 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 955 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
| 1197 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
| 1198 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 1199 | + } else { |
|
| 1200 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
| 1201 | + } |
|
| 956 | 1202 | } else { |
| 957 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 958 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
| 1203 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
| 1204 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 1205 | + } else { |
|
| 1206 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
| 1207 | + } |
|
| 959 | 1208 | } |
| 960 | 1209 | } |
| 961 | 1210 | $ignoreImport = false; |
@@ -1001,23 +1250,31 @@ discard block |
||
| 1001 | 1250 | |
| 1002 | 1251 | if (!$ignoreImport) { |
| 1003 | 1252 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
| 1004 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1253 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 1254 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1255 | + } |
|
| 1005 | 1256 | $timeelapsed = microtime(true); |
| 1006 | 1257 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 1007 | 1258 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 1008 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
| 1259 | + if ($globalDebug) { |
|
| 1260 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
| 1261 | + } |
|
| 1009 | 1262 | $SpotterLive = new SpotterLive($this->db); |
| 1010 | 1263 | //var_dump($this->all_flights[$id]); |
| 1011 | 1264 | $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
| 1012 | 1265 | $SpotterLive->db = null; |
| 1013 | - if ($globalDebug) echo $result."\n"; |
|
| 1266 | + if ($globalDebug) { |
|
| 1267 | + echo $result."\n"; |
|
| 1268 | + } |
|
| 1014 | 1269 | } |
| 1015 | 1270 | } |
| 1016 | 1271 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 1017 | 1272 | $APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
| 1018 | 1273 | } |
| 1019 | 1274 | $this->all_flights[$id]['putinarchive'] = false; |
| 1020 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1275 | + if ($globalDebugTimeElapsed) { |
|
| 1276 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1277 | + } |
|
| 1021 | 1278 | |
| 1022 | 1279 | // Put statistics in $this->stats variable |
| 1023 | 1280 | //if ($line['format_source'] != 'aprs') { |
@@ -1025,7 +1282,9 @@ discard block |
||
| 1025 | 1282 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 1026 | 1283 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
| 1027 | 1284 | $source = $this->all_flights[$id]['source_name']; |
| 1028 | - if ($source == '') $source = $this->all_flights[$id]['format_source']; |
|
| 1285 | + if ($source == '') { |
|
| 1286 | + $source = $this->all_flights[$id]['format_source']; |
|
| 1287 | + } |
|
| 1029 | 1288 | if (!isset($this->source_location[$source])) { |
| 1030 | 1289 | $Location = new Source($this->db); |
| 1031 | 1290 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -1046,7 +1305,9 @@ discard block |
||
| 1046 | 1305 | $stats_heading = round($stats_heading/22.5); |
| 1047 | 1306 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
| 1048 | 1307 | $current_date = date('Y-m-d'); |
| 1049 | - if ($stats_heading == 16) $stats_heading = 0; |
|
| 1308 | + if ($stats_heading == 16) { |
|
| 1309 | + $stats_heading = 0; |
|
| 1310 | + } |
|
| 1050 | 1311 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 1051 | 1312 | for ($i=0;$i<=15;$i++) { |
| 1052 | 1313 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -1064,7 +1325,9 @@ discard block |
||
| 1064 | 1325 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 1065 | 1326 | end($this->stats[$current_date][$source]['hist']); |
| 1066 | 1327 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
| 1067 | - } else $mini = 0; |
|
| 1328 | + } else { |
|
| 1329 | + $mini = 0; |
|
| 1330 | + } |
|
| 1068 | 1331 | for ($i=$mini;$i<=$distance;$i+=10) { |
| 1069 | 1332 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
| 1070 | 1333 | } |
@@ -1076,19 +1339,27 @@ discard block |
||
| 1076 | 1339 | } |
| 1077 | 1340 | |
| 1078 | 1341 | $this->all_flights[$id]['lastupdate'] = time(); |
| 1079 | - if ($this->all_flights[$id]['putinarchive']) $send = true; |
|
| 1342 | + if ($this->all_flights[$id]['putinarchive']) { |
|
| 1343 | + $send = true; |
|
| 1344 | + } |
|
| 1080 | 1345 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
| 1081 | - } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 1346 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
| 1347 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 1348 | + } |
|
| 1082 | 1349 | //$this->del(); |
| 1083 | 1350 | |
| 1084 | 1351 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 1085 | 1352 | if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
| 1086 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 1353 | + if ($globalDebug) { |
|
| 1354 | + echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 1355 | + } |
|
| 1087 | 1356 | $SpotterLive = new SpotterLive($this->db); |
| 1088 | 1357 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 1089 | 1358 | $SpotterLive->db = null; |
| 1090 | 1359 | //SpotterLive->deleteLiveSpotterData(); |
| 1091 | - if ($globalDebug) echo " Done\n"; |
|
| 1360 | + if ($globalDebug) { |
|
| 1361 | + echo " Done\n"; |
|
| 1362 | + } |
|
| 1092 | 1363 | $this->last_delete_hourly = time(); |
| 1093 | 1364 | } else { |
| 1094 | 1365 | $this->del(); |
@@ -1100,7 +1371,9 @@ discard block |
||
| 1100 | 1371 | //$ignoreImport = false; |
| 1101 | 1372 | } |
| 1102 | 1373 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 1103 | - if ($send) return $this->all_flights[$id]; |
|
| 1374 | + if ($send) { |
|
| 1375 | + return $this->all_flights[$id]; |
|
| 1376 | + } |
|
| 1104 | 1377 | } |
| 1105 | 1378 | } |
| 1106 | 1379 | } |
@@ -20,7 +20,9 @@ discard block |
||
| 20 | 20 | public function __construct($dbc = null) { |
| 21 | 21 | $Connection = new Connection($dbc); |
| 22 | 22 | $this->db = $Connection->db(); |
| 23 | - if ($this->db === null) die('Error: No DB connection. (Accident)'); |
|
| 23 | + if ($this->db === null) { |
|
| 24 | + die('Error: No DB connection. (Accident)'); |
|
| 25 | + } |
|
| 24 | 26 | } |
| 25 | 27 | |
| 26 | 28 | /* |
@@ -125,8 +127,11 @@ discard block |
||
| 125 | 127 | $data = array(); |
| 126 | 128 | if ($row['registration'] != '') { |
| 127 | 129 | $image_array = $Image->getSpotterImage($row['registration']); |
| 128 | - if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); |
|
| 129 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 130 | + if (count($image_array) > 0) { |
|
| 131 | + $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); |
|
| 132 | + } else { |
|
| 133 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 134 | + } |
|
| 130 | 135 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
| 131 | 136 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
| 132 | 137 | if (!empty($aircraft_info)) { |
@@ -142,17 +147,30 @@ discard block |
||
| 142 | 147 | $data['aircraft_base'] = $owner_data['base']; |
| 143 | 148 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
| 144 | 149 | } |
| 145 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 146 | - if ($row['registration'] == '') $row['registration'] = 'NA'; |
|
| 147 | - if ($row['ident'] == '') $row['ident'] = 'NA'; |
|
| 150 | + } else { |
|
| 151 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 152 | + } |
|
| 153 | + if ($row['registration'] == '') { |
|
| 154 | + $row['registration'] = 'NA'; |
|
| 155 | + } |
|
| 156 | + if ($row['ident'] == '') { |
|
| 157 | + $row['ident'] = 'NA'; |
|
| 158 | + } |
|
| 148 | 159 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3)); |
| 149 | 160 | if (isset($identicao[0])) { |
| 150 | 161 | if (substr($row['ident'],0,2) == 'AF') { |
| 151 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
| 152 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 153 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 162 | + if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) { |
|
| 163 | + $icao = $row['ident']; |
|
| 164 | + } else { |
|
| 165 | + $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 166 | + } |
|
| 167 | + } else { |
|
| 168 | + $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 169 | + } |
|
| 154 | 170 | $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
| 155 | - } else $icao = $row['ident']; |
|
| 171 | + } else { |
|
| 172 | + $icao = $row['ident']; |
|
| 173 | + } |
|
| 156 | 174 | $icao = $Translation->checkTranslation($icao,false); |
| 157 | 175 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
| 158 | 176 | if ($row['airline_name'] != '' && !isset($data['airline_name'])) { |
@@ -167,10 +185,14 @@ discard block |
||
| 167 | 185 | //else echo 'No data...'."\n"; |
| 168 | 186 | } |
| 169 | 187 | $data = array_merge($row,$data); |
| 170 | - if ($data['ident'] == null) $data['ident'] = $icao; |
|
| 188 | + if ($data['ident'] == null) { |
|
| 189 | + $data['ident'] = $icao; |
|
| 190 | + } |
|
| 171 | 191 | if ($data['title'] == null) { |
| 172 | 192 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
| 173 | - } else $data['message'] = strtolower($data['title']); |
|
| 193 | + } else { |
|
| 194 | + $data['message'] = strtolower($data['title']); |
|
| 195 | + } |
|
| 174 | 196 | $ids = $Spotter->getAllIDByRegistration($data['registration'],true); |
| 175 | 197 | $date = $data['date']; |
| 176 | 198 | if (isset($ids[$date])) { |
@@ -189,8 +211,9 @@ discard block |
||
| 189 | 211 | if (isset($result)) { |
| 190 | 212 | $result[0]['query_number_rows'] = $i; |
| 191 | 213 | return $result; |
| 214 | + } else { |
|
| 215 | + return array(); |
|
| 192 | 216 | } |
| 193 | - else return array(); |
|
| 194 | 217 | } |
| 195 | 218 | |
| 196 | 219 | /* |
@@ -235,7 +258,9 @@ discard block |
||
| 235 | 258 | */ |
| 236 | 259 | public function import($file) { |
| 237 | 260 | global $globalTransaction, $globalDebug; |
| 238 | - if ($globalDebug) echo 'Import '.$file."\n"; |
|
| 261 | + if ($globalDebug) { |
|
| 262 | + echo 'Import '.$file."\n"; |
|
| 263 | + } |
|
| 239 | 264 | $result = array(); |
| 240 | 265 | if (file_exists($file)) { |
| 241 | 266 | if (($handle = fopen($file,'r')) !== FALSE) { |
@@ -246,8 +271,11 @@ discard block |
||
| 246 | 271 | } |
| 247 | 272 | fclose($handle); |
| 248 | 273 | } |
| 249 | - if (!empty($result)) $this->add($result,true); |
|
| 250 | - elseif ($globalDebug) echo 'Nothing to import'; |
|
| 274 | + if (!empty($result)) { |
|
| 275 | + $this->add($result,true); |
|
| 276 | + } elseif ($globalDebug) { |
|
| 277 | + echo 'Nothing to import'; |
|
| 278 | + } |
|
| 251 | 279 | } |
| 252 | 280 | } |
| 253 | 281 | |
@@ -283,14 +311,23 @@ discard block |
||
| 283 | 311 | } |
| 284 | 312 | } |
| 285 | 313 | fclose($handle); |
| 286 | - } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
| 287 | - } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
| 314 | + } elseif ($globalDebug) { |
|
| 315 | + echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
| 316 | + } |
|
| 317 | + } elseif ($globalDebug) { |
|
| 318 | + echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
| 319 | + } |
|
| 288 | 320 | $result = $Common->arr_diff($all_md5_new,$all_md5); |
| 289 | - if (empty($result) && $globalDebug) echo 'Nothing to update'; |
|
| 321 | + if (empty($result) && $globalDebug) { |
|
| 322 | + echo 'Nothing to update'; |
|
| 323 | + } |
|
| 290 | 324 | foreach ($result as $file => $md5) { |
| 291 | 325 | $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
| 292 | - if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 293 | - elseif ($globalDebug) echo 'Download '.$file.' failed'; |
|
| 326 | + if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) { |
|
| 327 | + $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 328 | + } elseif ($globalDebug) { |
|
| 329 | + echo 'Download '.$file.' failed'; |
|
| 330 | + } |
|
| 294 | 331 | } |
| 295 | 332 | } |
| 296 | 333 | |
@@ -307,13 +344,17 @@ discard block |
||
| 307 | 344 | $Image = new Image($this->db); |
| 308 | 345 | $Spotter = new Spotter($this->db); |
| 309 | 346 | |
| 310 | - if (empty($crash)) return false; |
|
| 347 | + if (empty($crash)) { |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 311 | 350 | if ($new === false) { |
| 312 | 351 | $query_delete = 'DELETE FROM accidents WHERE source = :source'; |
| 313 | 352 | $sthd = $Connection->db->prepare($query_delete); |
| 314 | 353 | $sthd->execute(array(':source' => $crash[0]['source'])); |
| 315 | 354 | } |
| 316 | - if ($globalTransaction) $Connection->db->beginTransaction(); |
|
| 355 | + if ($globalTransaction) { |
|
| 356 | + $Connection->db->beginTransaction(); |
|
| 357 | + } |
|
| 317 | 358 | $initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null,'operator' => null); |
| 318 | 359 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
| 319 | 360 | $sth_check = $Connection->db->prepare($query_check); |
@@ -328,7 +369,9 @@ discard block |
||
| 328 | 369 | return $value === "" ? NULL : $value; |
| 329 | 370 | }, $cr); |
| 330 | 371 | if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
| 331 | - if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 372 | + if (strpos($cr['registration'],'-') === FALSE) { |
|
| 373 | + $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 374 | + } |
|
| 332 | 375 | $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
| 333 | 376 | $sth_check->execute($query_check_values); |
| 334 | 377 | $result_check = $sth_check->fetchAll(PDO::FETCH_ASSOC); |
@@ -339,13 +382,19 @@ discard block |
||
| 339 | 382 | if ($globalAircraftImageFetch) { |
| 340 | 383 | $imgchk = $Image->getSpotterImage($cr['registration']); |
| 341 | 384 | if (empty($imgchk)) { |
| 342 | - if ($globalDebug) echo "\t".'Get image for '.$cr['registration'].'...'; |
|
| 385 | + if ($globalDebug) { |
|
| 386 | + echo "\t".'Get image for '.$cr['registration'].'...'; |
|
| 387 | + } |
|
| 343 | 388 | $Image->addSpotterImage($cr['registration']); |
| 344 | - if ($globalDebug) echo "\t".'Done'."\n"; |
|
| 389 | + if ($globalDebug) { |
|
| 390 | + echo "\t".'Done'."\n"; |
|
| 391 | + } |
|
| 345 | 392 | } |
| 346 | 393 | // elseif ($globalDebug) echo 'Image already in DB'."\n"; |
| 347 | 394 | } |
| 348 | - if ($cr['title'] == '') $cr['title'] = $cr['registration'].' '.$cr['type']; |
|
| 395 | + if ($cr['title'] == '') { |
|
| 396 | + $cr['title'] = $cr['registration'].' '.$cr['type']; |
|
| 397 | + } |
|
| 349 | 398 | $Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date'])); |
| 350 | 399 | } |
| 351 | 400 | } |
@@ -355,9 +404,13 @@ discard block |
||
| 355 | 404 | $Connection->db->beginTransaction(); |
| 356 | 405 | } |
| 357 | 406 | } |
| 358 | - if ($globalTransaction) $Connection->db->commit(); |
|
| 407 | + if ($globalTransaction) { |
|
| 408 | + $Connection->db->commit(); |
|
| 409 | + } |
|
| 359 | 410 | } catch(PDOException $e) { |
| 360 | - if ($globalTransaction) $Connection->db->rollBack(); |
|
| 411 | + if ($globalTransaction) { |
|
| 412 | + $Connection->db->rollBack(); |
|
| 413 | + } |
|
| 361 | 414 | echo $e->getMessage(); |
| 362 | 415 | } |
| 363 | 416 | $sth_check->closeCursor(); |
@@ -400,8 +453,11 @@ discard block |
||
| 400 | 453 | return "error : ".$e->getMessage(); |
| 401 | 454 | } |
| 402 | 455 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 403 | - if ($row['nb'] > 0) return false; |
|
| 404 | - else return true; |
|
| 456 | + if ($row['nb'] > 0) { |
|
| 457 | + return false; |
|
| 458 | + } else { |
|
| 459 | + return true; |
|
| 460 | + } |
|
| 405 | 461 | } |
| 406 | 462 | |
| 407 | 463 | /** |
@@ -15,7 +15,9 @@ discard block |
||
| 15 | 15 | public function __construct($dbc = null) { |
| 16 | 16 | $Connection = new Connection($dbc); |
| 17 | 17 | $this->db = $Connection->db(); |
| 18 | - if ($this->db === null) die('Error: No DB connection. (Marine)'); |
|
| 18 | + if ($this->db === null) { |
|
| 19 | + die('Error: No DB connection. (Marine)'); |
|
| 20 | + } |
|
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | /** |
@@ -38,7 +40,9 @@ discard block |
||
| 38 | 40 | if (isset($filter[0]['source'])) { |
| 39 | 41 | $filters = array_merge($filters,$filter); |
| 40 | 42 | } |
| 41 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
| 43 | + if (is_array($globalFilter)) { |
|
| 44 | + $filter = array_merge($filter,$globalFilter); |
|
| 45 | + } |
|
| 42 | 46 | $filter_query_join = ''; |
| 43 | 47 | $filter_query_where = ''; |
| 44 | 48 | foreach($filters as $flt) { |
@@ -86,8 +90,11 @@ discard block |
||
| 86 | 90 | $filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'"; |
| 87 | 91 | } |
| 88 | 92 | } |
| 89 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
| 90 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
| 93 | + if ($filter_query_where == '' && $where) { |
|
| 94 | + $filter_query_where = ' WHERE'; |
|
| 95 | + } elseif ($filter_query_where != '' && $and) { |
|
| 96 | + $filter_query_where .= ' AND'; |
|
| 97 | + } |
|
| 91 | 98 | if ($filter_query_where != '') { |
| 92 | 99 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
| 93 | 100 | } |
@@ -142,42 +149,84 @@ discard block |
||
| 142 | 149 | $temp_array['spotter_id'] = $row['spotter_archive_id']; |
| 143 | 150 | } elseif (isset($row['spotter_archive_output_id'])) { |
| 144 | 151 | $temp_array['spotter_id'] = $row['spotter_archive_output_id']; |
| 145 | - */} |
|
| 146 | - elseif (isset($row['marineid'])) { |
|
| 152 | + */} elseif (isset($row['marineid'])) { |
|
| 147 | 153 | $temp_array['marine_id'] = $row['marineid']; |
| 148 | 154 | } else { |
| 149 | 155 | $temp_array['marine_id'] = ''; |
| 150 | 156 | } |
| 151 | - if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id']; |
|
| 152 | - if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi']; |
|
| 153 | - if (isset($row['type'])) $temp_array['type'] = html_entity_decode($row['type'],ENT_QUOTES); |
|
| 154 | - if (isset($row['type_id'])) $temp_array['type_id'] = $row['type_id']; |
|
| 155 | - if (isset($row['status'])) $temp_array['status'] = $row['status']; |
|
| 156 | - if (isset($row['status_id'])) $temp_array['status_id'] = $row['status_id']; |
|
| 157 | - if (isset($row['captain_id'])) $temp_array['captain_id'] = $row['captain_id']; |
|
| 158 | - if (isset($row['captain_name'])) $temp_array['captain_name'] = $row['captain_name']; |
|
| 159 | - if (isset($row['race_id'])) $temp_array['race_id'] = $row['race_id']; |
|
| 160 | - if (isset($row['race_name'])) $temp_array['race_name'] = $row['race_name']; |
|
| 161 | - if (isset($row['race_time']) && isset($row['status']) && $row['status'] != 'Racing' && $row['race_time'] > 0) $temp_array['race_time'] = $row['race_time']; |
|
| 162 | - if (isset($row['race_rank'])) $temp_array['race_rank'] = $row['race_rank']; |
|
| 163 | - if (isset($row['ident'])) $temp_array['ident'] = $row['ident']; |
|
| 164 | - if (isset($row['arrival_port_name'])) $temp_array['arrival_port_name'] = $row['arrival_port_name']; |
|
| 165 | - if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude']; |
|
| 166 | - if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude']; |
|
| 167 | - if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; |
|
| 168 | - if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source']; |
|
| 157 | + if (isset($row['fammarine_id'])) { |
|
| 158 | + $temp_array['fammarine_id'] = $row['fammarine_id']; |
|
| 159 | + } |
|
| 160 | + if (isset($row['mmsi'])) { |
|
| 161 | + $temp_array['mmsi'] = $row['mmsi']; |
|
| 162 | + } |
|
| 163 | + if (isset($row['type'])) { |
|
| 164 | + $temp_array['type'] = html_entity_decode($row['type'],ENT_QUOTES); |
|
| 165 | + } |
|
| 166 | + if (isset($row['type_id'])) { |
|
| 167 | + $temp_array['type_id'] = $row['type_id']; |
|
| 168 | + } |
|
| 169 | + if (isset($row['status'])) { |
|
| 170 | + $temp_array['status'] = $row['status']; |
|
| 171 | + } |
|
| 172 | + if (isset($row['status_id'])) { |
|
| 173 | + $temp_array['status_id'] = $row['status_id']; |
|
| 174 | + } |
|
| 175 | + if (isset($row['captain_id'])) { |
|
| 176 | + $temp_array['captain_id'] = $row['captain_id']; |
|
| 177 | + } |
|
| 178 | + if (isset($row['captain_name'])) { |
|
| 179 | + $temp_array['captain_name'] = $row['captain_name']; |
|
| 180 | + } |
|
| 181 | + if (isset($row['race_id'])) { |
|
| 182 | + $temp_array['race_id'] = $row['race_id']; |
|
| 183 | + } |
|
| 184 | + if (isset($row['race_name'])) { |
|
| 185 | + $temp_array['race_name'] = $row['race_name']; |
|
| 186 | + } |
|
| 187 | + if (isset($row['race_time']) && isset($row['status']) && $row['status'] != 'Racing' && $row['race_time'] > 0) { |
|
| 188 | + $temp_array['race_time'] = $row['race_time']; |
|
| 189 | + } |
|
| 190 | + if (isset($row['race_rank'])) { |
|
| 191 | + $temp_array['race_rank'] = $row['race_rank']; |
|
| 192 | + } |
|
| 193 | + if (isset($row['ident'])) { |
|
| 194 | + $temp_array['ident'] = $row['ident']; |
|
| 195 | + } |
|
| 196 | + if (isset($row['arrival_port_name'])) { |
|
| 197 | + $temp_array['arrival_port_name'] = $row['arrival_port_name']; |
|
| 198 | + } |
|
| 199 | + if (isset($row['latitude'])) { |
|
| 200 | + $temp_array['latitude'] = $row['latitude']; |
|
| 201 | + } |
|
| 202 | + if (isset($row['longitude'])) { |
|
| 203 | + $temp_array['longitude'] = $row['longitude']; |
|
| 204 | + } |
|
| 205 | + if (isset($row['distance']) && $row['distance'] != '') { |
|
| 206 | + $temp_array['distance'] = $row['distance']; |
|
| 207 | + } |
|
| 208 | + if (isset($row['format_source'])) { |
|
| 209 | + $temp_array['format_source'] = $row['format_source']; |
|
| 210 | + } |
|
| 169 | 211 | if (isset($row['heading'])) { |
| 170 | 212 | $temp_array['heading'] = $row['heading']; |
| 171 | 213 | $heading_direction = $this->parseDirection($row['heading']); |
| 172 | - if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
|
| 214 | + if (isset($heading_direction[0]['direction_fullname'])) { |
|
| 215 | + $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + if (isset($row['ground_speed'])) { |
|
| 219 | + $temp_array['ground_speed'] = $row['ground_speed']; |
|
| 173 | 220 | } |
| 174 | - if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed']; |
|
| 175 | 221 | |
| 176 | 222 | if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "") |
| 177 | 223 | { |
| 178 | 224 | $Image = new Image($this->db); |
| 179 | - if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']); |
|
| 180 | - else $image_array = $Image->getMarineImage($temp_array['mmsi']); |
|
| 225 | + if (isset($temp_array['ident']) && $temp_array['ident'] != '') { |
|
| 226 | + $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']); |
|
| 227 | + } else { |
|
| 228 | + $image_array = $Image->getMarineImage($temp_array['mmsi']); |
|
| 229 | + } |
|
| 181 | 230 | unset($Image); |
| 182 | 231 | if (count($image_array) > 0) { |
| 183 | 232 | $temp_array['image'] = $image_array[0]['image']; |
@@ -241,13 +290,21 @@ discard block |
||
| 241 | 290 | } |
| 242 | 291 | |
| 243 | 292 | $fromsource = NULL; |
| 244 | - if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name']; |
|
| 245 | - if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country']; |
|
| 246 | - if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; |
|
| 293 | + if (isset($row['source_name']) && $row['source_name'] != '') { |
|
| 294 | + $temp_array['source_name'] = $row['source_name']; |
|
| 295 | + } |
|
| 296 | + if (isset($row['over_country']) && $row['over_country'] != '') { |
|
| 297 | + $temp_array['over_country'] = $row['over_country']; |
|
| 298 | + } |
|
| 299 | + if (isset($row['distance']) && $row['distance'] != '') { |
|
| 300 | + $temp_array['distance'] = $row['distance']; |
|
| 301 | + } |
|
| 247 | 302 | $temp_array['query_number_rows'] = $num_rows; |
| 248 | 303 | $spotter_array[] = $temp_array; |
| 249 | 304 | } |
| 250 | - if ($num_rows == 0) return array(); |
|
| 305 | + if ($num_rows == 0) { |
|
| 306 | + return array(); |
|
| 307 | + } |
|
| 251 | 308 | $spotter_array[0]['query_number_rows'] = $num_rows; |
| 252 | 309 | return $spotter_array; |
| 253 | 310 | } |
@@ -275,8 +332,12 @@ discard block |
||
| 275 | 332 | { |
| 276 | 333 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
| 277 | 334 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
| 278 | - } else $limit_query = ""; |
|
| 279 | - } else $limit_query = ""; |
|
| 335 | + } else { |
|
| 336 | + $limit_query = ""; |
|
| 337 | + } |
|
| 338 | + } else { |
|
| 339 | + $limit_query = ""; |
|
| 340 | + } |
|
| 280 | 341 | if ($sort != "") |
| 281 | 342 | { |
| 282 | 343 | $search_orderby_array = $this->getOrderBy(); |
@@ -300,7 +361,9 @@ discard block |
||
| 300 | 361 | global $global_marine_query; |
| 301 | 362 | |
| 302 | 363 | date_default_timezone_set('UTC'); |
| 303 | - if ($id == '') return array(); |
|
| 364 | + if ($id == '') { |
|
| 365 | + return array(); |
|
| 366 | + } |
|
| 304 | 367 | $additional_query = "marine_output.fammarine_id = :id"; |
| 305 | 368 | $query_values = array(':id' => $id); |
| 306 | 369 | $query = $global_marine_query." WHERE ".$additional_query." "; |
@@ -781,8 +844,11 @@ discard block |
||
| 781 | 844 | $sth = $this->db->prepare($query); |
| 782 | 845 | $sth->execute($query_values); |
| 783 | 846 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 784 | - if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']); |
|
| 785 | - else return $result[0]['duration']; |
|
| 847 | + if (is_int($result[0]['duration'])) { |
|
| 848 | + return gmdate('H:i:s',$result[0]['duration']); |
|
| 849 | + } else { |
|
| 850 | + return $result[0]['duration']; |
|
| 851 | + } |
|
| 786 | 852 | } |
| 787 | 853 | |
| 788 | 854 | /** |
@@ -830,7 +896,9 @@ discard block |
||
| 830 | 896 | } |
| 831 | 897 | } |
| 832 | 898 | $query .= " GROUP BY marine_output.captain_id,marine_output.captain_name ORDER BY duration DESC"; |
| 833 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
| 899 | + if ($limit) { |
|
| 900 | + $query .= " LIMIT 10 OFFSET 0"; |
|
| 901 | + } |
|
| 834 | 902 | $sth = $this->db->prepare($query); |
| 835 | 903 | $sth->execute($query_values); |
| 836 | 904 | //if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']); |
@@ -909,8 +977,11 @@ discard block |
||
| 909 | 977 | $query .= " ORDER BY marine_output.source_name ASC"; |
| 910 | 978 | |
| 911 | 979 | $sth = $this->db->prepare($query); |
| 912 | - if (!empty($query_values)) $sth->execute($query_values); |
|
| 913 | - else $sth->execute(); |
|
| 980 | + if (!empty($query_values)) { |
|
| 981 | + $sth->execute($query_values); |
|
| 982 | + } else { |
|
| 983 | + $sth->execute(); |
|
| 984 | + } |
|
| 914 | 985 | |
| 915 | 986 | $source_array = array(); |
| 916 | 987 | $temp_array = array(); |
@@ -965,8 +1036,11 @@ discard block |
||
| 965 | 1036 | $sth = $this->db->prepare($query); |
| 966 | 1037 | $sth->execute(array(':mmsi' => $mmsi)); |
| 967 | 1038 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 968 | - if (isset($result[0])) return $result[0]; |
|
| 969 | - else return array(); |
|
| 1039 | + if (isset($result[0])) { |
|
| 1040 | + return $result[0]; |
|
| 1041 | + } else { |
|
| 1042 | + return array(); |
|
| 1043 | + } |
|
| 970 | 1044 | } |
| 971 | 1045 | |
| 972 | 1046 | /** |
@@ -1011,7 +1085,9 @@ discard block |
||
| 1011 | 1085 | date_default_timezone_set($globalTimezone); |
| 1012 | 1086 | $datetime = new DateTime(); |
| 1013 | 1087 | $offset = $datetime->format('P'); |
| 1014 | - } else $offset = '+00:00'; |
|
| 1088 | + } else { |
|
| 1089 | + $offset = '+00:00'; |
|
| 1090 | + } |
|
| 1015 | 1091 | |
| 1016 | 1092 | if ($globalDBdriver == 'mysql') { |
| 1017 | 1093 | $query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date |
@@ -1127,8 +1203,12 @@ discard block |
||
| 1127 | 1203 | */ |
| 1128 | 1204 | public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '',$distance = NULL,$race_rank = NULL, $race_time = NULL, $status = '', $race_begin = '') |
| 1129 | 1205 | { |
| 1130 | - if ($latitude == '') $latitude = NULL; |
|
| 1131 | - if ($longitude == '') $longitude = NULL; |
|
| 1206 | + if ($latitude == '') { |
|
| 1207 | + $latitude = NULL; |
|
| 1208 | + } |
|
| 1209 | + if ($longitude == '') { |
|
| 1210 | + $longitude = NULL; |
|
| 1211 | + } |
|
| 1132 | 1212 | $groundspeed = round($groundspeed); |
| 1133 | 1213 | if ($race_begin != '') { |
| 1134 | 1214 | $query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed, distance = :distance, race_rank = :race_rank, race_time = :race_time, status = :status, date = :race_begin WHERE fammarine_id = :fammarine_id'; |
@@ -1286,14 +1366,28 @@ discard block |
||
| 1286 | 1366 | $latitude = 0; |
| 1287 | 1367 | $longitude = 0; |
| 1288 | 1368 | } |
| 1289 | - if ($type_id == '') $type_id = NULL; |
|
| 1290 | - if ($status_id == '') $status_id = NULL; |
|
| 1291 | - if ($distance == '') $distance = NULL; |
|
| 1292 | - if ($race_rank == '') $race_rank = NULL; |
|
| 1293 | - if ($race_time == '') $race_time = NULL; |
|
| 1294 | - if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0; |
|
| 1369 | + if ($type_id == '') { |
|
| 1370 | + $type_id = NULL; |
|
| 1371 | + } |
|
| 1372 | + if ($status_id == '') { |
|
| 1373 | + $status_id = NULL; |
|
| 1374 | + } |
|
| 1375 | + if ($distance == '') { |
|
| 1376 | + $distance = NULL; |
|
| 1377 | + } |
|
| 1378 | + if ($race_rank == '') { |
|
| 1379 | + $race_rank = NULL; |
|
| 1380 | + } |
|
| 1381 | + if ($race_time == '') { |
|
| 1382 | + $race_time = NULL; |
|
| 1383 | + } |
|
| 1384 | + if ($heading == '' || $Common->isInteger($heading) === false) { |
|
| 1385 | + $heading = 0; |
|
| 1386 | + } |
|
| 1295 | 1387 | //if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0; |
| 1296 | - if ($arrival_date == '') $arrival_date = NULL; |
|
| 1388 | + if ($arrival_date == '') { |
|
| 1389 | + $arrival_date = NULL; |
|
| 1390 | + } |
|
| 1297 | 1391 | $query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name, distance, race_rank,race_time) |
| 1298 | 1392 | VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:type_id,:status,:status_id,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name, :distance, :race_rank,:race_time)"; |
| 1299 | 1393 | |
@@ -1401,7 +1495,9 @@ discard block |
||
| 1401 | 1495 | global $globalDBdriver, $globalArchive; |
| 1402 | 1496 | //$filter_query = $this->getFilter($filters,true,true); |
| 1403 | 1497 | $Connection= new Connection($this->db); |
| 1404 | - if (!$Connection->tableExists('countries')) return array(); |
|
| 1498 | + if (!$Connection->tableExists('countries')) { |
|
| 1499 | + return array(); |
|
| 1500 | + } |
|
| 1405 | 1501 | require_once('class.SpotterLive.php'); |
| 1406 | 1502 | if (!isset($globalArchive) || $globalArchive !== TRUE) { |
| 1407 | 1503 | $MarineLive = new MarineLive($this->db); |
@@ -1445,7 +1541,9 @@ discard block |
||
| 1445 | 1541 | $query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT fammarine_id,over_country FROM marine_archive".$filter_query.") l ON c.iso2 = l.over_country "; |
| 1446 | 1542 | } |
| 1447 | 1543 | $query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC"; |
| 1448 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
| 1544 | + if ($limit) { |
|
| 1545 | + $query .= " LIMIT 10 OFFSET 0"; |
|
| 1546 | + } |
|
| 1449 | 1547 | |
| 1450 | 1548 | $sth = $this->db->prepare($query); |
| 1451 | 1549 | $sth->execute(); |
@@ -1484,12 +1582,18 @@ discard block |
||
| 1484 | 1582 | $query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count |
| 1485 | 1583 | FROM marine_output".$filter_query." marine_output.ident <> ''"; |
| 1486 | 1584 | if ($olderthanmonths > 0) { |
| 1487 | - if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
|
| 1488 | - else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
| 1585 | + if ($globalDBdriver == 'mysql') { |
|
| 1586 | + $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
|
| 1587 | + } else { |
|
| 1588 | + $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
| 1589 | + } |
|
| 1489 | 1590 | } |
| 1490 | 1591 | if ($sincedate != '') { |
| 1491 | - if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'"; |
|
| 1492 | - else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
|
| 1592 | + if ($globalDBdriver == 'mysql') { |
|
| 1593 | + $query .= " AND marine_output.date > '".$sincedate."'"; |
|
| 1594 | + } else { |
|
| 1595 | + $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
|
| 1596 | + } |
|
| 1493 | 1597 | } |
| 1494 | 1598 | $query_values = array(); |
| 1495 | 1599 | if ($year != '') { |
@@ -1520,7 +1624,9 @@ discard block |
||
| 1520 | 1624 | } |
| 1521 | 1625 | } |
| 1522 | 1626 | $query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC"; |
| 1523 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
| 1627 | + if ($limit) { |
|
| 1628 | + $query .= " LIMIT 10 OFFSET 0"; |
|
| 1629 | + } |
|
| 1524 | 1630 | |
| 1525 | 1631 | $sth = $this->db->prepare($query); |
| 1526 | 1632 | $sth->execute($query_values); |
@@ -1555,7 +1661,9 @@ discard block |
||
| 1555 | 1661 | date_default_timezone_set($globalTimezone); |
| 1556 | 1662 | $datetime = new DateTime(); |
| 1557 | 1663 | $offset = $datetime->format('P'); |
| 1558 | - } else $offset = '+00:00'; |
|
| 1664 | + } else { |
|
| 1665 | + $offset = '+00:00'; |
|
| 1666 | + } |
|
| 1559 | 1667 | |
| 1560 | 1668 | if ($globalDBdriver == 'mysql') { |
| 1561 | 1669 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -1605,7 +1713,9 @@ discard block |
||
| 1605 | 1713 | date_default_timezone_set($globalTimezone); |
| 1606 | 1714 | $datetime = new DateTime(); |
| 1607 | 1715 | $offset = $datetime->format('P'); |
| 1608 | - } else $offset = '+00:00'; |
|
| 1716 | + } else { |
|
| 1717 | + $offset = '+00:00'; |
|
| 1718 | + } |
|
| 1609 | 1719 | $filter_query = $this->getFilter($filters,true,true); |
| 1610 | 1720 | if ($globalDBdriver == 'mysql') { |
| 1611 | 1721 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -1651,7 +1761,9 @@ discard block |
||
| 1651 | 1761 | date_default_timezone_set($globalTimezone); |
| 1652 | 1762 | $datetime = new DateTime(); |
| 1653 | 1763 | $offset = $datetime->format('P'); |
| 1654 | - } else $offset = '+00:00'; |
|
| 1764 | + } else { |
|
| 1765 | + $offset = '+00:00'; |
|
| 1766 | + } |
|
| 1655 | 1767 | $filter_query = $this->getFilter($filters,true,true); |
| 1656 | 1768 | if ($globalDBdriver == 'mysql') { |
| 1657 | 1769 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -1699,7 +1811,9 @@ discard block |
||
| 1699 | 1811 | date_default_timezone_set($globalTimezone); |
| 1700 | 1812 | $datetime = new DateTime(); |
| 1701 | 1813 | $offset = $datetime->format('P'); |
| 1702 | - } else $offset = '+00:00'; |
|
| 1814 | + } else { |
|
| 1815 | + $offset = '+00:00'; |
|
| 1816 | + } |
|
| 1703 | 1817 | |
| 1704 | 1818 | if ($globalDBdriver == 'mysql') { |
| 1705 | 1819 | $query = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count |
@@ -1746,7 +1860,9 @@ discard block |
||
| 1746 | 1860 | date_default_timezone_set($globalTimezone); |
| 1747 | 1861 | $datetime = new DateTime(); |
| 1748 | 1862 | $offset = $datetime->format('P'); |
| 1749 | - } else $offset = '+00:00'; |
|
| 1863 | + } else { |
|
| 1864 | + $offset = '+00:00'; |
|
| 1865 | + } |
|
| 1750 | 1866 | $filter_query = $this->getFilter($filters,true,true); |
| 1751 | 1867 | if ($globalDBdriver == 'mysql') { |
| 1752 | 1868 | $query = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count |
@@ -1795,7 +1911,9 @@ discard block |
||
| 1795 | 1911 | date_default_timezone_set($globalTimezone); |
| 1796 | 1912 | $datetime = new DateTime(); |
| 1797 | 1913 | $offset = $datetime->format('P'); |
| 1798 | - } else $offset = '+00:00'; |
|
| 1914 | + } else { |
|
| 1915 | + $offset = '+00:00'; |
|
| 1916 | + } |
|
| 1799 | 1917 | |
| 1800 | 1918 | $orderby_sql = ''; |
| 1801 | 1919 | if ($orderby == "hour") |
@@ -1864,7 +1982,9 @@ discard block |
||
| 1864 | 1982 | date_default_timezone_set($globalTimezone); |
| 1865 | 1983 | $datetime = new DateTime($date); |
| 1866 | 1984 | $offset = $datetime->format('P'); |
| 1867 | - } else $offset = '+00:00'; |
|
| 1985 | + } else { |
|
| 1986 | + $offset = '+00:00'; |
|
| 1987 | + } |
|
| 1868 | 1988 | |
| 1869 | 1989 | if ($globalDBdriver == 'mysql') { |
| 1870 | 1990 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1912,7 +2032,9 @@ discard block |
||
| 1912 | 2032 | date_default_timezone_set($globalTimezone); |
| 1913 | 2033 | $datetime = new DateTime(); |
| 1914 | 2034 | $offset = $datetime->format('P'); |
| 1915 | - } else $offset = '+00:00'; |
|
| 2035 | + } else { |
|
| 2036 | + $offset = '+00:00'; |
|
| 2037 | + } |
|
| 1916 | 2038 | |
| 1917 | 2039 | if ($globalDBdriver == 'mysql') { |
| 1918 | 2040 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1974,7 +2096,9 @@ discard block |
||
| 1974 | 2096 | } |
| 1975 | 2097 | } |
| 1976 | 2098 | $query .= " GROUP BY marine_output.race_id,marine_output.race_name ORDER BY captain_count DESC"; |
| 1977 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
| 2099 | + if ($limit) { |
|
| 2100 | + $query .= " LIMIT 10 OFFSET 0"; |
|
| 2101 | + } |
|
| 1978 | 2102 | $sth = $this->db->prepare($query); |
| 1979 | 2103 | $sth->execute(); |
| 1980 | 2104 | $marine_array = array(); |
@@ -2023,8 +2147,11 @@ discard block |
||
| 2023 | 2147 | $query_values = array_merge($query_values,array(':month' => $month)); |
| 2024 | 2148 | } |
| 2025 | 2149 | } |
| 2026 | - if (empty($query_values)) $queryi .= $this->getFilter($filters); |
|
| 2027 | - else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2150 | + if (empty($query_values)) { |
|
| 2151 | + $queryi .= $this->getFilter($filters); |
|
| 2152 | + } else { |
|
| 2153 | + $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2154 | + } |
|
| 2028 | 2155 | |
| 2029 | 2156 | $sth = $this->db->prepare($queryi); |
| 2030 | 2157 | $sth->execute($query_values); |
@@ -2063,8 +2190,11 @@ discard block |
||
| 2063 | 2190 | $query_values = array_merge($query_values,array(':month' => $month)); |
| 2064 | 2191 | } |
| 2065 | 2192 | } |
| 2066 | - if (empty($query_values)) $queryi .= $this->getFilter($filters); |
|
| 2067 | - else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2193 | + if (empty($query_values)) { |
|
| 2194 | + $queryi .= $this->getFilter($filters); |
|
| 2195 | + } else { |
|
| 2196 | + $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2197 | + } |
|
| 2068 | 2198 | |
| 2069 | 2199 | $sth = $this->db->prepare($queryi); |
| 2070 | 2200 | $sth->execute($query_values); |
@@ -2103,8 +2233,11 @@ discard block |
||
| 2103 | 2233 | $query_values = array_merge($query_values,array(':month' => $month)); |
| 2104 | 2234 | } |
| 2105 | 2235 | } |
| 2106 | - if (empty($query_values)) $queryi .= $this->getFilter($filters); |
|
| 2107 | - else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2236 | + if (empty($query_values)) { |
|
| 2237 | + $queryi .= $this->getFilter($filters); |
|
| 2238 | + } else { |
|
| 2239 | + $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2240 | + } |
|
| 2108 | 2241 | |
| 2109 | 2242 | $sth = $this->db->prepare($queryi); |
| 2110 | 2243 | $sth->execute($query_values); |
@@ -2143,8 +2276,11 @@ discard block |
||
| 2143 | 2276 | $query_values = array_merge($query_values,array(':month' => $month)); |
| 2144 | 2277 | } |
| 2145 | 2278 | } |
| 2146 | - if (empty($query_values)) $queryi .= $this->getFilter($filters); |
|
| 2147 | - else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2279 | + if (empty($query_values)) { |
|
| 2280 | + $queryi .= $this->getFilter($filters); |
|
| 2281 | + } else { |
|
| 2282 | + $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
| 2283 | + } |
|
| 2148 | 2284 | |
| 2149 | 2285 | $sth = $this->db->prepare($queryi); |
| 2150 | 2286 | $sth->execute($query_values); |
@@ -2165,7 +2301,9 @@ discard block |
||
| 2165 | 2301 | date_default_timezone_set($globalTimezone); |
| 2166 | 2302 | $datetime = new DateTime(); |
| 2167 | 2303 | $offset = $datetime->format('P'); |
| 2168 | - } else $offset = '+00:00'; |
|
| 2304 | + } else { |
|
| 2305 | + $offset = '+00:00'; |
|
| 2306 | + } |
|
| 2169 | 2307 | |
| 2170 | 2308 | if ($globalDBdriver == 'mysql') { |
| 2171 | 2309 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -2269,7 +2407,9 @@ discard block |
||
| 2269 | 2407 | */ |
| 2270 | 2408 | public function parseDirection($direction = 0) |
| 2271 | 2409 | { |
| 2272 | - if ($direction == '') $direction = 0; |
|
| 2410 | + if ($direction == '') { |
|
| 2411 | + $direction = 0; |
|
| 2412 | + } |
|
| 2273 | 2413 | $direction_array = array(); |
| 2274 | 2414 | $temp_array = array(); |
| 2275 | 2415 | |
@@ -2358,7 +2498,9 @@ discard block |
||
| 2358 | 2498 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 2359 | 2499 | |
| 2360 | 2500 | $Connection = new Connection($this->db); |
| 2361 | - if (!$Connection->tableExists('countries')) return ''; |
|
| 2501 | + if (!$Connection->tableExists('countries')) { |
|
| 2502 | + return ''; |
|
| 2503 | + } |
|
| 2362 | 2504 | |
| 2363 | 2505 | try { |
| 2364 | 2506 | /* |
@@ -2378,9 +2520,13 @@ discard block |
||
| 2378 | 2520 | $sth->closeCursor(); |
| 2379 | 2521 | if (count($row) > 0) { |
| 2380 | 2522 | return $row; |
| 2381 | - } else return ''; |
|
| 2523 | + } else { |
|
| 2524 | + return ''; |
|
| 2525 | + } |
|
| 2382 | 2526 | } catch (PDOException $e) { |
| 2383 | - if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
|
| 2527 | + if (isset($globalDebug) && $globalDebug) { |
|
| 2528 | + echo 'Error : '.$e->getMessage()."\n"; |
|
| 2529 | + } |
|
| 2384 | 2530 | return ''; |
| 2385 | 2531 | } |
| 2386 | 2532 | |
@@ -2398,7 +2544,9 @@ discard block |
||
| 2398 | 2544 | $iso2 = filter_var($iso2,FILTER_SANITIZE_STRING); |
| 2399 | 2545 | |
| 2400 | 2546 | $Connection = new Connection($this->db); |
| 2401 | - if (!$Connection->tableExists('countries')) return ''; |
|
| 2547 | + if (!$Connection->tableExists('countries')) { |
|
| 2548 | + return ''; |
|
| 2549 | + } |
|
| 2402 | 2550 | |
| 2403 | 2551 | try { |
| 2404 | 2552 | $query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1"; |
@@ -2410,9 +2558,13 @@ discard block |
||
| 2410 | 2558 | $sth->closeCursor(); |
| 2411 | 2559 | if (count($row) > 0) { |
| 2412 | 2560 | return $row; |
| 2413 | - } else return ''; |
|
| 2561 | + } else { |
|
| 2562 | + return ''; |
|
| 2563 | + } |
|
| 2414 | 2564 | } catch (PDOException $e) { |
| 2415 | - if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
|
| 2565 | + if (isset($globalDebug) && $globalDebug) { |
|
| 2566 | + echo 'Error : '.$e->getMessage()."\n"; |
|
| 2567 | + } |
|
| 2416 | 2568 | return ''; |
| 2417 | 2569 | } |
| 2418 | 2570 | |
@@ -2430,7 +2582,9 @@ discard block |
||
| 2430 | 2582 | { |
| 2431 | 2583 | global $globalBitlyAccessToken; |
| 2432 | 2584 | |
| 2433 | - if ($globalBitlyAccessToken == '') return $url; |
|
| 2585 | + if ($globalBitlyAccessToken == '') { |
|
| 2586 | + return $url; |
|
| 2587 | + } |
|
| 2434 | 2588 | |
| 2435 | 2589 | $google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url; |
| 2436 | 2590 | |
@@ -2512,7 +2666,9 @@ discard block |
||
| 2512 | 2666 | } |
| 2513 | 2667 | } |
| 2514 | 2668 | $query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC"; |
| 2515 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
| 2669 | + if ($limit) { |
|
| 2670 | + $query .= " LIMIT 10 OFFSET 0"; |
|
| 2671 | + } |
|
| 2516 | 2672 | $sth = $this->db->prepare($query); |
| 2517 | 2673 | $sth->execute($query_values); |
| 2518 | 2674 | $marine_array = array(); |
@@ -2565,13 +2721,27 @@ discard block |
||
| 2565 | 2721 | foreach ($q_array as $q_item){ |
| 2566 | 2722 | $q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
| 2567 | 2723 | $additional_query .= " AND ("; |
| 2568 | - if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR "; |
|
| 2569 | - if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR "; |
|
| 2570 | - if (is_int($q_item)) $additional_query .= "(marine_output.imo = '".$q_item."') OR "; |
|
| 2571 | - if (is_int($q_item)) $additional_query .= "(marine_output.captain_id = '".$q_item."') OR "; |
|
| 2572 | - if (is_int($q_item)) $additional_query .= "(marine_output.race_id = '".$q_item."') OR "; |
|
| 2573 | - if (!is_int($q_item)) $additional_query .= "(marine_output.captain_name = '".$q_item."') OR "; |
|
| 2574 | - if (!is_int($q_item)) $additional_query .= "(marine_output.race_name = '".$q_item."') OR "; |
|
| 2724 | + if (is_int($q_item)) { |
|
| 2725 | + $additional_query .= "(marine_output.marine_id = '".$q_item."') OR "; |
|
| 2726 | + } |
|
| 2727 | + if (is_int($q_item)) { |
|
| 2728 | + $additional_query .= "(marine_output.mmsi = '".$q_item."') OR "; |
|
| 2729 | + } |
|
| 2730 | + if (is_int($q_item)) { |
|
| 2731 | + $additional_query .= "(marine_output.imo = '".$q_item."') OR "; |
|
| 2732 | + } |
|
| 2733 | + if (is_int($q_item)) { |
|
| 2734 | + $additional_query .= "(marine_output.captain_id = '".$q_item."') OR "; |
|
| 2735 | + } |
|
| 2736 | + if (is_int($q_item)) { |
|
| 2737 | + $additional_query .= "(marine_output.race_id = '".$q_item."') OR "; |
|
| 2738 | + } |
|
| 2739 | + if (!is_int($q_item)) { |
|
| 2740 | + $additional_query .= "(marine_output.captain_name = '".$q_item."') OR "; |
|
| 2741 | + } |
|
| 2742 | + if (!is_int($q_item)) { |
|
| 2743 | + $additional_query .= "(marine_output.race_name = '".$q_item."') OR "; |
|
| 2744 | + } |
|
| 2575 | 2745 | $additional_query .= "(marine_output.ident like '%".$q_item."%')"; |
| 2576 | 2746 | $additional_query .= ")"; |
| 2577 | 2747 | } |
@@ -2663,7 +2833,9 @@ discard block |
||
| 2663 | 2833 | date_default_timezone_set($globalTimezone); |
| 2664 | 2834 | $datetime = new DateTime(); |
| 2665 | 2835 | $offset = $datetime->format('P'); |
| 2666 | - } else $offset = '+00:00'; |
|
| 2836 | + } else { |
|
| 2837 | + $offset = '+00:00'; |
|
| 2838 | + } |
|
| 2667 | 2839 | if ($date_array[1] != "") |
| 2668 | 2840 | { |
| 2669 | 2841 | $date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
@@ -2690,8 +2862,12 @@ discard block |
||
| 2690 | 2862 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
| 2691 | 2863 | { |
| 2692 | 2864 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
| 2693 | - } else $limit_query = ""; |
|
| 2694 | - } else $limit_query = ""; |
|
| 2865 | + } else { |
|
| 2866 | + $limit_query = ""; |
|
| 2867 | + } |
|
| 2868 | + } else { |
|
| 2869 | + $limit_query = ""; |
|
| 2870 | + } |
|
| 2695 | 2871 | if ($sort != "") |
| 2696 | 2872 | { |
| 2697 | 2873 | $search_orderby_array = $this->getOrderBy(); |
@@ -2757,8 +2933,11 @@ discard block |
||
| 2757 | 2933 | $sth = $this->db->prepare($query); |
| 2758 | 2934 | $sth->execute(array(':race_name' => $race_name)); |
| 2759 | 2935 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 2760 | - if (isset($result[0])) return $result[0]; |
|
| 2761 | - else return array(); |
|
| 2936 | + if (isset($result[0])) { |
|
| 2937 | + return $result[0]; |
|
| 2938 | + } else { |
|
| 2939 | + return array(); |
|
| 2940 | + } |
|
| 2762 | 2941 | } |
| 2763 | 2942 | |
| 2764 | 2943 | /** |
@@ -2774,8 +2953,11 @@ discard block |
||
| 2774 | 2953 | $sth = $this->db->prepare($query); |
| 2775 | 2954 | $sth->execute(array(':race_id' => $race_id)); |
| 2776 | 2955 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 2777 | - if (isset($result[0])) return $result[0]; |
|
| 2778 | - else return array(); |
|
| 2956 | + if (isset($result[0])) { |
|
| 2957 | + return $result[0]; |
|
| 2958 | + } else { |
|
| 2959 | + return array(); |
|
| 2960 | + } |
|
| 2779 | 2961 | } |
| 2780 | 2962 | |
| 2781 | 2963 | /** |
@@ -19,7 +19,9 @@ discard block |
||
| 19 | 19 | public function __construct($dbc = null) { |
| 20 | 20 | $Connection = new Connection($dbc); |
| 21 | 21 | $this->db = $Connection->db(); |
| 22 | - if ($this->db === null) die('Error: No DB connection. (Image)'); |
|
| 22 | + if ($this->db === null) { |
|
| 23 | + die('Error: No DB connection. (Image)'); |
|
| 24 | + } |
|
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | /** |
@@ -36,7 +38,9 @@ discard block |
||
| 36 | 38 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
| 37 | 39 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
| 38 | 40 | $reg = $registration; |
| 39 | - if (($reg == '' || $reg == 'NA') && $aircraft_icao != '') $reg = $aircraft_icao.$airline_icao; |
|
| 41 | + if (($reg == '' || $reg == 'NA') && $aircraft_icao != '') { |
|
| 42 | + $reg = $aircraft_icao.$airline_icao; |
|
| 43 | + } |
|
| 40 | 44 | $reg = trim($reg); |
| 41 | 45 | $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 |
| 42 | 46 | FROM spotter_image |
@@ -44,9 +48,13 @@ discard block |
||
| 44 | 48 | $sth = $this->db->prepare($query); |
| 45 | 49 | $sth->execute(array(':registration' => $reg)); |
| 46 | 50 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 47 | - if (!empty($result)) return $result; |
|
| 48 | - elseif ($registration != '' && ($aircraft_icao != '' || $airline_icao != '')) return $this->getSpotterImage('',$aircraft_icao,$airline_icao); |
|
| 49 | - else return array(); |
|
| 51 | + if (!empty($result)) { |
|
| 52 | + return $result; |
|
| 53 | + } elseif ($registration != '' && ($aircraft_icao != '' || $airline_icao != '')) { |
|
| 54 | + return $this->getSpotterImage('',$aircraft_icao,$airline_icao); |
|
| 55 | + } else { |
|
| 56 | + return array(); |
|
| 57 | + } |
|
| 50 | 58 | } |
| 51 | 59 | |
| 52 | 60 | /** |
@@ -74,7 +82,9 @@ discard block |
||
| 74 | 82 | } |
| 75 | 83 | } |
| 76 | 84 | $name = trim($name); |
| 77 | - if ($mmsi == '' && $imo == '' && $name == '') return array(); |
|
| 85 | + if ($mmsi == '' && $imo == '' && $name == '') { |
|
| 86 | + return array(); |
|
| 87 | + } |
|
| 78 | 88 | $query = "SELECT marine_image.image, marine_image.image_thumbnail, marine_image.image_source, marine_image.image_source_website,marine_image.image_copyright, marine_image.mmsi, marine_image.imo, marine_image.name |
| 79 | 89 | FROM marine_image |
| 80 | 90 | WHERE marine_image.mmsi = :mmsi"; |
@@ -103,8 +113,11 @@ discard block |
||
| 103 | 113 | public function getExifCopyright($url) { |
| 104 | 114 | $exif = exif_read_data($url); |
| 105 | 115 | $copyright = ''; |
| 106 | - if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright']; |
|
| 107 | - elseif (isset($exif['copyright'])) $copyright = $exif['copyright']; |
|
| 116 | + if (isset($exif['COMPUTED']['copyright'])) { |
|
| 117 | + $copyright = $exif['COMPUTED']['copyright']; |
|
| 118 | + } elseif (isset($exif['copyright'])) { |
|
| 119 | + $copyright = $exif['copyright']; |
|
| 120 | + } |
|
| 108 | 121 | if ($copyright != '') { |
| 109 | 122 | $copyright = str_replace('Copyright ','',$copyright); |
| 110 | 123 | $copyright = str_replace('© ','',$copyright); |
@@ -124,17 +137,27 @@ discard block |
||
| 124 | 137 | public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '') |
| 125 | 138 | { |
| 126 | 139 | global $globalDebug,$globalAircraftImageFetch, $globalOffline; |
| 127 | - if ((isset($globalAircraftImageFetch) && $globalAircraftImageFetch === FALSE) || (isset($globalOffline) && $globalOffline === TRUE)) return ''; |
|
| 140 | + if ((isset($globalAircraftImageFetch) && $globalAircraftImageFetch === FALSE) || (isset($globalOffline) && $globalOffline === TRUE)) { |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 128 | 143 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
| 129 | 144 | $registration = trim($registration); |
| 130 | 145 | //getting the aircraft image |
| 131 | - if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...'; |
|
| 132 | - elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
|
| 133 | - elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
|
| 146 | + if ($globalDebug && $registration != '') { |
|
| 147 | + echo 'Try to find an aircraft image for '.$registration.'...'; |
|
| 148 | + } elseif ($globalDebug && $aircraft_icao != '') { |
|
| 149 | + echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
|
| 150 | + } elseif ($globalDebug && $airline_icao != '') { |
|
| 151 | + echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
|
| 152 | + } |
|
| 134 | 153 | $image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao); |
| 135 | - if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
|
| 154 | + if ($registration == '' && $aircraft_icao != '') { |
|
| 155 | + $registration = $aircraft_icao.$airline_icao; |
|
| 156 | + } |
|
| 136 | 157 | if ($image_url['original'] != '') { |
| 137 | - if ($globalDebug) echo 'Found !'."\n"; |
|
| 158 | + if ($globalDebug) { |
|
| 159 | + echo 'Found !'."\n"; |
|
| 160 | + } |
|
| 138 | 161 | $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)"; |
| 139 | 162 | try { |
| 140 | 163 | $sth = $this->db->prepare($query); |
@@ -143,7 +166,9 @@ discard block |
||
| 143 | 166 | echo $e->getMessage()."\n"; |
| 144 | 167 | return "error"; |
| 145 | 168 | } |
| 146 | - } elseif ($globalDebug) echo "Not found :'(\n"; |
|
| 169 | + } elseif ($globalDebug) { |
|
| 170 | + echo "Not found :'(\n"; |
|
| 171 | + } |
|
| 147 | 172 | return "success"; |
| 148 | 173 | } |
| 149 | 174 | |
@@ -158,7 +183,9 @@ discard block |
||
| 158 | 183 | public function addMarineImage($mmsi,$imo = '',$name = '') |
| 159 | 184 | { |
| 160 | 185 | global $globalDebug,$globalMarineImageFetch, $globalOffline; |
| 161 | - if ((isset($globalMarineImageFetch) && !$globalMarineImageFetch) || (isset($globalOffline) && $globalOffline === TRUE)) return ''; |
|
| 186 | + if ((isset($globalMarineImageFetch) && !$globalMarineImageFetch) || (isset($globalOffline) && $globalOffline === TRUE)) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 162 | 189 | $mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); |
| 163 | 190 | $imo = filter_var($imo,FILTER_SANITIZE_STRING); |
| 164 | 191 | $name = filter_var($name,FILTER_SANITIZE_STRING); |
@@ -168,16 +195,22 @@ discard block |
||
| 168 | 195 | $identity = $Marine->getIdentity($mmsi); |
| 169 | 196 | if (isset($identity[0]['mmsi'])) { |
| 170 | 197 | $imo = $identity[0]['imo']; |
| 171 | - if ($identity[0]['ship_name'] != '') $name = $identity[0]['ship_name']; |
|
| 198 | + if ($identity[0]['ship_name'] != '') { |
|
| 199 | + $name = $identity[0]['ship_name']; |
|
| 200 | + } |
|
| 172 | 201 | } |
| 173 | 202 | } |
| 174 | 203 | unset($Marine); |
| 175 | 204 | |
| 176 | 205 | //getting the aircraft image |
| 177 | - if ($globalDebug && $name != '') echo 'Try to find an vessel image for '.$name.'...'; |
|
| 206 | + if ($globalDebug && $name != '') { |
|
| 207 | + echo 'Try to find an vessel image for '.$name.'...'; |
|
| 208 | + } |
|
| 178 | 209 | $image_url = $this->findMarineImage($mmsi,$imo,$name); |
| 179 | 210 | if ($image_url['original'] != '') { |
| 180 | - if ($globalDebug) echo 'Found !'."\n"; |
|
| 211 | + if ($globalDebug) { |
|
| 212 | + echo 'Found !'."\n"; |
|
| 213 | + } |
|
| 181 | 214 | $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)"; |
| 182 | 215 | try { |
| 183 | 216 | $sth = $this->db->prepare($query); |
@@ -186,7 +219,9 @@ discard block |
||
| 186 | 219 | echo $e->getMessage()."\n"; |
| 187 | 220 | return "error"; |
| 188 | 221 | } |
| 189 | - } elseif ($globalDebug) echo "Not found :'(\n"; |
|
| 222 | + } elseif ($globalDebug) { |
|
| 223 | + echo "Not found :'(\n"; |
|
| 224 | + } |
|
| 190 | 225 | return "success"; |
| 191 | 226 | } |
| 192 | 227 | |
@@ -202,41 +237,85 @@ discard block |
||
| 202 | 237 | { |
| 203 | 238 | global $globalAircraftImageSources, $globalIVAO, $globalAircraftImageCheckICAO, $globalVA; |
| 204 | 239 | $Spotter = new Spotter($this->db); |
| 205 | - if (!isset($globalIVAO)) $globalIVAO = FALSE; |
|
| 240 | + if (!isset($globalIVAO)) { |
|
| 241 | + $globalIVAO = FALSE; |
|
| 242 | + } |
|
| 206 | 243 | $aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING); |
| 207 | 244 | if ($aircraft_registration != '' && $aircraft_registration != 'NA' && (!isset($globalVA) || $globalVA !== TRUE)) { |
| 208 | - if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 245 | + if (strpos($aircraft_registration,'/') !== false) { |
|
| 246 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 247 | + } |
|
| 209 | 248 | $aircraft_registration = urlencode(trim($aircraft_registration)); |
| 210 | 249 | $aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration); |
| 211 | - if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name']; |
|
| 212 | - else $aircraft_name = ''; |
|
| 213 | - if (isset($aircraft_info[0]['aircraft_icao'])) $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
|
| 214 | - else $aircraft_icao = ''; |
|
| 215 | - if (isset($aircraft_info[0]['airline_icao'])) $airline_icao = $aircraft_info[0]['airline_icao']; |
|
| 216 | - else $airline_icao = ''; |
|
| 250 | + if (isset($aircraft_info[0]['aircraft_name'])) { |
|
| 251 | + $aircraft_name = $aircraft_info[0]['aircraft_name']; |
|
| 252 | + } else { |
|
| 253 | + $aircraft_name = ''; |
|
| 254 | + } |
|
| 255 | + if (isset($aircraft_info[0]['aircraft_icao'])) { |
|
| 256 | + $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
|
| 257 | + } else { |
|
| 258 | + $aircraft_icao = ''; |
|
| 259 | + } |
|
| 260 | + if (isset($aircraft_info[0]['airline_icao'])) { |
|
| 261 | + $airline_icao = $aircraft_info[0]['airline_icao']; |
|
| 262 | + } else { |
|
| 263 | + $airline_icao = ''; |
|
| 264 | + } |
|
| 217 | 265 | } elseif ($aircraft_icao != '') { |
| 218 | 266 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_icao); |
| 219 | - if (isset($aircraft_info[0]['type'])) $aircraft_name = $aircraft_info[0]['type']; |
|
| 220 | - else $aircraft_name = ''; |
|
| 267 | + if (isset($aircraft_info[0]['type'])) { |
|
| 268 | + $aircraft_name = $aircraft_info[0]['type']; |
|
| 269 | + } else { |
|
| 270 | + $aircraft_name = ''; |
|
| 271 | + } |
|
| 221 | 272 | $aircraft_registration = $aircraft_icao; |
| 222 | - } else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 273 | + } else { |
|
| 274 | + return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 275 | + } |
|
| 223 | 276 | unset($Spotter); |
| 224 | - if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
|
| 277 | + if (!isset($globalAircraftImageSources)) { |
|
| 278 | + $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
|
| 279 | + } |
|
| 225 | 280 | foreach ($globalAircraftImageSources as $source) { |
| 226 | 281 | $source = strtolower($source); |
| 227 | - if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao); |
|
| 228 | - if ($source == 'planespotters' && !$globalIVAO && extension_loaded('simplexml')) $images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name); |
|
| 229 | - if ($source == 'flickr' && extension_loaded('simplexml')) $images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name); |
|
| 230 | - if ($source == 'bing') $images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name); |
|
| 231 | - if ($source == 'deviantart' && extension_loaded('simplexml')) $images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name); |
|
| 232 | - if ($source == 'wikimedia') $images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name); |
|
| 233 | - if ($source == 'jetphotos' && !$globalIVAO && class_exists("DomDocument")) $images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name); |
|
| 234 | - if ($source == 'planepictures' && !$globalIVAO && class_exists("DomDocument")) $images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name); |
|
| 235 | - if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name); |
|
| 236 | - if ($source == 'customsources') $images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name); |
|
| 237 | - if (isset($images_array) && $images_array['original'] != '') return $images_array; |
|
| 238 | - } |
|
| 239 | - if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) return $this->findAircraftImage($aircraft_icao); |
|
| 282 | + if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') { |
|
| 283 | + $images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao); |
|
| 284 | + } |
|
| 285 | + if ($source == 'planespotters' && !$globalIVAO && extension_loaded('simplexml')) { |
|
| 286 | + $images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name); |
|
| 287 | + } |
|
| 288 | + if ($source == 'flickr' && extension_loaded('simplexml')) { |
|
| 289 | + $images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name); |
|
| 290 | + } |
|
| 291 | + if ($source == 'bing') { |
|
| 292 | + $images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name); |
|
| 293 | + } |
|
| 294 | + if ($source == 'deviantart' && extension_loaded('simplexml')) { |
|
| 295 | + $images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name); |
|
| 296 | + } |
|
| 297 | + if ($source == 'wikimedia') { |
|
| 298 | + $images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name); |
|
| 299 | + } |
|
| 300 | + if ($source == 'jetphotos' && !$globalIVAO && class_exists("DomDocument")) { |
|
| 301 | + $images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name); |
|
| 302 | + } |
|
| 303 | + if ($source == 'planepictures' && !$globalIVAO && class_exists("DomDocument")) { |
|
| 304 | + $images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name); |
|
| 305 | + } |
|
| 306 | + if ($source == 'airportdata' && !$globalIVAO) { |
|
| 307 | + $images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name); |
|
| 308 | + } |
|
| 309 | + if ($source == 'customsources') { |
|
| 310 | + $images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name); |
|
| 311 | + } |
|
| 312 | + if (isset($images_array) && $images_array['original'] != '') { |
|
| 313 | + return $images_array; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) { |
|
| 317 | + return $this->findAircraftImage($aircraft_icao); |
|
| 318 | + } |
|
| 240 | 319 | return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
| 241 | 320 | } |
| 242 | 321 | |
@@ -256,7 +335,9 @@ discard block |
||
| 256 | 335 | //$imo = filter_var($imo,FILTER_SANITIZE_STRING); |
| 257 | 336 | $name = filter_var($name,FILTER_SANITIZE_STRING); |
| 258 | 337 | $name = trim($name); |
| 259 | - if (strlen($name) < 4) return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 338 | + if (strlen($name) < 4) { |
|
| 339 | + return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
| 340 | + } |
|
| 260 | 341 | /* |
| 261 | 342 | $Marine = new Marine($this->db); |
| 262 | 343 | if ($imo == '' || $name == '') { |
@@ -268,15 +349,29 @@ discard block |
||
| 268 | 349 | } |
| 269 | 350 | unset($Marine); |
| 270 | 351 | */ |
| 271 | - if (!isset($globalMarineImageSources)) $globalMarineImageSources = array('wikimedia','deviantart','flickr','bing'); |
|
| 352 | + if (!isset($globalMarineImageSources)) { |
|
| 353 | + $globalMarineImageSources = array('wikimedia','deviantart','flickr','bing'); |
|
| 354 | + } |
|
| 272 | 355 | foreach ($globalMarineImageSources as $source) { |
| 273 | 356 | $source = strtolower($source); |
| 274 | - if ($source == 'flickr') $images_array = $this->fromFlickr('marine',$mmsi,$name); |
|
| 275 | - if ($source == 'bing') $images_array = $this->fromBing('marine',$mmsi,$name); |
|
| 276 | - if ($source == 'deviantart') $images_array = $this->fromDeviantart('marine',$mmsi,$name); |
|
| 277 | - if ($source == 'wikimedia') $images_array = $this->fromWikimedia('marine',$mmsi,$name); |
|
| 278 | - if ($source == 'customsources') $images_array = $this->fromCustomSource('marine',$mmsi,$name); |
|
| 279 | - if (isset($images_array) && $images_array['original'] != '') return $images_array; |
|
| 357 | + if ($source == 'flickr') { |
|
| 358 | + $images_array = $this->fromFlickr('marine',$mmsi,$name); |
|
| 359 | + } |
|
| 360 | + if ($source == 'bing') { |
|
| 361 | + $images_array = $this->fromBing('marine',$mmsi,$name); |
|
| 362 | + } |
|
| 363 | + if ($source == 'deviantart') { |
|
| 364 | + $images_array = $this->fromDeviantart('marine',$mmsi,$name); |
|
| 365 | + } |
|
| 366 | + if ($source == 'wikimedia') { |
|
| 367 | + $images_array = $this->fromWikimedia('marine',$mmsi,$name); |
|
| 368 | + } |
|
| 369 | + if ($source == 'customsources') { |
|
| 370 | + $images_array = $this->fromCustomSource('marine',$mmsi,$name); |
|
| 371 | + } |
|
| 372 | + if (isset($images_array) && $images_array['original'] != '') { |
|
| 373 | + return $images_array; |
|
| 374 | + } |
|
| 280 | 375 | } |
| 281 | 376 | return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
| 282 | 377 | } |
@@ -299,7 +394,9 @@ discard block |
||
| 299 | 394 | $url= 'http://www.planespotters.net/Aviation_Photos/search.php?reg='.$aircraft_registration.'&output=rss'; |
| 300 | 395 | } |
| 301 | 396 | $data = $Common->getData($url); |
| 302 | - if (substr($data, 0, 5) != "<?xml") return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 397 | + if (substr($data, 0, 5) != "<?xml") { |
|
| 398 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 399 | + } |
|
| 303 | 400 | if ($xml = simplexml_load_string($data)) { |
| 304 | 401 | if (isset($xml->channel->item)) { |
| 305 | 402 | $image_url = array(); |
@@ -338,7 +435,9 @@ discard block |
||
| 338 | 435 | $url= 'http://backend.deviantart.com/rss.xml?type=deviation&q="'.urlencode($name).'"'; |
| 339 | 436 | } |
| 340 | 437 | $data = $Common->getData($url); |
| 341 | - if (substr($data, 0, 5) != "<?xml") return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 438 | + if (substr($data, 0, 5) != "<?xml") { |
|
| 439 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 440 | + } |
|
| 342 | 441 | if ($xml = simplexml_load_string($data)) { |
| 343 | 442 | if (isset($xml->channel->item->link)) { |
| 344 | 443 | $image_url = array(); |
@@ -442,14 +541,22 @@ discard block |
||
| 442 | 541 | public function fromFlickr($type,$registration,$name='') { |
| 443 | 542 | $Common = new Common(); |
| 444 | 543 | if ($type == 'aircraft') { |
| 445 | - 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); |
|
| 446 | - 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'; |
|
| 544 | + if ($name != '') { |
|
| 545 | + $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); |
|
| 546 | + } else { |
|
| 547 | + $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'; |
|
| 548 | + } |
|
| 447 | 549 | } elseif ($type == 'marine') { |
| 448 | - 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); |
|
| 449 | - 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'; |
|
| 550 | + if ($name != '') { |
|
| 551 | + $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); |
|
| 552 | + } else { |
|
| 553 | + $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'; |
|
| 554 | + } |
|
| 450 | 555 | } |
| 451 | 556 | $data = $Common->getData($url); |
| 452 | - if (substr($data, 0, 5) != "<?xml") return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 557 | + if (substr($data, 0, 5) != "<?xml") { |
|
| 558 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 559 | + } |
|
| 453 | 560 | if ($xml = simplexml_load_string($data)) { |
| 454 | 561 | if (isset($xml->channel->item)) { |
| 455 | 562 | $original_url = trim((string)$xml->channel->item->enclosure->attributes()->url); |
@@ -498,13 +605,21 @@ discard block |
||
| 498 | 605 | public function fromBing($type,$aircraft_registration,$aircraft_name='') { |
| 499 | 606 | global $globalImageBingKey; |
| 500 | 607 | $Common = new Common(); |
| 501 | - if (!isset($globalImageBingKey) || $globalImageBingKey == '') return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 608 | + if (!isset($globalImageBingKey) || $globalImageBingKey == '') { |
|
| 609 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 610 | + } |
|
| 502 | 611 | if ($type == 'aircraft') { |
| 503 | - 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'; |
|
| 504 | - 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'; |
|
| 612 | + if ($aircraft_name != '') { |
|
| 613 | + $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'; |
|
| 614 | + } else { |
|
| 615 | + $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'; |
|
| 616 | + } |
|
| 505 | 617 | } elseif ($type == 'marine') { |
| 506 | - 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'; |
|
| 507 | - 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'; |
|
| 618 | + if ($aircraft_name != '') { |
|
| 619 | + $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'; |
|
| 620 | + } else { |
|
| 621 | + $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'; |
|
| 622 | + } |
|
| 508 | 623 | } |
| 509 | 624 | $headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey)); |
| 510 | 625 | $data = $Common->getData($url,'get','',$headers); |
@@ -560,17 +675,25 @@ discard block |
||
| 560 | 675 | public function fromWikimedia($type,$registration,$name='') { |
| 561 | 676 | $Common = new Common(); |
| 562 | 677 | if ($type == 'aircraft') { |
| 563 | - 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); |
|
| 564 | - else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft'; |
|
| 678 | + if ($name != '') { |
|
| 679 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20'.urlencode($name); |
|
| 680 | + } else { |
|
| 681 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft'; |
|
| 682 | + } |
|
| 565 | 683 | } elseif ($type == 'marine') { |
| 566 | - 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"'; |
|
| 567 | - else return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 684 | + if ($name != '') { |
|
| 685 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.urlencode($name).'%20ship"'; |
|
| 686 | + } else { |
|
| 687 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 688 | + } |
|
| 568 | 689 | } |
| 569 | 690 | $data = $Common->getData($url); |
| 570 | 691 | $result = json_decode($data); |
| 571 | 692 | if (isset($result->query->search[0]->title)) { |
| 572 | 693 | $fileo = $result->query->search[0]->title; |
| 573 | - if (substr($fileo,-3) == 'pdf') return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 694 | + if (substr($fileo,-3) == 'pdf') { |
|
| 695 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 696 | + } |
|
| 574 | 697 | $file = urlencode($fileo); |
| 575 | 698 | $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; |
| 576 | 699 | $data2 = $Common->getData($url2); |
@@ -641,18 +764,27 @@ discard block |
||
| 641 | 764 | $image_url = array(); |
| 642 | 765 | $image_url['thumbnail'] = $url_thumbnail; |
| 643 | 766 | $image_url['original'] = $url; |
| 644 | - if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
|
| 645 | - else $exifCopyright = ''; |
|
| 646 | - if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
|
| 647 | - elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
|
| 648 | - else $image_url['copyright'] = $source['source_website']; |
|
| 767 | + if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) { |
|
| 768 | + $exifCopyright = $this->getExifCopyright($url); |
|
| 769 | + } else { |
|
| 770 | + $exifCopyright = ''; |
|
| 771 | + } |
|
| 772 | + if ($exifCopyright != '') { |
|
| 773 | + $image_url['copyright'] = $exifCopyright; |
|
| 774 | + } elseif (isset($source['copyright'])) { |
|
| 775 | + $image_url['copyright'] = $source['copyright']; |
|
| 776 | + } else { |
|
| 777 | + $image_url['copyright'] = $source['source_website']; |
|
| 778 | + } |
|
| 649 | 779 | $image_url['source_website'] = $source['source_website']; |
| 650 | 780 | $image_url['source'] = $source['source']; |
| 651 | 781 | return $image_url; |
| 652 | 782 | } |
| 653 | 783 | } |
| 654 | 784 | return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
| 655 | - } else return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 785 | + } else { |
|
| 786 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
| 787 | + } |
|
| 656 | 788 | |
| 657 | 789 | if (!empty($globalMarineImageCustomSources) && $type == 'marine') { |
| 658 | 790 | $customsources = array(); |
@@ -678,18 +810,27 @@ discard block |
||
| 678 | 810 | $image_url = array(); |
| 679 | 811 | $image_url['thumbnail'] = $url_thumbnail; |
| 680 | 812 | $image_url['original'] = $url; |
| 681 | - if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
|
| 682 | - else $exifCopyright = ''; |
|
| 683 | - if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
|
| 684 | - elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
|
| 685 | - else $image_url['copyright'] = $source['source_website']; |
|
| 813 | + if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) { |
|
| 814 | + $exifCopyright = $this->getExifCopyright($url); |
|
| 815 | + } else { |
|
| 816 | + $exifCopyright = ''; |
|
| 817 | + } |
|
| 818 | + if ($exifCopyright != '') { |
|
| 819 | + $image_url['copyright'] = $exifCopyright; |
|
| 820 | + } elseif (isset($source['copyright'])) { |
|
| 821 | + $image_url['copyright'] = $source['copyright']; |
|
| 822 | + } else { |
|
| 823 | + $image_url['copyright'] = $source['source_website']; |
|
| 824 | + } |
|
| 686 | 825 | $image_url['source_website'] = $source['source_website']; |
| 687 | 826 | $image_url['source'] = $source['source']; |
| 688 | 827 | return $image_url; |
| 689 | 828 | } |
| 690 | 829 | } |
| 691 | 830 | return false; |
| 692 | - } else return false; |
|
| 831 | + } else { |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 693 | 834 | } |
| 694 | 835 | } |
| 695 | 836 | |