Completed
Push — master ( c36b15...edc2c3 )
by Yannick
43:12 queued 10:24
created
scripts/daemon-spotter.php 2 patches
Spacing   +213 added lines, -213 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,22 +258,22 @@  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) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
266
+        } elseif (filter_var($host, FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
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 && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274 274
     		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276
-	    $hostport = explode(':',$host);
275
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
276
+	    $hostport = explode(':', $host);
277 277
 	    if (isset($hostport[1])) {
278 278
 		$port = $hostport[1];
279 279
 		$hostn = $hostport[0];
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	    }
284 284
 	    $Common = new Common();
285 285
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
286
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
286
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
287 287
     	    } else {
288
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
288
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
289 289
 	    }
290 290
 	    if ($s) {
291 291
     	        $sockets[$id] = $s;
292 292
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
293
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
293
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
294 294
 			//$formats[$id] = 'aprs';
295 295
 			$globalSources[$id]['format'] = 'aprs';
296 296
 			//$aprs_connect = 0;
297 297
 			//$use_aprs = true;
298
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
298
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
299 299
 			$globalSources[$id]['format'] = 'vrstcp';
300 300
     		    } elseif ($port == '10001') {
301 301
         		//$formats[$id] = 'tsv';
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
337 337
 else $timeout = 20;
338 338
 $errno = '';
339
-$errstr='';
339
+$errstr = '';
340 340
 
341 341
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
342 342
 /* Initiate connections to all the hosts simultaneously */
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 //connect_all($globalSources);
345 345
 
346 346
 if (isset($globalProxy) && $globalProxy) {
347
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
347
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
348 348
 } else {
349 349
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
350 350
 }
@@ -374,16 +374,16 @@  discard block
 block discarded – undo
374 374
 
375 375
 if ($use_aprs) {
376 376
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
377
-	$APRS=new APRS();
377
+	$APRS = new APRS();
378 378
 	$aprs_connect = 0;
379 379
 	$aprs_keep = 120;
380 380
 	$aprs_last_tx = time();
381 381
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
382
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
382
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
383 383
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
384
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
384
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
385 385
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
386
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
386
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
387 387
 	if ($aprs_full) $aprs_filter = '';
388 388
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
389 389
 	else $aprs_pass = '-1';
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
 sleep(1);
398 398
 if ($globalDebug) echo "SCAN MODE \n\n";
399 399
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
400
-$endtime = time()+$globalCronEnd;
400
+$endtime = time() + $globalCronEnd;
401 401
 $i = 1;
402 402
 $tt = array();
403 403
 // Delete all ATC
404 404
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
405
-	$ATC=new ATC($Connection->db);
405
+	$ATC = new ATC($Connection->db);
406 406
 }
407 407
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
408 408
 	$ATC->deleteAll();
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 while ($i > 0) {
413 413
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
414 414
 
415
-    if (!$globalDaemon) $i = $endtime-time();
415
+    if (!$globalDaemon) $i = $endtime - time();
416 416
     // Delete old ATC
417 417
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
418 418
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 	}
427 427
 	if ($max < $globalMinFetch) {
428 428
 	    if ($globalDebug) echo 'Sleeping...'."\n";
429
-	    sleep($globalMinFetch-$max+2);
429
+	    sleep($globalMinFetch - $max + 2);
430 430
 	}
431 431
     }
432 432
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	    //$buffer = $Common->getData($hosts[$id]);
446 446
 	    $buffer = $Common->getData($value['host']);
447 447
 	    if ($buffer != '') $reset = 0;
448
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
-	    $buffer = explode('\n',$buffer);
448
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
449
+	    $buffer = explode('\n', $buffer);
450 450
 	    foreach ($buffer as $line) {
451 451
     		if ($line != '' && count($line) > 7) {
452 452
     		    $line = explode(',', $line);
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	    )
480 480
 	) {
481 481
 	    date_default_timezone_set('CET');
482
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
482
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
483 483
 	    date_default_timezone_set('UTC');
484 484
 	    if ($buffer != '') $reset = 0;
485
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486
-	    $buffer = explode('\n',$buffer);
485
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
486
+	    $buffer = explode('\n', $buffer);
487 487
 	    foreach ($buffer as $line) {
488 488
 		if ($line != '') {
489 489
 		    //echo "'".$line."'\n";
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 		    $ais_data = $AIS->parse_line(trim($line));
492 492
 		    $data = array();
493 493
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
494
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
495 495
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496 496
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497 497
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504 504
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
505 505
 		    if (isset($ais_data['timestamp'])) {
506
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
506
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
507 507
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
508 508
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
509 509
 			    $add = true;
@@ -526,21 +526,21 @@  discard block
 block discarded – undo
526 526
 	    $w = $e = null;
527 527
 	    
528 528
 	    if (isset($arr[$id])) {
529
-		$nn = stream_select($arr,$w,$e,$timeout);
529
+		$nn = stream_select($arr, $w, $e, $timeout);
530 530
 		if ($nn > 0) {
531 531
 		    foreach ($httpfeeds as $feed) {
532
-			$buffer = stream_get_line($feed,2000,"\n");
532
+			$buffer = stream_get_line($feed, 2000, "\n");
533 533
 			if ($buffer === FALSE) {
534 534
 			    connect_all($globalSources);
535 535
 			}
536
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-			$buffer = explode('\n',$buffer);
536
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
537
+			$buffer = explode('\n', $buffer);
538 538
 			foreach ($buffer as $line) {
539 539
 			    if ($line != '') {
540 540
 				$ais_data = $AIS->parse_line(trim($line));
541 541
 				$data = array();
542 542
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
543
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
543
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
544 544
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
545 545
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
546 546
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
553 553
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
554 554
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
555
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
555
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
556 556
 				if (isset($ais_data['timestamp'])) {
557
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
557
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
558 558
 				} else {
559 559
 				    $data['datetime'] = date('Y-m-d H:i:s');
560 560
 				}
@@ -586,10 +586,10 @@  discard block
 block discarded – undo
586 586
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
587 587
 	    )
588 588
 	) {
589
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
589
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
590 590
 	    if ($buffer != '') {
591 591
 		//echo $buffer;
592
-		$all_data = json_decode($buffer,true);
592
+		$all_data = json_decode($buffer, true);
593 593
 		//print_r($all_data);
594 594
 		if (isset($all_data[0]['DATA'])) {
595 595
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 			    $data['ident'] = $line['NAME'];
599 599
 			    $data['mmsi'] = $line['MMSI'];
600 600
 			    if (strlen($data['mmsi']) > 9) {
601
-				$data['mmsi'] = substr($data['mmsi'],-9);
601
+				$data['mmsi'] = substr($data['mmsi'], -9);
602 602
 			    }
603 603
 			    $data['speed'] = $line['SOG'];
604 604
 			    $data['heading'] = $line['COG'];
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
 			    //$data['type_id'] = $line['TYPE'];
609 609
 			    $data['imo'] = $line['IMO'];
610 610
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
611
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
612
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
611
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
612
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
613 613
 			    $data['format_source'] = 'myshiptracking';
614 614
 			    $data['id_source'] = $id_source;
615 615
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -626,16 +626,16 @@  discard block
 block discarded – undo
626 626
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
627 627
 	    )
628 628
 	) {
629
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
629
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
630 630
 	    if ($buffer != '') {
631
-		$all_data = json_decode($buffer,true);
631
+		$all_data = json_decode($buffer, true);
632 632
 		if (isset($all_data[0]['mmsi'])) {
633 633
 		    foreach ($all_data as $line) {
634 634
 			if ($line != '') {
635 635
 			    $data = array();
636 636
 			    $data['ident'] = $line['shipname'];
637 637
 			    $data['callsign'] = $line['callsign'];
638
-			    $data['mmsi'] = substr($line['mmsi'],-9);
638
+			    $data['mmsi'] = substr($line['mmsi'], -9);
639 639
 			    $data['speed'] = $line['sog'];
640 640
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
641 641
 			    $data['latitude'] = $line['latitude'];
@@ -662,14 +662,14 @@  discard block
 block discarded – undo
662 662
 	) {
663 663
 	    $buffer = $Common->getData($value['host']);
664 664
 	    if ($buffer != '') {
665
-		$all_data = json_decode($buffer,true);
665
+		$all_data = json_decode($buffer, true);
666 666
 		if (isset($all_data['features'][0]['id'])) {
667 667
 		    foreach ($all_data['features'] as $line) {
668 668
 			print_r($line);
669 669
 			$data = array();
670 670
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
671 671
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
672
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
672
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
673 673
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
674 674
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
675 675
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -696,31 +696,31 @@  discard block
 block discarded – undo
696 696
 	    )
697 697
 	) {
698 698
 	    if ($globalDebug) echo 'download...';
699
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
699
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
700 700
 	    if ($globalDebug) echo 'done !'."\n";
701 701
 	    // FIXME: Need more work
702 702
 	    if ($buffer != '') $reset = 0;
703
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
704
-	    $buffer = explode('\n',$buffer);
703
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
704
+	    $buffer = explode('\n', $buffer);
705 705
 	    foreach ($buffer as $line) {
706 706
 		if ($line != '') {
707 707
 		    $data = array();
708 708
 		    //echo $line."\n";
709
-		    $data['mmsi'] = (int)substr($line,0,9);
710
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
711
-		    $data['status_id'] = substr($line,21,2);
712
-		    $data['type_id'] = substr($line,24,3);
713
-		    $data['latitude'] = substr($line,29,9);
714
-		    $data['longitude'] = substr($line,41,9);
715
-		    $data['speed'] = round(substr($line,51,5));
709
+		    $data['mmsi'] = (int) substr($line, 0, 9);
710
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
711
+		    $data['status_id'] = substr($line, 21, 2);
712
+		    $data['type_id'] = substr($line, 24, 3);
713
+		    $data['latitude'] = substr($line, 29, 9);
714
+		    $data['longitude'] = substr($line, 41, 9);
715
+		    $data['speed'] = round(substr($line, 51, 5));
716 716
 		    //$data['course'] = substr($line,57,5);
717
-		    $data['heading'] = round(substr($line,63,3));
717
+		    $data['heading'] = round(substr($line, 63, 3));
718 718
 		    //$data['draft'] = substr($line,67,4);
719 719
 		    //$data['length'] = substr($line,72,3);
720 720
 		    //$data['beam'] = substr($line,76,2);
721
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
721
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
722 722
 		    //$data['callsign'] = trim(substr($line,100,7);
723
-		    $data['arrival_code'] = substr($line,108,20);
723
+		    $data['arrival_code'] = substr($line, 108, 20);
724 724
 		    //$data['etaDate'] = substr($line,129,5);
725 725
 		    //$data['etaTime'] = substr($line,135,5);
726 726
 		    $data['format_source'] = 'shipplotter';
@@ -740,21 +740,21 @@  discard block
 block discarded – undo
740 740
 	    )
741 741
 	) {
742 742
 	    if ($globalDebug) echo '! Download... ';
743
-	    for ($i =0; $i <= 1; $i++) {
743
+	    for ($i = 0; $i <= 1; $i++) {
744 744
 		    if ($globalDebug) echo 'Racetype: '.$i.' ';
745 745
 	    $buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
746 746
 	    if ($globalDebug) echo 'done'."\n";
747 747
 	    if ($buffer != '') {
748
-		$all_data = json_decode($buffer,true);
748
+		$all_data = json_decode($buffer, true);
749 749
 		if (isset($all_data['missions'])) {
750 750
 			foreach ($all_data['missions'] as $mission) {
751 751
 				$mission_user = $mission['usrname'];
752
-				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
753
-				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
752
+				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle']));
753
+				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'], $globalFilter['sailway']['race']))) {
754 754
 					$bufferm = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
755 755
 				} else $bufferm = '';
756 756
 				if ($bufferm != '') {
757
-					$mission_data = json_decode($bufferm,true);
757
+					$mission_data = json_decode($bufferm, true);
758 758
 					if (isset($mission_data['leaderboard'][0]['results'])) {
759 759
 						foreach ($mission_data['leaderboard'][0]['results'] as $sail) {
760 760
 							//print_r($sail);
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 								//$data['id'] = $sail['misnr'].'-'.$sail['usrnr'].'-'.$sail['ubtnr'];
767 767
 								$data['id'] = $sail['misnr'].'-'.$sail['usrnr'];
768 768
 								$data['datetime'] = date('Y-m-d H:i:s');
769
-								$data['race_begin'] = date('Y-m-d H:i:s',strtotime($mission_data['leaderboard'][0]['misstart']));
769
+								$data['race_begin'] = date('Y-m-d H:i:s', strtotime($mission_data['leaderboard'][0]['misstart']));
770 770
 								$data['last_update'] = date('Y-m-d H:i:s');
771 771
 								$data['status'] = $sail['status'];
772 772
 								$data['type'] = $sail['btptype'];
@@ -777,16 +777,16 @@  discard block
 block discarded – undo
777 777
 									$data['longitude'] = $pos['longitude'];
778 778
 								}
779 779
 								if ($sail['status'] == 'Racing' && $sail['resultdescr'] != '-') {
780
-									$resultdescr = explode(',',$sail['resultdescr']);
780
+									$resultdescr = explode(',', $sail['resultdescr']);
781 781
 									if (count($resultdescr) > 2) {
782
-										$data['speed'] = round(str_replace(array('Spd: ','kn.'),'',trim($resultdescr[2]))*1.852,2);
783
-										$data['heading'] = str_replace(array('Hdg: ','°'),'',trim($resultdescr[1]));
782
+										$data['speed'] = round(str_replace(array('Spd: ', 'kn.'), '', trim($resultdescr[2]))*1.852, 2);
783
+										$data['heading'] = str_replace(array('Hdg: ', '°'), '', trim($resultdescr[1]));
784 784
 										if (isset($resultdescr[3])) {
785
-											$data['distance'] = round(str_replace('nm.','',trim(explode(' ',$resultdescr[3])[1]))*1.852,3);
785
+											$data['distance'] = round(str_replace('nm.', '', trim(explode(' ', $resultdescr[3])[1]))*1.852, 3);
786 786
 										}
787 787
 									}
788 788
 								}
789
-								$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
789
+								$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
790 790
 								$data['captain_id'] = $sail['usrnr'];
791 791
 								$data['captain_name'] = $sail['usrname'];
792 792
 								$data['race_id'] = $sail['misnr'];
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
 	) {
834 834
 	    //$buffer = $Common->getData($hosts[$id]);
835 835
 	    $buffer = $Common->getData($value['host']);
836
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
837
-	    $buffer = explode('\n',$buffer);
836
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
837
+	    $buffer = explode('\n', $buffer);
838 838
 	    $reset = 0;
839 839
 	    foreach ($buffer as $line) {
840 840
     		if ($line != '') {
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
846 846
 			$data['pilot_id'] = $line[1];
847 847
 			$data['pilot_name'] = $line[2];
848
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
848
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
849 849
 			$data['ident'] = $line[0]; // ident
850 850
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
851 851
 			$data['speed'] = $line[8]; // speed
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
862 862
 			//if (isset($line[37])) $data['last_update'] = $line[37];
863 863
 		        $data['departure_airport_icao'] = $line[11];
864
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
864
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
865 865
 		        $data['arrival_airport_icao'] = $line[13];
866 866
 			$data['frequency'] = $line[4];
867 867
 			$data['type'] = $line[18];
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
     			$data['id_source'] = $id_source;
871 871
 	    		//$data['arrival_airport_time'] = ;
872 872
 	    		if ($line[9] != '') {
873
-	    		    $aircraft_data = explode('/',$line[9]);
873
+	    		    $aircraft_data = explode('/', $line[9]);
874 874
 	    		    if (isset($aircraft_data[1])) {
875 875
 	    			$data['aircraft_icao'] = $aircraft_data[1];
876 876
 	    		    }
@@ -885,9 +885,9 @@  discard block
 block discarded – undo
885 885
     			if ($line[3] === 'PILOT') $SI->add($data);
886 886
 			elseif ($line[3] === 'ATC') {
887 887
 				//print_r($data);
888
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
889
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
890
-				$typec = substr($data['ident'],-3);
888
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
889
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
890
+				$typec = substr($data['ident'], -3);
891 891
 				if ($typec === 'APP') $data['type'] = 'Approach';
892 892
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
893 893
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -899,8 +899,8 @@  discard block
 block discarded – undo
899 899
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
900 900
 				if (!isset($data['source_name'])) $data['source_name'] = '';
901 901
 				if (isset($ATC)) {
902
-					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']);
903
-					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']);
902
+					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']);
903
+					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']);
904 904
 				}
905 905
 			}
906 906
     			unset($data);
@@ -916,24 +916,24 @@  discard block
 block discarded – undo
916 916
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
917 917
     	    )
918 918
     	) {
919
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
919
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
920 920
 	    if ($buffer != '') {
921 921
 		$all_data = simplexml_load_string($buffer);
922
-		foreach($all_data->children() as $childdata) {
922
+		foreach ($all_data->children() as $childdata) {
923 923
 			$data = array();
924 924
 			$line = $childdata;
925 925
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
926
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
927
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
928
-			$data['latitude'] = (float)$line['pktLatitude'];
929
-			$data['longitude'] = (float)$line['pktLongitude'];
930
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
931
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
932
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
926
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
927
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
928
+			$data['latitude'] = (float) $line['pktLatitude'];
929
+			$data['longitude'] = (float) $line['pktLongitude'];
930
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
931
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
932
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
933 933
 			$data['altitude_relative'] = 'AMSL';
934
-			$data['pilot_id'] = (int)$line['pktPilotID'];
934
+			$data['pilot_id'] = (int) $line['pktPilotID'];
935 935
 			$data['aircraft_icao'] = 'PARAGLIDER';
936
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
936
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
937 937
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
938 938
 			$data['format_source'] = $value['format'];
939 939
 			$SI->add($data);
@@ -941,22 +941,22 @@  discard block
 block discarded – undo
941 941
 		}
942 942
 	    }
943 943
 	    $Source->deleteOldLocationByType('gs');
944
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
944
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
945 945
 	    if ($buffer != '') {
946 946
 		$all_data = simplexml_load_string($buffer);
947
-		foreach($all_data->children() as $childdata) {
947
+		foreach ($all_data->children() as $childdata) {
948 948
 			$data = array();
949 949
 			$line = $childdata;
950
-			$data['id'] = (int)$line['gsID'];
951
-			$data['latitude'] = (float)$line['gsLatitude'];
952
-			$data['longitude'] = (float)$line['gsLongitude'];
953
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
950
+			$data['id'] = (int) $line['gsID'];
951
+			$data['latitude'] = (float) $line['gsLatitude'];
952
+			$data['longitude'] = (float) $line['gsLongitude'];
953
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
954 954
 			$data['altitude_relative'] = 'AMSL';
955
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
955
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
956 956
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
957
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
957
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
958 958
 			} else {
959
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
959
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
960 960
 			}
961 961
 			unset($data);
962 962
 		}
@@ -974,9 +974,9 @@  discard block
 block discarded – undo
974 974
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
975 975
 	    )
976 976
 	) {
977
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
977
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
978 978
 	    if ($buffer != '') {
979
-	        $all_data = json_decode($buffer,true);
979
+	        $all_data = json_decode($buffer, true);
980 980
 		if (isset($all_data['acList'])) {
981 981
 		    $reset = 0;
982 982
 		    foreach ($all_data['acList'] as $line) {
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
993 993
 			$data['emergency'] = ''; // emergency
994 994
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
995
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
995
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
996 996
 			else $data['datetime'] = date('Y-m-d H:i:s');
997 997
 			//$data['datetime'] = date('Y-m-d H:i:s');
998 998
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1018 1018
 			$data['squawk'] = $line['squawk']; // squawk
1019 1019
 			$data['emergency'] = ''; // emergency
1020
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1020
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1021 1021
 			else $data['datetime'] = date('Y-m-d H:i:s');
1022 1022
 			$data['format_source'] = 'aircraftlistjson';
1023 1023
 			$data['id_source'] = $id_source;
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
     	    )
1039 1039
     	) {
1040 1040
 	    $buffer = $Common->getData($value['host']);
1041
-	    $all_data = json_decode($buffer,true);
1041
+	    $all_data = json_decode($buffer, true);
1042 1042
 	    if (isset($all_data['planes'])) {
1043 1043
 		$reset = 0;
1044 1044
 		foreach ($all_data['planes'] as $key => $line) {
@@ -1055,12 +1055,12 @@  discard block
 block discarded – undo
1055 1055
 		    $data['emergency'] = ''; // emergency
1056 1056
 		    $data['registration'] = $line[2];
1057 1057
 		    $data['aircraft_icao'] = $line[0];
1058
-		    $deparr = explode('-',$line[1]);
1058
+		    $deparr = explode('-', $line[1]);
1059 1059
 		    if (count($deparr) === 2) {
1060 1060
 			$data['departure_airport_icao'] = $deparr[0];
1061 1061
 			$data['arrival_airport_icao'] = $deparr[1];
1062 1062
 		    }
1063
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1063
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
1064 1064
 	    	    $data['format_source'] = 'planeupdatefaa';
1065 1065
     		    $data['id_source'] = $id_source;
1066 1066
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 	    )
1079 1079
 	) {
1080 1080
 	    $buffer = $Common->getData($value['host']);
1081
-	    $all_data = json_decode($buffer,true);
1081
+	    $all_data = json_decode($buffer, true);
1082 1082
 	    if (isset($all_data['states'])) {
1083 1083
 		$reset = 0;
1084 1084
 		foreach ($all_data['states'] as $key => $line) {
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
 		    //$data['emergency'] = ''; // emergency
1096 1096
 		    //$data['registration'] = $line[2];
1097 1097
 		    //$data['aircraft_icao'] = $line[0];
1098
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1098
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1099 1099
 		    $data['format_source'] = 'opensky';
1100 1100
 		    $data['id_source'] = $id_source;
1101 1101
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1112,8 +1112,8 @@  discard block
 block discarded – undo
1112 1112
 	    )
1113 1113
 	) {
1114 1114
 	    $buffer = $Common->getData($value['host']);
1115
-	    $all_data = json_decode($buffer,true);
1116
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1115
+	    $all_data = json_decode($buffer, true);
1116
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1117 1117
 		$reset = 0;
1118 1118
 		foreach ($all_data['aircraft'] as $key => $line) {
1119 1119
 		    $data = array();
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
 	    )
1152 1152
 	) {
1153 1153
 	    $buffer = $Common->getData($value['host']);
1154
-	    $all_data = json_decode($buffer,true);
1154
+	    $all_data = json_decode($buffer, true);
1155 1155
 	    if (isset($all_data['aircraft'])) {
1156 1156
 		$reset = 0;
1157 1157
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1168,7 +1168,7 @@  discard block
 block discarded – undo
1168 1168
 		    //$data['emergency'] = ''; // emergency
1169 1169
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1170 1170
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1171
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1171
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1172 1172
 		    $data['format_source'] = 'planefinderclient';
1173 1173
 		    $data['id_source'] = $id_source;
1174 1174
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
 	) {
1188 1188
 	    //$buffer = $Common->getData($hosts[$id]);
1189 1189
 	    $buffer = $Common->getData($value['host']);
1190
-	    $all_data = json_decode($buffer,true);
1190
+	    $all_data = json_decode($buffer, true);
1191 1191
 	    if (!empty($all_data)) $reset = 0;
1192 1192
 	    foreach ($all_data as $key => $line) {
1193 1193
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1225,11 +1225,11 @@  discard block
 block discarded – undo
1225 1225
 	    )
1226 1226
 	) {
1227 1227
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1228
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1228
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1229 1229
 	    //echo $buffer;
1230
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1231
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1232
-	    $all_data = json_decode($buffer,true);
1230
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1231
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1232
+	    $all_data = json_decode($buffer, true);
1233 1233
 	    if (json_last_error() != JSON_ERROR_NONE) {
1234 1234
 		die(json_last_error_msg());
1235 1235
 	    }
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
 			//$data['departure_airport_iata'] = $line[11];
1253 1253
 			//$data['arrival_airport_iata'] = $line[12];
1254 1254
 	    		//$data['emergency'] = ''; // emergency
1255
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1255
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1256 1256
 	    		$data['format_source'] = 'radarvirtueljson';
1257 1257
     			$data['id_source'] = $id_source;
1258 1258
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1273,14 +1273,14 @@  discard block
 block discarded – undo
1273 1273
 	) {
1274 1274
 	    //$buffer = $Common->getData($hosts[$id]);
1275 1275
 	    $buffer = $Common->getData($value['host'].'?'.time());
1276
-	    $all_data = json_decode(utf8_encode($buffer),true);
1276
+	    $all_data = json_decode(utf8_encode($buffer), true);
1277 1277
 	    
1278 1278
 	    if (isset($all_data['pireps'])) {
1279 1279
 		$reset = 0;
1280 1280
 	        foreach ($all_data['pireps'] as $line) {
1281 1281
 		    $data = array();
1282 1282
 		    $data['id'] = $line['id'];
1283
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1283
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1284 1284
 		    $data['ident'] = $line['callsign']; // ident
1285 1285
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1286 1286
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1310,9 +1310,9 @@  discard block
 block discarded – undo
1310 1310
 			$SI->add($data);
1311 1311
 		    //    print_r($data);
1312 1312
     		    } elseif ($line['icon'] === 'ct') {
1313
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1314
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1315
-			$typec = substr($data['ident'],-3);
1313
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1314
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1315
+			$typec = substr($data['ident'], -3);
1316 1316
 			$data['type'] = '';
1317 1317
 			if ($typec === 'APP') $data['type'] = 'Approach';
1318 1318
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1324 1324
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1325 1325
 			else $data['type'] = 'Observer';
1326
-			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']);
1326
+			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']);
1327 1327
 		    }
1328 1328
 		    unset($data);
1329 1329
 		}
@@ -1340,14 +1340,14 @@  discard block
 block discarded – undo
1340 1340
 	    //$buffer = $Common->getData($hosts[$id]);
1341 1341
 	    if ($globalDebug) echo 'Get Data...'."\n";
1342 1342
 	    $buffer = $Common->getData($value['host']);
1343
-	    $all_data = json_decode($buffer,true);
1343
+	    $all_data = json_decode($buffer, true);
1344 1344
 	    if ($buffer != '' && is_array($all_data)) {
1345 1345
 		$reset = 0;
1346 1346
 		foreach ($all_data as $line) {
1347 1347
 	    	    $data = array();
1348 1348
 	    	    //$data['id'] = $line['id']; // id not usable
1349 1349
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1350
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1350
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1351 1351
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1352 1352
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1353 1353
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
 	    	    //$data['datetime'] = $line['lastupdate'];
1363 1363
 	    	    //$data['last_update'] = $line['lastupdate'];
1364 1364
 	    	    if (isset($value['timezone'])) {
1365
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1365
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1366 1366
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1367 1367
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1368 1368
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1378,14 +1378,14 @@  discard block
 block discarded – undo
1378 1378
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1379 1379
 		    if (isset($line['aircraftname'])) {
1380 1380
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1381
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1382
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1381
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1382
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1383 1383
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1384 1384
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1385 1385
 	    		else {
1386
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1387
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1388
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1386
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1387
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1388
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1389 1389
 	    		}
1390 1390
 	    	    }
1391 1391
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 	    //$buffer = $Common->getData($hosts[$id]);
1411 1411
 	    if ($globalDebug) echo 'Get Data...'."\n";
1412 1412
 	    $buffer = $Common->getData($value['host']);
1413
-	    $all_data = json_decode($buffer,true);
1413
+	    $all_data = json_decode($buffer, true);
1414 1414
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1415 1415
 		$reset = 0;
1416 1416
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1422 1422
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1423 1423
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1424
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1424
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1425 1425
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1426 1426
 	    	    $data['altitude'] = $line['altitude']; // altitude
1427 1427
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
 	    	    //$data['squawk'] = ''; // squawk
1433 1433
 	    	    //$data['emergency'] = ''; // emergency
1434 1434
 	    	    if (isset($value['timezone'])) {
1435
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1435
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1436 1436
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1437 1437
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1438 1438
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1468,14 +1468,14 @@  discard block
 block discarded – undo
1468 1468
 	    //$buffer = $Common->getData($hosts[$id]);
1469 1469
 	    if ($globalDebug) echo 'Get Data...'."\n";
1470 1470
 	    $buffer = $Common->getData($value['host']);
1471
-	    $all_data = json_decode($buffer,true);
1471
+	    $all_data = json_decode($buffer, true);
1472 1472
 	    if ($buffer != '' && is_array($all_data)) {
1473 1473
 		$reset = 0;
1474 1474
 		foreach ($all_data as $line) {
1475 1475
 	    	    $data = array();
1476 1476
 	    	    //$data['id'] = $line['id']; // id not usable
1477 1477
 	    	    $data['id'] = trim($line['flight_id']);
1478
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1478
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1479 1479
 	    	    $data['pilot_name'] = $line['pilot_name'];
1480 1480
 	    	    $data['pilot_id'] = $line['pilot_id'];
1481 1481
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1519,24 +1519,24 @@  discard block
 block discarded – undo
1519 1519
 	    //$buffer = $Common->getData($hosts[$id]);
1520 1520
 	    if ($globalDebug) echo 'Get Data...'."\n";
1521 1521
 	    $buffer = $Common->getData($value['host']);
1522
-	    $all_data = json_decode($buffer,true);
1522
+	    $all_data = json_decode($buffer, true);
1523 1523
 	    if ($buffer != '') {
1524 1524
 		$Source->deleteLocationBySource('blitzortung');
1525
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1526
-		$buffer = explode('\n',$buffer);
1525
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1526
+		$buffer = explode('\n', $buffer);
1527 1527
 		foreach ($buffer as $buffer_line) {
1528
-		    $line = json_decode($buffer_line,true);
1528
+		    $line = json_decode($buffer_line, true);
1529 1529
 		    if (isset($line['time'])) {
1530 1530
 			$data = array();
1531 1531
 			$data['altitude'] = $line['alt']; // altitude
1532 1532
 			$data['latitude'] = $line['lat']; // lat
1533 1533
 			$data['longitude'] = $line['lon']; // long
1534
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1534
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1535 1535
 			$data['id_source'] = $id_source;
1536 1536
 			$data['format_source'] = 'blitzortung';
1537 1537
 			$SI->add($data);
1538 1538
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1539
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1539
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1540 1540
 			unset($data);
1541 1541
 		    }
1542 1542
 		}
@@ -1559,11 +1559,11 @@  discard block
 block discarded – undo
1559 1559
 		    //$value = $formats[$nb];
1560 1560
 		    $format = $globalSources[$nb]['format'];
1561 1561
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1562
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1562
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1563 1563
 		    } elseif ($format === 'vrstcp') {
1564 1564
 			$buffer = @socket_read($r, 6000);
1565 1565
 		    } else {
1566
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1566
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1567 1567
 		    }
1568 1568
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1569 1569
 		    //echo $buffer."\n";
@@ -1573,8 +1573,8 @@  discard block
 block discarded – undo
1573 1573
 		    //$SI::del();
1574 1574
 		    if ($buffer !== FALSE) {
1575 1575
 			if ($format === 'vrstcp') {
1576
-			    $buffer = explode('},{',$buffer);
1577
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1576
+			    $buffer = explode('},{', $buffer);
1577
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1578 1578
 		    }
1579 1579
 		    // SBS format is CSV format
1580 1580
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1598,7 +1598,7 @@  discard block
 block discarded – undo
1598 1598
 			    $ais_data = $AIS->parse_line(trim($buffer));
1599 1599
 			    $data = array();
1600 1600
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1601
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1601
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1602 1602
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1603 1603
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1604 1604
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1609,13 +1609,13 @@  discard block
 block discarded – undo
1609 1609
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1610 1610
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1611 1611
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1612
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1612
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1613 1613
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1614 1614
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1615 1615
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1616 1616
 
1617 1617
 			    if (isset($ais_data['timestamp'])) {
1618
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1618
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1619 1619
 			    } else {
1620 1620
 				$data['datetime'] = date('Y-m-d H:i:s');
1621 1621
 			    }
@@ -1626,10 +1626,10 @@  discard block
 block discarded – undo
1626 1626
                         } elseif ($format === 'flightgearsp') {
1627 1627
                     	    //echo $buffer."\n";
1628 1628
                     	    if (strlen($buffer) > 5) {
1629
-				$line = explode(',',$buffer);
1629
+				$line = explode(',', $buffer);
1630 1630
 				$data = array();
1631 1631
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1632
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1632
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1633 1633
 				$data['ident'] = $line[6];
1634 1634
 				$data['aircraft_name'] = $line[7];
1635 1635
 				$data['longitude'] = $line[1];
@@ -1646,16 +1646,16 @@  discard block
 block discarded – undo
1646 1646
                         } elseif ($format === 'acars') {
1647 1647
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1648 1648
 			    $ACARS->add(trim($buffer));
1649
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1649
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1650 1650
 			    $ACARS->deleteLiveAcarsData();
1651 1651
 			} elseif ($format === 'flightgearmp') {
1652
-			    if (substr($buffer,0,1) != '#') {
1652
+			    if (substr($buffer, 0, 1) != '#') {
1653 1653
 				$data = array();
1654 1654
 				//echo $buffer."\n";
1655
-				$line = explode(' ',$buffer);
1655
+				$line = explode(' ', $buffer);
1656 1656
 				if (count($line) === 11) {
1657
-				    $userserver = explode('@',$line[0]);
1658
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1657
+				    $userserver = explode('@', $line[0]);
1658
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1659 1659
 				    $data['ident'] = $userserver[0];
1660 1660
 				    $data['registration'] = $userserver[0];
1661 1661
 				    $data['latitude'] = $line[4];
@@ -1663,8 +1663,8 @@  discard block
 block discarded – undo
1663 1663
 				    $data['altitude'] = $line[6];
1664 1664
 				    $data['datetime'] = date('Y-m-d H:i:s');
1665 1665
 				    $aircraft_type = $line[10];
1666
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1667
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1666
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1667
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1668 1668
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1669 1669
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1670 1670
 				}
@@ -1673,8 +1673,8 @@  discard block
 block discarded – undo
1673 1673
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1674 1674
 			    die;
1675 1675
 			} elseif ($format === 'vrstcp') {
1676
-			    foreach($buffer as $all_data) {
1677
-				$line = json_decode('{'.$all_data.'}',true);
1676
+			    foreach ($buffer as $all_data) {
1677
+				$line = json_decode('{'.$all_data.'}', true);
1678 1678
 				$data = array();
1679 1679
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1680 1680
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1700,16 +1700,16 @@  discard block
 block discarded – undo
1700 1700
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1701 1701
 				unset($data);
1702 1702
 			    }
1703
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1703
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1704 1704
 			    $line = explode("\t", $buffer);
1705
-			    for($k = 0; $k < count($line); $k=$k+2) {
1705
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1706 1706
 				$key = $line[$k];
1707
-			        $lined[$key] = $line[$k+1];
1707
+			        $lined[$key] = $line[$k + 1];
1708 1708
 			    }
1709 1709
     			    if (count($lined) > 3) {
1710 1710
     				$data['hex'] = $lined['hexid'];
1711 1711
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1712
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1712
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1713 1713
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1714 1714
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1715 1715
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1728,23 +1728,23 @@  discard block
 block discarded – undo
1728 1728
     			    } else $error = true;
1729 1729
 			} elseif ($format === 'aprs' && $use_aprs) {
1730 1730
 			    if ($aprs_connect === 0) {
1731
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1731
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1732 1732
 				$aprs_connect = 1;
1733 1733
 			    }
1734 1734
 			    
1735
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1735
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1736 1736
 				$aprs_last_tx = time();
1737 1737
 				$data_aprs = "# Keep alive";
1738
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1738
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1739 1739
 			    }
1740 1740
 			    
1741 1741
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1742 1742
 			    //echo 'APRS data : '.$buffer."\n";
1743
-			    $buffer = str_replace('APRS <- ','',$buffer);
1744
-			    $buffer = str_replace('APRS -> ','',$buffer);
1743
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1744
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1745 1745
 			    //echo $buffer."\n";
1746 1746
 			    date_default_timezone_set('UTC');
1747
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1747
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1748 1748
 				$line = $APRS->parse($buffer);
1749 1749
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1750 1750
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1759,7 +1759,7 @@  discard block
 block discarded – undo
1759 1759
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1760 1760
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1761 1761
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1762
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1762
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1763 1763
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1764 1764
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1765 1765
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1847,29 +1847,29 @@  discard block
 block discarded – undo
1847 1847
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1848 1848
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1849 1849
 					$Source->deleteOldLocationByType('gs');
1850
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1851
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1850
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1851
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1852 1852
 					} else {
1853
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1853
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1854 1854
 					}
1855 1855
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1856 1856
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1857 1857
 					if ($globalDebug) echo '# Weather Station added'."\n";
1858 1858
 					$Source->deleteOldLocationByType('wx');
1859 1859
 					$weather_data = json_encode($line);
1860
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1861
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1860
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1861
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1862 1862
 					} else {
1863
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1863
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1864 1864
 					}
1865 1865
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1866 1866
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1867 1867
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1868 1868
 					$Source->deleteOldLocationByType('lightning');
1869
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1870
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1869
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1870
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1871 1871
 					} else {
1872
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1872
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1873 1873
 					}
1874 1874
 				    } elseif ($globalDebug) {
1875 1875
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1878,7 +1878,7 @@  discard block
 block discarded – undo
1878 1878
 				    unset($data);
1879 1879
 				}
1880 1880
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1881
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1881
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1882 1882
 				}
1883 1883
 				/*
1884 1884
 				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')) {
@@ -1887,7 +1887,7 @@  discard block
 block discarded – undo
1887 1887
 				*/
1888 1888
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1889 1889
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1890
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1890
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1891 1891
 					$Source->deleteOldLocationByType('lightning');
1892 1892
 					$Source->deleteOldLocationByType('wx');
1893 1893
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1973,7 +1973,7 @@  discard block
 block discarded – undo
1973 1973
 				connect_all($sourceee);
1974 1974
 				$sourceee = array();
1975 1975
 				//connect_all($globalSources);
1976
-				$tt[$format]=0;
1976
+				$tt[$format] = 0;
1977 1977
 				break;
1978 1978
 			    } 
1979 1979
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1983,14 +1983,14 @@  discard block
 block discarded – undo
1983 1983
 	    } else {
1984 1984
 		$error = socket_strerror(socket_last_error());
1985 1985
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1986
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1986
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1987 1987
 			if (isset($globalDebug)) echo "Restarting...\n";
1988 1988
 			// Restart the script if possible
1989 1989
 			if (is_array($sockets)) {
1990 1990
 			    if ($globalDebug) echo "Shutdown all sockets...";
1991 1991
 			    
1992 1992
 			    foreach ($sockets as $sock) {
1993
-				@socket_shutdown($sock,2);
1993
+				@socket_shutdown($sock, 2);
1994 1994
 				@socket_close($sock);
1995 1995
 			    }
1996 1996
 			    
Please login to merge, or discard this patch.
Braces   +1213 added lines, -407 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -143,7 +188,9 @@  discard block
 block discarded – undo
143 188
 }
144 189
 
145 190
 // let's try and connect
146
-if ($globalDebug) echo "Connecting...\n";
191
+if ($globalDebug) {
192
+	echo "Connecting...\n";
193
+}
147 194
 $use_aprs = false;
148 195
 $aprs_full = false;
149 196
 $reset = 0;
@@ -152,7 +199,9 @@  discard block
 block discarded – undo
152 199
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153 200
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154 201
     $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
202
+    if ($globalDebug) {
203
+    	echo 'Connect to all...'."\n";
204
+    }
156 205
     foreach ($hosts as $id => $value) {
157 206
 	$host = $value['host'];
158 207
 	$globalSources[$id]['last_exec'] = 0;
@@ -162,32 +211,44 @@  discard block
 block discarded – undo
162 211
         	//$formats[$id] = 'deltadbtxt';
163 212
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 213
         	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to deltadb source (".$host.")...\n";
216
+        	}
166 217
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167 218
         	//$formats[$id] = 'vatsimtxt';
168 219
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 220
         	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
221
+        	if ($globalDebug) {
222
+        		echo "Connect to vatsim source (".$host.")...\n";
223
+        	}
171 224
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172 225
         	//$formats[$id] = 'aircraftlistjson';
173 226
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 227
         	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	if ($globalDebug) {
229
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
230
+        	}
176 231
     	    } else if (preg_match('/aircraft.json$/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftjson';
178 233
         	$globalSources[$id]['format'] = 'aircraftjson';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to aircraft.json source (".$host.")...\n";
237
+        	}
181 238
     	    } else if (preg_match('/aircraft$/i',$host)) {
182 239
         	//$formats[$id] = 'planefinderclient';
183 240
         	$globalSources[$id]['format'] = 'planefinderclient';
184 241
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
242
+        	if ($globalDebug) {
243
+        		echo "Connect to planefinderclient source (".$host.")...\n";
244
+        	}
186 245
     	    } else if (preg_match('/opensky/i',$host)) {
187 246
         	//$formats[$id] = 'aircraftlistjson';
188 247
         	$globalSources[$id]['format'] = 'opensky';
189 248
         	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
249
+        	if ($globalDebug) {
250
+        		echo "Connect to opensky source (".$host.")...\n";
251
+        	}
191 252
     	    /*
192 253
     	    // Disabled for now, site change source format
193 254
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -204,7 +265,9 @@  discard block
 block discarded – undo
204 265
         	//$formats[$id] = 'planeupdatefaa';
205 266
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 267
         	//$last_exec['planeupdatefaa'] = 0;
207
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
268
+        	if ($globalDebug) {
269
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
270
+        	}
208 271
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209 272
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 273
         	    exit(0);
@@ -213,37 +276,53 @@  discard block
 block discarded – undo
213 276
         	//$formats[$id] = 'phpvmacars';
214 277
         	$globalSources[$id]['format'] = 'phpvmacars';
215 278
         	//$last_exec['phpvmacars'] = 0;
216
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
279
+        	if ($globalDebug) {
280
+        		echo "Connect to phpvmacars source (".$host.")...\n";
281
+        	}
217 282
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218 283
         	//$formats[$id] = 'phpvmacars';
219 284
         	$globalSources[$id]['format'] = 'vaos';
220 285
         	//$last_exec['phpvmacars'] = 0;
221
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
286
+        	if ($globalDebug) {
287
+        		echo "Connect to vaos source (".$host.")...\n";
288
+        	}
222 289
             } else if (preg_match('/VAM-json.php$/i',$host)) {
223 290
         	//$formats[$id] = 'phpvmacars';
224 291
         	$globalSources[$id]['format'] = 'vam';
225
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
292
+        	if ($globalDebug) {
293
+        		echo "Connect to Vam source (".$host.")...\n";
294
+        	}
226 295
             } else if (preg_match('/whazzup/i',$host)) {
227 296
         	//$formats[$id] = 'whazzup';
228 297
         	$globalSources[$id]['format'] = 'whazzup';
229 298
         	//$last_exec['whazzup'] = 0;
230
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
299
+        	if ($globalDebug) {
300
+        		echo "Connect to whazzup source (".$host.")...\n";
301
+        	}
231 302
             } else if (preg_match('/blitzortung/i',$host)) {
232 303
         	$globalSources[$id]['format'] = 'blitzortung';
233
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
304
+        	if ($globalDebug) {
305
+        		echo "Connect to blitzortung source (".$host.")...\n";
306
+        	}
234 307
             } else if (preg_match('/airwhere/i',$host)) {
235 308
         	$globalSources[$id]['format'] = 'airwhere';
236
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
309
+        	if ($globalDebug) {
310
+        		echo "Connect to airwhere source (".$host.")...\n";
311
+        	}
237 312
             } else if (preg_match('/recentpireps/i',$host)) {
238 313
         	//$formats[$id] = 'pirepsjson';
239 314
         	$globalSources[$id]['format'] = 'pirepsjson';
240 315
         	//$last_exec['pirepsjson'] = 0;
241
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
316
+        	if ($globalDebug) {
317
+        		echo "Connect to pirepsjson source (".$host.")...\n";
318
+        	}
242 319
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243 320
         	//$formats[$id] = 'fr24json';
244 321
         	$globalSources[$id]['format'] = 'fr24json';
245 322
         	//$last_exec['fr24json'] = 0;
246
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
323
+        	if ($globalDebug) {
324
+        		echo "Connect to fr24 source (".$host.")...\n";
325
+        	}
247 326
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248 327
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 328
         	    exit(0);
@@ -252,7 +331,9 @@  discard block
 block discarded – undo
252 331
         	//$formats[$id] = 'fr24json';
253 332
         	$globalSources[$id]['format'] = 'myshiptracking';
254 333
         	//$last_exec['fr24json'] = 0;
255
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
334
+        	if ($globalDebug) {
335
+        		echo "Connect to myshiptracking source (".$host.")...\n";
336
+        	}
256 337
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257 338
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258 339
         	    exit(0);
@@ -261,17 +342,26 @@  discard block
 block discarded – undo
261 342
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 343
         	//$formats[$id] = 'tsv';
263 344
         	$globalSources[$id]['format'] = 'tsv';
264
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
345
+        	if ($globalDebug) {
346
+        		echo "Connect to tsv source (".$host.")...\n";
347
+        	}
265 348
             }
266 349
         } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
267 350
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268 351
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
269 352
     		    if ($idf !== false) {
270 353
     			$httpfeeds[$id] = $idf;
271
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
354
+        		if ($globalDebug) {
355
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
356
+        		}
357
+    		    } elseif ($globalDebug) {
358
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
359
+    		    }
360
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') {
361
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
362
+    		} elseif ($globalDebug) {
363
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
364
+    		}
275 365
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276 366
 	    $hostport = explode(':',$host);
277 367
 	    if (isset($hostport[1])) {
@@ -311,19 +401,27 @@  discard block
 block discarded – undo
311 401
         		//$formats[$id] = 'beast';
312 402
         		$globalSources[$id]['format'] = 'beast';
313 403
 		    //} else $formats[$id] = 'sbs';
314
-		    } else $globalSources[$id]['format'] = 'sbs';
404
+		    } else {
405
+		    	$globalSources[$id]['format'] = 'sbs';
406
+		    }
315 407
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
316 408
 		}
317
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
409
+		if ($globalDebug) {
410
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
411
+		}
318 412
             } else {
319
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
413
+		if ($globalDebug) {
414
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
415
+		}
320 416
 		sleep(10);
321 417
 		connect_all($hosts);
322 418
     	    }
323 419
         }
324 420
     }
325 421
 }
326
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
422
+if (!isset($globalMinFetch)) {
423
+	$globalMinFetch = 15;
424
+}
327 425
 
328 426
 // Initialize all
329 427
 $status = array();
@@ -332,13 +430,19 @@  discard block
 block discarded – undo
332 430
 $formats = array();
333 431
 $last_exec = array();
334 432
 $time = time();
335
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
336
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
337
-else $timeout = 20;
433
+if (isset($globalSourcesTimeout)) {
434
+	$timeout = $globalSourcesTimeOut;
435
+} else if (isset($globalSBS1TimeOut)) {
436
+	$timeout = $globalSBS1TimeOut;
437
+} else {
438
+	$timeout = 20;
439
+}
338 440
 $errno = '';
339 441
 $errstr='';
340 442
 
341
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
443
+if (!isset($globalDaemon)) {
444
+	$globalDaemon = TRUE;
445
+}
342 446
 /* Initiate connections to all the hosts simultaneously */
343 447
 //connect_all($hosts);
344 448
 //connect_all($globalSources);
@@ -367,7 +471,9 @@  discard block
 block discarded – undo
367 471
     if (isset($source['format']) && $source['format'] == 'aprs') {
368 472
 	$aprs_connect = 0;
369 473
 	$use_aprs = true;
370
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
474
+	if (isset($source['port']) && $source['port'] == '10152') {
475
+		$aprs_full = true;
476
+	}
371 477
 	break;
372 478
     }
373 479
 }
@@ -378,25 +484,46 @@  discard block
 block discarded – undo
378 484
 	$aprs_connect = 0;
379 485
 	$aprs_keep = 120;
380 486
 	$aprs_last_tx = time();
381
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
382
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
383
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
384
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
385
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
386
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
387
-	if ($aprs_full) $aprs_filter = '';
388
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
389
-	else $aprs_pass = '-1';
487
+	if (isset($globalAPRSversion)) {
488
+		$aprs_version = $globalAPRSversion;
489
+	} else {
490
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
491
+	}
492
+	if (isset($globalAPRSssid)) {
493
+		$aprs_ssid = $globalAPRSssid;
494
+	} else {
495
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
496
+	}
497
+	if (isset($globalAPRSfilter)) {
498
+		$aprs_filter = $globalAPRSfilter;
499
+	} else {
500
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
501
+	}
502
+	if ($aprs_full) {
503
+		$aprs_filter = '';
504
+	}
505
+	if (isset($globalAPRSpass)) {
506
+		$aprs_pass = $globalAPRSpass;
507
+	} else {
508
+		$aprs_pass = '-1';
509
+	}
390 510
 
391
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
392
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
393
-}
511
+	if ($aprs_filter != '') {
512
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
513
+	} else {
514
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
515
+	}
516
+	}
394 517
 
395 518
 // connected - lets do some work
396 519
 //if ($globalDebug) echo "Connected!\n";
397 520
 sleep(1);
398
-if ($globalDebug) echo "SCAN MODE \n\n";
399
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
521
+if ($globalDebug) {
522
+	echo "SCAN MODE \n\n";
523
+}
524
+if (!isset($globalCronEnd)) {
525
+	$globalCronEnd = 60;
526
+}
400 527
 $endtime = time()+$globalCronEnd;
401 528
 $i = 1;
402 529
 $tt = array();
@@ -410,22 +537,32 @@  discard block
 block discarded – undo
410 537
 
411 538
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
412 539
 while ($i > 0) {
413
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
540
+    if (function_exists('pcntl_fork')) {
541
+    	pcntl_signal_dispatch();
542
+    }
414 543
 
415
-    if (!$globalDaemon) $i = $endtime-time();
544
+    if (!$globalDaemon) {
545
+    	$i = $endtime-time();
546
+    }
416 547
     // Delete old ATC
417 548
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
418
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
549
+	if ($globalDebug) {
550
+		echo 'Delete old ATC...'."\n";
551
+	}
419 552
         $ATC->deleteOldATC();
420 553
     }
421 554
     
422 555
     if (count($last_exec) == count($globalSources)) {
423 556
 	$max = $globalMinFetch;
424 557
 	foreach ($last_exec as $last) {
425
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
558
+	    if ((time() - $last['last']) < $max) {
559
+	    	$max = time() - $last['last'];
560
+	    }
426 561
 	}
427 562
 	if ($max < $globalMinFetch) {
428
-	    if ($globalDebug) echo 'Sleeping...'."\n";
563
+	    if ($globalDebug) {
564
+	    	echo 'Sleeping...'."\n";
565
+	    }
429 566
 	    sleep($globalMinFetch-$max+2);
430 567
 	}
431 568
     }
@@ -435,7 +572,9 @@  discard block
 block discarded – undo
435 572
     foreach ($globalSources as $id => $value) {
436 573
 	date_default_timezone_set('UTC');
437 574
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
438
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
575
+	if (!isset($last_exec[$id]['last'])) {
576
+		$last_exec[$id]['last'] = 0;
577
+	}
439 578
 	if ($value['format'] === 'deltadbtxt' && 
440 579
 	    (
441 580
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -444,7 +583,9 @@  discard block
 block discarded – undo
444 583
 	) {
445 584
 	    //$buffer = $Common->getData($hosts[$id]);
446 585
 	    $buffer = $Common->getData($value['host']);
447
-	    if ($buffer != '') $reset = 0;
586
+	    if ($buffer != '') {
587
+	    	$reset = 0;
588
+	    }
448 589
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449 590
 	    $buffer = explode('\n',$buffer);
450 591
 	    foreach ($buffer as $line) {
@@ -453,20 +594,41 @@  discard block
 block discarded – undo
453 594
 	            $data = array();
454 595
 	            $data['hex'] = $line[1]; // hex
455 596
 	            $data['ident'] = $line[2]; // ident
456
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
457
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
458
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
459
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
460
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
597
+	            if (isset($line[3])) {
598
+	            	$data['altitude'] = $line[3];
599
+	            }
600
+	            // altitude
601
+	            if (isset($line[4])) {
602
+	            	$data['speed'] = $line[4];
603
+	            }
604
+	            // speed
605
+	            if (isset($line[5])) {
606
+	            	$data['heading'] = $line[5];
607
+	            }
608
+	            // heading
609
+	            if (isset($line[6])) {
610
+	            	$data['latitude'] = $line[6];
611
+	            }
612
+	            // lat
613
+	            if (isset($line[7])) {
614
+	            	$data['longitude'] = $line[7];
615
+	            }
616
+	            // long
461 617
 	            $data['verticalrate'] = ''; // vertical rate
462 618
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
463 619
 	            $data['emergency'] = ''; // emergency
464 620
 		    $data['datetime'] = date('Y-m-d H:i:s');
465 621
 		    $data['format_source'] = 'deltadbtxt';
466 622
     		    $data['id_source'] = $id_source;
467
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
468
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
469
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
623
+		    if (isset($value['name']) && $value['name'] != '') {
624
+		    	$data['source_name'] = $value['name'];
625
+		    }
626
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
627
+		    	$data['noarchive'] = true;
628
+		    }
629
+		    if (isset($value['sourcestats'])) {
630
+		    	$data['sourcestats'] = $value['sourcestats'];
631
+		    }
470 632
     		    $SI->add($data);
471 633
 		    unset($data);
472 634
     		}
@@ -481,7 +643,9 @@  discard block
 block discarded – undo
481 643
 	    date_default_timezone_set('CET');
482 644
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
483 645
 	    date_default_timezone_set('UTC');
484
-	    if ($buffer != '') $reset = 0;
646
+	    if ($buffer != '') {
647
+	    	$reset = 0;
648
+	    }
485 649
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486 650
 	    $buffer = explode('\n',$buffer);
487 651
 	    foreach ($buffer as $line) {
@@ -490,18 +654,42 @@  discard block
 block discarded – undo
490 654
 		    $add = false;
491 655
 		    $ais_data = $AIS->parse_line(trim($line));
492 656
 		    $data = array();
493
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
495
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
498
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
499
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
500
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
501
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
502
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
503
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
657
+		    if (isset($ais_data['ident'])) {
658
+		    	$data['ident'] = $ais_data['ident'];
659
+		    }
660
+		    if (isset($ais_data['mmsi'])) {
661
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
662
+		    }
663
+		    if (isset($ais_data['speed'])) {
664
+		    	$data['speed'] = $ais_data['speed'];
665
+		    }
666
+		    if (isset($ais_data['heading'])) {
667
+		    	$data['heading'] = $ais_data['heading'];
668
+		    }
669
+		    if (isset($ais_data['latitude'])) {
670
+		    	$data['latitude'] = $ais_data['latitude'];
671
+		    }
672
+		    if (isset($ais_data['longitude'])) {
673
+		    	$data['longitude'] = $ais_data['longitude'];
674
+		    }
675
+		    if (isset($ais_data['status'])) {
676
+		    	$data['status'] = $ais_data['status'];
677
+		    }
678
+		    if (isset($ais_data['statusid'])) {
679
+		    	$data['status_id'] = $ais_data['statusid'];
680
+		    }
681
+		    if (isset($ais_data['type'])) {
682
+		    	$data['type'] = $ais_data['type'];
683
+		    }
684
+		    if (isset($ais_data['typeid'])) {
685
+		    	$data['type_id'] = $ais_data['typeid'];
686
+		    }
687
+		    if (isset($ais_data['imo'])) {
688
+		    	$data['imo'] = $ais_data['imo'];
689
+		    }
690
+		    if (isset($ais_data['callsign'])) {
691
+		    	$data['callsign'] = $ais_data['callsign'];
692
+		    }
505 693
 		    if (isset($ais_data['timestamp'])) {
506 694
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
507 695
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -515,8 +703,12 @@  discard block
 block discarded – undo
515 703
 		    $data['format_source'] = 'aisnmeatxt';
516 704
     		    $data['id_source'] = $id_source;
517 705
 		    //print_r($data);
518
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
519
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
706
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
707
+		    	$data['noarchive'] = true;
708
+		    }
709
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
710
+		    	$MI->add($data);
711
+		    }
520 712
 		    unset($data);
521 713
 		}
522 714
     	    }
@@ -539,20 +731,48 @@  discard block
 block discarded – undo
539 731
 			    if ($line != '') {
540 732
 				$ais_data = $AIS->parse_line(trim($line));
541 733
 				$data = array();
542
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
543
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
544
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
545
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
546
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
547
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
548
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
549
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
550
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
551
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
552
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
553
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
554
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
555
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
734
+				if (isset($ais_data['ident'])) {
735
+					$data['ident'] = $ais_data['ident'];
736
+				}
737
+				if (isset($ais_data['mmsi'])) {
738
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
739
+				}
740
+				if (isset($ais_data['speed'])) {
741
+					$data['speed'] = $ais_data['speed'];
742
+				}
743
+				if (isset($ais_data['heading'])) {
744
+					$data['heading'] = $ais_data['heading'];
745
+				}
746
+				if (isset($ais_data['latitude'])) {
747
+					$data['latitude'] = $ais_data['latitude'];
748
+				}
749
+				if (isset($ais_data['longitude'])) {
750
+					$data['longitude'] = $ais_data['longitude'];
751
+				}
752
+				if (isset($ais_data['status'])) {
753
+					$data['status'] = $ais_data['status'];
754
+				}
755
+				if (isset($ais_data['statusid'])) {
756
+					$data['status_id'] = $ais_data['statusid'];
757
+				}
758
+				if (isset($ais_data['type'])) {
759
+					$data['type'] = $ais_data['type'];
760
+				}
761
+				if (isset($ais_data['typeid'])) {
762
+					$data['type_id'] = $ais_data['typeid'];
763
+				}
764
+				if (isset($ais_data['imo'])) {
765
+					$data['imo'] = $ais_data['imo'];
766
+				}
767
+				if (isset($ais_data['callsign'])) {
768
+					$data['callsign'] = $ais_data['callsign'];
769
+				}
770
+				if (isset($ais_data['destination'])) {
771
+					$data['arrival_code'] = $ais_data['destination'];
772
+				}
773
+				if (isset($ais_data['eta_ts'])) {
774
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
775
+				}
556 776
 				if (isset($ais_data['timestamp'])) {
557 777
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
558 778
 				} else {
@@ -560,18 +780,27 @@  discard block
 block discarded – undo
560 780
 				}
561 781
 				$data['format_source'] = 'aisnmeahttp';
562 782
 				$data['id_source'] = $id_source;
563
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
564
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
783
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
784
+					$data['noarchive'] = true;
785
+				}
786
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
787
+					$MI->add($data);
788
+				}
565 789
 				unset($data);
566 790
 			    }
567 791
 			}
568 792
 		    }
569 793
 		} else {
570 794
 		    $format = $value['format'];
571
-		    if (isset($tt[$format])) $tt[$format]++;
572
-		    else $tt[$format] = 0;
795
+		    if (isset($tt[$format])) {
796
+		    	$tt[$format]++;
797
+		    } else {
798
+		    	$tt[$format] = 0;
799
+		    }
573 800
 		    if ($tt[$format] > 30) {
574
-			if ($globalDebug) echo 'Reconnect...'."\n";
801
+			if ($globalDebug) {
802
+				echo 'Reconnect...'."\n";
803
+			}
575 804
 			sleep(2);
576 805
 			//$sourceeen[] = $value;
577 806
 			//connect_all($sourceeen);
@@ -607,12 +836,18 @@  discard block
 block discarded – undo
607 836
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
608 837
 			    //$data['type_id'] = $line['TYPE'];
609 838
 			    $data['imo'] = $line['IMO'];
610
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
611
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
839
+			    if ($line['DEST'] != '') {
840
+			    	$data['arrival_code'] = $line['DEST'];
841
+			    }
842
+			    if ($line['ARV'] != '') {
843
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
844
+			    }
612 845
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
613 846
 			    $data['format_source'] = 'myshiptracking';
614 847
 			    $data['id_source'] = $id_source;
615
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
848
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
849
+			    	$data['noarchive'] = true;
850
+			    }
616 851
 			    $MI->add($data);
617 852
 			    unset($data);
618 853
 			}
@@ -637,7 +872,9 @@  discard block
 block discarded – undo
637 872
 			    $data['callsign'] = $line['callsign'];
638 873
 			    $data['mmsi'] = substr($line['mmsi'],-9);
639 874
 			    $data['speed'] = $line['sog'];
640
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
875
+			    if ($line['heading'] != '511') {
876
+			    	$data['heading'] = $line['heading'];
877
+			    }
641 878
 			    $data['latitude'] = $line['latitude'];
642 879
 			    $data['longitude'] = $line['longitude'];
643 880
 			    $data['type_id'] = $line['shiptype'];
@@ -645,7 +882,9 @@  discard block
 block discarded – undo
645 882
 			    $data['datetime'] = $line['time'];
646 883
 			    $data['format_source'] = 'boatbeaconapp';
647 884
 			    $data['id_source'] = $id_source;
648
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
885
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
886
+			    	$data['noarchive'] = true;
887
+			    }
649 888
 			    $MI->add($data);
650 889
 			    unset($data);
651 890
 			}
@@ -667,22 +906,44 @@  discard block
 block discarded – undo
667 906
 		    foreach ($all_data['features'] as $line) {
668 907
 			print_r($line);
669 908
 			$data = array();
670
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
671
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
672
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
673
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
674
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
675
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
909
+			if (isset($line['properties']['name'])) {
910
+				$data['ident'] = $line['properties']['name'];
911
+			}
912
+			if (isset($line['properties']['callsign'])) {
913
+				$data['callsign'] = $line['properties']['callsign'];
914
+			}
915
+			if (isset($line['properties']['mmsi'])) {
916
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
917
+			}
918
+			if (isset($line['properties']['imo'])) {
919
+				$data['imo'] = $line['properties']['imo'];
920
+			}
921
+			if (isset($line['properties']['speed'])) {
922
+				$data['speed'] = $line['properties']['speed'];
923
+			}
924
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
925
+				$data['heading'] = $line['properties']['heading'];
926
+			}
676 927
 			$data['latitude'] = $line['geometry']['coordinates'][1];
677 928
 			$data['longitude'] = $line['geometry']['coordinates'][0];
678
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
679
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
680
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
929
+			if (isset($line['properties']['vesselType'])) {
930
+				$data['type'] = $line['properties']['vesselType'];
931
+			}
932
+			if (isset($line['properties']['destination'])) {
933
+				$data['arrival_code'] = $line['properties']['destination'];
934
+			}
935
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
936
+				$data['arrival_date'] = $line['properties']['eta'];
937
+			}
681 938
 			$data['format_source'] = 'boatnerd';
682 939
 			$data['id_source'] = $id_source;
683 940
 			$data['datetime'] = date('Y-m-d H:i:s');
684
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
685
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
941
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
942
+				$data['noarchive'] = true;
943
+			}
944
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
945
+				$MI->add($data);
946
+			}
686 947
 			unset($data);
687 948
 		    }
688 949
 		}
@@ -695,11 +956,17 @@  discard block
 block discarded – undo
695 956
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
696 957
 	    )
697 958
 	) {
698
-	    if ($globalDebug) echo 'download...';
959
+	    if ($globalDebug) {
960
+	    	echo 'download...';
961
+	    }
699 962
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
700
-	    if ($globalDebug) echo 'done !'."\n";
963
+	    if ($globalDebug) {
964
+	    	echo 'done !'."\n";
965
+	    }
701 966
 	    // FIXME: Need more work
702
-	    if ($buffer != '') $reset = 0;
967
+	    if ($buffer != '') {
968
+	    	$reset = 0;
969
+	    }
703 970
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
704 971
 	    $buffer = explode('\n',$buffer);
705 972
 	    foreach ($buffer as $line) {
@@ -725,7 +992,9 @@  discard block
 block discarded – undo
725 992
 		    //$data['etaTime'] = substr($line,135,5);
726 993
 		    $data['format_source'] = 'shipplotter';
727 994
     		    $data['id_source'] = $id_source;
728
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
995
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
996
+		    	$data['noarchive'] = true;
997
+		    }
729 998
 		    //print_r($data);
730 999
 		    //echo 'Add...'."\n";
731 1000
 		    $MI->add($data);
@@ -739,11 +1008,17 @@  discard block
 block discarded – undo
739 1008
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
740 1009
 	    )
741 1010
 	) {
742
-	    if ($globalDebug) echo '! Download... ';
1011
+	    if ($globalDebug) {
1012
+	    	echo '! Download... ';
1013
+	    }
743 1014
 	    for ($i =0; $i <= 1; $i++) {
744
-		    if ($globalDebug) echo 'Racetype: '.$i.' ';
1015
+		    if ($globalDebug) {
1016
+		    	echo 'Racetype: '.$i.' ';
1017
+		    }
745 1018
 	    $buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
746
-	    if ($globalDebug) echo 'done'."\n";
1019
+	    if ($globalDebug) {
1020
+	    	echo 'done'."\n";
1021
+	    }
747 1022
 	    if ($buffer != '') {
748 1023
 		$all_data = json_decode($buffer,true);
749 1024
 		if (isset($all_data['missions'])) {
@@ -752,7 +1027,9 @@  discard block
 block discarded – undo
752 1027
 				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
753 1028
 				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
754 1029
 					$bufferm = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
755
-				} else $bufferm = '';
1030
+				} else {
1031
+					$bufferm = '';
1032
+				}
756 1033
 				if ($bufferm != '') {
757 1034
 					$mission_data = json_decode($bufferm,true);
758 1035
 					if (isset($mission_data['leaderboard'][0]['results'])) {
@@ -790,7 +1067,9 @@  discard block
 block discarded – undo
790 1067
 								$data['captain_id'] = $sail['usrnr'];
791 1068
 								$data['captain_name'] = $sail['usrname'];
792 1069
 								$data['race_id'] = $sail['misnr'];
793
-								if ($sail['rank'] != 'DNF') $data['race_rank'] = $sail['rank'];
1070
+								if ($sail['rank'] != 'DNF') {
1071
+									$data['race_rank'] = $sail['rank'];
1072
+								}
794 1073
 								$data['race_time'] = $sail['racetime'];
795 1074
 								if ($mission_user != '') {
796 1075
 									$data['race_name'] = $mission_name.' ('.$mission_user.')';
@@ -800,7 +1079,9 @@  discard block
 block discarded – undo
800 1079
 								//$data['callsign'] = trim(substr($line,100,7);
801 1080
 								$data['format_source'] = 'sailaway';
802 1081
 								$data['id_source'] = $id_source;
803
-								if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1082
+								if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1083
+									$data['noarchive'] = true;
1084
+								}
804 1085
 								//print_r($data);
805 1086
 								//echo 'Add...'."\n";
806 1087
 								$MI->add($data);
@@ -841,16 +1122,28 @@  discard block
 block discarded – undo
841 1122
     		    $line = explode(':', $line);
842 1123
     		    if (count($line) > 30 && $line[0] != 'callsign') {
843 1124
 			$data = array();
844
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
845
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1125
+			if (isset($line[37]) && $line[37] != '') {
1126
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1127
+			} else {
1128
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1129
+			}
846 1130
 			$data['pilot_id'] = $line[1];
847 1131
 			$data['pilot_name'] = $line[2];
848 1132
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
849 1133
 			$data['ident'] = $line[0]; // ident
850
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1134
+			if ($line[7] != '' && $line[7] != 0) {
1135
+				$data['altitude'] = $line[7];
1136
+			}
1137
+			// altitude
851 1138
 			$data['speed'] = $line[8]; // speed
852
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
853
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1139
+			if (isset($line[45])) {
1140
+				$data['heading'] = $line[45];
1141
+			}
1142
+			// heading
1143
+			elseif (isset($line[38])) {
1144
+				$data['heading'] = $line[38];
1145
+			}
1146
+			// heading
854 1147
 			$data['latitude'] = $line[5]; // lat
855 1148
 	        	$data['longitude'] = $line[6]; // long
856 1149
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -866,7 +1159,9 @@  discard block
 block discarded – undo
866 1159
 			$data['frequency'] = $line[4];
867 1160
 			$data['type'] = $line[18];
868 1161
 			$data['range'] = $line[19];
869
-			if (isset($line[35])) $data['info'] = $line[35];
1162
+			if (isset($line[35])) {
1163
+				$data['info'] = $line[35];
1164
+			}
870 1165
     			$data['id_source'] = $id_source;
871 1166
 	    		//$data['arrival_airport_time'] = ;
872 1167
 	    		if ($line[9] != '') {
@@ -880,27 +1175,47 @@  discard block
 block discarded – undo
880 1175
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
881 1176
 	    		*/
882 1177
 	    		$data['format_source'] = $value['format'];
883
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
884
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
885
-    			if ($line[3] === 'PILOT') $SI->add($data);
886
-			elseif ($line[3] === 'ATC') {
1178
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1179
+				$data['noarchive'] = true;
1180
+			}
1181
+			if (isset($value['name']) && $value['name'] != '') {
1182
+				$data['source_name'] = $value['name'];
1183
+			}
1184
+    			if ($line[3] === 'PILOT') {
1185
+    				$SI->add($data);
1186
+    			} elseif ($line[3] === 'ATC') {
887 1187
 				//print_r($data);
888 1188
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
889 1189
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
890 1190
 				$typec = substr($data['ident'],-3);
891
-				if ($typec === 'APP') $data['type'] = 'Approach';
892
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
893
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
894
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
895
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
896
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
897
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
898
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
899
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
900
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1191
+				if ($typec === 'APP') {
1192
+					$data['type'] = 'Approach';
1193
+				} elseif ($typec === 'TWR') {
1194
+					$data['type'] = 'Tower';
1195
+				} elseif ($typec === 'OBS') {
1196
+					$data['type'] = 'Observer';
1197
+				} elseif ($typec === 'GND') {
1198
+					$data['type'] = 'Ground';
1199
+				} elseif ($typec === 'DEL') {
1200
+					$data['type'] = 'Delivery';
1201
+				} elseif ($typec === 'DEP') {
1202
+					$data['type'] = 'Departure';
1203
+				} elseif ($typec === 'FSS') {
1204
+					$data['type'] = 'Flight Service Station';
1205
+				} elseif ($typec === 'CTR') {
1206
+					$data['type'] = 'Control Radar or Centre';
1207
+				} elseif ($data['type'] === '') {
1208
+					$data['type'] = 'Observer';
1209
+				}
1210
+				if (!isset($data['source_name'])) {
1211
+					$data['source_name'] = '';
1212
+				}
901 1213
 				if (isset($ATC)) {
902
-					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']);
903
-					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']);
1214
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1215
+						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']);
1216
+					} else {
1217
+						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']);
1218
+					}
904 1219
 				}
905 1220
 			}
906 1221
     			unset($data);
@@ -927,14 +1242,20 @@  discard block
 block discarded – undo
927 1242
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
928 1243
 			$data['latitude'] = (float)$line['pktLatitude'];
929 1244
 			$data['longitude'] = (float)$line['pktLongitude'];
930
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
931
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1245
+			if ((float)$line['pktTrack'] != 0) {
1246
+				$data['heading'] = (float)$line['pktTrack'];
1247
+			}
1248
+			if ((int)$line['pktSpeed'] != 0) {
1249
+				$data['speed'] = (int)$line['pktSpeed'];
1250
+			}
932 1251
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
933 1252
 			$data['altitude_relative'] = 'AMSL';
934 1253
 			$data['pilot_id'] = (int)$line['pktPilotID'];
935 1254
 			$data['aircraft_icao'] = 'PARAGLIDER';
936 1255
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
937
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1256
+			if (isset($pilot_data[4])) {
1257
+				$data['pilot_name'] = $pilot_data[4];
1258
+			}
938 1259
 			$data['format_source'] = $value['format'];
939 1260
 			$SI->add($data);
940 1261
 			unset($data);
@@ -982,25 +1303,59 @@  discard block
 block discarded – undo
982 1303
 		    foreach ($all_data['acList'] as $line) {
983 1304
 			$data = array();
984 1305
 			$data['hex'] = $line['Icao']; // hex
985
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
986
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
987
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
988
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
989
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
990
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1306
+			if (isset($line['Call'])) {
1307
+				$data['ident'] = $line['Call'];
1308
+			}
1309
+			// ident
1310
+			if (isset($line['Alt'])) {
1311
+				$data['altitude'] = $line['Alt'];
1312
+			}
1313
+			// altitude
1314
+			if (isset($line['Spd'])) {
1315
+				$data['speed'] = $line['Spd'];
1316
+			}
1317
+			// speed
1318
+			if (isset($line['Trak'])) {
1319
+				$data['heading'] = $line['Trak'];
1320
+			}
1321
+			// heading
1322
+			if (isset($line['Lat'])) {
1323
+				$data['latitude'] = $line['Lat'];
1324
+			}
1325
+			// lat
1326
+			if (isset($line['Long'])) {
1327
+				$data['longitude'] = $line['Long'];
1328
+			}
1329
+			// long
991 1330
 			//$data['verticalrate'] = $line['']; // verticale rate
992
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1331
+			if (isset($line['Sqk'])) {
1332
+				$data['squawk'] = $line['Sqk'];
1333
+			}
1334
+			// squawk
993 1335
 			$data['emergency'] = ''; // emergency
994
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
995
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
996
-			else $data['datetime'] = date('Y-m-d H:i:s');
1336
+			if (isset($line['Reg'])) {
1337
+				$data['registration'] = $line['Reg'];
1338
+			}
1339
+			if (isset($line['PosTime'])) {
1340
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1341
+			} else {
1342
+				$data['datetime'] = date('Y-m-d H:i:s');
1343
+			}
997 1344
 			//$data['datetime'] = date('Y-m-d H:i:s');
998
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1345
+			if (isset($line['Type'])) {
1346
+				$data['aircraft_icao'] = $line['Type'];
1347
+			}
999 1348
 			$data['format_source'] = 'aircraftlistjson';
1000 1349
 			$data['id_source'] = $id_source;
1001
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1002
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1003
-			if (isset($data['latitude'])) $SI->add($data);
1350
+			if (isset($value['name']) && $value['name'] != '') {
1351
+				$data['source_name'] = $value['name'];
1352
+			}
1353
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1354
+				$data['noarchive'] = true;
1355
+			}
1356
+			if (isset($data['latitude'])) {
1357
+				$SI->add($data);
1358
+			}
1004 1359
 			unset($data);
1005 1360
 		    }
1006 1361
 		} elseif (is_array($all_data)) {
@@ -1017,17 +1372,26 @@  discard block
 block discarded – undo
1017 1372
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1018 1373
 			$data['squawk'] = $line['squawk']; // squawk
1019 1374
 			$data['emergency'] = ''; // emergency
1020
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1021
-			else $data['datetime'] = date('Y-m-d H:i:s');
1375
+			if (isset($line['PosTime'])) {
1376
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1377
+			} else {
1378
+				$data['datetime'] = date('Y-m-d H:i:s');
1379
+			}
1022 1380
 			$data['format_source'] = 'aircraftlistjson';
1023 1381
 			$data['id_source'] = $id_source;
1024
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1025
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1382
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1383
+				$data['noarchive'] = true;
1384
+			}
1385
+			if (isset($value['name']) && $value['name'] != '') {
1386
+				$data['source_name'] = $value['name'];
1387
+			}
1026 1388
 			$SI->add($data);
1027 1389
 			unset($data);
1028 1390
 		    }
1029 1391
 		}
1030
-	    } elseif ($globalDebug) echo 'No data'."\n";
1392
+	    } elseif ($globalDebug) {
1393
+	    	echo 'No data'."\n";
1394
+	    }
1031 1395
     	    //$last_exec['aircraftlistjson'] = time();
1032 1396
     	    $last_exec[$id]['last'] = time();
1033 1397
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -1063,8 +1427,12 @@  discard block
 block discarded – undo
1063 1427
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1064 1428
 	    	    $data['format_source'] = 'planeupdatefaa';
1065 1429
     		    $data['id_source'] = $id_source;
1066
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1067
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1430
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1431
+		    	$data['noarchive'] = true;
1432
+		    }
1433
+		    if (isset($value['name']) && $value['name'] != '') {
1434
+		    	$data['source_name'] = $value['name'];
1435
+		    }
1068 1436
 		    $SI->add($data);
1069 1437
 		    unset($data);
1070 1438
 		}
@@ -1098,7 +1466,9 @@  discard block
 block discarded – undo
1098 1466
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1099 1467
 		    $data['format_source'] = 'opensky';
1100 1468
 		    $data['id_source'] = $id_source;
1101
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1469
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1470
+		    	$data['noarchive'] = true;
1471
+		    }
1102 1472
 		    $SI->add($data);
1103 1473
 		    unset($data);
1104 1474
 		}
@@ -1118,15 +1488,42 @@  discard block
 block discarded – undo
1118 1488
 		foreach ($all_data['aircraft'] as $key => $line) {
1119 1489
 		    $data = array();
1120 1490
 		    // add support for ground vehicule with ~ in front of hex
1121
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1122
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1123
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1124
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1125
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1126
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1127
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1128
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1129
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1491
+		    if (isset($line['hex'])) {
1492
+		    	$data['hex'] = $line['hex'];
1493
+		    }
1494
+		    // hex
1495
+		    if (isset($line['flight'])) {
1496
+		    	$data['ident'] = trim($line['flight']);
1497
+		    }
1498
+		    // ident
1499
+		    if (isset($line['altitude'])) {
1500
+		    	$data['altitude'] = $line['altitude'];
1501
+		    }
1502
+		    // altitude
1503
+		    if (isset($line['speed'])) {
1504
+		    	$data['speed'] = $line['speed'];
1505
+		    }
1506
+		    // speed
1507
+		    if (isset($line['track'])) {
1508
+		    	$data['heading'] = $line['track'];
1509
+		    }
1510
+		    // heading
1511
+		    if (isset($line['lat'])) {
1512
+		    	$data['latitude'] = $line['lat'];
1513
+		    }
1514
+		    // lat
1515
+		    if (isset($line['lon'])) {
1516
+		    	$data['longitude'] = $line['lon'];
1517
+		    }
1518
+		    // long
1519
+		    if (isset($line['vert_rate'])) {
1520
+		    	$data['verticalrate'] = $line['vert_rate'];
1521
+		    }
1522
+		    // verticale rate
1523
+		    if (isset($line['squawk'])) {
1524
+		    	$data['squawk'] = $line['squawk'];
1525
+		    }
1526
+		    // squawk
1130 1527
 		    //$data['emergency'] = ''; // emergency
1131 1528
 		    //$data['registration'] = $line[2];
1132 1529
 		    //$data['aircraft_icao'] = $line[0];
@@ -1134,10 +1531,17 @@  discard block
 block discarded – undo
1134 1531
 		    $data['format_source'] = 'aircraftjson';
1135 1532
 		    $data['id_source'] = $id_source;
1136 1533
 		    if (isset($value['name']) && $value['name'] != '') {
1137
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1138
-			    else $data['source_name'] = $value['name'];
1139
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1140
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1534
+			    if (isset($line['mlat']) && !empty($line['mlat'])) {
1535
+			    	$data['source_name'] = $value['name'].'_MLAT';
1536
+			    } else {
1537
+			    	$data['source_name'] = $value['name'];
1538
+			    }
1539
+		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) {
1540
+		    	$data['source_name'] = 'MLAT';
1541
+		    }
1542
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1543
+		    	$data['noarchive'] = true;
1544
+		    }
1141 1545
 		    $SI->add($data);
1142 1546
 		    unset($data);
1143 1547
 		}
@@ -1157,22 +1561,54 @@  discard block
 block discarded – undo
1157 1561
 		foreach ($all_data['aircraft'] as $key => $line) {
1158 1562
 		    $data = array();
1159 1563
 		    $data['hex'] = $key; // hex
1160
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1161
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1162
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1163
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1164
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1165
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1166
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1167
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1564
+		    if (isset($line['callsign'])) {
1565
+		    	$data['ident'] = trim($line['callsign']);
1566
+		    }
1567
+		    // ident
1568
+		    if (isset($line['altitude'])) {
1569
+		    	$data['altitude'] = $line['altitude'];
1570
+		    }
1571
+		    // altitude
1572
+		    if (isset($line['speed'])) {
1573
+		    	$data['speed'] = $line['speed'];
1574
+		    }
1575
+		    // speed
1576
+		    if (isset($line['heading'])) {
1577
+		    	$data['heading'] = $line['heading'];
1578
+		    }
1579
+		    // heading
1580
+		    if (isset($line['lat'])) {
1581
+		    	$data['latitude'] = $line['lat'];
1582
+		    }
1583
+		    // lat
1584
+		    if (isset($line['lon'])) {
1585
+		    	$data['longitude'] = $line['lon'];
1586
+		    }
1587
+		    // long
1588
+		    if (isset($line['vert_rate'])) {
1589
+		    	$data['verticalrate'] = $line['vert_rate'];
1590
+		    }
1591
+		    // verticale rate
1592
+		    if (isset($line['squawk'])) {
1593
+		    	$data['squawk'] = $line['squawk'];
1594
+		    }
1595
+		    // squawk
1168 1596
 		    //$data['emergency'] = ''; // emergency
1169
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1170
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1597
+		    if (isset($line['reg'])) {
1598
+		    	$data['registration'] = $line['reg'];
1599
+		    }
1600
+		    if (isset($line['type'])) {
1601
+		    	$data['aircraft_icao'] = $line['type'];
1602
+		    }
1171 1603
 		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1172 1604
 		    $data['format_source'] = 'planefinderclient';
1173 1605
 		    $data['id_source'] = $id_source;
1174
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1175
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1606
+		    if (isset($value['name']) && $value['name'] != '') {
1607
+		    	$data['source_name'] = $value['name'];
1608
+		    }
1609
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1610
+		    	$data['noarchive'] = true;
1611
+		    }
1176 1612
 		    $SI->add($data);
1177 1613
 		    unset($data);
1178 1614
 		}
@@ -1188,7 +1624,9 @@  discard block
 block discarded – undo
1188 1624
 	    //$buffer = $Common->getData($hosts[$id]);
1189 1625
 	    $buffer = $Common->getData($value['host']);
1190 1626
 	    $all_data = json_decode($buffer,true);
1191
-	    if (!empty($all_data)) $reset = 0;
1627
+	    if (!empty($all_data)) {
1628
+	    	$reset = 0;
1629
+	    }
1192 1630
 	    foreach ($all_data as $key => $line) {
1193 1631
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1194 1632
 		    $data = array();
@@ -1209,8 +1647,12 @@  discard block
 block discarded – undo
1209 1647
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1210 1648
 	    	    $data['format_source'] = 'fr24json';
1211 1649
     		    $data['id_source'] = $id_source;
1212
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1213
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1650
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1651
+		    	$data['noarchive'] = true;
1652
+		    }
1653
+		    if (isset($value['name']) && $value['name'] != '') {
1654
+		    	$data['source_name'] = $value['name'];
1655
+		    }
1214 1656
 		    $SI->add($data);
1215 1657
 		    unset($data);
1216 1658
 		}
@@ -1239,24 +1681,42 @@  discard block
 block discarded – undo
1239 1681
 		    if (isset($line['inf'])) {
1240 1682
 			$data = array();
1241 1683
 			$data['hex'] = $line['inf']['ia'];
1242
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1684
+			if (isset($line['inf']['cs'])) {
1685
+				$data['ident'] = $line['inf']['cs'];
1686
+			}
1687
+			//$line[13]
1243 1688
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1244
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1245
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1689
+	    		if (isset($line['inf']['gs'])) {
1690
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1691
+	    		}
1692
+	    		// speed
1693
+	    		if (isset($line['inf']['tr'])) {
1694
+	    			$data['heading'] = $line['inf']['tr'];
1695
+	    		}
1696
+	    		// heading
1246 1697
 	    		$data['latitude'] = $line['pt'][0]; // lat
1247 1698
 	    		$data['longitude'] = $line['pt'][1]; // long
1248 1699
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1249
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1700
+	    		if (isset($line['inf']['sq'])) {
1701
+	    			$data['squawk'] = $line['inf']['sq'];
1702
+	    		}
1703
+	    		// squawk
1250 1704
 	    		//$data['aircraft_icao'] = $line[8];
1251
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1705
+	    		if (isset($line['inf']['rc'])) {
1706
+	    			$data['registration'] = $line['inf']['rc'];
1707
+	    		}
1252 1708
 			//$data['departure_airport_iata'] = $line[11];
1253 1709
 			//$data['arrival_airport_iata'] = $line[12];
1254 1710
 	    		//$data['emergency'] = ''; // emergency
1255 1711
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1256 1712
 	    		$data['format_source'] = 'radarvirtueljson';
1257 1713
     			$data['id_source'] = $id_source;
1258
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1259
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1714
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1715
+				$data['noarchive'] = true;
1716
+			}
1717
+			if (isset($value['name']) && $value['name'] != '') {
1718
+				$data['source_name'] = $value['name'];
1719
+			}
1260 1720
 			$SI->add($data);
1261 1721
 			unset($data);
1262 1722
 		    }
@@ -1282,30 +1742,65 @@  discard block
 block discarded – undo
1282 1742
 		    $data['id'] = $line['id'];
1283 1743
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1284 1744
 		    $data['ident'] = $line['callsign']; // ident
1285
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1286
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1287
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1288
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1289
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1290
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1745
+		    if (isset($line['pilotid'])) {
1746
+		    	$data['pilot_id'] = $line['pilotid'];
1747
+		    }
1748
+		    // pilot id
1749
+		    if (isset($line['name'])) {
1750
+		    	$data['pilot_name'] = $line['name'];
1751
+		    }
1752
+		    // pilot name
1753
+		    if (isset($line['alt'])) {
1754
+		    	$data['altitude'] = $line['alt'];
1755
+		    }
1756
+		    // altitude
1757
+		    if (isset($line['gs'])) {
1758
+		    	$data['speed'] = $line['gs'];
1759
+		    }
1760
+		    // speed
1761
+		    if (isset($line['heading'])) {
1762
+		    	$data['heading'] = $line['heading'];
1763
+		    }
1764
+		    // heading
1765
+		    if (isset($line['route'])) {
1766
+		    	$data['waypoints'] = $line['route'];
1767
+		    }
1768
+		    // route
1291 1769
 		    $data['latitude'] = $line['lat']; // lat
1292 1770
 		    $data['longitude'] = $line['lon']; // long
1293 1771
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1294 1772
 		    //$data['squawk'] = $line['squawk']; // squawk
1295 1773
 		    //$data['emergency'] = ''; // emergency
1296
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1297
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1298
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1774
+		    if (isset($line['depicao'])) {
1775
+		    	$data['departure_airport_icao'] = $line['depicao'];
1776
+		    }
1777
+		    if (isset($line['deptime'])) {
1778
+		    	$data['departure_airport_time'] = $line['deptime'];
1779
+		    }
1780
+		    if (isset($line['arricao'])) {
1781
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1782
+		    }
1299 1783
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1300
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1301
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1302
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1303
-		    else $data['info'] = '';
1784
+		    if (isset($line['aircraft'])) {
1785
+		    	$data['aircraft_icao'] = $line['aircraft'];
1786
+		    }
1787
+		    if (isset($line['transponder'])) {
1788
+		    	$data['squawk'] = $line['transponder'];
1789
+		    }
1790
+		    if (isset($line['atis'])) {
1791
+		    	$data['info'] = $line['atis'];
1792
+		    } else {
1793
+		    	$data['info'] = '';
1794
+		    }
1304 1795
 		    $data['format_source'] = 'pireps';
1305 1796
     		    $data['id_source'] = $id_source;
1306 1797
 		    $data['datetime'] = date('Y-m-d H:i:s');
1307
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1308
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1798
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1799
+		    	$data['noarchive'] = true;
1800
+		    }
1801
+		    if (isset($value['name']) && $value['name'] != '') {
1802
+		    	$data['source_name'] = $value['name'];
1803
+		    }
1309 1804
 		    if ($line['icon'] === 'plane') {
1310 1805
 			$SI->add($data);
1311 1806
 		    //    print_r($data);
@@ -1314,16 +1809,28 @@  discard block
 block discarded – undo
1314 1809
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1315 1810
 			$typec = substr($data['ident'],-3);
1316 1811
 			$data['type'] = '';
1317
-			if ($typec === 'APP') $data['type'] = 'Approach';
1318
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1319
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1320
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1321
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1322
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1323
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1324
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1325
-			else $data['type'] = 'Observer';
1326
-			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']);
1812
+			if ($typec === 'APP') {
1813
+				$data['type'] = 'Approach';
1814
+			} elseif ($typec === 'TWR') {
1815
+				$data['type'] = 'Tower';
1816
+			} elseif ($typec === 'OBS') {
1817
+				$data['type'] = 'Observer';
1818
+			} elseif ($typec === 'GND') {
1819
+				$data['type'] = 'Ground';
1820
+			} elseif ($typec === 'DEL') {
1821
+				$data['type'] = 'Delivery';
1822
+			} elseif ($typec === 'DEP') {
1823
+				$data['type'] = 'Departure';
1824
+			} elseif ($typec === 'FSS') {
1825
+				$data['type'] = 'Flight Service Station';
1826
+			} elseif ($typec === 'CTR') {
1827
+				$data['type'] = 'Control Radar or Centre';
1828
+			} else {
1829
+				$data['type'] = 'Observer';
1830
+			}
1831
+			if (isset($ATC)) {
1832
+				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']);
1833
+			}
1327 1834
 		    }
1328 1835
 		    unset($data);
1329 1836
 		}
@@ -1338,7 +1845,9 @@  discard block
 block discarded – undo
1338 1845
 	    )
1339 1846
 	) {
1340 1847
 	    //$buffer = $Common->getData($hosts[$id]);
1341
-	    if ($globalDebug) echo 'Get Data...'."\n";
1848
+	    if ($globalDebug) {
1849
+	    	echo 'Get Data...'."\n";
1850
+	    }
1342 1851
 	    $buffer = $Common->getData($value['host']);
1343 1852
 	    $all_data = json_decode($buffer,true);
1344 1853
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1346,10 +1855,16 @@  discard block
 block discarded – undo
1346 1855
 		foreach ($all_data as $line) {
1347 1856
 	    	    $data = array();
1348 1857
 	    	    //$data['id'] = $line['id']; // id not usable
1349
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1858
+	    	    if (isset($line['pilotid'])) {
1859
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1860
+	    	    }
1350 1861
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1351
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1352
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1862
+	    	    if (isset($line['pilotname'])) {
1863
+	    	    	$data['pilot_name'] = $line['pilotname'];
1864
+	    	    }
1865
+	    	    if (isset($line['pilotid'])) {
1866
+	    	    	$data['pilot_id'] = $line['pilotid'];
1867
+	    	    }
1353 1868
 	    	    $data['ident'] = $line['flightnum']; // ident
1354 1869
 	    	    $data['altitude'] = $line['alt']; // altitude
1355 1870
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1365,7 +1880,9 @@  discard block
 block discarded – undo
1365 1880
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1366 1881
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1367 1882
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1368
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1883
+	    	    } else {
1884
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1885
+	    	    }
1369 1886
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1370 1887
 	    	    $data['departure_airport_time'] = $line['deptime'];
1371 1888
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1373,29 +1890,47 @@  discard block
 block discarded – undo
1373 1890
     		    if (isset($line['registration'])) {
1374 1891
     			$data['registration'] = $line['registration'];
1375 1892
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1376
-    		    } else $data['registration'] = $line['aircraft'];
1377
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1378
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1893
+    		    } else {
1894
+    		    	$data['registration'] = $line['aircraft'];
1895
+    		    }
1896
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1897
+		    	$data['noarchive'] = true;
1898
+		    }
1899
+		    if (isset($line['route'])) {
1900
+		    	$data['waypoints'] = $line['route'];
1901
+		    }
1902
+		    // route
1379 1903
 		    if (isset($line['aircraftname'])) {
1380 1904
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1381 1905
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1382 1906
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1383
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1384
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1385
-	    		else {
1907
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1908
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1909
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1910
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1911
+	    		} else {
1386 1912
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1387
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1388
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1913
+	    		    if (isset($aircraft_data[1])) {
1914
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1915
+	    		    } else {
1916
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1917
+	    		    }
1389 1918
 	    		}
1390 1919
 	    	    }
1391
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1920
+    		    if (isset($line['route'])) {
1921
+    		    	$data['waypoints'] = $line['route'];
1922
+    		    }
1392 1923
     		    $data['id_source'] = $id_source;
1393 1924
 	    	    $data['format_source'] = 'phpvmacars';
1394
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1925
+		    if (isset($value['name']) && $value['name'] != '') {
1926
+		    	$data['source_name'] = $value['name'];
1927
+		    }
1395 1928
 		    $SI->add($data);
1396 1929
 		    unset($data);
1397 1930
 		}
1398
-		if ($globalDebug) echo 'No more data...'."\n";
1931
+		if ($globalDebug) {
1932
+			echo 'No more data...'."\n";
1933
+		}
1399 1934
 		unset($buffer);
1400 1935
 		unset($all_data);
1401 1936
 	    }
@@ -1408,7 +1943,9 @@  discard block
 block discarded – undo
1408 1943
 	    )
