Completed
Push — master ( 8c94fe...9091ef )
by Yannick
34:02 queued 02:35
created
scripts/daemon-spotter.php 3 patches
Indentation   +960 added lines, -960 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18 18
 if (isset($globalMarine) && $globalMarine) {
19
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
19
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 21
 }
22 22
 
23 23
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -25,46 +25,46 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->connectionExists() === false) {
28
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
-    exit();
28
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
+	exit();
30 30
 }
31 31
 if ($Connection->latest() === false) {
32
-    echo "You MUST update to latest schema. Run install/index.php";
33
-    exit();
32
+	echo "You MUST update to latest schema. Run install/index.php";
33
+	exit();
34 34
 }
35 35
 if (PHP_SAPI != 'cli') {
36
-    echo "This script MUST be called from console, not a web browser.";
36
+	echo "This script MUST be called from console, not a web browser.";
37 37
 //    exit();
38 38
 }
39 39
 
40 40
 // This is to be compatible with old version of settings.php
41 41
 if (!isset($globalSources)) {
42
-    if (isset($globalSBS1Hosts)) {
43
-        //$hosts = $globalSBS1Hosts;
44
-        foreach ($globalSBS1Hosts as $host) {
45
-	    $globalSources[] = array('host' => $host);
46
-    	}
47
-    } else {
48
-        if (!isset($globalSBS1Host)) {
49
-	    echo '$globalSources MUST be defined !';
50
-	    die;
42
+	if (isset($globalSBS1Hosts)) {
43
+		//$hosts = $globalSBS1Hosts;
44
+		foreach ($globalSBS1Hosts as $host) {
45
+		$globalSources[] = array('host' => $host);
46
+		}
47
+	} else {
48
+		if (!isset($globalSBS1Host)) {
49
+		echo '$globalSources MUST be defined !';
50
+		die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53 53
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
54
-    }
54
+	}
55 55
 }
56 56
 
57 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
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65
-    $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
65
+	$globalSources = array();
66
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
+	else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
70 70
 	$globalServerAPRS = TRUE;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 if (isset($options['idsource'])) $id_source = $options['idsource'];
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
106
+	if ($globalDebug) echo "Using Server Mode\n";
107
+	$SI=new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
117
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
117
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 119
 }
120 120
 
121 121
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
122 122
 if (isset($globalMarine) && $globalMarine) {
123
-    $AIS = new AIS();
124
-    $MI = new MarineImport($Connection->db);
123
+	$AIS = new AIS();
124
+	$MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127 127
 $SBS=new SBS();
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 //$servertz = system('date +%Z');
133 133
 // signal handler - playing nice with sockets and dump1090
134 134
 if (function_exists('pcntl_fork')) {
135
-    pcntl_signal(SIGINT,  function() {
136
-        global $sockets;
137
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
138
-        die("Bye!\n");
139
-    });
140
-    pcntl_signal_dispatch();
135
+	pcntl_signal(SIGINT,  function() {
136
+		global $sockets;
137
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
138
+		die("Bye!\n");
139
+	});
140
+	pcntl_signal_dispatch();
141 141
 }
142 142
 
143 143
 // let's try and connect
@@ -147,36 +147,36 @@  discard block
 block discarded – undo
147 147
 $reset = 0;
148 148
 
149 149
 function connect_all($hosts) {
150
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
151
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
152
-    $reset++;
153
-    if ($globalDebug) echo 'Connect to all...'."\n";
154
-    foreach ($hosts as $id => $value) {
150
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
151
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
152
+	$reset++;
153
+	if ($globalDebug) echo 'Connect to all...'."\n";
154
+	foreach ($hosts as $id => $value) {
155 155
 	$host = $value['host'];
156 156
 	$globalSources[$id]['last_exec'] = 0;
157 157
 	// Here we check type of source(s)
158 158
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
159
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
-        	//$formats[$id] = 'deltadbtxt';
161
-        	$globalSources[$id]['format'] = 'deltadbtxt';
162
-        	//$last_exec['deltadbtxt'] = 0;
163
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
164
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
165
-        	//$formats[$id] = 'vatsimtxt';
166
-        	$globalSources[$id]['format'] = 'vatsimtxt';
167
-        	//$last_exec['vatsimtxt'] = 0;
168
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
169
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
170
-        	//$formats[$id] = 'aircraftlistjson';
171
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
172
-        	//$last_exec['aircraftlistjson'] = 0;
173
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
174
-    	    } else if (preg_match('/opensky/i',$host)) {
175
-        	//$formats[$id] = 'aircraftlistjson';
176
-        	$globalSources[$id]['format'] = 'opensky';
177
-        	//$last_exec['aircraftlistjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
179
-    	    /*
159
+			if (preg_match('/deltadb.txt$/i',$host)) {
160
+			//$formats[$id] = 'deltadbtxt';
161
+			$globalSources[$id]['format'] = 'deltadbtxt';
162
+			//$last_exec['deltadbtxt'] = 0;
163
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
164
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
165
+			//$formats[$id] = 'vatsimtxt';
166
+			$globalSources[$id]['format'] = 'vatsimtxt';
167
+			//$last_exec['vatsimtxt'] = 0;
168
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
169
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
170
+			//$formats[$id] = 'aircraftlistjson';
171
+			$globalSources[$id]['format'] = 'aircraftlistjson';
172
+			//$last_exec['aircraftlistjson'] = 0;
173
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
174
+			} else if (preg_match('/opensky/i',$host)) {
175
+			//$formats[$id] = 'aircraftlistjson';
176
+			$globalSources[$id]['format'] = 'opensky';
177
+			//$last_exec['aircraftlistjson'] = 0;
178
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
179
+			/*
180 180
     	    // Disabled for now, site change source format
181 181
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
182 182
         	//$formats[$id] = 'radarvirtueljson';
@@ -188,121 +188,121 @@  discard block
 block discarded – undo
188 188
         	    exit(0);
189 189
         	}
190 190
     	    */
191
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
192
-        	//$formats[$id] = 'planeupdatefaa';
193
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
194
-        	//$last_exec['planeupdatefaa'] = 0;
195
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
196
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198
-        	    exit(0);
199
-        	}
200
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
201
-        	//$formats[$id] = 'phpvmacars';
202
-        	$globalSources[$id]['format'] = 'phpvmacars';
203
-        	//$last_exec['phpvmacars'] = 0;
204
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
205
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
206
-        	//$formats[$id] = 'phpvmacars';
207
-        	$globalSources[$id]['format'] = 'vam';
208
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
209
-            } else if (preg_match('/whazzup/i',$host)) {
210
-        	//$formats[$id] = 'whazzup';
211
-        	$globalSources[$id]['format'] = 'whazzup';
212
-        	//$last_exec['whazzup'] = 0;
213
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
214
-            } else if (preg_match('/blitzortung/i',$host)) {
215
-        	$globalSources[$id]['format'] = 'blitzortung';
216
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
217
-            } else if (preg_match('/airwhere/i',$host)) {
218
-        	$globalSources[$id]['format'] = 'airwhere';
219
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
220
-            } else if (preg_match('/recentpireps/i',$host)) {
221
-        	//$formats[$id] = 'pirepsjson';
222
-        	$globalSources[$id]['format'] = 'pirepsjson';
223
-        	//$last_exec['pirepsjson'] = 0;
224
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
225
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
226
-        	//$formats[$id] = 'fr24json';
227
-        	$globalSources[$id]['format'] = 'fr24json';
228
-        	//$last_exec['fr24json'] = 0;
229
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
230
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
231
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
232
-        	    exit(0);
233
-        	}
234
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
235
-        	//$formats[$id] = 'fr24json';
236
-        	$globalSources[$id]['format'] = 'myshiptracking';
237
-        	//$last_exec['fr24json'] = 0;
238
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
239
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
240
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
241
-        	    exit(0);
242
-        	}
243
-            //} else if (preg_match('/10001/',$host)) {
244
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
245
-        	//$formats[$id] = 'tsv';
246
-        	$globalSources[$id]['format'] = 'tsv';
247
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
248
-            }
249
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
250
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
251
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
252
-    		    if ($idf !== false) {
253
-    			$httpfeeds[$id] = $idf;
254
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
255
-    		    }
256
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
257
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
258
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
259
-	    $hostport = explode(':',$host);
260
-	    if (isset($hostport[1])) {
191
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
192
+			//$formats[$id] = 'planeupdatefaa';
193
+			$globalSources[$id]['format'] = 'planeupdatefaa';
194
+			//$last_exec['planeupdatefaa'] = 0;
195
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
196
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198
+				exit(0);
199
+			}
200
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
201
+			//$formats[$id] = 'phpvmacars';
202
+			$globalSources[$id]['format'] = 'phpvmacars';
203
+			//$last_exec['phpvmacars'] = 0;
204
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
205
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
206
+			//$formats[$id] = 'phpvmacars';
207
+			$globalSources[$id]['format'] = 'vam';
208
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
209
+			} else if (preg_match('/whazzup/i',$host)) {
210
+			//$formats[$id] = 'whazzup';
211
+			$globalSources[$id]['format'] = 'whazzup';
212
+			//$last_exec['whazzup'] = 0;
213
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
214
+			} else if (preg_match('/blitzortung/i',$host)) {
215
+			$globalSources[$id]['format'] = 'blitzortung';
216
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
217
+			} else if (preg_match('/airwhere/i',$host)) {
218
+			$globalSources[$id]['format'] = 'airwhere';
219
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
220
+			} else if (preg_match('/recentpireps/i',$host)) {
221
+			//$formats[$id] = 'pirepsjson';
222
+			$globalSources[$id]['format'] = 'pirepsjson';
223
+			//$last_exec['pirepsjson'] = 0;
224
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
225
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
226
+			//$formats[$id] = 'fr24json';
227
+			$globalSources[$id]['format'] = 'fr24json';
228
+			//$last_exec['fr24json'] = 0;
229
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
230
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
231
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
232
+				exit(0);
233
+			}
234
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
235
+			//$formats[$id] = 'fr24json';
236
+			$globalSources[$id]['format'] = 'myshiptracking';
237
+			//$last_exec['fr24json'] = 0;
238
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
239
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
240
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
241
+				exit(0);
242
+			}
243
+			//} else if (preg_match('/10001/',$host)) {
244
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
245
+			//$formats[$id] = 'tsv';
246
+			$globalSources[$id]['format'] = 'tsv';
247
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
248
+			}
249
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
250
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
251
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
252
+				if ($idf !== false) {
253
+				$httpfeeds[$id] = $idf;
254
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
255
+				}
256
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
257
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
258
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
259
+		$hostport = explode(':',$host);
260
+		if (isset($hostport[1])) {
261 261
 		$port = $hostport[1];
262 262
 		$hostn = $hostport[0];
263
-	    } else {
263
+		} else {
264 264
 		$port = $globalSources[$id]['port'];
265 265
 		$hostn = $globalSources[$id]['host'];
266
-	    }
267
-	    $Common = new Common();
268
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
269
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
270
-    	    } else {
271
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
272
-	    }
273
-	    if ($s) {
274
-    	        $sockets[$id] = $s;
275
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
276
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
266
+		}
267
+		$Common = new Common();
268
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
269
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
270
+			} else {
271
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
272
+		}
273
+		if ($s) {
274
+				$sockets[$id] = $s;
275
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
276
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
277 277
 			//$formats[$id] = 'aprs';
278 278
 			$globalSources[$id]['format'] = 'aprs';
279 279
 			//$aprs_connect = 0;
280 280
 			//$use_aprs = true;
281
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
281
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
282 282
 			$globalSources[$id]['format'] = 'vrstcp';
283
-    		    } elseif ($port == '10001') {
284
-        		//$formats[$id] = 'tsv';
285
-        		$globalSources[$id]['format'] = 'tsv';
286
-		    } elseif ($port == '30002') {
287
-        		//$formats[$id] = 'raw';
288
-        		$globalSources[$id]['format'] = 'raw';
289
-		    } elseif ($port == '5001') {
290
-        		//$formats[$id] = 'raw';
291
-        		$globalSources[$id]['format'] = 'flightgearmp';
292
-		    } elseif ($port == '30005') {
283
+				} elseif ($port == '10001') {
284
+				//$formats[$id] = 'tsv';
285
+				$globalSources[$id]['format'] = 'tsv';
286
+			} elseif ($port == '30002') {
287
+				//$formats[$id] = 'raw';
288
+				$globalSources[$id]['format'] = 'raw';
289
+			} elseif ($port == '5001') {
290
+				//$formats[$id] = 'raw';
291
+				$globalSources[$id]['format'] = 'flightgearmp';
292
+			} elseif ($port == '30005') {
293 293
 			// Not yet supported
294
-        		//$formats[$id] = 'beast';
295
-        		$globalSources[$id]['format'] = 'beast';
296
-		    //} else $formats[$id] = 'sbs';
297
-		    } else $globalSources[$id]['format'] = 'sbs';
298
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
294
+				//$formats[$id] = 'beast';
295
+				$globalSources[$id]['format'] = 'beast';
296
+			//} else $formats[$id] = 'sbs';
297
+			} else $globalSources[$id]['format'] = 'sbs';
298
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
299 299
 		}
300 300
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
301
-            } else {
301
+			} else {
302 302
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
303
-    	    }
304
-        }
305
-    }
303
+			}
304
+		}
305
+	}
306 306
 }
307 307
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
308 308
 
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 //connect_all($globalSources);
326 326
 
327 327
 if (isset($globalProxy) && $globalProxy) {
328
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
328
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
329 329
 } else {
330
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
330
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
331 331
 }
332 332
 
333 333
 // APRS Configuration
@@ -336,21 +336,21 @@  discard block
 block discarded – undo
336 336
 	die;
337 337
 }
338 338
 foreach ($globalSources as $key => $source) {
339
-    if (!isset($source['format'])) {
340
-        $globalSources[$key]['format'] = 'auto';
341
-    }
342
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
343
-        unset($globalSources[$key]);
344
-    }
339
+	if (!isset($source['format'])) {
340
+		$globalSources[$key]['format'] = 'auto';
341
+	}
342
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
343
+		unset($globalSources[$key]);
344
+	}
345 345
 }
346 346
 connect_all($globalSources);
347 347
 foreach ($globalSources as $key => $source) {
348
-    if (isset($source['format']) && $source['format'] == 'aprs') {
348
+	if (isset($source['format']) && $source['format'] == 'aprs') {
349 349
 	$aprs_connect = 0;
350 350
 	$use_aprs = true;
351 351
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
352 352
 	break;
353
-    }
353
+	}
354 354
 }
355 355
 
356 356
 if ($use_aprs) {
@@ -391,126 +391,126 @@  discard block
 block discarded – undo
391 391
 
392 392
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
393 393
 while ($i > 0) {
394
-    if (!$globalDaemon) $i = $endtime-time();
395
-    // Delete old ATC
396
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
394
+	if (!$globalDaemon) $i = $endtime-time();
395
+	// Delete old ATC
396
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
397 397
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
398
-        $ATC->deleteOldATC();
399
-    }
398
+		$ATC->deleteOldATC();
399
+	}
400 400
     
401
-    if (count($last_exec) == count($globalSources)) {
401
+	if (count($last_exec) == count($globalSources)) {
402 402
 	$max = $globalMinFetch;
403 403
 	foreach ($last_exec as $last) {
404
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
404
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
405 405
 	}
406 406
 	if ($max != $globalMinFetch) {
407
-	    if ($globalDebug) echo 'Sleeping...'."\n";
408
-	    sleep($globalMinFetch-$max+2);
407
+		if ($globalDebug) echo 'Sleeping...'."\n";
408
+		sleep($globalMinFetch-$max+2);
409
+	}
409 410
 	}
410
-    }
411 411
 
412 412
     
