Completed
Push — master ( 637110...04cc20 )
by Yannick
07:26
created
scripts/daemon-spotter.php 1 patch
Spacing   +132 added lines, -132 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::'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::'));
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'])) {
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
 else $id_source = 1;
66 66
 if (isset($globalServer) && $globalServer) {
67 67
     if ($globalDebug) echo "Using Server Mode\n";
68
-    $SI=new SpotterServer();
68
+    $SI = new SpotterServer();
69 69
 /*
70 70
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
71 71
     $SI = new adsb2aprs();
72 72
     $SI->connect();
73 73
 */
74
-} else $SI=new SpotterImport($Connection->db);
74
+} else $SI = new SpotterImport($Connection->db);
75 75
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
76 76
 if (isset($globalMarine) && $globalMarine) {
77 77
     $AIS = new AIS();
78 78
     $MI = new MarineImport($Connection->db);
79 79
 }
80 80
 //$APRS=new APRS($Connection->db);
81
-$SBS=new SBS();
82
-$ACARS=new ACARS($Connection->db);
83
-$Common=new Common();
81
+$SBS = new SBS();
82
+$ACARS = new ACARS($Connection->db);
83
+$Common = new Common();
84 84
 date_default_timezone_set('UTC');
85 85
 //$servertz = system('date +%Z');
86 86
 // signal handler - playing nice with sockets and dump1090
