Completed
Push — master ( f218a1...9aeaea )
by Yannick
05:36
created
scripts/daemon-spotter.php 1 patch
Braces   +544 added lines, -186 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 
17
-if (!isset($globalDebug)) $globalDebug = FALSE;
17
+if (!isset($globalDebug)) {
18
+	$globalDebug = FALSE;
19
+}
18 20
 
19 21
 // Check if schema is at latest version
20 22
 $Connection = new Connection();
@@ -54,13 +56,22 @@  discard block
 block discarded – undo
54 56
     $globalSources = array();
55 57
     $globalSources[] = array('host' => $options['source']);
56 58
 }
57
-if (isset($options['server'])) $globalServer = TRUE;
58
-if (isset($options['idsource'])) $id_source = $options['idsource'];
59
-else $id_source = 1;
59
+if (isset($options['server'])) {
60
+	$globalServer = TRUE;
61
+}
62
+if (isset($options['idsource'])) {
63
+	$id_source = $options['idsource'];
64
+} else {
65
+	$id_source = 1;
66
+}
60 67
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
68
+    if ($globalDebug) {
69
+    	echo "Using Server Mode\n";
70
+    }
62 71
     $SI=new SpotterServer();
63
-} else $SI=new SpotterImport($Connection->db);
72
+} else {
73
+	$SI=new SpotterImport($Connection->db);
74
+}
64 75
 //$APRS=new APRS($Connection->db);
65 76
 $SBS=new SBS();
66 77
 $ACARS=new ACARS($Connection->db);
@@ -78,7 +89,9 @@  discard block
 block discarded – undo
78 89
 }
79 90
 
80 91
 // let's try and connect
81
-if ($globalDebug) echo "Connecting...\n";
92
+if ($globalDebug) {
93
+	echo "Connecting...\n";
94
+}
82 95
 $use_aprs = false;
83 96
 $aprs_full = false;
84 97
 $reset = 0;
@@ -87,7 +100,9 @@  discard block
 block discarded – undo
87 100
     $ip = gethostbyname($host);
88 101
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
89 102
     $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
103
+    if (!socket_set_nonblock($s)) {
104
+    	echo "Unable to set nonblock on socket\n";
105
+    }
91 106
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92 107
         return $s;
93 108
     }
@@ -115,7 +130,9 @@  discard block
 block discarded – undo
115 130
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116 131
     global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117 132
     $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
133
+    if ($globalDebug) {
134
+    	echo 'Connect to all...'."\n";
135
+    }
119 136
     foreach ($hosts as $id => $value) {
120 137
 	$host = $value['host'];
121 138
 	$globalSources[$id]['last_exec'] = 0;
@@ -125,27 +142,37 @@  discard block
 block discarded – undo
125 142
         	//$formats[$id] = 'deltadbtxt';
126 143
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 144
         	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
145
+        	if ($globalDebug) {
146
+        		echo "Connect to deltadb source (".$host.")...\n";
147
+        	}
129 148
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130 149
         	//$formats[$id] = 'vatsimtxt';
131 150
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 151
         	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
152
+        	if ($globalDebug) {
153
+        		echo "Connect to vatsim source (".$host.")...\n";
154
+        	}
134 155
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135 156
         	//$formats[$id] = 'aircraftlistjson';
136 157
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 158
         	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
159
+        	if ($globalDebug) {
160
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
161
+        	}
139 162
     	    } else if (preg_match('/opensky/i',$host)) {
140 163
         	//$formats[$id] = 'aircraftlistjson';
141 164
         	$globalSources[$id]['format'] = 'opensky';
142 165
         	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to opensky source (".$host.")...\n";
168
+        	}
144 169
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145 170
         	//$formats[$id] = 'radarvirtueljson';
146 171
         	$globalSources[$id]['format'] = 'radarvirtueljson';
147 172
         	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
175
+        	}
149 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151 178
         	    exit(0);
@@ -154,7 +181,9 @@  discard block
 block discarded – undo
154 181
         	//$formats[$id] = 'planeupdatefaa';
155 182
         	$globalSources[$id]['format'] = 'planeupdatefaa';
156 183
         	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
186
+        	}
158 187
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159 188
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160 189
         	    exit(0);
@@ -163,26 +192,36 @@  discard block
 block discarded – undo
163 192
         	//$formats[$id] = 'phpvmacars';
164 193
         	$globalSources[$id]['format'] = 'phpvmacars';
165 194
         	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
195
+        	if ($globalDebug) {
196
+        		echo "Connect to phpvmacars source (".$host.")...\n";
197
+        	}
167 198
             } else if (preg_match('/VAM-json.php$/i',$host)) {
168 199
         	//$formats[$id] = 'phpvmacars';
169 200
         	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
201
+        	if ($globalDebug) {
202
+        		echo "Connect to Vam source (".$host.")...\n";
203
+        	}
171 204
             } else if (preg_match('/whazzup/i',$host)) {
172 205
         	//$formats[$id] = 'whazzup';
173 206
         	$globalSources[$id]['format'] = 'whazzup';
174 207
         	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
208
+        	if ($globalDebug) {
209
+        		echo "Connect to whazzup source (".$host.")...\n";
210
+        	}
176 211
             } else if (preg_match('/recentpireps/i',$host)) {
177 212
         	//$formats[$id] = 'pirepsjson';
178 213
         	$globalSources[$id]['format'] = 'pirepsjson';
179 214
         	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
215
+        	if ($globalDebug) {
216
+        		echo "Connect to pirepsjson source (".$host.")...\n";
217
+        	}
181 218
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182 219
         	//$formats[$id] = 'fr24json';
183 220
         	$globalSources[$id]['format'] = 'fr24json';
184 221
         	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to fr24 source (".$host.")...\n";
224
+        	}
186 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188 227
         	    exit(0);