413
-    //foreach ($formats as $id => $value) {
414
-    foreach ($globalSources as $id => $value) {
413
+	//foreach ($formats as $id => $value) {
414
+	foreach ($globalSources as $id => $value) {
415 415
 	date_default_timezone_set('UTC');
416 416
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
417 417
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
418 418
 	if ($value['format'] == 'deltadbtxt' && 
419
-	    (
419
+		(
420 420
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
421 421
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
422
-	    )
422
+		)
423 423
 	) {
424
-	    //$buffer = $Common->getData($hosts[$id]);
425
-	    $buffer = $Common->getData($value['host']);
426
-	    if ($buffer != '') $reset = 0;
427
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
428
-	    $buffer = explode('\n',$buffer);
429
-	    foreach ($buffer as $line) {
430
-    		if ($line != '' && count($line) > 7) {
431
-    		    $line = explode(',', $line);
432
-	            $data = array();
433
-	            $data['hex'] = $line[1]; // hex
434
-	            $data['ident'] = $line[2]; // ident
435
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
436
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
437
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
438
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
439
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
440
-	            $data['verticalrate'] = ''; // vertical rate
441
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
442
-	            $data['emergency'] = ''; // emergency
443
-		    $data['datetime'] = date('Y-m-d H:i:s');
444
-		    $data['format_source'] = 'deltadbtxt';
445
-    		    $data['id_source'] = $id_source;
446
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
447
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
448
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
449
-    		    $SI->add($data);
450
-		    unset($data);
451
-    		}
452
-    	    }
453
-    	    $last_exec[$id]['last'] = time();
424
+		//$buffer = $Common->getData($hosts[$id]);
425
+		$buffer = $Common->getData($value['host']);
426
+		if ($buffer != '') $reset = 0;
427
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
428
+		$buffer = explode('\n',$buffer);
429
+		foreach ($buffer as $line) {
430
+			if ($line != '' && count($line) > 7) {
431
+				$line = explode(',', $line);
432
+				$data = array();
433
+				$data['hex'] = $line[1]; // hex
434
+				$data['ident'] = $line[2]; // ident
435
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
436
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
437
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
438
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
439
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
440
+				$data['verticalrate'] = ''; // vertical rate
441
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
442
+				$data['emergency'] = ''; // emergency
443
+			$data['datetime'] = date('Y-m-d H:i:s');
444
+			$data['format_source'] = 'deltadbtxt';
445
+				$data['id_source'] = $id_source;
446
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
447
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
448
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
449
+				$SI->add($data);
450
+			unset($data);
451
+			}
452
+			}
453
+			$last_exec[$id]['last'] = time();
454 454
 	} elseif ($value['format'] == 'aisnmeatxt' && 
455
-	    (
455
+		(
456 456
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
457 457
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
458
-	    )
458
+		)
459 459
 	) {
460
-	    date_default_timezone_set('CET');
461
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
462
-	    date_default_timezone_set('UTC');
463
-	    if ($buffer != '') $reset = 0;
464
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
465
-	    $buffer = explode('\n',$buffer);
466
-	    foreach ($buffer as $line) {
460
+		date_default_timezone_set('CET');
461
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
462
+		date_default_timezone_set('UTC');
463
+		if ($buffer != '') $reset = 0;
464
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
465
+		$buffer = explode('\n',$buffer);
466
+		foreach ($buffer as $line) {
467 467
 		if ($line != '') {
468
-		    //echo "'".$line."'\n";
469
-		    $add = false;
470
-		    $ais_data = $AIS->parse_line(trim($line));
471
-		    $data = array();
472
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
473
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
474
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
475
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
476
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
477
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
478
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
479
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
480
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
481
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
482
-		    if (isset($ais_data['timestamp'])) {
468
+			//echo "'".$line."'\n";
469
+			$add = false;
470
+			$ais_data = $AIS->parse_line(trim($line));
471
+			$data = array();
472
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
473
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
474
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
475
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
476
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
477
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
478
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
479
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
480
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
481
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
482
+			if (isset($ais_data['timestamp'])) {
483 483
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
484 484
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
485
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
486
-			    $add = true;
485
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
486
+				$add = true;
487 487
 			}
488
-		    } else {
488
+			} else {
489 489
 			$data['datetime'] = date('Y-m-d H:i:s');
490 490
 			$add = true;
491
-		    }
492
-		    $data['format_source'] = 'aisnmeatxt';
493
-    		    $data['id_source'] = $id_source;
494
-		    //print_r($data);
495
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
496
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
497
-		    unset($data);
491
+			}
492
+			$data['format_source'] = 'aisnmeatxt';
493
+				$data['id_source'] = $id_source;
494
+			//print_r($data);
495
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
496
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
497
+			unset($data);
498 498
 		}
499
-    	    }
500
-    	    $last_exec[$id]['last'] = time();
499
+			}
500
+			$last_exec[$id]['last'] = time();
501 501
 	} elseif ($value['format'] == 'aisnmeahttp') {
502
-	    $arr = $httpfeeds;
503
-	    $w = $e = null;
502
+		$arr = $httpfeeds;
503
+		$w = $e = null;
504 504
 	    
505
-	    if (isset($arr[$id])) {
505
+		if (isset($arr[$id])) {
506 506
 		$nn = stream_select($arr,$w,$e,$timeout);
507 507
 		if ($nn > 0) {
508
-		    foreach ($httpfeeds as $feed) {
508
+			foreach ($httpfeeds as $feed) {
509 509
 			$buffer = stream_get_line($feed,2000,"\n");
510 510
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
511 511
 			$buffer = explode('\n',$buffer);
512 512
 			foreach ($buffer as $line) {
513
-			    if ($line != '') {
513
+				if ($line != '') {
514 514
 				$ais_data = $AIS->parse_line(trim($line));
515 515
 				$data = array();
516 516
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -528,114 +528,114 @@  discard block
 block discarded – undo
528 528
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
529 529
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
530 530
 				if (isset($ais_data['timestamp'])) {
531
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
531
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
532 532
 				} else {
533
-				    $data['datetime'] = date('Y-m-d H:i:s');
533
+					$data['datetime'] = date('Y-m-d H:i:s');
534 534
 				}
535 535
 				$data['format_source'] = 'aisnmeahttp';
536 536
 				$data['id_source'] = $id_source;
537 537
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
538 538
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
539 539
 				unset($data);
540
-			    }
540
+				}
541
+			}
541 542
 			}
542
-		    }
543 543
 		} else {
544
-		    $format = $value['format'];
545
-		    if (isset($tt[$format])) $tt[$format]++;
546
-		    else $tt[$format] = 0;
547
-		    if ($tt[$format] > 30) {
544
+			$format = $value['format'];
545
+			if (isset($tt[$format])) $tt[$format]++;
546
+			else $tt[$format] = 0;
547
+			if ($tt[$format] > 30) {
548 548
 			if ($globalDebug) echo 'Reconnect...'."\n";
549 549
 			sleep(2);
550 550
 			$sourceeen[] = $value;
551 551
 			connect_all($sourceeen);
552 552
 			$sourceeen = array();
553
-		    }
553
+			}
554
+		}
554 555
 		}
555
-	    }
556 556
 	} elseif ($value['format'] == 'myshiptracking' && 
557
-	    (
557
+		(
558 558
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
559 559
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
560
-	    )
560
+		)
561 561
 	) {
562
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
563
-	    if ($buffer != '') {
562
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
563
+		if ($buffer != '') {
564 564
 		//echo $buffer;
565 565
 		$all_data = json_decode($buffer,true);
566 566
 		//print_r($all_data);
567 567
 		if (isset($all_data[0]['DATA'])) {
568
-		    foreach ($all_data[0]['DATA'] as $line) {
568
+			foreach ($all_data[0]['DATA'] as $line) {
569 569
 			if ($line != '') {
570
-			    $data = array();
571
-			    $data['ident'] = $line['NAME'];
572
-			    $data['mmsi'] = $line['MMSI'];
573
-			    if (strlen($data['mmsi']) > 9) {
570
+				$data = array();
571
+				$data['ident'] = $line['NAME'];
572
+				$data['mmsi'] = $line['MMSI'];
573
+				if (strlen($data['mmsi']) > 9) {
574 574
 				$data['mmsi'] = substr($data['mmsi'],-9);
575
-			    }
576
-			    $data['speed'] = $line['SOG'];
577
-			    $data['heading'] = $line['COG'];
578
-			    $data['latitude'] = $line['LAT'];
579
-			    $data['longitude'] = $line['LNG'];
580
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
581
-			    $data['imo'] = $line['IMO'];
582
-			    //$data['arrival_code'] = $ais_data['destination'];
583
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
584
-			    $data['format_source'] = 'myshiptracking';
585
-			    $data['id_source'] = $id_source;
586
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
587
-			    $MI->add($data);
588
-			    unset($data);
575
+				}
576
+				$data['speed'] = $line['SOG'];
577
+				$data['heading'] = $line['COG'];
578
+				$data['latitude'] = $line['LAT'];
579
+				$data['longitude'] = $line['LNG'];
580
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
581
+				$data['imo'] = $line['IMO'];
582
+				//$data['arrival_code'] = $ais_data['destination'];
583
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
584
+				$data['format_source'] = 'myshiptracking';
585
+				$data['id_source'] = $id_source;
586
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
587
+				$MI->add($data);
588
+				unset($data);
589 589
 			}
590
-		    }
590
+			}
591
+		}
591 592
 		}
592
-	    }
593
-	    $last_exec[$id]['last'] = time();
593
+		$last_exec[$id]['last'] = time();
594 594
 	} elseif ($value['format'] == 'boatbeaconapp' && 
595
-	    (
595
+		(
596 596
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
597 597
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
598
-	    )
598
+		)
599 599
 	) {
600
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
601
-	    if ($buffer != '') {
600
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
601
+		if ($buffer != '') {
602 602
 		$all_data = json_decode($buffer,true);
603 603
 		if (isset($all_data[0]['mmsi'])) {
604
-		    foreach ($all_data as $line) {
604
+			foreach ($all_data as $line) {
605 605
 			if ($line != '') {
606
-			    $data = array();
607
-			    $data['ident'] = $line['shipname'];
608
-			    $data['callsign'] = $line['callsign'];
609
-			    $data['mmsi'] = $line['mmsi'];
610
-			    $data['speed'] = $line['sog'];
611
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
612
-			    $data['latitude'] = $line['latitude'];
613
-			    $data['longitude'] = $line['longitude'];
614
-			    $data['type_id'] = $line['shiptype'];
615
-			    $data['arrival_code'] = $line['destination'];
616
-			    $data['datetime'] = $line['time'];
617
-			    $data['format_source'] = 'boatbeaconapp';
618
-			    $data['id_source'] = $id_source;
619
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
620
-			    $MI->add($data);
621
-			    unset($data);
606
+				$data = array();
607
+				$data['ident'] = $line['shipname'];
608
+				$data['callsign'] = $line['callsign'];
609
+				$data['mmsi'] = $line['mmsi'];
610
+				$data['speed'] = $line['sog'];
611
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
612
+				$data['latitude'] = $line['latitude'];
613
+				$data['longitude'] = $line['longitude'];
614
+				$data['type_id'] = $line['shiptype'];
615
+				$data['arrival_code'] = $line['destination'];
616
+				$data['datetime'] = $line['time'];
617
+				$data['format_source'] = 'boatbeaconapp';
618
+				$data['id_source'] = $id_source;
619
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
620
+				$MI->add($data);
621
+				unset($data);
622
+			}
622 623
 			}
623
-		    }
624 624
 		}
625 625
 		
626
-	    }
627
-    	    $last_exec[$id]['last'] = time();
626
+		}
627
+			$last_exec[$id]['last'] = time();
628 628
 	} elseif ($value['format'] == 'boatnerd' && 
629
-	    (
629
+		(
630 630
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
631 631
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
632
-	    )
632
+		)
633 633
 	) {
634
-	    $buffer = $Common->getData($value['host']);
635
-	    if ($buffer != '') {
634
+		$buffer = $Common->getData($value['host']);
635
+		if ($buffer != '') {
636 636
 		$all_data = json_decode($buffer,true);
637 637
 		if (isset($all_data['features'][0]['id'])) {
638
-		    foreach ($all_data['features'] as $line) {
638
+			foreach ($all_data['features'] as $line) {
639 639
 			$data = array();
640 640
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
641 641
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
@@ -654,78 +654,78 @@  discard block
 block discarded – undo
654 654
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
655 655
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
656 656
 			unset($data);
657
-		    }
657
+			}
658 658
 		}
659 659
 		
660
-	    }
661
-    	    $last_exec[$id]['last'] = time();
660
+		}
661
+			$last_exec[$id]['last'] = time();
662 662
 	} elseif ($value['format'] == 'shipplotter' && 
663
-	    (
663
+		(
664 664
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
665 665
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
666
-	    )
666
+		)
667 667
 	) {
668
-	    echo 'download...';
669
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
670
-	    echo 'done !'."\n";
671
-	    if ($buffer != '') $reset = 0;
672
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
673
-	    $buffer = explode('\n',$buffer);
674
-	    foreach ($buffer as $line) {
668
+		echo 'download...';
669
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
670
+		echo 'done !'."\n";
671
+		if ($buffer != '') $reset = 0;
672
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
673
+		$buffer = explode('\n',$buffer);
674
+		foreach ($buffer as $line) {
675 675
 		if ($line != '') {
676
-		    $data = array();
677
-		    $data['mmsi'] = (int)substr($line,0,9);
678
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
679
-		    //$data['status'] = substr($line,21,2);
680
-		    //$data['type'] = substr($line,24,3);
681
-		    $data['latitude'] = substr($line,29,9);
682
-		    $data['longitude'] = substr($line,41,9);
683
-		    $data['speed'] = round(substr($line,51,5));
684
-		    //$data['course'] = substr($line,57,5);
685
-		    $data['heading'] = round(substr($line,63,3));
686
-		    //$data['draft'] = substr($line,67,4);
687
-		    //$data['length'] = substr($line,72,3);
688
-		    //$data['beam'] = substr($line,76,2);
689
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
690
-		    //$data['callsign'] = trim(substr($line,100,7);
691
-		    //$data['dest'] = substr($line,108,20);
692
-		    //$data['etaDate'] = substr($line,129,5);
693
-		    //$data['etaTime'] = substr($line,135,5);
694
-		    $data['format_source'] = 'shipplotter';
695
-    		    $data['id_source'] = $id_source;
696
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
697
-		    //print_r($data);
698
-		    echo 'Add...'."\n";
699
-		    $MI->add($data);
700
-		    unset($data);
676
+			$data = array();
677
+			$data['mmsi'] = (int)substr($line,0,9);
678
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
679
+			//$data['status'] = substr($line,21,2);
680
+			//$data['type'] = substr($line,24,3);
681
+			$data['latitude'] = substr($line,29,9);
682
+			$data['longitude'] = substr($line,41,9);
683
+			$data['speed'] = round(substr($line,51,5));
684
+			//$data['course'] = substr($line,57,5);
685
+			$data['heading'] = round(substr($line,63,3));
686
+			//$data['draft'] = substr($line,67,4);
687
+			//$data['length'] = substr($line,72,3);
688
+			//$data['beam'] = substr($line,76,2);
689
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
690
+			//$data['callsign'] = trim(substr($line,100,7);
691
+			//$data['dest'] = substr($line,108,20);
692
+			//$data['etaDate'] = substr($line,129,5);
693
+			//$data['etaTime'] = substr($line,135,5);
694
+			$data['format_source'] = 'shipplotter';
695
+				$data['id_source'] = $id_source;
696
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
697
+			//print_r($data);
698
+			echo 'Add...'."\n";
699
+			$MI->add($data);
700
+			unset($data);
701 701
 		}
702
-    	    }
703
-    	    $last_exec[$id]['last'] = time();
702
+			}
703
+			$last_exec[$id]['last'] = time();
704 704
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
705 705
 	} elseif (
706
-	    (
706
+		(
707 707
 		$value['format'] == 'whazzup' && 
708 708
 		(
709
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
710
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
709
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
710
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
711 711
 		)
712
-	    ) || (
712
+		) || (
713 713
 		$value['format'] == 'vatsimtxt' && 
714 714
 		(
715
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
716
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
715
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
716
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
717
+		)
717 718
 		)
718
-	    )
719 719
 	) {
720
-	    //$buffer = $Common->getData($hosts[$id]);
721
-	    $buffer = $Common->getData($value['host']);
722
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
723
-	    $buffer = explode('\n',$buffer);
724
-	    $reset = 0;
725
-	    foreach ($buffer as $line) {
726
-    		if ($line != '') {
727
-    		    $line = explode(':', $line);
728
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
720
+		//$buffer = $Common->getData($hosts[$id]);
721
+		$buffer = $Common->getData($value['host']);
722
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
723
+		$buffer = explode('\n',$buffer);
724
+		$reset = 0;
725
+		foreach ($buffer as $line) {
726
+			if ($line != '') {
727
+				$line = explode(':', $line);
728
+				if (count($line) > 30 && $line[0] != 'callsign') {
729 729
 			$data = array();
730 730
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
731 731
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -738,37 +738,37 @@  discard block
 block discarded – undo
738 738
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
739 739
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
740 740
 			$data['latitude'] = $line[5]; // lat
741
-	        	$data['longitude'] = $line[6]; // long
742
-	        	$data['verticalrate'] = ''; // vertical rate
743
-	        	$data['squawk'] = ''; // squawk
744
-	        	$data['emergency'] = ''; // emergency
745
-	        	$data['waypoints'] = $line[30];
741
+				$data['longitude'] = $line[6]; // long
742
+				$data['verticalrate'] = ''; // vertical rate
743
+				$data['squawk'] = ''; // squawk
744
+				$data['emergency'] = ''; // emergency
745
+				$data['waypoints'] = $line[30];
746 746
 			$data['datetime'] = date('Y-m-d H:i:s');
747 747
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
748 748
 			//if (isset($line[37])) $data['last_update'] = $line[37];
749
-		        $data['departure_airport_icao'] = $line[11];
750
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
751
-		        $data['arrival_airport_icao'] = $line[13];
749
+				$data['departure_airport_icao'] = $line[11];
750
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
751
+				$data['arrival_airport_icao'] = $line[13];
752 752
 			$data['frequency'] = $line[4];
753 753
 			$data['type'] = $line[18];
754 754
 			$data['range'] = $line[19];
755 755
 			if (isset($line[35])) $data['info'] = $line[35];
756
-    			$data['id_source'] = $id_source;
757
-	    		//$data['arrival_airport_time'] = ;
758
-	    		if ($line[9] != '') {
759
-	    		    $aircraft_data = explode('/',$line[9]);
760
-	    		    if (isset($aircraft_data[1])) {
761
-	    			$data['aircraft_icao'] = $aircraft_data[1];
762
-	    		    }
763
-        		}
764
-	    		/*
756
+				$data['id_source'] = $id_source;
757
+				//$data['arrival_airport_time'] = ;
758
+				if ($line[9] != '') {
759
+					$aircraft_data = explode('/',$line[9]);
760
+					if (isset($aircraft_data[1])) {
761
+					$data['aircraft_icao'] = $aircraft_data[1];
762
+					}
763
+				}
764
+				/*
765 765
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
766 766
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
767 767
 	    		*/
768
-	    		$data['format_source'] = $value['format'];
768
+				$data['format_source'] = $value['format'];
769 769
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
770 770
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
771
-    			if ($line[3] == 'PILOT') $SI->add($data);
771
+				if ($line[3] == 'PILOT') $SI->add($data);
772 772
 			elseif ($line[3] == 'ATC') {
773 773
 				//print_r($data);
774 774
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
 					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']);
790 790
 				}
791 791
 			}
792
-    			unset($data);
793
-    		    }
794
-    		}
795
-    	    }
796
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
797
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
798
-    	    $last_exec[$id]['last'] = time();
799
-    	} elseif ($value['format'] == 'airwhere' && 
800
-    	    (
801
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
802
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
803
-    	    )
804
-    	) {
805
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
806
-	    if ($buffer != '') {
792
+				unset($data);
793
+				}
794
+			}
795
+			}
796
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
797
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
798
+			$last_exec[$id]['last'] = time();
799
+		} elseif ($value['format'] == 'airwhere' && 
800
+			(
801
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
802
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
803
+			)
804
+		) {
805
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
806
+		if ($buffer != '') {
807 807
 		$all_data = simplexml_load_string($buffer);
808 808
 		foreach($all_data->children() as $childdata) {
809 809
 			$data = array();
@@ -825,10 +825,10 @@  discard block
 block discarded – undo
825 825
 			$SI->add($data);
826 826
 			unset($data);
827 827
 		}
828
-	    }
829
-	    $Source->deleteOldLocationByType('gs');
830
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
831
-	    if ($buffer != '') {
828
+		}
829
+		$Source->deleteOldLocationByType('gs');
830
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
831
+		if ($buffer != '') {
832 832
 		$all_data = simplexml_load_string($buffer);
833 833
 		foreach($all_data->children() as $childdata) {
834 834
 			$data = array();
@@ -846,8 +846,8 @@  discard block
 block discarded – undo
846 846
 			}
847 847
 			unset($data);
848 848
 		}
849
-	    }
850
-	    $last_exec[$id]['last'] = time();
849
+		}
850
+		$last_exec[$id]['last'] = time();
851 851
 	/*
852 852
 	} if ($value['format'] == 'aircraftlistjson') {
853 853
 	    print_r($globalSources);
@@ -855,17 +855,17 @@  discard block
 block discarded – undo
855 855
 	    echo $globalMinFetch;
856 856
 	*/
