Completed
Push — master ( c26593...11b04b )
by Yannick
08:06
created
scripts/daemon-spotter.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 	    die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
48
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
49 49
     }
50 50
 }
51 51
 
52
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
@@ -67,27 +67,27 @@  discard block
 block discarded – undo
67 67
 else $id_source = 1;
68 68
 if (isset($globalServer) && $globalServer) {
69 69
     if ($globalDebug) echo "Using Server Mode\n";
70
-    $SI=new SpotterServer();
70
+    $SI = new SpotterServer();
71 71
 /*
72 72
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
73 73
     $SI = new adsb2aprs();
74 74
     $SI->connect();
75 75
 */
76
-} else $SI=new SpotterImport($Connection->db);
76
+} else $SI = new SpotterImport($Connection->db);
77 77
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
78 78
 if (isset($globalMarine) && $globalMarine) {
79 79
     $AIS = new AIS();
80 80
     $MI = new MarineImport($Connection->db);
81 81
 }
82 82
 //$APRS=new APRS($Connection->db);
83
-$SBS=new SBS();
84
-$ACARS=new ACARS($Connection->db);
85
-$Common=new Common();
83
+$SBS = new SBS();
84
+$ACARS = new ACARS($Connection->db);
85
+$Common = new Common();
86 86
 date_default_timezone_set('UTC');
87 87
 //$servertz = system('date +%Z');
88 88
 // signal handler - playing nice with sockets and dump1090
