Completed
Push — master ( df3bbc...431371 )
by Yannick
26:06
created
scripts/daemon-spotter.php 1 patch
Spacing   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,40 +150,40 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 152
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 156
     foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
+            if (preg_match('/deltadb.txt$/i', $host)) {
162 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
176
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftjson';
178 178
         	$globalSources[$id]['format'] = 'aircraftjson';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
180 180
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraft$/i',$host)) {
181
+    	    } else if (preg_match('/aircraft$/i', $host)) {
182 182
         	//$formats[$id] = 'planefinderclient';
183 183
         	$globalSources[$id]['format'] = 'planefinderclient';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
-    	    } else if (preg_match('/opensky/i',$host)) {
186
+    	    } else if (preg_match('/opensky/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftlistjson';
188 188
         	$globalSources[$id]['format'] = 'opensky';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         	    exit(0);
201 201
         	}
202 202
     	    */
203
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
203
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
204 204
         	//$formats[$id] = 'planeupdatefaa';
205 205
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 206
         	//$last_exec['planeupdatefaa'] = 0;
@@ -209,37 +209,37 @@  discard block
 block discarded – undo
209 209
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 210
         	    exit(0);
211 211
         	}
212
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
212
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'phpvmacars';
215 215
         	//$last_exec['phpvmacars'] = 0;
216 216
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
217
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
218 218
         	//$formats[$id] = 'phpvmacars';
219 219
         	$globalSources[$id]['format'] = 'vaos';
220 220
         	//$last_exec['phpvmacars'] = 0;
221 221
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
222
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'vam';
225 225
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
-            } else if (preg_match('/whazzup/i',$host)) {
226
+            } else if (preg_match('/whazzup/i', $host)) {
227 227
         	//$formats[$id] = 'whazzup';
228 228
         	$globalSources[$id]['format'] = 'whazzup';
229 229
         	//$last_exec['whazzup'] = 0;
230 230
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
-            } else if (preg_match('/blitzortung/i',$host)) {
231
+            } else if (preg_match('/blitzortung/i', $host)) {
232 232
         	$globalSources[$id]['format'] = 'blitzortung';
233 233
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
-            } else if (preg_match('/airwhere/i',$host)) {
234
+            } else if (preg_match('/airwhere/i', $host)) {
235 235
         	$globalSources[$id]['format'] = 'airwhere';
236 236
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
-            } else if (preg_match('/recentpireps/i',$host)) {
237
+            } else if (preg_match('/recentpireps/i', $host)) {
238 238
         	//$formats[$id] = 'pirepsjson';
239 239
         	$globalSources[$id]['format'] = 'pirepsjson';
240 240
         	//$last_exec['pirepsjson'] = 0;
241 241
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
242
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
243 243
         	//$formats[$id] = 'fr24json';
244 244
         	$globalSources[$id]['format'] = 'fr24json';
245 245
         	//$last_exec['fr24json'] = 0;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 249
         	    exit(0);
250 250
         	}
251
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
251
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
252 252
         	//$formats[$id] = 'fr24json';
253 253
         	$globalSources[$id]['format'] = 'myshiptracking';
254 254
         	//$last_exec['fr24json'] = 0;
@@ -258,21 +258,21 @@  discard block
 block discarded – undo
258 258
         	    exit(0);
259 259
         	}
260 260
             //} else if (preg_match('/10001/',$host)) {
261
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
261
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 262
         	//$formats[$id] = 'tsv';
263 263
         	$globalSources[$id]['format'] = 'tsv';
264 264
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265 265
             }
266
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
266
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
267 267
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
268
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
269 269
     		    if ($idf !== false) {
270 270
     			$httpfeeds[$id] = $idf;
271 271
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272 272
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273 273
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
274
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
275
-	    $hostport = explode(':',$host);
274
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
275
+	    $hostport = explode(':', $host);
276 276
 	    if (isset($hostport[1])) {
277 277
 		$port = $hostport[1];
278 278
 		$hostn = $hostport[0];
@@ -282,19 +282,19 @@  discard block
 block discarded – undo
282 282
 	    }
283 283
 	    $Common = new Common();
284 284
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
285
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
285
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
286 286
     	    } else {
287
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
287
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
288 288
 	    }