857 857
 	} elseif ($value['format'] == 'aircraftlistjson' && 
858
-	    (
858
+		(
859 859
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
860 860
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
861
-	    )
861
+		)
862 862
 	) {
863
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
864
-	    if ($buffer != '') {
865
-	        $all_data = json_decode($buffer,true);
863
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
864
+		if ($buffer != '') {
865
+			$all_data = json_decode($buffer,true);
866 866
 		if (isset($all_data['acList'])) {
867
-		    $reset = 0;
868
-		    foreach ($all_data['acList'] as $line) {
867
+			$reset = 0;
868
+			foreach ($all_data['acList'] as $line) {
869 869
 			$data = array();
870 870
 			$data['hex'] = $line['Icao']; // hex
871 871
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -888,10 +888,10 @@  discard block
 block discarded – undo
888 888
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
889 889
 			if (isset($data['latitude'])) $SI->add($data);
890 890
 			unset($data);
891
-		    }
891
+			}
892 892
 		} elseif (is_array($all_data)) {
893
-		    $reset = 0;
894
-		    foreach ($all_data as $line) {
893
+			$reset = 0;
894
+			foreach ($all_data as $line) {
895 895
 			$data = array();
896 896
 			$data['hex'] = $line['hex']; // hex
897 897
 			$data['ident'] = $line['flight']; // ident
@@ -911,218 +911,218 @@  discard block
 block discarded – undo
911 911
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
912 912
 			$SI->add($data);
913 913
 			unset($data);
914
-		    }
914
+			}
915 915
 		}
916
-	    } elseif ($globalDebug) echo 'No data'."\n";
917
-    	    //$last_exec['aircraftlistjson'] = time();
918
-    	    $last_exec[$id]['last'] = time();
919
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
920
-    	} elseif ($value['format'] == 'planeupdatefaa' && 
921
-    	    (
922
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
923
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
924
-    	    )
925
-    	) {
926
-	    $buffer = $Common->getData($value['host']);
927
-	    $all_data = json_decode($buffer,true);
928
-	    if (isset($all_data['planes'])) {
916
+		} elseif ($globalDebug) echo 'No data'."\n";
917
+			//$last_exec['aircraftlistjson'] = time();
918
+			$last_exec[$id]['last'] = time();
919
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
920
+		} elseif ($value['format'] == 'planeupdatefaa' && 
921
+			(
922
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
923
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
924
+			)
925
+		) {
926
+		$buffer = $Common->getData($value['host']);
927
+		$all_data = json_decode($buffer,true);
928
+		if (isset($all_data['planes'])) {
929 929
 		$reset = 0;
930 930
 		foreach ($all_data['planes'] as $key => $line) {
931
-		    $data = array();
932
-		    $data['hex'] = $key; // hex
933
-		    $data['ident'] = $line[3]; // ident
934
-		    $data['altitude'] = $line[6]; // altitude
935
-		    $data['speed'] = $line[8]; // speed
936
-		    $data['heading'] = $line[7]; // heading
937
-		    $data['latitude'] = $line[4]; // lat
938
-		    $data['longitude'] = $line[5]; // long
939
-		    //$data['verticalrate'] = $line[]; // verticale rate
940
-		    $data['squawk'] = $line[10]; // squawk
941
-		    $data['emergency'] = ''; // emergency
942
-		    $data['registration'] = $line[2];
943
-		    $data['aircraft_icao'] = $line[0];
944
-		    $deparr = explode('-',$line[1]);
945
-		    if (count($deparr) == 2) {
931
+			$data = array();
932
+			$data['hex'] = $key; // hex
933
+			$data['ident'] = $line[3]; // ident
934
+			$data['altitude'] = $line[6]; // altitude
935
+			$data['speed'] = $line[8]; // speed
936
+			$data['heading'] = $line[7]; // heading
937
+			$data['latitude'] = $line[4]; // lat
938
+			$data['longitude'] = $line[5]; // long
939
+			//$data['verticalrate'] = $line[]; // verticale rate
940
+			$data['squawk'] = $line[10]; // squawk
941
+			$data['emergency'] = ''; // emergency
942
+			$data['registration'] = $line[2];
943
+			$data['aircraft_icao'] = $line[0];
944
+			$deparr = explode('-',$line[1]);
945
+			if (count($deparr) == 2) {
946 946
 			$data['departure_airport_icao'] = $deparr[0];
947 947
 			$data['arrival_airport_icao'] = $deparr[1];
948
-		    }
949
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
950
-	    	    $data['format_source'] = 'planeupdatefaa';
951
-    		    $data['id_source'] = $id_source;
952
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
953
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
954
-		    $SI->add($data);
955
-		    unset($data);
948
+			}
949
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
950
+				$data['format_source'] = 'planeupdatefaa';
951
+				$data['id_source'] = $id_source;
952
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
953
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
954
+			$SI->add($data);
955
+			unset($data);
956
+		}
956 957
 		}
957
-	    }
958
-	    //$last_exec['planeupdatefaa'] = time();
959
-	    $last_exec[$id]['last'] = time();
958
+		//$last_exec['planeupdatefaa'] = time();
959
+		$last_exec[$id]['last'] = time();
960 960
 	} elseif ($value['format'] == 'opensky' && 
961
-	    (
961
+		(
962 962
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
963 963
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
964
-	    )
964
+		)
965 965
 	) {
966
-	    $buffer = $Common->getData($value['host']);
967
-	    $all_data = json_decode($buffer,true);
968
-	    if (isset($all_data['states'])) {
966
+		$buffer = $Common->getData($value['host']);
967
+		$all_data = json_decode($buffer,true);
968
+		if (isset($all_data['states'])) {
969 969
 		$reset = 0;
970 970
 		foreach ($all_data['states'] as $key => $line) {
971
-		    $data = array();
972
-		    $data['hex'] = $line[0]; // hex
973
-		    $data['ident'] = trim($line[1]); // ident
974
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
975
-		    $data['speed'] = round($line[9]*1.94384); // speed
976
-		    $data['heading'] = round($line[10]); // heading
977
-		    $data['latitude'] = $line[6]; // lat
978
-		    $data['longitude'] = $line[5]; // long
979
-		    $data['verticalrate'] = $line[11]; // verticale rate
980
-		    //$data['squawk'] = $line[10]; // squawk
981
-		    //$data['emergency'] = ''; // emergency
982
-		    //$data['registration'] = $line[2];
983
-		    //$data['aircraft_icao'] = $line[0];
984
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
985
-		    $data['format_source'] = 'opensky';
986
-		    $data['id_source'] = $id_source;
987
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
988
-		    $SI->add($data);
989
-		    unset($data);
971
+			$data = array();
972
+			$data['hex'] = $line[0]; // hex
973
+			$data['ident'] = trim($line[1]); // ident
974
+			$data['altitude'] = round($line[7]*3.28084); // altitude
975
+			$data['speed'] = round($line[9]*1.94384); // speed
976
+			$data['heading'] = round($line[10]); // heading
977
+			$data['latitude'] = $line[6]; // lat
978
+			$data['longitude'] = $line[5]; // long
979
+			$data['verticalrate'] = $line[11]; // verticale rate
980
+			//$data['squawk'] = $line[10]; // squawk
981
+			//$data['emergency'] = ''; // emergency
982
+			//$data['registration'] = $line[2];
983
+			//$data['aircraft_icao'] = $line[0];
984
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
985
+			$data['format_source'] = 'opensky';
986
+			$data['id_source'] = $id_source;
987
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
988
+			$SI->add($data);
989
+			unset($data);
990 990
 		}
991
-	    }
992
-	    //$last_exec['planeupdatefaa'] = time();
993
-	    $last_exec[$id]['last'] = time();
991
+		}
992
+		//$last_exec['planeupdatefaa'] = time();
993
+		$last_exec[$id]['last'] = time();
994 994
 	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
995 995
 	} elseif ($value['format'] == 'fr24json' && 
996
-	    (
996
+		(
997 997
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
998 998
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
999
-	    )
999
+		)
1000 1000
 	) {
1001
-	    //$buffer = $Common->getData($hosts[$id]);
1002
-	    $buffer = $Common->getData($value['host']);
1003
-	    $all_data = json_decode($buffer,true);
1004
-	    if (!empty($all_data)) $reset = 0;
1005
-	    foreach ($all_data as $key => $line) {
1001
+		//$buffer = $Common->getData($hosts[$id]);
1002
+		$buffer = $Common->getData($value['host']);
1003
+		$all_data = json_decode($buffer,true);
1004
+		if (!empty($all_data)) $reset = 0;
1005
+		foreach ($all_data as $key => $line) {
1006 1006
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1007
-		    $data = array();
1008
-		    $data['hex'] = $line[0];
1009
-		    $data['ident'] = $line[16]; //$line[13]
1010
-	    	    $data['altitude'] = $line[4]; // altitude
1011
-	    	    $data['speed'] = $line[5]; // speed
1012
-	    	    $data['heading'] = $line[3]; // heading
1013
-	    	    $data['latitude'] = $line[1]; // lat
1014
-	    	    $data['longitude'] = $line[2]; // long
1015
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1016
-	    	    $data['squawk'] = $line[6]; // squawk
1017
-	    	    $data['aircraft_icao'] = $line[8];
1018
-	    	    $data['registration'] = $line[9];
1019
-		    $data['departure_airport_iata'] = $line[11];
1020
-		    $data['arrival_airport_iata'] = $line[12];
1021
-	    	    $data['emergency'] = ''; // emergency
1022
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1023
-	    	    $data['format_source'] = 'fr24json';
1024
-    		    $data['id_source'] = $id_source;
1025
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1026
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1027
-		    $SI->add($data);
1028
-		    unset($data);
1007
+			$data = array();
1008
+			$data['hex'] = $line[0];
1009
+			$data['ident'] = $line[16]; //$line[13]
1010
+				$data['altitude'] = $line[4]; // altitude
1011
+				$data['speed'] = $line[5]; // speed
1012
+				$data['heading'] = $line[3]; // heading
1013
+				$data['latitude'] = $line[1]; // lat
1014
+				$data['longitude'] = $line[2]; // long
1015
+				$data['verticalrate'] = $line[15]; // verticale rate
1016
+				$data['squawk'] = $line[6]; // squawk
1017
+				$data['aircraft_icao'] = $line[8];
1018
+				$data['registration'] = $line[9];
1019
+			$data['departure_airport_iata'] = $line[11];
1020
+			$data['arrival_airport_iata'] = $line[12];
1021
+				$data['emergency'] = ''; // emergency
1022
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1023
+				$data['format_source'] = 'fr24json';
1024
+				$data['id_source'] = $id_source;
1025
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1026
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1027
+			$SI->add($data);
1028
+			unset($data);
1029 1029
 		}
1030
-	    }
1031
-	    //$last_exec['fr24json'] = time();
1032
-	    $last_exec[$id]['last'] = time();
1030
+		}
1031
+		//$last_exec['fr24json'] = time();
1032
+		$last_exec[$id]['last'] = time();
1033 1033
 	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1034 1034
 	} elseif ($value['format'] == 'radarvirtueljson' && 
1035
-	    (
1035
+		(
1036 1036
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1037 1037
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1038
-	    )
1038
+		)
1039 1039
 	) {
1040
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1041
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1042
-	    //echo $buffer;
1043
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1044
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1045
-	    $all_data = json_decode($buffer,true);
1046
-	    if (json_last_error() != JSON_ERROR_NONE) {
1040
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1041
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1042
+		//echo $buffer;
1043
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1044
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1045
+		$all_data = json_decode($buffer,true);
1046
+		if (json_last_error() != JSON_ERROR_NONE) {
1047 1047
 		die(json_last_error_msg());
1048
-	    }
1049
-	    if (isset($all_data['mrkrs'])) {
1048
+		}
1049
+		if (isset($all_data['mrkrs'])) {
1050 1050
 		$reset = 0;
1051 1051
 		foreach ($all_data['mrkrs'] as $key => $line) {
1052
-		    if (isset($line['inf'])) {
1052
+			if (isset($line['inf'])) {
1053 1053
 			$data = array();
1054 1054
 			$data['hex'] = $line['inf']['ia'];
1055 1055
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1056
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1057
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1058
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1059
-	    		$data['latitude'] = $line['pt'][0]; // lat
1060
-	    		$data['longitude'] = $line['pt'][1]; // long
1061
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1062
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1063
-	    		//$data['aircraft_icao'] = $line[8];
1064
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1056
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1057
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1058
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1059
+				$data['latitude'] = $line['pt'][0]; // lat
1060
+				$data['longitude'] = $line['pt'][1]; // long
1061
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1062
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1063
+				//$data['aircraft_icao'] = $line[8];
1064
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1065 1065
 			//$data['departure_airport_iata'] = $line[11];
1066 1066
 			//$data['arrival_airport_iata'] = $line[12];
1067
-	    		//$data['emergency'] = ''; // emergency
1067
+				//$data['emergency'] = ''; // emergency
1068 1068
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1069
-	    		$data['format_source'] = 'radarvirtueljson';
1070
-    			$data['id_source'] = $id_source;
1069
+				$data['format_source'] = 'radarvirtueljson';
1070
+				$data['id_source'] = $id_source;
1071 1071
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1072 1072
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1073 1073
 			$SI->add($data);
1074 1074
 			unset($data);
1075
-		    }
1075
+			}
1076
+		}
1076 1077
 		}
1077
-	    }
1078
-	    //$last_exec['radarvirtueljson'] = time();
1079
-	    $last_exec[$id]['last'] = time();
1078
+		//$last_exec['radarvirtueljson'] = time();
1079
+		$last_exec[$id]['last'] = time();
1080 1080
 	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1081 1081
 	} elseif ($value['format'] == 'pirepsjson' && 
1082
-	    (
1082
+		(
1083 1083
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1084 1084
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1085
-	    )
1085
+		)
1086 1086
 	) {
1087
-	    //$buffer = $Common->getData($hosts[$id]);
1088
-	    $buffer = $Common->getData($value['host'].'?'.time());
1089
-	    $all_data = json_decode(utf8_encode($buffer),true);
1087
+		//$buffer = $Common->getData($hosts[$id]);
1088
+		$buffer = $Common->getData($value['host'].'?'.time());
1089
+		$all_data = json_decode(utf8_encode($buffer),true);
1090 1090
 	    
1091
-	    if (isset($all_data['pireps'])) {
1091
+		if (isset($all_data['pireps'])) {
1092 1092
 		$reset = 0;
1093
-	        foreach ($all_data['pireps'] as $line) {
1094
-		    $data = array();
1095
-		    $data['id'] = $line['id'];
1096
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1097
-		    $data['ident'] = $line['callsign']; // ident
1098
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1099
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1100
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1101
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1102
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1103
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1104
-		    $data['latitude'] = $line['lat']; // lat
1105
-		    $data['longitude'] = $line['lon']; // long
1106
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1107
-		    //$data['squawk'] = $line['squawk']; // squawk
1108
-		    //$data['emergency'] = ''; // emergency
1109
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1110
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1111
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1112
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1113
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1114
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1115
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1116
-		    else $data['info'] = '';
1117
-		    $data['format_source'] = 'pireps';
1118
-    		    $data['id_source'] = $id_source;
1119
-		    $data['datetime'] = date('Y-m-d H:i:s');
1120
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1121
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1122
-		    if ($line['icon'] == 'plane') {
1093
+			foreach ($all_data['pireps'] as $line) {
1094
+			$data = array();
1095
+			$data['id'] = $line['id'];
1096
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1097
+			$data['ident'] = $line['callsign']; // ident
1098
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1099
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1100
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1101
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1102
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1103
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1104
+			$data['latitude'] = $line['lat']; // lat
1105
+			$data['longitude'] = $line['lon']; // long
1106
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1107
+			//$data['squawk'] = $line['squawk']; // squawk
1108
+			//$data['emergency'] = ''; // emergency
1109
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1110
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1111
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1112
+			//$data['arrival_airport_time'] = $line['arrtime'];
1113
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1114
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1115
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1116
+			else $data['info'] = '';
1117
+			$data['format_source'] = 'pireps';
1118
+				$data['id_source'] = $id_source;
1119
+			$data['datetime'] = date('Y-m-d H:i:s');
1120
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1121
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1122
+			if ($line['icon'] == 'plane') {
1123 1123
 			$SI->add($data);
1124
-		    //    print_r($data);
1125
-    		    } elseif ($line['icon'] == 'ct') {
1124
+			//    print_r($data);
1125
+				} elseif ($line['icon'] == 'ct') {
1126 1126
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1127 1127
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1128 1128
 			$typec = substr($data['ident'],-3);
@@ -1137,148 +1137,148 @@  discard block
 block discarded – undo
1137 1137
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1138 1138
 			else $data['type'] = 'Observer';
1139 1139
 			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']);
1140
-		    }
1141
-		    unset($data);
1140
+			}
1141
+			unset($data);
1142
+		}
1142 1143
 		}
1143
-	    }
1144
-	    //$last_exec['pirepsjson'] = time();
1145
-	    $last_exec[$id]['last'] = time();
1144
+		//$last_exec['pirepsjson'] = time();
1145
+		$last_exec[$id]['last'] = time();
1146 1146
 	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1147 1147
 	} elseif ($value['format'] == 'phpvmacars' && 
1148
-	    (
1148
+		(
1149 1149
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1150 1150
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1151
-	    )
1151
+		)
1152 1152
 	) {
1153
-	    //$buffer = $Common->getData($hosts[$id]);
1154
-	    if ($globalDebug) echo 'Get Data...'."\n";
1155
-	    $buffer = $Common->getData($value['host']);
1156
-	    $all_data = json_decode($buffer,true);
1157
-	    if ($buffer != '' && is_array($all_data)) {
1153
+		//$buffer = $Common->getData($hosts[$id]);
1154
+		if ($globalDebug) echo 'Get Data...'."\n";
1155
+		$buffer = $Common->getData($value['host']);
1156
+		$all_data = json_decode($buffer,true);
1157
+		if ($buffer != '' && is_array($all_data)) {
1158 1158
 		$reset = 0;
1159 1159
 		foreach ($all_data as $line) {
1160
-	    	    $data = array();
1161
-	    	    //$data['id'] = $line['id']; // id not usable
1162
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1163
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1164
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1165
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1166
-	    	    $data['ident'] = $line['flightnum']; // ident
1167
-	    	    $data['altitude'] = $line['alt']; // altitude
1168
-	    	    $data['speed'] = $line['gs']; // speed
1169
-	    	    $data['heading'] = $line['heading']; // heading
1170
-	    	    $data['latitude'] = $line['lat']; // lat
1171
-	    	    $data['longitude'] = $line['lng']; // long
1172
-	    	    $data['verticalrate'] = ''; // verticale rate
1173
-	    	    $data['squawk'] = ''; // squawk
1174
-	    	    $data['emergency'] = ''; // emergency
1175
-	    	    //$data['datetime'] = $line['lastupdate'];
1176
-	    	    //$data['last_update'] = $line['lastupdate'];
1177
-	    	    if (isset($value['timezone'])) {
1178
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1179
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1180
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1181
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1182
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1183
-	    	    $data['departure_airport_time'] = $line['deptime'];
1184
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1185
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1186
-    		    $data['registration'] = $line['aircraft'];
1187
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1188
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1189
-		    if (isset($line['aircraftname'])) {
1160
+				$data = array();
1161
+				//$data['id'] = $line['id']; // id not usable
1162
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1163
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1164
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1165
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1166
+				$data['ident'] = $line['flightnum']; // ident
1167
+				$data['altitude'] = $line['alt']; // altitude
1168
+				$data['speed'] = $line['gs']; // speed
1169
+				$data['heading'] = $line['heading']; // heading
1170
+				$data['latitude'] = $line['lat']; // lat
1171
+				$data['longitude'] = $line['lng']; // long
1172
+				$data['verticalrate'] = ''; // verticale rate
1173
+				$data['squawk'] = ''; // squawk
1174
+				$data['emergency'] = ''; // emergency
1175
+				//$data['datetime'] = $line['lastupdate'];
1176
+				//$data['last_update'] = $line['lastupdate'];
1177
+				if (isset($value['timezone'])) {
1178
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1179
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1180
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1181
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1182
+				$data['departure_airport_icao'] = $line['depicao'];
1183
+				$data['departure_airport_time'] = $line['deptime'];
1184
+				$data['arrival_airport_icao'] = $line['arricao'];
1185
+				$data['arrival_airport_time'] = $line['arrtime'];
1186
+				$data['registration'] = $line['aircraft'];
1187
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1188
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1189
+			if (isset($line['aircraftname'])) {
1190 1190
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1191 1191
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1192
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1193
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1194
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1195
-	    		else {
1196
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1197
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1198
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1199
-	    		}
1200
-	    	    }
1201
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1202
-    		    $data['id_source'] = $id_source;
1203
-	    	    $data['format_source'] = 'phpvmacars';
1204
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1205
-		    $SI->add($data);
1206
-		    unset($data);
1192
+				$aircraft_data = explode('-',$line['aircraftname']);
1193
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1194
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1195
+				else {
1196
+					$aircraft_data = explode(' ',$line['aircraftname']);
1197
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1198
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1199
+				}
1200
+				}
1201
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1202
+				$data['id_source'] = $id_source;
1203
+				$data['format_source'] = 'phpvmacars';
1204
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1205
+			$SI->add($data);
1206
+			unset($data);
1207 1207
 		}
1208 1208
 		if ($globalDebug) echo 'No more data...'."\n";
1209 1209
 		unset($buffer);
1210 1210
 		unset($all_data);
1211
-	    }
1212
-	    //$last_exec['phpvmacars'] = time();
1213
-	    $last_exec[$id]['last'] = time();
1211
+		}
1212
+		//$last_exec['phpvmacars'] = time();
1213
+		$last_exec[$id]['last'] = time();
1214 1214
 	} elseif ($value['format'] == 'vam' && 
1215
-	    (
1215
+		(
1216 1216
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1217 1217
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1218
-	    )
1218
+		)
1219 1219
 	) {
1220
-	    //$buffer = $Common->getData($hosts[$id]);
1221
-	    if ($globalDebug) echo 'Get Data...'."\n";
1222
-	    $buffer = $Common->getData($value['host']);
1223
-	    $all_data = json_decode($buffer,true);
1224
-	    if ($buffer != '' && is_array($all_data)) {
1220
+		//$buffer = $Common->getData($hosts[$id]);
1221
+		if ($globalDebug) echo 'Get Data...'."\n";
1222
+		$buffer = $Common->getData($value['host']);
1223
+		$all_data = json_decode($buffer,true);
1224
+		if ($buffer != '' && is_array($all_data)) {
1225 1225
 		$reset = 0;
1226 1226
 		foreach ($all_data as $line) {
1227
-	    	    $data = array();
1228
-	    	    //$data['id'] = $line['id']; // id not usable
1229
-	    	    $data['id'] = trim($line['flight_id']);
1230
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1231
-	    	    $data['pilot_name'] = $line['pilot_name'];
1232
-	    	    $data['pilot_id'] = $line['pilot_id'];
1233
-	    	    $data['ident'] = trim($line['callsign']); // ident
1234
-	    	    $data['altitude'] = $line['altitude']; // altitude
1235
-	    	    $data['speed'] = $line['gs']; // speed
1236
-	    	    $data['heading'] = $line['heading']; // heading
1237
-	    	    $data['latitude'] = $line['latitude']; // lat
1238
-	    	    $data['longitude'] = $line['longitude']; // long
1239
-	    	    $data['verticalrate'] = ''; // verticale rate
1240
-	    	    $data['squawk'] = ''; // squawk
1241
-	    	    $data['emergency'] = ''; // emergency
1242
-	    	    //$data['datetime'] = $line['lastupdate'];
1243
-	    	    $data['last_update'] = $line['last_update'];
1244
-		    $data['datetime'] = date('Y-m-d H:i:s');
1245
-	    	    $data['departure_airport_icao'] = $line['departure'];
1246
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1247
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1248
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1249
-    		    //$data['registration'] = $line['aircraft'];
1250
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1251
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1252
-    		    $data['id_source'] = $id_source;
1253
-	    	    $data['format_source'] = 'vam';
1254
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1255
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1256
-		    $SI->add($data);
1257
-		    unset($data);
1227
+				$data = array();
1228
+				//$data['id'] = $line['id']; // id not usable
1229
+				$data['id'] = trim($line['flight_id']);
1230
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1231
+				$data['pilot_name'] = $line['pilot_name'];
1232
+				$data['pilot_id'] = $line['pilot_id'];
1233
+				$data['ident'] = trim($line['callsign']); // ident
1234
+				$data['altitude'] = $line['altitude']; // altitude
1235
+				$data['speed'] = $line['gs']; // speed
1236
+				$data['heading'] = $line['heading']; // heading
1237
+				$data['latitude'] = $line['latitude']; // lat
1238
+				$data['longitude'] = $line['longitude']; // long
1239
+				$data['verticalrate'] = ''; // verticale rate
1240
+				$data['squawk'] = ''; // squawk
1241
+				$data['emergency'] = ''; // emergency
1242
+				//$data['datetime'] = $line['lastupdate'];
1243
+				$data['last_update'] = $line['last_update'];
1244
+			$data['datetime'] = date('Y-m-d H:i:s');
1245
+				$data['departure_airport_icao'] = $line['departure'];
1246
+				//$data['departure_airport_time'] = $line['departure_time'];
1247
+				$data['arrival_airport_icao'] = $line['arrival'];
1248
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1249
+				//$data['registration'] = $line['aircraft'];
1250
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1251
+				$data['aircraft_icao'] = $line['plane_type'];
1252
+				$data['id_source'] = $id_source;
1253
+				$data['format_source'] = 'vam';
1254
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1255
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1256
+			$SI->add($data);
1257
+			unset($data);
1258 1258
 		}
1259 1259
 		if ($globalDebug) echo 'No more data...'."\n";
1260 1260
 		unset($buffer);
1261 1261
 		unset($all_data);
1262
-	    }
1263
-	    //$last_exec['phpvmacars'] = time();
1264
-	    $last_exec[$id]['last'] = time();
1262
+		}
1263
+		//$last_exec['phpvmacars'] = time();
1264
+		$last_exec[$id]['last'] = time();
1265 1265
 	} elseif ($value['format'] == 'blitzortung' && 
1266
-	    (
1266
+		(
1267 1267
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1268 1268
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1269
-	    )
1269
+		)
1270 1270
 	) {
1271
-	    //$buffer = $Common->getData($hosts[$id]);
1272
-	    if ($globalDebug) echo 'Get Data...'."\n";
1273
-	    $buffer = $Common->getData($value['host']);
1274
-	    $all_data = json_decode($buffer,true);
1275
-	    if ($buffer != '') {
1271
+		//$buffer = $Common->getData($hosts[$id]);
1272
+		if ($globalDebug) echo 'Get Data...'."\n";
1273
+		$buffer = $Common->getData($value['host']);
1274
+		$all_data = json_decode($buffer,true);
1275
+		if ($buffer != '') {
1276 1276
 		$Source->deleteLocationBySource('blitzortung');
1277 1277
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1278 1278
 		$buffer = explode('\n',$buffer);
1279 1279
 		foreach ($buffer as $buffer_line) {
1280
-		    $line = json_decode($buffer_line,true);
1281
-		    if (isset($line['time'])) {
1280
+			$line = json_decode($buffer_line,true);
1281
+			if (isset($line['time'])) {
1282 1282
 			$data = array();
1283 1283
 			$data['altitude'] = $line['alt']; // altitude
1284 1284
 			$data['latitude'] = $line['lat']; // lat
@@ -1290,94 +1290,94 @@  discard block
 block discarded – undo
1290 1290
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1291 1291
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1292 1292
 			unset($data);
1293
-		    }
1293
+			}
1294 1294
 		}
1295 1295
 		if ($globalDebug) echo 'No more data...'."\n";
1296 1296
 		unset($buffer);
1297
-	    }
1298
-	    $last_exec[$id]['last'] = time();
1297
+		}
1298
+		$last_exec[$id]['last'] = time();
1299 1299
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1300 1300
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1301
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1302
-    	    //$last_exec[$id]['last'] = time();
1301
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1302
+			//$last_exec[$id]['last'] = time();
1303 1303
 
1304
-	    //$read = array( $sockets[$id] );
1305
-	    $read = $sockets;
1306
-	    $write = NULL;
1307
-	    $e = NULL;
1308
-	    $n = socket_select($read, $write, $e, $timeout);
1309
-	    if ($e != NULL) var_dump($e);
1310
-	    if ($n > 0) {
1304
+		//$read = array( $sockets[$id] );
1305
+		$read = $sockets;
1306
+		$write = NULL;
1307
+		$e = NULL;
1308
+		$n = socket_select($read, $write, $e, $timeout);
1309
+		if ($e != NULL) var_dump($e);
1310
+		if ($n > 0) {
1311 1311
 		$reset = 0;
1312 1312
 		foreach ($read as $nb => $r) {
1313
-		    //$value = $formats[$nb];
1314
-		    $format = $globalSources[$nb]['format'];
1315
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1313
+			//$value = $formats[$nb];
1314
+			$format = $globalSources[$nb]['format'];
1315
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1316 1316
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1317
-		    } elseif ($format == 'vrstcp') {
1317
+			} elseif ($format == 'vrstcp') {
1318 1318
 			$buffer = @socket_read($r, 6000);
1319
-		    } else {
1319
+			} else {
1320 1320
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1321
-		    }
1322
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1323
-		    //echo $buffer."\n";
1324
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1325
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1326
-		    $error = false;
1327
-		    //$SI::del();
1328
-		    if ($format == 'vrstcp') {
1321
+			}
1322
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1323
+			//echo $buffer."\n";
1324
+			// lets play nice and handle signals such as ctrl-c/kill properly
1325
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1326
+			$error = false;
1327
+			//$SI::del();
1328
+			if ($format == 'vrstcp') {
1329 1329
 			$buffer = explode('},{',$buffer);
1330
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1331
-		    // SBS format is CSV format
1332
-		    if ($buffer !== FALSE && $buffer != '') {
1330
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1331
+			// SBS format is CSV format
1332
+			if ($buffer !== FALSE && $buffer != '') {
1333 1333
 			$tt[$format] = 0;
1334 1334
 			if ($format == 'acarssbs3') {
1335
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1336
-			    $ACARS->add(trim($buffer));
1337
-			    $ACARS->deleteLiveAcarsData();
1335
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1336
+				$ACARS->add(trim($buffer));
1337
+				$ACARS->deleteLiveAcarsData();
1338 1338
 			} elseif ($format == 'raw') {
1339
-			    // AVR format
1340
-			    $data = $SBS->parse($buffer);
1341
-			    if (is_array($data)) {
1339
+				// AVR format
1340
+				$data = $SBS->parse($buffer);
1341
+				if (is_array($data)) {
1342 1342
 				$data['datetime'] = date('Y-m-d H:i:s');
1343 1343
 				$data['format_source'] = 'raw';
1344 1344
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1345 1345
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1346 1346
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1347 1347
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1348
-			    }
1348
+				}
1349 1349
 			} elseif ($format == 'ais') {
1350
-			    $ais_data = $AIS->parse_line(trim($buffer));
1351
-			    $data = array();
1352
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1353
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1354
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1355
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1356
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1357
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1358
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1359
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1360
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1361
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1362
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1363
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1364
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1365
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1366
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1367
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1350
+				$ais_data = $AIS->parse_line(trim($buffer));
1351
+				$data = array();
1352
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1353
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1354
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1355
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1356
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1357
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1358
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1359
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1360
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1361
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1362
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1363
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1364
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1365
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1366
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1367
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1368 1368
 
1369
-			    if (isset($ais_data['timestamp'])) {
1369
+				if (isset($ais_data['timestamp'])) {
1370 1370
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1371
-			    } else {
1371
+				} else {
1372 1372
 				$data['datetime'] = date('Y-m-d H:i:s');
1373
-			    }
1374
-			    $data['format_source'] = 'aisnmea';
1375
-    			    $data['id_source'] = $id_source;
1376
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1377
-			    unset($data);
1378
-                        } elseif ($format == 'flightgearsp') {
1379
-                    	    //echo $buffer."\n";
1380
-                    	    if (strlen($buffer) > 5) {
1373
+				}
1374
+				$data['format_source'] = 'aisnmea';
1375
+					$data['id_source'] = $id_source;
1376
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1377
+				unset($data);
1378
+						} elseif ($format == 'flightgearsp') {
1379
+							//echo $buffer."\n";
1380
+							if (strlen($buffer) > 5) {
1381 1381
 				$line = explode(',',$buffer);
1382 1382
 				$data = array();
1383 1383
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1394,38 +1394,38 @@  discard block
 block discarded – undo
1394 1394
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1395 1395
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1396 1396
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1397
-			    }
1398
-                        } elseif ($format == 'acars') {
1399
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1400
-			    $ACARS->add(trim($buffer));
1401
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1402
-			    $ACARS->deleteLiveAcarsData();
1397
+				}
1398
+						} elseif ($format == 'acars') {
1399
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1400
+				$ACARS->add(trim($buffer));
1401
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1402
+				$ACARS->deleteLiveAcarsData();
1403 1403
 			} elseif ($format == 'flightgearmp') {
1404
-			    if (substr($buffer,0,1) != '#') {
1404
+				if (substr($buffer,0,1) != '#') {
1405 1405
 				$data = array();
1406 1406
 				//echo $buffer."\n";
1407 1407
 				$line = explode(' ',$buffer);
1408 1408
 				if (count($line) == 11) {
1409
-				    $userserver = explode('@',$line[0]);
1410
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1411
-				    $data['ident'] = $userserver[0];
1412
-				    $data['registration'] = $userserver[0];
1413
-				    $data['latitude'] = $line[4];
1414
-				    $data['longitude'] = $line[5];
1415
-				    $data['altitude'] = $line[6];
1416
-				    $data['datetime'] = date('Y-m-d H:i:s');
1417
-				    $aircraft_type = $line[10];
1418
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1419
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1420
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1421
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1409
+					$userserver = explode('@',$line[0]);
1410
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1411
+					$data['ident'] = $userserver[0];
1412
+					$data['registration'] = $userserver[0];
1413
+					$data['latitude'] = $line[4];
1414
+					$data['longitude'] = $line[5];
1415
+					$data['altitude'] = $line[6];
1416
+					$data['datetime'] = date('Y-m-d H:i:s');
1417
+					$aircraft_type = $line[10];
1418
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1419
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1420
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1421
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1422
+				}
1422 1423
 				}
1423
-			    }
1424 1424
 			} elseif ($format == 'beast') {
1425
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1426
-			    die;
1425
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1426
+				die;
1427 1427
 			} elseif ($format == 'vrstcp') {
1428
-			    foreach($buffer as $all_data) {
1428
+				foreach($buffer as $all_data) {
1429 1429
 				$line = json_decode('{'.$all_data.'}',true);
1430 1430
 				$data = array();
1431 1431
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1445,151 +1445,151 @@  discard block
 block discarded – undo
1445 1445
 				*/
1446 1446
 				$data['datetime'] = date('Y-m-d H:i:s');
1447 1447
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1448
-		    		$data['format_source'] = 'vrstcp';
1448
+					$data['format_source'] = 'vrstcp';
1449 1449
 				$data['id_source'] = $id_source;
1450 1450
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1451 1451
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1452 1452
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1453 1453
 				unset($data);
1454
-			    }
1454
+				}
1455 1455
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1456
-			    $line = explode("\t", $buffer);
1457
-			    for($k = 0; $k < count($line); $k=$k+2) {
1456
+				$line = explode("\t", $buffer);
1457
+				for($k = 0; $k < count($line); $k=$k+2) {
1458 1458
 				$key = $line[$k];
1459
-			        $lined[$key] = $line[$k+1];
1460
-			    }
1461
-    			    if (count($lined) > 3) {
1462
-    				$data['hex'] = $lined['hexid'];
1463
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1464
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1465
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1466
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1467
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1468
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1469
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1470
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1471
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1472
-    				$data['id_source'] = $id_source;
1473
-    				$data['format_source'] = 'tsv';
1474
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1475
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1459
+					$lined[$key] = $line[$k+1];
1460
+				}
1461
+					if (count($lined) > 3) {
1462
+					$data['hex'] = $lined['hexid'];
1463
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1464
+					$data['datetime'] = date('Y-m-d H:i:s');;
1465
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1466
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1467
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1468
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1469
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1470
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1471
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1472
+					$data['id_source'] = $id_source;
1473
+					$data['format_source'] = 'tsv';
1474
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1475
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1476 1476
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1477
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1478
-    				unset($lined);
1479
-    				unset($data);
1480
-    			    } else $error = true;
1477
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1478
+					unset($lined);
1479
+					unset($data);
1480
+					} else $error = true;
1481 1481
 			} elseif ($format == 'aprs' && $use_aprs) {
1482
-			    if ($aprs_connect == 0) {
1482
+				if ($aprs_connect == 0) {
1483 1483
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1484 1484
 				$aprs_connect = 1;
1485
-			    }
1485
+				}
1486 1486
 			    
1487
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1487
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1488 1488
 				$aprs_last_tx = time();
1489 1489
 				$data_aprs = "# Keep alive";
1490 1490
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1491
-			    }
1491
+				}
1492 1492
 			    
1493
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1494
-			    //echo 'APRS data : '.$buffer."\n";
1495
-			    $buffer = str_replace('APRS <- ','',$buffer);
1496
-			    $buffer = str_replace('APRS -> ','',$buffer);
1497
-			    //echo $buffer."\n";
1498
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1493
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1494
+				//echo 'APRS data : '.$buffer."\n";
1495
+				$buffer = str_replace('APRS <- ','',$buffer);
1496
+				$buffer = str_replace('APRS -> ','',$buffer);
1497
+				//echo $buffer."\n";
1498
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1499 1499
 				$line = $APRS->parse($buffer);
1500 1500
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1501 1501
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1502
-				    $aprs_last_tx = time();
1503
-				    $data = array();
1504
-				    //print_r($line);
1505
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1506
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1507
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1508
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1509
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1510
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1511
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1512
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1513
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1514
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1515
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1516
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1517
-				    $data['latitude'] = $line['latitude'];
1518
-				    $data['longitude'] = $line['longitude'];
1519
-				    //$data['verticalrate'] = $line[16];
1520
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1521
-				    //else $data['speed'] = 0;
1522
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1523
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1524
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1525
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1502
+					$aprs_last_tx = time();
1503
+					$data = array();
1504
+					//print_r($line);
1505
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1506
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1507
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1508
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1509
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1510
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1511
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1512
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1513
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1514
+					else $data['datetime'] = date('Y-m-d H:i:s');
1515
+					//$data['datetime'] = date('Y-m-d H:i:s');
1516
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1517
+					$data['latitude'] = $line['latitude'];
1518
+					$data['longitude'] = $line['longitude'];
1519
+					//$data['verticalrate'] = $line[16];
1520
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1521
+					//else $data['speed'] = 0;
1522
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1523
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1524
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1525
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1526 1526
 				    
1527
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1528
-				    //else echo 'No heading...'."\n";
1529
-				    //else $data['heading'] = 0;
1530
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1531
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1532
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1533
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1534
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1535
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1536
-    				    $data['id_source'] = $id_source;
1537
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1538
-				    else $data['format_source'] = 'aprs';
1539
-				    $data['source_name'] = $line['source'];
1540
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1541
-				    else $data['source_type'] = 'flarm';
1542
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1543
-				    $currentdate = date('Y-m-d H:i:s');
1544
-				    $aprsdate = strtotime($data['datetime']);
1545
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1546
-				    // Accept data if time <= system time + 20s
1547
-				    //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'])))) {
1548
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1527
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1528
+					//else echo 'No heading...'."\n";
1529
+					//else $data['heading'] = 0;
1530
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1531
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1532
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1533
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1534
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1535
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1536
+						$data['id_source'] = $id_source;
1537
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1538
+					else $data['format_source'] = 'aprs';
1539
+					$data['source_name'] = $line['source'];
1540
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1541
+					else $data['source_type'] = 'flarm';
1542
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1543
+					$currentdate = date('Y-m-d H:i:s');
1544
+					$aprsdate = strtotime($data['datetime']);
1545
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1546
+					// Accept data if time <= system time + 20s
1547
+					//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'])))) {
1548
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1549 1549
 					$send = $SI->add($data);
1550
-				    } elseif ($data['source_type'] == 'ais') {
1550
+					} elseif ($data['source_type'] == 'ais') {
1551 1551
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1552
-				    } elseif (isset($line['stealth'])) {
1552
+					} elseif (isset($line['stealth'])) {
1553 1553
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1554 1554
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1555
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1556
-					    //$line['symbol'] == 'Balloon' ||
1557
-					    $line['symbol'] == 'Glider' || 
1558
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1559
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1560
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1561
-					    $send = $SI->add($data);
1562
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1563
-					    $line['symbol'] == 'Yacht (Sail)' || 
1564
-					    $line['symbol'] == 'Ship (Power Boat)')) {
1565
-					    $send = $MI->add($data);
1566
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1567
-					    $line['symbol'] == 'Car' || 
1568
-					    $line['symbol'] == 'Ambulance' || 
1569
-					    $line['symbol'] == 'Van' || 
1570
-					    $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1571
-					    $line['symbol'] == 'Motorcycle' || 
1572
-					    $line['symbol'] == 'Tractor' || 
1573
-					    $line['symbol'] == 'Police' || 
1574
-					    $line['symbol'] == 'Bike' || 
1575
-					    $line['symbol'] == 'Jogger' || 
1576
-					    $line['symbol'] == 'Horse' || 
1577
-					    $line['symbol'] == 'Bus' || 
1578
-					    $line['symbol'] == 'Jeep' || 
1579
-					    $line['symbol'] == 'Recreational Vehicle' || 
1580
-					    $line['symbol'] == 'Yacht (Sail)' || 
1581
-					    $line['symbol'] == 'Ship (Power Boat)' || 
1582
-					    $line['symbol'] == 'Firetruck' || 
1583
-					    $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1584
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1585
-					    $line['symbol'] == 'SUV' ||
1586
-					    $line['symbol'] == 'Snowmobile' ||
1587
-					    $line['symbol'] == 'Mobile Satellite Station')) {
1588
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1555
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1556
+						//$line['symbol'] == 'Balloon' ||
1557
+						$line['symbol'] == 'Glider' || 
1558
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1559
+						if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1560
+						if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1561
+						$send = $SI->add($data);
1562
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1563
+						$line['symbol'] == 'Yacht (Sail)' || 
1564
+						$line['symbol'] == 'Ship (Power Boat)')) {
1565
+						$send = $MI->add($data);
1566
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1567
+						$line['symbol'] == 'Car' || 
1568
+						$line['symbol'] == 'Ambulance' || 
1569
+						$line['symbol'] == 'Van' || 
1570
+						$line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1571
+						$line['symbol'] == 'Motorcycle' || 
1572
+						$line['symbol'] == 'Tractor' || 
1573
+						$line['symbol'] == 'Police' || 
1574
+						$line['symbol'] == 'Bike' || 
1575
+						$line['symbol'] == 'Jogger' || 
1576
+						$line['symbol'] == 'Horse' || 
1577
+						$line['symbol'] == 'Bus' || 
1578
+						$line['symbol'] == 'Jeep' || 
1579
+						$line['symbol'] == 'Recreational Vehicle' || 
1580
+						$line['symbol'] == 'Yacht (Sail)' || 
1581
+						$line['symbol'] == 'Ship (Power Boat)' || 
1582
+						$line['symbol'] == 'Firetruck' || 
1583
+						$line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1584
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1585
+						$line['symbol'] == 'SUV' ||
1586
+						$line['symbol'] == 'Snowmobile' ||
1587
+						$line['symbol'] == 'Mobile Satellite Station')) {
1588
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1589 1589
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1590 1590
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1591 1591
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1592
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1592
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1593 1593
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1594 1594
 					$Source->deleteOldLocationByType('gs');
1595 1595
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -1597,7 +1597,7 @@  discard block
 block discarded – undo
1597 1597
 					} else {
1598 1598
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1599 1599
 					}
1600
-				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1600
+					} elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1601 1601
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1602 1602
 					if ($globalDebug) echo '# Weather Station added'."\n";
1603 1603
 					$Source->deleteOldLocationByType('wx');
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
 					} else {
1608 1608
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1609 1609
 					}
1610
-				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1610
+					} elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1611 1611
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1612 1612
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1613 1613
 					$Source->deleteOldLocationByType('lightning');
