@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | die; |
41 | 41 | } |
42 | 42 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
43 | - $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
|
43 | + $globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | -$options = getopt('s::',array('source::','server','idsource::')); |
|
47 | +$options = getopt('s::', array('source::', 'server', 'idsource::')); |
|
48 | 48 | //if (isset($options['s'])) $hosts = array($options['s']); |
49 | 49 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
50 | 50 | if (isset($options['s'])) { |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | else $id_source = 1; |
60 | 60 | if (isset($globalServer) && $globalServer) { |
61 | 61 | if ($globalDebug) echo "Using Server Mode\n"; |
62 | - $SI=new SpotterServer(); |
|
63 | -} else $SI=new SpotterImport($Connection->db); |
|
62 | + $SI = new SpotterServer(); |
|
63 | +} else $SI = new SpotterImport($Connection->db); |
|
64 | 64 | //$APRS=new APRS($Connection->db); |
65 | -$SBS=new SBS(); |
|
66 | -$ACARS=new ACARS($Connection->db); |
|
67 | -$Common=new Common(); |
|
65 | +$SBS = new SBS(); |
|
66 | +$ACARS = new ACARS($Connection->db); |
|
67 | +$Common = new Common(); |
|
68 | 68 | date_default_timezone_set('UTC'); |
69 | 69 | //$servertz = system('date +%Z'); |
70 | 70 | // signal handler - playing nice with sockets and dump1090 |
71 | 71 | if (function_exists('pcntl_fork')) { |
72 | - pcntl_signal(SIGINT, function() { |
|
72 | + pcntl_signal(SIGINT, function() { |
|
73 | 73 | global $sockets; |
74 | 74 | echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
75 | 75 | die("Bye!\n"); |
@@ -113,35 +113,35 @@ discard block |
||
113 | 113 | |
114 | 114 | function connect_all($hosts) { |
115 | 115 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
116 | - global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
116 | + global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset; |
|
117 | 117 | $reset++; |
118 | 118 | if ($globalDebug) echo 'Connect to all...'."\n"; |
119 | 119 | foreach ($hosts as $id => $value) { |
120 | 120 | $host = $value['host']; |
121 | 121 | $globalSources[$id]['last_exec'] = 0; |
122 | 122 | // Here we check type of source(s) |
123 | - if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
124 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
123 | + if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
124 | + if (preg_match('/deltadb.txt$/i', $host)) { |
|
125 | 125 | //$formats[$id] = 'deltadbtxt'; |
126 | 126 | $globalSources[$id]['format'] = 'deltadbtxt'; |
127 | 127 | //$last_exec['deltadbtxt'] = 0; |
128 | 128 | if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
129 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
129 | + } else if (preg_match('/vatsim-data.txt$/i', $host)) { |
|
130 | 130 | //$formats[$id] = 'vatsimtxt'; |
131 | 131 | $globalSources[$id]['format'] = 'vatsimtxt'; |
132 | 132 | //$last_exec['vatsimtxt'] = 0; |
133 | 133 | if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
134 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
134 | + } else if (preg_match('/aircraftlist.json$/i', $host)) { |
|
135 | 135 | //$formats[$id] = 'aircraftlistjson'; |
136 | 136 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
137 | 137 | //$last_exec['aircraftlistjson'] = 0; |
138 | 138 | if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
139 | - } else if (preg_match('/opensky/i',$host)) { |
|
139 | + } else if (preg_match('/opensky/i', $host)) { |
|
140 | 140 | //$formats[$id] = 'aircraftlistjson'; |
141 | 141 | $globalSources[$id]['format'] = 'opensky'; |
142 | 142 | //$last_exec['aircraftlistjson'] = 0; |
143 | 143 | if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
144 | - } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
|
144 | + } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) { |
|
145 | 145 | //$formats[$id] = 'radarvirtueljson'; |
146 | 146 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
147 | 147 | //$last_exec['radarvirtueljson'] = 0; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
151 | 151 | exit(0); |
152 | 152 | } |
153 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
153 | + } else if (preg_match('/planeUpdateFAA.php$/i', $host)) { |
|
154 | 154 | //$formats[$id] = 'planeupdatefaa'; |
155 | 155 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
156 | 156 | //$last_exec['planeupdatefaa'] = 0; |
@@ -159,26 +159,26 @@ discard block |
||
159 | 159 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
160 | 160 | exit(0); |
161 | 161 | } |
162 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
162 | + } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) { |
|
163 | 163 | //$formats[$id] = 'phpvmacars'; |
164 | 164 | $globalSources[$id]['format'] = 'phpvmacars'; |
165 | 165 | //$last_exec['phpvmacars'] = 0; |
166 | 166 | if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
167 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
167 | + } else if (preg_match('/VAM-json.php$/i', $host)) { |
|
168 | 168 | //$formats[$id] = 'phpvmacars'; |
169 | 169 | $globalSources[$id]['format'] = 'vam'; |
170 | 170 | if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
171 | - } else if (preg_match('/whazzup/i',$host)) { |
|
171 | + } else if (preg_match('/whazzup/i', $host)) { |
|
172 | 172 | //$formats[$id] = 'whazzup'; |
173 | 173 | $globalSources[$id]['format'] = 'whazzup'; |
174 | 174 | //$last_exec['whazzup'] = 0; |
175 | 175 | if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
176 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
176 | + } else if (preg_match('/recentpireps/i', $host)) { |
|
177 | 177 | //$formats[$id] = 'pirepsjson'; |
178 | 178 | $globalSources[$id]['format'] = 'pirepsjson'; |
179 | 179 | //$last_exec['pirepsjson'] = 0; |
180 | 180 | if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
181 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
181 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) { |
|
182 | 182 | //$formats[$id] = 'fr24json'; |
183 | 183 | $globalSources[$id]['format'] = 'fr24json'; |
184 | 184 | //$last_exec['fr24json'] = 0; |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | exit(0); |
189 | 189 | } |
190 | 190 | //} else if (preg_match('/10001/',$host)) { |
191 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
191 | + } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
192 | 192 | //$formats[$id] = 'tsv'; |
193 | 193 | $globalSources[$id]['format'] = 'tsv'; |
194 | 194 | if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
195 | 195 | } |
196 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
196 | + } elseif (filter_var($host, FILTER_VALIDATE_URL)) { |
|
197 | 197 | if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
198 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
199 | - $hostport = explode(':',$host); |
|
198 | + } elseif (!filter_var($host, FILTER_VALIDATE_URL)) { |
|
199 | + $hostport = explode(':', $host); |
|
200 | 200 | if (isset($hostport[1])) { |
201 | 201 | $port = $hostport[1]; |
202 | 202 | $hostn = $hostport[0]; |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | $hostn = $globalSources[$id]['host']; |
206 | 206 | } |
207 | 207 | if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
208 | - $s = create_socket($hostn,$port, $errno, $errstr); |
|
208 | + $s = create_socket($hostn, $port, $errno, $errstr); |
|
209 | 209 | } else { |
210 | - $s = create_socket_udp($hostn,$port, $errno, $errstr); |
|
210 | + $s = create_socket_udp($hostn, $port, $errno, $errstr); |
|
211 | 211 | } |
212 | 212 | if ($s) { |
213 | 213 | $sockets[$id] = $s; |
214 | 214 | if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
215 | - if (preg_match('/aprs/',$hostn)) { |
|
215 | + if (preg_match('/aprs/', $hostn)) { |
|
216 | 216 | //$formats[$id] = 'aprs'; |
217 | 217 | $globalSources[$id]['format'] = 'aprs'; |
218 | 218 | //$aprs_connect = 0; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
254 | 254 | else $timeout = 20; |
255 | 255 | $errno = ''; |
256 | -$errstr=''; |
|
256 | +$errstr = ''; |
|
257 | 257 | |
258 | 258 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
259 | 259 | /* Initiate connections to all the hosts simultaneously */ |
@@ -282,16 +282,16 @@ discard block |
||
282 | 282 | |
283 | 283 | if ($use_aprs) { |
284 | 284 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
285 | - $APRS=new APRS(); |
|
285 | + $APRS = new APRS(); |
|
286 | 286 | $aprs_connect = 0; |
287 | 287 | $aprs_keep = 120; |
288 | 288 | $aprs_last_tx = time(); |
289 | 289 | if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
290 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
290 | + else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName); |
|
291 | 291 | if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
292 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
292 | + else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8); |
|
293 | 293 | if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
294 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
294 | + else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
295 | 295 | if ($aprs_full) $aprs_filter = ''; |
296 | 296 | |
297 | 297 | if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
@@ -303,12 +303,12 @@ discard block |
||
303 | 303 | sleep(1); |
304 | 304 | if ($globalDebug) echo "SCAN MODE \n\n"; |
305 | 305 | if (!isset($globalCronEnd)) $globalCronEnd = 60; |
306 | -$endtime = time()+$globalCronEnd; |
|
306 | +$endtime = time() + $globalCronEnd; |
|
307 | 307 | $i = 1; |
308 | 308 | $tt = array(); |
309 | 309 | // Delete all ATC |
310 | 310 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) { |
311 | - $ATC=new ATC($Connection->db); |
|
311 | + $ATC = new ATC($Connection->db); |
|
312 | 312 | } |
313 | 313 | if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
314 | 314 | $ATC->deleteAll(); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | |
317 | 317 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
318 | 318 | while ($i > 0) { |
319 | - if (!$globalDaemon) $i = $endtime-time(); |
|
319 | + if (!$globalDaemon) $i = $endtime - time(); |
|
320 | 320 | // Delete old ATC |
321 | 321 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
322 | 322 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | } |
331 | 331 | if ($max != $globalMinFetch) { |
332 | 332 | if ($globalDebug) echo 'Sleeping...'."\n"; |
333 | - sleep($globalMinFetch-$max+2); |
|
333 | + sleep($globalMinFetch - $max + 2); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | //$buffer = $Common->getData($hosts[$id]); |
344 | 344 | $buffer = $Common->getData($value['host']); |
345 | 345 | if ($buffer != '') $reset = 0; |
346 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
347 | - $buffer = explode('\n',$buffer); |
|
346 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
347 | + $buffer = explode('\n', $buffer); |
|
348 | 348 | foreach ($buffer as $line) { |
349 | 349 | if ($line != '' && count($line) > 7) { |
350 | 350 | $line = explode(',', $line); |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | } elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) { |
374 | 374 | //$buffer = $Common->getData($hosts[$id]); |
375 | 375 | $buffer = $Common->getData($value['host']); |
376 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
377 | - $buffer = explode('\n',$buffer); |
|
376 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
377 | + $buffer = explode('\n', $buffer); |
|
378 | 378 | $reset = 0; |
379 | 379 | foreach ($buffer as $line) { |
380 | 380 | if ($line != '') { |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
386 | 386 | $data['pilot_id'] = $line[1]; |
387 | 387 | $data['pilot_name'] = $line[2]; |
388 | - $data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT); |
|
388 | + $data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT); |
|
389 | 389 | $data['ident'] = $line[0]; // ident |
390 | 390 | if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
391 | 391 | $data['speed'] = $line[8]; // speed |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
402 | 402 | //if (isset($line[37])) $data['last_update'] = $line[37]; |
403 | 403 | $data['departure_airport_icao'] = $line[11]; |
404 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
404 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':'); |
|
405 | 405 | $data['arrival_airport_icao'] = $line[13]; |
406 | 406 | $data['frequency'] = $line[4]; |
407 | 407 | $data['type'] = $line[18]; |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | $data['id_source'] = $id_source; |
411 | 411 | //$data['arrival_airport_time'] = ; |
412 | 412 | if ($line[9] != '') { |
413 | - $aircraft_data = explode('/',$line[9]); |
|
413 | + $aircraft_data = explode('/', $line[9]); |
|
414 | 414 | if (isset($aircraft_data[1])) { |
415 | 415 | $data['aircraft_icao'] = $aircraft_data[1]; |
416 | 416 | } |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | if ($line[3] == 'PILOT') $SI->add($data); |
425 | 425 | elseif ($line[3] == 'ATC') { |
426 | 426 | //print_r($data); |
427 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
428 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
429 | - $typec = substr($data['ident'],-3); |
|
427 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
428 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
429 | + $typec = substr($data['ident'], -3); |
|
430 | 430 | if ($typec == 'APP') $data['type'] = 'Approach'; |
431 | 431 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
432 | 432 | elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
438 | 438 | elseif ($data['type'] == '') $data['type'] = 'Observer'; |
439 | 439 | if (!isset($data['source_name'])) $data['source_name'] = ''; |
440 | - echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
440 | + echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']); |
|
441 | 441 | } |
442 | 442 | unset($data); |
443 | 443 | } |
@@ -448,9 +448,9 @@ discard block |
||
448 | 448 | $last_exec[$id]['last'] = time(); |
449 | 449 | //} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { |
450 | 450 | } elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
451 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
451 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
452 | 452 | if ($buffer != '') { |
453 | - $all_data = json_decode($buffer,true); |
|
453 | + $all_data = json_decode($buffer, true); |
|
454 | 454 | if (isset($all_data['acList'])) { |
455 | 455 | $reset = 0; |
456 | 456 | foreach ($all_data['acList'] as $line) { |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
507 | 507 | } elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
508 | 508 | $buffer = $Common->getData($value['host']); |
509 | - $all_data = json_decode($buffer,true); |
|
509 | + $all_data = json_decode($buffer, true); |
|
510 | 510 | if (isset($all_data['planes'])) { |
511 | 511 | $reset = 0; |
512 | 512 | foreach ($all_data['planes'] as $key => $line) { |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | $data['emergency'] = ''; // emergency |
524 | 524 | $data['registration'] = $line[2]; |
525 | 525 | $data['aircraft_icao'] = $line[0]; |
526 | - $deparr = explode('-',$line[1]); |
|
526 | + $deparr = explode('-', $line[1]); |
|
527 | 527 | if (count($deparr) == 2) { |
528 | 528 | $data['departure_airport_icao'] = $deparr[0]; |
529 | 529 | $data['arrival_airport_icao'] = $deparr[1]; |
530 | 530 | } |
531 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
531 | + $data['datetime'] = date('Y-m-d H:i:s', $line[9]); |
|
532 | 532 | $data['format_source'] = 'planeupdatefaa'; |
533 | 533 | $data['id_source'] = $id_source; |
534 | 534 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | $last_exec[$id]['last'] = time(); |
541 | 541 | } elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
542 | 542 | $buffer = $Common->getData($value['host']); |
543 | - $all_data = json_decode($buffer,true); |
|
543 | + $all_data = json_decode($buffer, true); |
|
544 | 544 | if (isset($all_data['states'])) { |
545 | 545 | $reset = 0; |
546 | 546 | foreach ($all_data['states'] as $key => $line) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | //$data['emergency'] = ''; // emergency |
558 | 558 | //$data['registration'] = $line[2]; |
559 | 559 | //$data['aircraft_icao'] = $line[0]; |
560 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
560 | + $data['datetime'] = date('Y-m-d H:i:s', $line[3]); |
|
561 | 561 | $data['format_source'] = 'opensky'; |
562 | 562 | $data['id_source'] = $id_source; |
563 | 563 | $SI->add($data); |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | } elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
571 | 571 | //$buffer = $Common->getData($hosts[$id]); |
572 | 572 | $buffer = $Common->getData($value['host']); |
573 | - $all_data = json_decode($buffer,true); |
|
573 | + $all_data = json_decode($buffer, true); |
|
574 | 574 | if (!empty($all_data)) $reset = 0; |
575 | 575 | foreach ($all_data as $key => $line) { |
576 | 576 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
@@ -602,11 +602,11 @@ discard block |
||
602 | 602 | //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
603 | 603 | } elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
604 | 604 | //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
605 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
605 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150'); |
|
606 | 606 | //echo $buffer; |
607 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
608 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
609 | - $all_data = json_decode($buffer,true); |
|
607 | + $buffer = str_replace(array("\n", "\r"), "", $buffer); |
|
608 | + $buffer = preg_replace('/,"num":(.+)/', '}', $buffer); |
|
609 | + $all_data = json_decode($buffer, true); |
|
610 | 610 | if (json_last_error() != JSON_ERROR_NONE) { |
611 | 611 | die(json_last_error_msg()); |
612 | 612 | } |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | //$data['departure_airport_iata'] = $line[11]; |
630 | 630 | //$data['arrival_airport_iata'] = $line[12]; |
631 | 631 | //$data['emergency'] = ''; // emergency |
632 | - $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
|
632 | + $data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10] |
|
633 | 633 | $data['format_source'] = 'radarvirtueljson'; |
634 | 634 | $data['id_source'] = $id_source; |
635 | 635 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
@@ -644,14 +644,14 @@ discard block |
||
644 | 644 | } elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
645 | 645 | //$buffer = $Common->getData($hosts[$id]); |
646 | 646 | $buffer = $Common->getData($value['host'].'?'.time()); |
647 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
647 | + $all_data = json_decode(utf8_encode($buffer), true); |
|
648 | 648 | |
649 | 649 | if (isset($all_data['pireps'])) { |
650 | 650 | $reset = 0; |
651 | 651 | foreach ($all_data['pireps'] as $line) { |
652 | 652 | $data = array(); |
653 | 653 | $data['id'] = $line['id']; |
654 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
654 | + $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
655 | 655 | $data['ident'] = $line['callsign']; // ident |
656 | 656 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
657 | 657 | if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
@@ -680,9 +680,9 @@ discard block |
||
680 | 680 | $SI->add($data); |
681 | 681 | // print_r($data); |
682 | 682 | } elseif ($line['icon'] == 'ct') { |
683 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
684 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
685 | - $typec = substr($data['ident'],-3); |
|
683 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
684 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
685 | + $typec = substr($data['ident'], -3); |
|
686 | 686 | $data['type'] = ''; |
687 | 687 | if ($typec == 'APP') $data['type'] = 'Approach'; |
688 | 688 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
694 | 694 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
695 | 695 | else $data['type'] = 'Observer'; |
696 | - echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
696 | + echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']); |
|
697 | 697 | } |
698 | 698 | unset($data); |
699 | 699 | } |
@@ -705,14 +705,14 @@ discard block |
||
705 | 705 | //$buffer = $Common->getData($hosts[$id]); |
706 | 706 | if ($globalDebug) echo 'Get Data...'."\n"; |
707 | 707 | $buffer = $Common->getData($value['host']); |
708 | - $all_data = json_decode($buffer,true); |
|
708 | + $all_data = json_decode($buffer, true); |
|
709 | 709 | if ($buffer != '' && is_array($all_data)) { |
710 | 710 | $reset = 0; |
711 | 711 | foreach ($all_data as $line) { |
712 | 712 | $data = array(); |
713 | 713 | //$data['id'] = $line['id']; // id not usable |
714 | 714 | if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
715 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
715 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
716 | 716 | if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
717 | 717 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
718 | 718 | $data['ident'] = $line['flightnum']; // ident |
@@ -735,12 +735,12 @@ discard block |
||
735 | 735 | if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
736 | 736 | if (isset($line['aircraftname'])) { |
737 | 737 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
738 | - $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
|
739 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
738 | + $line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']); |
|
739 | + $aircraft_data = explode('-', $line['aircraftname']); |
|
740 | 740 | if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
741 | 741 | elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
742 | 742 | else { |
743 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
743 | + $aircraft_data = explode(' ', $line['aircraftname']); |
|
744 | 744 | if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
745 | 745 | else $data['aircraft_icao'] = $line['aircraftname']; |
746 | 746 | } |
@@ -762,14 +762,14 @@ discard block |
||
762 | 762 | //$buffer = $Common->getData($hosts[$id]); |
763 | 763 | if ($globalDebug) echo 'Get Data...'."\n"; |
764 | 764 | $buffer = $Common->getData($value['host']); |
765 | - $all_data = json_decode($buffer,true); |
|
765 | + $all_data = json_decode($buffer, true); |
|
766 | 766 | if ($buffer != '' && is_array($all_data)) { |
767 | 767 | $reset = 0; |
768 | 768 | foreach ($all_data as $line) { |
769 | 769 | $data = array(); |
770 | 770 | //$data['id'] = $line['id']; // id not usable |
771 | 771 | $data['id'] = trim($line['flight_id']); |
772 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
772 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
773 | 773 | $data['pilot_name'] = $line['pilot_name']; |
774 | 774 | $data['pilot_id'] = $line['pilot_id']; |
775 | 775 | $data['ident'] = trim($line['callsign']); // ident |
@@ -820,9 +820,9 @@ discard block |
||
820 | 820 | //$value = $formats[$nb]; |
821 | 821 | $format = $globalSources[$nb]['format']; |
822 | 822 | if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
823 | - $buffer = socket_read($r, 6000,PHP_NORMAL_READ); |
|
823 | + $buffer = socket_read($r, 6000, PHP_NORMAL_READ); |
|
824 | 824 | } else { |
825 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
825 | + $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port); |
|
826 | 826 | } |
827 | 827 | //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
828 | 828 | //echo $buffer."\n"; |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
831 | 831 | $error = false; |
832 | 832 | //$SI::del(); |
833 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
833 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer)); |
|
834 | 834 | // SBS format is CSV format |
835 | 835 | if ($buffer != '') { |
836 | 836 | $tt[$format] = 0; |
@@ -851,10 +851,10 @@ discard block |
||
851 | 851 | } elseif ($format == 'flightgearsp') { |
852 | 852 | //echo $buffer."\n"; |
853 | 853 | if (strlen($buffer) > 5) { |
854 | - $line = explode(',',$buffer); |
|
854 | + $line = explode(',', $buffer); |
|
855 | 855 | $data = array(); |
856 | 856 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
857 | - $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6); |
|
857 | + $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
858 | 858 | $data['ident'] = $line[6]; |
859 | 859 | $data['aircraft_name'] = $line[7]; |
860 | 860 | $data['longitude'] = $line[1]; |
@@ -865,21 +865,21 @@ discard block |
||
865 | 865 | $data['datetime'] = date('Y-m-d H:i:s'); |
866 | 866 | $data['format_source'] = 'flightgearsp'; |
867 | 867 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
868 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
868 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
869 | 869 | } |
870 | 870 | } elseif ($format == 'acars') { |
871 | 871 | if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
872 | 872 | $ACARS->add(trim($buffer)); |
873 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
873 | + socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port); |
|
874 | 874 | $ACARS->deleteLiveAcarsData(); |
875 | 875 | } elseif ($format == 'flightgearmp') { |
876 | - if (substr($buffer,0,1) != '#') { |
|
876 | + if (substr($buffer, 0, 1) != '#') { |
|
877 | 877 | $data = array(); |
878 | 878 | //echo $buffer."\n"; |
879 | - $line = explode(' ',$buffer); |
|
879 | + $line = explode(' ', $buffer); |
|
880 | 880 | if (count($line) == 11) { |
881 | - $userserver = explode('@',$line[0]); |
|
882 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
881 | + $userserver = explode('@', $line[0]); |
|
882 | + $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex |
|
883 | 883 | $data['ident'] = $userserver[0]; |
884 | 884 | $data['registration'] = $userserver[0]; |
885 | 885 | $data['latitude'] = $line[4]; |
@@ -887,24 +887,24 @@ discard block |
||
887 | 887 | $data['altitude'] = $line[6]; |
888 | 888 | $data['datetime'] = date('Y-m-d H:i:s'); |
889 | 889 | $aircraft_type = $line[10]; |
890 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
891 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
890 | + $aircraft_type = preg_split(':/:', $aircraft_type); |
|
891 | + $data['aircraft_name'] = substr(end($aircraft_type), 0, -4); |
|
892 | 892 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
893 | 893 | } |
894 | 894 | } |
895 | 895 | } elseif ($format == 'beast') { |
896 | 896 | echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
897 | 897 | die; |
898 | - } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
|
898 | + } elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') { |
|
899 | 899 | $line = explode("\t", $buffer); |
900 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
900 | + for ($k = 0; $k < count($line); $k = $k + 2) { |
|
901 | 901 | $key = $line[$k]; |
902 | - $lined[$key] = $line[$k+1]; |
|
902 | + $lined[$key] = $line[$k + 1]; |
|
903 | 903 | } |
904 | 904 | if (count($lined) > 3) { |
905 | 905 | $data['hex'] = $lined['hexid']; |
906 | 906 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
907 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
907 | + $data['datetime'] = date('Y-m-d H:i:s'); ; |
|
908 | 908 | if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
909 | 909 | if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
910 | 910 | if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
@@ -922,21 +922,21 @@ discard block |
||
922 | 922 | } else $error = true; |
923 | 923 | } elseif ($format == 'aprs' && $use_aprs) { |
924 | 924 | if ($aprs_connect == 0) { |
925 | - $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
|
925 | + $send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0); |
|
926 | 926 | $aprs_connect = 1; |
927 | 927 | } |
928 | 928 | |
929 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
929 | + if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) { |
|
930 | 930 | $aprs_last_tx = time(); |
931 | 931 | $data_aprs = "# Keep alive"; |
932 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
932 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
936 | - $buffer = str_replace('APRS <- ','',$buffer); |
|
937 | - $buffer = str_replace('APRS -> ','',$buffer); |
|
936 | + $buffer = str_replace('APRS <- ', '', $buffer); |
|
937 | + $buffer = str_replace('APRS -> ', '', $buffer); |
|
938 | 938 | //echo $buffer."\n"; |
939 | - if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
939 | + if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') { |
|
940 | 940 | $line = $APRS->parse($buffer); |
941 | 941 | //print_r($line); |
942 | 942 | if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | $data = array(); |
945 | 945 | //print_r($line); |
946 | 946 | $data['hex'] = $line['address']; |
947 | - $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
947 | + $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']); |
|
948 | 948 | //$data['datetime'] = date('Y-m-d H:i:s'); |
949 | 949 | $data['ident'] = $line['ident']; |
950 | 950 | $data['latitude'] = $line['latitude']; |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $currentdate = date('Y-m-d H:i:s'); |
965 | 965 | $aprsdate = strtotime($data['datetime']); |
966 | 966 | // Accept data if time <= system time + 20s |
967 | - if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
967 | + if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
968 | 968 | $send = $SI->add($data); |
969 | 969 | } else { |
970 | 970 | if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | connect_all($sourceee); |
1055 | 1055 | $sourceee = array(); |
1056 | 1056 | //connect_all($globalSources); |
1057 | - $tt[$format]=0; |
|
1057 | + $tt[$format] = 0; |
|
1058 | 1058 | break; |
1059 | 1059 | } |
1060 | 1060 | } |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | } |
1063 | 1063 | } else { |
1064 | 1064 | $error = socket_strerror(socket_last_error()); |
1065 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1065 | + if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n"; |
|
1066 | 1066 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { |
1067 | 1067 | if (isset($globalDebug)) echo "Restarting...\n"; |
1068 | 1068 | // Restart the script if possible |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | if ($globalDebug) echo "Shutdown all sockets..."; |
1071 | 1071 | |
1072 | 1072 | foreach ($sockets as $sock) { |
1073 | - @socket_shutdown($sock,2); |
|
1073 | + @socket_shutdown($sock, 2); |
|
1074 | 1074 | @socket_close($sock); |
1075 | 1075 | } |
1076 | 1076 |
@@ -85,8 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | |
87 | 87 | private function urshift($n, $s) { |
88 | - return ($n >= 0) ? ($n >> $s) : |
|
89 | - (($n & 0x7fffffff) >> $s) | |
|
88 | + return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| |
|
90 | 89 | (0x40000000 >> ($s - 1)); |
91 | 90 | } |
92 | 91 | |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | //$split_input = str_split($input); |
99 | 98 | |
100 | 99 | /* Find the end of header checking for NULL bytes while doing it. */ |
101 | - $splitpos = strpos($input,':'); |
|
100 | + $splitpos = strpos($input, ':'); |
|
102 | 101 | |
103 | 102 | /* Check that end was found and body has at least one byte. */ |
104 | 103 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
@@ -107,28 +106,28 @@ discard block |
||
107 | 106 | } |
108 | 107 | |
109 | 108 | /* Save header and body. */ |
110 | - $body = substr($input,$splitpos+1,$input_len); |
|
109 | + $body = substr($input, $splitpos + 1, $input_len); |
|
111 | 110 | $body_len = strlen($body); |
112 | - $header = substr($input,0,$splitpos); |
|
111 | + $header = substr($input, 0, $splitpos); |
|
113 | 112 | //$header_len = strlen($header); |
114 | 113 | if ($debug) echo 'header : '.$header."\n"; |
115 | 114 | |
116 | 115 | /* Parse source, target and path. */ |
117 | 116 | //FLRDF0A52>APRS,qAS,LSTB |
118 | - if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
|
117 | + if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) { |
|
119 | 118 | $ident = $matches[1]; |
120 | 119 | $all_elements = $matches[2]; |
121 | 120 | if ($debug) echo 'ident : '.$ident."\n"; |
122 | 121 | $result['ident'] = $ident; |
123 | 122 | } else return false; |
124 | - $elements = explode(',',$all_elements); |
|
123 | + $elements = explode(',', $all_elements); |
|
125 | 124 | $source = end($elements); |
126 | 125 | $result['source'] = $source; |
127 | 126 | foreach ($elements as $element) { |
128 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
127 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) { |
|
129 | 128 | //echo "ok"; |
130 | 129 | //if ($element == 'TCPIP*') return false; |
131 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
130 | + } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) { |
|
132 | 131 | echo 'element : '.$element."\n"; |
133 | 132 | return false; |
134 | 133 | } |
@@ -142,24 +141,24 @@ discard block |
||
142 | 141 | } |
143 | 142 | // Check for Timestamp |
144 | 143 | $find = false; |
145 | - $body_parse = substr($body,1); |
|
144 | + $body_parse = substr($body, 1); |
|
146 | 145 | //echo 'Body : '.$body."\n"; |
147 | - if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
|
148 | - $body_parse = substr($body_parse,10); |
|
146 | + if (preg_match('/^;(.){9}\*/', $body, $matches)) { |
|
147 | + $body_parse = substr($body_parse, 10); |
|
149 | 148 | $find = true; |
150 | 149 | //echo $body_parse."\n"; |
151 | 150 | } |
152 | - if (preg_match('/^`(.*)\//',$body,$matches)) { |
|
153 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
151 | + if (preg_match('/^`(.*)\//', $body, $matches)) { |
|
152 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
154 | 153 | $find = true; |
155 | 154 | //echo $body_parse."\n"; |
156 | 155 | } |
157 | - if (preg_match("/^'(.*)\//",$body,$matches)) { |
|
158 | - $body_parse = substr($body_parse,strlen($matches[1])-1); |
|
156 | + if (preg_match("/^'(.*)\//", $body, $matches)) { |
|
157 | + $body_parse = substr($body_parse, strlen($matches[1]) - 1); |
|
159 | 158 | $find = true; |
160 | 159 | //echo $body_parse."\n"; |
161 | 160 | } |
162 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
|
161 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) { |
|
163 | 162 | $find = true; |
164 | 163 | //print_r($matches); |
165 | 164 | $timestamp = $matches[0]; |
@@ -174,19 +173,19 @@ discard block |
||
174 | 173 | // This work or not ? |
175 | 174 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
176 | 175 | } |
177 | - $body_parse = substr($body_parse,7); |
|
176 | + $body_parse = substr($body_parse, 7); |
|
178 | 177 | $result['timestamp'] = $timestamp; |
179 | 178 | //echo date('Ymd H:i:s',$timestamp); |
180 | 179 | } |
181 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
|
180 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) { |
|
182 | 181 | $find = true; |
183 | 182 | $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
184 | - $body_parse = substr($body_parse,8); |
|
183 | + $body_parse = substr($body_parse, 8); |
|
185 | 184 | $result['timestamp'] = $timestamp; |
186 | 185 | //echo date('Ymd H:i:s',$timestamp); |
187 | 186 | } |
188 | 187 | //if (strlen($body_parse) > 19) { |
189 | - if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { |
|
188 | + if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) { |
|
190 | 189 | $find = true; |
191 | 190 | // 4658.70N/00707.78Ez |
192 | 191 | //print_r(str_split($body_parse)); |
@@ -212,11 +211,11 @@ discard block |
||
212 | 211 | */ |
213 | 212 | $latitude = $lat + floatval($lat_min)/60; |
214 | 213 | $longitude = $lon + floatval($lon_min)/60; |
215 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
216 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
214 | + if ($sind == 'S') $latitude = 0 - $latitude; |
|
215 | + if ($wind == 'W') $longitude = 0 - $longitude; |
|
217 | 216 | $result['latitude'] = $latitude; |
218 | 217 | $result['longitude'] = $longitude; |
219 | - $body_parse = substr($body_parse,18); |
|
218 | + $body_parse = substr($body_parse, 18); |
|
220 | 219 | $body_parse_len = strlen($body_parse); |
221 | 220 | } |
222 | 221 | $body_parse_len = strlen($body_parse); |
@@ -240,7 +239,7 @@ discard block |
||
240 | 239 | if ($find) { |
241 | 240 | $body_split = str_split($body_parse); |
242 | 241 | $symbol_code = $body_split[0]; |
243 | - $body_parse = substr($body_parse,1); |
|
242 | + $body_parse = substr($body_parse, 1); |
|
244 | 243 | $body_parse_len = strlen($body_parse); |
245 | 244 | //} |
246 | 245 | //echo $body_parse; |
@@ -252,13 +251,13 @@ discard block |
||
252 | 251 | //$body_parse_len = strlen($body_parse); |
253 | 252 | if ($body_parse_len >= 7) { |
254 | 253 | |
255 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
256 | - $course = substr($body_parse,0,3); |
|
254 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) { |
|
255 | + $course = substr($body_parse, 0, 3); |
|
257 | 256 | $tmp_s = intval($course); |
258 | 257 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
259 | - $speed = substr($body_parse,4,3); |
|
258 | + $speed = substr($body_parse, 4, 3); |
|
260 | 259 | $result['speed'] = round($speed*1.852); |
261 | - $body_parse = substr($body_parse,7); |
|
260 | + $body_parse = substr($body_parse, 7); |
|
262 | 261 | } |
263 | 262 | // Check PHGR, PHG, RNG |
264 | 263 | } |
@@ -268,11 +267,11 @@ discard block |
||
268 | 267 | } |
269 | 268 | */ |
270 | 269 | if (strlen($body_parse) > 0) { |
271 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
270 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) { |
|
272 | 271 | $altitude = intval($matches[1]); |
273 | 272 | //$result['altitude'] = round($altitude*0.3048); |
274 | 273 | $result['altitude'] = $altitude; |
275 | - $body_parse = trim(substr($body_parse,strlen($matches[0]))); |
|
274 | + $body_parse = trim(substr($body_parse, strlen($matches[0]))); |
|
276 | 275 | } |
277 | 276 | } |
278 | 277 | |
@@ -283,35 +282,35 @@ discard block |
||
283 | 282 | } |
284 | 283 | */ |
285 | 284 | // DAO |
286 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
285 | + if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) { |
|
287 | 286 | $dao = $matches[1]; |
288 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
287 | + if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) { |
|
289 | 288 | $dao_split = str_split($dao); |
290 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
291 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
289 | + $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0; |
|
290 | + $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0; |
|
292 | 291 | |
293 | 292 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
294 | 293 | else $result['latitude'] += $lat_off; |
295 | 294 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
296 | 295 | else $result['longitude'] += $lon_off; |
297 | 296 | } |
298 | - $body_parse = substr($body_parse,6); |
|
297 | + $body_parse = substr($body_parse, 6); |
|
299 | 298 | } |
300 | 299 | |
301 | 300 | // OGN comment |
302 | 301 | // echo "Before OGN : ".$body_parse."\n"; |
303 | 302 | //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
304 | - if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
|
303 | + if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) { |
|
305 | 304 | $id = $matches[1]; |
306 | 305 | //$mode = substr($id,0,2); |
307 | - $address = substr($id,2); |
|
306 | + $address = substr($id, 2); |
|
308 | 307 | //print_r($matches); |
309 | - $addressType = (intval(substr($id,0,2),16))&3; |
|
308 | + $addressType = (intval(substr($id, 0, 2), 16))&3; |
|
310 | 309 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
311 | 310 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
312 | 311 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
313 | 312 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
314 | - $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
|
313 | + $aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2); |
|
315 | 314 | $result['aircrafttype_code'] = $aircraftType; |
316 | 315 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
317 | 316 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
@@ -328,7 +327,7 @@ discard block |
||
328 | 327 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
329 | 328 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
330 | 329 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
331 | - $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
|
330 | + $stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0; |
|
332 | 331 | $result['stealth'] = $stealth; |
333 | 332 | $result['address'] = $address; |
334 | 333 | } |
@@ -340,39 +339,39 @@ discard block |
||
340 | 339 | //$body_parse = substr($body_parse,1); |
341 | 340 | //$body_parse_len = strlen($body_parse); |
342 | 341 | |
343 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
342 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
344 | 343 | $result['wind_dir'] = intval($matches[1]); |
345 | - $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
|
346 | - $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
|
347 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
348 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
349 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
344 | + $result['wind_speed'] = round(intval($matches[2])*1.60934, 1); |
|
345 | + $result['wind_gust'] = round(intval($matches[3])*1.60934, 1); |
|
346 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
347 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
348 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
350 | 349 | $result['wind_dir'] = intval($matches[1]); |
351 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
352 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
353 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
354 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
355 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
350 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
351 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
352 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
353 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
354 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
356 | 355 | $result['wind_dir'] = intval($matches[1]); |
357 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
358 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
359 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
360 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
356 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
357 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
358 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
359 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) { |
|
361 | 360 | $result['wind_dir'] = intval($matches[1]); |
362 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
363 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
364 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
361 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
362 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
363 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
365 | 364 | } |
366 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
367 | - $result['temp'] = round(5/9*(($matches[1])-32),1); |
|
365 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) { |
|
366 | + $result['temp'] = round(5/9*(($matches[1]) - 32), 1); |
|
368 | 367 | } |
369 | 368 | } |
370 | 369 | } else $result['comment'] = trim($body_parse); |
371 | 370 | |
372 | 371 | } |
373 | 372 | //} |
374 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
375 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
373 | + if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4); |
|
374 | + if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4); |
|
376 | 375 | //print_r($result); |
377 | 376 | return $result; |
378 | 377 | } |