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