@@ -1616,11 +1616,11 @@  discard block
 block discarded – undo
1616 1616
 					} else {
1617 1617
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1618 1618
 					}
1619
-				    } elseif ($globalDebug) {
1620
-				    	echo '/!\ Not added: '.$buffer."\n";
1621
-				    	print_r($line);
1622
-				    }
1623
-				    unset($data);
1619
+					} elseif ($globalDebug) {
1620
+						echo '/!\ Not added: '.$buffer."\n";
1621
+						print_r($line);
1622
+					}
1623
+					unset($data);
1624 1624
 				}
1625 1625
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1626 1626
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -1639,12 +1639,12 @@  discard block
 block discarded – undo
1639 1639
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
1640 1640
 					$globalSources[$nb]['last_weather_clean'] = time();
1641 1641
 				}
1642
-			    }
1642
+				}
1643 1643
 			} else {
1644
-			    $line = explode(',', $buffer);
1645
-    			    if (count($line) > 20) {
1646
-    			    	$data['hex'] = $line[4];
1647
-    				/*
1644
+				$line = explode(',', $buffer);
1645
+					if (count($line) > 20) {
1646
+						$data['hex'] = $line[4];
1647
+					/*
1648 1648
     				$data['datetime'] = $line[6].' '.$line[7];
1649 1649
     					date_default_timezone_set($globalTimezone);
1650 1650
     					$datetime = new DateTime($data['datetime']);
@@ -1652,30 +1652,30 @@  discard block
 block discarded – undo
1652 1652
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1653 1653
     					date_default_timezone_set('UTC');
1654 1654
     				*/
1655
-    				// Force datetime to current UTC datetime
1656
-    				date_default_timezone_set('UTC');
1657
-    				$data['datetime'] = date('Y-m-d H:i:s');
1658
-    				$data['ident'] = trim($line[10]);
1659
-    				$data['latitude'] = $line[14];
1660
-    				$data['longitude'] = $line[15];
1661
-    				$data['verticalrate'] = $line[16];
1662
-    				$data['emergency'] = $line[20];
1663
-    				$data['speed'] = $line[12];
1664
-    				$data['squawk'] = $line[17];
1665
-    				$data['altitude'] = $line[11];
1666
-    				$data['heading'] = $line[13];
1667
-    				$data['ground'] = $line[21];
1668
-    				$data['emergency'] = $line[19];
1669
-    				$data['format_source'] = 'sbs';
1655
+					// Force datetime to current UTC datetime
1656
+					date_default_timezone_set('UTC');
1657
+					$data['datetime'] = date('Y-m-d H:i:s');
1658
+					$data['ident'] = trim($line[10]);
1659
+					$data['latitude'] = $line[14];
1660
+					$data['longitude'] = $line[15];
1661
+					$data['verticalrate'] = $line[16];
1662
+					$data['emergency'] = $line[20];
1663
+					$data['speed'] = $line[12];
1664
+					$data['squawk'] = $line[17];
1665
+					$data['altitude'] = $line[11];
1666
+					$data['heading'] = $line[13];
1667
+					$data['ground'] = $line[21];
1668
+					$data['emergency'] = $line[19];
1669
+					$data['format_source'] = 'sbs';
1670 1670
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1671
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1671
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1672 1672
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1673
-    				$data['id_source'] = $id_source;
1674
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1675
-    				else $error = true;
1676
-    				unset($data);
1677
-    			    } else $error = true;
1678
-			    if ($error) {
1673
+					$data['id_source'] = $id_source;
1674
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1675
+					else $error = true;
1676
+					unset($data);
1677
+					} else $error = true;
1678
+				if ($error) {
1679 1679
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1680 1680
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1681 1681
 				} else {
@@ -1691,13 +1691,13 @@  discard block
 block discarded – undo
1691 1691
 					connect_all($sourceer);
1692 1692
 					$sourceer = array();
1693 1693
 				}
1694
-			    }
1694
+				}
1695 1695
 			}
1696 1696
 			// Sleep for xxx microseconds
1697 1697
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1698
-		    } else {
1698
+			} else {
1699 1699
 			if ($format == 'flightgearmp') {
1700
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1700
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1701 1701
 				//@socket_close($r);
1702 1702
 				sleep($globalMinFetch);
1703 1703
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1706,9 +1706,9 @@  discard block
 block discarded – undo
1706 1706
 				break;
1707 1707
 				
1708 1708
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1709
-			    if (isset($tt[$format])) $tt[$format]++;
1710
-			    else $tt[$format] = 0;
1711
-			    if ($tt[$format] > 30) {
1709
+				if (isset($tt[$format])) $tt[$format]++;
1710
+				else $tt[$format] = 0;
1711
+				if ($tt[$format] > 30) {
1712 1712
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1713 1713
 				//@socket_close($r);
1714 1714
 				sleep(2);
@@ -1719,23 +1719,23 @@  discard block
 block discarded – undo
1719 1719
 				//connect_all($globalSources);
1720 1720
 				$tt[$format]=0;
1721 1721
 				break;
1722
-			    }
1722
+				}
1723
+			}
1723 1724
 			}
1724
-		    }
1725 1725
 		}
1726
-	    } else {
1726
+		} else {
1727 1727
 		$error = socket_strerror(socket_last_error());
1728 1728
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1729 1729
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1730 1730
 			if (isset($globalDebug)) echo "Restarting...\n";
1731 1731
 			// Restart the script if possible
1732 1732
 			if (is_array($sockets)) {
1733
-			    if ($globalDebug) echo "Shutdown all sockets...";
1733
+				if ($globalDebug) echo "Shutdown all sockets...";
1734 1734
 			    
1735
-			    foreach ($sockets as $sock) {
1735
+				foreach ($sockets as $sock) {
1736 1736
 				@socket_shutdown($sock,2);
1737 1737
 				@socket_close($sock);
1738
-			    }
1738
+				}
1739 1739
 			    
1740 1740
 			}
1741 1741
 			if ($globalDebug) echo "Waiting...";
@@ -1750,15 +1750,15 @@  discard block
 block discarded – undo
1750 1750
 			if ($globalDebug) echo "Restart all connections...";
1751 1751
 			connect_all($globalSources);
1752 1752
 		}
1753
-	    }
1753
+		}
1754 1754
 	}
1755 1755
 	if ($globalDaemon === false) {
1756
-	    if ($globalDebug) echo 'Check all...'."\n";
1757
-	    if (isset($SI)) $SI->checkAll();
1758
-	    if (isset($TI)) $TI->checkAll();
1759
-	    if (isset($MI)) $MI->checkAll();
1756
+		if ($globalDebug) echo 'Check all...'."\n";
1757
+		if (isset($SI)) $SI->checkAll();
1758
+		if (isset($TI)) $TI->checkAll();
1759
+		if (isset($MI)) $MI->checkAll();
1760
+	}
1760 1761
 	}
1761
-    }
1762 1762
 }
1763 1763
 
1764 1764
 ?>
Please login to merge, or discard this patch.
Braces   +1049 added lines, -358 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -141,7 +186,9 @@  discard block
 block discarded – undo
141 186
 }
142 187
 
143 188
 // let's try and connect
144
-if ($globalDebug) echo "Connecting...\n";
189
+if ($globalDebug) {
190
+	echo "Connecting...\n";
191
+}
145 192
 $use_aprs = false;
146 193
 $aprs_full = false;
147 194
 $reset = 0;
@@ -150,7 +197,9 @@  discard block
 block discarded – undo
150 197
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
151 198
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
152 199
     $reset++;
153
-    if ($globalDebug) echo 'Connect to all...'."\n";
200
+    if ($globalDebug) {
201
+    	echo 'Connect to all...'."\n";
202
+    }
154 203
     foreach ($hosts as $id => $value) {
155 204
 	$host = $value['host'];
156 205
 	$globalSources[$id]['last_exec'] = 0;
@@ -160,22 +209,30 @@  discard block
 block discarded – undo
160 209
         	//$formats[$id] = 'deltadbtxt';
161 210
         	$globalSources[$id]['format'] = 'deltadbtxt';
162 211
         	//$last_exec['deltadbtxt'] = 0;
163
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
212
+        	if ($globalDebug) {
213
+        		echo "Connect to deltadb source (".$host.")...\n";
214
+        	}
164 215
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
165 216
         	//$formats[$id] = 'vatsimtxt';
166 217
         	$globalSources[$id]['format'] = 'vatsimtxt';
167 218
         	//$last_exec['vatsimtxt'] = 0;
168
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
219
+        	if ($globalDebug) {
220
+        		echo "Connect to vatsim source (".$host.")...\n";
221
+        	}
169 222
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
170 223
         	//$formats[$id] = 'aircraftlistjson';
171 224
         	$globalSources[$id]['format'] = 'aircraftlistjson';
172 225
         	//$last_exec['aircraftlistjson'] = 0;
173
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
226
+        	if ($globalDebug) {
227
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	}
174 229
     	    } else if (preg_match('/opensky/i',$host)) {
175 230
         	//$formats[$id] = 'aircraftlistjson';
176 231
         	$globalSources[$id]['format'] = 'opensky';
177 232
         	//$last_exec['aircraftlistjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to opensky source (".$host.")...\n";
235
+        	}
179 236
     	    /*
180 237
     	    // Disabled for now, site change source format
181 238
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -192,7 +249,9 @@  discard block
 block discarded – undo
192 249
         	//$formats[$id] = 'planeupdatefaa';
193 250
         	$globalSources[$id]['format'] = 'planeupdatefaa';
194 251
         	//$last_exec['planeupdatefaa'] = 0;
195
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
252
+        	if ($globalDebug) {
253
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
254
+        	}
196 255
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197 256
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198 257
         	    exit(0);
@@ -201,32 +260,46 @@  discard block
 block discarded – undo
201 260
         	//$formats[$id] = 'phpvmacars';
202 261
         	$globalSources[$id]['format'] = 'phpvmacars';
203 262
         	//$last_exec['phpvmacars'] = 0;
204
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
263
+        	if ($globalDebug) {
264
+        		echo "Connect to phpvmacars source (".$host.")...\n";
265
+        	}
205 266
             } else if (preg_match('/VAM-json.php$/i',$host)) {
206 267
         	//$formats[$id] = 'phpvmacars';
207 268
         	$globalSources[$id]['format'] = 'vam';
208
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
269
+        	if ($globalDebug) {
270
+        		echo "Connect to Vam source (".$host.")...\n";
271
+        	}
209 272
             } else if (preg_match('/whazzup/i',$host)) {
210 273
         	//$formats[$id] = 'whazzup';
211 274
         	$globalSources[$id]['format'] = 'whazzup';
212 275
         	//$last_exec['whazzup'] = 0;
213
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
276
+        	if ($globalDebug) {
277
+        		echo "Connect to whazzup source (".$host.")...\n";
278
+        	}
214 279
             } else if (preg_match('/blitzortung/i',$host)) {
215 280
         	$globalSources[$id]['format'] = 'blitzortung';
216
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
281
+        	if ($globalDebug) {
282
+        		echo "Connect to blitzortung source (".$host.")...\n";
283
+        	}
217 284
             } else if (preg_match('/airwhere/i',$host)) {
218 285
         	$globalSources[$id]['format'] = 'airwhere';
219
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
286
+        	if ($globalDebug) {
287
+        		echo "Connect to airwhere source (".$host.")...\n";
288
+        	}
220 289
             } else if (preg_match('/recentpireps/i',$host)) {
221 290
         	//$formats[$id] = 'pirepsjson';
222 291
         	$globalSources[$id]['format'] = 'pirepsjson';
223 292
         	//$last_exec['pirepsjson'] = 0;
224
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
293
+        	if ($globalDebug) {
294
+        		echo "Connect to pirepsjson source (".$host.")...\n";
295
+        	}
225 296
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
226 297
         	//$formats[$id] = 'fr24json';
227 298
         	$globalSources[$id]['format'] = 'fr24json';
228 299
         	//$last_exec['fr24json'] = 0;
229
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
300
+        	if ($globalDebug) {
301
+        		echo "Connect to fr24 source (".$host.")...\n";
302
+        	}
230 303
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
231 304
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
232 305
         	    exit(0);
@@ -235,7 +308,9 @@  discard block
 block discarded – undo
235 308
         	//$formats[$id] = 'fr24json';
236 309
         	$globalSources[$id]['format'] = 'myshiptracking';
237 310
         	//$last_exec['fr24json'] = 0;
238
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
311
+        	if ($globalDebug) {
312
+        		echo "Connect to myshiptracking source (".$host.")...\n";
313
+        	}
239 314
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
240 315
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
241 316
         	    exit(0);
@@ -244,17 +319,24 @@  discard block
 block discarded – undo
244 319
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
245 320
         	//$formats[$id] = 'tsv';
246 321
         	$globalSources[$id]['format'] = 'tsv';
247
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
322
+        	if ($globalDebug) {
323
+        		echo "Connect to tsv source (".$host.")...\n";
324
+        	}
248 325
             }
249 326
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
250 327
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
251 328
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
252 329
     		    if ($idf !== false) {
253 330
     			$httpfeeds[$id] = $idf;
254
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
331
+        		if ($globalDebug) {
332
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
333
+        		}
334
+    		    } elseif ($globalDebug) {
335
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
255 336
     		    }
256
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
257
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
337
+    		} elseif ($globalDebug) {
338
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
339
+    		}
258 340
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
259 341
 	    $hostport = explode(':',$host);
260 342
 	    if (isset($hostport[1])) {
@@ -294,17 +376,25 @@  discard block
 block discarded – undo
294 376
         		//$formats[$id] = 'beast';
295 377
         		$globalSources[$id]['format'] = 'beast';
296 378
 		    //} else $formats[$id] = 'sbs';
297
-		    } else $globalSources[$id]['format'] = 'sbs';
379
+		    } else {
380
+		    	$globalSources[$id]['format'] = 'sbs';
381
+		    }
298 382
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
299 383
 		}
300
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
384
+		if ($globalDebug) {
385
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
386
+		}
301 387
             } else {
302
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
388
+		if ($globalDebug) {
389
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
390
+		}
303 391
     	    }
304 392
         }
305 393
     }
306 394
 }
307
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
395
+if (!isset($globalMinFetch)) {
396
+	$globalMinFetch = 15;
397
+}
308 398
 
309 399
 // Initialize all
310 400
 $status = array();
@@ -313,13 +403,19 @@  discard block
 block discarded – undo
313 403
 $formats = array();
314 404
 $last_exec = array();
315 405
 $time = time();
316
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
317
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
318
-else $timeout = 20;
406
+if (isset($globalSourcesTimeout)) {
407
+	$timeout = $globalSourcesTimeOut;
408
+} else if (isset($globalSBS1TimeOut)) {
409
+	$timeout = $globalSBS1TimeOut;
410
+} else {
411
+	$timeout = 20;
412
+}
319 413
 $errno = '';
320 414
 $errstr='';
321 415
 
322
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
416
+if (!isset($globalDaemon)) {
417
+	$globalDaemon = TRUE;
418
+}
323 419
 /* Initiate connections to all the hosts simultaneously */
324 420
 //connect_all($hosts);
325 421
 //connect_all($globalSources);
@@ -348,7 +444,9 @@  discard block
 block discarded – undo
348 444
     if (isset($source['format']) && $source['format'] == 'aprs') {
349 445
 	$aprs_connect = 0;
350 446
 	$use_aprs = true;
351
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
447
+	if (isset($source['port']) && $source['port'] == '10152') {
448
+		$aprs_full = true;
449
+	}
352 450
 	break;
353 451
     }
354 452
 }
@@ -359,25 +457,48 @@  discard block
 block discarded – undo
359 457
 	$aprs_connect = 0;
360 458
 	$aprs_keep = 120;
361 459
 	$aprs_last_tx = time();
362
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
363
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
364
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
365
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
366
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
367
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
368
-	if ($aprs_full) $aprs_filter = '';
369
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
370
-	else $aprs_pass = '-1';
460
+	if (isset($globalAPRSversion)) {
461
+		$aprs_version = $globalAPRSversion;
462
+	} else {
463
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
464
+	}
465
+	if (isset($globalAPRSssid)) {
466
+		$aprs_ssid = $globalAPRSssid;
467
+	} else {
468
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
469
+	}
470
+	if (isset($globalAPRSfilter)) {
471
+		$aprs_filter = $globalAPRSfilter;
472
+	} else {
473
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
474
+	}
475
+	if ($aprs_full) {
476
+		$aprs_filter = '';
477
+	}
478
+	if (isset($globalAPRSpass)) {
479
+		$aprs_pass = $globalAPRSpass;
480
+	} else {
481
+		$aprs_pass = '-1';
482
+	}
371 483
 