289 289
 	    if ($s) {
290 290
     	        $sockets[$id] = $s;
291 291
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
292
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
292
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
293 293
 			//$formats[$id] = 'aprs';
294 294
 			$globalSources[$id]['format'] = 'aprs';
295 295
 			//$aprs_connect = 0;
296 296
 			//$use_aprs = true;
297
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
297
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
298 298
 			$globalSources[$id]['format'] = 'vrstcp';
299 299
     		    } elseif ($port == '10001') {
300 300
         		//$formats[$id] = 'tsv';
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
336 336
 else $timeout = 20;
337 337
 $errno = '';
338
-$errstr='';
338
+$errstr = '';
339 339
 
340 340
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
341 341
 /* Initiate connections to all the hosts simultaneously */
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 //connect_all($globalSources);
344 344
 
345 345
 if (isset($globalProxy) && $globalProxy) {
346
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
346
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
347 347
 } else {
348 348
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
349 349
 }
@@ -373,16 +373,16 @@  discard block
 block discarded – undo
373 373
 
374 374
 if ($use_aprs) {
375 375
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
376
-	$APRS=new APRS();
376
+	$APRS = new APRS();
377 377
 	$aprs_connect = 0;
378 378
 	$aprs_keep = 120;
379 379
 	$aprs_last_tx = time();
380 380
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
381
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
381
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
382 382
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
383
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
383
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
384 384
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
385
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
385
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
386 386
 	if ($aprs_full) $aprs_filter = '';
387 387
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
388 388
 	else $aprs_pass = '-1';
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
 sleep(1);
397 397
 if ($globalDebug) echo "SCAN MODE \n\n";
398 398
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
399
-$endtime = time()+$globalCronEnd;
399
+$endtime = time() + $globalCronEnd;
400 400
 $i = 1;
401 401
 $tt = array();
402 402
 // Delete all ATC
403 403
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
404
-	$ATC=new ATC($Connection->db);
404
+	$ATC = new ATC($Connection->db);
405 405
 }
406 406
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
407 407
 	$ATC->deleteAll();
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 while ($i > 0) {
412 412
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
413 413
 
414
-    if (!$globalDaemon) $i = $endtime-time();
414
+    if (!$globalDaemon) $i = $endtime - time();
415 415
     // Delete old ATC
416 416
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
417 417
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 	}
426 426
 	if ($max < $globalMinFetch) {
427 427
 	    if ($globalDebug) echo 'Sleeping...'."\n";
428
-	    sleep($globalMinFetch-$max+2);
428
+	    sleep($globalMinFetch - $max + 2);
429 429
 	}
430 430
     }
431 431
 
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	    //$buffer = $Common->getData($hosts[$id]);
445 445
 	    $buffer = $Common->getData($value['host']);
446 446
 	    if ($buffer != '') $reset = 0;