1409 1944
 	) {
1410 1945
 	    //$buffer = $Common->getData($hosts[$id]);
1411
-	    if ($globalDebug) echo 'Get Data...'."\n";
1946
+	    if ($globalDebug) {
1947
+	    	echo 'Get Data...'."\n";
1948
+	    }
1412 1949
 	    $buffer = $Common->getData($value['host']);
1413 1950
 	    $all_data = json_decode($buffer,true);
1414 1951
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1419,10 +1956,16 @@  discard block
 block discarded – undo
1419 1956
 	    	    //$data['id'] = $line['id']; // id not usable
1420 1957
 	    	    $data['id'] = $line['id'];
1421 1958
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1422
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1423
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1959
+	    	    if (isset($line['user']['username'])) {
1960
+	    	    	$data['pilot_name'] = $line['user']['username'];
1961
+	    	    }
1962
+	    	    if (isset($line['user_id'])) {
1963
+	    	    	$data['pilot_id'] = $line['user_id'];
1964
+	    	    }
1424 1965
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1425
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1966
+	    	    if (is_numeric($data['ident'])) {
1967
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1968
+	    	    }
1426 1969
 	    	    $data['altitude'] = $line['altitude']; // altitude
1427 1970
 	    	    $data['speed'] = $line['groundspeed']; // speed
1428 1971
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1435,7 +1978,9 @@  discard block
 block discarded – undo
1435 1978
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1436 1979
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1437 1980
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1438
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1981
+	    	    } else {
1982
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1983
+	    	    }
1439 1984
 	    	    