372
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
373
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
374
-}
484
+	if ($aprs_filter != '') {
485
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
486
+	} else {
487
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
488
+	}
489
+	}
375 490
 
376 491
 // connected - lets do some work
377
-if ($globalDebug) echo "Connected!\n";
492
+if ($globalDebug) {
493
+	echo "Connected!\n";
494
+}
378 495
 sleep(1);
379
-if ($globalDebug) echo "SCAN MODE \n\n";
380
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
496
+if ($globalDebug) {
497
+	echo "SCAN MODE \n\n";
498
+}
499
+if (!isset($globalCronEnd)) {
500
+	$globalCronEnd = 60;
501
+}
381 502
 $endtime = time()+$globalCronEnd;
382 503
 $i = 1;
383 504
 $tt = array();
@@ -391,20 +512,28 @@  discard block
 block discarded – undo
391 512
 
392 513
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
393 514
 while ($i > 0) {
394
-    if (!$globalDaemon) $i = $endtime-time();
515
+    if (!$globalDaemon) {
516
+    	$i = $endtime-time();
517
+    }
395 518
     // Delete old ATC
396 519
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
397
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
520
+	if ($globalDebug) {
521
+		echo 'Delete old ATC...'."\n";
522
+	}
398 523
         $ATC->deleteOldATC();
399 524
     }
400 525
     
401 526
     if (count($last_exec) == count($globalSources)) {
402 527
 	$max = $globalMinFetch;
403 528
 	foreach ($last_exec as $last) {
404
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
529
+	    if ((time() - $last['last']) < $max) {
530
+	    	$max = time() - $last['last'];
531
+	    }
405 532
 	}
406 533
 	if ($max != $globalMinFetch) {
407
-	    if ($globalDebug) echo 'Sleeping...'."\n";
534
+	    if ($globalDebug) {
535
+	    	echo 'Sleeping...'."\n";
536
+	    }
408 537
 	    sleep($globalMinFetch-$max+2);
409 538
 	}
410 539
     }
@@ -414,7 +543,9 @@  discard block
 block discarded – undo
414 543
     foreach ($globalSources as $id => $value) {
415 544
 	date_default_timezone_set('UTC');
416 545
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
417
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
546
+	if (!isset($last_exec[$id]['last'])) {
547
+		$last_exec[$id]['last'] = 0;
548
+	}
418 549
 	if ($value['format'] == 'deltadbtxt' && 
419 550
 	    (
420 551
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -423,7 +554,9 @@  discard block
 block discarded – undo
423 554
 	) {
424 555
 	    //$buffer = $Common->getData($hosts[$id]);
425 556
 	    $buffer = $Common->getData($value['host']);
426
-	    if ($buffer != '') $reset = 0;
557
+	    if ($buffer != '') {
558
+	    	$reset = 0;
559
+	    }
427 560
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
428 561
 	    $buffer = explode('\n',$buffer);
429 562
 	    foreach ($buffer as $line) {
@@ -432,20 +565,41 @@  discard block
 block discarded – undo
432 565
 	            $data = array();
433 566
 	            $data['hex'] = $line[1]; // hex
434 567
 	            $data['ident'] = $line[2]; // ident
435
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
436
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
437
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
438
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
439
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
568
+	            if (isset($line[3])) {
569
+	            	$data['altitude'] = $line[3];
570
+	            }
571
+	            // altitude
572
+	            if (isset($line[4])) {
573
+	            	$data['speed'] = $line[4];
574
+	            }
575
+	            // speed
576
+	            if (isset($line[5])) {
577
+	            	$data['heading'] = $line[5];
578
+	            }
579
+	            // heading
580
+	            if (isset($line[6])) {
581
+	            	$data['latitude'] = $line[6];
582
+	            }
583
+	            // lat
584
+	            if (isset($line[7])) {
585
+	            	$data['longitude'] = $line[7];
586
+	            }
587
+	            // long
440 588
 	            $data['verticalrate'] = ''; // vertical rate
441 589
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
442 590
 	            $data['emergency'] = ''; // emergency
443 591
 		    $data['datetime'] = date('Y-m-d H:i:s');
444 592
 		    $data['format_source'] = 'deltadbtxt';
445 593
     		    $data['id_source'] = $id_source;
446
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
447
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
448
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
594
+		    if (isset($value['name']) && $value['name'] != '') {
595
+		    	$data['source_name'] = $value['name'];
596
+		    }
597
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
598
+		    	$data['noarchive'] = true;
599
+		    }
600
+		    if (isset($value['sourcestats'])) {
601
+		    	$data['sourcestats'] = $value['sourcestats'];
602
+		    }
449 603
     		    $SI->add($data);
450 604
 		    unset($data);
451 605
     		}
@@ -460,7 +614,9 @@  discard block
 block discarded – undo
460 614
 	    date_default_timezone_set('CET');
461 615
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
462 616
 	    date_default_timezone_set('UTC');
463
-	    if ($buffer != '') $reset = 0;
617
+	    if ($buffer != '') {
618
+	    	$reset = 0;
619
+	    }
464 620
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
465 621
 	    $buffer = explode('\n',$buffer);
466 622
 	    foreach ($buffer as $line) {
@@ -469,16 +625,36 @@  discard block
 block discarded – undo
469 625
 		    $add = false;
470 626
 		    $ais_data = $AIS->parse_line(trim($line));
471 627
 		    $data = array();
472
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
473
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
474
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
475
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
476
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
477
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
478
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
479
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
480
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
481
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
628
+		    if (isset($ais_data['ident'])) {
629
+		    	$data['ident'] = $ais_data['ident'];
630
+		    }
631
+		    if (isset($ais_data['mmsi'])) {
632
+		    	$data['mmsi'] = $ais_data['mmsi'];
633
+		    }
634
+		    if (isset($ais_data['speed'])) {
635
+		    	$data['speed'] = $ais_data['speed'];
636
+		    }
637
+		    if (isset($ais_data['heading'])) {
638
+		    	$data['heading'] = $ais_data['heading'];
639
+		    }
640
+		    if (isset($ais_data['latitude'])) {
641
+		    	$data['latitude'] = $ais_data['latitude'];
642
+		    }
643
+		    if (isset($ais_data['longitude'])) {
644
+		    	$data['longitude'] = $ais_data['longitude'];
645
+		    }
646
+		    if (isset($ais_data['status'])) {
647
+		    	$data['status'] = $ais_data['status'];
648
+		    }
649
+		    if (isset($ais_data['type'])) {
650
+		    	$data['type'] = $ais_data['type'];
651
+		    }
652
+		    if (isset($ais_data['imo'])) {
653
+		    	$data['imo'] = $ais_data['imo'];
654
+		    }
655
+		    if (isset($ais_data['callsign'])) {
656
+		    	$data['callsign'] = $ais_data['callsign'];
657
+		    }
482 658
 		    if (isset($ais_data['timestamp'])) {
483 659
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
484 660
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -492,8 +668,12 @@  discard block
 block discarded – undo
492 668
 		    $data['format_source'] = 'aisnmeatxt';
493 669
     		    $data['id_source'] = $id_source;
494 670
 		    //print_r($data);
495
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
496
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
671
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
672
+		    	$data['noarchive'] = true;
673
+		    }
674
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
675
+		    	$MI->add($data);
676
+		    }
497 677
 		    unset($data);
498 678
 		}
499 679
     	    }
@@ -513,20 +693,48 @@  discard block
 block discarded – undo
513 693
 			    if ($line != '') {
514 694
 				$ais_data = $AIS->parse_line(trim($line));
515 695
 				$data = array();
516
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
517
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
518
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
519
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
520
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
521
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
522
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
523
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
524
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
525
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
526
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
527
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
528
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
529
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
696
+				if (isset($ais_data['ident'])) {
697
+					$data['ident'] = $ais_data['ident'];
698
+				}
699
+				if (isset($ais_data['mmsi'])) {
700
+					$data['mmsi'] = $ais_data['mmsi'];
701
+				}
702
+				if (isset($ais_data['speed'])) {
703
+					$data['speed'] = $ais_data['speed'];
704
+				}
705
+				if (isset($ais_data['heading'])) {
706
+					$data['heading'] = $ais_data['heading'];
707
+				}
708
+				if (isset($ais_data['latitude'])) {
709
+					$data['latitude'] = $ais_data['latitude'];
710
+				}
711
+				if (isset($ais_data['longitude'])) {
712
+					$data['longitude'] = $ais_data['longitude'];
713
+				}
714
+				if (isset($ais_data['status'])) {
715
+					$data['status'] = $ais_data['status'];
716
+				}
717
+				if (isset($ais_data['statusid'])) {
718
+					$data['status_id'] = $ais_data['statusid'];
719
+				}
720
+				if (isset($ais_data['type'])) {
721
+					$data['type'] = $ais_data['type'];
722
+				}
723
+				if (isset($ais_data['typeid'])) {
724
+					$data['type_id'] = $ais_data['typeid'];
725
+				}
726
+				if (isset($ais_data['imo'])) {
727
+					$data['imo'] = $ais_data['imo'];
728
+				}
729
+				if (isset($ais_data['callsign'])) {
730
+					$data['callsign'] = $ais_data['callsign'];
731
+				}
732
+				if (isset($ais_data['destination'])) {
733
+					$data['arrival_code'] = $ais_data['destination'];
734
+				}
735
+				if (isset($ais_data['eta_ts'])) {
736
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
737
+				}
530 738
 				if (isset($ais_data['timestamp'])) {
531 739
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
532 740
 				} else {
@@ -534,18 +742,27 @@  discard block
 block discarded – undo
534 742
 				}
535 743
 				$data['format_source'] = 'aisnmeahttp';
536 744
 				$data['id_source'] = $id_source;
537
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
538
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
745
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
746
+					$data['noarchive'] = true;
747
+				}
748
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
749
+					$MI->add($data);
750
+				}
539 751
 				unset($data);
540 752
 			    }
541 753
 			}
542 754
 		    }
543 755
 		} else {
544 756
 		    $format = $value['format'];
545
-		    if (isset($tt[$format])) $tt[$format]++;
546
-		    else $tt[$format] = 0;
757
+		    if (isset($tt[$format])) {
758
+		    	$tt[$format]++;
759
+		    } else {
760
+		    	$tt[$format] = 0;
761
+		    }
547 762
 		    if ($tt[$format] > 30) {
548
-			if ($globalDebug) echo 'Reconnect...'."\n";
763
+			if ($globalDebug) {
764
+				echo 'Reconnect...'."\n";
765
+			}
549 766
 			sleep(2);
550 767
 			$sourceeen[] = $value;
551 768
 			connect_all($sourceeen);
@@ -583,7 +800,9 @@  discard block
 block discarded – undo
583 800
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
584 801
 			    $data['format_source'] = 'myshiptracking';
585 802
 			    $data['id_source'] = $id_source;
586
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
803
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
804
+			    	$data['noarchive'] = true;
805
+			    }
587 806
 			    $MI->add($data);
588 807
 			    unset($data);
589 808
 			}
@@ -608,7 +827,9 @@  discard block
 block discarded – undo
608 827
 			    $data['callsign'] = $line['callsign'];
609 828
 			    $data['mmsi'] = $line['mmsi'];
610 829
 			    $data['speed'] = $line['sog'];
611
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
830
+			    if ($line['heading'] != '511') {
831
+			    	$data['heading'] = $line['heading'];
832
+			    }
612 833
 			    $data['latitude'] = $line['latitude'];
613 834
 			    $data['longitude'] = $line['longitude'];
614 835
 			    $data['type_id'] = $line['shiptype'];
@@ -616,7 +837,9 @@  discard block
 block discarded – undo
616 837
 			    $data['datetime'] = $line['time'];
617 838
 			    $data['format_source'] = 'boatbeaconapp';
618 839
 			    $data['id_source'] = $id_source;
619
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
840
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
841
+			    	$data['noarchive'] = true;
842
+			    }
620 843
 			    $MI->add($data);
621 844
 			    unset($data);
622 845
 			}
@@ -637,22 +860,44 @@  discard block
 block discarded – undo
637 860
 		if (isset($all_data['features'][0]['id'])) {
638 861
 		    foreach ($all_data['features'] as $line) {
639 862
 			$data = array();
640
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
641
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
642
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = $line['properties']['mmsi'];
643
-			if (isset($line['properties']['imo'])) $data['mmsi'] = $line['properties']['imo'];
644
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
645
-			if (isset($line['properties']['heading'])) $data['heading'] = $line['properties']['heading'];
863
+			if (isset($line['properties']['name'])) {
864
+				$data['ident'] = $line['properties']['name'];
865
+			}
866
+			if (isset($line['properties']['callsign'])) {
867
+				$data['callsign'] = $line['properties']['callsign'];
868
+			}
869
+			if (isset($line['properties']['mmsi'])) {
870
+				$data['mmsi'] = $line['properties']['mmsi'];
871
+			}
872
+			if (isset($line['properties']['imo'])) {
873
+				$data['mmsi'] = $line['properties']['imo'];
874
+			}
875
+			if (isset($line['properties']['speed'])) {
876
+				$data['speed'] = $line['properties']['speed'];
877
+			}
878
+			if (isset($line['properties']['heading'])) {
879
+				$data['heading'] = $line['properties']['heading'];
880
+			}
646 881
 			$data['latitude'] = $line['geometry']['coordinates'][1];
647 882
 			$data['longitude'] = $line['geometry']['coordinates'][0];
648
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
649
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
650
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
883
+			if (isset($line['properties']['vesselType'])) {
884
+				$data['type'] = $line['properties']['vesselType'];
885
+			}
886
+			if (isset($line['properties']['destination'])) {
887
+				$data['arrival_code'] = $line['properties']['destination'];
888
+			}
889
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
890
+				$data['arrival_date'] = $line['properties']['eta'];
891
+			}
651 892
 			$data['format_source'] = 'boatnerd';
652 893
 			$data['id_source'] = $id_source;
653 894
 			$data['datetime'] = date('Y-m-d H:i:s');
654
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
655
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
895
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
896
+				$data['noarchive'] = true;
897
+			}
898
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
899
+				$MI->add($data);
900
+			}
656 901
 			unset($data);
657 902
 		    }
658 903
 		}
@@ -668,7 +913,9 @@  discard block
 block discarded – undo
668 913
 	    echo 'download...';
669 914
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
670 915
 	    echo 'done !'."\n";
671
-	    if ($buffer != '') $reset = 0;
916
+	    if ($buffer != '') {
917
+	    	$reset = 0;
918
+	    }
672 919
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
673 920
 	    $buffer = explode('\n',$buffer);
674 921
 	    foreach ($buffer as $line) {
@@ -693,7 +940,9 @@  discard block
 block discarded – undo
693 940
 		    //$data['etaTime'] = substr($line,135,5);
694 941
 		    $data['format_source'] = 'shipplotter';
695 942
     		    $data['id_source'] = $id_source;
696
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
943
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
944
+		    	$data['noarchive'] = true;
945
+		    }
697 946
 		    //print_r($data);
698 947
 		    echo 'Add...'."\n";
699 948
 		    $MI->add($data);
@@ -727,16 +976,28 @@  discard block
 block discarded – undo
727 976
     		    $line = explode(':', $line);
728 977
     		    if (count($line) > 30 && $line[0] != 'callsign') {
729 978
 			$data = array();
730
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
731
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
979
+			if (isset($line[37]) && $line[37] != '') {
980
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
981
+			} else {
982
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
983
+			}
732 984
 			$data['pilot_id'] = $line[1];
733 985
 			$data['pilot_name'] = $line[2];
734 986
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
735 987
 			$data['ident'] = $line[0]; // ident
736
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
988
+			if ($line[7] != '' && $line[7] != 0) {
989
+				$data['altitude'] = $line[7];
990
+			}
991
+			// altitude
737 992
 			$data['speed'] = $line[8]; // speed
738
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
739
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
993
+			if (isset($line[45])) {
994
+				$data['heading'] = $line[45];
995
+			}
996
+			// heading
997
+			elseif (isset($line[38])) {
998
+				$data['heading'] = $line[38];
999
+			}
1000
+			// heading
740 1001
 			$data['latitude'] = $line[5]; // lat
741 1002
 	        	$data['longitude'] = $line[6]; // long
742 1003
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -752,7 +1013,9 @@  discard block
 block discarded – undo
752 1013
 			$data['frequency'] = $line[4];
753 1014
 			$data['type'] = $line[18];
754 1015
 			$data['range'] = $line[19];
755
-			if (isset($line[35])) $data['info'] = $line[35];
1016
+			if (isset($line[35])) {
1017
+				$data['info'] = $line[35];
1018
+			}
756 1019
     			$data['id_source'] = $id_source;
757 1020
 	    		//$data['arrival_airport_time'] = ;
758 1021
 	    		if ($line[9] != '') {
@@ -766,27 +1029,47 @@  discard block
 block discarded – undo
766 1029
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
767 1030
 	    		*/
768 1031
 	    		$data['format_source'] = $value['format'];
769
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
770
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
771
-    			if ($line[3] == 'PILOT') $SI->add($data);
772
-			elseif ($line[3] == 'ATC') {
1032
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1033
+				$data['noarchive'] = true;
1034
+			}
1035
+			if (isset($value['name']) && $value['name'] != '') {
1036
+				$data['source_name'] = $value['name'];
1037
+			}
1038
+    			if ($line[3] == 'PILOT') {
1039
+    				$SI->add($data);
1040
+    			} elseif ($line[3] == 'ATC') {
773 1041
 				//print_r($data);
774 1042
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
775 1043
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
776 1044
 				$typec = substr($data['ident'],-3);
777
-				if ($typec == 'APP') $data['type'] = 'Approach';
778
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
779
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
780
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
781
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
782
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
783
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
784
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
785
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
786
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1045
+				if ($typec == 'APP') {
1046
+					$data['type'] = 'Approach';
1047
+				} elseif ($typec == 'TWR') {
1048
+					$data['type'] = 'Tower';
1049
+				} elseif ($typec == 'OBS') {
1050
+					$data['type'] = 'Observer';
1051
+				} elseif ($typec == 'GND') {
1052
+					$data['type'] = 'Ground';
1053
+				} elseif ($typec == 'DEL') {
1054
+					$data['type'] = 'Delivery';
1055
+				} elseif ($typec == 'DEP') {
1056
+					$data['type'] = 'Departure';
1057
+				} elseif ($typec == 'FSS') {
1058
+					$data['type'] = 'Flight Service Station';
1059
+				} elseif ($typec == 'CTR') {
1060
+					$data['type'] = 'Control Radar or Centre';
1061
+				} elseif ($data['type'] == '') {
1062
+					$data['type'] = 'Observer';
1063
+				}
1064
+				if (!isset($data['source_name'])) {
1065
+					$data['source_name'] = '';
1066
+				}
787 1067
 				if (isset($ATC)) {
788
-					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']);
789
-					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']);
1068
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1069
+						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']);
1070
+					} else {
1071
+						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']);
1072
+					}
790 1073
 				}
791 1074
 			}
792 1075
     			unset($data);
@@ -813,14 +1096,20 @@  discard block
 block discarded – undo
813 1096
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
814 1097
 			$data['latitude'] = (float)$line['pktLatitude'];
815 1098
 			$data['longitude'] = (float)$line['pktLongitude'];
816
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
817
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1099
+			if ((float)$line['pktTrack'] != 0) {
1100
+				$data['heading'] = (float)$line['pktTrack'];
1101
+			}
1102
+			if ((int)$line['pktSpeed'] != 0) {
1103
+				$data['speed'] = (int)$line['pktSpeed'];
1104
+			}
818 1105
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
819 1106
 			$data['altitude_relative'] = 'AMSL';
820 1107
 			$data['pilot_id'] = (int)$line['pktPilotID'];
821 1108
 			$data['aircraft_icao'] = 'PARAGLIDER';
822 1109
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
823
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1110
+			if (isset($pilot_data[4])) {
1111
+				$data['pilot_name'] = $pilot_data[4];
1112
+			}
824 1113
 			$data['format_source'] = $value['format'];
825 1114
 			$SI->add($data);
826 1115
 			unset($data);
@@ -868,25 +1157,59 @@  discard block
 block discarded – undo
868 1157
 		    foreach ($all_data['acList'] as $line) {
869 1158
 			$data = array();
870 1159
 			$data['hex'] = $line['Icao']; // hex
871
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
872
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
873
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
874
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
875
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
876
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1160
+			if (isset($line['Call'])) {
1161
+				$data['ident'] = $line['Call'];
1162
+			}
1163
+			// ident
1164
+			if (isset($line['Alt'])) {
1165
+				$data['altitude'] = $line['Alt'];
1166
+			}
1167
+			// altitude
1168
+			if (isset($line['Spd'])) {
1169
+				$data['speed'] = $line['Spd'];
1170
+			}
1171
+			// speed
1172
+			if (isset($line['Trak'])) {
1173
+				$data['heading'] = $line['Trak'];
1174
+			}
1175
+			// heading
1176
+			if (isset($line['Lat'])) {
1177
+				$data['latitude'] = $line['Lat'];
1178
+			}
1179
+			// lat
1180
+			if (isset($line['Long'])) {
1181
+				$data['longitude'] = $line['Long'];
1182
+			}
1183
+			// long
877 1184
 			//$data['verticalrate'] = $line['']; // verticale rate
878
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1185
+			if (isset($line['Sqk'])) {
1186
+				$data['squawk'] = $line['Sqk'];
1187
+			}
1188
+			// squawk
879 1189
 			$data['emergency'] = ''; // emergency
880
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
881
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
882
-			else $data['datetime'] = date('Y-m-d H:i:s');
1190
+			if (isset($line['Reg'])) {
1191
+				$data['registration'] = $line['Reg'];
1192
+			}
1193
+			if (isset($line['PosTime'])) {
1194
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1195
+			} else {
1196
+				$data['datetime'] = date('Y-m-d H:i:s');
1197
+			}
883 1198
 			//$data['datetime'] = date('Y-m-d H:i:s');
884
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1199
+			if (isset($line['Type'])) {
1200
+				$data['aircraft_icao'] = $line['Type'];
1201
+			}
885 1202
 			$data['format_source'] = 'aircraftlistjson';
886 1203
 			$data['id_source'] = $id_source;
887
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
888
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
889
-			if (isset($data['latitude'])) $SI->add($data);
1204
+			if (isset($value['name']) && $value['name'] != '') {
1205
+				$data['source_name'] = $value['name'];
1206
+			}
1207
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1208
+				$data['noarchive'] = true;
1209
+			}
1210
+			if (isset($data['latitude'])) {
1211
+				$SI->add($data);
1212
+			}
890 1213
 			unset($data);
891 1214
 		    }
892 1215
 		} elseif (is_array($all_data)) {
@@ -903,17 +1226,26 @@  discard block
 block discarded – undo
903 1226
 			$data['verticalrate'] = $line['vrt']; // verticale rate
904 1227
 			$data['squawk'] = $line['squawk']; // squawk
905 1228
 			$data['emergency'] = ''; // emergency
906
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
907
-			else $data['datetime'] = date('Y-m-d H:i:s');
1229
+			if (isset($line['PosTime'])) {
1230
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1231
+			} else {
1232
+				$data['datetime'] = date('Y-m-d H:i:s');
1233
+			}
908 1234
 			$data['format_source'] = 'aircraftlistjson';
909 1235
 			$data['id_source'] = $id_source;
910
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
911
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1236
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1237
+				$data['noarchive'] = true;
1238
+			}
1239
+			if (isset($value['name']) && $value['name'] != '') {
1240
+				$data['source_name'] = $value['name'];
1241
+			}
912 1242
 			$SI->add($data);
913 1243
 			unset($data);
914 1244
 		    }
915 1245
 		}
916
-	    } elseif ($globalDebug) echo 'No data'."\n";
1246
+	    } elseif ($globalDebug) {
1247
+	    	echo 'No data'."\n";
1248
+	    }
917 1249
     	    //$last_exec['aircraftlistjson'] = time();
918 1250
     	    $last_exec[$id]['last'] = time();
919 1251
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -949,8 +1281,12 @@  discard block
 block discarded – undo
949 1281
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
950 1282
 	    	    $data['format_source'] = 'planeupdatefaa';
951 1283
     		    $data['id_source'] = $id_source;
952
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
953
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1284
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1285
+		    	$data['noarchive'] = true;
1286
+		    }
1287
+		    if (isset($value['name']) && $value['name'] != '') {
1288
+		    	$data['source_name'] = $value['name'];
1289
+		    }
954 1290
 		    $SI->add($data);