@@ -191,10 +230,14 @@  discard block
 block discarded – undo
191 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192 231
         	//$formats[$id] = 'tsv';
193 232
         	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
195 236
             }
196 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
238
+        	if ($globalDebug) {
239
+        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
240
+        	}
198 241
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199 242
 	    $hostport = explode(':',$host);
200 243
 	    if (isset($hostport[1])) {
@@ -231,17 +274,25 @@  discard block
 block discarded – undo
231 274
         		//$formats[$id] = 'beast';
232 275
         		$globalSources[$id]['format'] = 'beast';
233 276
 		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
277
+		    } else {
278
+		    	$globalSources[$id]['format'] = 'sbs';
279
+		    }
235 280
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 281
 		}
237
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
282
+		if ($globalDebug) {
283
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
284
+		}
238 285
             } else {
239
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
286
+		if ($globalDebug) {
287
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
288
+		}
240 289
     	    }
241 290
         }
242 291
     }
243 292
 }
244
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
293
+if (!isset($globalMinFetch)) {
294
+	$globalMinFetch = 15;
295
+}
245 296
 
246 297
 // Initialize all
247 298
 $status = array();
@@ -249,13 +300,19 @@  discard block
 block discarded – undo
249 300
 $formats = array();
250 301
 $last_exec = array();
251 302
 $time = time();
252
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
253
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
254
-else $timeout = 20;
303
+if (isset($globalSourcesTimeout)) {
304
+	$timeout = $globalSourcesTimeOut;
305
+} else if (isset($globalSBS1TimeOut)) {
306
+	$timeout = $globalSBS1TimeOut;
307
+} else {
308
+	$timeout = 20;
309
+}
255 310
 $errno = '';
256 311
 $errstr='';
257 312
 
258
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
313
+if (!isset($globalDaemon)) {
314
+	$globalDaemon = TRUE;
315
+}
259 316
 /* Initiate connections to all the hosts simultaneously */
260 317
 //connect_all($hosts);
261 318
 //connect_all($globalSources);
@@ -275,7 +332,9 @@  discard block
 block discarded – undo
275 332
     if (isset($source['format']) && $source['format'] == 'aprs') {
276 333
 	$aprs_connect = 0;
277 334
 	$use_aprs = true;
278
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
335
+	if (isset($source['port']) && $source['port'] == '10152') {
336
+		$aprs_full = true;
337
+	}
279 338
 	break;
280 339
     }
281 340
 }
@@ -286,24 +345,44 @@  discard block
 block discarded – undo
286 345
 	$aprs_connect = 0;
287 346
 	$aprs_keep = 120;
288 347
 	$aprs_last_tx = time();
289
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
290
-	else $aprs_version = $globalName.' using FlightAirMap';
348
+	if (isset($globalAPRSversion)) {
349
+		$aprs_version = $globalAPRSversion;
350
+	} else {
351
+		$aprs_version = $globalName.' using FlightAirMap';
352
+	}
291 353
 	//else $aprs_version = 'Perl Example App';
292
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
293
-	else $aprs_ssid = 'FAM';
354
+	if (isset($globalAPRSssid)) {
355
+		$aprs_ssid = $globalAPRSssid;
356
+	} else {
357
+		$aprs_ssid = 'FAM';
358
+	}
294 359
 	//else $aprs_ssid = 'PerlEx';
295
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
296
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
297
-	if ($aprs_full) $aprs_filter = '';
298
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
299
-	else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
300
-}
360
+	if (isset($globalAPRSfilter)) {
361
+		$aprs_filter = $globalAPRSfilter;
362
+	} else {
363
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
364
+	}
365
+	if ($aprs_full) {
366
+		$aprs_filter = '';
367
+	}
368
+	if ($aprs_filter != '') {
369
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
370
+	} else {
371
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
372
+	}
373
+	}
301 374
 
302 375
 // connected - lets do some work
303
-if ($globalDebug) echo "Connected!\n";
376
+if ($globalDebug) {
377
+	echo "Connected!\n";
378
+}
304 379
 sleep(1);
305
-if ($globalDebug) echo "SCAN MODE \n\n";
306
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
380
+if ($globalDebug) {
381
+	echo "SCAN MODE \n\n";
382
+}
383
+if (!isset($globalCronEnd)) {
384
+	$globalCronEnd = 60;
385
+}
307 386
 $endtime = time()+$globalCronEnd;
308 387
 $i = 1;
309 388
 $tt = array();
@@ -317,20 +396,28 @@  discard block
 block discarded – undo
317 396
 
318 397
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
319 398
 while ($i > 0) {
320
-    if (!$globalDaemon) $i = $endtime-time();
399
+    if (!$globalDaemon) {
400
+    	$i = $endtime-time();
401
+    }
321 402
     // Delete old ATC
322 403
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
323
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
404
+	if ($globalDebug) {
405
+		echo 'Delete old ATC...'."\n";
406
+	}
324 407
         $ATC->deleteOldATC();
325 408
     }
326 409
     
327 410
     if (count($last_exec) > 0) {
328 411
 	$max = $globalMinFetch;
329 412
 	foreach ($last_exec as $last) {
330
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
413
+	    if ((time() - $last['last']) < $max) {
414
+	    	$max = time() - $last['last'];
415
+	    }
331 416
 	}
332 417
 	if ($max != $globalMinFetch) {
333
-	    if ($globalDebug) echo 'Sleeping...'."\n";
418
+	    if ($globalDebug) {
419
+	    	echo 'Sleeping...'."\n";
420
+	    }
334 421
 	    sleep($globalMinFetch-$max+2);
335 422
 	}
336 423
     }
@@ -338,11 +425,15 @@  discard block
 block discarded – undo