1440 1985
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1441 1986
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1443,17 +1988,26 @@  discard block
 block discarded – undo
1443 1988
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1444 1989
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1445 1990
 
1446
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1447
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1991
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1992
+		    	$data['noarchive'] = true;
1993
+		    }
1994
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
1995
+		    	$data['waypoints'] = $line['bid']['route'];
1996
+		    }
1997
+		    // route
1448 1998
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1449 1999
 
1450 2000
     		    $data['id_source'] = $id_source;
1451 2001
 	    	    $data['format_source'] = 'vaos';
1452
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2002
+		    if (isset($value['name']) && $value['name'] != '') {
2003
+		    	$data['source_name'] = $value['name'];
2004
+		    }
1453 2005
 		    $SI->add($data);
1454 2006
 		    unset($data);
1455 2007
 		}
1456
-		if ($globalDebug) echo 'No more data...'."\n";
2008
+		if ($globalDebug) {
2009
+			echo 'No more data...'."\n";
2010
+		}
1457 2011
 		unset($buffer);
1458 2012
 		unset($all_data);
1459 2013
 	    }
@@ -1466,7 +2020,9 @@  discard block
 block discarded – undo
1466 2020
 	    )
1467 2021
 	) {
1468 2022
 	    //$buffer = $Common->getData($hosts[$id]);
1469
-	    if ($globalDebug) echo 'Get Data...'."\n";
2023
+	    if ($globalDebug) {
2024
+	    	echo 'Get Data...'."\n";
2025
+	    }
1470 2026
 	    $buffer = $Common->getData($value['host']);
1471 2027
 	    $all_data = json_decode($buffer,true);
1472 2028
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1495,16 +2051,25 @@  discard block
 block discarded – undo
1495 2051
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1496 2052
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1497 2053
     		    //$data['registration'] = $line['aircraft'];
1498
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2054
+		    if (isset($line['route'])) {
2055
+		    	$data['waypoints'] = $line['route'];
2056
+		    }
2057
+		    // route
1499 2058
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1500 2059
     		    $data['id_source'] = $id_source;
1501 2060
 	    	    $data['format_source'] = 'vam';
1502
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1503
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2061
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2062
+		    	$data['noarchive'] = true;
2063
+		    }
2064
+		    if (isset($value['name']) && $value['name'] != '') {
2065
+		    	$data['source_name'] = $value['name'];
2066
+		    }
1504 2067
 		    $SI->add($data);
