@@ -73,8 +73,11 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 75 | 75 | $sth->closeCursor(); |
| 76 | - if ($row['nb'] > 0) return false; |
|
| 77 | - else return true; |
|
| 76 | + if ($row['nb'] > 0) { |
|
| 77 | + return false; |
|
| 78 | + } else { |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 78 | 81 | } |
| 79 | 82 | |
| 80 | 83 | /* |
@@ -104,29 +107,48 @@ discard block |
||
| 104 | 107 | //$pieces = explode(' ',$data); |
| 105 | 108 | $pieces = preg_split('/\s/',$data); |
| 106 | 109 | $pos = 0; |
| 107 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 108 | - elseif ($pieces[0] == 'SPECI') $pos++; |
|
| 109 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 110 | + if ($pieces[0] == 'METAR') { |
|
| 111 | + $pos++; |
|
| 112 | + } elseif ($pieces[0] == 'SPECI') { |
|
| 113 | + $pos++; |
|
| 114 | + } |
|
| 115 | + if (strlen($pieces[$pos]) != 4) { |
|
| 116 | + $pos++; |
|
| 117 | + } |
|
| 110 | 118 | $result = array(); |
| 111 | - if (!isset($pieces[$pos])) return $result; |
|
| 119 | + if (!isset($pieces[$pos])) { |
|
| 120 | + return $result; |
|
| 121 | + } |
|
| 112 | 122 | $result['location'] = $pieces[$pos]; |
| 113 | 123 | $pos++; |
| 114 | - if (!isset($pieces[$pos])) return $result; |
|
| 124 | + if (!isset($pieces[$pos])) { |
|
| 125 | + return $result; |
|
| 126 | + } |
|
| 115 | 127 | $result['dayofmonth'] = substr($pieces[$pos],0,2); |
| 116 | 128 | $result['time'] = substr($pieces[$pos],2,4); |
| 117 | 129 | $c = count($pieces); |
| 118 | 130 | for($pos++; $pos < $c; $pos++) { |
| 119 | 131 | $piece = $pieces[$pos]; |
| 120 | - if ($piece == 'RMK') break; |
|
| 121 | - if ($piece == 'AUTO') $result['auto'] = true; |
|
| 122 | - if ($piece == 'COR') $result['correction'] = true; |
|
| 132 | + if ($piece == 'RMK') { |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + if ($piece == 'AUTO') { |
|
| 136 | + $result['auto'] = true; |
|
| 137 | + } |
|
| 138 | + if ($piece == 'COR') { |
|
| 139 | + $result['correction'] = true; |
|
| 140 | + } |
|
| 123 | 141 | // Wind Speed |
| 124 | 142 | if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
| 125 | 143 | $result['wind']['direction'] = (float)$matches[1]; |
| 126 | 144 | $result['wind']['unit'] = $matches[4]; |
| 127 | - if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 128 | - elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 129 | - elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 145 | + if ($result['wind']['unit'] == 'KT') { |
|
| 146 | + $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 147 | + } elseif ($result['wind']['unit'] == 'KPH') { |
|
| 148 | + $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 149 | + } elseif ($result['wind']['unit'] == 'MPS') { |
|
| 150 | + $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 151 | + } |
|
| 130 | 152 | $result['wind']['gust'] = (float)$matches[3]; |
| 131 | 153 | $result['wind']['unit'] = $matches[4]; |
| 132 | 154 | $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
@@ -210,27 +232,49 @@ discard block |
||
| 210 | 232 | //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
| 211 | 233 | $type = $matches[1]; |
| 212 | 234 | $cloud = array(); |
| 213 | - if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear'; |
|
| 214 | - elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
| 215 | - elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud'; |
|
| 216 | - elseif ($type == 'FEW') $cloud['type'] = 'Few'; |
|
| 217 | - elseif ($type == 'SCT') $cloud['type'] = 'Scattered'; |
|
| 218 | - elseif ($type == 'BKN') $cloud['type'] = 'Broken'; |
|
| 219 | - elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
| 220 | - elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
|
| 235 | + if ($type == 'SKC') { |
|
| 236 | + $cloud['type'] = 'No cloud/Sky clear'; |
|
| 237 | + } elseif ($type == 'CLR') { |
|
| 238 | + $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
| 239 | + } elseif ($type == 'NSC') { |
|
| 240 | + $cloud['type'] = 'No significant cloud'; |
|
| 241 | + } elseif ($type == 'FEW') { |
|
| 242 | + $cloud['type'] = 'Few'; |
|
| 243 | + } elseif ($type == 'SCT') { |
|
| 244 | + $cloud['type'] = 'Scattered'; |
|
| 245 | + } elseif ($type == 'BKN') { |
|
| 246 | + $cloud['type'] = 'Broken'; |
|
| 247 | + } elseif ($type == 'OVC') { |
|
| 248 | + $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
| 249 | + } elseif ($type == 'VV') { |
|
| 250 | + $cloud['type'] = 'Vertical visibility'; |
|
| 251 | + } |
|
| 221 | 252 | $cloud['type_code'] = $type; |
| 222 | 253 | $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
| 223 | - if (isset($matches[3])) $significant = $matches[3]; |
|
| 224 | - else $significant = ''; |
|
| 225 | - if ($significant == 'CB') $cloud['significant'] = 'Cumulonimbus'; |
|
| 226 | - elseif ($significant == 'AC') $cloud['significant'] = 'Altocumulus'; |
|
| 227 | - elseif ($significant == 'CBS') $cloud['significant'] = 'Cumulonimbus'; |
|
| 228 | - elseif ($significant == 'CC') $cloud['significant'] = 'Cirrocumulus'; |
|
| 229 | - elseif ($significant == 'CU') $cloud['significant'] = 'Cumulus'; |
|
| 230 | - elseif ($significant == 'CI') $cloud['significant'] = 'Cirrus'; |
|
| 231 | - elseif ($significant == 'CS') $cloud['significant'] = 'Cirrostratus'; |
|
| 232 | - elseif ($significant == 'TCU') $cloud['significant'] = 'Towering Cumulus'; |
|
| 233 | - else $cloud['significant'] = $significant; |
|
| 254 | + if (isset($matches[3])) { |
|
| 255 | + $significant = $matches[3]; |
|
| 256 | + } else { |
|
| 257 | + $significant = ''; |
|
| 258 | + } |
|
| 259 | + if ($significant == 'CB') { |
|
| 260 | + $cloud['significant'] = 'Cumulonimbus'; |
|
| 261 | + } elseif ($significant == 'AC') { |
|
| 262 | + $cloud['significant'] = 'Altocumulus'; |
|
| 263 | + } elseif ($significant == 'CBS') { |
|
| 264 | + $cloud['significant'] = 'Cumulonimbus'; |
|
| 265 | + } elseif ($significant == 'CC') { |
|
| 266 | + $cloud['significant'] = 'Cirrocumulus'; |
|
| 267 | + } elseif ($significant == 'CU') { |
|
| 268 | + $cloud['significant'] = 'Cumulus'; |
|
| 269 | + } elseif ($significant == 'CI') { |
|
| 270 | + $cloud['significant'] = 'Cirrus'; |
|
| 271 | + } elseif ($significant == 'CS') { |
|
| 272 | + $cloud['significant'] = 'Cirrostratus'; |
|
| 273 | + } elseif ($significant == 'TCU') { |
|
| 274 | + $cloud['significant'] = 'Towering Cumulus'; |
|
| 275 | + } else { |
|
| 276 | + $cloud['significant'] = $significant; |
|
| 277 | + } |
|
| 234 | 278 | //$cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
| 235 | 279 | $result['cloud'][] = $cloud; |
| 236 | 280 | } |
@@ -254,8 +298,11 @@ discard block |
||
| 254 | 298 | $result['RVR']['friction'] = $matches[5]; |
| 255 | 299 | } |
| 256 | 300 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
| 257 | - if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 258 | - else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 301 | + if (isset($matches[5])) { |
|
| 302 | + $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 303 | + } else { |
|
| 304 | + $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 305 | + } |
|
| 259 | 306 | if (isset($matches[3])) { |
| 260 | 307 | $range = Array( |
| 261 | 308 | 'from' => (float)$matches[2], |
@@ -288,8 +335,11 @@ discard block |
||
| 288 | 335 | if (isset($matches[3])) { |
| 289 | 336 | $text[] = $this->texts[$matches[3]]; |
| 290 | 337 | } |
| 291 | - if (!isset($result['weather'])) $result['weather'] = implode(' ', $text); |
|
| 292 | - else $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
|
| 338 | + if (!isset($result['weather'])) { |
|
| 339 | + $result['weather'] = implode(' ', $text); |
|
| 340 | + } else { |
|
| 341 | + $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
|
| 342 | + } |
|
| 293 | 343 | } |
| 294 | 344 | } |
| 295 | 345 | return $result; |
@@ -305,8 +355,11 @@ discard block |
||
| 305 | 355 | if (isset($globalMETARcycle) && $globalMETARcycle) { |
| 306 | 356 | $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
| 307 | 357 | } else { |
| 308 | - if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
| 309 | - else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
| 358 | + if ($globalDBdriver == 'mysql') { |
|
| 359 | + $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
| 360 | + } else { |
|
| 361 | + $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
| 362 | + } |
|
| 310 | 363 | } |
| 311 | 364 | $query_values = array(':icao' => $icao); |
| 312 | 365 | try { |
@@ -378,7 +431,9 @@ discard block |
||
| 378 | 431 | */ |
| 379 | 432 | public function addMETARCycle() { |
| 380 | 433 | global $globalDebug, $globalIVAO, $globalTransaction; |
| 381 | - if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
| 434 | + if (isset($globalDebug) && $globalDebug) { |
|
| 435 | + echo "Downloading METAR cycle..."; |
|
| 436 | + } |
|
| 382 | 437 | date_default_timezone_set("UTC"); |
| 383 | 438 | $Common = new Common(); |
| 384 | 439 | if (isset($globalIVAO) && $globalIVAO) { |
@@ -389,28 +444,42 @@ discard block |
||
| 389 | 444 | $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r"); |
| 390 | 445 | } |
| 391 | 446 | if ($handle) { |
| 392 | - if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
| 447 | + if (isset($globalDebug) && $globalDebug) { |
|
| 448 | + echo "Done - Updating DB..."; |
|
| 449 | + } |
|
| 393 | 450 | $date = ''; |
| 394 | - if ($globalTransaction) $this->db->beginTransaction(); |
|
| 451 | + if ($globalTransaction) { |
|
| 452 | + $this->db->beginTransaction(); |
|
| 453 | + } |
|
| 395 | 454 | while(($line = fgets($handle,4096)) !== false) { |
| 396 | 455 | $line = str_replace(array("\r\n","\r", "\n"), '', $line); |
| 397 | 456 | if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
| 398 | 457 | $date = $line; |
| 399 | 458 | } elseif (trim($line) != '') { |
| 400 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 459 | + if ($date == '') { |
|
| 460 | + $date = date('Y/m/d H:m'); |
|
| 461 | + } |
|
| 401 | 462 | $pos = 0; |
| 402 | 463 | $pieces = preg_split('/\s/',$line); |
| 403 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 404 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 464 | + if ($pieces[0] == 'METAR') { |
|
| 465 | + $pos++; |
|
| 466 | + } |
|
| 467 | + if (strlen($pieces[$pos]) != 4) { |
|
| 468 | + $pos++; |
|
| 469 | + } |
|
| 405 | 470 | $location = $pieces[$pos]; |
| 406 | 471 | //echo 'location: '.$location.' - date: '.$date.' - data: '.$line."\n"; |
| 407 | 472 | echo $this->addMETAR($location,$line,$date); |
| 408 | 473 | } |
| 409 | 474 | } |
| 410 | 475 | fclose($handle); |
| 411 | - if ($globalTransaction) $this->db->commit(); |
|
| 476 | + if ($globalTransaction) { |
|
| 477 | + $this->db->commit(); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + if (isset($globalDebug) && $globalDebug) { |
|
| 481 | + echo "Done\n"; |
|
| 412 | 482 | } |
| 413 | - if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
| 414 | 483 | } |
| 415 | 484 | |
| 416 | 485 | /* |
@@ -420,7 +489,9 @@ discard block |
||
| 420 | 489 | */ |
| 421 | 490 | public function downloadMETAR($icao) { |
| 422 | 491 | global $globalMETARurl; |
| 423 | - if ($globalMETARurl == '') return array(); |
|
| 492 | + if ($globalMETARurl == '') { |
|
| 493 | + return array(); |
|
| 494 | + } |
|
| 424 | 495 | date_default_timezone_set("UTC"); |
| 425 | 496 | $Common = new Common(); |
| 426 | 497 | $url = str_replace('{icao}',$icao,$globalMETARurl); |
@@ -432,16 +503,24 @@ discard block |
||
| 432 | 503 | $date = $line; |
| 433 | 504 | } |
| 434 | 505 | if (trim($line) != '') { |
| 435 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 506 | + if ($date == '') { |
|
| 507 | + $date = date('Y/m/d H:m'); |
|
| 508 | + } |
|
| 436 | 509 | $pos = 0; |
| 437 | 510 | $pieces = preg_split('/\s/',$line); |
| 438 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 439 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 511 | + if ($pieces[0] == 'METAR') { |
|
| 512 | + $pos++; |
|
| 513 | + } |
|
| 514 | + if (strlen($pieces[$pos]) != 4) { |
|
| 515 | + $pos++; |
|
| 516 | + } |
|
| 440 | 517 | $location = $pieces[$pos]; |
| 441 | 518 | if (strlen($location == 4)) { |
| 442 | 519 | $this->addMETAR($location,$line,$date); |
| 443 | 520 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
| 444 | - } else return array(); |
|
| 521 | + } else { |
|
| 522 | + return array(); |
|
| 523 | + } |
|
| 445 | 524 | } |
| 446 | 525 | } |
| 447 | 526 | return array(); |