@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $Connection = new Connection(); |
| 69 | 69 | $sth = $Connection->db->prepare($query); |
| 70 | 70 | $sth->execute(); |
| 71 | - } catch(PDOException $e) { |
|
| 71 | + } catch (PDOException $e) { |
|
| 72 | 72 | return "error : ".$e->getMessage(); |
| 73 | 73 | } |
| 74 | 74 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $Connection = new Connection(); |
| 88 | 88 | $sth = $Connection->db->prepare($query); |
| 89 | 89 | $sth->execute(); |
| 90 | - } catch(PDOException $e) { |
|
| 90 | + } catch (PDOException $e) { |
|
| 91 | 91 | return "error : ".$e->getMessage(); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | public function parse($data) { |
| 101 | 101 | //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
| 102 | 102 | $codes = implode('|', array_keys($this->texts)); |
| 103 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 103 | + $regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#'; |
|
| 104 | 104 | //$pieces = explode(' ',$data); |
| 105 | - $pieces = preg_split('/\s/',$data); |
|
| 105 | + $pieces = preg_split('/\s/', $data); |
|
| 106 | 106 | $pos = 0; |
| 107 | 107 | if ($pieces[0] == 'METAR') $pos++; |
| 108 | 108 | elseif ($pieces[0] == 'SPECI') $pos++; |
@@ -112,25 +112,25 @@ discard block |
||
| 112 | 112 | $result['location'] = $pieces[$pos]; |
| 113 | 113 | $pos++; |
| 114 | 114 | if (!isset($pieces[$pos])) return $result; |
| 115 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 116 | - $result['time'] = substr($pieces[$pos],2,4); |
|
| 115 | + $result['dayofmonth'] = substr($pieces[$pos], 0, 2); |
|
| 116 | + $result['time'] = substr($pieces[$pos], 2, 4); |
|
| 117 | 117 | $c = count($pieces); |
| 118 | - for($pos++; $pos < $c; $pos++) { |
|
| 118 | + for ($pos++; $pos < $c; $pos++) { |
|
| 119 | 119 | $piece = $pieces[$pos]; |
| 120 | 120 | if ($piece == 'RMK') break; |
| 121 | 121 | if ($piece == 'AUTO') $result['auto'] = true; |
| 122 | 122 | if ($piece == 'COR') $result['correction'] = true; |
| 123 | 123 | // Wind Speed |
| 124 | 124 | 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 | - $result['wind']['direction'] = (float)$matches[1]; |
|
| 125 | + $result['wind']['direction'] = (float) $matches[1]; |
|
| 126 | 126 | $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); |
|
| 130 | - $result['wind']['gust'] = (float)$matches[3]; |
|
| 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); |
|
| 130 | + $result['wind']['gust'] = (float) $matches[3]; |
|
| 131 | 131 | $result['wind']['unit'] = $matches[4]; |
| 132 | - $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
|
| 133 | - $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
|
| 132 | + $result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0; |
|
| 133 | + $result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Temperature |
| 153 | 153 | if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
| 154 | - $temp = (float)$matches[1]; |
|
| 154 | + $temp = (float) $matches[1]; |
|
| 155 | 155 | if ($matches[1]{0} == 'M') { |
| 156 | - $temp = ((float)substr($matches[1], 1)) * -1; |
|
| 156 | + $temp = ((float) substr($matches[1], 1))*-1; |
|
| 157 | 157 | } |
| 158 | 158 | $result['temperature'] = $temp; |
| 159 | - $dew = (float)$matches[2]; |
|
| 159 | + $dew = (float) $matches[2]; |
|
| 160 | 160 | if ($matches[2]{0} == 'M') { |
| 161 | - $dew = ((float)substr($matches[2], 1)) * -1; |
|
| 161 | + $dew = ((float) substr($matches[2], 1))*-1; |
|
| 162 | 162 | } |
| 163 | 163 | $result['dew'] = $dew; |
| 164 | - $result['rh'] = 100*(exp((17.625*$dew)/(243.04+$dew))/exp((17.625*$temp)/(243.04+$temp))); |
|
| 164 | + $result['rh'] = 100*(exp((17.625*$dew)/(243.04 + $dew))/exp((17.625*$temp)/(243.04 + $temp))); |
|
| 165 | 165 | } |
| 166 | 166 | // QNH |
| 167 | 167 | if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $result['QNH'] = $matches[2]; |
| 172 | 172 | } else { |
| 173 | 173 | // inHg |
| 174 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 174 | + $result['QNH'] = round(($matches[2]/100)*33.86389, 2); |
|
| 175 | 175 | } |
| 176 | 176 | /* |
| 177 | 177 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
@@ -192,12 +192,12 @@ discard block |
||
| 192 | 192 | // Visibility |
| 193 | 193 | if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
| 194 | 194 | if (isset($matches[3]) && strlen($matches[3]) > 0) { |
| 195 | - $result['visibility'] = (float)$matches[3] * 1609.34; |
|
| 195 | + $result['visibility'] = (float) $matches[3]*1609.34; |
|
| 196 | 196 | } else { |
| 197 | 197 | if ($matches[1] == '9999') { |
| 198 | 198 | $result['visibility'] = '> 10000'; |
| 199 | 199 | } else { |
| 200 | - $result['visibility'] = (float)$matches[1]; |
|
| 200 | + $result['visibility'] = (float) $matches[1]; |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | if (preg_match('#^CAVOK$#', $piece, $matches)) { |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
| 220 | 220 | elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
| 221 | 221 | $cloud['type_code'] = $type; |
| 222 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 222 | + $cloud['level'] = round(((float) $matches[2])*100*0.3048); |
|
| 223 | 223 | if (isset($matches[3])) $significant = $matches[3]; |
| 224 | 224 | else $significant = ''; |
| 225 | 225 | if ($significant == 'CB') $cloud['significant'] = 'Cumulonimbus'; |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | $rvr['runway'] = $matches[1]; |
| 241 | 241 | $rvr['assessment'] = $matches[2]; |
| 242 | 242 | $rvr['rvr'] = $matches[3]; |
| 243 | - $rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0; |
|
| 244 | - $rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : ''; |
|
| 243 | + $rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0; |
|
| 244 | + $rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : ''; |
|
| 245 | 245 | $result['RVR'] = $rvr; |
| 246 | 246 | } |
| 247 | 247 | //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
@@ -254,12 +254,12 @@ discard block |
||
| 254 | 254 | $result['RVR']['friction'] = $matches[5]; |
| 255 | 255 | } |
| 256 | 256 | 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'); |
|
| 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'); |
|
| 259 | 259 | if (isset($matches[3])) { |
| 260 | 260 | $range = Array( |
| 261 | - 'from' => (float)$matches[2], |
|
| 262 | - 'to' => (float)$matches[4], |
|
| 261 | + 'from' => (float) $matches[2], |
|
| 262 | + 'to' => (float) $matches[4], |
|
| 263 | 263 | 'unit' => $matches[5] ? 'FT' : 'M' |
| 264 | 264 | ); |
| 265 | 265 | } |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | try { |
| 313 | 313 | $sth = $this->db->prepare($query); |
| 314 | 314 | $sth->execute($query_values); |
| 315 | - } catch(PDOException $e) { |
|
| 315 | + } catch (PDOException $e) { |
|
| 316 | 316 | return "error : ".$e->getMessage(); |
| 317 | 317 | } |
| 318 | 318 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -328,19 +328,19 @@ discard block |
||
| 328 | 328 | * @param String $metar METAR text |
| 329 | 329 | * @param String $date date of the METAR |
| 330 | 330 | */ |
| 331 | - public function addMETAR($location,$metar,$date) { |
|
| 331 | + public function addMETAR($location, $metar, $date) { |
|
| 332 | 332 | global $globalDBdriver; |
| 333 | - $date = date('Y-m-d H:i:s',strtotime($date)); |
|
| 333 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 334 | 334 | if ($globalDBdriver == 'mysql') { |
| 335 | 335 | $query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar"; |
| 336 | 336 | } else { |
| 337 | 337 | $query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);"; |
| 338 | 338 | } |
| 339 | - $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar)); |
|
| 339 | + $query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar)); |
|
| 340 | 340 | try { |
| 341 | 341 | $sth = $this->db->prepare($query); |
| 342 | 342 | $sth->execute($query_values); |
| 343 | - } catch(PDOException $e) { |
|
| 343 | + } catch (PDOException $e) { |
|
| 344 | 344 | return "error : ".$e->getMessage(); |
| 345 | 345 | } |
| 346 | 346 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | try { |
| 356 | 356 | $sth = $this->db->prepare($query); |
| 357 | 357 | $sth->execute($query_values); |
| 358 | - } catch(PDOException $e) { |
|
| 358 | + } catch (PDOException $e) { |
|
| 359 | 359 | return "error : ".$e->getMessage(); |
| 360 | 360 | } |
| 361 | 361 | } |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | try { |
| 369 | 369 | $sth = $this->db->prepare($query); |
| 370 | 370 | $sth->execute(); |
| 371 | - } catch(PDOException $e) { |
|
| 371 | + } catch (PDOException $e) { |
|
| 372 | 372 | return "error : ".$e->getMessage(); |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -382,29 +382,29 @@ discard block |
||
| 382 | 382 | date_default_timezone_set("UTC"); |
| 383 | 383 | $Common = new Common(); |
| 384 | 384 | if (isset($globalIVAO) && $globalIVAO) { |
| 385 | - $Common->download('http://wx.ivao.aero/metar.php',dirname(__FILE__).'/../install/tmp/ivaometar.txt'); |
|
| 386 | - $handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r"); |
|
| 385 | + $Common->download('http://wx.ivao.aero/metar.php', dirname(__FILE__).'/../install/tmp/ivaometar.txt'); |
|
| 386 | + $handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt', "r"); |
|
| 387 | 387 | } else { |
| 388 | - $Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT',dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT'); |
|
| 389 | - $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r"); |
|
| 388 | + $Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT', dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT'); |
|
| 389 | + $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT', "r"); |
|
| 390 | 390 | } |
| 391 | 391 | if ($handle) { |
| 392 | 392 | if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
| 393 | 393 | $date = ''; |
| 394 | 394 | if ($globalTransaction) $this->db->beginTransaction(); |
| 395 | - while(($line = fgets($handle,4096)) !== false) { |
|
| 396 | - $line = str_replace(array("\r\n","\r", "\n"), '', $line); |
|
| 397 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 395 | + while (($line = fgets($handle, 4096)) !== false) { |
|
| 396 | + $line = str_replace(array("\r\n", "\r", "\n"), '', $line); |
|
| 397 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 398 | 398 | $date = $line; |
| 399 | 399 | } elseif (trim($line) != '') { |
| 400 | 400 | if ($date == '') $date = date('Y/m/d H:m'); |
| 401 | 401 | $pos = 0; |
| 402 | - $pieces = preg_split('/\s/',$line); |
|
| 402 | + $pieces = preg_split('/\s/', $line); |
|
| 403 | 403 | if ($pieces[0] == 'METAR') $pos++; |
| 404 | 404 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 405 | 405 | $location = $pieces[$pos]; |
| 406 | 406 | //echo 'location: '.$location.' - date: '.$date.' - data: '.$line."\n"; |
| 407 | - echo $this->addMETAR($location,$line,$date); |
|
| 407 | + echo $this->addMETAR($location, $line, $date); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | fclose($handle); |
@@ -423,23 +423,23 @@ discard block |
||
| 423 | 423 | if ($globalMETARurl == '') return array(); |
| 424 | 424 | date_default_timezone_set("UTC"); |
| 425 | 425 | $Common = new Common(); |
| 426 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 426 | + $url = str_replace('{icao}', $icao, $globalMETARurl); |
|
| 427 | 427 | $cycle = $Common->getData($url); |
| 428 | 428 | $date = ''; |
| 429 | - foreach(explode("\n",$cycle) as $line) { |
|
| 430 | - $line = str_replace(array("\r\n","\r", "\n"), '', $line); |
|
| 431 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 429 | + foreach (explode("\n", $cycle) as $line) { |
|
| 430 | + $line = str_replace(array("\r\n", "\r", "\n"), '', $line); |
|
| 431 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 432 | 432 | $date = $line; |
| 433 | 433 | } |
| 434 | 434 | if (trim($line) != '') { |
| 435 | 435 | if ($date == '') $date = date('Y/m/d H:m'); |
| 436 | 436 | $pos = 0; |
| 437 | - $pieces = preg_split('/\s/',$line); |
|
| 437 | + $pieces = preg_split('/\s/', $line); |
|
| 438 | 438 | if ($pieces[0] == 'METAR') $pos++; |
| 439 | 439 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 440 | 440 | $location = $pieces[$pos]; |
| 441 | 441 | if (strlen($location == 4)) { |
| 442 | - $this->addMETAR($location,$line,$date); |
|
| 442 | + $this->addMETAR($location, $line, $date); |
|
| 443 | 443 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
| 444 | 444 | } else return array(); |
| 445 | 445 | } |
@@ -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(); |