955 1291
 		    unset($data);
956 1292
 		}
@@ -984,7 +1320,9 @@  discard block
 block discarded – undo
984 1320
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
985 1321
 		    $data['format_source'] = 'opensky';
986 1322
 		    $data['id_source'] = $id_source;
987
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1323
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1324
+		    	$data['noarchive'] = true;
1325
+		    }
988 1326
 		    $SI->add($data);
989 1327
 		    unset($data);
990 1328
 		}
@@ -1001,7 +1339,9 @@  discard block
 block discarded – undo
1001 1339
 	    //$buffer = $Common->getData($hosts[$id]);
1002 1340
 	    $buffer = $Common->getData($value['host']);
1003 1341
 	    $all_data = json_decode($buffer,true);
1004
-	    if (!empty($all_data)) $reset = 0;
1342
+	    if (!empty($all_data)) {
1343
+	    	$reset = 0;
1344
+	    }
1005 1345
 	    foreach ($all_data as $key => $line) {
1006 1346
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1007 1347
 		    $data = array();
@@ -1022,8 +1362,12 @@  discard block
 block discarded – undo
1022 1362
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1023 1363
 	    	    $data['format_source'] = 'fr24json';
1024 1364
     		    $data['id_source'] = $id_source;
1025
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1026
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1365
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1366
+		    	$data['noarchive'] = true;
1367
+		    }
1368
+		    if (isset($value['name']) && $value['name'] != '') {
1369
+		    	$data['source_name'] = $value['name'];
1370
+		    }
1027 1371
 		    $SI->add($data);
1028 1372
 		    unset($data);
1029 1373
 		}
@@ -1052,24 +1396,42 @@  discard block
 block discarded – undo
1052 1396
 		    if (isset($line['inf'])) {
1053 1397
 			$data = array();
1054 1398
 			$data['hex'] = $line['inf']['ia'];
1055
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1399
+			if (isset($line['inf']['cs'])) {
1400
+				$data['ident'] = $line['inf']['cs'];
1401
+			}
1402
+			//$line[13]
1056 1403
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1057
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1058
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1404
+	    		if (isset($line['inf']['gs'])) {
1405
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1406
+	    		}
1407
+	    		// speed
1408
+	    		if (isset($line['inf']['tr'])) {
1409
+	    			$data['heading'] = $line['inf']['tr'];
1410
+	    		}
1411
+	    		// heading
1059 1412
 	    		$data['latitude'] = $line['pt'][0]; // lat
1060 1413
 	    		$data['longitude'] = $line['pt'][1]; // long
1061 1414
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1062
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1415
+	    		if (isset($line['inf']['sq'])) {
1416
+	    			$data['squawk'] = $line['inf']['sq'];
1417
+	    		}
1418
+	    		// squawk
1063 1419
 	    		//$data['aircraft_icao'] = $line[8];
1064
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1420
+	    		if (isset($line['inf']['rc'])) {
1421
+	    			$data['registration'] = $line['inf']['rc'];
1422
+	    		}
1065 1423
 			//$data['departure_airport_iata'] = $line[11];
1066 1424
 			//$data['arrival_airport_iata'] = $line[12];
1067 1425
 	    		//$data['emergency'] = ''; // emergency
1068 1426
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1069 1427
 	    		$data['format_source'] = 'radarvirtueljson';
1070 1428
     			$data['id_source'] = $id_source;
1071
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1072
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1429
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1430
+				$data['noarchive'] = true;
1431
+			}
1432
+			if (isset($value['name']) && $value['name'] != '') {
1433
+				$data['source_name'] = $value['name'];
1434
+			}
1073 1435
 			$SI->add($data);
1074 1436
 			unset($data);
1075 1437
 		    }
@@ -1095,30 +1457,65 @@  discard block
 block discarded – undo
1095 1457
 		    $data['id'] = $line['id'];
1096 1458
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1097 1459
 		    $data['ident'] = $line['callsign']; // ident
1098
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1099
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1100
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1101
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1102
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1103
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1460
+		    if (isset($line['pilotid'])) {
1461
+		    	$data['pilot_id'] = $line['pilotid'];
1462
+		    }
1463
+		    // pilot id
1464
+		    if (isset($line['name'])) {
1465
+		    	$data['pilot_name'] = $line['name'];
1466
+		    }
1467
+		    // pilot name
1468
+		    if (isset($line['alt'])) {
1469
+		    	$data['altitude'] = $line['alt'];
1470
+		    }
1471
+		    // altitude
1472
+		    if (isset($line['gs'])) {
1473
+		    	$data['speed'] = $line['gs'];
1474
+		    }
1475
+		    // speed
1476
+		    if (isset($line['heading'])) {
1477
+		    	$data['heading'] = $line['heading'];
1478
+		    }
1479
+		    // heading
1480
+		    if (isset($line['route'])) {
1481
+		    	$data['waypoints'] = $line['route'];
1482
+		    }
1483
+		    // route
1104 1484
 		    $data['latitude'] = $line['lat']; // lat
1105 1485
 		    $data['longitude'] = $line['lon']; // long
1106 1486
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1107 1487
 		    //$data['squawk'] = $line['squawk']; // squawk
1108 1488
 		    //$data['emergency'] = ''; // emergency
1109
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1110
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1111
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1489
+		    if (isset($line['depicao'])) {
1490
+		    	$data['departure_airport_icao'] = $line['depicao'];
1491
+		    }
1492
+		    if (isset($line['deptime'])) {
1493
+		    	$data['departure_airport_time'] = $line['deptime'];
1494
+		    }
1495
+		    if (isset($line['arricao'])) {
1496
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1497
+		    }
1112 1498
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1113
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1114
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1115
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1116
-		    else $data['info'] = '';
1499
+		    if (isset($line['aircraft'])) {
1500
+		    	$data['aircraft_icao'] = $line['aircraft'];
1501
+		    }
1502
+		    if (isset($line['transponder'])) {
1503
+		    	$data['squawk'] = $line['transponder'];
1504
+		    }
1505
+		    if (isset($line['atis'])) {
1506
+		    	$data['info'] = $line['atis'];
1507
+		    } else {
1508
+		    	$data['info'] = '';
1509
+		    }
1117 1510
 		    $data['format_source'] = 'pireps';
1118 1511
     		    $data['id_source'] = $id_source;
1119 1512
 		    $data['datetime'] = date('Y-m-d H:i:s');
1120
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1121
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1513
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1514
+		    	$data['noarchive'] = true;
1515
+		    }
1516
+		    if (isset($value['name']) && $value['name'] != '') {
1517
+		    	$data['source_name'] = $value['name'];
1518
+		    }
1122 1519
 		    if ($line['icon'] == 'plane') {
1123 1520
 			$SI->add($data);
1124 1521
 		    //    print_r($data);
@@ -1127,16 +1524,28 @@  discard block
 block discarded – undo
1127 1524
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1128 1525
 			$typec = substr($data['ident'],-3);
1129 1526
 			$data['type'] = '';
1130
-			if ($typec == 'APP') $data['type'] = 'Approach';
1131
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1132
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1133
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1134
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1135
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1136
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1137
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1138
-			else $data['type'] = 'Observer';
1139
-			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']);
1527
+			if ($typec == 'APP') {
1528
+				$data['type'] = 'Approach';
1529
+			} elseif ($typec == 'TWR') {
1530
+				$data['type'] = 'Tower';
1531
+			} elseif ($typec == 'OBS') {
1532
+				$data['type'] = 'Observer';
1533
+			} elseif ($typec == 'GND') {
1534
+				$data['type'] = 'Ground';
1535
+			} elseif ($typec == 'DEL') {
1536
+				$data['type'] = 'Delivery';
1537
+			} elseif ($typec == 'DEP') {
1538
+				$data['type'] = 'Departure';
1539
+			} elseif ($typec == 'FSS') {
1540
+				$data['type'] = 'Flight Service Station';
1541
+			} elseif ($typec == 'CTR') {
1542
+				$data['type'] = 'Control Radar or Centre';
1543
+			} else {
1544
+				$data['type'] = 'Observer';
1545
+			}
1546
+			if (isset($ATC)) {
1547
+				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']);
1548
+			}
1140 1549
 		    }
1141 1550
 		    unset($data);
1142 1551
 		}
@@ -1151,7 +1560,9 @@  discard block
 block discarded – undo
1151 1560
 	    )
1152 1561
 	) {
1153 1562
 	    //$buffer = $Common->getData($hosts[$id]);
1154
-	    if ($globalDebug) echo 'Get Data...'."\n";
1563
+	    if ($globalDebug) {
1564
+	    	echo 'Get Data...'."\n";
1565
+	    }
1155 1566
 	    $buffer = $Common->getData($value['host']);
1156 1567
 	    $all_data = json_decode($buffer,true);
1157 1568
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1159,10 +1570,16 @@  discard block
 block discarded – undo
1159 1570
 		foreach ($all_data as $line) {
1160 1571
 	    	    $data = array();
1161 1572
 	    	    //$data['id'] = $line['id']; // id not usable
1162
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1573
+	    	    if (isset($line['pilotid'])) {
1574
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1575
+	    	    }
1163 1576
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1164
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1165
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1577
+	    	    if (isset($line['pilotname'])) {
1578
+	    	    	$data['pilot_name'] = $line['pilotname'];
1579
+	    	    }
1580
+	    	    if (isset($line['pilotid'])) {
1581
+	    	    	$data['pilot_id'] = $line['pilotid'];
1582
+	    	    }
1166 1583
 	    	    $data['ident'] = $line['flightnum']; // ident
1167 1584
 	    	    $data['altitude'] = $line['alt']; // altitude
1168 1585
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1178,34 +1595,52 @@  discard block
 block discarded – undo
1178 1595
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1179 1596
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1180 1597
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1181
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1598
+	    	    } else {
1599
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1600
+	    	    }
1182 1601
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1183 1602
 	    	    $data['departure_airport_time'] = $line['deptime'];
1184 1603
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
1185 1604
     		    $data['arrival_airport_time'] = $line['arrtime'];
1186 1605
     		    $data['registration'] = $line['aircraft'];
1187
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1188
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1606
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1607
+		    	$data['noarchive'] = true;
1608
+		    }
1609
+		    if (isset($line['route'])) {
1610
+		    	$data['waypoints'] = $line['route'];
1611
+		    }
1612
+		    // route
1189 1613
 		    if (isset($line['aircraftname'])) {
1190 1614
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1191 1615
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1192 1616
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1193
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1194
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1195
-	    		else {
1617
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1618
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1619
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1620
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1621
+	    		} else {
1196 1622
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1197
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1198
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1623
+	    		    if (isset($aircraft_data[1])) {
1624
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1625
+	    		    } else {
1626
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1627
+	    		    }
1199 1628
 	    		}
1200 1629
 	    	    }
1201
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1630
+    		    if (isset($line['route'])) {
1631
+    		    	$data['waypoints'] = $line['route'];
1632
+    		    }
1202 1633
     		    $data['id_source'] = $id_source;
1203 1634
 	    	    $data['format_source'] = 'phpvmacars';
1204
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1635
+		    if (isset($value['name']) && $value['name'] != '') {
1636
+		    	$data['source_name'] = $value['name'];
1637
+		    }
1205 1638
 		    $SI->add($data);
1206 1639
 		    unset($data);
1207 1640
 		}
1208
-		if ($globalDebug) echo 'No more data...'."\n";
1641
+		if ($globalDebug) {
1642
+			echo 'No more data...'."\n";
1643
+		}
1209 1644
 		unset($buffer);
1210 1645
 		unset($all_data);
1211 1646
 	    }
@@ -1218,7 +1653,9 @@  discard block
 block discarded – undo
1218 1653
 	    )
1219 1654
 	) {
1220 1655
 	    //$buffer = $Common->getData($hosts[$id]);
1221
-	    if ($globalDebug) echo 'Get Data...'."\n";
1656
+	    if ($globalDebug) {
1657
+	    	echo 'Get Data...'."\n";
1658
+	    }
1222 1659
 	    $buffer = $Common->getData($value['host']);
1223 1660
 	    $all_data = json_decode($buffer,true);
1224 1661
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1247,16 +1684,25 @@  discard block
 block discarded – undo
1247 1684
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1248 1685
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1249 1686
     		    //$data['registration'] = $line['aircraft'];
1250
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1687
+		    if (isset($line['route'])) {
1688
+		    	$data['waypoints'] = $line['route'];
1689
+		    }
1690
+		    // route
1251 1691
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1252 1692
     		    $data['id_source'] = $id_source;
1253 1693
 	    	    $data['format_source'] = 'vam';
1254
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1255
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1694
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1695
+		    	$data['noarchive'] = true;
1696
+		    }
1697
+		    if (isset($value['name']) && $value['name'] != '') {
1698
+		    	$data['source_name'] = $value['name'];
1699
+		    }
1256 1700
 		    $SI->add($data);
1257 1701
 		    unset($data);
1258 1702
 		}
1259
-		if ($globalDebug) echo 'No more data...'."\n";
1703
+		if ($globalDebug) {
1704
+			echo 'No more data...'."\n";
1705
+		}
1260 1706
 		unset($buffer);
1261 1707
 		unset($all_data);
1262 1708
 	    }
@@ -1269,7 +1715,9 @@  discard block
 block discarded – undo
1269 1715
 	    )
1270 1716
 	) {
1271 1717
 	    //$buffer = $Common->getData($hosts[$id]);
1272
-	    if ($globalDebug) echo 'Get Data...'."\n";
1718
+	    if ($globalDebug) {
1719
+	    	echo 'Get Data...'."\n";
1720
+	    }
1273 1721
 	    $buffer = $Common->getData($value['host']);
1274 1722
 	    $all_data = json_decode($buffer,true);
1275 1723
 	    if ($buffer != '') {
@@ -1287,18 +1735,24 @@  discard block
 block discarded – undo
1287 1735
 			$data['id_source'] = $id_source;
1288 1736
 			$data['format_source'] = 'blitzortung';
1289 1737
 			$SI->add($data);
1290
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1738
+			if ($globalDebug) {
1739
+				echo '☈ Lightning added'."\n";
1740
+			}
1291 1741
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1292 1742
 			unset($data);
1293 1743
 		    }
1294 1744
 		}
1295
-		if ($globalDebug) echo 'No more data...'."\n";
1745
+		if ($globalDebug) {
1746
+			echo 'No more data...'."\n";
1747
+		}
1296 1748
 		unset($buffer);
1297 1749
 	    }
1298 1750
 	    $last_exec[$id]['last'] = time();
1299 1751
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1300 1752
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1301
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1753
+	    if (function_exists('pcntl_fork')) {
1754
+	    	pcntl_signal_dispatch();
1755
+	    }
1302 1756
     	    //$last_exec[$id]['last'] = time();
1303 1757
 
1304 1758
 	    //$read = array( $sockets[$id] );
@@ -1306,7 +1760,9 @@  discard block
 block discarded – undo
1306 1760
 	    $write = NULL;
1307 1761
 	    $e = NULL;
1308 1762
 	    $n = socket_select($read, $write, $e, $timeout);
1309
-	    if ($e != NULL) var_dump($e);
1763
+	    if ($e != NULL) {
1764
+	    	var_dump($e);
1765
+	    }
1310 1766
 	    if ($n > 0) {
1311 1767
 		$reset = 0;
1312 1768
 		foreach ($read as $nb => $r) {
@@ -1327,12 +1783,16 @@  discard block
 block discarded – undo
1327 1783
 		    //$SI::del();
1328 1784
 		    if ($format == 'vrstcp') {
1329 1785
 			$buffer = explode('},{',$buffer);
1330
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1786
+		    } else {
1787
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1788
+		    }
1331 1789
 		    // SBS format is CSV format
1332 1790
 		    if ($buffer !== FALSE && $buffer != '') {
1333 1791
 			$tt[$format] = 0;
1334 1792
 			if ($format == 'acarssbs3') {
1335
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1793
+			    if ($globalDebug) {
1794
+			    	echo 'ACARS : '.$buffer."\n";
1795
+			    }
1336 1796
 			    $ACARS->add(trim($buffer));
1337 1797
 			    $ACARS->deleteLiveAcarsData();
1338 1798
 			} elseif ($format == 'raw') {
@@ -1341,30 +1801,70 @@  discard block
 block discarded – undo
1341 1801
 			    if (is_array($data)) {
1342 1802
 				$data['datetime'] = date('Y-m-d H:i:s');
1343 1803
 				$data['format_source'] = 'raw';
1344
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1345
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1346
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1347
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1804
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1805
+					$data['source_name'] = $globalSources[$nb]['name'];
1806
+				}
1807
+				if (isset($globalSources[$nb]['sourcestats'])) {
1808
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1809
+				}
1810
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1811
+					$data['noarchive'] = true;
1812
+				}
1813
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1814
+					$SI->add($data);
1815
+				}
1348 1816
 			    }
1349 1817
 			} elseif ($format == 'ais') {
1350 1818
 			    $ais_data = $AIS->parse_line(trim($buffer));
1351 1819
 			    $data = array();
1352
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1353
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1354
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1355
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1356
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1357
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1358
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1359
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1360
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1361
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1362
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1363
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1364
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1365
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1366
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1367
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1820
+			    if (isset($ais_data['ident'])) {
1821
+			    	$data['ident'] = $ais_data['ident'];
1822
+			    }
1823
+			    if (isset($ais_data['mmsi'])) {
1824
+			    	$data['mmsi'] = $ais_data['mmsi'];
1825
+			    }
1826
+			    if (isset($ais_data['speed'])) {
1827
+			    	$data['speed'] = $ais_data['speed'];
1828
+			    }
1829
+			    if (isset($ais_data['heading'])) {
1830
+			    	$data['heading'] = $ais_data['heading'];
1831
+			    }
1832
+			    if (isset($ais_data['latitude'])) {
1833
+			    	$data['latitude'] = $ais_data['latitude'];
1834
+			    }
1835
+			    if (isset($ais_data['longitude'])) {
1836
+			    	$data['longitude'] = $ais_data['longitude'];
1837
+			    }
1838
+			    if (isset($ais_data['status'])) {
1839
+			    	$data['status'] = $ais_data['status'];
1840
+			    }
1841
+			    if (isset($ais_data['statusid'])) {
1842
+			    	$data['status_id'] = $ais_data['statusid'];
1843
+			    }
1844
+			    if (isset($ais_data['type'])) {
1845
+			    	$data['type'] = $ais_data['type'];
1846
+			    }
1847
+			    if (isset($ais_data['imo'])) {
1848
+			    	$data['imo'] = $ais_data['imo'];
1849
+			    }
1850
+			    if (isset($ais_data['callsign'])) {
1851
+			    	$data['callsign'] = $ais_data['callsign'];
1852
+			    }
1853
+			    if (isset($ais_data['destination'])) {
1854
+			    	$data['arrival_code'] = $ais_data['destination'];
1855
+			    }
1856
+			    if (isset($ais_data['eta_ts'])) {
1857
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1858
+			    }
1859
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1860
+			    	$data['noarchive'] = true;
1861
+			    }
1862
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1863
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1864
+			    }
1865
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1866
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1867
+			    }
1368 1868
 
1369 1869
 			    if (isset($ais_data['timestamp'])) {
1370 1870
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1373,7 +1873,9 @@  discard block
 block discarded – undo
1373 1873
 			    }
1374 1874
 			    $data['format_source'] = 'aisnmea';
1375 1875
     			    $data['id_source'] = $id_source;
1376
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1876
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1877
+			    	$MI->add($data);
1878
+			    }
1377 1879
 			    unset($data);
1378 1880
                         } elseif ($format == 'flightgearsp') {
1379 1881
                     	    //echo $buffer."\n";
@@ -1391,12 +1893,18 @@  discard block
 block discarded – undo
1391 1893
 				$data['speed'] = round($line[5]*1.94384);
1392 1894
 				$data['datetime'] = date('Y-m-d H:i:s');
1393 1895
 				$data['format_source'] = 'flightgearsp';
1394
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1395
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1896
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1897
+					$data['noarchive'] = true;
1898
+				}
1899
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1900
+					$SI->add($data);
1901
+				}
1396 1902
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1397 1903
 			    }
1398 1904
                         } elseif ($format == 'acars') {
1399
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1905
+                    	    if ($globalDebug) {
1906
+                    	    	echo 'ACARS : '.$buffer."\n";
1907
+                    	    }
1400 1908
 			    $ACARS->add(trim($buffer));
1401 1909
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1402 1910
 			    $ACARS->deleteLiveAcarsData();
@@ -1417,8 +1925,12 @@  discard block
 block discarded – undo
1417 1925
 				    $aircraft_type = $line[10];
1418 1926
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1419 1927
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1420
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1421
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1928
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1929
+				    	$data['noarchive'] = true;
1930
+				    }
1931
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1932
+				    	$SI->add($data);
1933
+				    }
1422 1934
 				}
1423 1935
 			    }
1424 1936
 			} elseif ($format == 'beast') {
@@ -1428,28 +1940,62 @@  discard block
 block discarded – undo
1428 1940
 			    foreach($buffer as $all_data) {
1429 1941
 				$line = json_decode('{'.$all_data.'}',true);
1430 1942
 				$data = array();
1431
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1432
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1433
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1434
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1435
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1436
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1437
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1943
+				if (isset($line['Icao'])) {
1944
+					$data['hex'] = $line['Icao'];
1945
+				}
1946
+				// hex
1947
+				if (isset($line['Call'])) {
1948
+					$data['ident'] = $line['Call'];
1949
+				}
1950
+				// ident
1951
+				if (isset($line['Alt'])) {
1952
+					$data['altitude'] = $line['Alt'];
1953
+				}
1954
+				// altitude
1955
+				if (isset($line['Spd'])) {
1956
+					$data['speed'] = $line['Spd'];
1957
+				}
1958
+				// speed
1959
+				if (isset($line['Trak'])) {
1960
+					$data['heading'] = $line['Trak'];
1961
+				}
1962
+				// heading
1963
+				if (isset($line['Lat'])) {
1964
+					$data['latitude'] = $line['Lat'];
1965
+				}
1966
+				// lat
1967
+				if (isset($line['Long'])) {
1968
+					$data['longitude'] = $line['Long'];
1969
+				}
1970
+				// long
1438 1971
 				//$data['verticalrate'] = $line['']; // verticale rate
1439
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1972
+				if (isset($line['Sqk'])) {
1973
+					$data['squawk'] = $line['Sqk'];
1974
+				}
1975
+				// squawk
1440 1976
 				$data['emergency'] = ''; // emergency
1441
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1977
+				if (isset($line['Reg'])) {
1978
+					$data['registration'] = $line['Reg'];
1979
+				}
1442 1980
 				/*
1443 1981
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1444 1982
 				else $data['datetime'] = date('Y-m-d H:i:s');
1445 1983
 				*/
1446 1984
 				$data['datetime'] = date('Y-m-d H:i:s');
1447
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1985
+				if (isset($line['Type'])) {
1986
+					$data['aircraft_icao'] = $line['Type'];
1987
+				}
1448 1988
 		    		$data['format_source'] = 'vrstcp';
1449 1989
 				$data['id_source'] = $id_source;
1450
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1451
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1452
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1990
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1991
+					$data['noarchive'] = true;
1992
+				}
1993
+				if (isset($value['name']) && $value['name'] != '') {
1994
+					$data['source_name'] = $value['name'];
1995
+				}
1996
+				if (isset($data['latitude']) && isset($data['hex'])) {
1997
+					$SI->add($data);
1998
+				}
1453 1999
 				unset($data);
1454 2000
 			    }
1455 2001
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1462,22 +2008,46 @@  discard block
 block discarded – undo
1462 2008
     				$data['hex'] = $lined['hexid'];
1463 2009
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1464 2010
     				$data['datetime'] = date('Y-m-d H:i:s');;
1465
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1466
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1467
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1468
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1469
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1470
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1471
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2011
+    				if (isset($lined['ident'])) {
2012
+    					$data['ident'] = $lined['ident'];
2013
+    				}
2014
+    				if (isset($lined['lat'])) {
2015
+    					$data['latitude'] = $lined['lat'];
2016
+    				}
2017
+    				if (isset($lined['lon'])) {
2018
+    					$data['longitude'] = $lined['lon'];
2019
+    				}
2020
+    				if (isset($lined['speed'])) {
2021
+    					$data['speed'] = $lined['speed'];
2022
+    				}
2023
+    				if (isset($lined['squawk'])) {
2024
+    					$data['squawk'] = $lined['squawk'];
2025
+    				}
2026
+    				if (isset($lined['alt'])) {
2027
+    					$data['altitude'] = $lined['alt'];
2028
+    				}
2029
+    				if (isset($lined['heading'])) {
2030
+    					$data['heading'] = $lined['heading'];
2031
+    				}
1472 2032
     				$data['id_source'] = $id_source;
