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