338 425
     
339 426
     //foreach ($formats as $id => $value) {
340 427
     foreach ($globalSources as $id => $value) {
341
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
428
+	if (!isset($last_exec[$id]['last'])) {
429
+		$last_exec[$id]['last'] = 0;
430
+	}
342 431
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
343 432
 	    //$buffer = $Common->getData($hosts[$id]);
344 433
 	    $buffer = $Common->getData($value['host']);
345
-	    if ($buffer != '') $reset = 0;
434
+	    if ($buffer != '') {
435
+	    	$reset = 0;
436
+	    }
346 437
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347 438
 	    $buffer = explode('\n',$buffer);
348 439
 	    foreach ($buffer as $line) {
@@ -351,19 +442,38 @@  discard block
 block discarded – undo
351 442
 	            $data = array();
352 443
 	            $data['hex'] = $line[1]; // hex
353 444
 	            $data['ident'] = $line[2]; // ident
354
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
445
+	            if (isset($line[3])) {
446
+	            	$data['altitude'] = $line[3];
447
+	            }
448
+	            // altitude
449
+	            if (isset($line[4])) {
450
+	            	$data['speed'] = $line[4];
451
+	            }
452
+	            // speed
453
+	            if (isset($line[5])) {
454
+	            	$data['heading'] = $line[5];
455
+	            }
456
+	            // heading
457
+	            if (isset($line[6])) {
458
+	            	$data['latitude'] = $line[6];
459
+	            }
460
+	            // lat
461
+	            if (isset($line[7])) {
462
+	            	$data['longitude'] = $line[7];
463
+	            }
464
+	            // long
359 465
 	            $data['verticalrate'] = ''; // vertical rate
360 466
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361 467
 	            $data['emergency'] = ''; // emergency
362 468
 		    $data['datetime'] = date('Y-m-d H:i:s');
363 469
 		    $data['format_source'] = 'deltadbtxt';
364 470
     		    $data['id_source'] = $id_source;
365
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
471
+		    if (isset($value['name']) && $value['name'] != '') {
472
+		    	$data['source_name'] = $value['name'];
473
+		    }
474
+		    if (isset($value['sourcestats'])) {
475
+		    	$data['sourcestats'] = $value['sourcestats'];
476
+		    }
367 477
     		    $SI->add($data);
368 478
 		    unset($data);
369 479
     		}
@@ -386,10 +496,19 @@  discard block
 block discarded – undo
386 496
 			$data['pilot_name'] = $line[2];
387 497
 			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
388 498
 			$data['ident'] = $line[0]; // ident
389
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
499
+			if ($line[7] != '' && $line[7] != 0) {
500
+				$data['altitude'] = $line[7];
501
+			}
502
+			// altitude
390 503
 			$data['speed'] = $line[8]; // speed
391
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
392
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
504
+			if (isset($line[45])) {
505
+				$data['heading'] = $line[45];
506
+			}
507
+			// heading
508
+			elseif (isset($line[38])) {
509
+				$data['heading'] = $line[38];
510
+			}
511
+			// heading
393 512
 			$data['latitude'] = $line[5]; // lat
394 513
 	        	$data['longitude'] = $line[6]; // long
395 514
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -398,14 +517,18 @@  discard block
 block discarded – undo
398 517
 	        	$data['waypoints'] = $line[30];
399 518
 			$data['datetime'] = date('Y-m-d H:i:s');
400 519
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
401
-			if (isset($line[37])) $data['last_update'] = $line[37];
520
+			if (isset($line[37])) {
521
+				$data['last_update'] = $line[37];
522
+			}
402 523
 		        $data['departure_airport_icao'] = $line[11];
403 524
 		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
404 525
 		        $data['arrival_airport_icao'] = $line[13];
405 526
 			$data['frequency'] = $line[4];
406 527
 			$data['type'] = $line[18];
407 528
 			$data['range'] = $line[19];
408
-			if (isset($line[35])) $data['info'] = $line[35];
529
+			if (isset($line[35])) {
530
+				$data['info'] = $line[35];
531
+			}
409 532
     			$data['id_source'] = $id_source;
410 533
 	    		//$data['arrival_airport_time'] = ;
411 534
 	    		if ($line[9] != '') {
@@ -419,23 +542,38 @@  discard block
 block discarded – undo
419 542
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
420 543
 	    		*/
421 544
 	    		$data['format_source'] = $value['format'];
422
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
423
-    			if ($line[3] == 'PILOT') $SI->add($data);
424
-			elseif ($line[3] == 'ATC') {
545
+			if (isset($value['name']) && $value['name'] != '') {
546
+				$data['source_name'] = $value['name'];
547
+			}
548
+    			if ($line[3] == 'PILOT') {
549
+    				$SI->add($data);
550
+    			} elseif ($line[3] == 'ATC') {
425 551
 				//print_r($data);
426 552
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
427 553
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
428 554
 				$typec = substr($data['ident'],-3);
429
-				if ($typec == 'APP') $data['type'] = 'Approach';
430
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
431
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
432
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
433
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
434
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
435
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
436
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
437
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
438
-				if (!isset($data['source_name'])) $data['source_name'] = '';
555
+				if ($typec == 'APP') {
556
+					$data['type'] = 'Approach';
557
+				} elseif ($typec == 'TWR') {
558
+					$data['type'] = 'Tower';
559
+				} elseif ($typec == 'OBS') {
560
+					$data['type'] = 'Observer';
561
+				} elseif ($typec == 'GND') {
562
+					$data['type'] = 'Ground';
563
+				} elseif ($typec == 'DEL') {
564
+					$data['type'] = 'Delivery';
565
+				} elseif ($typec == 'DEP') {
566
+					$data['type'] = 'Departure';
567
+				} elseif ($typec == 'FSS') {
568
+					$data['type'] = 'Flight Service Station';
569
+				} elseif ($typec == 'CTR') {
570
+					$data['type'] = 'Control Radar or Centre';
571
+				} elseif ($data['type'] == '') {
572
+					$data['type'] = 'Observer';
573
+				}
574
+				if (!isset($data['source_name'])) {
575
+					$data['source_name'] = '';
576
+				}
439 577
 				echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
440 578
 			}
441 579
     			unset($data);
@@ -455,26 +593,55 @@  discard block
 block discarded – undo
455 593
 		foreach ($all_data['acList'] as $line) {
456 594
 		    $data = array();
457 595
 		    $data['hex'] = $line['Icao']; // hex
458
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
459
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
460
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
461
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
462
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
463
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
596
+		    if (isset($line['Call'])) {
597
+		    	$data['ident'] = $line['Call'];
598
+		    }
599
+		    // ident
600
+		    if (isset($line['Alt'])) {
601
+		    	$data['altitude'] = $line['Alt'];
602
+		    }
603
+		    // altitude
604
+		    if (isset($line['Spd'])) {
605
+		    	$data['speed'] = $line['Spd'];
606
+		    }
607
+		    // speed
608
+		    if (isset($line['Trak'])) {
609
+		    	$data['heading'] = $line['Trak'];
610
+		    }
611
+		    // heading
612
+		    if (isset($line['Lat'])) {
613
+		    	$data['latitude'] = $line['Lat'];
614
+		    }
615
+		    // lat
616
+		    if (isset($line['Long'])) {
617
+		    	$data['longitude'] = $line['Long'];
618
+		    }
619
+		    // long
464 620
 		    //$data['verticalrate'] = $line['']; // verticale rate
465
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
621
+		    if (isset($line['Sqk'])) {
622
+		    	$data['squawk'] = $line['Sqk'];
623
+		    }
624
+		    // squawk
466 625
 		    $data['emergency'] = ''; // emergency
467
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
626
+		    if (isset($line['Reg'])) {
627
+		    	$data['registration'] = $line['Reg'];
628
+		    }
468 629
 		    /*
469 630
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
470 631
 		    else $data['datetime'] = date('Y-m-d H:i:s');
471 632
 		    */
472 633
 		    $data['datetime'] = date('Y-m-d H:i:s');
473
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
634
+		    if (isset($line['Type'])) {
635
+		    	$data['aircraft_icao'] = $line['Type'];
636
+		    }
474 637
 	    	    $data['format_source'] = 'aircraftlistjson';
475 638
 		    $data['id_source'] = $id_source;
476
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
477
-		    if (isset($data['datetime'])) $SI->add($data);
639
+		    if (isset($value['name']) && $value['name'] != '') {
640
+		    	$data['source_name'] = $value['name'];
641
+		    }
642
+		    if (isset($data['datetime'])) {
643
+		    	$SI->add($data);
644
+		    }
478 645
 		    unset($data);
479 646
 		}
480 647
 	    } else {
@@ -494,7 +661,9 @@  discard block
 block discarded – undo
494 661
 		    $data['datetime'] = date('Y-m-d H:i:s');
495 662
 	    	    $data['format_source'] = 'aircraftlistjson';
496 663
     		    $data['id_source'] = $id_source;
497
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
664
+		    if (isset($value['name']) && $value['name'] != '') {
665
+		    	$data['source_name'] = $value['name'];
666
+		    }
498 667
 		    $SI->add($data);
499 668
 		    unset($data);
500 669
 		}
@@ -530,7 +699,9 @@  discard block
 block discarded – undo
530 699
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
531 700
 	    	    $data['format_source'] = 'planeupdatefaa';
532 701
     		    $data['id_source'] = $id_source;
533
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
702
+		    if (isset($value['name']) && $value['name'] != '') {
703
+		    	$data['source_name'] = $value['name'];
704
+		    }
534 705
 		    $SI->add($data);
535 706
 		    unset($data);
536 707
 		}
@@ -570,7 +741,9 @@  discard block
 block discarded – undo
570 741
 	    //$buffer = $Common->getData($hosts[$id]);
571 742
 	    $buffer = $Common->getData($value['host']);
572 743
 	    $all_data = json_decode($buffer,true);
573
-	    if (!empty($all_data)) $reset = 0;
744
+	    if (!empty($all_data)) {
745
+	    	$reset = 0;
746
+	    }
574 747
 	    foreach ($all_data as $key => $line) {
575 748
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
576 749
 		    $data = array();
@@ -591,7 +764,9 @@  discard block
 block discarded – undo
591 764
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
592 765
 	    	    $data['format_source'] = 'fr24json';
593 766
     		    $data['id_source'] = $id_source;
594
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
767
+		    if (isset($value['name']) && $value['name'] != '') {
768
+		    	$data['source_name'] = $value['name'];
769
+		    }
595 770
 		    $SI->add($data);
596 771
 		    unset($data);
597 772
 		}
@@ -615,23 +790,39 @@  discard block
 block discarded – undo
615 790
 		    if (isset($line['inf'])) {
616 791
 			$data = array();
617 792
 			$data['hex'] = $line['inf']['ia'];
618
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
793
+			if (isset($line['inf']['cs'])) {
794
+				$data['ident'] = $line['inf']['cs'];
795
+			}
796
+			//$line[13]
619 797
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
620
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
621
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
798
+	    		if (isset($line['inf']['gs'])) {
799
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
800
+	    		}
801
+	    		// speed
802
+	    		if (isset($line['inf']['tr'])) {
803
+	    			$data['heading'] = $line['inf']['tr'];
804
+	    		}
805
+	    		// heading
622 806
 	    		$data['latitude'] = $line['pt'][0]; // lat
623 807
 	    		$data['longitude'] = $line['pt'][1]; // long
624 808
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
625
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
809
+	    		if (isset($line['inf']['sq'])) {
810
+	    			$data['squawk'] = $line['inf']['sq'];
811
+	    		}
812
+	    		// squawk
626 813
 	    		//$data['aircraft_icao'] = $line[8];
627
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
814
+	    		if (isset($line['inf']['rc'])) {
815
+	    			$data['registration'] = $line['inf']['rc'];
816
+	    		}
628 817
 			//$data['departure_airport_iata'] = $line[11];
629 818
 			//$data['arrival_airport_iata'] = $line[12];
630 819
 	    		//$data['emergency'] = ''; // emergency
631 820
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
632 821
 	    		$data['format_source'] = 'radarvirtueljson';
633 822
     			$data['id_source'] = $id_source;
634
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
823
+			if (isset($value['name']) && $value['name'] != '') {
824
+				$data['source_name'] = $value['name'];
825
+			}
635 826
 			$SI->add($data);
636 827
 			unset($data);
637 828
 		    }
@@ -652,29 +843,62 @@  discard block
 block discarded – undo
652 843
 		    $data['id'] = $line['id'];
653 844
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
654 845
 		    $data['ident'] = $line['callsign']; // ident
655
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
656
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
657
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
658
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
659
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
660
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
846
+		    if (isset($line['pilotid'])) {
847
+		    	$data['pilot_id'] = $line['pilotid'];
848
+		    }
849
+		    // pilot id
850
+		    if (isset($line['name'])) {
851
+		    	$data['pilot_name'] = $line['name'];
852
+		    }
853
+		    // pilot name
854
+		    if (isset($line['alt'])) {
855
+		    	$data['altitude'] = $line['alt'];
856
+		    }
857
+		    // altitude
858
+		    if (isset($line['gs'])) {
859
+		    	$data['speed'] = $line['gs'];
860
+		    }
861
+		    // speed
862
+		    if (isset($line['heading'])) {
863
+		    	$data['heading'] = $line['heading'];
864
+		    }
865
+		    // heading
866
+		    if (isset($line['route'])) {
867
+		    	$data['waypoints'] = $line['route'];
868
+		    }
869
+		    // route
661 870
 		    $data['latitude'] = $line['lat']; // lat
662 871
 		    $data['longitude'] = $line['lon']; // long
663 872
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
664 873
 		    //$data['squawk'] = $line['squawk']; // squawk
665 874
 		    //$data['emergency'] = ''; // emergency
666
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
667
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
668
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
875
+		    if (isset($line['depicao'])) {
876
+		    	$data['departure_airport_icao'] = $line['depicao'];
877
+		    }
878
+		    if (isset($line['deptime'])) {
879
+		    	$data['departure_airport_time'] = $line['deptime'];
880
+		    }
881
+		    if (isset($line['arricao'])) {
882
+		    	$data['arrival_airport_icao'] = $line['arricao'];
883
+		    }
669 884
 		    //$data['arrival_airport_time'] = $line['arrtime'];
670
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
671
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
672
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
673
-		    else $data['info'] = '';
885
+		    if (isset($line['aircraft'])) {
886
+		    	$data['aircraft_icao'] = $line['aircraft'];
887
+		    }
888
+		    if (isset($line['transponder'])) {
889
+		    	$data['squawk'] = $line['transponder'];
890
+		    }
891
+		    if (isset($line['atis'])) {
892
+		    	$data['info'] = $line['atis'];
893
+		    } else {
894
+		    	$data['info'] = '';
895
+		    }
674 896
 		    $data['format_source'] = 'pireps';
675 897
     		    $data['id_source'] = $id_source;
676 898
 		    $data['datetime'] = date('Y-m-d H:i:s');
677
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
899
+		    if (isset($value['name']) && $value['name'] != '') {
900
+		    	$data['source_name'] = $value['name'];
901
+		    }
678 902
 		    if ($line['icon'] == 'plane') {
679 903
 			$SI->add($data);
680 904
 		    //    print_r($data);
@@ -683,15 +907,25 @@  discard block
 block discarded – undo
683 907
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
684 908
 			$typec = substr($data['ident'],-3);
685 909
 			$data['type'] = '';
686
-			if ($typec == 'APP') $data['type'] = 'Approach';
687
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
688
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
689
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
690
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
691
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
692
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
693
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
694
-			else $data['type'] = 'Observer';
910
+			if ($typec == 'APP') {
911
+				$data['type'] = 'Approach';
912
+			} elseif ($typec == 'TWR') {
913
+				$data['type'] = 'Tower';
914
+			} elseif ($typec == 'OBS') {
915
+				$data['type'] = 'Observer';
916
+			} elseif ($typec == 'GND') {
917
+				$data['type'] = 'Ground';
918
+			} elseif ($typec == 'DEL') {
919
+				$data['type'] = 'Delivery';
920
+			} elseif ($typec == 'DEP') {
921
+				$data['type'] = 'Departure';
922
+			} elseif ($typec == 'FSS') {
923
+				$data['type'] = 'Flight Service Station';
924
+			} elseif ($typec == 'CTR') {
925
+				$data['type'] = 'Control Radar or Centre';
926
+			} else {
927
+				$data['type'] = 'Observer';
928
+			}
695 929
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
696 930
 		    }
697 931
 		    unset($data);
@@ -702,7 +936,9 @@  discard block
 block discarded – undo
702 936
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
703 937
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
704 938
 	    //$buffer = $Common->getData($hosts[$id]);
705
-	    if ($globalDebug) echo 'Get Data...'."\n";
939
+	    if ($globalDebug) {
940
+	    	echo 'Get Data...'."\n";
941
+	    }
706 942
 	    $buffer = $Common->getData($value['host']);
707 943
 	    $all_data = json_decode($buffer,true);
708 944
 	    if ($buffer != '' && is_array($all_data)) {
@@ -710,10 +946,16 @@  discard block
 block discarded – undo
710 946
 		foreach ($all_data as $line) {
711 947
 	    	    $data = array();
712 948
 	    	    //$data['id'] = $line['id']; // id not usable
713
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
949
+	    	    if (isset($line['pilotid'])) {
950
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
951
+	    	    }
714 952
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
715
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
716
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
953
+	    	    if (isset($line['pilotname'])) {
954
+	    	    	$data['pilot_name'] = $line['pilotname'];
955
+	    	    }
956
+	    	    if (isset($line['pilotid'])) {
957
+	    	    	$data['pilot_id'] = $line['pilotid'];
958
+	    	    }
717 959
 	    	    $data['ident'] = $line['flightnum']; // ident
718 960
 	    	    $data['altitude'] = $line['alt']; // altitude
719 961
 	    	    $data['speed'] = $line['gs']; // speed
@@ -731,27 +973,41 @@  discard block
 block discarded – undo
731 973
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
732 974
     		    $data['arrival_airport_time'] = $line['arrtime'];
733 975
     		    $data['registration'] = $line['aircraft'];
734
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
976
+		    if (isset($line['route'])) {
977
+		    	$data['waypoints'] = $line['route'];
978
+		    }
979
+		    // route
735 980
 		    if (isset($line['aircraftname'])) {
736 981
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
737 982
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
738 983
 	    		$aircraft_data = explode('-',$line['aircraftname']);
739
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
740
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
741
-	    		else {
984
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
985
+	    			$data['aircraft_icao'] = $aircraft_data[0];
986
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
987
+	    			$data['aircraft_icao'] = $aircraft_data[1];
988
+	    		} else {
742 989
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
743
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
744
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
990
+	    		    if (isset($aircraft_data[1])) {
991
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
992
+	    		    } else {
993
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
994
+	    		    }
745 995
 	    		}
746 996
 	    	    }
747
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
997
+    		    if (isset($line['route'])) {
998
+    		    	$data['waypoints'] = $line['route'];
999
+    		    }
748 1000
     		    $data['id_source'] = $id_source;
749 1001
 	    	    $data['format_source'] = 'phpvmacars';
750
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1002
+		    if (isset($value['name']) && $value['name'] != '') {
1003
+		    	$data['source_name'] = $value['name'];
1004
+		    }
751 1005
 		    $SI->add($data);
752 1006
 		    unset($data);
753 1007
 		}
754
-		if ($globalDebug) echo 'No more data...'."\n";
1008
+		if ($globalDebug) {
1009
+			echo 'No more data...'."\n";
1010
+		}
755 1011
 		unset($buffer);
756 1012
 		unset($all_data);
757 1013
 	    }
@@ -759,7 +1015,9 @@  discard block
 block discarded – undo
759 1015
     	    $last_exec[$id]['last'] = time();
760 1016
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
761 1017
 	    //$buffer = $Common->getData($hosts[$id]);
762
-	    if ($globalDebug) echo 'Get Data...'."\n";
1018
+	    if ($globalDebug) {
1019
+	    	echo 'Get Data...'."\n";
1020
+	    }
763 1021
 	    $buffer = $Common->getData($value['host']);
764 1022
 	    $all_data = json_decode($buffer,true);
765 1023
 	    if ($buffer != '' && is_array($all_data)) {
@@ -788,15 +1046,22 @@  discard block
 block discarded – undo
788 1046
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
789 1047
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
790 1048
     		    //$data['registration'] = $line['aircraft'];
791
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1049
+		    if (isset($line['route'])) {
1050
+		    	$data['waypoints'] = $line['route'];
1051
+		    }
1052
+		    // route
792 1053
 	    	    $data['aircraft_icao'] = $line['plane_type'];
793 1054
     		    $data['id_source'] = $id_source;
794 1055
 	    	    $data['format_source'] = 'vam';
795
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1056
+		    if (isset($value['name']) && $value['name'] != '') {
1057
+		    	$data['source_name'] = $value['name'];
1058
+		    }
796 1059
 		    $SI->add($data);
797 1060
 		    unset($data);
798 1061
 		}
799
-		if ($globalDebug) echo 'No more data...'."\n";
1062
+		if ($globalDebug) {
1063
+			echo 'No more data...'."\n";
1064
+		}
800 1065
 		unset($buffer);
801 1066
 		unset($all_data);
802 1067
 	    }
