Completed
Push — master ( 06f826...32823f )
by Yannick
68:39 queued 38:54
created
scripts/daemon-spotter.php 1 patch
Spacing   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,40 +150,40 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 152
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 156
     foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
+            if (preg_match('/deltadb.txt$/i', $host)) {
162 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
176
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftjson';
178 178
         	$globalSources[$id]['format'] = 'aircraftjson';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
180 180
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraft$/i',$host)) {
181
+    	    } else if (preg_match('/aircraft$/i', $host)) {
182 182
         	//$formats[$id] = 'planefinderclient';
183 183
         	$globalSources[$id]['format'] = 'planefinderclient';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
-    	    } else if (preg_match('/opensky/i',$host)) {
186
+    	    } else if (preg_match('/opensky/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftlistjson';
188 188
         	$globalSources[$id]['format'] = 'opensky';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         	    exit(0);
201 201
         	}
202 202
     	    */
203
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
203
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
204 204
         	//$formats[$id] = 'planeupdatefaa';
205 205
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 206
         	//$last_exec['planeupdatefaa'] = 0;
@@ -209,37 +209,37 @@  discard block
 block discarded – undo
209 209
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 210
         	    exit(0);
211 211
         	}
212
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
212
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'phpvmacars';
215 215
         	//$last_exec['phpvmacars'] = 0;
216 216
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
217
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
218 218
         	//$formats[$id] = 'phpvmacars';
219 219
         	$globalSources[$id]['format'] = 'vaos';
220 220
         	//$last_exec['phpvmacars'] = 0;
221 221
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
222
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'vam';
225 225
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
-            } else if (preg_match('/whazzup/i',$host)) {
226
+            } else if (preg_match('/whazzup/i', $host)) {
227 227
         	//$formats[$id] = 'whazzup';
228 228
         	$globalSources[$id]['format'] = 'whazzup';
229 229
         	//$last_exec['whazzup'] = 0;
230 230
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
-            } else if (preg_match('/blitzortung/i',$host)) {
231
+            } else if (preg_match('/blitzortung/i', $host)) {
232 232
         	$globalSources[$id]['format'] = 'blitzortung';
233 233
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
-            } else if (preg_match('/airwhere/i',$host)) {
234
+            } else if (preg_match('/airwhere/i', $host)) {
235 235
         	$globalSources[$id]['format'] = 'airwhere';
236 236
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
-            } else if (preg_match('/recentpireps/i',$host)) {
237
+            } else if (preg_match('/recentpireps/i', $host)) {
238 238
         	//$formats[$id] = 'pirepsjson';
239 239
         	$globalSources[$id]['format'] = 'pirepsjson';
240 240
         	//$last_exec['pirepsjson'] = 0;
241 241
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
242
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
243 243
         	//$formats[$id] = 'fr24json';
244 244
         	$globalSources[$id]['format'] = 'fr24json';
245 245
         	//$last_exec['fr24json'] = 0;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 249
         	    exit(0);
250 250
         	}
251
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
251
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
252 252
         	//$formats[$id] = 'fr24json';
253 253
         	$globalSources[$id]['format'] = 'myshiptracking';
254 254
         	//$last_exec['fr24json'] = 0;
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
         	    exit(0);
259 259
         	}
260 260
             //} else if (preg_match('/10001/',$host)) {
261
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
261
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 262
         	//$formats[$id] = 'tsv';
263 263
         	$globalSources[$id]['format'] = 'tsv';
264 264
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265 265
             }
