@@ -28,20 +28,20 @@ discard block |
||
28 | 28 | * @param String $date get data for a date |
29 | 29 | * @return Array Return Accidents data in array |
30 | 30 | */ |
31 | - public function getAccidentData($limit = '',$type = '',$date = '') { |
|
31 | + public function getAccidentData($limit = '', $type = '', $date = '') { |
|
32 | 32 | global $globalURL, $globalDBdriver; |
33 | 33 | $Image = new Image($this->db); |
34 | 34 | $Spotter = new Spotter($this->db); |
35 | 35 | $Translation = new Translation($this->db); |
36 | - $date = filter_var($date,FILTER_SANITIZE_STRING); |
|
36 | + $date = filter_var($date, FILTER_SANITIZE_STRING); |
|
37 | 37 | date_default_timezone_set('UTC'); |
38 | 38 | $result = array(); |
39 | 39 | $limit_query = ''; |
40 | 40 | if ($limit != "") |
41 | 41 | { |
42 | 42 | $limit_array = explode(",", $limit); |
43 | - $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
44 | - $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
43 | + $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT); |
|
44 | + $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT); |
|
45 | 45 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
46 | 46 | { |
47 | 47 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
@@ -50,29 +50,29 @@ discard block |
||
50 | 50 | |
51 | 51 | if ($type != '') { |
52 | 52 | if ($date != '') { |
53 | - if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) { |
|
53 | + if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) { |
|
54 | 54 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
55 | 55 | //$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
56 | - $query_values = array(':type' => $type,':date' => $date); |
|
57 | - } elseif (preg_match("/^[0-9]{4}-[0-9]{2}$/",$date)) { |
|
56 | + $query_values = array(':type' => $type, ':date' => $date); |
|
57 | + } elseif (preg_match("/^[0-9]{4}-[0-9]{2}$/", $date)) { |
|
58 | 58 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date BETWEEN :dated AND :datef GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
59 | - $query_values = array(':type' => $type,':dated' => $date.'-01', ':datef' => $date.'-31'); |
|
60 | - } elseif (preg_match("/^[0-9]{4}$/",$date)) { |
|
59 | + $query_values = array(':type' => $type, ':dated' => $date.'-01', ':datef' => $date.'-31'); |
|
60 | + } elseif (preg_match("/^[0-9]{4}$/", $date)) { |
|
61 | 61 | if ($globalDBdriver == 'mysql') { |
62 | 62 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND YEAR(date) = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
63 | 63 | } else { |
64 | 64 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND EXTRACT(YEAR FROM date) = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
65 | 65 | } |
66 | - $query_values = array(':type' => $type,':date' => $date); |
|
66 | + $query_values = array(':type' => $type, ':date' => $date); |
|
67 | 67 | } else { |
68 | 68 | $date = $date.'%'; |
69 | 69 | if ($globalDBdriver == 'mysql') { |
70 | 70 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND DATE_FORMAT(date,'%Y-%m-%d') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
71 | - $query_values = array(':type' => $type,':date' => $date); |
|
71 | + $query_values = array(':type' => $type, ':date' => $date); |
|
72 | 72 | } else { |
73 | 73 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
74 | 74 | //$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
75 | - $query_values = array(':type' => $type,':date' => $date); |
|
75 | + $query_values = array(':type' => $type, ':date' => $date); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | } else { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | } else { |
84 | 84 | if ($date != '') { |
85 | - if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) { |
|
85 | + if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) { |
|
86 | 86 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
87 | 87 | //$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
88 | 88 | } else { |
@@ -100,17 +100,17 @@ discard block |
||
100 | 100 | try { |
101 | 101 | $sth = $this->db->prepare($query); |
102 | 102 | $sth->execute($query_values); |
103 | - } catch(PDOException $e) { |
|
103 | + } catch (PDOException $e) { |
|
104 | 104 | echo "error : ".$e->getMessage(); |
105 | 105 | } |
106 | 106 | $i = 0; |
107 | 107 | while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
108 | - if (preg_match('/^[\w\-]+$/',$row['registration'])) { |
|
108 | + if (preg_match('/^[\w\-]+$/', $row['registration'])) { |
|
109 | 109 | $data = array(); |
110 | 110 | if ($row['registration'] != '') { |
111 | 111 | $image_array = $Image->getSpotterImage($row['registration']); |
112 | - if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); |
|
113 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
112 | + if (count($image_array) > 0) $data = array_merge($data, array('image' => $image_array[0]['image'], 'image_thumbnail' => $image_array[0]['image_thumbnail'], 'image_copyright' => $image_array[0]['image_copyright'], 'image_source' => $image_array[0]['image_source'], 'image_source_website' => $image_array[0]['image_source_website'])); |
|
113 | + else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
114 | 114 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
115 | 115 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
116 | 116 | if (!empty($aircraft_info)) { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $data['aircraft_name'] = $aircraft_info[0]['type']; |
119 | 119 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; |
120 | 120 | } else { |
121 | - $data = array_merge($data,array('aircraft_type' => 'NA')); |
|
121 | + $data = array_merge($data, array('aircraft_type' => 'NA')); |
|
122 | 122 | } |
123 | 123 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); |
124 | 124 | if (!empty($owner_data)) { |
@@ -126,18 +126,18 @@ discard block |
||
126 | 126 | $data['aircraft_base'] = $owner_data['base']; |
127 | 127 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
128 | 128 | } |
129 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
129 | + } else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
130 | 130 | if ($row['registration'] == '') $row['registration'] = 'NA'; |
131 | 131 | if ($row['ident'] == '') $row['ident'] = 'NA'; |
132 | - $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3)); |
|
132 | + $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 3)); |
|
133 | 133 | if (isset($identicao[0])) { |
134 | - if (substr($row['ident'],0,2) == 'AF') { |
|
135 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
136 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
137 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
138 | - $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
|
134 | + if (substr($row['ident'], 0, 2) == 'AF') { |
|
135 | + if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
136 | + else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0'); |
|
137 | + } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0'); |
|
138 | + $data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name'])); |
|
139 | 139 | } else $icao = $row['ident']; |
140 | - $icao = $Translation->checkTranslation($icao,false); |
|
140 | + $icao = $Translation->checkTranslation($icao, false); |
|
141 | 141 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
142 | 142 | if ($row['airline_name'] != '' && !isset($data['airline_name'])) { |
143 | 143 | //echo 'Check airline info... for '.$row['airline_name'].' '; |
@@ -146,16 +146,16 @@ discard block |
||
146 | 146 | if (!empty($airline_info)) { |
147 | 147 | //echo 'data found !'."\n"; |
148 | 148 | //print_r($airline_info); |
149 | - $data = array_merge($data,$airline_info); |
|
149 | + $data = array_merge($data, $airline_info); |
|
150 | 150 | } |
151 | 151 | //else echo 'No data...'."\n"; |
152 | 152 | } |
153 | - $data = array_merge($row,$data); |
|
153 | + $data = array_merge($row, $data); |
|
154 | 154 | if ($data['ident'] == null) $data['ident'] = $icao; |
155 | 155 | if ($data['title'] == null) { |
156 | 156 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
157 | 157 | } else $data['message'] = strtolower($data['title']); |
158 | - $ids = $Spotter->getAllIDByRegistration($data['registration'],true); |
|
158 | + $ids = $Spotter->getAllIDByRegistration($data['registration'], true); |
|
159 | 159 | $date = $data['date']; |
160 | 160 | if (isset($ids[$date])) { |
161 | 161 | $data['spotted'] = TRUE; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | try { |
188 | 188 | $sth = $this->db->prepare($query); |
189 | 189 | $sth->execute(); |
190 | - } catch(PDOException $e) { |
|
190 | + } catch (PDOException $e) { |
|
191 | 191 | echo "Error : ".$e->getMessage(); |
192 | 192 | } |
193 | 193 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | try { |
208 | 208 | $sth = $this->db->prepare($query); |
209 | 209 | $sth->execute(); |
210 | - } catch(PDOException $e) { |
|
210 | + } catch (PDOException $e) { |
|
211 | 211 | echo "Error : ".$e->getMessage(); |
212 | 212 | } |
213 | 213 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -222,15 +222,15 @@ discard block |
||
222 | 222 | if ($globalDebug) echo 'Import '.$file."\n"; |
223 | 223 | $result = array(); |
224 | 224 | if (file_exists($file)) { |
225 | - if (($handle = fopen($file,'r')) !== FALSE) { |
|
226 | - while (($data = fgetcsv($handle,2000,",")) !== FALSE) { |
|
225 | + if (($handle = fopen($file, 'r')) !== FALSE) { |
|
226 | + while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) { |
|
227 | 227 | if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') { |
228 | - $result[] = array('registration' => $data[0],'date' => strtotime($data[1]),'url' => $data[2],'country' => $data[3],'place' => $data[4],'title' => $data[5],'fatalities' => $data[6],'latitude' => $data[7],'longitude' => $data[8],'type' => $data[9],'ident' => $data[10],'aircraft_manufacturer' => $data[11],'aircraft_name' => $data[12],'operator' => $data[13],'source' => 'website_fam'); |
|
228 | + $result[] = array('registration' => $data[0], 'date' => strtotime($data[1]), 'url' => $data[2], 'country' => $data[3], 'place' => $data[4], 'title' => $data[5], 'fatalities' => $data[6], 'latitude' => $data[7], 'longitude' => $data[8], 'type' => $data[9], 'ident' => $data[10], 'aircraft_manufacturer' => $data[11], 'aircraft_name' => $data[12], 'operator' => $data[13], 'source' => 'website_fam'); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | fclose($handle); |
232 | 232 | } |
233 | - if (!empty($result)) $this->add($result,true); |
|
233 | + if (!empty($result)) $this->add($result, true); |
|
234 | 234 | elseif ($globalDebug) echo 'Nothing to import'; |
235 | 235 | } |
236 | 236 | } |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | $all_md5_new = array(); |
247 | 247 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
248 | 248 | if ($this->check_accidents_nb() > 0) { |
249 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
250 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
249 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
250 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
251 | 251 | if (isset($data[1])) { |
252 | 252 | $year = $data[0]; |
253 | 253 | $all_md5[$year] = $data[1]; |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | - $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
260 | + $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
261 | 261 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
262 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
263 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
262 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
263 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
264 | 264 | if (isset($data[1])) { |
265 | 265 | $year = $data[0]; |
266 | 266 | $all_md5_new[$year] = $data[1]; |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | fclose($handle); |
270 | 270 | } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
271 | 271 | } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
272 | - $result = $Common->arr_diff($all_md5_new,$all_md5); |
|
272 | + $result = $Common->arr_diff($all_md5_new, $all_md5); |
|
273 | 273 | if (empty($result) && $globalDebug) echo 'Nothing to update'; |
274 | 274 | foreach ($result as $file => $md5) { |
275 | - $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
|
275 | + $Common->download('http://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file); |
|
276 | 276 | if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
277 | 277 | elseif ($globalDebug) echo 'Download '.$file.' failed'; |
278 | 278 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * Add data to DB |
283 | 283 | * @param Array $crash An array with accidents/incidents data |
284 | 284 | */ |
285 | - public function add($crash,$new = false) { |
|
285 | + public function add($crash, $new = false) { |
|
286 | 286 | global $globalTransaction, $globalDebug; |
287 | 287 | require_once('class.Connection.php'); |
288 | 288 | require_once('class.Image.php'); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $sthd->execute(array(':source' => $crash[0]['source'])); |
299 | 299 | } |
300 | 300 | if ($globalTransaction) $Connection->db->beginTransaction(); |
301 | - $initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null,'operator' => null); |
|
301 | + $initial_array = array('ident' => null, 'type' => 'accident', 'url' => null, 'registration' => null, 'date' => null, 'place' => null, 'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '', 'source' => '', 'aircraft_manufacturer' => null, 'aircraft_name' => null, 'operator' => null); |
|
302 | 302 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
303 | 303 | $sth_check = $Connection->db->prepare($query_check); |
304 | 304 | $query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,airline_name,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:airline_name,:source)'; |
@@ -311,15 +311,15 @@ discard block |
||
311 | 311 | $cr = array_map(function($value) { |
312 | 312 | return $value === "" ? NULL : $value; |
313 | 313 | }, $cr); |
314 | - if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
|
315 | - if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
316 | - $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
|
314 | + if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) { |
|
315 | + if (strpos($cr['registration'], '-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
316 | + $query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']); |
|
317 | 317 | $sth_check->execute($query_check_values); |
318 | 318 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
319 | 319 | if ($result_check['nb'] == 0) { |
320 | - $query_values = array(':registration' => trim($cr['registration']),':date' => date('Y-m-d',$cr['date']),':url' => $cr['url'],':country' => $cr['country'],':place' => $cr['place'],':title' => $cr['title'],':fatalities' => $cr['fatalities'],':latitude' => $cr['latitude'],':longitude' => $cr['longitude'],':type' => $cr['type'],':source' => $cr['source'],':ident' => $cr['ident'],':aircraft_manufacturer' => $cr['aircraft_manufacturer'],':aircraft_name' => $cr['aircraft_name'],':airline_name' => $cr['operator']); |
|
320 | + $query_values = array(':registration' => trim($cr['registration']), ':date' => date('Y-m-d', $cr['date']), ':url' => $cr['url'], ':country' => $cr['country'], ':place' => $cr['place'], ':title' => $cr['title'], ':fatalities' => $cr['fatalities'], ':latitude' => $cr['latitude'], ':longitude' => $cr['longitude'], ':type' => $cr['type'], ':source' => $cr['source'], ':ident' => $cr['ident'], ':aircraft_manufacturer' => $cr['aircraft_manufacturer'], ':aircraft_name' => $cr['aircraft_name'], ':airline_name' => $cr['operator']); |
|
321 | 321 | $sth->execute($query_values); |
322 | - if ($cr['date'] > time()-(30*86400)) { |
|
322 | + if ($cr['date'] > time() - (30*86400)) { |
|
323 | 323 | if (empty($Image->getSpotterImage($cr['registration']))) { |
324 | 324 | if ($globalDebug) echo "\t".'Get image for '.$cr['registration'].'...'; |
325 | 325 | $Image->addSpotterImage($cr['registration']); |
@@ -328,16 +328,16 @@ discard block |
||
328 | 328 | // elseif ($globalDebug) echo 'Image already in DB'."\n"; |
329 | 329 | } |
330 | 330 | if ($cr['title'] == '') $cr['title'] = $cr['registration'].' '.$cr['type']; |
331 | - $Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date'])); |
|
331 | + $Spotter->setHighlightFlightByRegistration($cr['registration'], $cr['title'], date('Y-m-d', $cr['date'])); |
|
332 | 332 | } |
333 | 333 | } |
334 | - if ($globalTransaction && $j % 1000 == 0) { |
|
334 | + if ($globalTransaction && $j%1000 == 0) { |
|
335 | 335 | $Connection->db->commit(); |
336 | 336 | $Connection->db->beginTransaction(); |
337 | 337 | } |
338 | 338 | } |
339 | 339 | if ($globalTransaction) $Connection->db->commit(); |
340 | - } catch(PDOException $e) { |
|
340 | + } catch (PDOException $e) { |
|
341 | 341 | if ($globalTransaction) $Connection->db->rollBack(); |
342 | 342 | echo $e->getMessage(); |
343 | 343 | } |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | try { |
355 | 355 | $sth = $this->db->prepare($query); |
356 | 356 | $sth->execute(); |
357 | - } catch(PDOException $e) { |
|
357 | + } catch (PDOException $e) { |
|
358 | 358 | return "error : ".$e->getMessage(); |
359 | 359 | } |
360 | 360 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | try { |
372 | 372 | $sth = $this->db->prepare($query); |
373 | 373 | $sth->execute(); |
374 | - } catch(PDOException $e) { |
|
374 | + } catch (PDOException $e) { |
|
375 | 375 | return "error : ".$e->getMessage(); |
376 | 376 | } |
377 | 377 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | try { |
386 | 386 | $sth = $this->db->prepare($query); |
387 | 387 | $sth->execute(); |
388 | - } catch(PDOException $e) { |
|
388 | + } catch (PDOException $e) { |
|
389 | 389 | return "error : ".$e->getMessage(); |
390 | 390 | } |
391 | 391 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | try { |
54 | 54 | $sth = $this->db->prepare($query); |
55 | 55 | $sth->execute(); |
56 | - } catch(PDOException $e) { |
|
56 | + } catch (PDOException $e) { |
|
57 | 57 | return "error : ".$e->getMessage(); |
58 | 58 | } |
59 | 59 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | try { |
69 | 69 | $sth = $this->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 | } |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | public function parse($data) { |
77 | 77 | //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
78 | 78 | $codes = implode('|', array_keys($this->texts)); |
79 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
79 | + $regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#'; |
|
80 | 80 | //$pieces = explode(' ',$data); |
81 | - $pieces = preg_split('/\s/',$data); |
|
81 | + $pieces = preg_split('/\s/', $data); |
|
82 | 82 | $pos = 0; |
83 | 83 | if ($pieces[0] == 'METAR') $pos++; |
84 | 84 | elseif ($pieces[0] == 'SPECI') $pos++; |
@@ -86,25 +86,25 @@ discard block |
||
86 | 86 | $result = array(); |
87 | 87 | $result['location'] = $pieces[$pos]; |
88 | 88 | $pos++; |
89 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
90 | - $result['time'] = substr($pieces[$pos],2,4); |
|
89 | + $result['dayofmonth'] = substr($pieces[$pos], 0, 2); |
|
90 | + $result['time'] = substr($pieces[$pos], 2, 4); |
|
91 | 91 | $c = count($pieces); |
92 | - for($pos++; $pos < $c; $pos++) { |
|
92 | + for ($pos++; $pos < $c; $pos++) { |
|
93 | 93 | $piece = $pieces[$pos]; |
94 | 94 | if ($piece == 'RMK') break; |
95 | 95 | if ($piece == 'AUTO') $result['auto'] = true; |
96 | 96 | if ($piece == 'COR') $result['correction'] = true; |
97 | 97 | // Wind Speed |
98 | 98 | if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
99 | - $result['wind']['direction'] = (float)$matches[1]; |
|
99 | + $result['wind']['direction'] = (float) $matches[1]; |
|
100 | 100 | $result['wind']['unit'] = $matches[4]; |
101 | - if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
102 | - elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
103 | - elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
104 | - $result['wind']['gust'] = (float)$matches[3]; |
|
101 | + if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float) $matches[2])*0.51444444444, 2); |
|
102 | + elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float) $matches[2])*1000, 2); |
|
103 | + elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float) $matches[2]), 2); |
|
104 | + $result['wind']['gust'] = (float) $matches[3]; |
|
105 | 105 | $result['wind']['unit'] = $matches[4]; |
106 | - $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
|
107 | - $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
|
106 | + $result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0; |
|
107 | + $result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | |
126 | 126 | // Temperature |
127 | 127 | if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
128 | - $temp = (float)$matches[1]; |
|
128 | + $temp = (float) $matches[1]; |
|
129 | 129 | if ($matches[1]{0} == 'M') { |
130 | - $temp = ((float)substr($matches[1], 1)) * -1; |
|
130 | + $temp = ((float) substr($matches[1], 1))*-1; |
|
131 | 131 | } |
132 | 132 | $result['temperature'] = $temp; |
133 | - $dew = (float)$matches[2]; |
|
133 | + $dew = (float) $matches[2]; |
|
134 | 134 | if ($matches[2]{0} == 'M') { |
135 | - $dew = ((float)substr($matches[2], 1)) * -1; |
|
135 | + $dew = ((float) substr($matches[2], 1))*-1; |
|
136 | 136 | } |
137 | 137 | $result['dew'] = $dew; |
138 | 138 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $result['QNH'] = $matches[2]; |
145 | 145 | } else { |
146 | 146 | // inHg |
147 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
147 | + $result['QNH'] = round(($matches[2]/100)*33.86389, 2); |
|
148 | 148 | } |
149 | 149 | /* |
150 | 150 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | // Visibility |
166 | 166 | if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
167 | 167 | if (isset($matches[3]) && strlen($matches[3]) > 0) { |
168 | - $result['visibility'] = (float)$matches[3] * 1609.34; |
|
168 | + $result['visibility'] = (float) $matches[3]*1609.34; |
|
169 | 169 | } else { |
170 | 170 | if ($matches[1] == '9999') { |
171 | 171 | $result['visibility'] = '> 10000'; |
172 | 172 | } else { |
173 | - $result['visibility'] = (float)$matches[1]; |
|
173 | + $result['visibility'] = (float) $matches[1]; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | if (preg_match('#^CAVOK$#', $piece, $matches)) { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
193 | 193 | elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
194 | 194 | $cloud['type_code'] = $type; |
195 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
195 | + $cloud['level'] = round(((float) $matches[2])*100*0.3048); |
|
196 | 196 | $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
197 | 197 | $result['cloud'][] = $cloud; |
198 | 198 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | $rvr['runway'] = $matches[1]; |
203 | 203 | $rvr['assessment'] = $matches[2]; |
204 | 204 | $rvr['rvr'] = $matches[3]; |
205 | - $rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0; |
|
206 | - $rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : ''; |
|
205 | + $rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0; |
|
206 | + $rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : ''; |
|
207 | 207 | $result['RVR'] = $rvr; |
208 | 208 | } |
209 | 209 | //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | $result['RVR']['friction'] = $matches[5]; |
217 | 217 | } |
218 | 218 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
219 | - if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
220 | - else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
219 | + if (isset($matches[5])) $range = array('exact' => (float) $matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
220 | + else $range = array('exact' => (float) $matches[2], 'unit' => 'M'); |
|
221 | 221 | if (isset($matches[3])) { |
222 | 222 | $range = Array( |
223 | - 'from' => (float)$matches[2], |
|
224 | - 'to' => (float)$matches[4], |
|
223 | + 'from' => (float) $matches[2], |
|
224 | + 'to' => (float) $matches[4], |
|
225 | 225 | 'unit' => $matches[5] ? 'FT' : 'M' |
226 | 226 | ); |
227 | 227 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | try { |
270 | 270 | $sth = $this->db->prepare($query); |
271 | 271 | $sth->execute($query_values); |
272 | - } catch(PDOException $e) { |
|
272 | + } catch (PDOException $e) { |
|
273 | 273 | return "error : ".$e->getMessage(); |
274 | 274 | } |
275 | 275 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -279,19 +279,19 @@ discard block |
||
279 | 279 | return $all; |
280 | 280 | } |
281 | 281 | |
282 | - public function addMETAR($location,$metar,$date) { |
|
282 | + public function addMETAR($location, $metar, $date) { |
|
283 | 283 | global $globalDBdriver; |
284 | - $date = date('Y-m-d H:i:s',strtotime($date)); |
|
284 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
285 | 285 | if ($globalDBdriver == 'mysql') { |
286 | 286 | $query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar"; |
287 | 287 | } else { |
288 | 288 | $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);"; |
289 | 289 | } |
290 | - $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar)); |
|
290 | + $query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar)); |
|
291 | 291 | try { |
292 | 292 | $sth = $this->db->prepare($query); |
293 | 293 | $sth->execute($query_values); |
294 | - } catch(PDOException $e) { |
|
294 | + } catch (PDOException $e) { |
|
295 | 295 | return "error : ".$e->getMessage(); |
296 | 296 | } |
297 | 297 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | try { |
303 | 303 | $sth = $this->db->prepare($query); |
304 | 304 | $sth->execute($query_values); |
305 | - } catch(PDOException $e) { |
|
305 | + } catch (PDOException $e) { |
|
306 | 306 | return "error : ".$e->getMessage(); |
307 | 307 | } |
308 | 308 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | try { |
313 | 313 | $sth = $this->db->prepare($query); |
314 | 314 | $sth->execute(); |
315 | - } catch(PDOException $e) { |
|
315 | + } catch (PDOException $e) { |
|
316 | 316 | return "error : ".$e->getMessage(); |
317 | 317 | } |
318 | 318 | } |
@@ -323,27 +323,27 @@ discard block |
||
323 | 323 | date_default_timezone_set("UTC"); |
324 | 324 | $Common = new Common(); |
325 | 325 | if (isset($globalIVAO) && $globalIVAO) { |
326 | - $Common->download('http://wx.ivao.aero/metar.php',dirname(__FILE__).'/../install/tmp/ivaometar.txt'); |
|
327 | - $handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt',"r"); |
|
326 | + $Common->download('http://wx.ivao.aero/metar.php', dirname(__FILE__).'/../install/tmp/ivaometar.txt'); |
|
327 | + $handle = fopen(dirname(__FILE__).'/../install/tmp/ivaometar.txt', "r"); |
|
328 | 328 | } else { |
329 | - $Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT',dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT'); |
|
330 | - $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r"); |
|
329 | + $Common->download('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT', dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT'); |
|
330 | + $handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT', "r"); |
|
331 | 331 | } |
332 | 332 | if ($handle) { |
333 | 333 | if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
334 | 334 | $date = ''; |
335 | 335 | if ($globalTransaction) $this->db->beginTransaction(); |
336 | - while(($line = fgets($handle,4096)) !== false) { |
|
337 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
336 | + while (($line = fgets($handle, 4096)) !== false) { |
|
337 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
338 | 338 | $date = $line; |
339 | 339 | } elseif ($line != '') { |
340 | 340 | if ($date == '') $date = date('Y/m/d H:m'); |
341 | 341 | $pos = 0; |
342 | - $pieces = preg_split('/\s/',$line); |
|
342 | + $pieces = preg_split('/\s/', $line); |
|
343 | 343 | if ($pieces[0] == 'METAR') $pos++; |
344 | 344 | if (strlen($pieces[$pos]) != 4) $pos++; |
345 | 345 | $location = $pieces[$pos]; |
346 | - echo $this->addMETAR($location,$line,$date); |
|
346 | + echo $this->addMETAR($location, $line, $date); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | fclose($handle); |
@@ -357,22 +357,22 @@ discard block |
||
357 | 357 | if ($globalMETARurl == '') return array(); |
358 | 358 | date_default_timezone_set("UTC"); |
359 | 359 | $Common = new Common(); |
360 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
360 | + $url = str_replace('{icao}', $icao, $globalMETARurl); |
|
361 | 361 | $cycle = $Common->getData($url); |
362 | 362 | $date = ''; |
363 | - foreach(explode("\n",$cycle) as $line) { |
|
364 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
363 | + foreach (explode("\n", $cycle) as $line) { |
|
364 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
365 | 365 | $date = $line; |
366 | 366 | } |
367 | 367 | if ($line != '') { |
368 | 368 | if ($date == '') $date = date('Y/m/d H:m'); |
369 | 369 | $pos = 0; |
370 | - $pieces = preg_split('/\s/',$line); |
|
370 | + $pieces = preg_split('/\s/', $line); |
|
371 | 371 | if ($pieces[0] == 'METAR') $pos++; |
372 | 372 | if (strlen($pieces[$pos]) != 4) $pos++; |
373 | 373 | $location = $pieces[$pos]; |
374 | 374 | if (strlen($location == 4)) { |
375 | - $this->addMETAR($location,$line,$date); |
|
375 | + $this->addMETAR($location, $line, $date); |
|
376 | 376 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
377 | 377 | } else return array(); |
378 | 378 | } |