@@ -804,7 +1069,9 @@  discard block
 block discarded – undo
804 1069
     	    $last_exec[$id]['last'] = time();
805 1070
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
806 1071
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') {
807
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1072
+	    if (function_exists('pcntl_fork')) {
1073
+	    	pcntl_signal_dispatch();
1074
+	    }
808 1075
     	    //$last_exec[$id]['last'] = time();
809 1076
 
810 1077
 	    //$read = array( $sockets[$id] );
@@ -812,7 +1079,9 @@  discard block
 block discarded – undo
812 1079
 	    $write = NULL;
813 1080
 	    $e = NULL;
814 1081
 	    $n = socket_select($read, $write, $e, $timeout);
815
-	    if ($e != NULL) var_dump($e);
1082
+	    if ($e != NULL) {
1083
+	    	var_dump($e);
1084
+	    }
816 1085
 	    if ($n > 0) {
817 1086
 		$reset = 0;
818 1087
 		foreach ($read as $nb => $r) {
@@ -834,7 +1103,9 @@  discard block
 block discarded – undo
834 1103
 		    if ($buffer != '') {
835 1104
 			$tt[$format] = 0;
836 1105
 			if ($format == 'acarssbs3') {
837
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1106
+                    	    if ($globalDebug) {
1107
+                    	    	echo 'ACARS : '.$buffer."\n";
1108
+                    	    }
838 1109
 			    $ACARS->add(trim($buffer));
839 1110
 			    $ACARS->deleteLiveAcarsData();
840 1111
 			} elseif ($format == 'raw') {
@@ -843,9 +1114,15 @@  discard block
 block discarded – undo
843 1114
 			    if (is_array($data)) {
844 1115
 				$data['datetime'] = date('Y-m-d H:i:s');
845 1116
 				$data['format_source'] = 'raw';
846
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
847
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
848
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1117
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1118
+					$data['source_name'] = $globalSources[$nb]['name'];
1119
+				}
1120
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1121
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1122
+    				}
1123
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1124
+                                	$SI->add($data);
1125
+                                }
849 1126
                             }
850 1127
                         } elseif ($format == 'flightgearsp') {
851 1128
                     	    //echo $buffer."\n";
@@ -863,11 +1140,15 @@  discard block
 block discarded – undo
863 1140
 				$data['speed'] = round($line[5]*1.94384);
864 1141
 				$data['datetime'] = date('Y-m-d H:i:s');
865 1142
 				$data['format_source'] = 'flightgearsp';
866
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1143
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1144
+					$SI->add($data);
1145
+				}
867 1146
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
868 1147
 			    }