87 87
 if (function_exists('pcntl_fork')) {
88
-    pcntl_signal(SIGINT,  function() {
88
+    pcntl_signal(SIGINT, function() {
89 89
         global $sockets;
90 90
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
91 91
         die("Bye!\n");
@@ -101,35 +101,35 @@  discard block
 block discarded – undo
101 101
 
102 102
 function connect_all($hosts) {
103 103
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
104
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
105 105
     $reset++;
106 106
     if ($globalDebug) echo 'Connect to all...'."\n";
107 107
     foreach ($hosts as $id => $value) {
108 108
 	$host = $value['host'];
109 109
 	$globalSources[$id]['last_exec'] = 0;
110 110
 	// Here we check type of source(s)
111
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
-            if (preg_match('/deltadb.txt$/i',$host)) {
111
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
+            if (preg_match('/deltadb.txt$/i', $host)) {
113 113
         	//$formats[$id] = 'deltadbtxt';
114 114
         	$globalSources[$id]['format'] = 'deltadbtxt';
115 115
         	//$last_exec['deltadbtxt'] = 0;
116 116
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
118 118
         	//$formats[$id] = 'vatsimtxt';
119 119
         	$globalSources[$id]['format'] = 'vatsimtxt';
120 120
         	//$last_exec['vatsimtxt'] = 0;
121 121
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
123 123
         	//$formats[$id] = 'aircraftlistjson';
124 124
         	$globalSources[$id]['format'] = 'aircraftlistjson';
125 125
         	//$last_exec['aircraftlistjson'] = 0;
126 126
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
-    	    } else if (preg_match('/opensky/i',$host)) {
127
+    	    } else if (preg_match('/opensky/i', $host)) {
128 128
         	//$formats[$id] = 'aircraftlistjson';
129 129
         	$globalSources[$id]['format'] = 'opensky';
130 130
         	//$last_exec['aircraftlistjson'] = 0;
131 131
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
132
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
133 133
         	//$formats[$id] = 'radarvirtueljson';
134 134
         	$globalSources[$id]['format'] = 'radarvirtueljson';
135 135
         	//$last_exec['radarvirtueljson'] = 0;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
139 139
         	    exit(0);
140 140
         	}
141
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
142 142
         	//$formats[$id] = 'planeupdatefaa';
143 143
         	$globalSources[$id]['format'] = 'planeupdatefaa';
144 144
         	//$last_exec['planeupdatefaa'] = 0;
@@ -147,26 +147,26 @@  discard block
 block discarded – undo
147 147
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
148 148
         	    exit(0);
149 149
         	}
150
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
151 151
         	//$formats[$id] = 'phpvmacars';
152 152
         	$globalSources[$id]['format'] = 'phpvmacars';
153 153
         	//$last_exec['phpvmacars'] = 0;
154 154
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
155
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
156 156
         	//$formats[$id] = 'phpvmacars';
157 157
         	$globalSources[$id]['format'] = 'vam';
158 158
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
159
-            } else if (preg_match('/whazzup/i',$host)) {
159
+            } else if (preg_match('/whazzup/i', $host)) {
160 160
         	//$formats[$id] = 'whazzup';
161 161
         	$globalSources[$id]['format'] = 'whazzup';
162 162
         	//$last_exec['whazzup'] = 0;
163 163
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
164
-            } else if (preg_match('/recentpireps/i',$host)) {
164
+            } else if (preg_match('/recentpireps/i', $host)) {
165 165
         	//$formats[$id] = 'pirepsjson';
166 166
         	$globalSources[$id]['format'] = 'pirepsjson';
167 167
         	//$last_exec['pirepsjson'] = 0;
168 168
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
169
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
170 170
         	//$formats[$id] = 'fr24json';
171 171
         	$globalSources[$id]['format'] = 'fr24json';
172 172
         	//$last_exec['fr24json'] = 0;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
176 176
         	    exit(0);
177 177
         	}
178
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
179 179
         	//$formats[$id] = 'fr24json';
180 180
         	$globalSources[$id]['format'] = 'myshiptracking';
181 181
         	//$last_exec['fr24json'] = 0;
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
         	    exit(0);
186 186
         	}
187 187
             //} else if (preg_match('/10001/',$host)) {
188
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
189 189
         	//$formats[$id] = 'tsv';
190 190
         	$globalSources[$id]['format'] = 'tsv';
191 191
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
192 192
             }
193
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
194 194
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
195
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
196 196
     		    if ($idf !== false) {
197 197
     			$httpfeeds[$id] = $idf;
198 198
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
199 199
     		    }
200 200
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
201 201
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
202
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
203
-	    $hostport = explode(':',$host);
202
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
203
+	    $hostport = explode(':', $host);
204 204
 	    if (isset($hostport[1])) {
205 205
 		$port = $hostport[1];
206 206
 		$hostn = $hostport[0];
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 	    }
211 211
 	    $Common = new Common();
212 212
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
213
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
214 214
     	    } else {
215
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
216 216
 	    }
217 217
 	    if ($s) {
218 218
     	        $sockets[$id] = $s;
219 219
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
220
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
221 221
 			//$formats[$id] = 'aprs';
222 222
 			$globalSources[$id]['format'] = 'aprs';
223 223
 			//$aprs_connect = 0;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
260 260
 else $timeout = 20;
261 261
 $errno = '';
262
-$errstr='';
262
+$errstr = '';
263 263
 
264 264
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
265 265
 /* Initiate connections to all the hosts simultaneously */
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 //connect_all($globalSources);
268 268
 
269 269
 if (isset($globalProxy) && $globalProxy) {
270
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
270
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
271 271
 } else {
272 272
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
273 273
 }
@@ -294,16 +294,16 @@  discard block
 block discarded – undo
294 294
 
295 295
 if ($use_aprs) {
296 296
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
297
-	$APRS=new APRS();
297
+	$APRS = new APRS();
298 298
 	$aprs_connect = 0;
299 299
 	$aprs_keep = 120;
300 300
 	$aprs_last_tx = time();
301 301
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
302
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
302
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
303 303
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
304
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
304
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
305 305
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
306
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
307 307
 	if ($aprs_full) $aprs_filter = '';
308 308
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
309 309
 	else $aprs_pass = '-1';
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 sleep(1);
319 319
 if ($globalDebug) echo "SCAN MODE \n\n";
320 320
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
321
-$endtime = time()+$globalCronEnd;
321
+$endtime = time() + $globalCronEnd;
322 322
 $i = 1;
323 323
 $tt = array();
324 324
 // Delete all ATC
325 325
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
326
-	$ATC=new ATC($Connection->db);
326
+	$ATC = new ATC($Connection->db);
327 327
 }
328 328
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
329 329
 	$ATC->deleteAll();
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 
332 332
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
333 333
 while ($i > 0) {
334
-    if (!$globalDaemon) $i = $endtime-time();
334
+    if (!$globalDaemon) $i = $endtime - time();
335 335
     // Delete old ATC
336 336
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
337 337
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	}
347 347
 	if ($max != $globalMinFetch) {
348 348
 	    if ($globalDebug) echo 'Sleeping...'."\n";
349
-	    sleep($globalMinFetch-$max+2);
349
+	    sleep($globalMinFetch - $max + 2);
350 350
 	}
351 351
     }
352 352
 
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
 	    //$buffer = $Common->getData($hosts[$id]);
360 360
 	    $buffer = $Common->getData($value['host']);
361 361
 	    if ($buffer != '') $reset = 0;
362
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
363
-	    $buffer = explode('\n',$buffer);
362
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
363
+	    $buffer = explode('\n', $buffer);
364 364
 	    foreach ($buffer as $line) {
365 365
     		if ($line != '' && count($line) > 7) {
366 366
     		    $line = explode(',', $line);
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
     	    $last_exec[$id]['last'] = time();
388 388
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
389 389
 	    date_default_timezone_set('CET');
390
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
391 391
 	    date_default_timezone_set('UTC');
392 392
 	    if ($buffer != '') $reset = 0;
393
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
394
-	    $buffer = explode('\n',$buffer);
393
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
394
+	    $buffer = explode('\n', $buffer);
395 395
 	    foreach ($buffer as $line) {
396 396
 		if ($line != '') {
397 397
 		    echo "'".$line."'\n";
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
410 410
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
411 411
 		    if (isset($ais_data['timestamp'])) {
412
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
412
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
413 413
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
414 414
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
415 415
 			    $add = true;
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
 	    $w = $e = null;
433 433
 	    
434 434
 	    if (isset($arr[$id])) {
435
-	    $nn = stream_select($arr,$w,$e,$timeout);
435
+	    $nn = stream_select($arr, $w, $e, $timeout);
436 436
 	    if ($nn > 0) {
437 437
 		foreach ($httpfeeds as $feed) {
438
-		    $buffer = stream_get_line($feed,2000,"\n");
439
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
440
-		    $buffer = explode('\n',$buffer);
438
+		    $buffer = stream_get_line($feed, 2000, "\n");
439
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
440
+		    $buffer = explode('\n', $buffer);
441 441
 		    foreach ($buffer as $line) {
442 442
 			if ($line != '') {
443 443
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
454 454
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
455 455
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
456
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
456
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
457 457
 			    if (isset($ais_data['timestamp'])) {
458
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
458
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
459 459
 			    } else {
460 460
 				$data['datetime'] = date('Y-m-d H:i:s');
461 461
 			    }
@@ -469,10 +469,10 @@  discard block
 block discarded – undo
469 469
 		}
470 470
 	    }
471 471
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
472
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
472
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
473 473
 	    if ($buffer != '') {
474 474
 		//echo $buffer;
475
-		$all_data = json_decode($buffer,true);
475
+		$all_data = json_decode($buffer, true);
476 476
 		//print_r($all_data);
477 477
 		if (isset($all_data[0]['DATA'])) {
478 478
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
488 488
 			$data['imo'] = $line['IMO'];
489 489
 			//$data['arrival_code'] = $ais_data['destination'];
490
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
490
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
491 491
 			$data['format_source'] = 'myshiptracking';
492 492
 			$data['id_source'] = $id_source;
493 493
 			$MI->add($data);
@@ -499,9 +499,9 @@  discard block
 block discarded – undo
499 499
 	    }
500 500
     	    $last_exec[$id]['last'] = time();
501 501
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
502
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
503 503
 	    if ($buffer != '') {
504
-		$all_data = json_decode($buffer,true);
504
+		$all_data = json_decode($buffer, true);
505 505
 		if (isset($all_data[0]['mmsi'])) {
506 506
 		    foreach ($all_data as $line) {
507 507
 			if ($line != '') {
@@ -528,27 +528,27 @@  discard block
 block discarded – undo
528 528
     	    $last_exec[$id]['last'] = time();
529 529
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
530 530
 	    echo 'download...';
531
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
532 532
 	    echo 'done !'."\n";
533 533
 	    if ($buffer != '') $reset = 0;
534
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
535
-	    $buffer = explode('\n',$buffer);
534
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
535
+	    $buffer = explode('\n', $buffer);
536 536
 	    foreach ($buffer as $line) {
537 537
 		if ($line != '') {
538 538
 		    $data = array();
539
-		    $data['mmsi'] = (int)substr($line,0,9);
540
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
539
+		    $data['mmsi'] = (int) substr($line, 0, 9);
540
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
541 541
 		    //$data['status'] = substr($line,21,2);
542 542
 		    //$data['type'] = substr($line,24,3);
543
-		    $data['latitude'] = substr($line,29,9);
544
-		    $data['longitude'] = substr($line,41,9);
545
-		    $data['speed'] = round(substr($line,51,5));
543
+		    $data['latitude'] = substr($line, 29, 9);
544
+		    $data['longitude'] = substr($line, 41, 9);
545
+		    $data['speed'] = round(substr($line, 51, 5));
546 546
 		    //$data['course'] = substr($line,57,5);
547
-		    $data['heading'] = round(substr($line,63,3));
547
+		    $data['heading'] = round(substr($line, 63, 3));
548 548
 		    //$data['draft'] = substr($line,67,4);
549 549
 		    //$data['length'] = substr($line,72,3);
550 550
 		    //$data['beam'] = substr($line,76,2);
551
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
551
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
552 552
 		    //$data['callsign'] = trim(substr($line,100,7);
553 553
 		    //$data['dest'] = substr($line,108,20);
554 554
 		    //$data['etaDate'] = substr($line,129,5);
@@ -566,8 +566,8 @@  discard block
 block discarded – undo
566 566
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
567 567
 	    //$buffer = $Common->getData($hosts[$id]);
568 568
 	    $buffer = $Common->getData($value['host']);
569
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
570
-	    $buffer = explode('\n',$buffer);
569
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
570
+	    $buffer = explode('\n', $buffer);
571 571
 	    $reset = 0;
572 572
 	    foreach ($buffer as $line) {
573 573
     		if ($line != '') {
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
579 579
 			$data['pilot_id'] = $line[1];
580 580
 			$data['pilot_name'] = $line[2];
581
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
581
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
582 582
 			$data['ident'] = $line[0]; // ident
583 583
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
584 584
 			$data['speed'] = $line[8]; // speed
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
595 595
 			//if (isset($line[37])) $data['last_update'] = $line[37];
596 596
 		        $data['departure_airport_icao'] = $line[11];
597
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
597
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
598 598
 		        $data['arrival_airport_icao'] = $line[13];
599 599
 			$data['frequency'] = $line[4];
600 600
 			$data['type'] = $line[18];
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     			$data['id_source'] = $id_source;
604 604
 	    		//$data['arrival_airport_time'] = ;
605 605
 	    		if ($line[9] != '') {
606
-	    		    $aircraft_data = explode('/',$line[9]);
606
+	    		    $aircraft_data = explode('/', $line[9]);
607 607
 	    		    if (isset($aircraft_data[1])) {
608 608
 	    			$data['aircraft_icao'] = $aircraft_data[1];
609 609
 	    		    }
@@ -617,9 +617,9 @@  discard block
 block discarded – undo
617 617
     			if ($line[3] == 'PILOT') $SI->add($data);
618 618
 			elseif ($line[3] == 'ATC') {
619 619
 				//print_r($data);
620
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
621
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
622
-				$typec = substr($data['ident'],-3);
620
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
621
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
622
+				$typec = substr($data['ident'], -3);
623 623
 				if ($typec == 'APP') $data['type'] = 'Approach';
624 624
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
625 625
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
631 631
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
632 632
 				if (!isset($data['source_name'])) $data['source_name'] = '';
633
-				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']);
633
+				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']);
634 634
 			}
635 635
     			unset($data);
636 636
     		    }
@@ -641,9 +641,9 @@  discard block
 block discarded – undo
641 641
     	    $last_exec[$id]['last'] = time();
642 642
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
643 643
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
644
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
644
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
645 645
 	    if ($buffer != '') {
646
-	    $all_data = json_decode($buffer,true);
646
+	    $all_data = json_decode($buffer, true);
647 647
 	    if (isset($all_data['acList'])) {
648 648
 		$reset = 0;
649 649
 		foreach ($all_data['acList'] as $line) {
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
700 700
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
701 701
 	    $buffer = $Common->getData($value['host']);
702
-	    $all_data = json_decode($buffer,true);
702
+	    $all_data = json_decode($buffer, true);
703 703
 	    if (isset($all_data['planes'])) {
704 704
 		$reset = 0;
705 705
 		foreach ($all_data['planes'] as $key => $line) {
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
 		    $data['emergency'] = ''; // emergency
717 717
 		    $data['registration'] = $line[2];
718 718
 		    $data['aircraft_icao'] = $line[0];
719
-		    $deparr = explode('-',$line[1]);
719
+		    $deparr = explode('-', $line[1]);
720 720
 		    if (count($deparr) == 2) {
721 721
 			$data['departure_airport_icao'] = $deparr[0];
722 722
 			$data['arrival_airport_icao'] = $deparr[1];
723 723
 		    }
724
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
725 725
 	    	    $data['format_source'] = 'planeupdatefaa';
726 726
     		    $data['id_source'] = $id_source;
727 727
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
     	    $last_exec[$id]['last'] = time();
734 734
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
735 735
 	    $buffer = $Common->getData($value['host']);
736
-	    $all_data = json_decode($buffer,true);
736
+	    $all_data = json_decode($buffer, true);
737 737
 	    if (isset($all_data['states'])) {
738 738
 		$reset = 0;
739 739
 		foreach ($all_data['states'] as $key => $line) {
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 		    //$data['emergency'] = ''; // emergency
751 751
 		    //$data['registration'] = $line[2];
752 752
 		    //$data['aircraft_icao'] = $line[0];
753
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
753
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
754 754
 	    	    $data['format_source'] = 'opensky';
755 755
     		    $data['id_source'] = $id_source;
756 756
 		    $SI->add($data);
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
764 764
 	    //$buffer = $Common->getData($hosts[$id]);
765 765
 	    $buffer = $Common->getData($value['host']);
766
-	    $all_data = json_decode($buffer,true);
766
+	    $all_data = json_decode($buffer, true);
767 767
 	    if (!empty($all_data)) $reset = 0;
768 768
 	    foreach ($all_data as $key => $line) {
769 769
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -795,11 +795,11 @@  discard block
 block discarded – undo
795 795
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
796 796
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
797 797
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
798
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
798
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
799 799
 	    //echo $buffer;
800
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
801
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
802
-	    $all_data = json_decode($buffer,true);
800
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
801
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
802
+	    $all_data = json_decode($buffer, true);
803 803
 	    if (json_last_error() != JSON_ERROR_NONE) {
804 804
 		die(json_last_error_msg());
805 805
 	    }
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 			//$data['departure_airport_iata'] = $line[11];
823 823
 			//$data['arrival_airport_iata'] = $line[12];
824 824
 	    		//$data['emergency'] = ''; // emergency
825
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
825
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
826 826
 	    		$data['format_source'] = 'radarvirtueljson';
827 827
     			$data['id_source'] = $id_source;
828 828
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -837,14 +837,14 @@  discard block
 block discarded – undo
837 837
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
838 838
 	    //$buffer = $Common->getData($hosts[$id]);
839 839
 	    $buffer = $Common->getData($value['host'].'?'.time());
840
-	    $all_data = json_decode(utf8_encode($buffer),true);
840
+	    $all_data = json_decode(utf8_encode($buffer), true);
841 841
 	    
842 842
 	    if (isset($all_data['pireps'])) {
843 843
 		$reset = 0;
844 844
 	        foreach ($all_data['pireps'] as $line) {
845 845
 		    $data = array();
846 846
 		    $data['id'] = $line['id'];
847
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
848 848
 		    $data['ident'] = $line['callsign']; // ident
849 849
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
850 850
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -873,9 +873,9 @@  discard block
 block discarded – undo
873 873
 			$SI->add($data);
874 874
 		    //    print_r($data);
875 875
     		    } elseif ($line['icon'] == 'ct') {
876
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
877
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
878
-			$typec = substr($data['ident'],-3);
876
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
877
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
878
+			$typec = substr($data['ident'], -3);
879 879
 			$data['type'] = '';
880 880
 			if ($typec == 'APP') $data['type'] = 'Approach';
881 881
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
887 887
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
888 888
 			else $data['type'] = 'Observer';
889
-			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']);
889
+			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']);
890 890
 		    }
891 891
 		    unset($data);
892 892
 		}
@@ -898,14 +898,14 @@  discard block
 block discarded – undo
898 898
 	    //$buffer = $Common->getData($hosts[$id]);
899 899
 	    if ($globalDebug) echo 'Get Data...'."\n";
900 900
 	    $buffer = $Common->getData($value['host']);
901
-	    $all_data = json_decode($buffer,true);
901
+	    $all_data = json_decode($buffer, true);
902 902
 	    if ($buffer != '' && is_array($all_data)) {
903 903
 		$reset = 0;
904 904
 		foreach ($all_data as $line) {
905 905
 	    	    $data = array();
906 906
 	    	    //$data['id'] = $line['id']; // id not usable
907 907
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
908
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
909 909
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
910 910
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
911 911
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -928,12 +928,12 @@  discard block
 block discarded – undo
928 928
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
929 929
 		    if (isset($line['aircraftname'])) {
930 930
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
931
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
932
-	    		$aircraft_data = explode('-',$line['aircraftname']);
931
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
932
+	    		$aircraft_data = explode('-', $line['aircraftname']);
933 933
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
934 934
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
935 935
 	    		else {
936
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
936
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
937 937
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
938 938
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
939 939
 	    		}
@@ -955,14 +955,14 @@  discard block
 block discarded – undo
955 955
 	    //$buffer = $Common->getData($hosts[$id]);
956 956
 	    if ($globalDebug) echo 'Get Data...'."\n";
957 957
 	    $buffer = $Common->getData($value['host']);
958
-	    $all_data = json_decode($buffer,true);
958
+	    $all_data = json_decode($buffer, true);
959 959
 	    if ($buffer != '' && is_array($all_data)) {
960 960
 		$reset = 0;
961 961
 		foreach ($all_data as $line) {
962 962
 	    	    $data = array();
963 963
 	    	    //$data['id'] = $line['id']; // id not usable
964 964
 	    	    $data['id'] = trim($line['flight_id']);
965
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
965
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
966 966
 	    	    $data['pilot_name'] = $line['pilot_name'];
967 967
 	    	    $data['pilot_id'] = $line['pilot_id'];
968 968
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1013,9 +1013,9 @@  discard block
 block discarded – undo
1013 1013
 		    //$value = $formats[$nb];
1014 1014
 		    $format = $globalSources[$nb]['format'];
1015 1015
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1016
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1016
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1017 1017
         	    } else {
1018
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1018
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1019 1019
 	    	    }
1020 1020
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1021 1021
         	    //echo $buffer."\n";
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1024 1024
 		    $error = false;
1025 1025
 		    //$SI::del();
1026
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1026
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1027 1027
 		    // SBS format is CSV format
1028 1028
 		    if ($buffer != '') {
1029 1029
 			$tt[$format] = 0;
@@ -1055,10 +1055,10 @@  discard block
 block discarded – undo
1055 1055
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1056 1056
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1057 1057
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1058
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1058
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1059 1059
 
1060 1060
 			    if (isset($ais_data['timestamp'])) {
1061
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1061
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1062 1062
 			    } else {
1063 1063
 				$data['datetime'] = date('Y-m-d H:i:s');
1064 1064
 			    }
@@ -1069,10 +1069,10 @@  discard block
 block discarded – undo
1069 1069
                         } elseif ($format == 'flightgearsp') {
1070 1070
                     	    //echo $buffer."\n";
1071 1071
                     	    if (strlen($buffer) > 5) {
1072
-				$line = explode(',',$buffer);
1072
+				$line = explode(',', $buffer);
1073 1073
 				$data = array();
1074 1074
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1075
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1075
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1076 1076
 				$data['ident'] = $line[6];
1077 1077
 				$data['aircraft_name'] = $line[7];
1078 1078
 				$data['longitude'] = $line[1];
@@ -1083,21 +1083,21 @@  discard block
 block discarded – undo
1083 1083
 				$data['datetime'] = date('Y-m-d H:i:s');
1084 1084
 				$data['format_source'] = 'flightgearsp';
1085 1085
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1086
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1086
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1087 1087
 			    }
1088 1088
                         } elseif ($format == 'acars') {
1089 1089
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1090 1090
 			    $ACARS->add(trim($buffer));
1091
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1092 1092
 			    $ACARS->deleteLiveAcarsData();
1093 1093
 			} elseif ($format == 'flightgearmp') {
1094
-			    if (substr($buffer,0,1) != '#') {
1094
+			    if (substr($buffer, 0, 1) != '#') {
1095 1095
 				$data = array();
1096 1096
 				//echo $buffer."\n";
1097
-				$line = explode(' ',$buffer);
1097
+				$line = explode(' ', $buffer);
1098 1098
 				if (count($line) == 11) {
1099
-				    $userserver = explode('@',$line[0]);
1100
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1099
+				    $userserver = explode('@', $line[0]);
1100
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1101 1101
 				    $data['ident'] = $userserver[0];
1102 1102
 				    $data['registration'] = $userserver[0];
1103 1103
 				    $data['latitude'] = $line[4];
@@ -1105,24 +1105,24 @@  discard block
 block discarded – undo
1105 1105
 				    $data['altitude'] = $line[6];
1106 1106
 				    $data['datetime'] = date('Y-m-d H:i:s');
1107 1107
 				    $aircraft_type = $line[10];
1108
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1109
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1108
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1109
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1110 1110
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1111 1111
 				}
1112 1112
 			    }
1113 1113
 			} elseif ($format == 'beast') {
1114 1114
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1115 1115
 			    die;
1116
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1116
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1117 1117
 			    $line = explode("\t", $buffer);
1118
-			    for($k = 0; $k < count($line); $k=$k+2) {
1118
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1119 1119
 				$key = $line[$k];
1120
-			        $lined[$key] = $line[$k+1];
1120
+			        $lined[$key] = $line[$k + 1];
1121 1121
 			    }
1122 1122
     			    if (count($lined) > 3) {
1123 1123
     				$data['hex'] = $lined['hexid'];
1124 1124
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1125
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1125
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1126 1126
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1127 1127
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1128 1128
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1140,22 +1140,22 @@  discard block
 block discarded – undo
1140 1140
     			    } else $error = true;
1141 1141
 			} elseif ($format == 'aprs' && $use_aprs) {
1142 1142
 			    if ($aprs_connect == 0) {
1143
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1143
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1144 1144
 				$aprs_connect = 1;
1145 1145
 			    }
1146 1146
 			    
1147
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1147
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1148 1148
 				$aprs_last_tx = time();
1149 1149
 				$data_aprs = "# Keep alive";
1150
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1150
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1151 1151
 			    }
1152 1152
 			    
1153 1153
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1154 1154
 			    //echo 'APRS data : '.$buffer."\n";
1155
-			    $buffer = str_replace('APRS <- ','',$buffer);
1156
-			    $buffer = str_replace('APRS -> ','',$buffer);
1155
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1156
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1157 1157
 			    echo $buffer."\n";
1158
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1158
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1159 1159
 				$line = $APRS->parse($buffer);
1160 1160
 				//print_r($line);
1161 1161
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
 				    $data = array();
1165 1165
 				    //print_r($line);
1166 1166
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1167
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1168 1168
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1169 1169
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1170 1170
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 				    $currentdate = date('Y-m-d H:i:s');
1191 1191
 				    $aprsdate = strtotime($data['datetime']);
1192 1192
 				    // Accept data if time <= system time + 20s
1193
-				    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'])))) {
1193
+				    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'])))) {
1194 1194
 					$send = $SI->add($data);
1195 1195
 				    } elseif (isset($line['stealth'])) {
1196 1196
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 				connect_all($sourceee);
1288 1288
 				$sourceee = array();
1289 1289
 				//connect_all($globalSources);
1290
-				$tt[$format]=0;
1290
+				$tt[$format] = 0;
1291 1291
 				break;
1292 1292
 			    }
1293 1293
 			}
@@ -1296,14 +1296,14 @@  discard block
 block discarded – undo
1296 1296
 	    } else {
1297 1297
 		$error = socket_strerror(socket_last_error());
1298 1298
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1299
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1299
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1300 1300
 			if (isset($globalDebug)) echo "Restarting...\n";
1301 1301
 			// Restart the script if possible
1302 1302
 			if (is_array($sockets)) {
1303 1303
 			    if ($globalDebug) echo "Shutdown all sockets...";
1304 1304
 			    
1305 1305
 			    foreach ($sockets as $sock) {
1306
-				@socket_shutdown($sock,2);
1306
+				@socket_shutdown($sock, 2);
1307 1307
 				@socket_close($sock);
1308 1308
 			    }
1309 1309
 			    
Please login to merge, or discard this patch.