1505 2068
 		    unset($data);
1506 2069
 		}
1507
-		if ($globalDebug) echo 'No more data...'."\n";
2070
+		if ($globalDebug) {
2071
+			echo 'No more data...'."\n";
2072
+		}
1508 2073
 		unset($buffer);
1509 2074
 		unset($all_data);
1510 2075
 	    }
@@ -1517,7 +2082,9 @@  discard block
 block discarded – undo
1517 2082
 	    )
1518 2083
 	) {
1519 2084
 	    //$buffer = $Common->getData($hosts[$id]);
1520
-	    if ($globalDebug) echo 'Get Data...'."\n";
2085
+	    if ($globalDebug) {
2086
+	    	echo 'Get Data...'."\n";
2087
+	    }
1521 2088
 	    $buffer = $Common->getData($value['host']);
1522 2089
 	    $all_data = json_decode($buffer,true);
1523 2090
 	    if ($buffer != '') {
@@ -1535,12 +2102,16 @@  discard block
 block discarded – undo
1535 2102
 			$data['id_source'] = $id_source;
1536 2103
 			$data['format_source'] = 'blitzortung';
1537 2104
 			$SI->add($data);
1538
-			if ($globalDebug) echo '☈ Lightning added'."\n";
2105
+			if ($globalDebug) {
2106
+				echo '☈ Lightning added'."\n";
2107
+			}
1539 2108
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1540 2109
 			unset($data);
1541 2110
 		    }
1542 2111
 		}