869 1148
                         } elseif ($format == 'acars') {
870
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1149
+                    	    if ($globalDebug) {
1150
+                    	    	echo 'ACARS : '.$buffer."\n";
1151
+                    	    }
871 1152
 			    $ACARS->add(trim($buffer));
872 1153
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
873 1154
 			    $ACARS->deleteLiveAcarsData();
@@ -888,7 +1169,9 @@  discard block
 block discarded – undo
888 1169
 				    $aircraft_type = $line[10];
889 1170
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
890 1171
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
891
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1172
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1173
+				    	$SI->add($data);
1174
+				    }
892 1175
 				}
893 1176
 			    }
894 1177
 			} elseif ($format == 'beast') {
@@ -904,21 +1187,43 @@  discard block
 block discarded – undo
904 1187
     				$data['hex'] = $lined['hexid'];
905 1188
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
906 1189
     				$data['datetime'] = date('Y-m-d H:i:s');;
907
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
908
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
909
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
910
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
911
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
912
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
913
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1190
+    				if (isset($lined['ident'])) {
1191
+    					$data['ident'] = $lined['ident'];
1192
+    				}
1193
+    				if (isset($lined['lat'])) {
1194
+    					$data['latitude'] = $lined['lat'];
1195
+    				}
1196
+    				if (isset($lined['lon'])) {
1197
+    					$data['longitude'] = $lined['lon'];
1198
+    				}
1199
+    				if (isset($lined['speed'])) {
1200
+    					$data['speed'] = $lined['speed'];
1201
+    				}
1202
+    				if (isset($lined['squawk'])) {
1203
+    					$data['squawk'] = $lined['squawk'];
1204
+    				}
1205
+    				if (isset($lined['alt'])) {
1206
+    					$data['altitude'] = $lined['alt'];
1207
+    				}
1208
+    				if (isset($lined['heading'])) {
1209
+    					$data['heading'] = $lined['heading'];
1210
+    				}
914 1211
     				$data['id_source'] = $id_source;
915 1212
     				$data['format_source'] = 'tsv';
916
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
917
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
918
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1213
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1214
+    					$data['source_name'] = $globalSources[$nb]['name'];
1215
+    				}
1216
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1217
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1218
+    				}
1219
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1220
+    					$SI->add($data);
1221
+    				}
919 1222
     				unset($lined);
