Completed
Push — master ( 44a8cc...5ee062 )
by Yannick
34:55 queued 07:43
created
scripts/daemon-spotter.php 1 patch
Spacing   +199 added lines, -199 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,35 +150,35 @@  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 aircraftlist.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/opensky/i',$host)) {
181
+    	    } else if (preg_match('/opensky/i', $host)) {
182 182
         	//$formats[$id] = 'aircraftlistjson';
183 183
         	$globalSources[$id]['format'] = 'opensky';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
         	    exit(0);
196 196
         	}
197 197
     	    */
198
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
198
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
199 199
         	//$formats[$id] = 'planeupdatefaa';
200 200
         	$globalSources[$id]['format'] = 'planeupdatefaa';
201 201
         	//$last_exec['planeupdatefaa'] = 0;
@@ -204,37 +204,37 @@  discard block
 block discarded – undo
204 204
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
205 205
         	    exit(0);
206 206
         	}
207
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
207
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
208 208
         	//$formats[$id] = 'phpvmacars';
209 209
         	$globalSources[$id]['format'] = 'phpvmacars';
210 210
         	//$last_exec['phpvmacars'] = 0;
211 211
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
212
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
212
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'vaos';
215 215
         	//$last_exec['phpvmacars'] = 0;
216 216
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
217
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
217
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
218 218
         	//$formats[$id] = 'phpvmacars';
219 219
         	$globalSources[$id]['format'] = 'vam';
220 220
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
221
-            } else if (preg_match('/whazzup/i',$host)) {
221
+            } else if (preg_match('/whazzup/i', $host)) {
222 222
         	//$formats[$id] = 'whazzup';
223 223
         	$globalSources[$id]['format'] = 'whazzup';
224 224
         	//$last_exec['whazzup'] = 0;
225 225
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
226
-            } else if (preg_match('/blitzortung/i',$host)) {
226
+            } else if (preg_match('/blitzortung/i', $host)) {
227 227
         	$globalSources[$id]['format'] = 'blitzortung';
228 228
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
229
-            } else if (preg_match('/airwhere/i',$host)) {
229
+            } else if (preg_match('/airwhere/i', $host)) {
230 230
         	$globalSources[$id]['format'] = 'airwhere';
231 231
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
232
-            } else if (preg_match('/recentpireps/i',$host)) {
232
+            } else if (preg_match('/recentpireps/i', $host)) {
233 233
         	//$formats[$id] = 'pirepsjson';
234 234
         	$globalSources[$id]['format'] = 'pirepsjson';
235 235
         	//$last_exec['pirepsjson'] = 0;
236 236
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
237
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
237
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
238 238
         	//$formats[$id] = 'fr24json';
239 239
         	$globalSources[$id]['format'] = 'fr24json';
240 240
         	//$last_exec['fr24json'] = 0;
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
244 244
         	    exit(0);
245 245
         	}
246
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
246
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
247 247
         	//$formats[$id] = 'fr24json';
248 248
         	$globalSources[$id]['format'] = 'myshiptracking';
249 249
         	//$last_exec['fr24json'] = 0;
@@ -253,21 +253,21 @@  discard block
 block discarded – undo
253 253
         	    exit(0);
254 254
         	}
255 255
             //} else if (preg_match('/10001/',$host)) {
256
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
256
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
257 257
         	//$formats[$id] = 'tsv';
258 258
         	$globalSources[$id]['format'] = 'tsv';
259 259
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
260 260
             }
261
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
261
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
262 262
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
263
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
263
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
264 264
     		    if ($idf !== false) {
265 265
     			$httpfeeds[$id] = $idf;
266 266
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
267 267
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
268 268
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
269
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
270
-	    $hostport = explode(':',$host);
269
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
270
+	    $hostport = explode(':', $host);
271 271
 	    if (isset($hostport[1])) {
272 272
 		$port = $hostport[1];
273 273
 		$hostn = $hostport[0];
@@ -277,19 +277,19 @@  discard block
 block discarded – undo
277 277
 	    }
278 278
 	    $Common = new Common();
279 279
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
280
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
280
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
281 281
     	    } else {
282
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
282
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
283 283
 	    }