1543
-		if ($globalDebug) echo 'No more data...'."\n";
2112
+		if ($globalDebug) {
2113
+			echo 'No more data...'."\n";
2114
+		}
1544 2115
 		unset($buffer);
1545 2116
 	    }
1546 2117
 	    $last_exec[$id]['last'] = time();
@@ -1552,7 +2123,9 @@  discard block
 block discarded – undo
1552 2123
 	    $write = NULL;
1553 2124
 	    $e = NULL;
1554 2125
 	    $n = socket_select($read, $write, $e, $timeout);
1555
-	    if ($e != NULL) var_dump($e);
2126
+	    if ($e != NULL) {
2127
+	    	var_dump($e);
2128
+	    }
1556 2129
 	    if ($n > 0) {
1557 2130
 		$reset = 0;
1558 2131
 		foreach ($read as $nb => $r) {
@@ -1574,13 +2147,17 @@  discard block
 block discarded – undo
1574 2147
 		    if ($buffer !== FALSE) {
1575 2148
 			if ($format === 'vrstcp') {
1576 2149
 			    $buffer = explode('},{',$buffer);
1577
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2150
+			} else {
2151
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2152
+			}
1578 2153
 		    }
1579 2154
 		    // SBS format is CSV format
1580 2155
 		    if ($buffer !== FALSE && $buffer !== '') {
1581 2156
 			$tt[$format] = 0;
1582 2157
 			if ($format === 'acarssbs3') {
1583
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2158
+			    if ($globalDebug) {
2159
+			    	echo 'ACARS : '.$buffer."\n";
2160
+			    }
1584 2161
 			    $ACARS->add(trim($buffer));
1585 2162
 			    $ACARS->deleteLiveAcarsData();
1586 2163
 			} elseif ($format === 'raw') {
@@ -1589,30 +2166,70 @@  discard block
 block discarded – undo
1589 2166
 			    if (is_array($data)) {
1590 2167
 				$data['datetime'] = date('Y-m-d H:i:s');
1591 2168
 				$data['format_source'] = 'raw';
1592
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1593
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1594
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1595
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2169
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2170
+					$data['source_name'] = $globalSources[$nb]['name'];
2171
+				}
2172
+				if (isset($globalSources[$nb]['sourcestats'])) {
2173
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2174
+				}
2175
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2176
+					$data['noarchive'] = true;
2177
+				}
2178
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2179
+					$SI->add($data);
2180
+				}
1596 2181
 			    }
1597 2182
 			} elseif ($format === 'ais') {
1598 2183
 			    $ais_data = $AIS->parse_line(trim($buffer));
1599 2184
 			    $data = array();
1600
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1601
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1602
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1603
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1604
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1605
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1606
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1607
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1608
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1609
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1610
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1611
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1612
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1613
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1614
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1615
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2185
+			    if (isset($ais_data['ident'])) {
2186
+			    	$data['ident'] = $ais_data['ident'];
2187
+			    }
2188
+			    if (isset($ais_data['mmsi'])) {
2189
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2190
+			    }
2191
+			    if (isset($ais_data['speed'])) {
2192
+			    	$data['speed'] = $ais_data['speed'];
2193
+			    }
2194
+			    if (isset($ais_data['heading'])) {
2195
+			    	$data['heading'] = $ais_data['heading'];
2196
+			    }
2197
+			    if (isset($ais_data['latitude'])) {
2198
+			    	$data['latitude'] = $ais_data['latitude'];
2199
+			    }
2200
+			    if (isset($ais_data['longitude'])) {
2201
+			    	$data['longitude'] = $ais_data['longitude'];
2202
+			    }
2203
+			    if (isset($ais_data['status'])) {
2204
+			    	$data['status'] = $ais_data['status'];
2205
+			    }
2206
+			    if (isset($ais_data['statusid'])) {
2207
+			    	$data['status_id'] = $ais_data['statusid'];
2208
+			    }
2209
+			    if (isset($ais_data['type'])) {
2210
+			    	$data['type'] = $ais_data['type'];
2211
+			    }
2212
+			    if (isset($ais_data['imo'])) {
2213
+			    	$data['imo'] = $ais_data['imo'];
2214
+			    }
2215
+			    if (isset($ais_data['callsign'])) {
2216
+			    	$data['callsign'] = $ais_data['callsign'];
2217
+			    }
2218
+			    if (isset($ais_data['destination'])) {
2219
+			    	$data['arrival_code'] = $ais_data['destination'];
2220
+			    }
2221
+			    if (isset($ais_data['eta_ts'])) {
2222
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2223
+			    }
2224
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2225
+			    	$data['noarchive'] = true;
2226
+			    }
2227
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2228
+			    	$data['source_name'] = $globalSources[$nb]['name'];
2229
+			    }
2230
+			    if (isset($globalSources[$nb]['sourcestats'])) {
2231
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2232
+			    }
1616 2233
 