920 1223
     				unset($data);
921
-    			    } else $error = true;
1224
+    			    } else {
1225
+    			    	$error = true;
1226
+    			    }
922 1227
 			} elseif ($format == 'aprs' && $use_aprs) {
923 1228
 			    if ($aprs_connect == 0) {
924 1229
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -944,29 +1249,44 @@  discard block
 block discarded – undo
944 1249
 				    $data['latitude'] = $line['latitude'];
945 1250
 				    $data['longitude'] = $line['longitude'];
946 1251
 				    //$data['verticalrate'] = $line[16];
947
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
948
-				    else $data['speed'] = 0;
1252
+				    if (isset($line['speed'])) {
1253
+				    	$data['speed'] = $line['speed'];
1254
+				    } else {
1255
+				    	$data['speed'] = 0;
1256
+				    }
949 1257
 				    $data['altitude'] = $line['altitude'];
950
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
1258
+				    if (isset($line['course'])) {
1259
+				    	$data['heading'] = $line['course'];
1260
+				    }
951 1261
 				    //else $data['heading'] = 0;
952 1262
 				    $data['aircraft_type'] = $line['stealth'];
953
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1263
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1264
+				    	$data['noarchive'] = true;
1265
+				    }
954 1266
     				    $data['id_source'] = $id_source;
955 1267
 				    $data['format_source'] = 'aprs';
956 1268
 				    $data['source_name'] = $line['source'];
957
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1269
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1270
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1271
+    				    }
958 1272
 				    $currentdate = date('Y-m-d H:i:s');
