@@ -59,8 +59,11 @@ discard block |
||
59 | 59 | } |
60 | 60 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
61 | 61 | $sth->closeCursor(); |
62 | - if ($row['nb'] > 0) return false; |
|
63 | - else return true; |
|
62 | + if ($row['nb'] > 0) { |
|
63 | + return false; |
|
64 | + } else { |
|
65 | + return true; |
|
66 | + } |
|
64 | 67 | } |
65 | 68 | |
66 | 69 | public static function insert_last_update() { |
@@ -84,9 +87,14 @@ discard block |
||
84 | 87 | //$pieces = explode(' ',$data); |
85 | 88 | $pieces = preg_split('/\s/',$data); |
86 | 89 | $pos = 0; |
87 | - if ($pieces[0] == 'METAR') $pos++; |
|
88 | - elseif ($pieces[0] == 'SPECI') $pos++; |
|
89 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
90 | + if ($pieces[0] == 'METAR') { |
|
91 | + $pos++; |
|
92 | + } elseif ($pieces[0] == 'SPECI') { |
|
93 | + $pos++; |
|
94 | + } |
|
95 | + if (strlen($pieces[$pos]) != 4) { |
|
96 | + $pos++; |
|
97 | + } |
|
90 | 98 | $result = array(); |
91 | 99 | $result['location'] = $pieces[$pos]; |
92 | 100 | $pos++; |
@@ -95,16 +103,26 @@ discard block |
||
95 | 103 | $c = count($pieces); |
96 | 104 | for($pos++; $pos < $c; $pos++) { |
97 | 105 | $piece = $pieces[$pos]; |
98 | - if ($piece == 'RMK') break; |
|
99 | - if ($piece == 'AUTO') $result['auto'] = true; |
|
100 | - if ($piece == 'COR') $result['correction'] = true; |
|
106 | + if ($piece == 'RMK') { |
|
107 | + break; |
|
108 | + } |
|
109 | + if ($piece == 'AUTO') { |
|
110 | + $result['auto'] = true; |
|
111 | + } |
|
112 | + if ($piece == 'COR') { |
|
113 | + $result['correction'] = true; |
|
114 | + } |
|
101 | 115 | // Wind Speed |
102 | 116 | if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
103 | 117 | $result['wind']['direction'] = (float)$matches[1]; |
104 | 118 | $result['wind']['unit'] = $matches[4]; |
105 | - if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
106 | - elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
107 | - elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
119 | + if ($result['wind']['unit'] == 'KT') { |
|
120 | + $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
121 | + } elseif ($result['wind']['unit'] == 'KPH') { |
|
122 | + $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
123 | + } elseif ($result['wind']['unit'] == 'MPS') { |
|
124 | + $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
125 | + } |
|
108 | 126 | $result['wind']['gust'] = (float)$matches[3]; |
109 | 127 | $result['wind']['unit'] = $matches[4]; |
110 | 128 | $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
@@ -186,14 +204,23 @@ discard block |
||
186 | 204 | //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
187 | 205 | $type = $matches[1]; |
188 | 206 | $cloud = array(); |
189 | - if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear'; |
|
190 | - elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
191 | - elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud'; |
|
192 | - elseif ($type == 'FEW') $cloud['type'] = 'Few'; |
|
193 | - elseif ($type == 'SCT') $cloud['type'] = 'Scattered'; |
|
194 | - elseif ($type == 'BKN') $cloud['type'] = 'Broken'; |
|
195 | - elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
196 | - elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
|
207 | + if ($type == 'SKC') { |
|
208 | + $cloud['type'] = 'No cloud/Sky clear'; |
|
209 | + } elseif ($type == 'CLR') { |
|
210 | + $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
211 | + } elseif ($type == 'NSC') { |
|
212 | + $cloud['type'] = 'No significant cloud'; |
|
213 | + } elseif ($type == 'FEW') { |
|
214 | + $cloud['type'] = 'Few'; |
|
215 | + } elseif ($type == 'SCT') { |
|
216 | + $cloud['type'] = 'Scattered'; |
|
217 | + } elseif ($type == 'BKN') { |
|
218 | + $cloud['type'] = 'Broken'; |
|
219 | + } elseif ($type == 'OVC') { |
|
220 | + $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
221 | + } elseif ($type == 'VV') { |
|
222 | + $cloud['type'] = 'Vertical visibility'; |
|
223 | + } |
|
197 | 224 | $cloud['type_code'] = $type; |
198 | 225 | $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
199 | 226 | $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
@@ -223,8 +250,11 @@ discard block |
||
223 | 250 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
224 | 251 | //echo $piece; |
225 | 252 | //print_r($matches); |
226 | - if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
227 | - else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
253 | + if (isset($matches[5])) { |
|
254 | + $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
255 | + } else { |
|
256 | + $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
257 | + } |
|
228 | 258 | if (isset($matches[3])) { |
229 | 259 | $range = Array( |
230 | 260 | 'from' => (float)$matches[2], |
@@ -257,8 +287,11 @@ discard block |
||
257 | 287 | if (isset($matches[3])) { |
258 | 288 | $text[] = $this->texts[$matches[3]]; |
259 | 289 | } |
260 | - if (!isset($result['weather'])) $result['weather'] = implode(' ', $text); |
|
261 | - else $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
|
290 | + if (!isset($result['weather'])) { |
|
291 | + $result['weather'] = implode(' ', $text); |
|
292 | + } else { |
|
293 | + $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
|
294 | + } |
|
262 | 295 | } |
263 | 296 | } |
264 | 297 | return $result; |
@@ -270,8 +303,11 @@ discard block |
||
270 | 303 | if (isset($globalMETARcycle) && $globalMETARcycle) { |
271 | 304 | $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
272 | 305 | } else { |
273 | - if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
274 | - else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
306 | + if ($globalDBdriver == 'mysql') { |
|
307 | + $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
308 | + } else { |
|
309 | + $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
310 | + } |
|
275 | 311 | } |
276 | 312 | $query_values = array(':icao' => $icao); |
277 | 313 | try { |
@@ -326,7 +362,9 @@ discard block |
||
326 | 362 | |
327 | 363 | public function addMETARCycle() { |
328 | 364 | global $globalDebug, $globalIVAO; |
329 | - if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
365 | + if (isset($globalDebug) && $globalDebug) { |
|
366 | + echo "Downloading METAR cycle..."; |
|
367 | + } |
|
330 | 368 | date_default_timezone_set("UTC"); |
331 | 369 | $Common = new Common(); |
332 | 370 | if (isset($globalIVAO) && $globalIVAO) { |
@@ -339,7 +377,9 @@ discard block |
||
339 | 377 | $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r"); |
340 | 378 | } |
341 | 379 | if ($handle) { |
342 | - if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
380 | + if (isset($globalDebug) && $globalDebug) { |
|
381 | + echo "Done - Updating DB..."; |
|
382 | + } |
|
343 | 383 | $date = ''; |
344 | 384 | //foreach(explode("\n",$cycle) as $line) { |
345 | 385 | while(($line = fgets($handle,4096)) !== false) { |
@@ -347,23 +387,33 @@ discard block |
||
347 | 387 | $date = $line; |
348 | 388 | } elseif ($line != '') { |
349 | 389 | //$this->parse($line); |
350 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
390 | + if ($date == '') { |
|
391 | + $date = date('Y/m/d H:m'); |
|
392 | + } |
|
351 | 393 | $pos = 0; |
352 | 394 | $pieces = preg_split('/\s/',$line); |
353 | - if ($pieces[0] == 'METAR') $pos++; |
|
354 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
395 | + if ($pieces[0] == 'METAR') { |
|
396 | + $pos++; |
|
397 | + } |
|
398 | + if (strlen($pieces[$pos]) != 4) { |
|
399 | + $pos++; |
|
400 | + } |
|
355 | 401 | $location = $pieces[$pos]; |
356 | 402 | echo $this->addMETAR($location,$line,$date); |
357 | 403 | } |
358 | 404 | } |
359 | 405 | fclose($handle); |
360 | 406 | } |
361 | - if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
407 | + if (isset($globalDebug) && $globalDebug) { |
|
408 | + echo "Done\n"; |
|
409 | + } |
|
362 | 410 | |
363 | 411 | } |
364 | 412 | public function downloadMETAR($icao) { |
365 | 413 | global $globalMETARurl; |
366 | - if ($globalMETARurl == '') return array(); |
|
414 | + if ($globalMETARurl == '') { |
|
415 | + return array(); |
|
416 | + } |
|
367 | 417 | date_default_timezone_set("UTC"); |
368 | 418 | $Common = new Common(); |
369 | 419 | $url = str_replace('{icao}',$icao,$globalMETARurl); |
@@ -377,16 +427,24 @@ discard block |
||
377 | 427 | if ($line != '') { |
378 | 428 | //$this->parse($line); |
379 | 429 | //echo $line; |
380 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
430 | + if ($date == '') { |
|
431 | + $date = date('Y/m/d H:m'); |
|
432 | + } |
|
381 | 433 | $pos = 0; |
382 | 434 | $pieces = preg_split('/\s/',$line); |
383 | - if ($pieces[0] == 'METAR') $pos++; |
|
384 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
435 | + if ($pieces[0] == 'METAR') { |
|
436 | + $pos++; |
|
437 | + } |
|
438 | + if (strlen($pieces[$pos]) != 4) { |
|
439 | + $pos++; |
|
440 | + } |
|
385 | 441 | $location = $pieces[$pos]; |
386 | 442 | if (strlen($location == 4)) { |
387 | 443 | $this->addMETAR($location,$line,$date); |
388 | 444 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
389 | - } else return array(); |
|
445 | + } else { |
|
446 | + return array(); |
|
447 | + } |
|
390 | 448 | } |
391 | 449 | //echo $line."\n"; |
392 | 450 | } |