1617 2234
 			    if (isset($ais_data['timestamp'])) {
1618 2235
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1621,7 +2238,9 @@  discard block
 block discarded – undo
1621 2238
 			    }
1622 2239
 			    $data['format_source'] = 'aisnmea';
1623 2240
     			    $data['id_source'] = $id_source;
1624
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2241
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2242
+			    	$MI->add($data);
2243
+			    }
1625 2244
 			    unset($data);
1626 2245
                         } elseif ($format === 'flightgearsp') {
1627 2246
                     	    //echo $buffer."\n";
@@ -1639,12 +2258,18 @@  discard block
 block discarded – undo
1639 2258
 				$data['speed'] = round($line[5]*1.94384);
1640 2259
 				$data['datetime'] = date('Y-m-d H:i:s');
1641 2260
 				$data['format_source'] = 'flightgearsp';
1642
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1643
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2261
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2262
+					$data['noarchive'] = true;
2263
+				}
2264
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2265
+					$SI->add($data);
2266
+				}
1644 2267
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1645 2268
 			    }
1646 2269
                         } elseif ($format === 'acars') {
1647
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2270
+                    	    if ($globalDebug) {
2271
+                    	    	echo 'ACARS : '.$buffer."\n";
2272
+                    	    }
1648 2273
 			    $ACARS->add(trim($buffer));
1649 2274
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1650 2275
 			    $ACARS->deleteLiveAcarsData();
@@ -1665,8 +2290,12 @@  discard block
 block discarded – undo
1665 2290
 				    $aircraft_type = $line[10];
1666 2291
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1667 2292
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1668
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1669
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2293
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2294
+				    	$data['noarchive'] = true;
2295
+				    }
2296
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2297
+				    	$SI->add($data);
2298
+				    }
1670 2299
 				}