1473 2033
     				$data['format_source'] = 'tsv';
1474
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1475
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1476
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1477
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2034
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2035
+    					$data['source_name'] = $globalSources[$nb]['name'];
2036
+    				}
2037
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2038
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2039
+    				}
2040
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2041
+					$data['noarchive'] = true;
2042
+				}
2043
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2044
+    					$SI->add($data);
2045
+    				}
1478 2046
     				unset($lined);
1479 2047
     				unset($data);
1480
-    			    } else $error = true;
2048
+    			    } else {
2049
+    			    	$error = true;
2050
+    			    }
1481 2051
 			} elseif ($format == 'aprs' && $use_aprs) {
1482 2052
 			    if ($aprs_connect == 0) {
1483 2053
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1502,62 +2072,120 @@  discard block
 block discarded – undo
1502 2072
 				    $aprs_last_tx = time();
1503 2073
 				    $data = array();
1504 2074
 				    //print_r($line);
1505
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1506
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1507
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1508
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1509
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1510
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1511
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1512
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1513
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1514
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2075
+				    if (isset($line['address'])) {
2076
+				    	$data['hex'] = $line['address'];
2077
+				    }
2078
+				    if (isset($line['mmsi'])) {
2079
+				    	$data['mmsi'] = $line['mmsi'];
2080
+				    }
2081
+				    if (isset($line['imo'])) {
2082
+				    	$data['imo'] = $line['imo'];
2083
+				    }
2084
+				    if (isset($line['squawk'])) {
2085
+				    	$data['squawk'] = $line['squawk'];
2086
+				    }
2087
+				    if (isset($line['arrival_code'])) {
2088
+				    	$data['arrical_code'] = $line['arrival_code'];
2089
+				    }
2090
+				    if (isset($line['arrival_date'])) {
2091
+				    	$data['arrical_date'] = $line['arrival_date'];
2092
+				    }
2093
+				    if (isset($line['type_id'])) {
2094
+				    	$data['type_id'] = $line['typeid'];
2095
+				    }
2096
+				    if (isset($line['status_id'])) {
2097
+				    	$data['status_id'] = $line['statusid'];
2098
+				    }
2099
+				    if (isset($line['timestamp'])) {
2100
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2101
+				    } else {
2102
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2103
+				    }
1515 2104
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1516
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2105
+				    if (isset($line['ident'])) {
2106
+				    	$data['ident'] = $line['ident'];
2107
+				    }
1517 2108
 				    $data['latitude'] = $line['latitude'];
1518 2109
 				    $data['longitude'] = $line['longitude'];
1519 2110
 				    //$data['verticalrate'] = $line[16];
1520
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2111
+				    if (isset($line['speed'])) {
2112
+				    	$data['speed'] = $line['speed'];
2113
+				    }
1521 2114
 				    //else $data['speed'] = 0;
1522
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1523
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1524
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2115
+				    if (isset($line['altitude'])) {
2116
+				    	$data['altitude'] = $line['altitude'];
2117
+				    }
2118
+				    if (isset($line['comment'])) {
2119
+				    	$data['comment'] = $line['comment'];
2120
+				    }
2121
+				    if (isset($line['symbol'])) {
2122
+				    	$data['type'] = $line['symbol'];
2123
+				    }
1525 2124
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1526 2125
 				    
1527
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2126
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2127
+				    	$data['heading'] = $line['heading'];
2128
+				    }
1528 2129
 				    //else echo 'No heading...'."\n";
1529 2130
 				    //else $data['heading'] = 0;
1530
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2131
+				    if (isset($line['stealth'])) {
2132
+				    	$data['aircraft_type'] = $line['stealth'];
2133
+				    }
1531 2134
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1532
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1533
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1534
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1535
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2135
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2136
+				    	$data['noarchive'] = true;
2137
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2138
+				    	$data['noarchive'] = false;
2139
+				    }
2140
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2141
+				    	$data['noarchive'] = true;
2142
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2143
+				    	$data['noarchive'] = false;
2144
+				    }
1536 2145
     				    $data['id_source'] = $id_source;
1537
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1538
-				    else $data['format_source'] = 'aprs';
2146
+    				    if (isset($line['format_source'])) {
2147
+    				    	$data['format_source'] = $line['format_source'];
2148
+    				    } else {
2149
+				    	$data['format_source'] = 'aprs';
2150
+				    }
1539 2151
 				    $data['source_name'] = $line['source'];
1540
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1541
-				    else $data['source_type'] = 'flarm';
1542
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2152
+				    if (isset($line['source_type'])) {
2153
+				    	$data['source_type'] = $line['source_type'];
2154
+				    } else {
2155
+				    	$data['source_type'] = 'flarm';
2156
+				    }
2157
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2158
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2159
+    				    }
1543 2160
 				    $currentdate = date('Y-m-d H:i:s');
1544 2161
 				    $aprsdate = strtotime($data['datetime']);
1545
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2162
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2163
+				    	$data['altitude_relative'] = 'AMSL';
2164
+				    }
1546 2165
 				    // Accept data if time <= system time + 20s
1547 2166
 				    //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'])))) {
1548 2167
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1549 2168
 					$send = $SI->add($data);
1550 2169
 				    } elseif ($data['source_type'] == 'ais') {
1551
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2170
+					if (isset($globalMarine) && $globalMarine) {
2171
+						$send = $MI->add($data);
2172
+					}
1552 2173
 				    } elseif (isset($line['stealth'])) {
1553
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1554
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2174
+					if ($line['stealth'] != 0) {
2175
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2176
+					} else {
2177
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2178
+					}
1555 2179
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1556 2180
 					    //$line['symbol'] == 'Balloon' ||
1557 2181
 					    $line['symbol'] == 'Glider' || 
1558 2182
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1559
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1560
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2183
+					    if ($line['symbol'] == 'Ballon') {
2184
+					    	$data['aircraft_icao'] = 'BALL';
2185
+					    }
2186
+					    if ($line['symbol'] == 'Glider') {
2187
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2188
+					    }
1561 2189
 					    $send = $SI->add($data);
1562 2190
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1563 2191
 					    $line['symbol'] == 'Yacht (Sail)' || 
@@ -1588,9 +2216,13 @@  discard block
 block discarded – undo
1588 2216
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1589 2217
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1590 2218
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1591
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2219
+					if (isset($globalTracker) && $globalTracker) {
2220
+						$send = $TI->add($data);
2221
+					}
1592 2222
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1593
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2223
+					if (!isset($data['altitude'])) {
2224
+						$data['altitude'] = 0;
2225
+					}
1594 2226
 					$Source->deleteOldLocationByType('gs');
1595 2227
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1596 2228
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1599,7 +2231,9 @@  discard block
 block discarded – undo
1599 2231
 					}
1600 2232
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1601 2233
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1602
-					if ($globalDebug) echo '# Weather Station added'."\n";
2234
+					if ($globalDebug) {
2235
+						echo '# Weather Station added'."\n";
2236
+					}
1603 2237
 					$Source->deleteOldLocationByType('wx');
1604 2238
 					$weather_data = json_encode($line);
1605 2239
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1609,7 +2243,9 @@  discard block
 block discarded – undo
1609 2243
 					}
1610 2244
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1611 2245
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1612
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2246
+					if ($globalDebug) {
2247
+						echo '☈ Lightning added'."\n";
2248
+					}
1613 2249
 					$Source->deleteOldLocationByType('lightning');
1614 2250
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1615 2251
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1621,8 +2257,7 @@  discard block
 block discarded – undo
1621 2257
 				    	print_r($line);
1622 2258
 				    }
1623 2259
 				    unset($data);
1624
-				}
1625
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2260
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1626 2261
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1627 2262
 				}
1628 2263
 				/*
@@ -1631,7 +2266,9 @@  discard block
 block discarded – undo
1631 2266
 				}
1632 2267
 				*/
1633 2268
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1634
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2269
+				elseif ($line == true && $globalDebug) {
2270
+					echo '!! Failed : '.$buffer."!!\n";
2271
+				}
1635 2272
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1636 2273
 					$Source->deleteOldLocationByType('lightning');
1637 2274
 					$Source->deleteOldLocationByType('wx');
@@ -1667,26 +2304,45 @@  discard block
 block discarded – undo
1667 2304
     				$data['ground'] = $line[21];
1668 2305
     				$data['emergency'] = $line[19];
1669 2306
     				$data['format_source'] = 'sbs';
1670
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1671
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1672
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2307
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2308
+					$data['source_name'] = $globalSources[$nb]['name'];
2309
+				}
2310
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2311
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2312
+    				}
2313
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2314
+					$data['noarchive'] = true;
2315
+				}
1673 2316
     				$data['id_source'] = $id_source;
1674
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1675
-    				else $error = true;
2317
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2318
+    					$send = $SI->add($data);
2319
+    				} else {
2320
+    					$error = true;
2321
+    				}
1676 2322
     				unset($data);
1677
-    			    } else $error = true;
2323
+    			    } else {
2324
+    			    	$error = true;
2325
+    			    }
1678 2326
 			    if ($error) {
1679 2327
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1680
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2328
+					if ($globalDebug) {
2329
+						echo "Not a message. Ignoring... \n";
2330
+					}
1681 2331
 				} else {
1682
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2332
+					if ($globalDebug) {
2333
+						echo "Wrong line format. Ignoring... \n";
2334
+					}
1683 2335
 					if ($globalDebug) {
1684 2336
 						echo $buffer;
1685 2337
 						//print_r($line);
1686 2338
 					}
1687 2339
 					//socket_close($r);
1688
-					if ($globalDebug) echo "Reconnect after an error...\n";
1689
-					if ($format == 'aprs') $aprs_connect = 0;
2340
+					if ($globalDebug) {
2341
+						echo "Reconnect after an error...\n";
2342
+					}
2343
+					if ($format == 'aprs') {
2344
+						$aprs_connect = 0;
2345
+					}
1690 2346
 					$sourceer[$nb] = $globalSources[$nb];
1691 2347
 					connect_all($sourceer);
1692 2348
 					$sourceer = array();
@@ -1694,10 +2350,14 @@  discard block
 block discarded – undo
1694 2350
 			    }
1695 2351
 			}
1696 2352
 			// Sleep for xxx microseconds
1697
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2353
+			if (isset($globalSBSSleep)) {
2354
+				usleep($globalSBSSleep);
2355
+			}
1698 2356
 		    } else {
1699 2357
 			if ($format == 'flightgearmp') {
1700
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2358
+			    	if ($globalDebug) {
2359
+			    		echo "Reconnect FlightGear MP...";
2360
+			    	}
1701 2361
 				//@socket_close($r);
1702 2362
 				sleep($globalMinFetch);
1703 2363
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1706,10 +2366,15 @@  discard block
 block discarded – undo
1706 2366
 				break;
1707 2367
 				
1708 2368
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1709
-			    if (isset($tt[$format])) $tt[$format]++;
1710
-			    else $tt[$format] = 0;
2369
+			    if (isset($tt[$format])) {
2370
+			    	$tt[$format]++;
2371
+			    } else {
2372
+			    	$tt[$format] = 0;
2373
+			    }
1711 2374
 			    if ($tt[$format] > 30) {
1712
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2375
+				if ($globalDebug) {
2376
+					echo "ERROR : Reconnect ".$format."...";
2377
+				}
1713 2378
 				//@socket_close($r);
1714 2379
 				sleep(2);
1715 2380
 				$aprs_connect = 0;
@@ -1726,11 +2391,17 @@  discard block
 block discarded – undo
1726 2391
 	    } else {
1727 2392
 		$error = socket_strerror(socket_last_error());
1728 2393
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1729
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1730
-			if (isset($globalDebug)) echo "Restarting...\n";
2394
+			if ($globalDebug) {
2395
+				echo "ERROR : socket_select give this error ".$error . "\n";
2396
+			}
2397
+			if (isset($globalDebug)) {
2398
+				echo "Restarting...\n";
2399
+			}
1731 2400
 			// Restart the script if possible
1732 2401
 			if (is_array($sockets)) {
1733
-			    if ($globalDebug) echo "Shutdown all sockets...";
2402
+			    if ($globalDebug) {
2403
+			    	echo "Shutdown all sockets...";
2404
+			    }
1734 2405
 			    
1735 2406
 			    foreach ($sockets as $sock) {
1736 2407
 				@socket_shutdown($sock,2);
@@ -1738,25 +2409,45 @@  discard block
 block discarded – undo
1738 2409
 			    }
1739 2410
 			    
1740 2411
 			}
1741
-			if ($globalDebug) echo "Waiting...";
2412
+			if ($globalDebug) {
2413
+				echo "Waiting...";
2414
+			}
1742 2415
 			sleep(2);
1743 2416
 			$time = time();
1744 2417
 			//connect_all($hosts);
1745 2418
 			$aprs_connect = 0;
1746
-			if ($reset%5 == 0) sleep(20);
1747
-			if ($reset%10 == 0) sleep(100);
1748
-			if ($reset%20 == 0) sleep(200);
1749
-			if ($reset > 100) exit('Too many attempts...');
1750
-			if ($globalDebug) echo "Restart all connections...";
2419
+			if ($reset%5 == 0) {
2420
+				sleep(20);
2421
+			}
2422
+			if ($reset%10 == 0) {
2423
+				sleep(100);
2424
+			}
2425
+			if ($reset%20 == 0) {
2426
+				sleep(200);
2427
+			}
2428
+			if ($reset > 100) {
2429
+				exit('Too many attempts...');
2430
+			}
2431
+			if ($globalDebug) {
2432
+				echo "Restart all connections...";
2433
+			}
1751 2434
 			connect_all($globalSources);
1752 2435
 		}
1753 2436
 	    }
1754 2437
 	}
1755 2438
 	if ($globalDaemon === false) {
1756
-	    if ($globalDebug) echo 'Check all...'."\n";
1757
-	    if (isset($SI)) $SI->checkAll();
1758
-	    if (isset($TI)) $TI->checkAll();
1759
-	    if (isset($MI)) $MI->checkAll();
2439
+	    if ($globalDebug) {
2440
+	    	echo 'Check all...'."\n";
2441
+	    }
2442
+	    if (isset($SI)) {
2443
+	    	$SI->checkAll();
2444
+	    }
2445
+	    if (isset($TI)) {
2446
+	    	$TI->checkAll();
2447
+	    }
2448
+	    if (isset($MI)) {
2449
+	    	$MI->checkAll();
2450
+	    }
1760 2451
 	}
1761 2452
     }
1762 2453
 }
Please login to merge, or discard this patch.
Spacing   +183 added lines, -183 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,30 +150,30 @@  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('/opensky/i',$host)) {
176
+    	    } else if (preg_match('/opensky/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftlistjson';
178 178
         	$globalSources[$id]['format'] = 'opensky';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         	    exit(0);
191 191
         	}
192 192
     	    */
193
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
193
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
194 194
         	//$formats[$id] = 'planeupdatefaa';
195 195
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 196
         	//$last_exec['planeupdatefaa'] = 0;
@@ -199,32 +199,32 @@  discard block
 block discarded – undo
199 199
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 200
         	    exit(0);
201 201
         	}
202
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
202
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
203 203
         	//$formats[$id] = 'phpvmacars';
204 204
         	$globalSources[$id]['format'] = 'phpvmacars';
205 205
         	//$last_exec['phpvmacars'] = 0;
206 206
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
207
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
208 208
         	//$formats[$id] = 'phpvmacars';
209 209
         	$globalSources[$id]['format'] = 'vam';
210 210
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
211
-            } else if (preg_match('/whazzup/i',$host)) {
211
+            } else if (preg_match('/whazzup/i', $host)) {
212 212
         	//$formats[$id] = 'whazzup';
213 213
         	$globalSources[$id]['format'] = 'whazzup';
214 214
         	//$last_exec['whazzup'] = 0;
215 215
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
216
-            } else if (preg_match('/blitzortung/i',$host)) {
216
+            } else if (preg_match('/blitzortung/i', $host)) {
217 217
         	$globalSources[$id]['format'] = 'blitzortung';
218 218
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
219
-            } else if (preg_match('/airwhere/i',$host)) {
219
+            } else if (preg_match('/airwhere/i', $host)) {
220 220
         	$globalSources[$id]['format'] = 'airwhere';
221 221
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
222
-            } else if (preg_match('/recentpireps/i',$host)) {
222
+            } else if (preg_match('/recentpireps/i', $host)) {
223 223
         	//$formats[$id] = 'pirepsjson';
224 224
         	$globalSources[$id]['format'] = 'pirepsjson';
225 225
         	//$last_exec['pirepsjson'] = 0;
226 226
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
227
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
227
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
228 228
         	//$formats[$id] = 'fr24json';
229 229
         	$globalSources[$id]['format'] = 'fr24json';
230 230
         	//$last_exec['fr24json'] = 0;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
234 234
         	    exit(0);
235 235
         	}
236
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
236
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
237 237
         	//$formats[$id] = 'fr24json';
238 238
         	$globalSources[$id]['format'] = 'myshiptracking';
239 239
         	//$last_exec['fr24json'] = 0;
@@ -243,22 +243,22 @@  discard block
 block discarded – undo
243 243
         	    exit(0);
244 244
         	}
245 245
             //} else if (preg_match('/10001/',$host)) {
246
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
246
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
247 247
         	//$formats[$id] = 'tsv';
248 248
         	$globalSources[$id]['format'] = 'tsv';
249 249
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
250 250
             }
251
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
251
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
252 252
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
253
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
253
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
254 254
     		    if ($idf !== false) {
255 255
     			$httpfeeds[$id] = $idf;
256 256
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
257 257
     		    }
258 258
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
259 259
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
260
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
261
-	    $hostport = explode(':',$host);
260
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
261
+	    $hostport = explode(':', $host);
262 262
 	    if (isset($hostport[1])) {
263 263
 		$port = $hostport[1];
264 264
 		$hostn = $hostport[0];
@@ -268,19 +268,19 @@  discard block
 block discarded – undo
268 268
 	    }
269 269
 	    $Common = new Common();
270 270
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
271
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
271
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
272 272
     	    } else {
273
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
273
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
274 274
 	    }
275 275
 	    if ($s) {
276 276
     	        $sockets[$id] = $s;
277 277
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
278
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
278
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
279 279
 			//$formats[$id] = 'aprs';
280 280
 			$globalSources[$id]['format'] = 'aprs';
281 281
 			//$aprs_connect = 0;
282 282
 			//$use_aprs = true;
283
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
283
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
284 284
 			$globalSources[$id]['format'] = 'vrstcp';
285 285
     		    } elseif ($port == '10001') {
286 286
         		//$formats[$id] = 'tsv';
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
320 320
 else $timeout = 20;
321 321
 $errno = '';
322
-$errstr='';
322
+$errstr = '';
323 323
 
324 324
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
325 325
 /* Initiate connections to all the hosts simultaneously */
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 //connect_all($globalSources);
328 328
 
329 329
 if (isset($globalProxy) && $globalProxy) {
330
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
330
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
331 331
 } else {
332 332
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
333 333
 }
@@ -357,16 +357,16 @@  discard block
 block discarded – undo
357 357
 
358 358
 if ($use_aprs) {
359 359
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
360
-	$APRS=new APRS();
360
+	$APRS = new APRS();
361 361
 	$aprs_connect = 0;
362 362
 	$aprs_keep = 120;
363 363
 	$aprs_last_tx = time();
364 364
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
365
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
365
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
366 366
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
367
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
367
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
368 368
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
369
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
369
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
370 370
 	if ($aprs_full) $aprs_filter = '';
371 371
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
372 372
 	else $aprs_pass = '-1';
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 sleep(1);
381 381
 if ($globalDebug) echo "SCAN MODE \n\n";
382 382
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
383
-$endtime = time()+$globalCronEnd;
383
+$endtime = time() + $globalCronEnd;
384 384
 $i = 1;
385 385
 $tt = array();
386 386
 // Delete all ATC
387 387
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
388
-	$ATC=new ATC($Connection->db);
388
+	$ATC = new ATC($Connection->db);
389 389
 }
390 390
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
391 391
 	$ATC->deleteAll();
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 
394 394
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
395 395
 while ($i > 0) {
396
-    if (!$globalDaemon) $i = $endtime-time();
396
+    if (!$globalDaemon) $i = $endtime - time();
397 397
     // Delete old ATC
398 398
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
399 399
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	}
408 408
 	if ($max != $globalMinFetch) {
409 409
 	    if ($globalDebug) echo 'Sleeping...'."\n";
410
-	    sleep($globalMinFetch-$max+2);
410
+	    sleep($globalMinFetch - $max + 2);
411 411
 	}
412 412
     }
413 413
 
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
 	    //$buffer = $Common->getData($hosts[$id]);
427 427
 	    $buffer = $Common->getData($value['host']);
428 428
 	    if ($buffer != '') $reset = 0;