447
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
448
-	    $buffer = explode('\n',$buffer);
447
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
448
+	    $buffer = explode('\n', $buffer);
449 449
 	    foreach ($buffer as $line) {
450 450
     		if ($line != '' && count($line) > 7) {
451 451
     		    $line = explode(',', $line);
@@ -478,11 +478,11 @@  discard block
 block discarded – undo
478 478
 	    )
479 479
 	) {
480 480
 	    date_default_timezone_set('CET');
481
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
481
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
482 482
 	    date_default_timezone_set('UTC');
483 483
 	    if ($buffer != '') $reset = 0;
484
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
485
-	    $buffer = explode('\n',$buffer);
484
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
485
+	    $buffer = explode('\n', $buffer);
486 486
 	    foreach ($buffer as $line) {
487 487
 		if ($line != '') {
488 488
 		    //echo "'".$line."'\n";
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 		    $ais_data = $AIS->parse_line(trim($line));
491 491
 		    $data = array();
492 492
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
493
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
493
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
494 494
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
495 495
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
496 496
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
503 503
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
504 504
 		    if (isset($ais_data['timestamp'])) {
505
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
505
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
506 506
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
507 507
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
508 508
 			    $add = true;
@@ -525,21 +525,21 @@  discard block
 block discarded – undo
525 525
 	    $w = $e = null;
526 526
 	    
527 527
 	    if (isset($arr[$id])) {
528
-		$nn = stream_select($arr,$w,$e,$timeout);
528
+		$nn = stream_select($arr, $w, $e, $timeout);
529 529
 		if ($nn > 0) {
530 530
 		    foreach ($httpfeeds as $feed) {
531
-			$buffer = stream_get_line($feed,2000,"\n");
531
+			$buffer = stream_get_line($feed, 2000, "\n");
532 532
 			if ($buffer === FALSE) {
533 533
 			    connect_all($globalSources);
534 534
 			}
535
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
536
-			$buffer = explode('\n',$buffer);
535
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
536
+			$buffer = explode('\n', $buffer);
537 537
 			foreach ($buffer as $line) {
538 538
 			    if ($line != '') {
539 539
 				$ais_data = $AIS->parse_line(trim($line));
540 540
 				$data = array();
541 541
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
542
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
542
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
543 543
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
544 544
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
545 545
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -551,9 +551,9 @@  discard block
 block discarded – undo
551 551
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
552 552
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
553 553
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
554
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
554
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
555 555
 				if (isset($ais_data['timestamp'])) {
556
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
556
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
557 557
 				} else {
558 558
 				    $data['datetime'] = date('Y-m-d H:i:s');
559 559
 				}
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
585 585
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
586 586
 	    )
587 587
 	) {
588
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
588
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
589 589
 	    if ($buffer != '') {
590 590
 		//echo $buffer;
591
-		$all_data = json_decode($buffer,true);
591
+		$all_data = json_decode($buffer, true);
592 592
 		//print_r($all_data);
593 593
 		if (isset($all_data[0]['DATA'])) {
594 594
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 			    $data['ident'] = $line['NAME'];
598 598
 			    $data['mmsi'] = $line['MMSI'];
599 599
 			    if (strlen($data['mmsi']) > 9) {
600
-				$data['mmsi'] = substr($data['mmsi'],-9);
600
+				$data['mmsi'] = substr($data['mmsi'], -9);
601 601
 			    }
602 602
 			    $data['speed'] = $line['SOG'];
603 603
 			    $data['heading'] = $line['COG'];
@@ -607,8 +607,8 @@  discard block
 block discarded – undo
607 607
 			    //$data['type_id'] = $line['TYPE'];
608 608
 			    $data['imo'] = $line['IMO'];
609 609
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
610
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
611
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
610
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
611
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
612 612
 			    $data['format_source'] = 'myshiptracking';
613 613
 			    $data['id_source'] = $id_source;
614 614
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -625,16 +625,16 @@  discard block
 block discarded – undo
625 625
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
626 626
 	    )
627 627
 	) {
628
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
628
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
629 629
 	    if ($buffer != '') {
630
-		$all_data = json_decode($buffer,true);
630
+		$all_data = json_decode($buffer, true);
631 631
 		if (isset($all_data[0]['mmsi'])) {
632 632
 		    foreach ($all_data as $line) {
633 633
 			if ($line != '') {
634 634
 			    $data = array();
635 635
 			    $data['ident'] = $line['shipname'];
636 636
 			    $data['callsign'] = $line['callsign'];
637
-			    $data['mmsi'] = substr($line['mmsi'],-9);
637
+			    $data['mmsi'] = substr($line['mmsi'], -9);
638 638
 			    $data['speed'] = $line['sog'];
639 639
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
640 640
 			    $data['latitude'] = $line['latitude'];
@@ -661,14 +661,14 @@  discard block
 block discarded – undo
661 661
 	) {
662 662
 	    $buffer = $Common->getData($value['host']);
663 663
 	    if ($buffer != '') {
664
-		$all_data = json_decode($buffer,true);
664
+		$all_data = json_decode($buffer, true);
665 665
 		if (isset($all_data['features'][0]['id'])) {
666 666
 		    foreach ($all_data['features'] as $line) {
667 667
 			print_r($line);
668 668
 			$data = array();
669 669
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
670 670
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
671
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
671
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
672 672
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
673 673
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
674 674
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -695,31 +695,31 @@  discard block
 block discarded – undo
695 695
 	    )
696 696
 	) {
697 697
 	    echo 'download...';
698
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
698
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
699 699
 	    echo 'done !'."\n";
700 700
 	    // FIXME: Need more work
701 701
 	    if ($buffer != '') $reset = 0;
702
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
703
-	    $buffer = explode('\n',$buffer);
702
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
703
+	    $buffer = explode('\n', $buffer);
704 704
 	    foreach ($buffer as $line) {
705 705
 		if ($line != '') {
706 706
 		    $data = array();
707 707
 		    echo $line."\n";
708
-		    $data['mmsi'] = (int)substr($line,0,9);
709
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
710
-		    $data['status_id'] = substr($line,21,2);
711
-		    $data['type_id'] = substr($line,24,3);
712
-		    $data['latitude'] = substr($line,29,9);
713
-		    $data['longitude'] = substr($line,41,9);
714
-		    $data['speed'] = round(substr($line,51,5));
708
+		    $data['mmsi'] = (int) substr($line, 0, 9);
709
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
710
+		    $data['status_id'] = substr($line, 21, 2);
711
+		    $data['type_id'] = substr($line, 24, 3);
712
+		    $data['latitude'] = substr($line, 29, 9);
713
+		    $data['longitude'] = substr($line, 41, 9);
714
+		    $data['speed'] = round(substr($line, 51, 5));
715 715
 		    //$data['course'] = substr($line,57,5);
716
-		    $data['heading'] = round(substr($line,63,3));
716
+		    $data['heading'] = round(substr($line, 63, 3));
717 717
 		    //$data['draft'] = substr($line,67,4);
718 718
 		    //$data['length'] = substr($line,72,3);
719 719
 		    //$data['beam'] = substr($line,76,2);
720
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
720
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
721 721
 		    //$data['callsign'] = trim(substr($line,100,7);
722
-		    $data['arrival_code'] = substr($line,108,20);
722
+		    $data['arrival_code'] = substr($line, 108, 20);
723 723
 		    //$data['etaDate'] = substr($line,129,5);
724 724
 		    //$data['etaTime'] = substr($line,135,5);
725 725
 		    $data['format_source'] = 'shipplotter';
@@ -750,8 +750,8 @@  discard block
 block discarded – undo
750 750
 	) {
751 751
 	    //$buffer = $Common->getData($hosts[$id]);
752 752
 	    $buffer = $Common->getData($value['host']);
753
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
754
-	    $buffer = explode('\n',$buffer);
753
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
754
+	    $buffer = explode('\n', $buffer);
755 755
 	    $reset = 0;
756 756
 	    foreach ($buffer as $line) {
757 757
     		if ($line != '') {
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
763 763
 			$data['pilot_id'] = $line[1];
764 764
 			$data['pilot_name'] = $line[2];
765
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
765
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
766 766
 			$data['ident'] = $line[0]; // ident
767 767
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
768 768
 			$data['speed'] = $line[8]; // speed
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
779 779
 			//if (isset($line[37])) $data['last_update'] = $line[37];
780 780
 		        $data['departure_airport_icao'] = $line[11];
781
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
781
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
782 782
 		        $data['arrival_airport_icao'] = $line[13];
783 783
 			$data['frequency'] = $line[4];
784 784
 			$data['type'] = $line[18];
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
     			$data['id_source'] = $id_source;
788 788
 	    		//$data['arrival_airport_time'] = ;
789 789
 	    		if ($line[9] != '') {
790
-	    		    $aircraft_data = explode('/',$line[9]);
790
+	    		    $aircraft_data = explode('/', $line[9]);
791 791
 	    		    if (isset($aircraft_data[1])) {
792 792
 	    			$data['aircraft_icao'] = $aircraft_data[1];
793 793
 	    		    }
@@ -802,9 +802,9 @@  discard block
 block discarded – undo
802 802
     			if ($line[3] === 'PILOT') $SI->add($data);
803 803
 			elseif ($line[3] === 'ATC') {
804 804
 				//print_r($data);
805
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
806
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
807
-				$typec = substr($data['ident'],-3);
805
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
806
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
807
+				$typec = substr($data['ident'], -3);
808 808
 				if ($typec === 'APP') $data['type'] = 'Approach';
809 809
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
810 810
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -816,8 +816,8 @@  discard block
 block discarded – undo
816 816
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
817 817
 				if (!isset($data['source_name'])) $data['source_name'] = '';
818 818
 				if (isset($ATC)) {
819
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
820
-					else 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']);
819
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($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']);
820
+					else 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']);
821 821
 				}
822 822
 			}
823 823
     			unset($data);
@@ -833,24 +833,24 @@  discard block
 block discarded – undo
833 833
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
834 834
     	    )
835 835
     	) {
836
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
836
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
837 837
 	    if ($buffer != '') {
838 838
 		$all_data = simplexml_load_string($buffer);
839
-		foreach($all_data->children() as $childdata) {
839
+		foreach ($all_data->children() as $childdata) {
840 840
 			$data = array();
841 841
 			$line = $childdata;
842 842
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
843
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
844
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
845
-			$data['latitude'] = (float)$line['pktLatitude'];
846
-			$data['longitude'] = (float)$line['pktLongitude'];
847
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
848
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
849
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
843
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
844
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
845
+			$data['latitude'] = (float) $line['pktLatitude'];
846
+			$data['longitude'] = (float) $line['pktLongitude'];
847
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
848
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
849
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
850 850
 			$data['altitude_relative'] = 'AMSL';
851
-			$data['pilot_id'] = (int)$line['pktPilotID'];
851
+			$data['pilot_id'] = (int) $line['pktPilotID'];
852 852
 			$data['aircraft_icao'] = 'PARAGLIDER';
853
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
853
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
854 854
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
855 855
 			$data['format_source'] = $value['format'];
856 856
 			$SI->add($data);
@@ -858,22 +858,22 @@  discard block
 block discarded – undo
858 858
 		}
859 859
 	    }
860 860
 	    $Source->deleteOldLocationByType('gs');
861
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
861
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
862 862
 	    if ($buffer != '') {
863 863
 		$all_data = simplexml_load_string($buffer);
864
-		foreach($all_data->children() as $childdata) {
864
+		foreach ($all_data->children() as $childdata) {
865 865
 			$data = array();
866 866
 			$line = $childdata;
867
-			$data['id'] = (int)$line['gsID'];
868
-			$data['latitude'] = (float)$line['gsLatitude'];
869
-			$data['longitude'] = (float)$line['gsLongitude'];
870
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
867
+			$data['id'] = (int) $line['gsID'];
868
+			$data['latitude'] = (float) $line['gsLatitude'];
869
+			$data['longitude'] = (float) $line['gsLongitude'];
870
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
871 871
 			$data['altitude_relative'] = 'AMSL';
872
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
872
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
873 873
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
874
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
874
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
875 875
 			} else {
876
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
876
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
877 877
 			}
878 878
 			unset($data);
879 879
 		}
@@ -891,9 +891,9 @@  discard block
 block discarded – undo
891 891
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
892 892
 	    )
893 893
 	) {
894
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
894
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
895 895
 	    if ($buffer != '') {
896
-	        $all_data = json_decode($buffer,true);
896
+	        $all_data = json_decode($buffer, true);
897 897
 		if (isset($all_data['acList'])) {
898 898
 		    $reset = 0;
899 899
 		    foreach ($all_data['acList'] as $line) {
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
910 910
 			$data['emergency'] = ''; // emergency
911 911
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
912
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
912
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
913 913
 			else $data['datetime'] = date('Y-m-d H:i:s');
914 914
 			//$data['datetime'] = date('Y-m-d H:i:s');
915 915
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 			$data['verticalrate'] = $line['vrt']; // verticale rate
935 935
 			$data['squawk'] = $line['squawk']; // squawk
936 936
 			$data['emergency'] = ''; // emergency
937
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
937
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
938 938
 			else $data['datetime'] = date('Y-m-d H:i:s');
939 939
 			$data['format_source'] = 'aircraftlistjson';
940 940
 			$data['id_source'] = $id_source;
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
     	    )
956 956
     	) {
957 957
 	    $buffer = $Common->getData($value['host']);
958
-	    $all_data = json_decode($buffer,true);
958
+	    $all_data = json_decode($buffer, true);
959 959
 	    if (isset($all_data['planes'])) {
960 960
 		$reset = 0;
961 961
 		foreach ($all_data['planes'] as $key => $line) {
@@ -972,12 +972,12 @@  discard block
 block discarded – undo
972 972
 		    $data['emergency'] = ''; // emergency
973 973
 		    $data['registration'] = $line[2];
974 974
 		    $data['aircraft_icao'] = $line[0];
975
-		    $deparr = explode('-',$line[1]);
975
+		    $deparr = explode('-', $line[1]);
976 976
 		    if (count($deparr) === 2) {
977 977
 			$data['departure_airport_icao'] = $deparr[0];
978 978
 			$data['arrival_airport_icao'] = $deparr[1];
979 979
 		    }
980
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
980
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
981 981
 	    	    $data['format_source'] = 'planeupdatefaa';
982 982
     		    $data['id_source'] = $id_source;
983 983
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 	    )
996 996
 	) {
997 997
 	    $buffer = $Common->getData($value['host']);
998
-	    $all_data = json_decode($buffer,true);
998
+	    $all_data = json_decode($buffer, true);
999 999
 	    if (isset($all_data['states'])) {
1000 1000
 		$reset = 0;
1001 1001
 		foreach ($all_data['states'] as $key => $line) {
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 		    //$data['emergency'] = ''; // emergency
1013 1013
 		    //$data['registration'] = $line[2];
1014 1014
 		    //$data['aircraft_icao'] = $line[0];
1015
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1015
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1016 1016
 		    $data['format_source'] = 'opensky';
1017 1017
 		    $data['id_source'] = $id_source;
1018 1018
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 	    )
1030 1030
 	) {
1031 1031
 	    $buffer = $Common->getData($value['host']);
1032
-	    $all_data = json_decode($buffer,true);
1033
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1032
+	    $all_data = json_decode($buffer, true);
1033
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1034 1034
 		$reset = 0;
1035 1035
 		foreach ($all_data['aircraft'] as $key => $line) {
1036 1036
 		    $data = array();
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 	    )
1069 1069
 	) {
1070 1070
 	    $buffer = $Common->getData($value['host']);
1071
-	    $all_data = json_decode($buffer,true);
1071
+	    $all_data = json_decode($buffer, true);
1072 1072
 	    if (isset($all_data['aircraft'])) {
1073 1073
 		$reset = 0;
1074 1074
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 		    //$data['emergency'] = ''; // emergency
1086 1086
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1087 1087
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1088
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1088
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1089 1089
 		    $data['format_source'] = 'planefinderclient';
1090 1090
 		    $data['id_source'] = $id_source;
1091 1091
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 	) {
1105 1105
 	    //$buffer = $Common->getData($hosts[$id]);
1106 1106
 	    $buffer = $Common->getData($value['host']);
1107
-	    $all_data = json_decode($buffer,true);
1107
+	    $all_data = json_decode($buffer, true);
1108 1108
 	    if (!empty($all_data)) $reset = 0;
1109 1109
 	    foreach ($all_data as $key => $line) {
1110 1110
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1142,11 +1142,11 @@  discard block
 block discarded – undo
1142 1142
 	    )
1143 1143
 	) {
1144 1144
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1145
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1145
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1146 1146
 	    //echo $buffer;
1147
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1148
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1149
-	    $all_data = json_decode($buffer,true);
1147
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1148
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1149
+	    $all_data = json_decode($buffer, true);
1150 1150
 	    if (json_last_error() != JSON_ERROR_NONE) {
1151 1151
 		die(json_last_error_msg());
1152 1152
 	    }
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 			//$data['departure_airport_iata'] = $line[11];
1170 1170
 			//$data['arrival_airport_iata'] = $line[12];
1171 1171
 	    		//$data['emergency'] = ''; // emergency
1172
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1172
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1173 1173
 	    		$data['format_source'] = 'radarvirtueljson';
1174 1174
     			$data['id_source'] = $id_source;
1175 1175
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1190,14 +1190,14 @@  discard block
 block discarded – undo
1190 1190
 	) {
1191 1191
 	    //$buffer = $Common->getData($hosts[$id]);
1192 1192
 	    $buffer = $Common->getData($value['host'].'?'.time());
1193
-	    $all_data = json_decode(utf8_encode($buffer),true);
1193
+	    $all_data = json_decode(utf8_encode($buffer), true);
1194 1194
 	    
1195 1195
 	    if (isset($all_data['pireps'])) {
1196 1196
 		$reset = 0;
1197 1197
 	        foreach ($all_data['pireps'] as $line) {
1198 1198
 		    $data = array();
1199 1199
 		    $data['id'] = $line['id'];
1200
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1200
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1201 1201
 		    $data['ident'] = $line['callsign']; // ident
1202 1202
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1203 1203
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1227,9 +1227,9 @@  discard block
 block discarded – undo
1227 1227
 			$SI->add($data);
1228 1228
 		    //    print_r($data);
1229 1229
     		    } elseif ($line['icon'] === 'ct') {
1230
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1231
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1232
-			$typec = substr($data['ident'],-3);
1230
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1231
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1232
+			$typec = substr($data['ident'], -3);
1233 1233
 			$data['type'] = '';
1234 1234
 			if ($typec === 'APP') $data['type'] = 'Approach';
1235 1235
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1241 1241
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1242 1242
 			else $data['type'] = 'Observer';
1243
-			if (isset($ATC)) 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']);
1243
+			if (isset($ATC)) 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']);
1244 1244
 		    }
1245 1245
 		    unset($data);
1246 1246
 		}
@@ -1257,14 +1257,14 @@  discard block
 block discarded – undo
1257 1257
 	    //$buffer = $Common->getData($hosts[$id]);
1258 1258
 	    if ($globalDebug) echo 'Get Data...'."\n";
1259 1259
 	    $buffer = $Common->getData($value['host']);
1260
-	    $all_data = json_decode($buffer,true);
1260
+	    $all_data = json_decode($buffer, true);
1261 1261
 	    if ($buffer != '' && is_array($all_data)) {
1262 1262
 		$reset = 0;
1263 1263
 		foreach ($all_data as $line) {
1264 1264
 	    	    $data = array();
1265 1265
 	    	    //$data['id'] = $line['id']; // id not usable
1266 1266
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1267
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1267
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1268 1268
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1269 1269
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1270 1270
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1279,7 +1279,7 @@  discard block
 block discarded – undo
1279 1279
 	    	    //$data['datetime'] = $line['lastupdate'];
1280 1280
 	    	    //$data['last_update'] = $line['lastupdate'];
1281 1281
 	    	    if (isset($value['timezone'])) {
1282
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1282
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1283 1283
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1284 1284
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1285 1285
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1295,14 +1295,14 @@  discard block
 block discarded – undo
1295 1295
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1296 1296
 		    if (isset($line['aircraftname'])) {
1297 1297
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1298
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1299
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1298
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1299
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1300 1300
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1301 1301
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1302 1302
 	    		else {
1303
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1304
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1305
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1303
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1304
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1305
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1306 1306
 	    		}
1307 1307
 	    	    }
1308 1308
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
 	    //$buffer = $Common->getData($hosts[$id]);
1328 1328
 	    if ($globalDebug) echo 'Get Data...'."\n";
1329 1329
 	    $buffer = $Common->getData($value['host']);
1330
-	    $all_data = json_decode($buffer,true);
1330
+	    $all_data = json_decode($buffer, true);
1331 1331
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1332 1332
 		$reset = 0;
1333 1333
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1339 1339
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1340 1340
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1341
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1341
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1342 1342
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1343 1343
 	    	    $data['altitude'] = $line['altitude']; // altitude
1344 1344
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 	    	    //$data['squawk'] = ''; // squawk
1350 1350
 	    	    //$data['emergency'] = ''; // emergency
1351 1351
 	    	    if (isset($value['timezone'])) {
1352
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1352
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1353 1353
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1354 1354
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1355 1355
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1385,14 +1385,14 @@  discard block
 block discarded – undo
1385 1385
 	    //$buffer = $Common->getData($hosts[$id]);
1386 1386
 	    if ($globalDebug) echo 'Get Data...'."\n";
1387 1387
 	    $buffer = $Common->getData($value['host']);
1388
-	    $all_data = json_decode($buffer,true);
1388
+	    $all_data = json_decode($buffer, true);
1389 1389
 	    if ($buffer != '' && is_array($all_data)) {
1390 1390
 		$reset = 0;
1391 1391
 		foreach ($all_data as $line) {
1392 1392
 	    	    $data = array();
1393 1393
 	    	    //$data['id'] = $line['id']; // id not usable
1394 1394
 	    	    $data['id'] = trim($line['flight_id']);
1395
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1395
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1396 1396
 	    	    $data['pilot_name'] = $line['pilot_name'];
1397 1397
 	    	    $data['pilot_id'] = $line['pilot_id'];
1398 1398
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1436,24 +1436,24 @@  discard block
 block discarded – undo
1436 1436
 	    //$buffer = $Common->getData($hosts[$id]);
1437 1437
 	    if ($globalDebug) echo 'Get Data...'."\n";
1438 1438
 	    $buffer = $Common->getData($value['host']);
1439
-	    $all_data = json_decode($buffer,true);
1439
+	    $all_data = json_decode($buffer, true);
1440 1440
 	    if ($buffer != '') {
1441 1441
 		$Source->deleteLocationBySource('blitzortung');
1442
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1443
-		$buffer = explode('\n',$buffer);
1442
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1443
+		$buffer = explode('\n', $buffer);
1444 1444
 		foreach ($buffer as $buffer_line) {
1445
-		    $line = json_decode($buffer_line,true);
1445
+		    $line = json_decode($buffer_line, true);
1446 1446
 		    if (isset($line['time'])) {
1447 1447
 			$data = array();
1448 1448
 			$data['altitude'] = $line['alt']; // altitude
1449 1449
 			$data['latitude'] = $line['lat']; // lat
1450 1450
 			$data['longitude'] = $line['lon']; // long
1451
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1451
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1452 1452
 			$data['id_source'] = $id_source;
1453 1453
 			$data['format_source'] = 'blitzortung';
1454 1454
 			$SI->add($data);
1455 1455
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1456
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1456
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1457 1457
 			unset($data);
1458 1458
 		    }
1459 1459
 		}
@@ -1476,11 +1476,11 @@  discard block
 block discarded – undo
1476 1476
 		    //$value = $formats[$nb];
1477 1477
 		    $format = $globalSources[$nb]['format'];
1478 1478
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1479
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1479
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1480 1480
 		    } elseif ($format === 'vrstcp') {
1481 1481
 			$buffer = @socket_read($r, 6000);
1482 1482
 		    } else {
1483
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1483
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1484 1484
 		    }
1485 1485
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1486 1486
 		    //echo $buffer."\n";
@@ -1490,8 +1490,8 @@  discard block
 block discarded – undo
1490 1490
 		    //$SI::del();
1491 1491
 		    if ($buffer !== FALSE) {
1492 1492
 			if ($format === 'vrstcp') {
1493
-			    $buffer = explode('},{',$buffer);
1494
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1493
+			    $buffer = explode('},{', $buffer);
1494
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1495 1495
 		    }
1496 1496
 		    // SBS format is CSV format
1497 1497
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
 			    $ais_data = $AIS->parse_line(trim($buffer));
1516 1516
 			    $data = array();
1517 1517
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1518
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1518
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1519 1519
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1520 1520
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1521 1521
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1526,13 +1526,13 @@  discard block
 block discarded – undo
1526 1526
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1527 1527
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1528 1528
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1529
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1529
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1530 1530
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1531 1531
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1532 1532
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1533 1533
 
1534 1534
 			    if (isset($ais_data['timestamp'])) {
1535
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1535
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1536 1536
 			    } else {
1537 1537
 				$data['datetime'] = date('Y-m-d H:i:s');
1538 1538
 			    }
@@ -1543,10 +1543,10 @@  discard block
 block discarded – undo
1543 1543
                         } elseif ($format === 'flightgearsp') {
1544 1544
                     	    //echo $buffer."\n";
1545 1545
                     	    if (strlen($buffer) > 5) {
1546
-				$line = explode(',',$buffer);
1546
+				$line = explode(',', $buffer);
1547 1547
 				$data = array();
1548 1548
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1549
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1549
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1550 1550
 				$data['ident'] = $line[6];
1551 1551
 				$data['aircraft_name'] = $line[7];
1552 1552
 				$data['longitude'] = $line[1];
@@ -1563,16 +1563,16 @@  discard block
 block discarded – undo
1563 1563
                         } elseif ($format === 'acars') {
1564 1564
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1565 1565
 			    $ACARS->add(trim($buffer));
1566
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1566
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1567 1567
 			    $ACARS->deleteLiveAcarsData();
1568 1568
 			} elseif ($format === 'flightgearmp') {
1569
-			    if (substr($buffer,0,1) != '#') {
1569
+			    if (substr($buffer, 0, 1) != '#') {
1570 1570
 				$data = array();
1571 1571
 				//echo $buffer."\n";
1572
-				$line = explode(' ',$buffer);
1572
+				$line = explode(' ', $buffer);
1573 1573
 				if (count($line) === 11) {
1574
-				    $userserver = explode('@',$line[0]);
1575
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1574
+				    $userserver = explode('@', $line[0]);
1575
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1576 1576
 				    $data['ident'] = $userserver[0];
1577 1577
 				    $data['registration'] = $userserver[0];
1578 1578
 				    $data['latitude'] = $line[4];
@@ -1580,8 +1580,8 @@  discard block
 block discarded – undo
1580 1580
 				    $data['altitude'] = $line[6];
1581 1581
 				    $data['datetime'] = date('Y-m-d H:i:s');
1582 1582
 				    $aircraft_type = $line[10];
1583
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1584
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1583
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1584
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1585 1585
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1586 1586
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1587 1587
 				}
@@ -1590,8 +1590,8 @@  discard block
 block discarded – undo
1590 1590
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1591 1591
 			    die;
1592 1592
 			} elseif ($format === 'vrstcp') {
1593
-			    foreach($buffer as $all_data) {
1594
-				$line = json_decode('{'.$all_data.'}',true);
1593
+			    foreach ($buffer as $all_data) {
1594
+				$line = json_decode('{'.$all_data.'}', true);
1595 1595
 				$data = array();
1596 1596
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1597 1597
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1617,16 +1617,16 @@  discard block
 block discarded – undo
1617 1617
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1618 1618
 				unset($data);
1619 1619
 			    }
1620
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1620
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1621 1621
 			    $line = explode("\t", $buffer);
1622
-			    for($k = 0; $k < count($line); $k=$k+2) {
1622
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1623 1623
 				$key = $line[$k];
1624
-			        $lined[$key] = $line[$k+1];
1624
+			        $lined[$key] = $line[$k + 1];
1625 1625
 			    }
1626 1626
     			    if (count($lined) > 3) {
1627 1627
     				$data['hex'] = $lined['hexid'];
1628 1628
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1629
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1629
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1630 1630
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1631 1631
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1632 1632
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1645,23 +1645,23 @@  discard block
 block discarded – undo
1645 1645
     			    } else $error = true;
1646 1646
 			} elseif ($format === 'aprs' && $use_aprs) {
1647 1647
 			    if ($aprs_connect === 0) {
1648
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1648
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1649 1649
 				$aprs_connect = 1;
1650 1650
 			    }
1651 1651
 			    
1652
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1652
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1653 1653
 				$aprs_last_tx = time();
1654 1654
 				$data_aprs = "# Keep alive";
1655
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1655
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1656 1656
 			    }
1657 1657
 			    
1658 1658
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1659 1659
 			    //echo 'APRS data : '.$buffer."\n";
1660
-			    $buffer = str_replace('APRS <- ','',$buffer);
1661
-			    $buffer = str_replace('APRS -> ','',$buffer);
1660
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1661
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1662 1662
 			    //echo $buffer."\n";
1663 1663
 			    date_default_timezone_set('UTC');
1664
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1664
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1665 1665
 				$line = $APRS->parse($buffer);
1666 1666
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1667 1667
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1676,7 +1676,7 @@  discard block
 block discarded – undo
1676 1676
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1677 1677
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1678 1678
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1679
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1679
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1680 1680
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1681 1681
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1682 1682
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1759,29 +1759,29 @@  discard block
 block discarded – undo
1759 1759
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1760 1760
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1761 1761
 					$Source->deleteOldLocationByType('gs');
1762
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1763
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1762
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1763
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1764 1764
 					} else {
1765
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1765
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1766 1766
 					}
1767 1767
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1768 1768
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1769 1769
 					if ($globalDebug) echo '# Weather Station added'."\n";
1770 1770
 					$Source->deleteOldLocationByType('wx');
1771 1771
 					$weather_data = json_encode($line);
1772
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1773
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1772
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1773
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1774 1774
 					} else {
1775
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1775
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1776 1776
 					}
1777 1777
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1778 1778
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1779 1779
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1780 1780
 					$Source->deleteOldLocationByType('lightning');
1781
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1782
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1781
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1782
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1783 1783
 					} else {
1784
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1784
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1785 1785
 					}
1786 1786
 				    } elseif ($globalDebug) {
1787 1787
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
 				    unset($data);
1791 1791
 				}
1792 1792
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1793
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1793
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1794 1794
 				}
1795 1795
 				/*
1796 1796
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] === 'Car' || $line['symbol'] === 'Ambulance' || $line['symbol'] === 'Van' || $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || $line['symbol'] === 'Motorcycle')) {
@@ -1799,7 +1799,7 @@  discard block
 block discarded – undo
1799 1799
 				*/
1800 1800
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1801 1801
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1802
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1802
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1803 1803
 					$Source->deleteOldLocationByType('lightning');
1804 1804
 					$Source->deleteOldLocationByType('wx');
1805 1805
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1884,7 +1884,7 @@  discard block
 block discarded – undo
1884 1884
 				connect_all($sourceee);
1885 1885
 				$sourceee = array();
1886 1886
 				//connect_all($globalSources);
1887
-				$tt[$format]=0;
1887
+				$tt[$format] = 0;
1888 1888
 				break;
1889 1889
 			    } 
1890 1890
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1894,14 +1894,14 @@  discard block
 block discarded – undo
1894 1894
 	    } else {
1895 1895
 		$error = socket_strerror(socket_last_error());
1896 1896
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1897
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1897
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1898 1898
 			if (isset($globalDebug)) echo "Restarting...\n";
1899 1899
 			// Restart the script if possible
1900 1900
 			if (is_array($sockets)) {
1901 1901
 			    if ($globalDebug) echo "Shutdown all sockets...";
1902 1902
 			    
1903 1903
 			    foreach ($sockets as $sock) {
1904
-				@socket_shutdown($sock,2);
1904
+				@socket_shutdown($sock, 2);
1905 1905
 				@socket_close($sock);
1906 1906
 			    }
1907 1907
 			    
Please login to merge, or discard this patch.