1671 2300
 			    }
1672 2301
 			} elseif ($format === 'beast') {
@@ -1676,28 +2305,62 @@  discard block
 block discarded – undo
1676 2305
 			    foreach($buffer as $all_data) {
1677 2306
 				$line = json_decode('{'.$all_data.'}',true);
1678 2307
 				$data = array();
1679
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1680
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1681
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1682
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1683
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1684
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1685
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2308
+				if (isset($line['Icao'])) {
2309
+					$data['hex'] = $line['Icao'];
2310
+				}
2311
+				// hex
2312
+				if (isset($line['Call'])) {
2313
+					$data['ident'] = $line['Call'];
2314
+				}
2315
+				// ident
2316
+				if (isset($line['Alt'])) {
2317
+					$data['altitude'] = $line['Alt'];
2318
+				}
2319
+				// altitude
2320
+				if (isset($line['Spd'])) {
2321
+					$data['speed'] = $line['Spd'];
2322
+				}
2323
+				// speed
2324
+				if (isset($line['Trak'])) {
2325
+					$data['heading'] = $line['Trak'];
2326
+				}
2327
+				// heading
2328
+				if (isset($line['Lat'])) {
2329
+					$data['latitude'] = $line['Lat'];
2330
+				}
2331
+				// lat
2332
+				if (isset($line['Long'])) {
2333
+					$data['longitude'] = $line['Long'];
2334
+				}
2335
+				// long
1686 2336
 				//$data['verticalrate'] = $line['']; // verticale rate
1687
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2337
+				if (isset($line['Sqk'])) {
2338
+					$data['squawk'] = $line['Sqk'];
2339
+				}
2340
+				// squawk
1688 2341
 				$data['emergency'] = ''; // emergency
1689
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2342
+				if (isset($line['Reg'])) {
2343
+					$data['registration'] = $line['Reg'];
2344
+				}
1690 2345
 				/*
1691 2346
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1692 2347
 				else $data['datetime'] = date('Y-m-d H:i:s');
1693 2348
 				*/
1694 2349
 				$data['datetime'] = date('Y-m-d H:i:s');
1695
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2350
+				if (isset($line['Type'])) {
2351
+					$data['aircraft_icao'] = $line['Type'];
2352
+				}
1696 2353
 		    		$data['format_source'] = 'vrstcp';
1697 2354
 				$data['id_source'] = $id_source;
1698
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1699
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1700
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2355
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2356
+					$data['noarchive'] = true;
2357
+				}
2358
+				if (isset($value['name']) && $value['name'] != '') {
2359
+					$data['source_name'] = $value['name'];
2360
+				}
2361
+				if (isset($data['latitude']) && isset($data['hex'])) {
2362
+					$SI->add($data);
2363
+				}
1701 2364
 				unset($data);
1702 2365
 			    }
1703 2366
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1710,22 +2373,46 @@  discard block
 block discarded – undo
1710 2373
     				$data['hex'] = $lined['hexid'];
1711 2374
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1712 2375
     				$data['datetime'] = date('Y-m-d H:i:s');;