284 284
 	    if ($s) {
285 285
     	        $sockets[$id] = $s;
286 286
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
287
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
287
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
288 288
 			//$formats[$id] = 'aprs';
289 289
 			$globalSources[$id]['format'] = 'aprs';
290 290
 			//$aprs_connect = 0;
291 291
 			//$use_aprs = true;
292
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
292
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
293 293
 			$globalSources[$id]['format'] = 'vrstcp';
294 294
     		    } elseif ($port == '10001') {
295 295
         		//$formats[$id] = 'tsv';
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
329 329
 else $timeout = 20;
330 330
 $errno = '';
331
-$errstr='';
331
+$errstr = '';
332 332
 
333 333
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
334 334
 /* Initiate connections to all the hosts simultaneously */
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 //connect_all($globalSources);
337 337
 
338 338
 if (isset($globalProxy) && $globalProxy) {
339
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
339
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
340 340
 } else {
341 341
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
342 342
 }
@@ -366,16 +366,16 @@  discard block
 block discarded – undo
366 366
 
367 367
 if ($use_aprs) {
368 368
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
369
-	$APRS=new APRS();
369
+	$APRS = new APRS();
370 370
 	$aprs_connect = 0;
371 371
 	$aprs_keep = 120;
372 372
 	$aprs_last_tx = time();
373 373
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
374
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
374
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
375 375
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
376
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
376
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
377 377
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
378
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
378
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
379 379
 	if ($aprs_full) $aprs_filter = '';
380 380
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
381 381
 	else $aprs_pass = '-1';
@@ -389,12 +389,12 @@  discard block
 block discarded – undo
389 389
 sleep(1);
390 390
 if ($globalDebug) echo "SCAN MODE \n\n";
391 391
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
392
-$endtime = time()+$globalCronEnd;
392
+$endtime = time() + $globalCronEnd;
393 393
 $i = 1;
394 394
 $tt = array();
395 395
 // Delete all ATC
396 396
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
397
-	$ATC=new ATC($Connection->db);
397
+	$ATC = new ATC($Connection->db);
398 398
 }
399 399
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
400 400
 	$ATC->deleteAll();
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 while ($i > 0) {
405 405
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
406 406
 
407
-    if (!$globalDaemon) $i = $endtime-time();
407
+    if (!$globalDaemon) $i = $endtime - time();
408 408
     // Delete old ATC
409 409
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
410 410
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 	}
419 419
 	if ($max < $globalMinFetch) {
420 420
 	    if ($globalDebug) echo 'Sleeping...'."\n";
421
-	    sleep($globalMinFetch-$max+2);
421
+	    sleep($globalMinFetch - $max + 2);
422 422
 	}
423 423
     }
424 424
 
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 	    //$buffer = $Common->getData($hosts[$id]);
438 438
 	    $buffer = $Common->getData($value['host']);
439 439
 	    if ($buffer != '') $reset = 0;