89 89
 if (function_exists('pcntl_fork')) {
90
-    pcntl_signal(SIGINT,  function() {
90
+    pcntl_signal(SIGINT, function() {
91 91
         global $sockets;
92 92
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
93 93
         die("Bye!\n");
@@ -103,35 +103,35 @@  discard block
 block discarded – undo
103 103
 
104 104
 function connect_all($hosts) {
105 105
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
106
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
107 107
     $reset++;
108 108
     if ($globalDebug) echo 'Connect to all...'."\n";
109 109
     foreach ($hosts as $id => $value) {
110 110
 	$host = $value['host'];
111 111
 	$globalSources[$id]['last_exec'] = 0;
112 112
 	// Here we check type of source(s)
113
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
114
-            if (preg_match('/deltadb.txt$/i',$host)) {
113
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
114
+            if (preg_match('/deltadb.txt$/i', $host)) {
115 115
         	//$formats[$id] = 'deltadbtxt';
116 116
         	$globalSources[$id]['format'] = 'deltadbtxt';
117 117
         	//$last_exec['deltadbtxt'] = 0;
118 118
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
119
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
119
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
120 120
         	//$formats[$id] = 'vatsimtxt';
121 121
         	$globalSources[$id]['format'] = 'vatsimtxt';
122 122
         	//$last_exec['vatsimtxt'] = 0;
123 123
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
124
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
124
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
125 125
         	//$formats[$id] = 'aircraftlistjson';
126 126
         	$globalSources[$id]['format'] = 'aircraftlistjson';
127 127
         	//$last_exec['aircraftlistjson'] = 0;
128 128
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
129
-    	    } else if (preg_match('/opensky/i',$host)) {
129
+    	    } else if (preg_match('/opensky/i', $host)) {
130 130
         	//$formats[$id] = 'aircraftlistjson';
131 131
         	$globalSources[$id]['format'] = 'opensky';
132 132
         	//$last_exec['aircraftlistjson'] = 0;
133 133
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
134
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
134
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
135 135
         	//$formats[$id] = 'radarvirtueljson';
136 136
         	$globalSources[$id]['format'] = 'radarvirtueljson';
137 137
         	//$last_exec['radarvirtueljson'] = 0;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
141 141
         	    exit(0);
142 142
         	}
143
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
143
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
144 144
         	//$formats[$id] = 'planeupdatefaa';
145 145
         	$globalSources[$id]['format'] = 'planeupdatefaa';
146 146
         	//$last_exec['planeupdatefaa'] = 0;
@@ -149,26 +149,26 @@  discard block
 block discarded – undo
149 149
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
150 150
         	    exit(0);
151 151
         	}
152
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
152
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
153 153
         	//$formats[$id] = 'phpvmacars';
154 154
         	$globalSources[$id]['format'] = 'phpvmacars';
155 155
         	//$last_exec['phpvmacars'] = 0;
156 156
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
157
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
157
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
158 158
         	//$formats[$id] = 'phpvmacars';
159 159
         	$globalSources[$id]['format'] = 'vam';
160 160
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
161
-            } else if (preg_match('/whazzup/i',$host)) {
161
+            } else if (preg_match('/whazzup/i', $host)) {
162 162
         	//$formats[$id] = 'whazzup';
163 163
         	$globalSources[$id]['format'] = 'whazzup';
164 164
         	//$last_exec['whazzup'] = 0;
165 165
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
166
-            } else if (preg_match('/recentpireps/i',$host)) {
166
+            } else if (preg_match('/recentpireps/i', $host)) {
167 167
         	//$formats[$id] = 'pirepsjson';
168 168
         	$globalSources[$id]['format'] = 'pirepsjson';
169 169
         	//$last_exec['pirepsjson'] = 0;
170 170
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
171
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
171
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
172 172
         	//$formats[$id] = 'fr24json';
173 173
         	$globalSources[$id]['format'] = 'fr24json';
174 174
         	//$last_exec['fr24json'] = 0;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
178 178
         	    exit(0);
179 179
         	}
180
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
180
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
181 181
         	//$formats[$id] = 'fr24json';
182 182
         	$globalSources[$id]['format'] = 'myshiptracking';
183 183
         	//$last_exec['fr24json'] = 0;
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
         	    exit(0);
188 188
         	}
189 189
             //} else if (preg_match('/10001/',$host)) {
190
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
190
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191 191
         	//$formats[$id] = 'tsv';
192 192
         	$globalSources[$id]['format'] = 'tsv';
193 193
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
194 194
             }
195
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
195
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
196 196
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
197
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
197
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
198 198
     		    if ($idf !== false) {
199 199
     			$httpfeeds[$id] = $idf;
200 200
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
201 201
     		    }
202 202
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
203 203
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
204
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
205
-	    $hostport = explode(':',$host);
204
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
205
+	    $hostport = explode(':', $host);
206 206
 	    if (isset($hostport[1])) {
207 207
 		$port = $hostport[1];
208 208
 		$hostn = $hostport[0];
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 	    }
213 213
 	    $Common = new Common();
214 214
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
215
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
215
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
216 216
     	    } else {
217
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
217
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
218 218
 	    }
219 219
 	    if ($s) {
220 220
     	        $sockets[$id] = $s;
221 221
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
222
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
222
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
223 223
 			//$formats[$id] = 'aprs';
224 224
 			$globalSources[$id]['format'] = 'aprs';
225 225
 			//$aprs_connect = 0;
226 226
 			//$use_aprs = true;
227
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
227
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
228 228
 			$globalSources[$id]['format'] = 'vrstcp';
229 229
     		    } elseif ($port == '10001') {
230 230
         		//$formats[$id] = 'tsv';
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
264 264
 else $timeout = 20;
265 265
 $errno = '';
266
-$errstr='';
266
+$errstr = '';
267 267
 
268 268
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
269 269
 /* Initiate connections to all the hosts simultaneously */
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 //connect_all($globalSources);
272 272
 
273 273
 if (isset($globalProxy) && $globalProxy) {
274
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
274
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
275 275
 } else {
276 276
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
277 277
 }
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 
299 299
 if ($use_aprs) {
300 300
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
301
-	$APRS=new APRS();
301
+	$APRS = new APRS();
302 302
 	$aprs_connect = 0;
303 303
 	$aprs_keep = 120;
304 304
 	$aprs_last_tx = time();
305 305
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
306
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
306
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
307 307
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
308
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
308
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
309 309
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
310
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
310
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
311 311
 	if ($aprs_full) $aprs_filter = '';
312 312
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
313 313
 	else $aprs_pass = '-1';
@@ -322,12 +322,12 @@  discard block
 block discarded – undo
322 322
 sleep(1);
323 323
 if ($globalDebug) echo "SCAN MODE \n\n";
324 324
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
325
-$endtime = time()+$globalCronEnd;
325
+$endtime = time() + $globalCronEnd;
326 326
 $i = 1;
327 327
 $tt = array();
328 328
 // Delete all ATC
329 329
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
330
-	$ATC=new ATC($Connection->db);
330
+	$ATC = new ATC($Connection->db);
331 331
 }
332 332
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
333 333
 	$ATC->deleteAll();
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 
336 336
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
337 337
 while ($i > 0) {
338
-    if (!$globalDaemon) $i = $endtime-time();
338
+    if (!$globalDaemon) $i = $endtime - time();
339 339
     // Delete old ATC
340 340
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
341 341
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	}
351 351
 	if ($max != $globalMinFetch) {
352 352
 	    if ($globalDebug) echo 'Sleeping...'."\n";
353
-	    sleep($globalMinFetch-$max+2);
353
+	    sleep($globalMinFetch - $max + 2);
354 354
 	}
355 355
     }
356 356
 
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	    //$buffer = $Common->getData($hosts[$id]);
364 364
 	    $buffer = $Common->getData($value['host']);
365 365
 	    if ($buffer != '') $reset = 0;
366
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
367
-	    $buffer = explode('\n',$buffer);
366
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
367
+	    $buffer = explode('\n', $buffer);
368 368
 	    foreach ($buffer as $line) {
369 369
     		if ($line != '' && count($line) > 7) {
370 370
     		    $line = explode(',', $line);
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
     	    $last_exec[$id]['last'] = time();
392 392
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
393 393
 	    date_default_timezone_set('CET');
394
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
394
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
395 395
 	    date_default_timezone_set('UTC');
396 396
 	    if ($buffer != '') $reset = 0;
397
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
398
-	    $buffer = explode('\n',$buffer);
397
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
398
+	    $buffer = explode('\n', $buffer);
399 399
 	    foreach ($buffer as $line) {
400 400
 		if ($line != '') {
401 401
 		    echo "'".$line."'\n";
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
414 414
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
415 415
 		    if (isset($ais_data['timestamp'])) {
416
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
416
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
417 417
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
418 418
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
419 419
 			    $add = true;
@@ -436,12 +436,12 @@  discard block
 block discarded – undo
436 436
 	    $w = $e = null;
437 437
 	    
438 438
 	    if (isset($arr[$id])) {
439
-	    $nn = stream_select($arr,$w,$e,$timeout);
439
+	    $nn = stream_select($arr, $w, $e, $timeout);
440 440
 	    if ($nn > 0) {
441 441
 		foreach ($httpfeeds as $feed) {
442
-		    $buffer = stream_get_line($feed,2000,"\n");
443
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
444
-		    $buffer = explode('\n',$buffer);
442
+		    $buffer = stream_get_line($feed, 2000, "\n");
443
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
444
+		    $buffer = explode('\n', $buffer);
445 445
 		    foreach ($buffer as $line) {
446 446
 			if ($line != '') {
447 447
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -457,9 +457,9 @@  discard block
 block discarded – undo
457 457
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
458 458
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
459 459
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
460
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
460
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
461 461
 			    if (isset($ais_data['timestamp'])) {
462
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
462
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
463 463
 			    } else {
464 464
 				$data['datetime'] = date('Y-m-d H:i:s');
465 465
 			    }
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
 		}
474 474
 	    }
475 475
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
476
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
476
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
477 477
 	    if ($buffer != '') {
478 478
 		//echo $buffer;
479
-		$all_data = json_decode($buffer,true);
479
+		$all_data = json_decode($buffer, true);
480 480
 		//print_r($all_data);
481 481
 		if (isset($all_data[0]['DATA'])) {
482 482
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
492 492
 			$data['imo'] = $line['IMO'];
493 493
 			//$data['arrival_code'] = $ais_data['destination'];
494
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
494
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
495 495
 			$data['format_source'] = 'myshiptracking';
496 496
 			$data['id_source'] = $id_source;
497 497
 			$MI->add($data);
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 	    }
504 504
     	    $last_exec[$id]['last'] = time();
505 505
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
506
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
506
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
507 507
 	    if ($buffer != '') {
508
-		$all_data = json_decode($buffer,true);
508
+		$all_data = json_decode($buffer, true);
509 509
 		if (isset($all_data[0]['mmsi'])) {
510 510
 		    foreach ($all_data as $line) {
511 511
 			if ($line != '') {
@@ -532,27 +532,27 @@  discard block
 block discarded – undo
532 532
     	    $last_exec[$id]['last'] = time();
533 533
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
534 534
 	    echo 'download...';
535
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
535
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
536 536
 	    echo 'done !'."\n";
537 537
 	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
538
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
539
+	    $buffer = explode('\n', $buffer);
540 540
 	    foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542 542
 		    $data = array();
543
-		    $data['mmsi'] = (int)substr($line,0,9);
544
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
+		    $data['mmsi'] = (int) substr($line, 0, 9);
544
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
545 545
 		    //$data['status'] = substr($line,21,2);
546 546
 		    //$data['type'] = substr($line,24,3);
547
-		    $data['latitude'] = substr($line,29,9);
548
-		    $data['longitude'] = substr($line,41,9);
549
-		    $data['speed'] = round(substr($line,51,5));
547
+		    $data['latitude'] = substr($line, 29, 9);
548
+		    $data['longitude'] = substr($line, 41, 9);
549
+		    $data['speed'] = round(substr($line, 51, 5));
550 550
 		    //$data['course'] = substr($line,57,5);
551
-		    $data['heading'] = round(substr($line,63,3));
551
+		    $data['heading'] = round(substr($line, 63, 3));
552 552
 		    //$data['draft'] = substr($line,67,4);
553 553
 		    //$data['length'] = substr($line,72,3);
554 554
 		    //$data['beam'] = substr($line,76,2);
555
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
555
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
556 556
 		    //$data['callsign'] = trim(substr($line,100,7);
557 557
 		    //$data['dest'] = substr($line,108,20);
558 558
 		    //$data['etaDate'] = substr($line,129,5);
@@ -570,8 +570,8 @@  discard block
 block discarded – undo
570 570
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
571 571
 	    //$buffer = $Common->getData($hosts[$id]);
572 572
 	    $buffer = $Common->getData($value['host']);
573
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
574
-	    $buffer = explode('\n',$buffer);
573
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
574
+	    $buffer = explode('\n', $buffer);
575 575
 	    $reset = 0;
576 576
 	    foreach ($buffer as $line) {
577 577
     		if ($line != '') {
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
583 583
 			$data['pilot_id'] = $line[1];
584 584
 			$data['pilot_name'] = $line[2];
585
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
585
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
586 586
 			$data['ident'] = $line[0]; // ident
587 587
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
588 588
 			$data['speed'] = $line[8]; // speed
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
599 599
 			//if (isset($line[37])) $data['last_update'] = $line[37];
600 600
 		        $data['departure_airport_icao'] = $line[11];
601
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
601
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
602 602
 		        $data['arrival_airport_icao'] = $line[13];
603 603
 			$data['frequency'] = $line[4];
604 604
 			$data['type'] = $line[18];
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
     			$data['id_source'] = $id_source;
608 608
 	    		//$data['arrival_airport_time'] = ;
609 609
 	    		if ($line[9] != '') {
610
-	    		    $aircraft_data = explode('/',$line[9]);
610
+	    		    $aircraft_data = explode('/', $line[9]);
611 611
 	    		    if (isset($aircraft_data[1])) {
612 612
 	    			$data['aircraft_icao'] = $aircraft_data[1];
613 613
 	    		    }
@@ -621,9 +621,9 @@  discard block
 block discarded – undo
621 621
     			if ($line[3] == 'PILOT') $SI->add($data);
622 622
 			elseif ($line[3] == 'ATC') {
623 623
 				//print_r($data);
624
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
625
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
626
-				$typec = substr($data['ident'],-3);
624
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
625
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
626
+				$typec = substr($data['ident'], -3);
627 627
 				if ($typec == 'APP') $data['type'] = 'Approach';
628 628
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
629 629
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
635 635
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
636 636
 				if (!isset($data['source_name'])) $data['source_name'] = '';
637
-				if (isset($ATC)) 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']);
637
+				if (isset($ATC)) 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']);
638 638
 			}
639 639
     			unset($data);
640 640
     		    }
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
     	    $last_exec[$id]['last'] = time();
646 646
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
647 647
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
648
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
648
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
649 649
 	    if ($buffer != '') {
650
-	    $all_data = json_decode($buffer,true);
650
+	    $all_data = json_decode($buffer, true);
651 651
 	    if (isset($all_data['acList'])) {
652 652
 		$reset = 0;
653 653
 		foreach ($all_data['acList'] as $line) {
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
704 704
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705 705
 	    $buffer = $Common->getData($value['host']);
706
-	    $all_data = json_decode($buffer,true);
706
+	    $all_data = json_decode($buffer, true);
707 707
 	    if (isset($all_data['planes'])) {
708 708
 		$reset = 0;
709 709
 		foreach ($all_data['planes'] as $key => $line) {
@@ -720,12 +720,12 @@  discard block
 block discarded – undo
720 720
 		    $data['emergency'] = ''; // emergency
721 721
 		    $data['registration'] = $line[2];
722 722
 		    $data['aircraft_icao'] = $line[0];
723
-		    $deparr = explode('-',$line[1]);
723
+		    $deparr = explode('-', $line[1]);
724 724
 		    if (count($deparr) == 2) {
725 725
 			$data['departure_airport_icao'] = $deparr[0];
726 726
 			$data['arrival_airport_icao'] = $deparr[1];
727 727
 		    }
728
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
728
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
729 729
 	    	    $data['format_source'] = 'planeupdatefaa';
730 730
     		    $data['id_source'] = $id_source;
731 731
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
     	    $last_exec[$id]['last'] = time();
738 738
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
739 739
 	    $buffer = $Common->getData($value['host']);
740
-	    $all_data = json_decode($buffer,true);
740
+	    $all_data = json_decode($buffer, true);
741 741
 	    if (isset($all_data['states'])) {
742 742
 		$reset = 0;
743 743
 		foreach ($all_data['states'] as $key => $line) {
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 		    //$data['emergency'] = ''; // emergency
755 755
 		    //$data['registration'] = $line[2];
756 756
 		    //$data['aircraft_icao'] = $line[0];
757
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
757
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
758 758
 	    	    $data['format_source'] = 'opensky';
759 759
     		    $data['id_source'] = $id_source;
760 760
 		    $SI->add($data);
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
768 768
 	    //$buffer = $Common->getData($hosts[$id]);
769 769
 	    $buffer = $Common->getData($value['host']);
770
-	    $all_data = json_decode($buffer,true);
770
+	    $all_data = json_decode($buffer, true);
771 771
 	    if (!empty($all_data)) $reset = 0;
772 772
 	    foreach ($all_data as $key => $line) {
773 773
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -799,11 +799,11 @@  discard block
 block discarded – undo
799 799
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
800 800
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
801 801
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
802
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
802
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
803 803
 	    //echo $buffer;
804
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
805
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
806
-	    $all_data = json_decode($buffer,true);
804
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
805
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
806
+	    $all_data = json_decode($buffer, true);
807 807
 	    if (json_last_error() != JSON_ERROR_NONE) {
808 808
 		die(json_last_error_msg());
809 809
 	    }
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 			//$data['departure_airport_iata'] = $line[11];
827 827
 			//$data['arrival_airport_iata'] = $line[12];
828 828
 	    		//$data['emergency'] = ''; // emergency
829
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
829
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
830 830
 	    		$data['format_source'] = 'radarvirtueljson';
831 831
     			$data['id_source'] = $id_source;
832 832
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -841,14 +841,14 @@  discard block
 block discarded – undo
841 841
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
842 842
 	    //$buffer = $Common->getData($hosts[$id]);
843 843
 	    $buffer = $Common->getData($value['host'].'?'.time());
844
-	    $all_data = json_decode(utf8_encode($buffer),true);
844
+	    $all_data = json_decode(utf8_encode($buffer), true);
845 845
 	    
846 846
 	    if (isset($all_data['pireps'])) {
847 847
 		$reset = 0;
848 848
 	        foreach ($all_data['pireps'] as $line) {
849 849
 		    $data = array();
850 850
 		    $data['id'] = $line['id'];
851
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
851
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
852 852
 		    $data['ident'] = $line['callsign']; // ident
853 853
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
854 854
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -877,9 +877,9 @@  discard block
 block discarded – undo
877 877
 			$SI->add($data);
878 878
 		    //    print_r($data);
879 879
     		    } elseif ($line['icon'] == 'ct') {
880
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
881
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
882
-			$typec = substr($data['ident'],-3);
880
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
881
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
882
+			$typec = substr($data['ident'], -3);
883 883
 			$data['type'] = '';
884 884
 			if ($typec == 'APP') $data['type'] = 'Approach';
885 885
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
891 891
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
892 892
 			else $data['type'] = 'Observer';
893
-			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']);
893
+			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']);
894 894
 		    }
895 895
 		    unset($data);
896 896
 		}
@@ -902,14 +902,14 @@  discard block
 block discarded – undo
902 902
 	    //$buffer = $Common->getData($hosts[$id]);
903 903
 	    if ($globalDebug) echo 'Get Data...'."\n";
904 904
 	    $buffer = $Common->getData($value['host']);
905
-	    $all_data = json_decode($buffer,true);
905
+	    $all_data = json_decode($buffer, true);
906 906
 	    if ($buffer != '' && is_array($all_data)) {
907 907
 		$reset = 0;
908 908
 		foreach ($all_data as $line) {
909 909
 	    	    $data = array();
910 910
 	    	    //$data['id'] = $line['id']; // id not usable
911 911
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
912
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
912
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
913 913
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
914 914
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
915 915
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -932,12 +932,12 @@  discard block
 block discarded – undo
932 932
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
933 933
 		    if (isset($line['aircraftname'])) {
934 934
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
935
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
936
-	    		$aircraft_data = explode('-',$line['aircraftname']);
935
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
936
+	    		$aircraft_data = explode('-', $line['aircraftname']);
937 937
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
938 938
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
939 939
 	    		else {
940
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
940
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
941 941
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
942 942
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
943 943
 	    		}
@@ -959,14 +959,14 @@  discard block
 block discarded – undo
959 959
 	    //$buffer = $Common->getData($hosts[$id]);
960 960
 	    if ($globalDebug) echo 'Get Data...'."\n";
961 961
 	    $buffer = $Common->getData($value['host']);
962
-	    $all_data = json_decode($buffer,true);
962
+	    $all_data = json_decode($buffer, true);
963 963
 	    if ($buffer != '' && is_array($all_data)) {
964 964
 		$reset = 0;
965 965
 		foreach ($all_data as $line) {
966 966
 	    	    $data = array();
967 967
 	    	    //$data['id'] = $line['id']; // id not usable
968 968
 	    	    $data['id'] = trim($line['flight_id']);
969
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
969
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
970 970
 	    	    $data['pilot_name'] = $line['pilot_name'];
971 971
 	    	    $data['pilot_id'] = $line['pilot_id'];
972 972
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1017,9 +1017,9 @@  discard block
 block discarded – undo
1017 1017
 		    //$value = $formats[$nb];
1018 1018
 		    $format = $globalSources[$nb]['format'];
1019 1019
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1020
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1020
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1021 1021
         	    } else {
1022
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1022
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1023 1023
 	    	    }
1024 1024
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1025 1025
         	    //echo $buffer."\n";
@@ -1028,8 +1028,8 @@  discard block
 block discarded – undo
1028 1028
 		    $error = false;
1029 1029
 		    //$SI::del();
1030 1030
 		    if ($format == 'vrstcp') {
1031
-			$buffer = explode('},{',$buffer);
1032
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1031
+			$buffer = explode('},{', $buffer);
1032
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1033 1033
 		    // SBS format is CSV format
1034 1034
 		    if ($buffer != '') {
1035 1035
 			$tt[$format] = 0;
@@ -1061,10 +1061,10 @@  discard block
 block discarded – undo
1061 1061
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1062 1062
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1063 1063
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1064
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1064
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1065 1065
 
1066 1066
 			    if (isset($ais_data['timestamp'])) {
1067
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1067
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1068 1068
 			    } else {
1069 1069
 				$data['datetime'] = date('Y-m-d H:i:s');
1070 1070
 			    }
@@ -1075,10 +1075,10 @@  discard block
 block discarded – undo
1075 1075
                         } elseif ($format == 'flightgearsp') {
1076 1076
                     	    //echo $buffer."\n";
1077 1077
                     	    if (strlen($buffer) > 5) {
1078
-				$line = explode(',',$buffer);
1078
+				$line = explode(',', $buffer);
1079 1079
 				$data = array();
1080 1080
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1081
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1081
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1082 1082
 				$data['ident'] = $line[6];
1083 1083
 				$data['aircraft_name'] = $line[7];
1084 1084
 				$data['longitude'] = $line[1];
@@ -1089,21 +1089,21 @@  discard block
 block discarded – undo
1089 1089
 				$data['datetime'] = date('Y-m-d H:i:s');
1090 1090
 				$data['format_source'] = 'flightgearsp';
1091 1091
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1092
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1092
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1093 1093
 			    }
1094 1094
                         } elseif ($format == 'acars') {
1095 1095
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1096 1096
 			    $ACARS->add(trim($buffer));
1097
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1097
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1098 1098
 			    $ACARS->deleteLiveAcarsData();
1099 1099
 			} elseif ($format == 'flightgearmp') {
1100
-			    if (substr($buffer,0,1) != '#') {
1100
+			    if (substr($buffer, 0, 1) != '#') {
1101 1101
 				$data = array();
1102 1102
 				//echo $buffer."\n";
1103
-				$line = explode(' ',$buffer);
1103
+				$line = explode(' ', $buffer);
1104 1104
 				if (count($line) == 11) {
1105
-				    $userserver = explode('@',$line[0]);
1106
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1105
+				    $userserver = explode('@', $line[0]);
1106
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1107 1107
 				    $data['ident'] = $userserver[0];
1108 1108
 				    $data['registration'] = $userserver[0];
1109 1109
 				    $data['latitude'] = $line[4];
@@ -1111,8 +1111,8 @@  discard block
 block discarded – undo
1111 1111
 				    $data['altitude'] = $line[6];
1112 1112
 				    $data['datetime'] = date('Y-m-d H:i:s');
1113 1113
 				    $aircraft_type = $line[10];
1114
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1115
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1114
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1115
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1116 1116
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1117 1117
 				}
1118 1118
 			    }
@@ -1120,8 +1120,8 @@  discard block
 block discarded – undo
1120 1120
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1121 1121
 			    die;
1122 1122
 			} elseif ($format == 'vrstcp') {
1123
-			    foreach($buffer as $all_data) {
1124
-				$line = json_decode('{'.$all_data.'}',true);
1123
+			    foreach ($buffer as $all_data) {
1124
+				$line = json_decode('{'.$all_data.'}', true);
1125 1125
 				$data = array();
1126 1126
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1127 1127
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1146,16 +1146,16 @@  discard block
 block discarded – undo
1146 1146
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1147 1147
 				unset($data);
1148 1148
 			    }
1149
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1149
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1150 1150
 			    $line = explode("\t", $buffer);
1151
-			    for($k = 0; $k < count($line); $k=$k+2) {
1151
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1152 1152
 				$key = $line[$k];
1153
-			        $lined[$key] = $line[$k+1];
1153
+			        $lined[$key] = $line[$k + 1];
1154 1154
 			    }
1155 1155
     			    if (count($lined) > 3) {
1156 1156
     				$data['hex'] = $lined['hexid'];
1157 1157
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1158
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1158
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1159 1159
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1160 1160
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1161 1161
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1173,22 +1173,22 @@  discard block
 block discarded – undo
1173 1173
     			    } else $error = true;
1174 1174
 			} elseif ($format == 'aprs' && $use_aprs) {
1175 1175
 			    if ($aprs_connect == 0) {
1176
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1176
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1177 1177
 				$aprs_connect = 1;
1178 1178
 			    }
1179 1179
 			    
1180
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1180
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1181 1181
 				$aprs_last_tx = time();
1182 1182
 				$data_aprs = "# Keep alive";
1183
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1183
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1184 1184
 			    }
1185 1185
 			    
1186 1186
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1187 1187
 			    //echo 'APRS data : '.$buffer."\n";
1188
-			    $buffer = str_replace('APRS <- ','',$buffer);
1189
-			    $buffer = str_replace('APRS -> ','',$buffer);
1188
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1189
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1190 1190
 			    //echo $buffer."\n";
1191
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1191
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1192 1192
 				$line = $APRS->parse($buffer);
1193 1193
 				//print_r($line);
1194 1194
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 				    $data = array();
1198 1198
 				    //print_r($line);
1199 1199
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1200
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1200
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1201 1201
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1202 1202
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1203 1203
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 				    $currentdate = date('Y-m-d H:i:s');
1224 1224
 				    $aprsdate = strtotime($data['datetime']);
1225 1225
 				    // Accept data if time <= system time + 20s
1226
-				    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'])))) {
1226
+				    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'])))) {
1227 1227
 					$send = $SI->add($data);
1228 1228
 				    } elseif (isset($line['stealth'])) {
1229 1229
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1320,7 +1320,7 @@  discard block
 block discarded – undo
1320 1320
 				connect_all($sourceee);
1321 1321
 				$sourceee = array();
1322 1322
 				//connect_all($globalSources);
1323
-				$tt[$format]=0;
1323
+				$tt[$format] = 0;
1324 1324
 				break;
1325 1325
 			    }
1326 1326
 			}
@@ -1329,14 +1329,14 @@  discard block
 block discarded – undo
1329 1329
 	    } else {
1330 1330
 		$error = socket_strerror(socket_last_error());
1331 1331
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1332
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1332
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1333 1333
 			if (isset($globalDebug)) echo "Restarting...\n";
1334 1334
 			// Restart the script if possible
1335 1335
 			if (is_array($sockets)) {
1336 1336
 			    if ($globalDebug) echo "Shutdown all sockets...";
1337 1337
 			    
1338 1338
 			    foreach ($sockets as $sock) {
1339
-				@socket_shutdown($sock,2);
1339
+				@socket_shutdown($sock, 2);
1340 1340
 				@socket_close($sock);
1341 1341
 			    }
1342 1342
 			    
Please login to merge, or discard this patch.