266
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
266
+        } elseif (filter_var($host, FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway')) {
267 267
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
268
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
269 269
     		    if ($idf !== false) {
270 270
     			$httpfeeds[$id] = $idf;
271 271
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272 272
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273 273
     		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
274 274
     		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
276
-	    $hostport = explode(':',$host);
275
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
276
+	    $hostport = explode(':', $host);
277 277
 	    if (isset($hostport[1])) {
278 278
 		$port = $hostport[1];
279 279
 		$hostn = $hostport[0];
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	    }
284 284
 	    $Common = new Common();
285 285
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
286
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
286
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
287 287
     	    } else {
288
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
288
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
289 289
 	    }
290 290
 	    if ($s) {
291 291
     	        $sockets[$id] = $s;
292 292
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
293
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
293
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
294 294
 			//$formats[$id] = 'aprs';
295 295
 			$globalSources[$id]['format'] = 'aprs';
296 296
 			//$aprs_connect = 0;
297 297
 			//$use_aprs = true;
298
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
298
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
299 299
 			$globalSources[$id]['format'] = 'vrstcp';
300 300
     		    } elseif ($port == '10001') {
301 301
         		//$formats[$id] = 'tsv';
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
337 337
 else $timeout = 20;
338 338
 $errno = '';
339
-$errstr='';
339
+$errstr = '';
340 340
 
341 341
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
342 342
 /* Initiate connections to all the hosts simultaneously */
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 //connect_all($globalSources);
345 345
 
346 346
 if (isset($globalProxy) && $globalProxy) {
347
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
347
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
348 348
 } else {
349 349
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
350 350
 }
@@ -374,16 +374,16 @@  discard block
 block discarded – undo
374 374
 
375 375
 if ($use_aprs) {
376 376
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
377
-	$APRS=new APRS();
377
+	$APRS = new APRS();
378 378
 	$aprs_connect = 0;
379 379
 	$aprs_keep = 120;
380 380
 	$aprs_last_tx = time();
381 381
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
382
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
382
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
383 383
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
384
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
384
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
385 385
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
386
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
386
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
387 387
 	if ($aprs_full) $aprs_filter = '';
388 388
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
389 389
 	else $aprs_pass = '-1';
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
 sleep(1);
398 398
 if ($globalDebug) echo "SCAN MODE \n\n";
399 399
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
400
-$endtime = time()+$globalCronEnd;
400
+$endtime = time() + $globalCronEnd;
401 401
 $i = 1;
402 402
 $tt = array();
403 403
 // Delete all ATC
404 404
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
405
-	$ATC=new ATC($Connection->db);
405
+	$ATC = new ATC($Connection->db);
406 406
 }
407 407
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
408 408
 	$ATC->deleteAll();
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 while ($i > 0) {
413 413
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
414 414
 
415
-    if (!$globalDaemon) $i = $endtime-time();
415
+    if (!$globalDaemon) $i = $endtime - time();
416 416
     // Delete old ATC
417 417
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
418 418
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 	}
427 427
 	if ($max < $globalMinFetch) {
428 428
 	    if ($globalDebug) echo 'Sleeping...'."\n";
429
-	    sleep($globalMinFetch-$max+2);
429
+	    sleep($globalMinFetch - $max + 2);
430 430
 	}
431 431
     }
432 432
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	    //$buffer = $Common->getData($hosts[$id]);
446 446
 	    $buffer = $Common->getData($value['host']);
447 447
 	    if ($buffer != '') $reset = 0;
448
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
-	    $buffer = explode('\n',$buffer);
448
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
449
+	    $buffer = explode('\n', $buffer);
450 450
 	    foreach ($buffer as $line) {
451 451
     		if ($line != '' && count($line) > 7) {
452 452
     		    $line = explode(',', $line);
@@ -479,11 +479,11 @@  discard block
 block discarded – undo
479 479
 	    )
480 480
 	) {
481 481
 	    date_default_timezone_set('CET');
482
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
482
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
483 483
 	    date_default_timezone_set('UTC');
484 484
 	    if ($buffer != '') $reset = 0;
485
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486
-	    $buffer = explode('\n',$buffer);
485
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
486
+	    $buffer = explode('\n', $buffer);
487 487
 	    foreach ($buffer as $line) {
488 488
 		if ($line != '') {
489 489
 		    //echo "'".$line."'\n";
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 		    $ais_data = $AIS->parse_line(trim($line));
492 492
 		    $data = array();
493 493
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
494
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
494
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
495 495
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
496 496
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
497 497
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
504 504
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
505 505
 		    if (isset($ais_data['timestamp'])) {
506
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
506
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
507 507
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
508 508
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
509 509
 			    $add = true;
@@ -526,21 +526,21 @@  discard block
 block discarded – undo
526 526
 	    $w = $e = null;
527 527
 	    
528 528
 	    if (isset($arr[$id])) {
529
-		$nn = stream_select($arr,$w,$e,$timeout);
529
+		$nn = stream_select($arr, $w, $e, $timeout);
530 530
 		if ($nn > 0) {
531 531
 		    foreach ($httpfeeds as $feed) {
532
-			$buffer = stream_get_line($feed,2000,"\n");
532
+			$buffer = stream_get_line($feed, 2000, "\n");
533 533
 			if ($buffer === FALSE) {
534 534
 			    connect_all($globalSources);
535 535
 			}
536
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-			$buffer = explode('\n',$buffer);
536
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
537
+			$buffer = explode('\n', $buffer);
538 538
 			foreach ($buffer as $line) {
539 539
 			    if ($line != '') {
540 540
 				$ais_data = $AIS->parse_line(trim($line));
541 541
 				$data = array();
542 542
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
543
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
543
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
544 544
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
545 545
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
546 546
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
553 553
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
554 554
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
555
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
555
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
556 556
 				if (isset($ais_data['timestamp'])) {
557
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
557
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
558 558
 				} else {
559 559
 				    $data['datetime'] = date('Y-m-d H:i:s');
560 560
 				}
@@ -586,10 +586,10 @@  discard block
 block discarded – undo
586 586
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
587 587
 	    )
588 588
 	) {
589
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
589
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
590 590
 	    if ($buffer != '') {
591 591
 		//echo $buffer;
592
-		$all_data = json_decode($buffer,true);
592
+		$all_data = json_decode($buffer, true);
593 593
 		//print_r($all_data);
594 594
 		if (isset($all_data[0]['DATA'])) {
595 595
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 			    $data['ident'] = $line['NAME'];
599 599
 			    $data['mmsi'] = $line['MMSI'];
600 600
 			    if (strlen($data['mmsi']) > 9) {
601
-				$data['mmsi'] = substr($data['mmsi'],-9);
601
+				$data['mmsi'] = substr($data['mmsi'], -9);
602 602
 			    }
603 603
 			    $data['speed'] = $line['SOG'];
604 604
 			    $data['heading'] = $line['COG'];
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
 			    //$data['type_id'] = $line['TYPE'];
609 609
 			    $data['imo'] = $line['IMO'];
610 610
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
611
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
612
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
611
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
612
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
613 613
 			    $data['format_source'] = 'myshiptracking';
614 614
 			    $data['id_source'] = $id_source;
615 615
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -626,16 +626,16 @@  discard block
 block discarded – undo
626 626
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
627 627
 	    )
628 628
 	) {
629
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
629
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
630 630
 	    if ($buffer != '') {
631
-		$all_data = json_decode($buffer,true);
631
+		$all_data = json_decode($buffer, true);
632 632
 		if (isset($all_data[0]['mmsi'])) {
633 633
 		    foreach ($all_data as $line) {
634 634
 			if ($line != '') {
635 635
 			    $data = array();
636 636
 			    $data['ident'] = $line['shipname'];
637 637
 			    $data['callsign'] = $line['callsign'];
638
-			    $data['mmsi'] = substr($line['mmsi'],-9);
638
+			    $data['mmsi'] = substr($line['mmsi'], -9);
639 639
 			    $data['speed'] = $line['sog'];
640 640
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
641 641
 			    $data['latitude'] = $line['latitude'];
@@ -662,14 +662,14 @@  discard block
 block discarded – undo
662 662
 	) {
663 663
 	    $buffer = $Common->getData($value['host']);
664 664
 	    if ($buffer != '') {
665
-		$all_data = json_decode($buffer,true);
665
+		$all_data = json_decode($buffer, true);
666 666
 		if (isset($all_data['features'][0]['id'])) {
667 667
 		    foreach ($all_data['features'] as $line) {
668 668
 			print_r($line);
669 669
 			$data = array();
670 670
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
671 671
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
672
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
672
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
673 673
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
674 674
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
675 675
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -696,31 +696,31 @@  discard block
 block discarded – undo
696 696
 	    )
697 697
 	) {
698 698
 	    if ($globalDebug) echo 'download...';
699
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
699
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
700 700
 	    if ($globalDebug) echo 'done !'."\n";
701 701
 	    // FIXME: Need more work
702 702
 	    if ($buffer != '') $reset = 0;
703
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
704
-	    $buffer = explode('\n',$buffer);
703
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
704
+	    $buffer = explode('\n', $buffer);
705 705
 	    foreach ($buffer as $line) {
706 706
 		if ($line != '') {
707 707
 		    $data = array();
708 708
 		    //echo $line."\n";
709
-		    $data['mmsi'] = (int)substr($line,0,9);
710
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
711
-		    $data['status_id'] = substr($line,21,2);
712
-		    $data['type_id'] = substr($line,24,3);
713
-		    $data['latitude'] = substr($line,29,9);
714
-		    $data['longitude'] = substr($line,41,9);
715
-		    $data['speed'] = round(substr($line,51,5));
709
+		    $data['mmsi'] = (int) substr($line, 0, 9);
710
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
711
+		    $data['status_id'] = substr($line, 21, 2);
712
+		    $data['type_id'] = substr($line, 24, 3);
713
+		    $data['latitude'] = substr($line, 29, 9);
714
+		    $data['longitude'] = substr($line, 41, 9);
715
+		    $data['speed'] = round(substr($line, 51, 5));
716 716
 		    //$data['course'] = substr($line,57,5);
717
-		    $data['heading'] = round(substr($line,63,3));
717
+		    $data['heading'] = round(substr($line, 63, 3));
718 718
 		    //$data['draft'] = substr($line,67,4);
719 719
 		    //$data['length'] = substr($line,72,3);
720 720
 		    //$data['beam'] = substr($line,76,2);
721
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
721
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
722 722
 		    //$data['callsign'] = trim(substr($line,100,7);
723
-		    $data['arrival_code'] = substr($line,108,20);
723
+		    $data['arrival_code'] = substr($line, 108, 20);
724 724
 		    //$data['etaDate'] = substr($line,129,5);
725 725
 		    //$data['etaTime'] = substr($line,135,5);
726 726
 		    $data['format_source'] = 'shipplotter';
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 	    )
741 741
 	) {
742 742
 	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
743
-		$authsailaway = $Common->getData('https://sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
743
+		$authsailaway = $Common->getData('https://sailaway.world/cgi-bin/sailaway/weblogin.pl', 'post', array('submitlogin' => 'Login', 'email' => $globalSailaway['email'], 'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'), '', '', '', '', '', false, false, true);
744 744
 		//echo $authsailaway;
745 745
 		preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $authsailaway, $setcookie);
746 746
 		if (isset($setcookie[1][0])) {
@@ -749,18 +749,18 @@  discard block
 block discarded – undo
749 749
 	    }
750 750
 
751 751
 	    if ($globalDebug) echo '! Download... ';
752
-	    for ($i =0; $i <= 1; $i++) {
752
+	    for ($i = 0; $i <= 1; $i++) {
753 753
 		if ($globalDebug) echo 'Racetype: '.$i.' ';
754 754
 		$buffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
755 755
 	    if ($globalDebug) echo 'done'."\n";
756 756
 	    if ($buffer != '') {
757
-		$all_data = json_decode($buffer,true);
757
+		$all_data = json_decode($buffer, true);
758 758
 		if (isset($all_data['missions'])) {
759 759
 			foreach ($all_data['missions'] as $mission) {
760 760
 				$mission_user = $mission['usrname'];
761
-				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
762
-				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
763
-					if (isset($sailaway_authcookie) && $sailaway_authcookie != '') $racebuffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMission.pl?misnr='.$mission['misnr'],'get','','',$sailaway_authcookie);
761
+				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle']));
762
+				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'], $globalFilter['sailway']['race']))) {
763
+					if (isset($sailaway_authcookie) && $sailaway_authcookie != '') $racebuffer = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetMission.pl?misnr='.$mission['misnr'], 'get', '', '', $sailaway_authcookie);
764 764
 					else $racebuffer = '';
765 765
 					$bufferm = $Common->getData('https://sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
766 766
 				} else {
@@ -768,19 +768,19 @@  discard block
 block discarded – undo
768 768
 					$racebuffer = '';
769 769
 				}
770 770
 				if ($racebuffer != '') {
771
-					$race_data = json_decode($racebuffer,true);
771
+					$race_data = json_decode($racebuffer, true);
772 772
 					//print_r($race_data);
773 773
 					unset($racebuffer);
774 774
 					if (isset($race_data['mission'])) {
775 775
 					    $datar = array();
776 776
 					    $datar['id'] = $mission['misnr'];
777 777
 					    $datar['desc'] = $race_data['mission']['misdescr'];
778
-					    $datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
779
-					    $datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['mistitle'])));
778
+					    $datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($race_data['mission']['usrname'])));
779
+					    $datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($race_data['mission']['mistitle'])));
780 780
 					    $datar['startdate'] = $race_data['mission']['misstartdatetime'];
781 781
 					    $markers = array();
782 782
 					    foreach ($race_data['mission']['course'] as $course) {
783
-						$markers[] = array('lat' => $course['miclat'],'lon' => $course['miclon'],'name' => $course['micname'],'type' => $course['mictype']);
783
+						$markers[] = array('lat' => $course['miclat'], 'lon' => $course['miclon'], 'name' => $course['micname'], 'type' => $course['mictype']);
784 784
 					    }
785 785
 					    $datar['markers'] = json_encode($markers);
786 786
 					    //print_r($datar);
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 					}
789 789
 				}
790 790
 				if ($bufferm != '') {
791
-					$mission_data = json_decode($bufferm,true);
791
+					$mission_data = json_decode($bufferm, true);
792 792
 					unset($bufferm);
793 793
 					if (isset($mission_data['leaderboard'][0]['results'])) {
794 794
 						foreach ($mission_data['leaderboard'][0]['results'] as $sail) {
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 								//$data['id'] = $sail['misnr'].'-'.$sail['usrnr'].'-'.$sail['ubtnr'];
802 802
 								$data['id'] = $sail['misnr'].'-'.$sail['usrnr'];
803 803
 								$data['datetime'] = date('Y-m-d H:i:s');
804
-								$data['race_begin'] = date('Y-m-d H:i:s',strtotime($mission_data['leaderboard'][0]['misstart']));
804
+								$data['race_begin'] = date('Y-m-d H:i:s', strtotime($mission_data['leaderboard'][0]['misstart']));
805 805
 								$data['last_update'] = date('Y-m-d H:i:s');
806 806
 								$data['status'] = $sail['status'];
807 807
 								$data['type'] = $sail['btptype'];
@@ -812,16 +812,16 @@  discard block
 block discarded – undo
812 812
 									$data['longitude'] = $pos['longitude'];
813 813
 								}
814 814
 								if ($sail['status'] == 'Racing' && $sail['resultdescr'] != '-') {
815
-									$resultdescr = explode(',',$sail['resultdescr']);
815
+									$resultdescr = explode(',', $sail['resultdescr']);
816 816
 									if (count($resultdescr) > 2) {
817
-										$data['speed'] = round(str_replace(array('Spd: ','kn.'),'',trim($resultdescr[2]))*1.852,2);
818
-										$data['heading'] = str_replace(array('Hdg: ','°'),'',trim($resultdescr[1]));
817
+										$data['speed'] = round(str_replace(array('Spd: ', 'kn.'), '', trim($resultdescr[2]))*1.852, 2);
818
+										$data['heading'] = str_replace(array('Hdg: ', '°'), '', trim($resultdescr[1]));
819 819
 										if (isset($resultdescr[3])) {
820
-											$data['distance'] = round(str_replace('nm.','',trim(explode(' ',$resultdescr[3])[1]))*1.852,3);
820
+											$data['distance'] = round(str_replace('nm.', '', trim(explode(' ', $resultdescr[3])[1]))*1.852, 3);
821 821
 										}
822 822
 									}
823 823
 								}
824
-								$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
824
+								$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
825 825
 								$data['captain_id'] = $sail['usrnr'];
826 826
 								$data['captain_name'] = $sail['usrname'];
827 827
 								$data['race_id'] = $sail['misnr'];
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
 	) {
869 869
 	    //$buffer = $Common->getData($hosts[$id]);
870 870
 	    $buffer = $Common->getData($value['host']);
871
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
872
-	    $buffer = explode('\n',$buffer);
871
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
872
+	    $buffer = explode('\n', $buffer);
873 873
 	    $reset = 0;
874 874
 	    foreach ($buffer as $line) {
875 875
     		if ($line != '') {
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
881 881
 			$data['pilot_id'] = $line[1];
882 882
 			$data['pilot_name'] = $line[2];
883
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
883
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
884 884
 			$data['ident'] = $line[0]; // ident
885 885
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
886 886
 			$data['speed'] = $line[8]; // speed
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
897 897
 			//if (isset($line[37])) $data['last_update'] = $line[37];
898 898
 		        $data['departure_airport_icao'] = $line[11];
899
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
899
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
900 900
 		        $data['arrival_airport_icao'] = $line[13];
901 901
 			$data['frequency'] = $line[4];
902 902
 			$data['type'] = $line[18];
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
     			$data['id_source'] = $id_source;
906 906
 	    		//$data['arrival_airport_time'] = ;
907 907
 	    		if ($line[9] != '') {
908
-	    		    $aircraft_data = explode('/',$line[9]);
908
+	    		    $aircraft_data = explode('/', $line[9]);
909 909
 	    		    if (isset($aircraft_data[1])) {
910 910
 	    			$data['aircraft_icao'] = $aircraft_data[1];
911 911
 	    		    }
@@ -920,9 +920,9 @@  discard block
 block discarded – undo
920 920
     			if ($line[3] === 'PILOT') $SI->add($data);
921 921
 			elseif ($line[3] === 'ATC') {
922 922
 				//print_r($data);
923
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
924
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
925
-				$typec = substr($data['ident'],-3);
923
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
924
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
925
+				$typec = substr($data['ident'], -3);
926 926
 				if ($typec === 'APP') $data['type'] = 'Approach';
927 927
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
928 928
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
935 935
 				if (!isset($data['source_name'])) $data['source_name'] = '';
936 936
 				if (isset($ATC)) {
937
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
938
-					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
937
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
938
+					else echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
939 939
 				}
940 940
 			}
941 941
     			unset($data);
@@ -951,24 +951,24 @@  discard block
 block discarded – undo
951 951
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
952 952
     	    )
953 953
     	) {
954
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
954
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
955 955
 	    if ($buffer != '') {
956 956
 		$all_data = simplexml_load_string($buffer);
957
-		foreach($all_data->children() as $childdata) {
957
+		foreach ($all_data->children() as $childdata) {
958 958
 			$data = array();
959 959
 			$line = $childdata;
960 960
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
961
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
962
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
963
-			$data['latitude'] = (float)$line['pktLatitude'];
964
-			$data['longitude'] = (float)$line['pktLongitude'];
965
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
966
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
967
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
961
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
962
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
963
+			$data['latitude'] = (float) $line['pktLatitude'];
964
+			$data['longitude'] = (float) $line['pktLongitude'];
965
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
966
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
967
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
968 968
 			$data['altitude_relative'] = 'AMSL';
969
-			$data['pilot_id'] = (int)$line['pktPilotID'];
969
+			$data['pilot_id'] = (int) $line['pktPilotID'];
970 970
 			$data['aircraft_icao'] = 'PARAGLIDER';
971
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
971
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
972 972
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
973 973
 			$data['format_source'] = $value['format'];
974 974
 			$SI->add($data);
@@ -976,22 +976,22 @@  discard block
 block discarded – undo
976 976
 		}
977 977
 	    }
978 978
 	    $Source->deleteOldLocationByType('gs');
979
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
979
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
980 980
 	    if ($buffer != '') {
981 981
 		$all_data = simplexml_load_string($buffer);
982
-		foreach($all_data->children() as $childdata) {
982
+		foreach ($all_data->children() as $childdata) {
983 983
 			$data = array();
984 984
 			$line = $childdata;
985
-			$data['id'] = (int)$line['gsID'];
986
-			$data['latitude'] = (float)$line['gsLatitude'];
987
-			$data['longitude'] = (float)$line['gsLongitude'];
988
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
985
+			$data['id'] = (int) $line['gsID'];
986
+			$data['latitude'] = (float) $line['gsLatitude'];
987
+			$data['longitude'] = (float) $line['gsLongitude'];
988
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
989 989
 			$data['altitude_relative'] = 'AMSL';
990
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
990
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
991 991
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
992
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
992
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
993 993
 			} else {
994
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
994
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
995 995
 			}
996 996
 			unset($data);
997 997
 		}
@@ -1009,9 +1009,9 @@  discard block
 block discarded – undo
1009 1009
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1010 1010
 	    )
1011 1011
 	) {
1012
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1012
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
1013 1013
 	    if ($buffer != '') {
1014
-	        $all_data = json_decode($buffer,true);
1014
+	        $all_data = json_decode($buffer, true);
1015 1015
 		if (isset($all_data['acList'])) {
1016 1016
 		    $reset = 0;
1017 1017
 		    foreach ($all_data['acList'] as $line) {
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1028 1028
 			$data['emergency'] = ''; // emergency
1029 1029
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1030
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1030
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1031 1031
 			else $data['datetime'] = date('Y-m-d H:i:s');
1032 1032
 			//$data['datetime'] = date('Y-m-d H:i:s');
1033 1033
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1053 1053
 			$data['squawk'] = $line['squawk']; // squawk
1054 1054
 			$data['emergency'] = ''; // emergency
1055
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1055
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1056 1056
 			else $data['datetime'] = date('Y-m-d H:i:s');
1057 1057
 			$data['format_source'] = 'aircraftlistjson';
1058 1058
 			$data['id_source'] = $id_source;
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
     	    )
1074 1074
     	) {
1075 1075
 	    $buffer = $Common->getData($value['host']);
1076
-	    $all_data = json_decode($buffer,true);
1076
+	    $all_data = json_decode($buffer, true);
1077 1077
 	    if (isset($all_data['planes'])) {
1078 1078
 		$reset = 0;
1079 1079
 		foreach ($all_data['planes'] as $key => $line) {
@@ -1090,12 +1090,12 @@  discard block
 block discarded – undo
1090 1090
 		    $data['emergency'] = ''; // emergency
1091 1091
 		    $data['registration'] = $line[2];
1092 1092
 		    $data['aircraft_icao'] = $line[0];
1093
-		    $deparr = explode('-',$line[1]);
1093
+		    $deparr = explode('-', $line[1]);
1094 1094
 		    if (count($deparr) === 2) {
1095 1095
 			$data['departure_airport_icao'] = $deparr[0];
1096 1096
 			$data['arrival_airport_icao'] = $deparr[1];
1097 1097
 		    }
1098
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1098
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
1099 1099
 	    	    $data['format_source'] = 'planeupdatefaa';
1100 1100
     		    $data['id_source'] = $id_source;
1101 1101
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
 	    )
1114 1114
 	) {
1115 1115
 	    $buffer = $Common->getData($value['host']);
1116
-	    $all_data = json_decode($buffer,true);
1116
+	    $all_data = json_decode($buffer, true);
1117 1117
 	    if (isset($all_data['states'])) {
1118 1118
 		$reset = 0;
1119 1119
 		foreach ($all_data['states'] as $key => $line) {
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 		    //$data['emergency'] = ''; // emergency
1131 1131
 		    //$data['registration'] = $line[2];
1132 1132
 		    //$data['aircraft_icao'] = $line[0];
1133
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1133
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1134 1134
 		    $data['format_source'] = 'opensky';
1135 1135
 		    $data['id_source'] = $id_source;
1136 1136
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1147,8 +1147,8 @@  discard block
 block discarded – undo
1147 1147
 	    )
1148 1148
 	) {
1149 1149
 	    $buffer = $Common->getData($value['host']);
1150
-	    $all_data = json_decode($buffer,true);
1151
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1150
+	    $all_data = json_decode($buffer, true);
1151
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1152 1152
 		$reset = 0;
1153 1153
 		foreach ($all_data['aircraft'] as $key => $line) {
1154 1154
 		    $data = array();
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 	    )
1187 1187
 	) {
1188 1188
 	    $buffer = $Common->getData($value['host']);
1189
-	    $all_data = json_decode($buffer,true);
1189
+	    $all_data = json_decode($buffer, true);
1190 1190
 	    if (isset($all_data['aircraft'])) {
1191 1191
 		$reset = 0;
1192 1192
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
 		    //$data['emergency'] = ''; // emergency
1204 1204
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1205 1205
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1206
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1206
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1207 1207
 		    $data['format_source'] = 'planefinderclient';
1208 1208
 		    $data['id_source'] = $id_source;
1209 1209
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1222,7 +1222,7 @@  discard block
 block discarded – undo
1222 1222
 	) {
1223 1223
 	    //$buffer = $Common->getData($hosts[$id]);
1224 1224
 	    $buffer = $Common->getData($value['host']);
1225
-	    $all_data = json_decode($buffer,true);
1225
+	    $all_data = json_decode($buffer, true);
1226 1226
 	    if (!empty($all_data)) $reset = 0;
1227 1227
 	    foreach ($all_data as $key => $line) {
1228 1228
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1260,11 +1260,11 @@  discard block
 block discarded – undo
1260 1260
 	    )
1261 1261
 	) {
1262 1262
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1263
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1263
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1264 1264
 	    //echo $buffer;
1265
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1266
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1267
-	    $all_data = json_decode($buffer,true);
1265
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1266
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1267
+	    $all_data = json_decode($buffer, true);
1268 1268
 	    if (json_last_error() != JSON_ERROR_NONE) {
1269 1269
 		die(json_last_error_msg());
1270 1270
 	    }
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 			//$data['departure_airport_iata'] = $line[11];
1288 1288
 			//$data['arrival_airport_iata'] = $line[12];
1289 1289
 	    		//$data['emergency'] = ''; // emergency
1290
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1290
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1291 1291
 	    		$data['format_source'] = 'radarvirtueljson';
1292 1292
     			$data['id_source'] = $id_source;
1293 1293
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1308,14 +1308,14 @@  discard block
 block discarded – undo
1308 1308
 	) {
1309 1309
 	    //$buffer = $Common->getData($hosts[$id]);
1310 1310
 	    $buffer = $Common->getData($value['host'].'?'.time());
1311
-	    $all_data = json_decode(utf8_encode($buffer),true);
1311
+	    $all_data = json_decode(utf8_encode($buffer), true);
1312 1312
 	    
1313 1313
 	    if (isset($all_data['pireps'])) {
1314 1314
 		$reset = 0;
1315 1315
 	        foreach ($all_data['pireps'] as $line) {
1316 1316
 		    $data = array();
1317 1317
 		    $data['id'] = $line['id'];
1318
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1318
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1319 1319
 		    $data['ident'] = $line['callsign']; // ident
1320 1320
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1321 1321
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1345,9 +1345,9 @@  discard block
 block discarded – undo
1345 1345
 			$SI->add($data);
1346 1346
 		    //    print_r($data);
1347 1347
     		    } elseif ($line['icon'] === 'ct') {
1348
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1349
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1350
-			$typec = substr($data['ident'],-3);
1348
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1349
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1350
+			$typec = substr($data['ident'], -3);
1351 1351
 			$data['type'] = '';
1352 1352
 			if ($typec === 'APP') $data['type'] = 'Approach';
1353 1353
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1358,7 +1358,7 @@  discard block
 block discarded – undo
1358 1358
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1359 1359
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1360 1360
 			else $data['type'] = 'Observer';
1361
-			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']);
1361
+			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']);
1362 1362
 		    }
1363 1363
 		    unset($data);
1364 1364
 		}
@@ -1375,14 +1375,14 @@  discard block
 block discarded – undo
1375 1375
 	    //$buffer = $Common->getData($hosts[$id]);
1376 1376
 	    if ($globalDebug) echo 'Get Data...'."\n";
1377 1377
 	    $buffer = $Common->getData($value['host']);
1378
-	    $all_data = json_decode($buffer,true);
1378
+	    $all_data = json_decode($buffer, true);
1379 1379
 	    if ($buffer != '' && is_array($all_data)) {
1380 1380
 		$reset = 0;
1381 1381
 		foreach ($all_data as $line) {
1382 1382
 	    	    $data = array();
1383 1383
 	    	    //$data['id'] = $line['id']; // id not usable
1384 1384
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1385
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1385
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1386 1386
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1387 1387
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1388 1388
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1397,7 +1397,7 @@  discard block
 block discarded – undo
1397 1397
 	    	    //$data['datetime'] = $line['lastupdate'];
1398 1398
 	    	    //$data['last_update'] = $line['lastupdate'];
1399 1399
 	    	    if (isset($value['timezone'])) {
1400
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1400
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1401 1401
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1402 1402
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1403 1403
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1413,14 +1413,14 @@  discard block
 block discarded – undo
1413 1413
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1414 1414
 		    if (isset($line['aircraftname'])) {
1415 1415
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1416
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1417
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1416
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1417
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1418 1418
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1419 1419
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1420 1420
 	    		else {
1421
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1422
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1423
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1421
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1422
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1423
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1424 1424
 	    		}
1425 1425
 	    	    }
1426 1426
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1445,7 +1445,7 @@  discard block
 block discarded – undo
1445 1445
 	    //$buffer = $Common->getData($hosts[$id]);
1446 1446
 	    if ($globalDebug) echo 'Get Data...'."\n";
1447 1447
 	    $buffer = $Common->getData($value['host']);
1448
-	    $all_data = json_decode($buffer,true);
1448
+	    $all_data = json_decode($buffer, true);
1449 1449
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1450 1450
 		$reset = 0;
1451 1451
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1456,7 +1456,7 @@  discard block
 block discarded – undo
1456 1456
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1457 1457
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1458 1458
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1459
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1459
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1460 1460
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1461 1461
 	    	    $data['altitude'] = $line['altitude']; // altitude
1462 1462
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
 	    	    //$data['squawk'] = ''; // squawk
1468 1468
 	    	    //$data['emergency'] = ''; // emergency
1469 1469
 	    	    if (isset($value['timezone'])) {
1470
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1470
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1471 1471
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1472 1472
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1473 1473
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1503,14 +1503,14 @@  discard block
 block discarded – undo
1503 1503
 	    //$buffer = $Common->getData($hosts[$id]);
1504 1504
 	    if ($globalDebug) echo 'Get Data...'."\n";
1505 1505
 	    $buffer = $Common->getData($value['host']);
1506
-	    $all_data = json_decode($buffer,true);
1506
+	    $all_data = json_decode($buffer, true);
1507 1507
 	    if ($buffer != '' && is_array($all_data)) {
1508 1508
 		$reset = 0;
1509 1509
 		foreach ($all_data as $line) {
1510 1510
 	    	    $data = array();
1511 1511
 	    	    //$data['id'] = $line['id']; // id not usable
1512 1512
 	    	    $data['id'] = trim($line['flight_id']);
1513
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1513
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1514 1514
 	    	    $data['pilot_name'] = $line['pilot_name'];
1515 1515
 	    	    $data['pilot_id'] = $line['pilot_id'];
1516 1516
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1554,24 +1554,24 @@  discard block
 block discarded – undo
1554 1554
 	    //$buffer = $Common->getData($hosts[$id]);
1555 1555
 	    if ($globalDebug) echo 'Get Data...'."\n";
1556 1556
 	    $buffer = $Common->getData($value['host']);
1557
-	    $all_data = json_decode($buffer,true);
1557
+	    $all_data = json_decode($buffer, true);
1558 1558
 	    if ($buffer != '') {
1559 1559
 		$Source->deleteLocationBySource('blitzortung');
1560
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1561
-		$buffer = explode('\n',$buffer);
1560
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1561
+		$buffer = explode('\n', $buffer);
1562 1562
 		foreach ($buffer as $buffer_line) {
1563
-		    $line = json_decode($buffer_line,true);
1563
+		    $line = json_decode($buffer_line, true);
1564 1564
 		    if (isset($line['time'])) {
1565 1565
 			$data = array();
1566 1566
 			$data['altitude'] = $line['alt']; // altitude
1567 1567
 			$data['latitude'] = $line['lat']; // lat
1568 1568
 			$data['longitude'] = $line['lon']; // long
1569
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1569
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1570 1570
 			$data['id_source'] = $id_source;
1571 1571
 			$data['format_source'] = 'blitzortung';
1572 1572
 			$SI->add($data);
1573 1573
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1574
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1574
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1575 1575
 			unset($data);
1576 1576
 		    }
1577 1577
 		}
@@ -1594,11 +1594,11 @@  discard block
 block discarded – undo
1594 1594
 		    //$value = $formats[$nb];
1595 1595
 		    $format = $globalSources[$nb]['format'];
1596 1596
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1597
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1597
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1598 1598
 		    } elseif ($format === 'vrstcp') {
1599 1599
 			$buffer = @socket_read($r, 6000);
1600 1600
 		    } else {
1601
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1601
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1602 1602
 		    }
1603 1603
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1604 1604
 		    //echo $buffer."\n";
@@ -1608,8 +1608,8 @@  discard block
 block discarded – undo
1608 1608
 		    //$SI::del();
1609 1609
 		    if ($buffer !== FALSE) {
1610 1610
 			if ($format === 'vrstcp') {
1611
-			    $buffer = explode('},{',$buffer);
1612
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1611
+			    $buffer = explode('},{', $buffer);
1612
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1613 1613
 		    }
1614 1614
 		    // SBS format is CSV format
1615 1615
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
 			    $ais_data = $AIS->parse_line(trim($buffer));
1634 1634
 			    $data = array();
1635 1635
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1636
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1636
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1637 1637
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1638 1638
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1639 1639
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1644,13 +1644,13 @@  discard block
 block discarded – undo
1644 1644
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1645 1645
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1646 1646
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1647
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1647
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1648 1648
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1649 1649
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1650 1650
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1651 1651
 
1652 1652
 			    if (isset($ais_data['timestamp'])) {
1653
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1653
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1654 1654
 			    } else {
1655 1655
 				$data['datetime'] = date('Y-m-d H:i:s');
1656 1656
 			    }
@@ -1661,10 +1661,10 @@  discard block
 block discarded – undo
1661 1661
                         } elseif ($format === 'flightgearsp') {
1662 1662
                     	    //echo $buffer."\n";
1663 1663
                     	    if (strlen($buffer) > 5) {
1664
-				$line = explode(',',$buffer);
1664
+				$line = explode(',', $buffer);
1665 1665
 				$data = array();
1666 1666
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1667
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1667
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1668 1668
 				$data['ident'] = $line[6];
1669 1669
 				$data['aircraft_name'] = $line[7];
1670 1670
 				$data['longitude'] = $line[1];
@@ -1681,16 +1681,16 @@  discard block
 block discarded – undo
1681 1681
                         } elseif ($format === 'acars') {
1682 1682
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1683 1683
 			    $ACARS->add(trim($buffer));
1684
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1684
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1685 1685
 			    $ACARS->deleteLiveAcarsData();
1686 1686
 			} elseif ($format === 'flightgearmp') {
1687
-			    if (substr($buffer,0,1) != '#') {
1687
+			    if (substr($buffer, 0, 1) != '#') {
1688 1688
 				$data = array();
1689 1689
 				//echo $buffer."\n";
1690
-				$line = explode(' ',$buffer);
1690
+				$line = explode(' ', $buffer);
1691 1691
 				if (count($line) === 11) {
1692
-				    $userserver = explode('@',$line[0]);
1693
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1692
+				    $userserver = explode('@', $line[0]);
1693
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1694 1694
 				    $data['ident'] = $userserver[0];
1695 1695
 				    $data['registration'] = $userserver[0];
1696 1696
 				    $data['latitude'] = $line[4];
@@ -1698,8 +1698,8 @@  discard block
 block discarded – undo
1698 1698
 				    $data['altitude'] = $line[6];
1699 1699
 				    $data['datetime'] = date('Y-m-d H:i:s');
1700 1700
 				    $aircraft_type = $line[10];
1701
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1702
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1701
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1702
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1703 1703
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1704 1704
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1705 1705
 				}
@@ -1708,8 +1708,8 @@  discard block
 block discarded – undo
1708 1708
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1709 1709
 			    die;
1710 1710
 			} elseif ($format === 'vrstcp') {
1711
-			    foreach($buffer as $all_data) {
1712
-				$line = json_decode('{'.$all_data.'}',true);
1711
+			    foreach ($buffer as $all_data) {
1712
+				$line = json_decode('{'.$all_data.'}', true);
1713 1713
 				$data = array();
1714 1714
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1715 1715
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1735,16 +1735,16 @@  discard block
 block discarded – undo
1735 1735
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1736 1736
 				unset($data);
1737 1737
 			    }
1738
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1738
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1739 1739
 			    $line = explode("\t", $buffer);
1740
-			    for($k = 0; $k < count($line); $k=$k+2) {
1740
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1741 1741
 				$key = $line[$k];
1742
-			        $lined[$key] = $line[$k+1];
1742
+			        $lined[$key] = $line[$k + 1];
1743 1743
 			    }
1744 1744
     			    if (count($lined) > 3) {
1745 1745
     				$data['hex'] = $lined['hexid'];
1746 1746
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1747
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1747
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1748 1748
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1749 1749
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1750 1750
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1763,23 +1763,23 @@  discard block
 block discarded – undo
1763 1763
     			    } else $error = true;
1764 1764
 			} elseif ($format === 'aprs' && $use_aprs) {
1765 1765
 			    if ($aprs_connect === 0) {
1766
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1766
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1767 1767
 				$aprs_connect = 1;
1768 1768
 			    }
1769 1769
 			    
1770
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1770
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1771 1771
 				$aprs_last_tx = time();
1772 1772
 				$data_aprs = "# Keep alive";
1773
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1773
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1774 1774
 			    }
1775 1775
 			    
1776 1776
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1777 1777
 			    //echo 'APRS data : '.$buffer."\n";
1778
-			    $buffer = str_replace('APRS <- ','',$buffer);
1779
-			    $buffer = str_replace('APRS -> ','',$buffer);
1778
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1779
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1780 1780
 			    //echo $buffer."\n";
1781 1781
 			    date_default_timezone_set('UTC');
1782
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1782
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1783 1783
 				$line = $APRS->parse($buffer);
1784 1784
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1785 1785
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1794,7 +1794,7 @@  discard block
 block discarded – undo
1794 1794
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1795 1795
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1796 1796
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1797
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1797
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1798 1798
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1799 1799
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1800 1800
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1882,29 +1882,29 @@  discard block
 block discarded – undo
1882 1882
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1883 1883
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1884 1884
 					$Source->deleteOldLocationByType('gs');
1885
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1886
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1885
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1886
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1887 1887
 					} else {
1888
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1888
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1889 1889
 					}
1890 1890
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1891 1891
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1892 1892
 					if ($globalDebug) echo '# Weather Station added'."\n";
1893 1893
 					$Source->deleteOldLocationByType('wx');
1894 1894
 					$weather_data = json_encode($line);
1895
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1896
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1895
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1896
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1897 1897
 					} else {
1898
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1898
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1899 1899
 					}
1900 1900
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1901 1901
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1902 1902
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1903 1903
 					$Source->deleteOldLocationByType('lightning');
1904
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1905
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1904
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1905
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1906 1906
 					} else {
1907
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1907
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1908 1908
 					}
1909 1909
 				    } elseif ($globalDebug) {
1910 1910
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1913,7 +1913,7 @@  discard block
 block discarded – undo
1913 1913
 				    unset($data);
1914 1914
 				}
1915 1915
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1916
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1916
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1917 1917
 				}
1918 1918
 				/*
1919 1919
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] === 'Car' || $line['symbol'] === 'Ambulance' || $line['symbol'] === 'Van' || $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || $line['symbol'] === 'Motorcycle')) {
@@ -1922,7 +1922,7 @@  discard block
 block discarded – undo
1922 1922
 				*/
1923 1923
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1924 1924
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1925
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1925
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1926 1926
 					$Source->deleteOldLocationByType('lightning');
1927 1927
 					$Source->deleteOldLocationByType('wx');
1928 1928
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -2008,7 +2008,7 @@  discard block
 block discarded – undo
2008 2008
 				connect_all($sourceee);
2009 2009
 				$sourceee = array();
2010 2010
 				//connect_all($globalSources);
2011
-				$tt[$format]=0;
2011
+				$tt[$format] = 0;
2012 2012
 				break;
2013 2013
 			    } 
2014 2014
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -2018,14 +2018,14 @@  discard block
 block discarded – undo
2018 2018
 	    } else {
2019 2019
 		$error = socket_strerror(socket_last_error());
2020 2020
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2021
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2021
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
2022 2022
 			if (isset($globalDebug)) echo "Restarting...\n";
2023 2023
 			// Restart the script if possible
2024 2024
 			if (is_array($sockets)) {
2025 2025
 			    if ($globalDebug) echo "Shutdown all sockets...";
2026 2026
 			    
2027 2027
 			    foreach ($sockets as $sock) {
2028
-				@socket_shutdown($sock,2);
2028
+				@socket_shutdown($sock, 2);
2029 2029
 				@socket_close($sock);
2030 2030
 			    }
2031 2031
 			    
Please login to merge, or discard this patch.