959 1273
 				    $aprsdate = strtotime($data['datetime']);
960 1274
 				    // Accept data if time <= system time + 20s
961
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
962
-				    else {
963
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
964
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1275
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1276
+				    	$send = $SI->add($data);
1277
+				    } else {
1278
+					if ($line['stealth'] != 0) {
1279
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1280
+					} else {
1281
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1282
+					}
965 1283
 				    }
966 1284
 				    unset($data);
967 1285
 				} 
968 1286
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
969
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1287
+				elseif ($line == true && $globalDebug) {
1288
+					echo '!! Failed : '.$buffer."!!\n";
1289
+				}
970 1290
 			    }
971 1291
 			} else {
972 1292
 			    $line = explode(',', $buffer);
@@ -995,25 +1315,42 @@  discard block
 block discarded – undo
995 1315
     				$data['ground'] = $line[21];
996 1316
     				$data['emergency'] = $line[19];
997 1317
     				$data['format_source'] = 'sbs';
998
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
999
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1318
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1319
+					$data['source_name'] = $globalSources[$nb]['name'];
1320
+				}
1321
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1322
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1323
+    				}
1000 1324
     				$data['id_source'] = $id_source;
1001
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1002
-    				else $error = true;
1325
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1326
+    					$send = $SI->add($data);
1327
+    				} else {
1328
+    					$error = true;
1329
+    				}
1003 1330
     				unset($data);
