@@ -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 | return ''; |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | public function parse($data) { |
| 102 | 102 | //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
| 103 | 103 | $codes = implode('|', array_keys($this->texts)); |
| 104 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 104 | + $regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#'; |
|
| 105 | 105 | //$pieces = explode(' ',$data); |
| 106 | - $pieces = preg_split('/\s/',$data); |
|
| 106 | + $pieces = preg_split('/\s/', $data); |
|
| 107 | 107 | $pos = 0; |
| 108 | 108 | if ($pieces[0] == 'METAR') $pos++; |
| 109 | 109 | elseif ($pieces[0] == 'SPECI') $pos++; |
@@ -113,25 +113,25 @@ discard block |
||
| 113 | 113 | $result['location'] = $pieces[$pos]; |
| 114 | 114 | $pos++; |
| 115 | 115 | if (!isset($pieces[$pos])) return $result; |
| 116 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 117 | - $result['time'] = substr($pieces[$pos],2,4); |
|
| 116 | + $result['dayofmonth'] = substr($pieces[$pos], 0, 2); |
|
| 117 | + $result['time'] = substr($pieces[$pos], 2, 4); |
|
| 118 | 118 | $c = count($pieces); |
| 119 | - for($pos++; $pos < $c; $pos++) { |
|
| 119 | + for ($pos++; $pos < $c; $pos++) { |
|
| 120 | 120 | $piece = $pieces[$pos]; |
| 121 | 121 | if ($piece == 'RMK') break; |
| 122 | 122 | if ($piece == 'AUTO') $result['auto'] = true; |
| 123 | 123 | if ($piece == 'COR') $result['correction'] = true; |
| 124 | 124 | // Wind Speed |
| 125 | 125 | 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 | - $result['wind']['direction'] = (float)$matches[1]; |
|
| 126 | + $result['wind']['direction'] = (float) $matches[1]; |
|
| 127 | 127 | $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); |
|
| 131 | - $result['wind']['gust'] = (float)$matches[3]; |
|
| 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); |
|
| 131 | + $result['wind']['gust'] = (float) $matches[3]; |
|
| 132 | 132 | $result['wind']['unit'] = $matches[4]; |
| 133 | - $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
|
| 134 | - $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
|
| 133 | + $result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0; |
|
| 134 | + $result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
@@ -152,17 +152,17 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | // Temperature |
| 154 | 154 | if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
| 155 | - $temp = (float)$matches[1]; |
|
| 155 | + $temp = (float) $matches[1]; |
|
| 156 | 156 | if ($matches[1]{0} == 'M') { |
| 157 | - $temp = ((float)substr($matches[1], 1)) * -1; |
|
| 157 | + $temp = ((float) substr($matches[1], 1))*-1; |
|
| 158 | 158 | } |
| 159 | 159 | $result['temperature'] = $temp; |
| 160 | - $dew = (float)$matches[2]; |
|
| 160 | + $dew = (float) $matches[2]; |
|
| 161 | 161 | if ($matches[2]{0} == 'M') { |
| 162 | - $dew = ((float)substr($matches[2], 1)) * -1; |
|
| 162 | + $dew = ((float) substr($matches[2], 1))*-1; |
|
| 163 | 163 | } |
| 164 | 164 | $result['dew'] = $dew; |
| 165 | - $result['rh'] = round(100*(exp((17.625*$dew)/(243.04+$dew))/exp((17.625*$temp)/(243.04+$temp)))); |
|
| 165 | + $result['rh'] = round(100*(exp((17.625*$dew)/(243.04 + $dew))/exp((17.625*$temp)/(243.04 + $temp)))); |
|
| 166 | 166 | } |
| 167 | 167 | // QNH |
| 168 | 168 | if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $result['QNH'] = $matches[2]; |
| 173 | 173 | } else { |
| 174 | 174 | // inHg |
| 175 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 175 | + $result['QNH'] = round(($matches[2]/100)*33.86389, 2); |
|
| 176 | 176 | } |
| 177 | 177 | /* |
| 178 | 178 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | // Visibility |
| 194 | 194 | if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
| 195 | 195 | if (isset($matches[3]) && strlen($matches[3]) > 0) { |
| 196 | - $result['visibility'] = (float)$matches[3] * 1609.34; |
|
| 196 | + $result['visibility'] = (float) $matches[3]*1609.34; |
|
| 197 | 197 | } else { |
| 198 | 198 | if ($matches[1] == '9999') { |
| 199 | 199 | $result['visibility'] = '> 10000'; |
| 200 | 200 | } else { |
| 201 | - $result['visibility'] = (float)$matches[1]; |
|
| 201 | + $result['visibility'] = (float) $matches[1]; |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
| 222 | 222 | elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
| 223 | 223 | $cloud['type_code'] = $type; |
| 224 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 224 | + $cloud['level'] = round(((float) $matches[2])*100*0.3048); |
|
| 225 | 225 | if (isset($matches[3])) $significant = $matches[3]; |
| 226 | 226 | else $significant = ''; |
| 227 | 227 | if ($significant == 'CB') $cloud['significant'] = 'Cumulonimbus'; |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | $rvr['runway'] = $matches[1]; |
| 243 | 243 | $rvr['assessment'] = $matches[2]; |
| 244 | 244 | $rvr['rvr'] = $matches[3]; |
| 245 | - $rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0; |
|
| 246 | - $rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : ''; |
|
| 245 | + $rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0; |
|
| 246 | + $rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : ''; |
|
| 247 | 247 | $result['RVR'] = $rvr; |
| 248 | 248 | } |
| 249 | 249 | //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
@@ -256,12 +256,12 @@ discard block |
||
| 256 | 256 | $result['RVR']['friction'] = $matches[5]; |
| 257 | 257 | } |
| 258 | 258 | 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'); |
|
| 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'); |
|
| 261 | 261 | if (isset($matches[3])) { |
| 262 | 262 | $range = Array( |
| 263 | - 'from' => (float)$matches[2], |
|
| 264 | - 'to' => (float)$matches[4], |
|
| 263 | + 'from' => (float) $matches[2], |
|
| 264 | + 'to' => (float) $matches[4], |
|
| 265 | 265 | 'unit' => $matches[5] ? 'FT' : 'M' |
| 266 | 266 | ); |
| 267 | 267 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | try { |
| 315 | 315 | $sth = $this->db->prepare($query); |
| 316 | 316 | $sth->execute($query_values); |
| 317 | - } catch(PDOException $e) { |
|
| 317 | + } catch (PDOException $e) { |
|
| 318 | 318 | return "error : ".$e->getMessage(); |
| 319 | 319 | } |
| 320 | 320 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -330,19 +330,19 @@ discard block |
||
| 330 | 330 | * @param String $metar METAR text |
| 331 | 331 | * @param String $date date of the METAR |
| 332 | 332 | */ |
| 333 | - public function addMETAR($location,$metar,$date) { |
|
| 333 | + public function addMETAR($location, $metar, $date) { |
|
| 334 | 334 | global $globalDBdriver; |
| 335 | - $date = date('Y-m-d H:i:s',strtotime($date)); |
|
| 335 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 336 | 336 | if ($globalDBdriver == 'mysql') { |
| 337 | 337 | $query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar"; |
| 338 | 338 | } else { |
| 339 | 339 | $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);"; |
| 340 | 340 | } |
| 341 | - $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar)); |
|
| 341 | + $query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar)); |
|
| 342 | 342 | try { |
| 343 | 343 | $sth = $this->db->prepare($query); |
| 344 | 344 | $sth->execute($query_values); |
| 345 | - } catch(PDOException $e) { |
|
| 345 | + } catch (PDOException $e) { |
|
| 346 | 346 | return "error : ".$e->getMessage(); |
| 347 | 347 | } |
| 348 | 348 | return ''; |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | try { |
| 359 | 359 | $sth = $this->db->prepare($query); |
| 360 | 360 | $sth->execute($query_values); |
| 361 | - } catch(PDOException $e) { |
|
| 361 | + } catch (PDOException $e) { |
|
| 362 | 362 | return "error : ".$e->getMessage(); |
| 363 | 363 | } |
| 364 | 364 | return ''; |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | try { |
| 373 | 373 | $sth = $this->db->prepare($query); |
| 374 | 374 | $sth->execute(); |
| 375 | - } catch(PDOException $e) { |
|
| 375 | + } catch (PDOException $e) { |
|
| 376 | 376 | return "error : ".$e->getMessage(); |
| 377 | 377 | } |
| 378 | 378 | return ''; |
@@ -387,30 +387,30 @@ discard block |
||
| 387 | 387 | date_default_timezone_set("UTC"); |
| 388 | 388 | $Common = new Common(); |
| 389 | 389 | if (isset($globalIVAO) && $globalIVAO) { |
| 390 | - $Common->download('http://wx.ivao.aero/metar.php',dirname(__FILE__).'/../install/tmp/ivaometar.txt'); |
|
| 391 | - $handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r"); |
|
| 390 | + $Common->download('http://wx.ivao.aero/metar.php', dirname(__FILE__).'/../install/tmp/ivaometar.txt'); |
|
| 391 | + $handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt', "r"); |
|
| 392 | 392 | } else { |
| 393 | - $Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT',dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT'); |
|
| 394 | - $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r"); |
|
| 393 | + $Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT', dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT'); |
|
| 394 | + $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT', "r"); |
|
| 395 | 395 | } |
| 396 | 396 | if ($handle) { |
| 397 | 397 | if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
| 398 | 398 | $date = ''; |
| 399 | 399 | if ($globalTransaction) $this->db->beginTransaction(); |
| 400 | - while(($line = fgets($handle,4096)) !== false) { |
|
| 401 | - $line = str_replace(array("\r\n","\r", "\n"), '', $line); |
|
| 402 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 400 | + while (($line = fgets($handle, 4096)) !== false) { |
|
| 401 | + $line = str_replace(array("\r\n", "\r", "\n"), '', $line); |
|
| 402 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 403 | 403 | $date = $line; |
| 404 | 404 | } elseif (trim($line) != '') { |
| 405 | 405 | if ($date == '') $date = date('Y/m/d H:m'); |
| 406 | 406 | $pos = 0; |
| 407 | - $pieces = preg_split('/\s/',$line); |
|
| 407 | + $pieces = preg_split('/\s/', $line); |
|
| 408 | 408 | if ($pieces[0] == 'METAR') $pos++; |
| 409 | 409 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 410 | 410 | if (isset($pieces[$pos])) { |
| 411 | 411 | $location = $pieces[$pos]; |
| 412 | 412 | //if ($location == 'LFLL') echo 'location: '.$location.' - date: '.$date.' - data: '.$line."\n"; |
| 413 | - echo $this->addMETAR($location,$line,$date); |
|
| 413 | + echo $this->addMETAR($location, $line, $date); |
|
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -430,23 +430,23 @@ discard block |
||
| 430 | 430 | if ($globalMETARurl == '') return array(); |
| 431 | 431 | date_default_timezone_set("UTC"); |
| 432 | 432 | $Common = new Common(); |
| 433 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 433 | + $url = str_replace('{icao}', $icao, $globalMETARurl); |
|
| 434 | 434 | $cycle = $Common->getData($url); |
| 435 | 435 | $date = ''; |
| 436 | - foreach(explode("\n",$cycle) as $line) { |
|
| 437 | - $line = str_replace(array("\r\n","\r", "\n"), '', $line); |
|
| 438 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 436 | + foreach (explode("\n", $cycle) as $line) { |
|
| 437 | + $line = str_replace(array("\r\n", "\r", "\n"), '', $line); |
|
| 438 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 439 | 439 | $date = $line; |
| 440 | 440 | } |
| 441 | 441 | if (trim($line) != '') { |
| 442 | 442 | if ($date == '') $date = date('Y/m/d H:m'); |
| 443 | 443 | $pos = 0; |
| 444 | - $pieces = preg_split('/\s/',$line); |
|
| 444 | + $pieces = preg_split('/\s/', $line); |
|
| 445 | 445 | if ($pieces[0] == 'METAR') $pos++; |
| 446 | 446 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 447 | 447 | $location = $pieces[$pos]; |
| 448 | 448 | if (strlen($location == 4)) { |
| 449 | - $this->addMETAR($location,$line,$date); |
|
| 449 | + $this->addMETAR($location, $line, $date); |
|
| 450 | 450 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
| 451 | 451 | } else return array(); |
| 452 | 452 | } |
@@ -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(); |