429
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
430
-	    $buffer = explode('\n',$buffer);
429
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
430
+	    $buffer = explode('\n', $buffer);
431 431
 	    foreach ($buffer as $line) {
432 432
     		if ($line != '' && count($line) > 7) {
433 433
     		    $line = explode(',', $line);
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
 	    )
461 461
 	) {
462 462
 	    date_default_timezone_set('CET');
463
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
463
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
464 464
 	    date_default_timezone_set('UTC');
465 465
 	    if ($buffer != '') $reset = 0;
466
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
467
-	    $buffer = explode('\n',$buffer);
466
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
467
+	    $buffer = explode('\n', $buffer);
468 468
 	    foreach ($buffer as $line) {
469 469
 		if ($line != '') {
470 470
 		    //echo "'".$line."'\n";
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
483 483
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
484 484
 		    if (isset($ais_data['timestamp'])) {
485
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
485
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
486 486
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
487 487
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
488 488
 			    $add = true;
@@ -505,12 +505,12 @@  discard block
 block discarded – undo
505 505
 	    $w = $e = null;
506 506
 	    
507 507
 	    if (isset($arr[$id])) {
508
-		$nn = stream_select($arr,$w,$e,$timeout);
508
+		$nn = stream_select($arr, $w, $e, $timeout);
509 509
 		if ($nn > 0) {
510 510
 		    foreach ($httpfeeds as $feed) {
511
-			$buffer = stream_get_line($feed,2000,"\n");
512
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
513
-			$buffer = explode('\n',$buffer);
511
+			$buffer = stream_get_line($feed, 2000, "\n");
512
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
513
+			$buffer = explode('\n', $buffer);
514 514
 			foreach ($buffer as $line) {
515 515
 			    if ($line != '') {
516 516
 				$ais_data = $AIS->parse_line(trim($line));
@@ -528,9 +528,9 @@  discard block
 block discarded – undo
528 528
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
529 529
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
530 530
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
531
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
531
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
532 532
 				if (isset($ais_data['timestamp'])) {
533
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
533
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
534 534
 				} else {
535 535
 				    $data['datetime'] = date('Y-m-d H:i:s');
536 536
 				}
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
562 562
 	    )
563 563
 	) {
564
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
564
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
565 565
 	    if ($buffer != '') {
566 566
 		//echo $buffer;
567
-		$all_data = json_decode($buffer,true);
567
+		$all_data = json_decode($buffer, true);
568 568
 		//print_r($all_data);
569 569
 		if (isset($all_data[0]['DATA'])) {
570 570
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 			    $data['ident'] = $line['NAME'];
574 574
 			    $data['mmsi'] = $line['MMSI'];
575 575
 			    if (strlen($data['mmsi']) > 9) {
576
-				$data['mmsi'] = substr($data['mmsi'],-9);
576
+				$data['mmsi'] = substr($data['mmsi'], -9);
577 577
 			    }
578 578
 			    $data['speed'] = $line['SOG'];
579 579
 			    $data['heading'] = $line['COG'];
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
583 583
 			    $data['imo'] = $line['IMO'];
584 584
 			    //$data['arrival_code'] = $ais_data['destination'];
585
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
585
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
586 586
 			    $data['format_source'] = 'myshiptracking';
587 587
 			    $data['id_source'] = $id_source;
588 588
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -599,9 +599,9 @@  discard block
 block discarded – undo
599 599
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
600 600
 	    )
601 601
 	) {
602
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
602
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
603 603
 	    if ($buffer != '') {
604
-		$all_data = json_decode($buffer,true);
604
+		$all_data = json_decode($buffer, true);
605 605
 		if (isset($all_data[0]['mmsi'])) {
606 606
 		    foreach ($all_data as $line) {
607 607
 			if ($line != '') {
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 	) {
636 636
 	    $buffer = $Common->getData($value['host']);
637 637
 	    if ($buffer != '') {
638
-		$all_data = json_decode($buffer,true);
638
+		$all_data = json_decode($buffer, true);
639 639
 		if (isset($all_data['features'][0]['id'])) {
640 640
 		    foreach ($all_data['features'] as $line) {
641 641
 			$data = array();
@@ -668,27 +668,27 @@  discard block
 block discarded – undo
668 668
 	    )
669 669
 	) {
670 670
 	    echo 'download...';
671
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
671
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
672 672
 	    echo 'done !'."\n";
673 673
 	    if ($buffer != '') $reset = 0;
674
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
675
-	    $buffer = explode('\n',$buffer);
674
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
675
+	    $buffer = explode('\n', $buffer);
676 676
 	    foreach ($buffer as $line) {
677 677
 		if ($line != '') {
678 678
 		    $data = array();
679
-		    $data['mmsi'] = (int)substr($line,0,9);
680
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
679
+		    $data['mmsi'] = (int) substr($line, 0, 9);
680
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
681 681
 		    //$data['status'] = substr($line,21,2);
682 682
 		    //$data['type'] = substr($line,24,3);
683
-		    $data['latitude'] = substr($line,29,9);
684
-		    $data['longitude'] = substr($line,41,9);
685
-		    $data['speed'] = round(substr($line,51,5));
683
+		    $data['latitude'] = substr($line, 29, 9);
684
+		    $data['longitude'] = substr($line, 41, 9);
685
+		    $data['speed'] = round(substr($line, 51, 5));
686 686
 		    //$data['course'] = substr($line,57,5);
687
-		    $data['heading'] = round(substr($line,63,3));
687
+		    $data['heading'] = round(substr($line, 63, 3));
688 688
 		    //$data['draft'] = substr($line,67,4);
689 689
 		    //$data['length'] = substr($line,72,3);
690 690
 		    //$data['beam'] = substr($line,76,2);
691
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
691
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
692 692
 		    //$data['callsign'] = trim(substr($line,100,7);
693 693
 		    //$data['dest'] = substr($line,108,20);
694 694
 		    //$data['etaDate'] = substr($line,129,5);
@@ -721,8 +721,8 @@  discard block
 block discarded – undo
721 721
 	) {
722 722
 	    //$buffer = $Common->getData($hosts[$id]);
723 723
 	    $buffer = $Common->getData($value['host']);
724
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
725
-	    $buffer = explode('\n',$buffer);
724
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
725
+	    $buffer = explode('\n', $buffer);
726 726
 	    $reset = 0;
727 727
 	    foreach ($buffer as $line) {
728 728
     		if ($line != '') {
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
734 734
 			$data['pilot_id'] = $line[1];
735 735
 			$data['pilot_name'] = $line[2];
736
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
736
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
737 737
 			$data['ident'] = $line[0]; // ident
738 738
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
739 739
 			$data['speed'] = $line[8]; // speed
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
750 750
 			//if (isset($line[37])) $data['last_update'] = $line[37];
751 751
 		        $data['departure_airport_icao'] = $line[11];
752
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
752
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
753 753
 		        $data['arrival_airport_icao'] = $line[13];
754 754
 			$data['frequency'] = $line[4];
755 755
 			$data['type'] = $line[18];
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
     			$data['id_source'] = $id_source;
759 759
 	    		//$data['arrival_airport_time'] = ;
760 760
 	    		if ($line[9] != '') {
761
-	    		    $aircraft_data = explode('/',$line[9]);
761
+	    		    $aircraft_data = explode('/', $line[9]);
762 762
 	    		    if (isset($aircraft_data[1])) {
763 763
 	    			$data['aircraft_icao'] = $aircraft_data[1];
764 764
 	    		    }
@@ -773,9 +773,9 @@  discard block
 block discarded – undo
773 773
     			if ($line[3] == 'PILOT') $SI->add($data);
774 774
 			elseif ($line[3] == 'ATC') {
775 775
 				//print_r($data);
776
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
777
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
778
-				$typec = substr($data['ident'],-3);
776
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
777
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
778
+				$typec = substr($data['ident'], -3);
779 779
 				if ($typec == 'APP') $data['type'] = 'Approach';
780 780
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
781 781
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
788 788
 				if (!isset($data['source_name'])) $data['source_name'] = '';
789 789
 				if (isset($ATC)) {
790
-					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']);
791
-					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']);
790
+					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']);
791
+					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']);
792 792
 				}
793 793
 			}
794 794
     			unset($data);
@@ -804,24 +804,24 @@  discard block
 block discarded – undo
804 804
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
805 805
     	    )
806 806
     	) {
807
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
807
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
808 808
 	    if ($buffer != '') {
809 809
 		$all_data = simplexml_load_string($buffer);
810
-		foreach($all_data->children() as $childdata) {
810
+		foreach ($all_data->children() as $childdata) {
811 811
 			$data = array();
812 812
 			$line = $childdata;
813 813
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
814
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
815
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
816
-			$data['latitude'] = (float)$line['pktLatitude'];
817
-			$data['longitude'] = (float)$line['pktLongitude'];
818
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
819
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
820
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
814
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
815
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
816
+			$data['latitude'] = (float) $line['pktLatitude'];
817
+			$data['longitude'] = (float) $line['pktLongitude'];
818
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
819
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
820
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
821 821
 			$data['altitude_relative'] = 'AMSL';
822
-			$data['pilot_id'] = (int)$line['pktPilotID'];
822
+			$data['pilot_id'] = (int) $line['pktPilotID'];
823 823
 			$data['aircraft_icao'] = 'PARAGLIDER';
824
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
824
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
825 825
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
826 826
 			$data['format_source'] = $value['format'];
827 827
 			$SI->add($data);
@@ -829,22 +829,22 @@  discard block
 block discarded – undo
829 829
 		}
830 830
 	    }
831 831
 	    $Source->deleteOldLocationByType('gs');
832
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
832
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
833 833
 	    if ($buffer != '') {
834 834
 		$all_data = simplexml_load_string($buffer);
835
-		foreach($all_data->children() as $childdata) {
835
+		foreach ($all_data->children() as $childdata) {
836 836
 			$data = array();
837 837
 			$line = $childdata;
838
-			$data['id'] = (int)$line['gsID'];
839
-			$data['latitude'] = (float)$line['gsLatitude'];
840
-			$data['longitude'] = (float)$line['gsLongitude'];
841
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
838
+			$data['id'] = (int) $line['gsID'];
839
+			$data['latitude'] = (float) $line['gsLatitude'];
840
+			$data['longitude'] = (float) $line['gsLongitude'];
841
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
842 842
 			$data['altitude_relative'] = 'AMSL';
843
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
843
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
844 844
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
845
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
845
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
846 846
 			} else {
847
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
847
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
848 848
 			}
849 849
 			unset($data);
850 850
 		}
@@ -862,9 +862,9 @@  discard block
 block discarded – undo
862 862
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
863 863
 	    )
864 864
 	) {
865
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
865
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
866 866
 	    if ($buffer != '') {
867
-	        $all_data = json_decode($buffer,true);
867
+	        $all_data = json_decode($buffer, true);
868 868
 		if (isset($all_data['acList'])) {
869 869
 		    $reset = 0;
870 870
 		    foreach ($all_data['acList'] as $line) {
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
881 881
 			$data['emergency'] = ''; // emergency
882 882
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
883
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
883
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
884 884
 			else $data['datetime'] = date('Y-m-d H:i:s');
885 885
 			//$data['datetime'] = date('Y-m-d H:i:s');
886 886
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
 			$data['verticalrate'] = $line['vrt']; // verticale rate
906 906
 			$data['squawk'] = $line['squawk']; // squawk
907 907
 			$data['emergency'] = ''; // emergency
908
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
908
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
909 909
 			else $data['datetime'] = date('Y-m-d H:i:s');
910 910
 			$data['format_source'] = 'aircraftlistjson';
911 911
 			$data['id_source'] = $id_source;
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
     	    )
927 927
     	) {
928 928
 	    $buffer = $Common->getData($value['host']);
929
-	    $all_data = json_decode($buffer,true);
929
+	    $all_data = json_decode($buffer, true);
930 930
 	    if (isset($all_data['planes'])) {
931 931
 		$reset = 0;
932 932
 		foreach ($all_data['planes'] as $key => $line) {
@@ -943,12 +943,12 @@  discard block
 block discarded – undo
943 943
 		    $data['emergency'] = ''; // emergency
944 944
 		    $data['registration'] = $line[2];
945 945
 		    $data['aircraft_icao'] = $line[0];
946
-		    $deparr = explode('-',$line[1]);
946
+		    $deparr = explode('-', $line[1]);
947 947
 		    if (count($deparr) == 2) {
948 948
 			$data['departure_airport_icao'] = $deparr[0];
949 949
 			$data['arrival_airport_icao'] = $deparr[1];
950 950
 		    }
951
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
951
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
952 952
 	    	    $data['format_source'] = 'planeupdatefaa';
953 953
     		    $data['id_source'] = $id_source;
954 954
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
 	    )
967 967
 	) {
968 968
 	    $buffer = $Common->getData($value['host']);
969
-	    $all_data = json_decode($buffer,true);
969
+	    $all_data = json_decode($buffer, true);
970 970
 	    if (isset($all_data['states'])) {
971 971
 		$reset = 0;
972 972
 		foreach ($all_data['states'] as $key => $line) {
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 		    //$data['emergency'] = ''; // emergency
984 984
 		    //$data['registration'] = $line[2];
985 985
 		    //$data['aircraft_icao'] = $line[0];
986
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
986
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
987 987
 		    $data['format_source'] = 'opensky';
988 988
 		    $data['id_source'] = $id_source;
989 989
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
 	) {
1003 1003
 	    //$buffer = $Common->getData($hosts[$id]);
1004 1004
 	    $buffer = $Common->getData($value['host']);
1005
-	    $all_data = json_decode($buffer,true);
1005
+	    $all_data = json_decode($buffer, true);
1006 1006
 	    if (!empty($all_data)) $reset = 0;
1007 1007
 	    foreach ($all_data as $key => $line) {
1008 1008
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1040,11 +1040,11 @@  discard block
 block discarded – undo
1040 1040
 	    )
1041 1041
 	) {
1042 1042
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1043
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1043
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1044 1044
 	    //echo $buffer;
1045
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1046
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1047
-	    $all_data = json_decode($buffer,true);
1045
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1046
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1047
+	    $all_data = json_decode($buffer, true);
1048 1048
 	    if (json_last_error() != JSON_ERROR_NONE) {
1049 1049
 		die(json_last_error_msg());
1050 1050
 	    }
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
 			//$data['departure_airport_iata'] = $line[11];
1068 1068
 			//$data['arrival_airport_iata'] = $line[12];
1069 1069
 	    		//$data['emergency'] = ''; // emergency
1070
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1070
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1071 1071
 	    		$data['format_source'] = 'radarvirtueljson';
1072 1072
     			$data['id_source'] = $id_source;
1073 1073
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1088,14 +1088,14 @@  discard block
 block discarded – undo
1088 1088
 	) {
1089 1089
 	    //$buffer = $Common->getData($hosts[$id]);
1090 1090
 	    $buffer = $Common->getData($value['host'].'?'.time());
1091
-	    $all_data = json_decode(utf8_encode($buffer),true);
1091
+	    $all_data = json_decode(utf8_encode($buffer), true);
1092 1092
 	    
1093 1093
 	    if (isset($all_data['pireps'])) {
1094 1094
 		$reset = 0;
1095 1095
 	        foreach ($all_data['pireps'] as $line) {
1096 1096
 		    $data = array();
1097 1097
 		    $data['id'] = $line['id'];
1098
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1098
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1099 1099
 		    $data['ident'] = $line['callsign']; // ident
1100 1100
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1101 1101
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1125,9 +1125,9 @@  discard block
 block discarded – undo
1125 1125
 			$SI->add($data);
1126 1126
 		    //    print_r($data);
1127 1127
     		    } elseif ($line['icon'] == 'ct') {
1128
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1129
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1130
-			$typec = substr($data['ident'],-3);
1128
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1129
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1130
+			$typec = substr($data['ident'], -3);
1131 1131
 			$data['type'] = '';
1132 1132
 			if ($typec == 'APP') $data['type'] = 'Approach';
1133 1133
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1139 1139
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1140 1140
 			else $data['type'] = 'Observer';
1141
-			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']);
1141
+			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']);
1142 1142
 		    }
1143 1143
 		    unset($data);
1144 1144
 		}
@@ -1155,14 +1155,14 @@  discard block
 block discarded – undo
1155 1155
 	    //$buffer = $Common->getData($hosts[$id]);
1156 1156
 	    if ($globalDebug) echo 'Get Data...'."\n";
1157 1157
 	    $buffer = $Common->getData($value['host']);
1158
-	    $all_data = json_decode($buffer,true);
1158
+	    $all_data = json_decode($buffer, true);
1159 1159
 	    if ($buffer != '' && is_array($all_data)) {
1160 1160
 		$reset = 0;
1161 1161
 		foreach ($all_data as $line) {
1162 1162
 	    	    $data = array();
1163 1163
 	    	    //$data['id'] = $line['id']; // id not usable
1164 1164
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1165
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1165
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1166 1166
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1167 1167
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1168 1168
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 	    	    //$data['datetime'] = $line['lastupdate'];
1178 1178
 	    	    //$data['last_update'] = $line['lastupdate'];
1179 1179
 	    	    if (isset($value['timezone'])) {
1180
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1180
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1181 1181
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1182 1182
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1183 1183
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1190,14 +1190,14 @@  discard block
 block discarded – undo
1190 1190
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1191 1191
 		    if (isset($line['aircraftname'])) {
1192 1192
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1193
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1194
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1193
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1194
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1195 1195
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1196 1196
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1197 1197
 	    		else {
1198
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1199
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1200
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1198
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1199
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1200
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1201 1201
 	    		}
1202 1202
 	    	    }
1203 1203
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1222,14 +1222,14 @@  discard block
 block discarded – undo
1222 1222
 	    //$buffer = $Common->getData($hosts[$id]);
1223 1223
 	    if ($globalDebug) echo 'Get Data...'."\n";
1224 1224
 	    $buffer = $Common->getData($value['host']);
1225
-	    $all_data = json_decode($buffer,true);
1225
+	    $all_data = json_decode($buffer, true);
1226 1226
 	    if ($buffer != '' && is_array($all_data)) {
1227 1227
 		$reset = 0;
1228 1228
 		foreach ($all_data as $line) {
1229 1229
 	    	    $data = array();
1230 1230
 	    	    //$data['id'] = $line['id']; // id not usable
1231 1231
 	    	    $data['id'] = trim($line['flight_id']);
1232
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1232
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1233 1233
 	    	    $data['pilot_name'] = $line['pilot_name'];
1234 1234
 	    	    $data['pilot_id'] = $line['pilot_id'];
1235 1235
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1273,24 +1273,24 @@  discard block
 block discarded – undo
1273 1273
 	    //$buffer = $Common->getData($hosts[$id]);
1274 1274
 	    if ($globalDebug) echo 'Get Data...'."\n";
1275 1275
 	    $buffer = $Common->getData($value['host']);
1276
-	    $all_data = json_decode($buffer,true);
1276
+	    $all_data = json_decode($buffer, true);
1277 1277
 	    if ($buffer != '') {
1278 1278
 		$Source->deleteLocationBySource('blitzortung');
1279
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1280
-		$buffer = explode('\n',$buffer);
1279
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1280
+		$buffer = explode('\n', $buffer);
1281 1281
 		foreach ($buffer as $buffer_line) {
1282
-		    $line = json_decode($buffer_line,true);
1282
+		    $line = json_decode($buffer_line, true);
1283 1283
 		    if (isset($line['time'])) {
1284 1284
 			$data = array();
1285 1285
 			$data['altitude'] = $line['alt']; // altitude
1286 1286
 			$data['latitude'] = $line['lat']; // lat
1287 1287
 			$data['longitude'] = $line['lon']; // long
1288
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1288
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1289 1289
 			$data['id_source'] = $id_source;
1290 1290
 			$data['format_source'] = 'blitzortung';
1291 1291
 			$SI->add($data);
1292 1292
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1293
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1293
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1294 1294
 			unset($data);
1295 1295
 		    }
1296 1296
 		}
@@ -1315,11 +1315,11 @@  discard block
 block discarded – undo
1315 1315
 		    //$value = $formats[$nb];
1316 1316
 		    $format = $globalSources[$nb]['format'];
1317 1317
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1318
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1318
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1319 1319
 		    } elseif ($format == 'vrstcp') {
1320 1320
 			$buffer = @socket_read($r, 6000);
1321 1321
 		    } else {
1322
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1322
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1323 1323
 		    }
1324 1324
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1325 1325
 		    //echo $buffer."\n";
@@ -1328,8 +1328,8 @@  discard block
 block discarded – undo
1328 1328
 		    $error = false;
1329 1329
 		    //$SI::del();
1330 1330
 		    if ($format == 'vrstcp') {
1331
-			$buffer = explode('},{',$buffer);
1332
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1331
+			$buffer = explode('},{', $buffer);
1332
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1333 1333
 		    // SBS format is CSV format
1334 1334
 		    if ($buffer !== FALSE && $buffer != '') {
1335 1335
 			$tt[$format] = 0;
@@ -1363,13 +1363,13 @@  discard block
 block discarded – undo
1363 1363
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1364 1364
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1365 1365
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1366
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1366
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1367 1367
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1368 1368
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1369 1369
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1370 1370
 
1371 1371
 			    if (isset($ais_data['timestamp'])) {
1372
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1372
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1373 1373
 			    } else {
1374 1374
 				$data['datetime'] = date('Y-m-d H:i:s');
1375 1375
 			    }
@@ -1380,10 +1380,10 @@  discard block
 block discarded – undo
1380 1380
                         } elseif ($format == 'flightgearsp') {
1381 1381
                     	    //echo $buffer."\n";
1382 1382
                     	    if (strlen($buffer) > 5) {
1383
-				$line = explode(',',$buffer);
1383
+				$line = explode(',', $buffer);
1384 1384
 				$data = array();
1385 1385
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1386
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1386
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1387 1387
 				$data['ident'] = $line[6];
1388 1388
 				$data['aircraft_name'] = $line[7];
1389 1389
 				$data['longitude'] = $line[1];
@@ -1400,16 +1400,16 @@  discard block
 block discarded – undo
1400 1400
                         } elseif ($format == 'acars') {
1401 1401
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1402 1402
 			    $ACARS->add(trim($buffer));
1403
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1403
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1404 1404
 			    $ACARS->deleteLiveAcarsData();
1405 1405
 			} elseif ($format == 'flightgearmp') {
1406
-			    if (substr($buffer,0,1) != '#') {
1406
+			    if (substr($buffer, 0, 1) != '#') {
1407 1407
 				$data = array();
1408 1408
 				//echo $buffer."\n";
1409
-				$line = explode(' ',$buffer);
1409
+				$line = explode(' ', $buffer);
1410 1410
 				if (count($line) == 11) {
1411
-				    $userserver = explode('@',$line[0]);
1412
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1411
+				    $userserver = explode('@', $line[0]);
1412
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1413 1413
 				    $data['ident'] = $userserver[0];
1414 1414
 				    $data['registration'] = $userserver[0];
1415 1415
 				    $data['latitude'] = $line[4];
@@ -1417,8 +1417,8 @@  discard block
 block discarded – undo
1417 1417
 				    $data['altitude'] = $line[6];
1418 1418
 				    $data['datetime'] = date('Y-m-d H:i:s');
1419 1419
 				    $aircraft_type = $line[10];
1420
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1421
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1420
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1421
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1422 1422
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1423 1423
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1424 1424
 				}
@@ -1427,8 +1427,8 @@  discard block
 block discarded – undo
1427 1427
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1428 1428
 			    die;
1429 1429
 			} elseif ($format == 'vrstcp') {
1430
-			    foreach($buffer as $all_data) {
1431
-				$line = json_decode('{'.$all_data.'}',true);
1430
+			    foreach ($buffer as $all_data) {
1431
+				$line = json_decode('{'.$all_data.'}', true);
1432 1432
 				$data = array();
1433 1433
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1434 1434
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1454,16 +1454,16 @@  discard block
 block discarded – undo
1454 1454
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1455 1455
 				unset($data);
1456 1456
 			    }
1457
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1457
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1458 1458
 			    $line = explode("\t", $buffer);
1459
-			    for($k = 0; $k < count($line); $k=$k+2) {
1459
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1460 1460
 				$key = $line[$k];
1461
-			        $lined[$key] = $line[$k+1];
1461
+			        $lined[$key] = $line[$k + 1];
1462 1462
 			    }
1463 1463
     			    if (count($lined) > 3) {
1464 1464
     				$data['hex'] = $lined['hexid'];
1465 1465
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1466
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1466
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1467 1467
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1468 1468
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1469 1469
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1482,22 +1482,22 @@  discard block
 block discarded – undo
1482 1482
     			    } else $error = true;
1483 1483
 			} elseif ($format == 'aprs' && $use_aprs) {
1484 1484
 			    if ($aprs_connect == 0) {
1485
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1485
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1486 1486
 				$aprs_connect = 1;
1487 1487
 			    }
1488 1488
 			    
1489
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1489
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1490 1490
 				$aprs_last_tx = time();
1491 1491
 				$data_aprs = "# Keep alive";
1492
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1492
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1493 1493
 			    }
1494 1494
 			    
1495 1495
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1496 1496
 			    //echo 'APRS data : '.$buffer."\n";
1497
-			    $buffer = str_replace('APRS <- ','',$buffer);
1498
-			    $buffer = str_replace('APRS -> ','',$buffer);
1497
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1498
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1499 1499
 			    //echo $buffer."\n";
1500
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1500
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1501 1501
 				$line = $APRS->parse($buffer);
1502 1502
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1503 1503
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
 				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1513 1513
 				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1514 1514
 				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1515
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1515
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1516 1516
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1517 1517
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1518 1518
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1594,29 +1594,29 @@  discard block
 block discarded – undo
1594 1594
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1595 1595
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1596 1596
 					$Source->deleteOldLocationByType('gs');
1597
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1598
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1597
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1598
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1599 1599
 					} else {
1600
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1600
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1601 1601
 					}
1602 1602
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1603 1603
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1604 1604
 					if ($globalDebug) echo '# Weather Station added'."\n";
1605 1605
 					$Source->deleteOldLocationByType('wx');
1606 1606
 					$weather_data = json_encode($line);
1607
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1608
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1607
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1608
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1609 1609
 					} else {
1610
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1610
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1611 1611
 					}
1612 1612
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1613 1613
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1614 1614
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1615 1615
 					$Source->deleteOldLocationByType('lightning');
1616
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1617
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1616
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1617
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1618 1618
 					} else {
1619
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1619
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1620 1620
 					}
1621 1621
 				    } elseif ($globalDebug) {
1622 1622
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
 				    unset($data);
1626 1626
 				}
1627 1627
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1628
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1628
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1629 1629
 				}
1630 1630
 				/*
1631 1631
 				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')) {
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 				*/
1635 1635
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1636 1636
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1637
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1637
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1638 1638
 					$Source->deleteOldLocationByType('lightning');
1639 1639
 					$Source->deleteOldLocationByType('wx');
1640 1640
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
 				connect_all($sourceee);
1720 1720
 				$sourceee = array();
1721 1721
 				//connect_all($globalSources);
1722
-				$tt[$format]=0;
1722
+				$tt[$format] = 0;
1723 1723
 				break;
1724 1724
 			    }
1725 1725
 			}
@@ -1728,14 +1728,14 @@  discard block
 block discarded – undo
1728 1728
 	    } else {
1729 1729
 		$error = socket_strerror(socket_last_error());
1730 1730
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1731
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1731
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1732 1732
 			if (isset($globalDebug)) echo "Restarting...\n";
1733 1733
 			// Restart the script if possible
1734 1734
 			if (is_array($sockets)) {
1735 1735
 			    if ($globalDebug) echo "Shutdown all sockets...";
1736 1736
 			    
1737 1737
 			    foreach ($sockets as $sock) {
1738
-				@socket_shutdown($sock,2);
1738
+				@socket_shutdown($sock, 2);
1739 1739
 				@socket_close($sock);
1740 1740
 			    }
1741 1741
 			    
Please login to merge, or discard this patch.