440
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
441
-	    $buffer = explode('\n',$buffer);
440
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
441
+	    $buffer = explode('\n', $buffer);
442 442
 	    foreach ($buffer as $line) {
443 443
     		if ($line != '' && count($line) > 7) {
444 444
     		    $line = explode(',', $line);
@@ -471,11 +471,11 @@  discard block
 block discarded – undo
471 471
 	    )
472 472
 	) {
473 473
 	    date_default_timezone_set('CET');
474
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
474
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
475 475
 	    date_default_timezone_set('UTC');
476 476
 	    if ($buffer != '') $reset = 0;
477
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
478
-	    $buffer = explode('\n',$buffer);
477
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
478
+	    $buffer = explode('\n', $buffer);
479 479
 	    foreach ($buffer as $line) {
480 480
 		if ($line != '') {
481 481
 		    //echo "'".$line."'\n";
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 		    $ais_data = $AIS->parse_line(trim($line));
484 484
 		    $data = array();
485 485
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
486
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
486
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
487 487
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
488 488
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
489 489
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
496 496
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
497 497
 		    if (isset($ais_data['timestamp'])) {
498
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
498
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
499 499
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
500 500
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
501 501
 			    $add = true;
@@ -518,21 +518,21 @@  discard block
 block discarded – undo
518 518
 	    $w = $e = null;
519 519
 	    
520 520
 	    if (isset($arr[$id])) {
521
-		$nn = stream_select($arr,$w,$e,$timeout);
521
+		$nn = stream_select($arr, $w, $e, $timeout);
522 522
 		if ($nn > 0) {
523 523
 		    foreach ($httpfeeds as $feed) {
524
-			$buffer = stream_get_line($feed,2000,"\n");
524
+			$buffer = stream_get_line($feed, 2000, "\n");
525 525
 			if ($buffer === FALSE) {
526 526
 			    connect_all($globalSources);
527 527
 			}
528
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
529
-			$buffer = explode('\n',$buffer);
528
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
529
+			$buffer = explode('\n', $buffer);
530 530
 			foreach ($buffer as $line) {
531 531
 			    if ($line != '') {
532 532
 				$ais_data = $AIS->parse_line(trim($line));
533 533
 				$data = array();
534 534
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
535
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
535
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
536 536
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
537 537
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
538 538
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
545 545
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
546 546
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
547
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
547
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
548 548
 				if (isset($ais_data['timestamp'])) {
549
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
549
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
550 550
 				} else {
551 551
 				    $data['datetime'] = date('Y-m-d H:i:s');
552 552
 				}
@@ -578,10 +578,10 @@  discard block
 block discarded – undo
578 578
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
579 579
 	    )
580 580
 	) {
581
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
581
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
582 582
 	    if ($buffer != '') {
583 583
 		//echo $buffer;
584
-		$all_data = json_decode($buffer,true);
584
+		$all_data = json_decode($buffer, true);
585 585
 		//print_r($all_data);
586 586
 		if (isset($all_data[0]['DATA'])) {
587 587
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 			    $data['ident'] = $line['NAME'];
591 591
 			    $data['mmsi'] = $line['MMSI'];
592 592
 			    if (strlen($data['mmsi']) > 9) {
593
-				$data['mmsi'] = substr($data['mmsi'],-9);
593
+				$data['mmsi'] = substr($data['mmsi'], -9);
594 594
 			    }
595 595
 			    $data['speed'] = $line['SOG'];
596 596
 			    $data['heading'] = $line['COG'];
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 			    //$data['type_id'] = $line['TYPE'];
601 601
 			    $data['imo'] = $line['IMO'];
602 602
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
603
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
604
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
603
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
604
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
605 605
 			    $data['format_source'] = 'myshiptracking';
606 606
 			    $data['id_source'] = $id_source;
607 607
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -618,16 +618,16 @@  discard block
 block discarded – undo
618 618
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
619 619
 	    )
620 620
 	) {
621
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
621
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
622 622
 	    if ($buffer != '') {
623
-		$all_data = json_decode($buffer,true);
623
+		$all_data = json_decode($buffer, true);
624 624
 		if (isset($all_data[0]['mmsi'])) {
625 625
 		    foreach ($all_data as $line) {
626 626
 			if ($line != '') {
627 627
 			    $data = array();
628 628
 			    $data['ident'] = $line['shipname'];
629 629
 			    $data['callsign'] = $line['callsign'];
630
-			    $data['mmsi'] = substr($line['mmsi'],-9);
630
+			    $data['mmsi'] = substr($line['mmsi'], -9);
631 631
 			    $data['speed'] = $line['sog'];
632 632
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
633 633
 			    $data['latitude'] = $line['latitude'];
@@ -654,14 +654,14 @@  discard block
 block discarded – undo
654 654
 	) {
655 655
 	    $buffer = $Common->getData($value['host']);
656 656
 	    if ($buffer != '') {
657
-		$all_data = json_decode($buffer,true);
657
+		$all_data = json_decode($buffer, true);
658 658
 		if (isset($all_data['features'][0]['id'])) {
659 659
 		    foreach ($all_data['features'] as $line) {
660 660
 			print_r($line);
661 661
 			$data = array();
662 662
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
663 663
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
664
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
664
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
665 665
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
666 666
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
667 667
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -688,31 +688,31 @@  discard block
 block discarded – undo
688 688
 	    )
689 689
 	) {
690 690
 	    echo 'download...';
691
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
691
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
692 692
 	    echo 'done !'."\n";
693 693
 	    // FIXME: Need more work
694 694
 	    if ($buffer != '') $reset = 0;
695
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
696
-	    $buffer = explode('\n',$buffer);
695
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
696
+	    $buffer = explode('\n', $buffer);
697 697
 	    foreach ($buffer as $line) {
698 698
 		if ($line != '') {
699 699
 		    $data = array();
700 700
 		    echo $line."\n";
701
-		    $data['mmsi'] = (int)substr($line,0,9);
702
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
703
-		    $data['status_id'] = substr($line,21,2);
704
-		    $data['type_id'] = substr($line,24,3);
705
-		    $data['latitude'] = substr($line,29,9);
706
-		    $data['longitude'] = substr($line,41,9);
707
-		    $data['speed'] = round(substr($line,51,5));
701
+		    $data['mmsi'] = (int) substr($line, 0, 9);
702
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
703
+		    $data['status_id'] = substr($line, 21, 2);
704
+		    $data['type_id'] = substr($line, 24, 3);
705
+		    $data['latitude'] = substr($line, 29, 9);
706
+		    $data['longitude'] = substr($line, 41, 9);
707
+		    $data['speed'] = round(substr($line, 51, 5));
708 708
 		    //$data['course'] = substr($line,57,5);
709
-		    $data['heading'] = round(substr($line,63,3));
709
+		    $data['heading'] = round(substr($line, 63, 3));
710 710
 		    //$data['draft'] = substr($line,67,4);
711 711
 		    //$data['length'] = substr($line,72,3);
712 712
 		    //$data['beam'] = substr($line,76,2);
713
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
713
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
714 714
 		    //$data['callsign'] = trim(substr($line,100,7);
715
-		    $data['arrival_code'] = substr($line,108,20);
715
+		    $data['arrival_code'] = substr($line, 108, 20);
716 716
 		    //$data['etaDate'] = substr($line,129,5);
717 717
 		    //$data['etaTime'] = substr($line,135,5);
718 718
 		    $data['format_source'] = 'shipplotter';
@@ -743,8 +743,8 @@  discard block
 block discarded – undo
743 743
 	) {
744 744
 	    //$buffer = $Common->getData($hosts[$id]);
745 745
 	    $buffer = $Common->getData($value['host']);
746
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
747
-	    $buffer = explode('\n',$buffer);
746
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
747
+	    $buffer = explode('\n', $buffer);
748 748
 	    $reset = 0;
749 749
 	    foreach ($buffer as $line) {
750 750
     		if ($line != '') {
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
756 756
 			$data['pilot_id'] = $line[1];
757 757
 			$data['pilot_name'] = $line[2];
758
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
758
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
759 759
 			$data['ident'] = $line[0]; // ident
760 760
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
761 761
 			$data['speed'] = $line[8]; // speed
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
772 772
 			//if (isset($line[37])) $data['last_update'] = $line[37];
773 773
 		        $data['departure_airport_icao'] = $line[11];
774
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
774
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
775 775
 		        $data['arrival_airport_icao'] = $line[13];
776 776
 			$data['frequency'] = $line[4];
777 777
 			$data['type'] = $line[18];
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
     			$data['id_source'] = $id_source;
781 781
 	    		//$data['arrival_airport_time'] = ;
782 782
 	    		if ($line[9] != '') {
783
-	    		    $aircraft_data = explode('/',$line[9]);
783
+	    		    $aircraft_data = explode('/', $line[9]);
784 784
 	    		    if (isset($aircraft_data[1])) {
785 785
 	    			$data['aircraft_icao'] = $aircraft_data[1];
786 786
 	    		    }
@@ -795,9 +795,9 @@  discard block
 block discarded – undo
795 795
     			if ($line[3] === 'PILOT') $SI->add($data);
796 796
 			elseif ($line[3] === 'ATC') {
797 797
 				//print_r($data);
798
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
799
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
800
-				$typec = substr($data['ident'],-3);
798
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
799
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
800
+				$typec = substr($data['ident'], -3);
801 801
 				if ($typec === 'APP') $data['type'] = 'Approach';
802 802
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
803 803
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -809,8 +809,8 @@  discard block
 block discarded – undo
809 809
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
810 810
 				if (!isset($data['source_name'])) $data['source_name'] = '';
811 811
 				if (isset($ATC)) {
812
-					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']);
813
-					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']);
812
+					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']);
813
+					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']);
814 814
 				}
815 815
 			}
816 816
     			unset($data);
@@ -826,24 +826,24 @@  discard block
 block discarded – undo
826 826
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
827 827
     	    )
828 828
     	) {
829
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
829
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
830 830
 	    if ($buffer != '') {
831 831
 		$all_data = simplexml_load_string($buffer);
832
-		foreach($all_data->children() as $childdata) {
832
+		foreach ($all_data->children() as $childdata) {
833 833
 			$data = array();
834 834
 			$line = $childdata;
835 835
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
836
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
837
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
838
-			$data['latitude'] = (float)$line['pktLatitude'];
839
-			$data['longitude'] = (float)$line['pktLongitude'];
840
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
841
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
842
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
836
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
837
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
838
+			$data['latitude'] = (float) $line['pktLatitude'];
839
+			$data['longitude'] = (float) $line['pktLongitude'];
840
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
841
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
842
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
843 843
 			$data['altitude_relative'] = 'AMSL';
844
-			$data['pilot_id'] = (int)$line['pktPilotID'];
844
+			$data['pilot_id'] = (int) $line['pktPilotID'];
845 845
 			$data['aircraft_icao'] = 'PARAGLIDER';
846
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
846
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
847 847
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
848 848
 			$data['format_source'] = $value['format'];
849 849
 			$SI->add($data);
@@ -851,22 +851,22 @@  discard block
 block discarded – undo
851 851
 		}
852 852
 	    }
853 853
 	    $Source->deleteOldLocationByType('gs');
854
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
854
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
855 855
 	    if ($buffer != '') {
856 856
 		$all_data = simplexml_load_string($buffer);
857
-		foreach($all_data->children() as $childdata) {
857
+		foreach ($all_data->children() as $childdata) {
858 858
 			$data = array();
859 859
 			$line = $childdata;
860
-			$data['id'] = (int)$line['gsID'];
861
-			$data['latitude'] = (float)$line['gsLatitude'];
862
-			$data['longitude'] = (float)$line['gsLongitude'];
863
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
860
+			$data['id'] = (int) $line['gsID'];
861
+			$data['latitude'] = (float) $line['gsLatitude'];
862
+			$data['longitude'] = (float) $line['gsLongitude'];
863
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
864 864
 			$data['altitude_relative'] = 'AMSL';
865
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
865
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
866 866
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
867
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
867
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
868 868
 			} else {
869
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
869
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
870 870
 			}
871 871
 			unset($data);
872 872
 		}
@@ -884,9 +884,9 @@  discard block
 block discarded – undo
884 884
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
885 885
 	    )
886 886
 	) {
887
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
887
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
888 888
 	    if ($buffer != '') {
889
-	        $all_data = json_decode($buffer,true);
889
+	        $all_data = json_decode($buffer, true);
890 890
 		if (isset($all_data['acList'])) {
891 891
 		    $reset = 0;
892 892
 		    foreach ($all_data['acList'] as $line) {
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
903 903
 			$data['emergency'] = ''; // emergency
904 904
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
905
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
905
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
906 906
 			else $data['datetime'] = date('Y-m-d H:i:s');
907 907
 			//$data['datetime'] = date('Y-m-d H:i:s');
908 908
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
 			$data['verticalrate'] = $line['vrt']; // verticale rate
928 928
 			$data['squawk'] = $line['squawk']; // squawk
929 929
 			$data['emergency'] = ''; // emergency
930
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
930
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
931 931
 			else $data['datetime'] = date('Y-m-d H:i:s');
932 932
 			$data['format_source'] = 'aircraftlistjson';
933 933
 			$data['id_source'] = $id_source;
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
     	    )
949 949
     	) {
950 950
 	    $buffer = $Common->getData($value['host']);
951
-	    $all_data = json_decode($buffer,true);
951
+	    $all_data = json_decode($buffer, true);
952 952
 	    if (isset($all_data['planes'])) {
953 953
 		$reset = 0;
954 954
 		foreach ($all_data['planes'] as $key => $line) {
@@ -965,12 +965,12 @@  discard block
 block discarded – undo
965 965
 		    $data['emergency'] = ''; // emergency
966 966
 		    $data['registration'] = $line[2];
967 967
 		    $data['aircraft_icao'] = $line[0];
968
-		    $deparr = explode('-',$line[1]);
968
+		    $deparr = explode('-', $line[1]);
969 969
 		    if (count($deparr) === 2) {
970 970
 			$data['departure_airport_icao'] = $deparr[0];
971 971
 			$data['arrival_airport_icao'] = $deparr[1];
972 972
 		    }
973
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
973
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
974 974
 	    	    $data['format_source'] = 'planeupdatefaa';
975 975
     		    $data['id_source'] = $id_source;
976 976
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 	    )
989 989
 	) {
990 990
 	    $buffer = $Common->getData($value['host']);
991
-	    $all_data = json_decode($buffer,true);
991
+	    $all_data = json_decode($buffer, true);
992 992
 	    if (isset($all_data['states'])) {
993 993
 		$reset = 0;
994 994
 		foreach ($all_data['states'] as $key => $line) {
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
 		    //$data['emergency'] = ''; // emergency
1006 1006
 		    //$data['registration'] = $line[2];
1007 1007
 		    //$data['aircraft_icao'] = $line[0];
1008
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1008
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1009 1009
 		    $data['format_source'] = 'opensky';
1010 1010
 		    $data['id_source'] = $id_source;
1011 1011
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1022,8 +1022,8 @@  discard block
 block discarded – undo
1022 1022
 	    )
1023 1023
 	) {
1024 1024
 	    $buffer = $Common->getData($value['host']);
1025
-	    $all_data = json_decode($buffer,true);
1026
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1025
+	    $all_data = json_decode($buffer, true);
1026
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1027 1027
 		$reset = 0;
1028 1028
 		foreach ($all_data['aircraft'] as $key => $line) {
1029 1029
 		    $data = array();
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
 	) {
1063 1063
 	    //$buffer = $Common->getData($hosts[$id]);
1064 1064
 	    $buffer = $Common->getData($value['host']);
1065
-	    $all_data = json_decode($buffer,true);
1065
+	    $all_data = json_decode($buffer, true);
1066 1066
 	    if (!empty($all_data)) $reset = 0;
1067 1067
 	    foreach ($all_data as $key => $line) {
1068 1068
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1100,11 +1100,11 @@  discard block
 block discarded – undo
1100 1100
 	    )
1101 1101
 	) {
1102 1102
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1103
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1103
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1104 1104
 	    //echo $buffer;
1105
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1106
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1107
-	    $all_data = json_decode($buffer,true);
1105
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1106
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1107
+	    $all_data = json_decode($buffer, true);
1108 1108
 	    if (json_last_error() != JSON_ERROR_NONE) {
1109 1109
 		die(json_last_error_msg());
1110 1110
 	    }
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
 			//$data['departure_airport_iata'] = $line[11];
1128 1128
 			//$data['arrival_airport_iata'] = $line[12];
1129 1129
 	    		//$data['emergency'] = ''; // emergency
1130
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1130
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1131 1131
 	    		$data['format_source'] = 'radarvirtueljson';
1132 1132
     			$data['id_source'] = $id_source;
1133 1133
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1148,14 +1148,14 @@  discard block
 block discarded – undo
1148 1148
 	) {
1149 1149
 	    //$buffer = $Common->getData($hosts[$id]);
1150 1150
 	    $buffer = $Common->getData($value['host'].'?'.time());
1151
-	    $all_data = json_decode(utf8_encode($buffer),true);
1151
+	    $all_data = json_decode(utf8_encode($buffer), true);
1152 1152
 	    
1153 1153
 	    if (isset($all_data['pireps'])) {
1154 1154
 		$reset = 0;
1155 1155
 	        foreach ($all_data['pireps'] as $line) {
1156 1156
 		    $data = array();
1157 1157
 		    $data['id'] = $line['id'];
1158
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1158
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1159 1159
 		    $data['ident'] = $line['callsign']; // ident
1160 1160
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1161 1161
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1185,9 +1185,9 @@  discard block
 block discarded – undo
1185 1185
 			$SI->add($data);
1186 1186
 		    //    print_r($data);
1187 1187
     		    } elseif ($line['icon'] === 'ct') {
1188
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1189
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1190
-			$typec = substr($data['ident'],-3);
1188
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1189
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1190
+			$typec = substr($data['ident'], -3);
1191 1191
 			$data['type'] = '';
1192 1192
 			if ($typec === 'APP') $data['type'] = 'Approach';
1193 1193
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1199 1199
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1200 1200
 			else $data['type'] = 'Observer';
1201
-			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']);
1201
+			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']);
1202 1202
 		    }
1203 1203
 		    unset($data);
1204 1204
 		}
@@ -1215,14 +1215,14 @@  discard block
 block discarded – undo
1215 1215
 	    //$buffer = $Common->getData($hosts[$id]);
1216 1216
 	    if ($globalDebug) echo 'Get Data...'."\n";
1217 1217
 	    $buffer = $Common->getData($value['host']);
1218
-	    $all_data = json_decode($buffer,true);
1218
+	    $all_data = json_decode($buffer, true);
1219 1219
 	    if ($buffer != '' && is_array($all_data)) {
1220 1220
 		$reset = 0;
1221 1221
 		foreach ($all_data as $line) {
1222 1222
 	    	    $data = array();
1223 1223
 	    	    //$data['id'] = $line['id']; // id not usable
1224 1224
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1225
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1225
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1226 1226
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1227 1227
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1228 1228
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
 	    	    //$data['datetime'] = $line['lastupdate'];
1238 1238
 	    	    //$data['last_update'] = $line['lastupdate'];
1239 1239
 	    	    if (isset($value['timezone'])) {
1240
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1240
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1241 1241
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1242 1242
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1243 1243
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1253,14 +1253,14 @@  discard block
 block discarded – undo
1253 1253
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1254 1254
 		    if (isset($line['aircraftname'])) {
1255 1255
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1256
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1257
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1256
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1257
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1258 1258
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1259 1259
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1260 1260
 	    		else {
1261
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1262
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1263
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1261
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1262
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1263
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1264 1264
 	    		}
1265 1265
 	    	    }
1266 1266
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
 	    //$buffer = $Common->getData($hosts[$id]);
1286 1286
 	    if ($globalDebug) echo 'Get Data...'."\n";
1287 1287
 	    $buffer = $Common->getData($value['host']);
1288
-	    $all_data = json_decode($buffer,true);
1288
+	    $all_data = json_decode($buffer, true);
1289 1289
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1290 1290
 		$reset = 0;
1291 1291
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1297 1297
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1298 1298
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1299
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1299
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1300 1300
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1301 1301
 	    	    $data['altitude'] = $line['altitude']; // altitude
1302 1302
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	    	    //$data['squawk'] = ''; // squawk
1308 1308
 	    	    //$data['emergency'] = ''; // emergency
1309 1309
 	    	    if (isset($value['timezone'])) {
1310
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1310
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1311 1311
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1312 1312
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1313 1313
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1343,14 +1343,14 @@  discard block
 block discarded – undo
1343 1343
 	    //$buffer = $Common->getData($hosts[$id]);
1344 1344
 	    if ($globalDebug) echo 'Get Data...'."\n";
1345 1345
 	    $buffer = $Common->getData($value['host']);
1346
-	    $all_data = json_decode($buffer,true);
1346
+	    $all_data = json_decode($buffer, true);
1347 1347
 	    if ($buffer != '' && is_array($all_data)) {
1348 1348
 		$reset = 0;
1349 1349
 		foreach ($all_data as $line) {
1350 1350
 	    	    $data = array();
1351 1351
 	    	    //$data['id'] = $line['id']; // id not usable
1352 1352
 	    	    $data['id'] = trim($line['flight_id']);
1353
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1353
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1354 1354
 	    	    $data['pilot_name'] = $line['pilot_name'];
1355 1355
 	    	    $data['pilot_id'] = $line['pilot_id'];
1356 1356
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1394,24 +1394,24 @@  discard block
 block discarded – undo
1394 1394
 	    //$buffer = $Common->getData($hosts[$id]);
1395 1395
 	    if ($globalDebug) echo 'Get Data...'."\n";
1396 1396
 	    $buffer = $Common->getData($value['host']);
1397
-	    $all_data = json_decode($buffer,true);
1397
+	    $all_data = json_decode($buffer, true);
1398 1398
 	    if ($buffer != '') {
1399 1399
 		$Source->deleteLocationBySource('blitzortung');
1400
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1401
-		$buffer = explode('\n',$buffer);
1400
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1401
+		$buffer = explode('\n', $buffer);
1402 1402
 		foreach ($buffer as $buffer_line) {
1403
-		    $line = json_decode($buffer_line,true);
1403
+		    $line = json_decode($buffer_line, true);
1404 1404
 		    if (isset($line['time'])) {
1405 1405
 			$data = array();
1406 1406
 			$data['altitude'] = $line['alt']; // altitude
1407 1407
 			$data['latitude'] = $line['lat']; // lat
1408 1408
 			$data['longitude'] = $line['lon']; // long
1409
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1409
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1410 1410
 			$data['id_source'] = $id_source;
1411 1411
 			$data['format_source'] = 'blitzortung';
1412 1412
 			$SI->add($data);
1413 1413
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1414
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1414
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1415 1415
 			unset($data);
1416 1416
 		    }
1417 1417
 		}
@@ -1434,11 +1434,11 @@  discard block
 block discarded – undo
1434 1434
 		    //$value = $formats[$nb];
1435 1435
 		    $format = $globalSources[$nb]['format'];
1436 1436
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1437
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1437
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1438 1438
 		    } elseif ($format === 'vrstcp') {
1439 1439
 			$buffer = @socket_read($r, 6000);
1440 1440
 		    } else {
1441
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1441
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1442 1442
 		    }
1443 1443
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1444 1444
 		    //echo $buffer."\n";
@@ -1448,8 +1448,8 @@  discard block
 block discarded – undo
1448 1448
 		    //$SI::del();
1449 1449
 		    if ($buffer !== FALSE) {
1450 1450
 			if ($format === 'vrstcp') {
1451
-			    $buffer = explode('},{',$buffer);
1452
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1451
+			    $buffer = explode('},{', $buffer);
1452
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1453 1453
 		    }
1454 1454
 		    // SBS format is CSV format
1455 1455
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1473,7 +1473,7 @@  discard block
 block discarded – undo
1473 1473
 			    $ais_data = $AIS->parse_line(trim($buffer));
1474 1474
 			    $data = array();
1475 1475
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1476
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1476
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1477 1477
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1478 1478
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1479 1479
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1484,13 +1484,13 @@  discard block
 block discarded – undo
1484 1484
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1485 1485
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1486 1486
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1487
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1487
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1488 1488
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1489 1489
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1490 1490
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1491 1491
 
1492 1492
 			    if (isset($ais_data['timestamp'])) {
1493
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1493
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1494 1494
 			    } else {
1495 1495
 				$data['datetime'] = date('Y-m-d H:i:s');
1496 1496
 			    }
@@ -1501,10 +1501,10 @@  discard block
 block discarded – undo
1501 1501
                         } elseif ($format === 'flightgearsp') {
1502 1502
                     	    //echo $buffer."\n";
1503 1503
                     	    if (strlen($buffer) > 5) {
1504
-				$line = explode(',',$buffer);
1504
+				$line = explode(',', $buffer);
1505 1505
 				$data = array();
1506 1506
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1507
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1507
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1508 1508
 				$data['ident'] = $line[6];
1509 1509
 				$data['aircraft_name'] = $line[7];
1510 1510
 				$data['longitude'] = $line[1];
@@ -1521,16 +1521,16 @@  discard block
 block discarded – undo
1521 1521
                         } elseif ($format === 'acars') {
1522 1522
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1523 1523
 			    $ACARS->add(trim($buffer));
1524
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1524
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1525 1525
 			    $ACARS->deleteLiveAcarsData();
1526 1526
 			} elseif ($format === 'flightgearmp') {
1527
-			    if (substr($buffer,0,1) != '#') {
1527
+			    if (substr($buffer, 0, 1) != '#') {
1528 1528
 				$data = array();
1529 1529
 				//echo $buffer."\n";
1530
-				$line = explode(' ',$buffer);
1530
+				$line = explode(' ', $buffer);
1531 1531
 				if (count($line) === 11) {
1532
-				    $userserver = explode('@',$line[0]);
1533
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1532
+				    $userserver = explode('@', $line[0]);
1533
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1534 1534
 				    $data['ident'] = $userserver[0];
1535 1535
 				    $data['registration'] = $userserver[0];
1536 1536
 				    $data['latitude'] = $line[4];
@@ -1538,8 +1538,8 @@  discard block
 block discarded – undo
1538 1538
 				    $data['altitude'] = $line[6];
1539 1539
 				    $data['datetime'] = date('Y-m-d H:i:s');
1540 1540
 				    $aircraft_type = $line[10];
1541
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1542
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1541
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1542
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1543 1543
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1544 1544
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1545 1545
 				}
@@ -1548,8 +1548,8 @@  discard block
 block discarded – undo
1548 1548
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1549 1549
 			    die;
1550 1550
 			} elseif ($format === 'vrstcp') {
1551
-			    foreach($buffer as $all_data) {
1552
-				$line = json_decode('{'.$all_data.'}',true);
1551
+			    foreach ($buffer as $all_data) {
1552
+				$line = json_decode('{'.$all_data.'}', true);
1553 1553
 				$data = array();
1554 1554
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1555 1555
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1575,16 +1575,16 @@  discard block
 block discarded – undo
1575 1575
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1576 1576
 				unset($data);
1577 1577
 			    }
1578
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1578
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1579 1579
 			    $line = explode("\t", $buffer);
1580
-			    for($k = 0; $k < count($line); $k=$k+2) {
1580
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1581 1581
 				$key = $line[$k];
1582
-			        $lined[$key] = $line[$k+1];
1582
+			        $lined[$key] = $line[$k + 1];
1583 1583
 			    }
1584 1584
     			    if (count($lined) > 3) {
1585 1585
     				$data['hex'] = $lined['hexid'];
1586 1586
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1587
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1587
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1588 1588
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1589 1589
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1590 1590
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1603,23 +1603,23 @@  discard block
 block discarded – undo
1603 1603
     			    } else $error = true;
1604 1604
 			} elseif ($format === 'aprs' && $use_aprs) {
1605 1605
 			    if ($aprs_connect === 0) {
1606
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1606
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1607 1607
 				$aprs_connect = 1;
1608 1608
 			    }
1609 1609
 			    
1610
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1610
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1611 1611
 				$aprs_last_tx = time();
1612 1612
 				$data_aprs = "# Keep alive";
1613
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1613
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1614 1614
 			    }
1615 1615
 			    
1616 1616
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1617 1617
 			    //echo 'APRS data : '.$buffer."\n";
1618
-			    $buffer = str_replace('APRS <- ','',$buffer);
1619
-			    $buffer = str_replace('APRS -> ','',$buffer);
1618
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1619
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1620 1620
 			    //echo $buffer."\n";
1621 1621
 			    date_default_timezone_set('UTC');
1622
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1622
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1623 1623
 				$line = $APRS->parse($buffer);
1624 1624
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1625 1625
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1635 1635
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1636 1636
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1637
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1637
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1638 1638
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1639 1639
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1640 1640
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1717,29 +1717,29 @@  discard block
 block discarded – undo
1717 1717
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1718 1718
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1719 1719
 					$Source->deleteOldLocationByType('gs');
1720
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1721
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1720
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1721
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1722 1722
 					} else {
1723
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1723
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1724 1724
 					}
1725 1725
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1726 1726
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1727 1727
 					if ($globalDebug) echo '# Weather Station added'."\n";
1728 1728
 					$Source->deleteOldLocationByType('wx');
1729 1729
 					$weather_data = json_encode($line);
1730
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1731
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1730
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1731
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1732 1732
 					} else {
1733
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1733
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1734 1734
 					}
1735 1735
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1736 1736
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1737 1737
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1738 1738
 					$Source->deleteOldLocationByType('lightning');
1739
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1740
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1739
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1740
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1741 1741
 					} else {
1742
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1742
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1743 1743
 					}
1744 1744
 				    } elseif ($globalDebug) {
1745 1745
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1748,7 +1748,7 @@  discard block
 block discarded – undo
1748 1748
 				    unset($data);
1749 1749
 				}
1750 1750
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1751
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1751
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1752 1752
 				}
1753 1753
 				/*
1754 1754
 				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')) {
@@ -1757,7 +1757,7 @@  discard block
 block discarded – undo
1757 1757
 				*/
1758 1758
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1759 1759
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1760
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1760
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1761 1761
 					$Source->deleteOldLocationByType('lightning');
1762 1762
 					$Source->deleteOldLocationByType('wx');
1763 1763
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1842,7 +1842,7 @@  discard block
 block discarded – undo
1842 1842
 				connect_all($sourceee);
1843 1843
 				$sourceee = array();
1844 1844
 				//connect_all($globalSources);
1845
-				$tt[$format]=0;
1845
+				$tt[$format] = 0;
1846 1846
 				break;
1847 1847
 			    } 
1848 1848
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1852,14 +1852,14 @@  discard block
 block discarded – undo
1852 1852
 	    } else {
1853 1853
 		$error = socket_strerror(socket_last_error());
1854 1854
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1855
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1855
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1856 1856
 			if (isset($globalDebug)) echo "Restarting...\n";
1857 1857
 			// Restart the script if possible
1858 1858
 			if (is_array($sockets)) {
1859 1859
 			    if ($globalDebug) echo "Shutdown all sockets...";
1860 1860
 			    
1861 1861
 			    foreach ($sockets as $sock) {
1862
-				@socket_shutdown($sock,2);
1862
+				@socket_shutdown($sock, 2);
1863 1863
 				@socket_close($sock);
1864 1864
 			    }
1865 1865
 			    
Please login to merge, or discard this patch.