1713
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1714
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1715
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1716
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1717
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1718
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1719
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2376
+    				if (isset($lined['ident'])) {
2377
+    					$data['ident'] = $lined['ident'];
2378
+    				}
2379
+    				if (isset($lined['lat'])) {
2380
+    					$data['latitude'] = $lined['lat'];
2381
+    				}
2382
+    				if (isset($lined['lon'])) {
2383
+    					$data['longitude'] = $lined['lon'];
2384
+    				}
2385
+    				if (isset($lined['speed'])) {
2386
+    					$data['speed'] = $lined['speed'];
2387
+    				}
2388
+    				if (isset($lined['squawk'])) {
2389
+    					$data['squawk'] = $lined['squawk'];
2390
+    				}
2391
+    				if (isset($lined['alt'])) {
2392
+    					$data['altitude'] = $lined['alt'];
2393
+    				}
2394
+    				if (isset($lined['heading'])) {
2395
+    					$data['heading'] = $lined['heading'];
2396
+    				}
1720 2397
     				$data['id_source'] = $id_source;
1721 2398
     				$data['format_source'] = 'tsv';
1722
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1723
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1724
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1725
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2399
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2400
+    					$data['source_name'] = $globalSources[$nb]['name'];
2401
+    				}
2402
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2403
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2404
+    				}
2405
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2406
+					$data['noarchive'] = true;
2407
+				}
2408
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2409
+    					$SI->add($data);
2410
+    				}
1726 2411
     				unset($lined);
1727 2412
     				unset($data);
1728
-    			    } else $error = true;
2413
+    			    } else {
2414
+    			    	$error = true;
2415
+    			    }
1729 2416
 			} elseif ($format === 'aprs' && $use_aprs) {
1730 2417
 			    if ($aprs_connect === 0) {
1731 2418
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1751,47 +2438,96 @@  discard block
 block discarded – undo
1751 2438
 				    $aprs_last_tx = time();
1752 2439
 				    $data = array();
1753 2440
 				    //print_r($line);
1754
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1755
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1756
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1757
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1758
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1759
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1760
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1761
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1762
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1763
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2441
+				    if (isset($line['address'])) {
2442
+				    	$data['hex'] = $line['address'];
2443
+				    }
2444
+				    if (isset($line['mmsi'])) {
2445
+				    	$data['mmsi'] = $line['mmsi'];
2446
+				    }
2447
+				    if (isset($line['imo'])) {
2448
+				    	$data['imo'] = $line['imo'];
2449
+				    }
2450
+				    if (isset($line['squawk'])) {
2451
+				    	$data['squawk'] = $line['squawk'];
2452
+				    }
2453
+				    if (isset($line['arrival_code'])) {
2454
+				    	$data['arrival_code'] = $line['arrival_code'];
2455
+				    }
2456
+				    if (isset($line['arrival_date'])) {
2457
+				    	$data['arrival_date'] = $line['arrival_date'];
2458
+				    }
2459
+				    if (isset($line['typeid'])) {
2460
+				    	$data['type_id'] = $line['typeid'];
2461
+				    }
2462
+				    if (isset($line['statusid'])) {
2463
+				    	$data['status_id'] = $line['statusid'];
2464
+				    }
2465
+				    if (isset($line['timestamp'])) {
2466
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2467
+				    } else {
2468
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2469
+				    }
1764 2470
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1765
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2471
+				    if (isset($line['ident'])) {
2472
+				    	$data['ident'] = $line['ident'];
2473
+				    }
1766 2474
 				    $data['latitude'] = $line['latitude'];
1767 2475
 				    $data['longitude'] = $line['longitude'];
1768 2476
 				    //$data['verticalrate'] = $line[16];
1769
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2477
+				    if (isset($line['speed'])) {
2478
+				    	$data['speed'] = $line['speed'];
2479
+				    }
1770 2480
 				    //else $data['speed'] = 0;
1771
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1772
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1773
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2481
+				    if (isset($line['altitude'])) {
2482
+				    	$data['altitude'] = $line['altitude'];
2483
+				    }
2484
+				    if (isset($line['comment'])) {
2485
+				    	$data['comment'] = $line['comment'];
2486
+				    }
2487
+				    if (isset($line['symbol'])) {
2488
+				    	$data['type'] = $line['symbol'];
2489
+				    }
1774 2490
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1775 2491
 				    
1776
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2492
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2493
+				    	$data['heading'] = $line['heading'];
2494
+				    }
1777 2495
 				    //else echo 'No heading...'."\n";
1778 2496
 				    //else $data['heading'] = 0;
1779
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2497
+				    if (isset($line['stealth'])) {
2498
+				    	$data['aircraft_type'] = $line['stealth'];
2499
+				    }
1780 2500
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1781
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1782
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1783
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1784
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2501
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2502
+				    	$data['noarchive'] = true;
2503
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2504
+				    	$data['noarchive'] = false;
2505
+				    }
2506
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2507
+				    	$data['noarchive'] = true;
2508
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2509
+				    	$data['noarchive'] = false;
2510
+				    }
1785 2511
     				    $data['id_source'] = $id_source;
1786
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1787
-				    else $data['format_source'] = 'aprs';
2512
+    				    if (isset($line['format_source'])) {
2513
+    				    	$data['format_source'] = $line['format_source'];
2514
+    				    } else {
2515
+				    	$data['format_source'] = 'aprs';
2516
+				    }
1788 2517
 				    $data['source_name'] = $line['source'];
1789
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1790
-				    else $data['source_type'] = 'flarm';
1791
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2518
+				    if (isset($line['source_type'])) {
2519
+				    	$data['source_type'] = $line['source_type'];
2520
+				    } else {
2521
+				    	$data['source_type'] = 'flarm';
2522
+				    }
2523
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2524
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2525
+    				    }
1792 2526
 				    $currentdate = date('Y-m-d H:i:s');
1793 2527
 				    $aprsdate = strtotime($data['datetime']);
1794
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2528
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2529
+				    	$data['altitude_relative'] = 'AMSL';
2530
+				    }
1795 2531
 				    // Accept data if time <= system time + 20s
1796 2532
 				    //if (($data['source_type'] === 'modes') || isset($line['stealth']) && ($line['stealth'] === 0 || $line['stealth'] === '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1797 2533
 				    if (
@@ -1803,7 +2539,9 @@  discard block
 block discarded – undo
1803 2539
 					$send = $SI->add($data);
1804 2540
 				    } elseif ($data['source_type'] === 'ais') {
1805 2541
 					$data['type'] = '';
1806
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2542
+					if (isset($globalMarine) && $globalMarine) {
2543
+						$send = $MI->add($data);
2544
+					}
1807 2545
 				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1808 2546
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1809 2547
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
@@ -1811,8 +2549,12 @@  discard block
 block discarded – undo
1811 2549
 					    $line['symbol'] === 'Glider' || 
1812 2550
 					    $line['symbol'] === 'No. Plane' || 
1813 2551
 					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1814
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1815
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2552
+					    if ($line['symbol'] === 'Ballon') {
2553
+					    	$data['aircraft_icao'] = 'BALL';
2554
+					    }
2555
+					    if ($line['symbol'] === 'Glider') {
2556
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2557
+					    }
1816 2558
 					    $send = $SI->add($data);
1817 2559
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1818 2560
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -1843,9 +2585,13 @@  discard block
 block discarded – undo
1843 2585
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1844 2586
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1845 2587
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1846
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2588
+					if (isset($globalTracker) && $globalTracker) {
2589
+						$send = $TI->add($data);
2590
+					}
1847 2591
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1848
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2592
+					if (!isset($data['altitude'])) {
2593
+						$data['altitude'] = 0;
2594
+					}
1849 2595
 					$Source->deleteOldLocationByType('gs');
1850 2596
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1851 2597
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1854,7 +2600,9 @@  discard block
 block discarded – undo
1854 2600
 					}
1855 2601
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1856 2602
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1857
-					if ($globalDebug) echo '# Weather Station added'."\n";
2603
+					if ($globalDebug) {
2604
+						echo '# Weather Station added'."\n";
2605
+					}
1858 2606
 					$Source->deleteOldLocationByType('wx');
1859 2607
 					$weather_data = json_encode($line);
1860 2608
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1864,7 +2612,9 @@  discard block
 block discarded – undo
1864 2612
 					}
1865 2613
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1866 2614
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1867
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2615
+					if ($globalDebug) {
2616
+						echo '☈ Lightning added'."\n";
2617
+					}
1868 2618
 					$Source->deleteOldLocationByType('lightning');
1869 2619
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1870 2620
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1876,8 +2626,7 @@  discard block
 block discarded – undo
1876 2626
 				    	print_r($line);
1877 2627
 				    }
1878 2628
 				    unset($data);
1879
-				}
1880
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2629
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1881 2630
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1882 2631
 				}
1883 2632
 				/*
@@ -1886,7 +2635,9 @@  discard block
 block discarded – undo
1886 2635
 				}
1887 2636
 				*/
1888 2637
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1889
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2638
+				elseif ($line === true && $globalDebug) {
2639
+					echo '!! Failed : '.$buffer."!!\n";
2640
+				}
1890 2641
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1891 2642
 					$Source->deleteOldLocationByType('lightning');
1892 2643
 					$Source->deleteOldLocationByType('wx');
@@ -1922,27 +2673,47 @@  discard block
 block discarded – undo
1922 2673
     				$data['ground'] = $line[21];
1923 2674
     				$data['emergency'] = $line[19];
1924 2675
     				$data['format_source'] = 'sbs';
1925
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1926
-				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
1927
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1928
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2676
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2677
+					$data['source_name'] = $globalSources[$nb]['name'];
2678
+				} elseif ($line[0] == 'MLAT') {
2679
+					$data['source_name'] = 'MLAT';
2680
+				}
2681
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2682
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2683
+    				}
2684
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2685
+					$data['noarchive'] = true;
2686
+				}
1929 2687
     				$data['id_source'] = $id_source;
1930
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1931
-    				else $error = true;
2688
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2689
+    					$send = $SI->add($data);
2690
+    				} else {
2691
+    					$error = true;
2692
+    				}
1932 2693
     				unset($data);
1933
-    			    } else $error = true;
2694
+    			    } else {
2695
+    			    	$error = true;
2696
+    			    }
1934 2697
 			    if ($error) {
1935 2698
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1936
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2699
+					if ($globalDebug) {
2700
+						echo "Not a message. Ignoring... \n";
2701
+					}
1937 2702
 				} else {
1938
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2703
+					if ($globalDebug) {
2704
+						echo "Wrong line format. Ignoring... \n";
2705
+					}
1939 2706
 					if ($globalDebug) {
1940 2707
 						echo $buffer;
1941 2708
 						//print_r($line);
1942 2709
 					}
1943 2710
 					//socket_close($r);
1944
-					if ($globalDebug) echo "Reconnect after an error...\n";
1945
-					if ($format === 'aprs') $aprs_connect = 0;
2711
+					if ($globalDebug) {
2712
+						echo "Reconnect after an error...\n";
2713
+					}
2714
+					if ($format === 'aprs') {
2715
+						$aprs_connect = 0;
2716
+					}
1946 2717
 					$sourceer[$nb] = $globalSources[$nb];
1947 2718
 					connect_all($sourceer);
1948 2719
 					$sourceer = array();
@@ -1950,10 +2721,14 @@  discard block
 block discarded – undo
1950 2721
 			    }
1951 2722
 			}
1952 2723
 			// Sleep for xxx microseconds
1953
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2724
+			if (isset($globalSBSSleep)) {
2725
+				usleep($globalSBSSleep);
2726
+			}
1954 2727
 		    } else {
1955 2728
 			if ($format === 'flightgearmp') {
1956
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2729
+			    	if ($globalDebug) {
2730
+			    		echo "Reconnect FlightGear MP...";
2731
+			    	}
1957 2732
 				//@socket_close($r);
1958 2733
 				sleep($globalMinFetch);
1959 2734
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1962,10 +2737,15 @@  discard block
 block discarded – undo
1962 2737
 				break;
1963 2738
 				
1964 2739
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1965
-			    if (isset($tt[$format])) $tt[$format]++;
1966
-			    else $tt[$format] = 0;
2740
+			    if (isset($tt[$format])) {
2741
+			    	$tt[$format]++;
2742
+			    } else {
2743
+			    	$tt[$format] = 0;
2744
+			    }
1967 2745
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1968
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2746
+				if ($globalDebug) {
2747
+					echo "ERROR : Reconnect ".$format."...";
2748
+				}
1969 2749
 				//@socket_close($r);
1970 2750
 				sleep(2);
1971 2751
 				$aprs_connect = 0;
@@ -1983,11 +2763,17 @@  discard block
 block discarded – undo
1983 2763
 	    } else {
1984 2764
 		$error = socket_strerror(socket_last_error());
1985 2765
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1986
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1987
-			if (isset($globalDebug)) echo "Restarting...\n";
2766
+			if ($globalDebug) {
2767
+				echo "ERROR : socket_select give this error ".$error . "\n";
2768
+			}
2769
+			if (isset($globalDebug)) {
2770
+				echo "Restarting...\n";
2771
+			}
1988 2772
 			// Restart the script if possible
1989 2773
 			if (is_array($sockets)) {
1990
-			    if ($globalDebug) echo "Shutdown all sockets...";
2774
+			    if ($globalDebug) {
2775
+			    	echo "Shutdown all sockets...";
2776
+			    }
1991 2777
 			    
1992 2778
 			    foreach ($sockets as $sock) {
1993 2779
 				@socket_shutdown($sock,2);
@@ -1995,25 +2781,45 @@  discard block
 block discarded – undo
1995 2781
 			    }
1996 2782
 			    
1997 2783
 			}
1998
-			if ($globalDebug) echo "Waiting...";
2784
+			if ($globalDebug) {
2785
+				echo "Waiting...";
2786
+			}
1999 2787
 			sleep(2);
2000 2788
 			$time = time();
2001 2789
 			//connect_all($hosts);
2002 2790
 			$aprs_connect = 0;
2003
-			if ($reset%5 === 0) sleep(20);
2004
-			if ($reset%10 === 0) sleep(100);
2005
-			if ($reset%20 === 0) sleep(200);
2006
-			if ($reset > 100) exit('Too many attempts...');
2007
-			if ($globalDebug) echo "Restart all connections...";
2791
+			if ($reset%5 === 0) {
2792
+				sleep(20);
2793
+			}
2794
+			if ($reset%10 === 0) {
2795
+				sleep(100);
2796
+			}
2797
+			if ($reset%20 === 0) {
2798
+				sleep(200);
2799
+			}
2800
+			if ($reset > 100) {
2801
+				exit('Too many attempts...');
2802
+			}
2803
+			if ($globalDebug) {
2804
+				echo "Restart all connections...";
2805
+			}
2008 2806
 			connect_all($globalSources);
2009 2807
 		}
2010 2808
 	    }
2011 2809
 	}
2012 2810
 	if ($globalDaemon === false) {
2013
-	    if ($globalDebug) echo 'Check all...'."\n";
2014
-	    if (isset($SI)) $SI->checkAll();
2015
-	    if (isset($TI)) $TI->checkAll();
2016
-	    if (isset($MI)) $MI->checkAll();
2811
+	    if ($globalDebug) {
2812
+	    	echo 'Check all...'."\n";
2813
+	    }
2814
+	    if (isset($SI)) {
2815
+	    	$SI->checkAll();
2816
+	    }
2817
+	    if (isset($TI)) {
2818
+	    	$TI->checkAll();
2819
+	    }
2820
+	    if (isset($MI)) {
2821
+	    	$MI->checkAll();
2822
+	    }
2017 2823
 	}
2018 2824
     }
2019 2825
 }
Please login to merge, or discard this patch.