@@ -7,109 +7,109 @@ discard block |
||
| 7 | 7 | public $db; |
| 8 | 8 | |
| 9 | 9 | protected $texts = Array( |
| 10 | - 'MI' => 'Shallow', |
|
| 11 | - 'PR' => 'Partial', |
|
| 12 | - 'BC' => 'Low drifting', |
|
| 13 | - 'BL' => 'Blowing', |
|
| 14 | - 'SH' => 'Showers', |
|
| 15 | - 'TS' => 'Thunderstorm', |
|
| 16 | - 'FZ' => 'Freezing', |
|
| 17 | - 'DZ' => 'Drizzle', |
|
| 18 | - 'RA' => 'Rain', |
|
| 19 | - 'SN' => 'Snow', |
|
| 20 | - 'SG' => 'Snow Grains', |
|
| 21 | - 'IC' => 'Ice crystals', |
|
| 22 | - 'PL' => 'Ice pellets', |
|
| 23 | - 'GR' => 'Hail', |
|
| 24 | - 'GS' => 'Small hail', |
|
| 25 | - 'UP' => 'Unknown', |
|
| 26 | - 'BR' => 'Mist', |
|
| 27 | - 'FG' => 'Fog', |
|
| 28 | - 'FU' => 'Smoke', |
|
| 29 | - 'VA' => 'Volcanic ash', |
|
| 30 | - 'DU' => 'Widespread dust', |
|
| 31 | - 'SA' => 'Sand', |
|
| 32 | - 'HZ' => 'Haze', |
|
| 33 | - 'PY' => 'Spray', |
|
| 34 | - 'PO' => 'Well developed dust / sand whirls', |
|
| 35 | - 'SQ' => 'Squalls', |
|
| 36 | - 'FC' => 'Funnel clouds inc tornadoes or waterspouts', |
|
| 37 | - 'SS' => 'Sandstorm', |
|
| 38 | - 'DS' => 'Duststorm' |
|
| 10 | + 'MI' => 'Shallow', |
|
| 11 | + 'PR' => 'Partial', |
|
| 12 | + 'BC' => 'Low drifting', |
|
| 13 | + 'BL' => 'Blowing', |
|
| 14 | + 'SH' => 'Showers', |
|
| 15 | + 'TS' => 'Thunderstorm', |
|
| 16 | + 'FZ' => 'Freezing', |
|
| 17 | + 'DZ' => 'Drizzle', |
|
| 18 | + 'RA' => 'Rain', |
|
| 19 | + 'SN' => 'Snow', |
|
| 20 | + 'SG' => 'Snow Grains', |
|
| 21 | + 'IC' => 'Ice crystals', |
|
| 22 | + 'PL' => 'Ice pellets', |
|
| 23 | + 'GR' => 'Hail', |
|
| 24 | + 'GS' => 'Small hail', |
|
| 25 | + 'UP' => 'Unknown', |
|
| 26 | + 'BR' => 'Mist', |
|
| 27 | + 'FG' => 'Fog', |
|
| 28 | + 'FU' => 'Smoke', |
|
| 29 | + 'VA' => 'Volcanic ash', |
|
| 30 | + 'DU' => 'Widespread dust', |
|
| 31 | + 'SA' => 'Sand', |
|
| 32 | + 'HZ' => 'Haze', |
|
| 33 | + 'PY' => 'Spray', |
|
| 34 | + 'PO' => 'Well developed dust / sand whirls', |
|
| 35 | + 'SQ' => 'Squalls', |
|
| 36 | + 'FC' => 'Funnel clouds inc tornadoes or waterspouts', |
|
| 37 | + 'SS' => 'Sandstorm', |
|
| 38 | + 'DS' => 'Duststorm' |
|
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | public function __construct($dbc = null) { |
| 42 | - $Connection = new Connection($dbc); |
|
| 43 | - $this->db = $Connection->db; |
|
| 44 | - } |
|
| 42 | + $Connection = new Connection($dbc); |
|
| 43 | + $this->db = $Connection->db; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public static function check_last_update() { |
|
| 47 | - global $globalDBdriver; |
|
| 48 | - if ($globalDBdriver == 'mysql') { |
|
| 46 | + public static function check_last_update() { |
|
| 47 | + global $globalDBdriver; |
|
| 48 | + if ($globalDBdriver == 'mysql') { |
|
| 49 | 49 | $query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value > DATE_SUB(NOW(), INTERVAL 20 MINUTE)"; |
| 50 | 50 | } else { |
| 51 | 51 | $query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '20 MINUTES'"; |
| 52 | 52 | } |
| 53 | - try { |
|
| 54 | - $Connection = new Connection(); |
|
| 55 | - $sth = $Connection->db->prepare($query); |
|
| 56 | - $sth->execute(); |
|
| 57 | - } catch(PDOException $e) { |
|
| 58 | - return "error : ".$e->getMessage(); |
|
| 59 | - } |
|
| 60 | - $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
| 61 | - $sth->closeCursor(); |
|
| 62 | - if ($row['nb'] > 0) return false; |
|
| 63 | - else return true; |
|
| 64 | - } |
|
| 53 | + try { |
|
| 54 | + $Connection = new Connection(); |
|
| 55 | + $sth = $Connection->db->prepare($query); |
|
| 56 | + $sth->execute(); |
|
| 57 | + } catch(PDOException $e) { |
|
| 58 | + return "error : ".$e->getMessage(); |
|
| 59 | + } |
|
| 60 | + $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
| 61 | + $sth->closeCursor(); |
|
| 62 | + if ($row['nb'] > 0) return false; |
|
| 63 | + else return true; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public static function insert_last_update() { |
|
| 67 | - $query = "DELETE FROM config WHERE name = 'last_update_metar'; |
|
| 66 | + public static function insert_last_update() { |
|
| 67 | + $query = "DELETE FROM config WHERE name = 'last_update_metar'; |
|
| 68 | 68 | INSERT INTO config (name,value) VALUES ('last_update_metar',NOW());"; |
| 69 | - try { |
|
| 70 | - $Connection = new Connection(); |
|
| 71 | - $sth = $Connection->db->prepare($query); |
|
| 72 | - $sth->execute(); |
|
| 73 | - } catch(PDOException $e) { |
|
| 74 | - return "error : ".$e->getMessage(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 69 | + try { |
|
| 70 | + $Connection = new Connection(); |
|
| 71 | + $sth = $Connection->db->prepare($query); |
|
| 72 | + $sth->execute(); |
|
| 73 | + } catch(PDOException $e) { |
|
| 74 | + return "error : ".$e->getMessage(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | |
| 80 | - public function parse($data) { |
|
| 81 | - //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
|
| 82 | - $codes = implode('|', array_keys($this->texts)); |
|
| 83 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 84 | - //$pieces = explode(' ',$data); |
|
| 85 | - $pieces = preg_split('/\s/',$data); |
|
| 86 | - $pos = 0; |
|
| 87 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 88 | - elseif ($pieces[0] == 'SPECI') $pos++; |
|
| 89 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 90 | - $result = array(); |
|
| 91 | - $result['location'] = $pieces[$pos]; |
|
| 92 | - $pos++; |
|
| 93 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 94 | - $result['time'] = substr($pieces[$pos],2,4); |
|
| 95 | - $c = count($pieces); |
|
| 96 | - for($pos++; $pos < $c; $pos++) { |
|
| 97 | - $piece = $pieces[$pos]; |
|
| 98 | - if ($piece == 'RMK') break; |
|
| 99 | - if ($piece == 'AUTO') $result['auto'] = true; |
|
| 100 | - if ($piece == 'COR') $result['correction'] = true; |
|
| 101 | - // Wind Speed |
|
| 102 | - 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 | - $result['wind']['direction'] = (float)$matches[1]; |
|
| 80 | + public function parse($data) { |
|
| 81 | + //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
|
| 82 | + $codes = implode('|', array_keys($this->texts)); |
|
| 83 | + $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 84 | + //$pieces = explode(' ',$data); |
|
| 85 | + $pieces = preg_split('/\s/',$data); |
|
| 86 | + $pos = 0; |
|
| 87 | + if ($pieces[0] == 'METAR') $pos++; |
|
| 88 | + elseif ($pieces[0] == 'SPECI') $pos++; |
|
| 89 | + if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 90 | + $result = array(); |
|
| 91 | + $result['location'] = $pieces[$pos]; |
|
| 92 | + $pos++; |
|
| 93 | + $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 94 | + $result['time'] = substr($pieces[$pos],2,4); |
|
| 95 | + $c = count($pieces); |
|
| 96 | + for($pos++; $pos < $c; $pos++) { |
|
| 97 | + $piece = $pieces[$pos]; |
|
| 98 | + if ($piece == 'RMK') break; |
|
| 99 | + if ($piece == 'AUTO') $result['auto'] = true; |
|
| 100 | + if ($piece == 'COR') $result['correction'] = true; |
|
| 101 | + // Wind Speed |
|
| 102 | + 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 | + $result['wind']['direction'] = (float)$matches[1]; |
|
| 104 | 104 | $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); |
|
| 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); |
|
| 108 | 108 | $result['wind']['gust'] = (float)$matches[3]; |
| 109 | 109 | $result['wind']['unit'] = $matches[4]; |
| 110 | 110 | $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
| 111 | 111 | $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
| 115 | 115 | $result['wind_direction'] = (float)$matches[1]; |
@@ -126,35 +126,35 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | */ |
| 129 | - // Temperature |
|
| 130 | - if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
|
| 131 | - $temp = (float)$matches[1]; |
|
| 129 | + // Temperature |
|
| 130 | + if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
|
| 131 | + $temp = (float)$matches[1]; |
|
| 132 | 132 | if ($matches[1]{0} == 'M') { |
| 133 | 133 | $temp = ((float)substr($matches[1], 1)) * -1; |
| 134 | 134 | } |
| 135 | - $result['temperature'] = $temp; |
|
| 136 | - $dew = (float)$matches[2]; |
|
| 135 | + $result['temperature'] = $temp; |
|
| 136 | + $dew = (float)$matches[2]; |
|
| 137 | 137 | if ($matches[2]{0} == 'M') { |
| 138 | 138 | $dew = ((float)substr($matches[2], 1)) * -1; |
| 139 | 139 | } |
| 140 | 140 | $result['dew'] = $dew; |
| 141 | - } |
|
| 142 | - // QNH |
|
| 143 | - if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
|
| 144 | - // #^(Q|A)(////|[0-9]{4})( )# |
|
| 145 | - if ($matches[1] == 'Q') { |
|
| 146 | - // hPa |
|
| 147 | - $result['QNH'] = $matches[2]; |
|
| 148 | - } else { |
|
| 149 | - // inHg |
|
| 150 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 151 | 141 | } |
| 152 | - /* |
|
| 142 | + // QNH |
|
| 143 | + if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
|
| 144 | + // #^(Q|A)(////|[0-9]{4})( )# |
|
| 145 | + if ($matches[1] == 'Q') { |
|
| 146 | + // hPa |
|
| 147 | + $result['QNH'] = $matches[2]; |
|
| 148 | + } else { |
|
| 149 | + // inHg |
|
| 150 | + $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 151 | + } |
|
| 152 | + /* |
|
| 153 | 153 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
| 154 | 154 | $result['QNH_format'] = $matches[1] == 'Q' ? 'hPa' : 'inHg'; |
| 155 | 155 | */ |
| 156 | - } |
|
| 157 | - /* |
|
| 156 | + } |
|
| 157 | + /* |
|
| 158 | 158 | // Wind Direction |
| 159 | 159 | if (preg_match('#^([0-9]{3})V([0-9]{3})$#', $piece, $matches)) { |
| 160 | 160 | $result['wind_direction'] = $matches[1]; |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | $result['speed_variable'] = $matches[1]; |
| 166 | 166 | } |
| 167 | 167 | */ |
| 168 | - // Visibility |
|
| 169 | - if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
|
| 170 | - if (isset($matches[3]) && strlen($matches[3]) > 0) { |
|
| 168 | + // Visibility |
|
| 169 | + if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
|
| 170 | + if (isset($matches[3]) && strlen($matches[3]) > 0) { |
|
| 171 | 171 | $result['visibility'] = (float)$matches[3] * 1609.34; |
| 172 | 172 | } else { |
| 173 | 173 | if ($matches[1] == '9999') { |
@@ -180,28 +180,28 @@ discard block |
||
| 180 | 180 | $result['visibility'] = '> 10000'; |
| 181 | 181 | $result['weather'] = "CAVOK"; |
| 182 | 182 | } |
| 183 | - } |
|
| 184 | - // Cloud Coverage |
|
| 185 | - if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) { |
|
| 186 | - //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
|
| 187 | - $type = $matches[1]; |
|
| 188 | - $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'; |
|
| 197 | - $cloud['type_code'] = $type; |
|
| 198 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 199 | - $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
|
| 200 | - $result['cloud'][] = $cloud; |
|
| 201 | - } |
|
| 202 | - // RVR |
|
| 203 | - if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) { |
|
| 204 | - $rvr = array(); |
|
| 183 | + } |
|
| 184 | + // Cloud Coverage |
|
| 185 | + if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) { |
|
| 186 | + //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
|
| 187 | + $type = $matches[1]; |
|
| 188 | + $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'; |
|
| 197 | + $cloud['type_code'] = $type; |
|
| 198 | + $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 199 | + $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
|
| 200 | + $result['cloud'][] = $cloud; |
|
| 201 | + } |
|
| 202 | + // RVR |
|
| 203 | + if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) { |
|
| 204 | + $rvr = array(); |
|
| 205 | 205 | $rvr['runway'] = $matches[1]; |
| 206 | 206 | $rvr['assessment'] = $matches[2]; |
| 207 | 207 | $rvr['rvr'] = $matches[3]; |
@@ -210,33 +210,33 @@ discard block |
||
| 210 | 210 | $result['RVR'] = $rvr; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 214 | - if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) { |
|
| 215 | - //print_r($matches); |
|
| 216 | - // https://github.com/davidmegginson/metar-taf/blob/master/Metar.php |
|
| 217 | - $result['RVR']['runway'] = $matches[1]; |
|
| 218 | - $result['RVR']['deposits'] = $matches[2]; |
|
| 219 | - $result['RVR']['extent'] = $matches[3]; |
|
| 220 | - $result['RVR']['depth'] = $matches[4]; |
|
| 221 | - $result['RVR']['friction'] = $matches[5]; |
|
| 222 | - } |
|
| 223 | - if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 224 | - //echo $piece; |
|
| 225 | - //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'); |
|
| 213 | + //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 214 | + if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) { |
|
| 215 | + //print_r($matches); |
|
| 216 | + // https://github.com/davidmegginson/metar-taf/blob/master/Metar.php |
|
| 217 | + $result['RVR']['runway'] = $matches[1]; |
|
| 218 | + $result['RVR']['deposits'] = $matches[2]; |
|
| 219 | + $result['RVR']['extent'] = $matches[3]; |
|
| 220 | + $result['RVR']['depth'] = $matches[4]; |
|
| 221 | + $result['RVR']['friction'] = $matches[5]; |
|
| 222 | + } |
|
| 223 | + if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 224 | + //echo $piece; |
|
| 225 | + //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'); |
|
| 228 | 228 | if (isset($matches[3])) { |
| 229 | 229 | $range = Array( |
| 230 | - 'from' => (float)$matches[2], |
|
| 231 | - 'to' => (float)$matches[4], |
|
| 232 | - 'unit' => $matches[5] ? 'FT' : 'M' |
|
| 230 | + 'from' => (float)$matches[2], |
|
| 231 | + 'to' => (float)$matches[4], |
|
| 232 | + 'unit' => $matches[5] ? 'FT' : 'M' |
|
| 233 | 233 | ); |
| 234 | 234 | } |
| 235 | 235 | $result['RVR'] = $matches[1]; |
| 236 | 236 | $result['RVR_range'] = $range; |
| 237 | - } |
|
| 238 | - // Weather |
|
| 239 | - if (preg_match($regWeather, $piece, $matches)) { |
|
| 237 | + } |
|
| 238 | + // Weather |
|
| 239 | + if (preg_match($regWeather, $piece, $matches)) { |
|
| 240 | 240 | $text = Array(); |
| 241 | 241 | switch ($matches[1]) { |
| 242 | 242 | case '+': |
@@ -259,35 +259,35 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | if (!isset($result['weather'])) $result['weather'] = implode(' ', $text); |
| 261 | 261 | else $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
| 262 | - } |
|
| 263 | - } |
|
| 264 | - return $result; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + return $result; |
|
| 265 | 265 | |
| 266 | - } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | public function getMETAR($icao) { |
| 269 | - global $globalMETARcycle, $globalDBdriver; |
|
| 270 | - if (isset($globalMETARcycle) && $globalMETARcycle) { |
|
| 271 | - $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
|
| 272 | - } 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"; |
|
| 275 | - } |
|
| 276 | - $query_values = array(':icao' => $icao); |
|
| 277 | - try { |
|
| 278 | - $sth = $this->db->prepare($query); |
|
| 279 | - $sth->execute($query_values); |
|
| 280 | - } catch(PDOException $e) { |
|
| 281 | - return "error : ".$e->getMessage(); |
|
| 282 | - } |
|
| 283 | - $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 284 | - if ((!isset($globalMETARcycle) || $globalMETARcycle === false) && count($all) == 0) { |
|
| 285 | - $all = $this->downloadMETAR($icao); |
|
| 286 | - } |
|
| 287 | - return $all; |
|
| 288 | - } |
|
| 269 | + global $globalMETARcycle, $globalDBdriver; |
|
| 270 | + if (isset($globalMETARcycle) && $globalMETARcycle) { |
|
| 271 | + $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
|
| 272 | + } 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"; |
|
| 275 | + } |
|
| 276 | + $query_values = array(':icao' => $icao); |
|
| 277 | + try { |
|
| 278 | + $sth = $this->db->prepare($query); |
|
| 279 | + $sth->execute($query_values); |
|
| 280 | + } catch(PDOException $e) { |
|
| 281 | + return "error : ".$e->getMessage(); |
|
| 282 | + } |
|
| 283 | + $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 284 | + if ((!isset($globalMETARcycle) || $globalMETARcycle === false) && count($all) == 0) { |
|
| 285 | + $all = $this->downloadMETAR($icao); |
|
| 286 | + } |
|
| 287 | + return $all; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - public function addMETAR($location,$metar,$date) { |
|
| 290 | + public function addMETAR($location,$metar,$date) { |
|
| 291 | 291 | global $globalDBdriver; |
| 292 | 292 | $date = date('Y-m-d H:i:s',strtotime($date)); |
| 293 | 293 | if ($globalDBdriver == 'mysql') { |
@@ -295,100 +295,100 @@ discard block |
||
| 295 | 295 | } else { |
| 296 | 296 | $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);"; |
| 297 | 297 | } |
| 298 | - $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar)); |
|
| 299 | - try { |
|
| 300 | - $sth = $this->db->prepare($query); |
|
| 301 | - $sth->execute($query_values); |
|
| 302 | - } catch(PDOException $e) { |
|
| 303 | - return "error : ".$e->getMessage(); |
|
| 304 | - } |
|
| 305 | - } |
|
| 298 | + $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar)); |
|
| 299 | + try { |
|
| 300 | + $sth = $this->db->prepare($query); |
|
| 301 | + $sth->execute($query_values); |
|
| 302 | + } catch(PDOException $e) { |
|
| 303 | + return "error : ".$e->getMessage(); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - public function deleteMETAR($id) { |
|
| 308 | - $query = "DELETE FROM metar WHERE id = :id"; |
|
| 309 | - $query_values = array(':id' => $id); |
|
| 310 | - try { |
|
| 311 | - $sth = $this->db->prepare($query); |
|
| 312 | - $sth->execute($query_values); |
|
| 313 | - } catch(PDOException $e) { |
|
| 314 | - return "error : ".$e->getMessage(); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - public function deleteAllMETARLocation() { |
|
| 318 | - $query = "DELETE FROM metar"; |
|
| 319 | - try { |
|
| 320 | - $sth = $this->db->prepare($query); |
|
| 321 | - $sth->execute(); |
|
| 322 | - } catch(PDOException $e) { |
|
| 323 | - return "error : ".$e->getMessage(); |
|
| 324 | - } |
|
| 325 | - } |
|
| 307 | + public function deleteMETAR($id) { |
|
| 308 | + $query = "DELETE FROM metar WHERE id = :id"; |
|
| 309 | + $query_values = array(':id' => $id); |
|
| 310 | + try { |
|
| 311 | + $sth = $this->db->prepare($query); |
|
| 312 | + $sth->execute($query_values); |
|
| 313 | + } catch(PDOException $e) { |
|
| 314 | + return "error : ".$e->getMessage(); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + public function deleteAllMETARLocation() { |
|
| 318 | + $query = "DELETE FROM metar"; |
|
| 319 | + try { |
|
| 320 | + $sth = $this->db->prepare($query); |
|
| 321 | + $sth->execute(); |
|
| 322 | + } catch(PDOException $e) { |
|
| 323 | + return "error : ".$e->getMessage(); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - public function addMETARCycle() { |
|
| 328 | - global $globalDebug, $globalIVAO; |
|
| 329 | - if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
| 330 | - date_default_timezone_set("UTC"); |
|
| 331 | - $Common = new Common(); |
|
| 332 | - if (isset($globalIVAO) && $globalIVAO) { |
|
| 333 | - $cycle = $Common->getData('http://wx.ivao.aero/metar.php'); |
|
| 334 | - } else { |
|
| 327 | + public function addMETARCycle() { |
|
| 328 | + global $globalDebug, $globalIVAO; |
|
| 329 | + if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
| 330 | + date_default_timezone_set("UTC"); |
|
| 331 | + $Common = new Common(); |
|
| 332 | + if (isset($globalIVAO) && $globalIVAO) { |
|
| 333 | + $cycle = $Common->getData('http://wx.ivao.aero/metar.php'); |
|
| 334 | + } else { |
|
| 335 | 335 | $cycle = $Common->getData('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT'); |
| 336 | - } |
|
| 337 | - if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
| 338 | - $date = ''; |
|
| 339 | - foreach(explode("\n",$cycle) as $line) { |
|
| 340 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 341 | - //echo "date : ".$line."\n"; |
|
| 342 | - $date = $line; |
|
| 343 | - } |
|
| 344 | - if ($line != '') { |
|
| 345 | - //$this->parse($line); |
|
| 346 | - //echo $line; |
|
| 347 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 348 | - $pos = 0; |
|
| 349 | - $pieces = preg_split('/\s/',$line); |
|
| 350 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 351 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 352 | - $location = $pieces[$pos]; |
|
| 353 | - echo $this->addMETAR($location,$line,$date); |
|
| 354 | - } |
|
| 355 | - //echo $line."\n"; |
|
| 356 | - } |
|
| 357 | - if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
| 336 | + } |
|
| 337 | + if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
| 338 | + $date = ''; |
|
| 339 | + foreach(explode("\n",$cycle) as $line) { |
|
| 340 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 341 | + //echo "date : ".$line."\n"; |
|
| 342 | + $date = $line; |
|
| 343 | + } |
|
| 344 | + if ($line != '') { |
|
| 345 | + //$this->parse($line); |
|
| 346 | + //echo $line; |
|
| 347 | + if ($date == '') $date = date('Y/m/d H:m'); |
|
| 348 | + $pos = 0; |
|
| 349 | + $pieces = preg_split('/\s/',$line); |
|
| 350 | + if ($pieces[0] == 'METAR') $pos++; |
|
| 351 | + if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 352 | + $location = $pieces[$pos]; |
|
| 353 | + echo $this->addMETAR($location,$line,$date); |
|
| 354 | + } |
|
| 355 | + //echo $line."\n"; |
|
| 356 | + } |
|
| 357 | + if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
| 358 | 358 | |
| 359 | - } |
|
| 360 | - public function downloadMETAR($icao) { |
|
| 361 | - global $globalMETARurl; |
|
| 362 | - if ($globalMETARurl == '') return array(); |
|
| 363 | - date_default_timezone_set("UTC"); |
|
| 364 | - $Common = new Common(); |
|
| 365 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 366 | - $cycle = $Common->getData($url); |
|
| 367 | - $date = ''; |
|
| 368 | - foreach(explode("\n",$cycle) as $line) { |
|
| 369 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 370 | - //echo "date : ".$line."\n"; |
|
| 371 | - $date = $line; |
|
| 372 | - } |
|
| 373 | - if ($line != '') { |
|
| 374 | - //$this->parse($line); |
|
| 375 | - //echo $line; |
|
| 376 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 377 | - $pos = 0; |
|
| 378 | - $pieces = preg_split('/\s/',$line); |
|
| 379 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 380 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 381 | - $location = $pieces[$pos]; |
|
| 382 | - if (strlen($location == 4)) { |
|
| 383 | - $this->addMETAR($location,$line,$date); |
|
| 384 | - return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
|
| 385 | - } else return array(); |
|
| 386 | - } |
|
| 387 | - //echo $line."\n"; |
|
| 388 | - } |
|
| 389 | - return array(); |
|
| 359 | + } |
|
| 360 | + public function downloadMETAR($icao) { |
|
| 361 | + global $globalMETARurl; |
|
| 362 | + if ($globalMETARurl == '') return array(); |
|
| 363 | + date_default_timezone_set("UTC"); |
|
| 364 | + $Common = new Common(); |
|
| 365 | + $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 366 | + $cycle = $Common->getData($url); |
|
| 367 | + $date = ''; |
|
| 368 | + foreach(explode("\n",$cycle) as $line) { |
|
| 369 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 370 | + //echo "date : ".$line."\n"; |
|
| 371 | + $date = $line; |
|
| 372 | + } |
|
| 373 | + if ($line != '') { |
|
| 374 | + //$this->parse($line); |
|
| 375 | + //echo $line; |
|
| 376 | + if ($date == '') $date = date('Y/m/d H:m'); |
|
| 377 | + $pos = 0; |
|
| 378 | + $pieces = preg_split('/\s/',$line); |
|
| 379 | + if ($pieces[0] == 'METAR') $pos++; |
|
| 380 | + if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 381 | + $location = $pieces[$pos]; |
|
| 382 | + if (strlen($location == 4)) { |
|
| 383 | + $this->addMETAR($location,$line,$date); |
|
| 384 | + return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
|
| 385 | + } else return array(); |
|
| 386 | + } |
|
| 387 | + //echo $line."\n"; |
|
| 388 | + } |
|
| 389 | + return array(); |
|
| 390 | 390 | |
| 391 | - } |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | /* |
| 394 | 394 | $METAR = new METAR(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $Connection = new Connection(); |
| 55 | 55 | $sth = $Connection->db->prepare($query); |
| 56 | 56 | $sth->execute(); |
| 57 | - } catch(PDOException $e) { |
|
| 57 | + } catch (PDOException $e) { |
|
| 58 | 58 | return "error : ".$e->getMessage(); |
| 59 | 59 | } |
| 60 | 60 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $Connection = new Connection(); |
| 71 | 71 | $sth = $Connection->db->prepare($query); |
| 72 | 72 | $sth->execute(); |
| 73 | - } catch(PDOException $e) { |
|
| 73 | + } catch (PDOException $e) { |
|
| 74 | 74 | return "error : ".$e->getMessage(); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | public function parse($data) { |
| 81 | 81 | //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
| 82 | 82 | $codes = implode('|', array_keys($this->texts)); |
| 83 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 83 | + $regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#'; |
|
| 84 | 84 | //$pieces = explode(' ',$data); |
| 85 | - $pieces = preg_split('/\s/',$data); |
|
| 85 | + $pieces = preg_split('/\s/', $data); |
|
| 86 | 86 | $pos = 0; |
| 87 | 87 | if ($pieces[0] == 'METAR') $pos++; |
| 88 | 88 | elseif ($pieces[0] == 'SPECI') $pos++; |
@@ -90,25 +90,25 @@ discard block |
||
| 90 | 90 | $result = array(); |
| 91 | 91 | $result['location'] = $pieces[$pos]; |
| 92 | 92 | $pos++; |
| 93 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 94 | - $result['time'] = substr($pieces[$pos],2,4); |
|
| 93 | + $result['dayofmonth'] = substr($pieces[$pos], 0, 2); |
|
| 94 | + $result['time'] = substr($pieces[$pos], 2, 4); |
|
| 95 | 95 | $c = count($pieces); |
| 96 | - for($pos++; $pos < $c; $pos++) { |
|
| 96 | + for ($pos++; $pos < $c; $pos++) { |
|
| 97 | 97 | $piece = $pieces[$pos]; |
| 98 | 98 | if ($piece == 'RMK') break; |
| 99 | 99 | if ($piece == 'AUTO') $result['auto'] = true; |
| 100 | 100 | if ($piece == 'COR') $result['correction'] = true; |
| 101 | 101 | // Wind Speed |
| 102 | 102 | 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 | - $result['wind']['direction'] = (float)$matches[1]; |
|
| 103 | + $result['wind']['direction'] = (float) $matches[1]; |
|
| 104 | 104 | $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); |
|
| 108 | - $result['wind']['gust'] = (float)$matches[3]; |
|
| 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); |
|
| 108 | + $result['wind']['gust'] = (float) $matches[3]; |
|
| 109 | 109 | $result['wind']['unit'] = $matches[4]; |
| 110 | - $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
|
| 111 | - $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
|
| 110 | + $result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0; |
|
| 111 | + $result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
@@ -128,14 +128,14 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | // Temperature |
| 130 | 130 | if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
| 131 | - $temp = (float)$matches[1]; |
|
| 131 | + $temp = (float) $matches[1]; |
|
| 132 | 132 | if ($matches[1]{0} == 'M') { |
| 133 | - $temp = ((float)substr($matches[1], 1)) * -1; |
|
| 133 | + $temp = ((float) substr($matches[1], 1))*-1; |
|
| 134 | 134 | } |
| 135 | 135 | $result['temperature'] = $temp; |
| 136 | - $dew = (float)$matches[2]; |
|
| 136 | + $dew = (float) $matches[2]; |
|
| 137 | 137 | if ($matches[2]{0} == 'M') { |
| 138 | - $dew = ((float)substr($matches[2], 1)) * -1; |
|
| 138 | + $dew = ((float) substr($matches[2], 1))*-1; |
|
| 139 | 139 | } |
| 140 | 140 | $result['dew'] = $dew; |
| 141 | 141 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $result['QNH'] = $matches[2]; |
| 148 | 148 | } else { |
| 149 | 149 | // inHg |
| 150 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 150 | + $result['QNH'] = round(($matches[2]/100)*33.86389, 2); |
|
| 151 | 151 | } |
| 152 | 152 | /* |
| 153 | 153 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | // Visibility |
| 169 | 169 | if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
| 170 | 170 | if (isset($matches[3]) && strlen($matches[3]) > 0) { |
| 171 | - $result['visibility'] = (float)$matches[3] * 1609.34; |
|
| 171 | + $result['visibility'] = (float) $matches[3]*1609.34; |
|
| 172 | 172 | } else { |
| 173 | 173 | if ($matches[1] == '9999') { |
| 174 | 174 | $result['visibility'] = '> 10000'; |
| 175 | 175 | } else { |
| 176 | - $result['visibility'] = (float)$matches[1]; |
|
| 176 | + $result['visibility'] = (float) $matches[1]; |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | if (preg_match('#^CAVOK$#', $piece, $matches)) { |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
| 196 | 196 | elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
| 197 | 197 | $cloud['type_code'] = $type; |
| 198 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 198 | + $cloud['level'] = round(((float) $matches[2])*100*0.3048); |
|
| 199 | 199 | $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
| 200 | 200 | $result['cloud'][] = $cloud; |
| 201 | 201 | } |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | $rvr['runway'] = $matches[1]; |
| 206 | 206 | $rvr['assessment'] = $matches[2]; |
| 207 | 207 | $rvr['rvr'] = $matches[3]; |
| 208 | - $rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0; |
|
| 209 | - $rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : ''; |
|
| 208 | + $rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0; |
|
| 209 | + $rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : ''; |
|
| 210 | 210 | $result['RVR'] = $rvr; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
| 224 | 224 | //echo $piece; |
| 225 | 225 | //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'); |
|
| 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'); |
|
| 228 | 228 | if (isset($matches[3])) { |
| 229 | 229 | $range = Array( |
| 230 | - 'from' => (float)$matches[2], |
|
| 231 | - 'to' => (float)$matches[4], |
|
| 230 | + 'from' => (float) $matches[2], |
|
| 231 | + 'to' => (float) $matches[4], |
|
| 232 | 232 | 'unit' => $matches[5] ? 'FT' : 'M' |
| 233 | 233 | ); |
| 234 | 234 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | try { |
| 278 | 278 | $sth = $this->db->prepare($query); |
| 279 | 279 | $sth->execute($query_values); |
| 280 | - } catch(PDOException $e) { |
|
| 280 | + } catch (PDOException $e) { |
|
| 281 | 281 | return "error : ".$e->getMessage(); |
| 282 | 282 | } |
| 283 | 283 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -287,19 +287,19 @@ discard block |
||
| 287 | 287 | return $all; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - public function addMETAR($location,$metar,$date) { |
|
| 290 | + public function addMETAR($location, $metar, $date) { |
|
| 291 | 291 | global $globalDBdriver; |
| 292 | - $date = date('Y-m-d H:i:s',strtotime($date)); |
|
| 292 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 293 | 293 | if ($globalDBdriver == 'mysql') { |
| 294 | 294 | $query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar"; |
| 295 | 295 | } else { |
| 296 | 296 | $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);"; |
| 297 | 297 | } |
| 298 | - $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar)); |
|
| 298 | + $query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar)); |
|
| 299 | 299 | try { |
| 300 | 300 | $sth = $this->db->prepare($query); |
| 301 | 301 | $sth->execute($query_values); |
| 302 | - } catch(PDOException $e) { |
|
| 302 | + } catch (PDOException $e) { |
|
| 303 | 303 | return "error : ".$e->getMessage(); |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | try { |
| 311 | 311 | $sth = $this->db->prepare($query); |
| 312 | 312 | $sth->execute($query_values); |
| 313 | - } catch(PDOException $e) { |
|
| 313 | + } catch (PDOException $e) { |
|
| 314 | 314 | return "error : ".$e->getMessage(); |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | try { |
| 320 | 320 | $sth = $this->db->prepare($query); |
| 321 | 321 | $sth->execute(); |
| 322 | - } catch(PDOException $e) { |
|
| 322 | + } catch (PDOException $e) { |
|
| 323 | 323 | return "error : ".$e->getMessage(); |
| 324 | 324 | } |
| 325 | 325 | } |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
| 338 | 338 | $date = ''; |
| 339 | - foreach(explode("\n",$cycle) as $line) { |
|
| 340 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 339 | + foreach (explode("\n", $cycle) as $line) { |
|
| 340 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 341 | 341 | //echo "date : ".$line."\n"; |
| 342 | 342 | $date = $line; |
| 343 | 343 | } |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | //echo $line; |
| 347 | 347 | if ($date == '') $date = date('Y/m/d H:m'); |
| 348 | 348 | $pos = 0; |
| 349 | - $pieces = preg_split('/\s/',$line); |
|
| 349 | + $pieces = preg_split('/\s/', $line); |
|
| 350 | 350 | if ($pieces[0] == 'METAR') $pos++; |
| 351 | 351 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 352 | 352 | $location = $pieces[$pos]; |
| 353 | - echo $this->addMETAR($location,$line,$date); |
|
| 353 | + echo $this->addMETAR($location, $line, $date); |
|
| 354 | 354 | } |
| 355 | 355 | //echo $line."\n"; |
| 356 | 356 | } |
@@ -362,11 +362,11 @@ discard block |
||
| 362 | 362 | if ($globalMETARurl == '') return array(); |
| 363 | 363 | date_default_timezone_set("UTC"); |
| 364 | 364 | $Common = new Common(); |
| 365 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 365 | + $url = str_replace('{icao}', $icao, $globalMETARurl); |
|
| 366 | 366 | $cycle = $Common->getData($url); |
| 367 | 367 | $date = ''; |
| 368 | - foreach(explode("\n",$cycle) as $line) { |
|
| 369 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 368 | + foreach (explode("\n", $cycle) as $line) { |
|
| 369 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 370 | 370 | //echo "date : ".$line."\n"; |
| 371 | 371 | $date = $line; |
| 372 | 372 | } |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | //echo $line; |
| 376 | 376 | if ($date == '') $date = date('Y/m/d H:m'); |
| 377 | 377 | $pos = 0; |
| 378 | - $pieces = preg_split('/\s/',$line); |
|
| 378 | + $pieces = preg_split('/\s/', $line); |
|
| 379 | 379 | if ($pieces[0] == 'METAR') $pos++; |
| 380 | 380 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 381 | 381 | $location = $pieces[$pos]; |
| 382 | 382 | if (strlen($location == 4)) { |
| 383 | - $this->addMETAR($location,$line,$date); |
|
| 383 | + $this->addMETAR($location, $line, $date); |
|
| 384 | 384 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
| 385 | 385 | } else return array(); |
| 386 | 386 | } |