1004
-    			    } else $error = true;
1331
+    			    } else {
1332
+    			    	$error = true;
1333
+    			    }
1005 1334
 			    if ($error) {
1006 1335
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1007
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1336
+					if ($globalDebug) {
1337
+						echo "Not a message. Ignoring... \n";
1338
+					}
1008 1339
 				} else {
1009
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1340
+					if ($globalDebug) {
1341
+						echo "Wrong line format. Ignoring... \n";
1342
+					}
1010 1343
 					if ($globalDebug) {
1011 1344
 						echo $buffer;
1012 1345
 						print_r($line);
1013 1346
 					}
1014 1347
 					//socket_close($r);
1015
-					if ($globalDebug) echo "Reconnect after an error...\n";
1016
-					if ($format == 'aprs') $aprs_connect = 0;
1348
+					if ($globalDebug) {
1349
+						echo "Reconnect after an error...\n";
1350
+					}
1351
+					if ($format == 'aprs') {
1352
+						$aprs_connect = 0;
1353
+					}
1017 1354
 					$sourceer[$nb] = $globalSources[$nb];
1018 1355
 					connect_all($sourceer);
1019 1356
 					$sourceer = array();
@@ -1021,10 +1358,14 @@  discard block
 block discarded – undo
1021 1358
 			    }
1022 1359
 			}
1023 1360
 			// Sleep for xxx microseconds
1024
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1361
+			if (isset($globalSBSSleep)) {
1362
+				usleep($globalSBSSleep);
1363
+			}
1025 1364
 		    } else {
1026 1365
 			if ($format == 'flightgearmp') {
1027
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1366
+			    	if ($globalDebug) {
1367
+			    		echo "Reconnect FlightGear MP...";
1368
+			    	}
1028 1369
 				//@socket_close($r);
1029 1370
 				sleep($globalMinFetch);
1030 1371
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1033,10 +1374,15 @@  discard block
 block discarded – undo
1033 1374
 				break;
1034 1375
 				
1035 1376
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1036
-			    if (isset($tt[$format])) $tt[$format]++;
1037
-			    else $tt[$format] = 0;
1377
+			    if (isset($tt[$format])) {
1378
+			    	$tt[$format]++;
1379
+			    } else {
1380
+			    	$tt[$format] = 0;
1381
+			    }
1038 1382
 			    if ($tt[$format] > 30) {
1039
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1383
+				if ($globalDebug) {
1384
+					echo "ERROR : Reconnect ".$format."...";
1385
+				}
1040 1386
 				//@socket_close($r);
1041 1387
 				sleep(2);
1042 1388
 				$aprs_connect = 0;
@@ -1052,12 +1398,18 @@  discard block
 block discarded – undo
1052 1398
 		}
1053 1399
 	    } else {
1054 1400
 		$error = socket_strerror(socket_last_error());
1055
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1401
+		if ($globalDebug) {
1402
+			echo "ERROR : socket_select give this error ".$error . "\n";
1403
+		}
1056 1404
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1057
-			if (isset($globalDebug)) echo "Restarting...\n";
1405
+			if (isset($globalDebug)) {
1406
+				echo "Restarting...\n";
1407
+			}
1058 1408
 			// Restart the script if possible
1059 1409
 			if (is_array($sockets)) {
1060
-			    if ($globalDebug) echo "Shutdown all sockets...";
1410
+			    if ($globalDebug) {
1411
+			    	echo "Shutdown all sockets...";
1412
+			    }
1061 1413
 			    
1062 1414
 			    foreach ($sockets as $sock) {
1063 1415
 				@socket_shutdown($sock,2);
@@ -1065,18 +1417,24 @@  discard block
 block discarded – undo
1065 1417
 			    }
1066 1418
 			    
1067 1419
 			}
1068
-			if ($globalDebug) echo "Restart all connections...";
1420
+			if ($globalDebug) {
1421
+				echo "Restart all connections...";
1422
+			}
1069 1423
 			sleep(2);
1070 1424
 			$time = time();
1071 1425
 			//connect_all($hosts);
1072 1426
 			$aprs_connect = 0;
1073
-			if ($reset > 40) exit('Too many attempts...');
1427
+			if ($reset > 40) {
1428
+				exit('Too many attempts...');
1429
+			}
1074 1430
 			connect_all($globalSources);
1075 1431
 		}
1076 1432
 	    }
1077 1433
 	}
1078 1434
 	if ($globalDaemon === false) {
1079
-	    if ($globalDebug) echo 'Check all...'."\n";
1435
+	    if ($globalDebug) {
1436
+	    	echo 'Check all...'."\n";
1437
+	    }
1080 1438
 	    $SI->checkAll();
1081 1439
 	}
1082 1440
     }
Please login to merge, or discard this patch.