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