Completed
Push — master ( 014bf0...2f98db )
by Yannick
09:33
created
scripts/daemon-spotter.php 3 patches
Indentation   +1217 added lines, -1217 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) {
18
-    require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19 19
 }
20 20
 if (isset($globalMarine) && $globalMarine) {
21
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25 25
 if (!isset($globalDebug)) $globalDebug = FALSE;
26 26
 
27 27
 if ($globalInstalled === FALSE) {
28
-    echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
-    sleep(5);
30
-    die();
28
+	echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
+	sleep(5);
30
+	die();
31 31
 }
32 32
 
33 33
 
34 34
 // Check if schema is at latest version
35 35
 $Connection = new Connection();
36 36
 if ($Connection->connectionExists() === false) {
37
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
-    exit();
37
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
+	exit();
39 39
 }
40 40
 if ($Connection->latest() === false) {
41
-    echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
-    exit();
41
+	echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
+	exit();
43 43
 }
44 44
 if (PHP_SAPI != 'cli') {
45
-    echo "This script MUST be called from console, not a web browser.";
45
+	echo "This script MUST be called from console, not a web browser.";
46 46
 //    exit();
47 47
 }
48 48
 
49 49
 // This is to be compatible with old version of settings.php
50 50
 if (!isset($globalSources)) {
51
-    if (isset($globalSBS1Hosts)) {
52
-        //$hosts = $globalSBS1Hosts;
53
-        foreach ($globalSBS1Hosts as $host) {
54
-	    $globalSources[] = array('host' => $host);
55
-    	}
56
-    } else {
57
-        if (!isset($globalSBS1Host)) {
58
-	    echo '$globalSources MUST be defined !';
59
-	    die;
51
+	if (isset($globalSBS1Hosts)) {
52
+		//$hosts = $globalSBS1Hosts;
53
+		foreach ($globalSBS1Hosts as $host) {
54
+		$globalSources[] = array('host' => $host);
55
+		}
56
+	} else {
57
+		if (!isset($globalSBS1Host)) {
58
+		echo '$globalSources MUST be defined !';
59
+		die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62 62
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
63
-    }
63
+	}
64 64
 }
65 65
 
66 66
 $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'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70
-    $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
70
+	$globalSources = array();
71
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
+	else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74
-    $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
74
+	$globalSources = array();
75
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
+	else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
79 79
 	$globalServerAPRS = TRUE;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 if (isset($options['idsource'])) $id_source = $options['idsource'];
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
115
+	if ($globalDebug) echo "Using Server Mode\n";
116
+	$SI=new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
126
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
126
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 128
 }
129 129
 
130 130
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
131 131
 if (isset($globalMarine) && $globalMarine) {
132
-    $AIS = new AIS();
133
-    $MI = new MarineImport($Connection->db);
132
+	$AIS = new AIS();
133
+	$MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136 136
 $SBS=new SBS();
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
147
-        global $sockets;
148
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
-        die("Bye!\n");
150
-    });
151
-    pcntl_signal_dispatch();
146
+	pcntl_signal(SIGINT,  function() {
147
+		global $sockets;
148
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
+		die("Bye!\n");
150
+	});
151
+	pcntl_signal_dispatch();
152 152
 }
153 153
 
154 154
 // let's try and connect
@@ -158,47 +158,47 @@  discard block
 block discarded – undo
158 158
 $reset = 0;
159 159
 
160 160
 function connect_all($hosts) {
161
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
-    $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
165
-    foreach ($hosts as $id => $value) {
161
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
+	$reset++;
164
+	if ($globalDebug) echo 'Connect to all...'."\n";
165
+	foreach ($hosts as $id => $value) {
166 166
 	$host = $value['host'];
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170 170
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
172
-        	//$formats[$id] = 'deltadbtxt';
173
-        	$globalSources[$id]['format'] = 'deltadbtxt';
174
-        	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
-        	//$formats[$id] = 'vatsimtxt';
178
-        	$globalSources[$id]['format'] = 'vatsimtxt';
179
-        	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182
-        	//$formats[$id] = 'aircraftlistjson';
183
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
184
-        	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
187
-        	//$formats[$id] = 'aircraftjson';
188
-        	$globalSources[$id]['format'] = 'aircraftjson';
189
-        	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
192
-        	//$formats[$id] = 'planefinderclient';
193
-        	$globalSources[$id]['format'] = 'planefinderclient';
194
-        	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
197
-        	//$formats[$id] = 'aircraftlistjson';
198
-        	$globalSources[$id]['format'] = 'opensky';
199
-        	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
-    	    /*
171
+			if (preg_match('/deltadb.txt$/i',$host)) {
172
+			//$formats[$id] = 'deltadbtxt';
173
+			$globalSources[$id]['format'] = 'deltadbtxt';
174
+			//$last_exec['deltadbtxt'] = 0;
175
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
+			//$formats[$id] = 'vatsimtxt';
178
+			$globalSources[$id]['format'] = 'vatsimtxt';
179
+			//$last_exec['vatsimtxt'] = 0;
180
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
182
+			//$formats[$id] = 'aircraftlistjson';
183
+			$globalSources[$id]['format'] = 'aircraftlistjson';
184
+			//$last_exec['aircraftlistjson'] = 0;
185
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
+			} else if (preg_match('/aircraft.json$/i',$host)) {
187
+			//$formats[$id] = 'aircraftjson';
188
+			$globalSources[$id]['format'] = 'aircraftjson';
189
+			//$last_exec['aircraftlistjson'] = 0;
190
+			if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
+			} else if (preg_match('/aircraft$/i',$host)) {
192
+			//$formats[$id] = 'planefinderclient';
193
+			$globalSources[$id]['format'] = 'planefinderclient';
194
+			//$last_exec['aircraftlistjson'] = 0;
195
+			if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
+			} else if (preg_match('/opensky/i',$host)) {
197
+			//$formats[$id] = 'aircraftlistjson';
198
+			$globalSources[$id]['format'] = 'opensky';
199
+			//$last_exec['aircraftlistjson'] = 0;
200
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
+			/*
202 202
     	    // Disabled for now, site change source format
203 203
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
204 204
         	//$formats[$id] = 'radarvirtueljson';
@@ -210,131 +210,131 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
-        	//$formats[$id] = 'planeupdatefaa';
215
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
216
-        	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
-        	    exit(0);
221
-        	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
-        	//$formats[$id] = 'phpvmacars';
224
-        	$globalSources[$id]['format'] = 'phpvmacars';
225
-        	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
-        	//$formats[$id] = 'phpvmacars';
229
-        	$globalSources[$id]['format'] = 'vaos';
230
-        	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
233
-        	//$formats[$id] = 'phpvmacars';
234
-        	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
237
-        	//$formats[$id] = 'whazzup';
238
-        	$globalSources[$id]['format'] = 'whazzup';
239
-        	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
242
-        	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
245
-        	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
248
-        	//$formats[$id] = 'pirepsjson';
249
-        	$globalSources[$id]['format'] = 'pirepsjson';
250
-        	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
-        	//$formats[$id] = 'fr24json';
254
-        	$globalSources[$id]['format'] = 'fr24json';
255
-        	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
-        	    exit(0);
260
-        	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
262
-        	//$formats[$id] = 'fr24json';
263
-        	$globalSources[$id]['format'] = 'myshiptracking';
264
-        	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
-        	    exit(0);
269
-        	}
270
-            //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
-        	//$formats[$id] = 'tsv';
273
-        	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
-            }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
-    		    if ($idf !== false) {
280
-    			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
288
-	    if (isset($hostport[1])) {
213
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
+			//$formats[$id] = 'planeupdatefaa';
215
+			$globalSources[$id]['format'] = 'planeupdatefaa';
216
+			//$last_exec['planeupdatefaa'] = 0;
217
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
+				exit(0);
221
+			}
222
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
+			//$formats[$id] = 'phpvmacars';
224
+			$globalSources[$id]['format'] = 'phpvmacars';
225
+			//$last_exec['phpvmacars'] = 0;
226
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
+			//$formats[$id] = 'phpvmacars';
229
+			$globalSources[$id]['format'] = 'vaos';
230
+			//$last_exec['phpvmacars'] = 0;
231
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
233
+			//$formats[$id] = 'phpvmacars';
234
+			$globalSources[$id]['format'] = 'vam';
235
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
+			} else if (preg_match('/whazzup/i',$host)) {
237
+			//$formats[$id] = 'whazzup';
238
+			$globalSources[$id]['format'] = 'whazzup';
239
+			//$last_exec['whazzup'] = 0;
240
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
+			} else if (preg_match('/blitzortung/i',$host)) {
242
+			$globalSources[$id]['format'] = 'blitzortung';
243
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
+			} else if (preg_match('/airwhere/i',$host)) {
245
+			$globalSources[$id]['format'] = 'airwhere';
246
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
+			} else if (preg_match('/recentpireps/i',$host)) {
248
+			//$formats[$id] = 'pirepsjson';
249
+			$globalSources[$id]['format'] = 'pirepsjson';
250
+			//$last_exec['pirepsjson'] = 0;
251
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
+			//$formats[$id] = 'fr24json';
254
+			$globalSources[$id]['format'] = 'fr24json';
255
+			//$last_exec['fr24json'] = 0;
256
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
+				exit(0);
260
+			}
261
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
262
+			//$formats[$id] = 'fr24json';
263
+			$globalSources[$id]['format'] = 'myshiptracking';
264
+			//$last_exec['fr24json'] = 0;
265
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
+				exit(0);
269
+			}
270
+			//} else if (preg_match('/10001/',$host)) {
271
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
+			//$formats[$id] = 'tsv';
273
+			$globalSources[$id]['format'] = 'tsv';
274
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
+			}
276
+		} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
+			if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
+				if ($idf !== false) {
280
+				$httpfeeds[$id] = $idf;
281
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
+			} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
+			elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
+			elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
+		$hostport = explode(':',$host);
288
+		if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
291
-	    } else {
291
+		} else {
292 292
 		$port = $globalSources[$id]['port'];
293 293
 		$hostn = $globalSources[$id]['host'];
294
-	    }
295
-	    $Common = new Common();
296
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
-    	    } else {
299
-    		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
-	    }
302
-	    if ($s) {
303
-    	        $sockets[$id] = $s;
304
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
294
+		}
295
+		$Common = new Common();
296
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
+			} else {
299
+			$udp = true;
300
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
+		}
302
+		if ($s) {
303
+				$sockets[$id] = $s;
304
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312
-    		    } elseif ($port == '10001') {
313
-        		//$formats[$id] = 'tsv';
314
-        		$globalSources[$id]['format'] = 'tsv';
315
-		    } elseif ($port == '30002') {
316
-        		//$formats[$id] = 'raw';
317
-        		$globalSources[$id]['format'] = 'raw';
318
-		    } elseif ($port == '5001') {
319
-        		//$formats[$id] = 'raw';
320
-        		$globalSources[$id]['format'] = 'flightgearmp';
321
-		    } elseif ($port == '30005') {
312
+				} elseif ($port == '10001') {
313
+				//$formats[$id] = 'tsv';
314
+				$globalSources[$id]['format'] = 'tsv';
315
+			} elseif ($port == '30002') {
316
+				//$formats[$id] = 'raw';
317
+				$globalSources[$id]['format'] = 'raw';
318
+			} elseif ($port == '5001') {
319
+				//$formats[$id] = 'raw';
320
+				$globalSources[$id]['format'] = 'flightgearmp';
321
+			} elseif ($port == '30005') {
322 322
 			// Not yet supported
323
-        		//$formats[$id] = 'beast';
324
-        		$globalSources[$id]['format'] = 'beast';
325
-		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
327
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
323
+				//$formats[$id] = 'beast';
324
+				$globalSources[$id]['format'] = 'beast';
325
+			//} else $formats[$id] = 'sbs';
326
+			} else $globalSources[$id]['format'] = 'sbs';
327
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 328
 		}
329 329
 		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330 330
 		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
331
-            } else {
331
+			} else {
332 332
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
333 333
 		sleep(10);
334 334
 		connect_all($hosts);
335
-    	    }
336
-        }
337
-    }
335
+			}
336
+		}
337
+	}
338 338
 }
339 339
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
340 340
 
@@ -357,9 +357,9 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
361 361
 } else {
362
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
362
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
364 364
 
365 365
 // APRS Configuration
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	die;
369 369
 }
370 370
 foreach ($globalSources as $key => $source) {
371
-    if (!isset($source['format'])) {
372
-        $globalSources[$key]['format'] = 'auto';
373
-    }
374
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
375
-        unset($globalSources[$key]);
376
-    }
371
+	if (!isset($source['format'])) {
372
+		$globalSources[$key]['format'] = 'auto';
373
+	}
374
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
375
+		unset($globalSources[$key]);
376
+	}
377 377
 }
378 378
 connect_all($globalSources);
379 379
 foreach ($globalSources as $key => $source) {
380
-    if (isset($source['format']) && $source['format'] == 'aprs') {
380
+	if (isset($source['format']) && $source['format'] == 'aprs') {
381 381
 	$aprs_connect = 0;
382 382
 	$use_aprs = true;
383 383
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
384 384
 	break;
385
-    }
385
+	}
386 386
 }
387 387
 
388 388
 if ($use_aprs) {
@@ -423,173 +423,173 @@  discard block
 block discarded – undo
423 423
 
424 424
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 425
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
426
+	if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
429
-    // Delete old ATC
430
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
428
+	if (!$globalDaemon) $i = $endtime-time();
429
+	// Delete old ATC
430
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
432
-        $ATC->deleteOldATC();
433
-    }
432
+		$ATC->deleteOldATC();
433
+	}
434 434
     
435
-    if (count($last_exec) == count($globalSources)) {
435
+	if (count($last_exec) == count($globalSources)) {
436 436
 	$max = $globalMinFetch;
437 437
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
438
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
441
+		if ($globalDebug) echo 'Sleeping...'."\n";
442
+		sleep($globalMinFetch-$max+2);
443
+	}
443 444
 	}
444
-    }
445 445
 
446 446
     
447
-    //foreach ($formats as $id => $value) {
448
-    foreach ($globalSources as $id => $value) {
447
+	//foreach ($formats as $id => $value) {
448
+	foreach ($globalSources as $id => $value) {
449 449
 	date_default_timezone_set('UTC');
450 450
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451 451
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
452 452
 	if ($value['format'] === 'deltadbtxt' && 
453
-	    (
453
+		(
454 454
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
455 455
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
456
-	    )
456
+		)
457 457
 	) {
458
-        //$buffer = $Common->getData($hosts[$id]);
459
-        $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
461
-        $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
-        $buffer = explode('\n', $buffer);
463
-        foreach ($buffer as $line) {
464
-            if ($line != '' && count($line) > 7) {
465
-                $line = explode(',', $line);
466
-                $data = array();
467
-                $data['hex'] = $line[1]; // hex
468
-                $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
-                $data['verticalrate'] = ''; // vertical rate
475
-                //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
-                $data['emergency'] = ''; // emergency
477
-                $data['datetime'] = date('Y-m-d H:i:s');
478
-                $data['format_source'] = 'deltadbtxt';
479
-                $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
-                $SI->add($data);
484
-                unset($data);
485
-            }
486
-        }
487
-        $last_exec[$id]['last'] = time();
488
-    } elseif ($value['format'] === 'radarcapejson' &&
489
-            (
490
-                (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
-                (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
-            )
493
-        ) {
494
-            //$buffer = $Common->getData($hosts[$id]);
495
-            $buffer = $Common->getData($value['host']);
496
-            if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
498
-                foreach ($all_data as $line) {
499
-                    $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
-                    $data['hex'] = $line['hex']; // hex
502
-                    $data['ident'] = $line['fli']; // ident
503
-                    $data['altitude'] = $line['alt']; // altitude
504
-                    $data['speed'] = $line['spd']; // speed
505
-                    $data['heading'] = $line['trk']; // heading
506
-                    $data['latitude'] = $line['lat']; // lat
507
-                    $data['longitude'] = $line['lon']; // long
508
-                    $data['verticalrate'] = $line['vrt']; // vertical rate
509
-                    $data['squawk'] = $line['squ']; // squawk
510
-                    $data['ground'] = $line['gda']; // ground
511
-                    $data['registration'] = $line['reg'];
512
-                    //$data['emergency'] = ''; // emergency
513
-                    $data['datetime'] = date('Y-m-d H:i:s');
514
-                    $data['format_source'] = 'radarcapejson';
515
-                    $data['id_source'] = $id_source;
516
-                    if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
458
+		//$buffer = $Common->getData($hosts[$id]);
459
+		$buffer = $Common->getData($value['host']);
460
+		if ($buffer != '') $reset = 0;
461
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
+		$buffer = explode('\n', $buffer);
463
+		foreach ($buffer as $line) {
464
+			if ($line != '' && count($line) > 7) {
465
+				$line = explode(',', $line);
466
+				$data = array();
467
+				$data['hex'] = $line[1]; // hex
468
+				$data['ident'] = $line[2]; // ident
469
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
+				$data['verticalrate'] = ''; // vertical rate
475
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
+				$data['emergency'] = ''; // emergency
477
+				$data['datetime'] = date('Y-m-d H:i:s');
478
+				$data['format_source'] = 'deltadbtxt';
479
+				$data['id_source'] = $id_source;
480
+				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
+				if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
+				$SI->add($data);
484
+				unset($data);
485
+			}
486
+		}
487
+		$last_exec[$id]['last'] = time();
488
+	} elseif ($value['format'] === 'radarcapejson' &&
489
+			(
490
+				(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
+				(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
+			)
493
+		) {
494
+			//$buffer = $Common->getData($hosts[$id]);
495
+			$buffer = $Common->getData($value['host']);
496
+			if ($buffer != '') {
497
+				$all_data = json_decode($buffer,true);
498
+				foreach ($all_data as $line) {
499
+					$data = array();
500
+					$data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
+					$data['hex'] = $line['hex']; // hex
502
+					$data['ident'] = $line['fli']; // ident
503
+					$data['altitude'] = $line['alt']; // altitude
504
+					$data['speed'] = $line['spd']; // speed
505
+					$data['heading'] = $line['trk']; // heading
506
+					$data['latitude'] = $line['lat']; // lat
507
+					$data['longitude'] = $line['lon']; // long
508
+					$data['verticalrate'] = $line['vrt']; // vertical rate
509
+					$data['squawk'] = $line['squ']; // squawk
510
+					$data['ground'] = $line['gda']; // ground
511
+					$data['registration'] = $line['reg'];
512
+					//$data['emergency'] = ''; // emergency
513
+					$data['datetime'] = date('Y-m-d H:i:s');
514
+					$data['format_source'] = 'radarcapejson';
515
+					$data['id_source'] = $id_source;
516
+					if (isset($value['name']) && $value['name'] != '') {
517
+						if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
+						else $data['source_name'] = $value['name'];
519
+					} elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
+					if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
+					if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
522 522
 
523
-                    $SI->add($data);
524
-                    unset($data);
525
-                }
526
-            }
527
-            $last_exec[$id]['last'] = time();
523
+					$SI->add($data);
524
+					unset($data);
525
+				}
526
+			}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] === 'aisnmeatxt' && 
529
-	    (
529
+		(
530 530
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
531 531
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
532
-	    )
532
+		)
533 533
 	) {
534
-	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
-	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
540
-	    foreach ($buffer as $line) {
534
+		date_default_timezone_set('CET');
535
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
+		date_default_timezone_set('UTC');
537
+		if ($buffer != '') $reset = 0;
538
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
+		$buffer = explode('\n',$buffer);
540
+		foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542
-		    //echo "'".$line."'\n";
543
-		    $add = false;
544
-		    $ais_data = $AIS->parse_line(trim($line));
545
-		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
-		    if (isset($ais_data['timestamp'])) {
542
+			//echo "'".$line."'\n";
543
+			$add = false;
544
+			$ais_data = $AIS->parse_line(trim($line));
545
+			$data = array();
546
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
+			if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
+			if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
+			if (isset($ais_data['timestamp'])) {
559 559
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
-			    $add = true;
561
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
+				$add = true;
563 563
 			}
564
-		    } else {
564
+			} else {
565 565
 			$data['datetime'] = date('Y-m-d H:i:s');
566 566
 			$add = true;
567
-		    }
568
-		    $data['format_source'] = 'aisnmeatxt';
569
-    		    $data['id_source'] = $id_source;
570
-		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
-		    unset($data);
567
+			}
568
+			$data['format_source'] = 'aisnmeatxt';
569
+				$data['id_source'] = $id_source;
570
+			//print_r($data);
571
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
+			unset($data);
574 574
 		}
575
-    	    }
576
-    	    $last_exec[$id]['last'] = time();
575
+			}
576
+			$last_exec[$id]['last'] = time();
577 577
 	} elseif ($value['format'] === 'aisnmeahttp') {
578
-	    $arr = $httpfeeds;
579
-	    $w = $e = null;
578
+		$arr = $httpfeeds;
579
+		$w = $e = null;
580 580
 	    
581
-	    if (isset($arr[$id])) {
581
+		if (isset($arr[$id])) {
582 582
 		$nn = stream_select($arr,$w,$e,$timeout);
583 583
 		if ($nn > 0) {
584
-		    foreach ($httpfeeds as $feed) {
584
+			foreach ($httpfeeds as $feed) {
585 585
 			$buffer = stream_get_line($feed,2000,"\n");
586 586
 			if ($buffer === FALSE) {
587
-			    connect_all($globalSources);
587
+				connect_all($globalSources);
588 588
 			}
589 589
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590 590
 			$buffer = explode('\n',$buffer);
591 591
 			foreach ($buffer as $line) {
592
-			    if ($line != '') {
592
+				if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -607,117 +607,117 @@  discard block
 block discarded – undo
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608 608
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 611
 				} else {
612
-				    $data['datetime'] = date('Y-m-d H:i:s');
612
+					$data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
614 614
 				$data['format_source'] = 'aisnmeahttp';
615 615
 				$data['id_source'] = $id_source;
616 616
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617 617
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
618 618
 				unset($data);
619
-			    }
619
+				}
620
+			}
620 621
 			}
621
-		    }
622 622
 		} else {
623
-		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
626
-		    if ($tt[$format] > 30) {
623
+			$format = $value['format'];
624
+			if (isset($tt[$format])) $tt[$format]++;
625
+			else $tt[$format] = 0;
626
+			if ($tt[$format] > 30) {
627 627
 			if ($globalDebug) echo 'Reconnect...'."\n";
628 628
 			sleep(2);
629 629
 			//$sourceeen[] = $value;
630 630
 			//connect_all($sourceeen);
631 631
 			//$sourceeen = array();
632 632
 			connect_all($globalSources);
633
-		    }
633
+			}
634
+		}
634 635
 		}
635
-	    }
636 636
 	} elseif ($value['format'] === 'myshiptracking' && 
637
-	    (
637
+		(
638 638
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640
-	    )
640
+		)
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
643
-	    if ($buffer != '') {
642
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
643
+		if ($buffer != '') {
644 644
 		//echo $buffer;
645 645
 		$all_data = json_decode($buffer,true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648
-		    foreach ($all_data[0]['DATA'] as $line) {
648
+			foreach ($all_data[0]['DATA'] as $line) {
649 649
 			if ($line != '') {
650
-			    $data = array();
651
-			    $data['ident'] = $line['NAME'];
652
-			    $data['mmsi'] = $line['MMSI'];
653
-			    if (strlen($data['mmsi']) > 9) {
650
+				$data = array();
651
+				$data['ident'] = $line['NAME'];
652
+				$data['mmsi'] = $line['MMSI'];
653
+				if (strlen($data['mmsi']) > 9) {
654 654
 				$data['mmsi'] = substr($data['mmsi'],-9);
655
-			    }
656
-			    $data['speed'] = $line['SOG'];
657
-			    $data['heading'] = $line['COG'];
658
-			    $data['latitude'] = $line['LAT'];
659
-			    $data['longitude'] = $line['LNG'];
660
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
-			    //$data['type_id'] = $line['TYPE'];
662
-			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
-			    $data['format_source'] = 'myshiptracking';
667
-			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
-			    $MI->add($data);
670
-			    unset($data);
655
+				}
656
+				$data['speed'] = $line['SOG'];
657
+				$data['heading'] = $line['COG'];
658
+				$data['latitude'] = $line['LAT'];
659
+				$data['longitude'] = $line['LNG'];
660
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
+				//$data['type_id'] = $line['TYPE'];
662
+				$data['imo'] = $line['IMO'];
663
+				if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
+				if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
+				$data['format_source'] = 'myshiptracking';
667
+				$data['id_source'] = $id_source;
668
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
+				$MI->add($data);
670
+				unset($data);
671
+			}
671 672
 			}
672
-		    }
673 673
 		}
674
-	    }
675
-	    $last_exec[$id]['last'] = time();
674
+		}
675
+		$last_exec[$id]['last'] = time();
676 676
 	} elseif ($value['format'] === 'boatbeaconapp' && 
677
-	    (
677
+		(
678 678
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680
-	    )
680
+		)
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
-	    if ($buffer != '') {
682
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
+		if ($buffer != '') {
684 684
 		$all_data = json_decode($buffer,true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686
-		    foreach ($all_data as $line) {
686
+			foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688
-			    $data = array();
689
-			    $data['ident'] = $line['shipname'];
690
-			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
692
-			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
-			    $data['latitude'] = $line['latitude'];
695
-			    $data['longitude'] = $line['longitude'];
696
-			    $data['type_id'] = $line['shiptype'];
697
-			    $data['arrival_code'] = $line['destination'];
698
-			    $data['datetime'] = $line['time'];
699
-			    $data['format_source'] = 'boatbeaconapp';
700
-			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-			    $MI->add($data);
703
-			    unset($data);
688
+				$data = array();
689
+				$data['ident'] = $line['shipname'];
690
+				$data['callsign'] = $line['callsign'];
691
+				$data['mmsi'] = substr($line['mmsi'],-9);
692
+				$data['speed'] = $line['sog'];
693
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
+				$data['latitude'] = $line['latitude'];
695
+				$data['longitude'] = $line['longitude'];
696
+				$data['type_id'] = $line['shiptype'];
697
+				$data['arrival_code'] = $line['destination'];
698
+				$data['datetime'] = $line['time'];
699
+				$data['format_source'] = 'boatbeaconapp';
700
+				$data['id_source'] = $id_source;
701
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
+				$MI->add($data);
703
+				unset($data);
704
+			}
704 705
 			}
705
-		    }
706 706
 		}
707 707
 		
708
-	    }
709
-    	    $last_exec[$id]['last'] = time();
708
+		}
709
+			$last_exec[$id]['last'] = time();
710 710
 	} elseif ($value['format'] === 'boatnerd' && 
711
-	    (
711
+		(
712 712
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
713 713
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
714
-	    )
714
+		)
715 715
 	) {
716
-	    $buffer = $Common->getData($value['host']);
717
-	    if ($buffer != '') {
716
+		$buffer = $Common->getData($value['host']);
717
+		if ($buffer != '') {
718 718
 		$all_data = json_decode($buffer,true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720
-		    foreach ($all_data['features'] as $line) {
720
+			foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
@@ -737,75 +737,75 @@  discard block
 block discarded – undo
737 737
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738 738
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
739 739
 			unset($data);
740
-		    }
740
+			}
741 741
 		}
742 742
 		
743
-	    }
744
-    	    $last_exec[$id]['last'] = time();
743
+		}
744
+			$last_exec[$id]['last'] = time();
745 745
 	} elseif ($value['format'] === 'shipplotter' && 
746
-	    (
746
+		(
747 747
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
748 748
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749
-	    )
749
+		)
750 750
 	) {
751
-	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
754
-	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
758
-	    foreach ($buffer as $line) {
751
+		if ($globalDebug) echo 'download...';
752
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
+		if ($globalDebug) echo 'done !'."\n";
754
+		// FIXME: Need more work
755
+		if ($buffer != '') $reset = 0;
756
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
+		$buffer = explode('\n',$buffer);
758
+		foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760
-		    $data = array();
761
-		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
769
-		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
771
-		    //$data['draft'] = substr($line,67,4);
772
-		    //$data['length'] = substr($line,72,3);
773
-		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
-		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
777
-		    //$data['etaDate'] = substr($line,129,5);
778
-		    //$data['etaTime'] = substr($line,135,5);
779
-		    $data['format_source'] = 'shipplotter';
780
-    		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
-		    //print_r($data);
783
-		    //echo 'Add...'."\n";
784
-		    $MI->add($data);
785
-		    unset($data);
760
+			$data = array();
761
+			//echo $line."\n";
762
+			$data['mmsi'] = (int)substr($line,0,9);
763
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
+			$data['status_id'] = substr($line,21,2);
765
+			$data['type_id'] = substr($line,24,3);
766
+			$data['latitude'] = substr($line,29,9);
767
+			$data['longitude'] = substr($line,41,9);
768
+			$data['speed'] = round(substr($line,51,5));
769
+			//$data['course'] = substr($line,57,5);
770
+			$data['heading'] = round(substr($line,63,3));
771
+			//$data['draft'] = substr($line,67,4);
772
+			//$data['length'] = substr($line,72,3);
773
+			//$data['beam'] = substr($line,76,2);
774
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
+			//$data['callsign'] = trim(substr($line,100,7);
776
+			$data['arrival_code'] = substr($line,108,20);
777
+			//$data['etaDate'] = substr($line,129,5);
778
+			//$data['etaTime'] = substr($line,135,5);
779
+			$data['format_source'] = 'shipplotter';
780
+				$data['id_source'] = $id_source;
781
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
+			//print_r($data);
783
+			//echo 'Add...'."\n";
784
+			$MI->add($data);
785
+			unset($data);
786 786
 		}
787
-    	    }
788
-    	    $last_exec[$id]['last'] = time();
787
+			}
788
+			$last_exec[$id]['last'] = time();
789 789
 	} elseif ($value['format'] === 'sailawayfull' && 
790
-	    (
790
+		(
791 791
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 10*60))
792
-	    )
792
+		)
793 793
 	) {
794
-	    if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
794
+		if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
795 795
 		echo 'Sailaway API key MUST be defined';
796 796
 		exit(0);
797
-	    }
798
-	    $sailawayoption = array('key' => $globalSailaway['key']);
799
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
797
+		}
798
+		$sailawayoption = array('key' => $globalSailaway['key']);
799
+		if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
+		if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
801 801
 
802
-	    for ($i = 0; $i <= 1; $i++) {
802
+		for ($i = 0; $i <= 1; $i++) {
803 803
 		if ($globalDebug) echo '! Download... ';
804 804
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?'.http_build_query($sailawayoption).'&race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2','get','','','','',30);
805 805
 		if ($globalDebug) echo 'done'."\n";
806 806
 		if ($buffer != '') {
807
-		    $all_data = json_decode($buffer,true);
808
-		    if (isset($all_data['missions'])) {
807
+			$all_data = json_decode($buffer,true);
808
+			if (isset($all_data['missions'])) {
809 809
 			foreach ($all_data['missions'] as $mission) {
810 810
 				$mission_user = $mission['usrname'];
811 811
 				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
@@ -832,17 +832,17 @@  discard block
 block discarded – undo
832 832
 					unset($datar);
833 833
 				}
834 834
 			}
835
-		    }
835
+			}
836 836
 		}
837 837
 		if ($globalDebug) echo '=== Wait... ===';
838 838
 		sleep(10*60);
839
-	    }
840
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
841
-	    if ($buffer != '') {
839
+		}
840
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
841
+		if ($buffer != '') {
842 842
 		$data = json_decode($buffer,true);
843 843
 		//print_r($data);
844 844
 		if (isset($data['boats'])) {
845
-		    foreach ($data['boats'] as $sail) {
845
+			foreach ($data['boats'] as $sail) {
846 846
 			$data = array();
847 847
 			$data['id'] = $sail['ubtnr'];
848 848
 			$data['datetime'] = date('Y-m-d H:i:s');
@@ -862,17 +862,17 @@  discard block
 block discarded – undo
862 862
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
863 863
 			$MI->add($data);
864 864
 			unset($data);
865
-		    }
865
+			}
866 866
 		} elseif ($globalDebug) echo 'Error in JSON parsing';
867
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
867
+		} elseif ($globalDebug) echo 'Empty result !'."\n";
868 868
 
869
-    	    $last_exec[$id]['last'] = time();
869
+			$last_exec[$id]['last'] = time();
870 870
 	} elseif ($value['format'] === 'sailaway' && 
871
-	    (
871
+		(
872 872
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 10*60))
873
-	    )
873
+		)
874 874
 	) {
875
-	    /*
875
+		/*
876 876
 	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
877 877
 		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
878 878
 		//echo $authsailaway;
@@ -883,21 +883,21 @@  discard block
 block discarded – undo
883 883
 		}
884 884
 	    }
885 885
 	    */
886
-	    if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
886
+		if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
887 887
 		echo 'Sailaway API key MUST be defined';
888 888
 		exit(0);
889
-	    }
890
-	    if ($globalDebug) echo '! Download... ';
891
-	    $sailawayoption = array('key' => $globalSailaway['key']);
892
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
893
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
894
-	    if (isset($globalSailaway['misnr'])) $sailawayoption = array_merge($sailawayoption,array('misnr' => $globalSailaway['misnr']));
895
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
896
-	    if ($buffer != '') {
889
+		}
890
+		if ($globalDebug) echo '! Download... ';
891
+		$sailawayoption = array('key' => $globalSailaway['key']);
892
+		if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
893
+		if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
894
+		if (isset($globalSailaway['misnr'])) $sailawayoption = array_merge($sailawayoption,array('misnr' => $globalSailaway['misnr']));
895
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
896
+		if ($buffer != '') {
897 897
 		$data = json_decode($buffer,true);
898 898
 		//print_r($data);
899 899
 		if (isset($data['boats'])) {
900
-		    foreach ($data['boats'] as $sail) {
900
+			foreach ($data['boats'] as $sail) {
901 901
 			$data = array();
902 902
 			$data['id'] = $sail['ubtnr'];
903 903
 			$data['datetime'] = date('Y-m-d H:i:s');
@@ -917,35 +917,35 @@  discard block
 block discarded – undo
917 917
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
918 918
 			$MI->add($data);
919 919
 			unset($data);
920
-		    }
920
+			}
921 921
 		} elseif ($globalDebug) echo 'Error in JSON parsing';
922
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
923
-    	    $last_exec[$id]['last'] = time();
922
+		} elseif ($globalDebug) echo 'Empty result !'."\n";
923
+			$last_exec[$id]['last'] = time();
924 924
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
925 925
 	} elseif (
926
-	    (
926
+		(
927 927
 		$value['format'] === 'whazzup' && 
928 928
 		(
929
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
930
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
929
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
930
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
931 931
 		)
932
-	    ) || (
932
+		) || (
933 933
 		$value['format'] === 'vatsimtxt' && 
934 934
 		(
935
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
936
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
935
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
936
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
937
+		)
937 938
 		)
938
-	    )
939 939
 	) {
940
-	    //$buffer = $Common->getData($hosts[$id]);
941
-	    $buffer = $Common->getData($value['host']);
942
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
943
-	    $buffer = explode('\n',$buffer);
944
-	    $reset = 0;
945
-	    foreach ($buffer as $line) {
946
-    		if ($line != '') {
947
-    		    $line = explode(':', $line);
948
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
940
+		//$buffer = $Common->getData($hosts[$id]);
941
+		$buffer = $Common->getData($value['host']);
942
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
943
+		$buffer = explode('\n',$buffer);
944
+		$reset = 0;
945
+		foreach ($buffer as $line) {
946
+			if ($line != '') {
947
+				$line = explode(':', $line);
948
+				if (count($line) > 30 && $line[0] != 'callsign') {
949 949
 			$data = array();
950 950
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
951 951
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -958,41 +958,41 @@  discard block
 block discarded – undo
958 958
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
959 959
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
960 960
 			$data['latitude'] = $line[5]; // lat
961
-	        	$data['longitude'] = $line[6]; // long
962
-	        	$data['verticalrate'] = ''; // vertical rate
963
-	        	$data['squawk'] = ''; // squawk
964
-	        	$data['emergency'] = ''; // emergency
965
-	        	$data['waypoints'] = $line[30];
961
+				$data['longitude'] = $line[6]; // long
962
+				$data['verticalrate'] = ''; // vertical rate
963
+				$data['squawk'] = ''; // squawk
964
+				$data['emergency'] = ''; // emergency
965
+				$data['waypoints'] = $line[30];
966 966
 			$data['datetime'] = date('Y-m-d H:i:s');
967 967
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
968 968
 			//if (isset($line[37])) $data['last_update'] = $line[37];
969
-		        $data['departure_airport_icao'] = $line[11];
970
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
971
-		        $data['arrival_airport_icao'] = $line[13];
969
+				$data['departure_airport_icao'] = $line[11];
970
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
971
+				$data['arrival_airport_icao'] = $line[13];
972 972
 			$data['frequency'] = $line[4];
973 973
 			$data['type'] = $line[18];
974 974
 			$data['range'] = $line[19];
975 975
 			if (isset($line[35])) $data['info'] = $line[35];
976
-    			$data['id_source'] = $id_source;
977
-	    		//$data['arrival_airport_time'] = ;
978
-	    		if ($line[9] != '') {
979
-	    		    $aircraft_data = explode('/',$line[9]);
980
-	    		    if (count($aircraft_data) == 2) {
976
+				$data['id_source'] = $id_source;
977
+				//$data['arrival_airport_time'] = ;
978
+				if ($line[9] != '') {
979
+					$aircraft_data = explode('/',$line[9]);
980
+					if (count($aircraft_data) == 2) {
981 981
 				//line[9] may equal to something like 'B738/L' in old FSD server's whazzup.txt file
982
-	    			$data['aircraft_icao'] = $aircraft_data[0];
983
-	    		    } else if (count($aircraft_data) > 2) {
982
+					$data['aircraft_icao'] = $aircraft_data[0];
983
+					} else if (count($aircraft_data) > 2) {
984 984
 				//line[9] may equal to something like 'H/B748/L'
985 985
 				$data['aircraft_icao'] = $aircraft_data[1];
986
-			    }
987
-        		}
988
-	    		/*
986
+				}
987
+				}
988
+				/*
989 989
 	    		if ($value === 'whazzup') $data['format_source'] = 'whazzup';
990 990
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
991 991
 	    		*/
992
-	    		$data['format_source'] = $value['format'];
992
+				$data['format_source'] = $value['format'];
993 993
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
994 994
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
995
-    			if ($line[3] === 'PILOT') $SI->add($data);
995
+				if ($line[3] === 'PILOT') $SI->add($data);
996 996
 			elseif ($line[3] === 'ATC') {
997 997
 				//print_r($data);
998 998
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -1013,21 +1013,21 @@  discard block
 block discarded – undo
1013 1013
 					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']);
1014 1014
 				}
1015 1015
 			}
1016
-    			unset($data);
1017
-    		    }
1018
-    		}
1019
-    	    }
1020
-    	    //if ($value === 'whazzup') $last_exec['whazzup'] = time();
1021
-    	    //elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1022
-    	    $last_exec[$id]['last'] = time();
1023
-    	} elseif ($value['format'] === 'airwhere' && 
1024
-    	    (
1025
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1026
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1027
-    	    )
1028
-    	) {
1029
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1030
-	    if ($buffer != '') {
1016
+				unset($data);
1017
+				}
1018
+			}
1019
+			}
1020
+			//if ($value === 'whazzup') $last_exec['whazzup'] = time();
1021
+			//elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1022
+			$last_exec[$id]['last'] = time();
1023
+		} elseif ($value['format'] === 'airwhere' && 
1024
+			(
1025
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1026
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1027
+			)
1028
+		) {
1029
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1030
+		if ($buffer != '') {
1031 1031
 		$all_data = simplexml_load_string($buffer);
1032 1032
 		foreach($all_data->children() as $childdata) {
1033 1033
 			$data = array();
@@ -1049,10 +1049,10 @@  discard block
 block discarded – undo
1049 1049
 			$SI->add($data);
1050 1050
 			unset($data);
1051 1051
 		}
1052
-	    }
1053
-	    $Source->deleteOldLocationByType('gs');
1054
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1055
-	    if ($buffer != '') {
1052
+		}
1053
+		$Source->deleteOldLocationByType('gs');
1054
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1055
+		if ($buffer != '') {
1056 1056
 		$all_data = simplexml_load_string($buffer);
1057 1057
 		foreach($all_data->children() as $childdata) {
1058 1058
 			$data = array();
@@ -1070,8 +1070,8 @@  discard block
 block discarded – undo
1070 1070
 			}
1071 1071
 			unset($data);
1072 1072
 		}
1073
-	    }
1074
-	    $last_exec[$id]['last'] = time();
1073
+		}
1074
+		$last_exec[$id]['last'] = time();
1075 1075
 	/*
1076 1076
 	} if ($value['format'] === 'aircraftlistjson') {
1077 1077
 	    print_r($globalSources);
@@ -1079,17 +1079,17 @@  discard block
 block discarded – undo
1079 1079
 	    echo $globalMinFetch;
1080 1080
 	*/
1081 1081
 	} elseif ($value['format'] === 'aircraftlistjson' && 
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($value['host'],'get','','','','','20');
1088
-	    if ($buffer != '') {
1089
-	        $all_data = json_decode($buffer,true);
1087
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
1088
+		if ($buffer != '') {
1089
+			$all_data = json_decode($buffer,true);
1090 1090
 		if (isset($all_data['acList'])) {
1091
-		    $reset = 0;
1092
-		    foreach ($all_data['acList'] as $line) {
1091
+			$reset = 0;
1092
+			foreach ($all_data['acList'] as $line) {
1093 1093
 			$data = array();
1094 1094
 			$data['hex'] = $line['Icao']; // hex
1095 1095
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1112,10 +1112,10 @@  discard block
 block discarded – undo
1112 1112
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1113 1113
 			if (isset($data['latitude'])) $SI->add($data);
1114 1114
 			unset($data);
1115
-		    }
1115
+			}
1116 1116
 		} elseif (is_array($all_data)) {
1117
-		    $reset = 0;
1118
-		    foreach ($all_data as $line) {
1117
+			$reset = 0;
1118
+			foreach ($all_data as $line) {
1119 1119
 			$data = array();
1120 1120
 			$data['hex'] = $line['hex']; // hex
1121 1121
 			$data['ident'] = $line['flight']; // ident
@@ -1135,291 +1135,291 @@  discard block
 block discarded – undo
1135 1135
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1136 1136
 			$SI->add($data);
1137 1137
 			unset($data);
1138
-		    }
1138
+			}
1139 1139
 		}
1140
-	    } elseif ($globalDebug) echo 'No data'."\n";
1141
-    	    //$last_exec['aircraftlistjson'] = time();
1142
-    	    $last_exec[$id]['last'] = time();
1143
-    	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1144
-    	} elseif ($value['format'] === 'planeupdatefaa' && 
1145
-    	    (
1146
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1147
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1148
-    	    )
1149
-    	) {
1150
-	    $buffer = $Common->getData($value['host']);
1151
-	    $all_data = json_decode($buffer,true);
1152
-	    if (isset($all_data['planes'])) {
1140
+		} elseif ($globalDebug) echo 'No data'."\n";
1141
+			//$last_exec['aircraftlistjson'] = time();
1142
+			$last_exec[$id]['last'] = time();
1143
+		//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1144
+		} elseif ($value['format'] === 'planeupdatefaa' && 
1145
+			(
1146
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1147
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1148
+			)
1149
+		) {
1150
+		$buffer = $Common->getData($value['host']);
1151
+		$all_data = json_decode($buffer,true);
1152
+		if (isset($all_data['planes'])) {
1153 1153
 		$reset = 0;
1154 1154
 		foreach ($all_data['planes'] as $key => $line) {
1155
-		    $data = array();
1156
-		    $data['hex'] = $key; // hex
1157
-		    $data['ident'] = $line[3]; // ident
1158
-		    $data['altitude'] = $line[6]; // altitude
1159
-		    $data['speed'] = $line[8]; // speed
1160
-		    $data['heading'] = $line[7]; // heading
1161
-		    $data['latitude'] = $line[4]; // lat
1162
-		    $data['longitude'] = $line[5]; // long
1163
-		    //$data['verticalrate'] = $line[]; // verticale rate
1164
-		    $data['squawk'] = $line[10]; // squawk
1165
-		    $data['emergency'] = ''; // emergency
1166
-		    $data['registration'] = $line[2];
1167
-		    $data['aircraft_icao'] = $line[0];
1168
-		    $deparr = explode('-',$line[1]);
1169
-		    if (count($deparr) === 2) {
1155
+			$data = array();
1156
+			$data['hex'] = $key; // hex
1157
+			$data['ident'] = $line[3]; // ident
1158
+			$data['altitude'] = $line[6]; // altitude
1159
+			$data['speed'] = $line[8]; // speed
1160
+			$data['heading'] = $line[7]; // heading
1161
+			$data['latitude'] = $line[4]; // lat
1162
+			$data['longitude'] = $line[5]; // long
1163
+			//$data['verticalrate'] = $line[]; // verticale rate
1164
+			$data['squawk'] = $line[10]; // squawk
1165
+			$data['emergency'] = ''; // emergency
1166
+			$data['registration'] = $line[2];
1167
+			$data['aircraft_icao'] = $line[0];
1168
+			$deparr = explode('-',$line[1]);
1169
+			if (count($deparr) === 2) {
1170 1170
 			$data['departure_airport_icao'] = $deparr[0];
1171 1171
 			$data['arrival_airport_icao'] = $deparr[1];
1172
-		    }
1173
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1174
-	    	    $data['format_source'] = 'planeupdatefaa';
1175
-    		    $data['id_source'] = $id_source;
1176
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1177
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1178
-		    $SI->add($data);
1179
-		    unset($data);
1172
+			}
1173
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1174
+				$data['format_source'] = 'planeupdatefaa';
1175
+				$data['id_source'] = $id_source;
1176
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1177
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1178
+			$SI->add($data);
1179
+			unset($data);
1180 1180
 		}
1181
-	    }
1182
-	    //$last_exec['planeupdatefaa'] = time();
1183
-	    $last_exec[$id]['last'] = time();
1181
+		}
1182
+		//$last_exec['planeupdatefaa'] = time();
1183
+		$last_exec[$id]['last'] = time();
1184 1184
 	} elseif ($value['format'] === 'opensky' && 
1185
-	    (
1185
+		(
1186 1186
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1187 1187
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1188
-	    )
1188
+		)
1189 1189
 	) {
1190
-	    $buffer = $Common->getData($value['host']);
1191
-	    $all_data = json_decode($buffer,true);
1192
-	    if (isset($all_data['states'])) {
1190
+		$buffer = $Common->getData($value['host']);
1191
+		$all_data = json_decode($buffer,true);
1192
+		if (isset($all_data['states'])) {
1193 1193
 		$reset = 0;
1194 1194
 		foreach ($all_data['states'] as $key => $line) {
1195
-		    $data = array();
1196
-		    $data['hex'] = $line[0]; // hex
1197
-		    $data['ident'] = trim($line[1]); // ident
1198
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
1199
-		    $data['speed'] = round($line[9]*1.94384); // speed
1200
-		    $data['heading'] = round($line[10]); // heading
1201
-		    $data['latitude'] = $line[6]; // lat
1202
-		    $data['longitude'] = $line[5]; // long
1203
-		    $data['verticalrate'] = $line[11]; // verticale rate
1204
-		    //$data['squawk'] = $line[10]; // squawk
1205
-		    //$data['emergency'] = ''; // emergency
1206
-		    //$data['registration'] = $line[2];
1207
-		    //$data['aircraft_icao'] = $line[0];
1208
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1209
-		    $data['format_source'] = 'opensky';
1210
-		    $data['id_source'] = $id_source;
1211
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
-		    $SI->add($data);
1213
-		    unset($data);
1195
+			$data = array();
1196
+			$data['hex'] = $line[0]; // hex
1197
+			$data['ident'] = trim($line[1]); // ident
1198
+			$data['altitude'] = round($line[7]*3.28084); // altitude
1199
+			$data['speed'] = round($line[9]*1.94384); // speed
1200
+			$data['heading'] = round($line[10]); // heading
1201
+			$data['latitude'] = $line[6]; // lat
1202
+			$data['longitude'] = $line[5]; // long
1203
+			$data['verticalrate'] = $line[11]; // verticale rate
1204
+			//$data['squawk'] = $line[10]; // squawk
1205
+			//$data['emergency'] = ''; // emergency
1206
+			//$data['registration'] = $line[2];
1207
+			//$data['aircraft_icao'] = $line[0];
1208
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1209
+			$data['format_source'] = 'opensky';
1210
+			$data['id_source'] = $id_source;
1211
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
+			$SI->add($data);
1213
+			unset($data);
1214 1214
 		}
1215
-	    }
1216
-	    //$last_exec['planeupdatefaa'] = time();
1217
-	    $last_exec[$id]['last'] = time();
1215
+		}
1216
+		//$last_exec['planeupdatefaa'] = time();
1217
+		$last_exec[$id]['last'] = time();
1218 1218
 	} elseif ($value['format'] === 'aircraftjson' && 
1219
-	    (
1219
+		(
1220 1220
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1221 1221
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1222
-	    )
1222
+		)
1223 1223
 	) {
1224
-	    $buffer = $Common->getData($value['host']);
1225
-	    $all_data = json_decode($buffer,true);
1226
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1224
+		$buffer = $Common->getData($value['host']);
1225
+		$all_data = json_decode($buffer,true);
1226
+		if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1227 1227
 		$reset = 0;
1228 1228
 		foreach ($all_data['aircraft'] as $key => $line) {
1229
-		    $data = array();
1230
-		    // add support for ground vehicule with ~ in front of hex
1231
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1232
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1233
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1234
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1235
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1236
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1237
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1238
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1239
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1240
-		    //$data['emergency'] = ''; // emergency
1241
-		    //$data['registration'] = $line[2];
1242
-		    //$data['aircraft_icao'] = $line[0];
1243
-		    $data['datetime'] = date('Y-m-d H:i:s');
1244
-		    $data['format_source'] = 'aircraftjson';
1245
-		    $data['id_source'] = $id_source;
1246
-		    if (isset($value['name']) && $value['name'] != '') {
1247
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1248
-			    else $data['source_name'] = $value['name'];
1249
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1250
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1251
-		    $SI->add($data);
1252
-		    unset($data);
1229
+			$data = array();
1230
+			// add support for ground vehicule with ~ in front of hex
1231
+			if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1232
+			if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1233
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1234
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1235
+			if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1236
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1237
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1238
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1239
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1240
+			//$data['emergency'] = ''; // emergency
1241
+			//$data['registration'] = $line[2];
1242
+			//$data['aircraft_icao'] = $line[0];
1243
+			$data['datetime'] = date('Y-m-d H:i:s');
1244
+			$data['format_source'] = 'aircraftjson';
1245
+			$data['id_source'] = $id_source;
1246
+			if (isset($value['name']) && $value['name'] != '') {
1247
+				if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1248
+				else $data['source_name'] = $value['name'];
1249
+			} elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1250
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1251
+			$SI->add($data);
1252
+			unset($data);
1253 1253
 		}
1254
-	    }
1255
-	    //$last_exec['planeupdatefaa'] = time();
1256
-	    $last_exec[$id]['last'] = time();
1254
+		}
1255
+		//$last_exec['planeupdatefaa'] = time();
1256
+		$last_exec[$id]['last'] = time();
1257 1257
 	} elseif ($value['format'] === 'planefinderclient' && 
1258
-	    (
1258
+		(
1259 1259
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1260 1260
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1261
-	    )
1261
+		)
1262 1262
 	) {
1263
-	    $buffer = $Common->getData($value['host']);
1264
-	    $all_data = json_decode($buffer,true);
1265
-	    if (isset($all_data['aircraft'])) {
1263
+		$buffer = $Common->getData($value['host']);
1264
+		$all_data = json_decode($buffer,true);
1265
+		if (isset($all_data['aircraft'])) {
1266 1266
 		$reset = 0;
1267 1267
 		foreach ($all_data['aircraft'] as $key => $line) {
1268
-		    $data = array();
1269
-		    $data['hex'] = $key; // hex
1270
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1271
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1272
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1273
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1274
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1275
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1276
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1277
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1278
-		    //$data['emergency'] = ''; // emergency
1279
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1280
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1281
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1282
-		    $data['format_source'] = 'planefinderclient';
1283
-		    $data['id_source'] = $id_source;
1284
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1285
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1286
-		    $SI->add($data);
1287
-		    unset($data);
1268
+			$data = array();
1269
+			$data['hex'] = $key; // hex
1270
+			if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1271
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1272
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1273
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1274
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1275
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1276
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1277
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1278
+			//$data['emergency'] = ''; // emergency
1279
+			if (isset($line['reg'])) $data['registration'] = $line['reg'];
1280
+			if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1281
+			$data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1282
+			$data['format_source'] = 'planefinderclient';
1283
+			$data['id_source'] = $id_source;
1284
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1285
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1286
+			$SI->add($data);
1287
+			unset($data);
1288 1288
 		}
1289
-	    }
1290
-	    $last_exec[$id]['last'] = time();
1289
+		}
1290
+		$last_exec[$id]['last'] = time();
1291 1291
 	//} elseif ($value === 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1292 1292
 	} elseif ($value['format'] === 'fr24json' && 
1293
-	    (
1293
+		(
1294 1294
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1295 1295
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1296
-	    )
1296
+		)
1297 1297
 	) {
1298
-	    //$buffer = $Common->getData($hosts[$id]);
1299
-	    $buffer = $Common->getData($value['host']);
1300
-	    $all_data = json_decode($buffer,true);
1301
-	    if (!empty($all_data)) $reset = 0;
1302
-	    foreach ($all_data as $key => $line) {
1298
+		//$buffer = $Common->getData($hosts[$id]);
1299
+		$buffer = $Common->getData($value['host']);
1300
+		$all_data = json_decode($buffer,true);
1301
+		if (!empty($all_data)) $reset = 0;
1302
+		foreach ($all_data as $key => $line) {
1303 1303
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1304
-		    $data = array();
1305
-		    $data['hex'] = $line[0];
1306
-		    $data['ident'] = $line[16]; //$line[13]
1307
-	    	    $data['altitude'] = $line[4]; // altitude
1308
-	    	    $data['speed'] = $line[5]; // speed
1309
-	    	    $data['heading'] = $line[3]; // heading
1310
-	    	    $data['latitude'] = $line[1]; // lat
1311
-	    	    $data['longitude'] = $line[2]; // long
1312
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1313
-	    	    $data['squawk'] = $line[6]; // squawk
1314
-	    	    $data['aircraft_icao'] = $line[8];
1315
-	    	    $data['registration'] = $line[9];
1316
-		    $data['departure_airport_iata'] = $line[11];
1317
-		    $data['arrival_airport_iata'] = $line[12];
1318
-	    	    $data['emergency'] = ''; // emergency
1319
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1320
-	    	    $data['format_source'] = 'fr24json';
1321
-    		    $data['id_source'] = $id_source;
1322
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1323
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1324
-		    $SI->add($data);
1325
-		    unset($data);
1304
+			$data = array();
1305
+			$data['hex'] = $line[0];
1306
+			$data['ident'] = $line[16]; //$line[13]
1307
+				$data['altitude'] = $line[4]; // altitude
1308
+				$data['speed'] = $line[5]; // speed
1309
+				$data['heading'] = $line[3]; // heading
1310
+				$data['latitude'] = $line[1]; // lat
1311
+				$data['longitude'] = $line[2]; // long
1312
+				$data['verticalrate'] = $line[15]; // verticale rate
1313
+				$data['squawk'] = $line[6]; // squawk
1314
+				$data['aircraft_icao'] = $line[8];
1315
+				$data['registration'] = $line[9];
1316
+			$data['departure_airport_iata'] = $line[11];
1317
+			$data['arrival_airport_iata'] = $line[12];
1318
+				$data['emergency'] = ''; // emergency
1319
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1320
+				$data['format_source'] = 'fr24json';
1321
+				$data['id_source'] = $id_source;
1322
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1323
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1324
+			$SI->add($data);
1325
+			unset($data);
1326 1326
 		}
1327
-	    }
1328
-	    //$last_exec['fr24json'] = time();
1329
-	    $last_exec[$id]['last'] = time();
1327
+		}
1328
+		//$last_exec['fr24json'] = time();
1329
+		$last_exec[$id]['last'] = time();
1330 1330
 	//} elseif ($value === 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1331 1331
 	} elseif ($value['format'] === 'radarvirtueljson' && 
1332
-	    (
1332
+		(
1333 1333
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1334 1334
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1335
-	    )
1335
+		)
1336 1336
 	) {
1337
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1338
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1339
-	    //echo $buffer;
1340
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1341
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1342
-	    $all_data = json_decode($buffer,true);
1343
-	    if (json_last_error() != JSON_ERROR_NONE) {
1337
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1338
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1339
+		//echo $buffer;
1340
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1341
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1342
+		$all_data = json_decode($buffer,true);
1343
+		if (json_last_error() != JSON_ERROR_NONE) {
1344 1344
 		die(json_last_error_msg());
1345
-	    }
1346
-	    if (isset($all_data['mrkrs'])) {
1345
+		}
1346
+		if (isset($all_data['mrkrs'])) {
1347 1347
 		$reset = 0;
1348 1348
 		foreach ($all_data['mrkrs'] as $key => $line) {
1349
-		    if (isset($line['inf'])) {
1349
+			if (isset($line['inf'])) {
1350 1350
 			$data = array();
1351 1351
 			$data['hex'] = $line['inf']['ia'];
1352 1352
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1353
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1354
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1355
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1356
-	    		$data['latitude'] = $line['pt'][0]; // lat
1357
-	    		$data['longitude'] = $line['pt'][1]; // long
1358
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1359
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1360
-	    		//$data['aircraft_icao'] = $line[8];
1361
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1353
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1354
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1355
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1356
+				$data['latitude'] = $line['pt'][0]; // lat
1357
+				$data['longitude'] = $line['pt'][1]; // long
1358
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1359
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1360
+				//$data['aircraft_icao'] = $line[8];
1361
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1362 1362
 			//$data['departure_airport_iata'] = $line[11];
1363 1363
 			//$data['arrival_airport_iata'] = $line[12];
1364
-	    		//$data['emergency'] = ''; // emergency
1364
+				//$data['emergency'] = ''; // emergency
1365 1365
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1366
-	    		$data['format_source'] = 'radarvirtueljson';
1367
-    			$data['id_source'] = $id_source;
1366
+				$data['format_source'] = 'radarvirtueljson';
1367
+				$data['id_source'] = $id_source;
1368 1368
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1369 1369
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1370 1370
 			$SI->add($data);
1371 1371
 			unset($data);
1372
-		    }
1372
+			}
1373 1373
 		}
1374
-	    }
1375
-	    //$last_exec['radarvirtueljson'] = time();
1376
-	    $last_exec[$id]['last'] = time();
1374
+		}
1375
+		//$last_exec['radarvirtueljson'] = time();
1376
+		$last_exec[$id]['last'] = time();
1377 1377
 	//} elseif ($value === 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1378 1378
 	} elseif ($value['format'] === 'pirepsjson' && 
1379
-	    (
1379
+		(
1380 1380
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1381 1381
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1382
-	    )
1382
+		)
1383 1383
 	) {
1384
-	    //$buffer = $Common->getData($hosts[$id]);
1385
-	    $buffer = $Common->getData($value['host'].'?'.time());
1386
-	    $all_data = json_decode(utf8_encode($buffer),true);
1384
+		//$buffer = $Common->getData($hosts[$id]);
1385
+		$buffer = $Common->getData($value['host'].'?'.time());
1386
+		$all_data = json_decode(utf8_encode($buffer),true);
1387 1387
 	    
1388
-	    if (isset($all_data['pireps'])) {
1388
+		if (isset($all_data['pireps'])) {
1389 1389
 		$reset = 0;
1390
-	        foreach ($all_data['pireps'] as $line) {
1391
-		    $data = array();
1392
-		    $data['id'] = $line['id'];
1393
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1394
-		    $data['ident'] = $line['callsign']; // ident
1395
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1396
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1397
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1398
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1399
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1400
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1401
-		    $data['latitude'] = $line['lat']; // lat
1402
-		    $data['longitude'] = $line['lon']; // long
1403
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1404
-		    //$data['squawk'] = $line['squawk']; // squawk
1405
-		    //$data['emergency'] = ''; // emergency
1406
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1407
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1408
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1409
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1410
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1411
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1412
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1413
-		    else $data['info'] = '';
1414
-		    $data['format_source'] = 'pireps';
1415
-    		    $data['id_source'] = $id_source;
1416
-		    $data['datetime'] = date('Y-m-d H:i:s');
1417
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1418
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1419
-		    if ($line['icon'] === 'plane') {
1390
+			foreach ($all_data['pireps'] as $line) {
1391
+			$data = array();
1392
+			$data['id'] = $line['id'];
1393
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1394
+			$data['ident'] = $line['callsign']; // ident
1395
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1396
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1397
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1398
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1399
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1400
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1401
+			$data['latitude'] = $line['lat']; // lat
1402
+			$data['longitude'] = $line['lon']; // long
1403
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1404
+			//$data['squawk'] = $line['squawk']; // squawk
1405
+			//$data['emergency'] = ''; // emergency
1406
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1407
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1408
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1409
+			//$data['arrival_airport_time'] = $line['arrtime'];
1410
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1411
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1412
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1413
+			else $data['info'] = '';
1414
+			$data['format_source'] = 'pireps';
1415
+				$data['id_source'] = $id_source;
1416
+			$data['datetime'] = date('Y-m-d H:i:s');
1417
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1418
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1419
+			if ($line['icon'] === 'plane') {
1420 1420
 			$SI->add($data);
1421
-		    //    print_r($data);
1422
-    		    } elseif ($line['icon'] === 'ct') {
1421
+			//    print_r($data);
1422
+				} elseif ($line['icon'] === 'ct') {
1423 1423
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1424 1424
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1425 1425
 			$typec = substr($data['ident'],-3);
@@ -1434,210 +1434,210 @@  discard block
 block discarded – undo
1434 1434
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1435 1435
 			else $data['type'] = 'Observer';
1436 1436
 			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']);
1437
-		    }
1438
-		    unset($data);
1437
+			}
1438
+			unset($data);
1439 1439
 		}
1440
-	    }
1441
-	    //$last_exec['pirepsjson'] = time();
1442
-	    $last_exec[$id]['last'] = time();
1440
+		}
1441
+		//$last_exec['pirepsjson'] = time();
1442
+		$last_exec[$id]['last'] = time();
1443 1443
 	//} elseif ($value === 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1444 1444
 	} elseif ($value['format'] === 'phpvmacars' && 
1445
-	    (
1445
+		(
1446 1446
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1447 1447
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1448
-	    )
1448
+		)
1449 1449
 	) {
1450
-	    //$buffer = $Common->getData($hosts[$id]);
1451
-	    if ($globalDebug) echo 'Get Data...'."\n";
1452
-	    $buffer = $Common->getData($value['host']);
1453
-	    $all_data = json_decode($buffer,true);
1454
-	    if ($buffer != '' && is_array($all_data)) {
1450
+		//$buffer = $Common->getData($hosts[$id]);
1451
+		if ($globalDebug) echo 'Get Data...'."\n";
1452
+		$buffer = $Common->getData($value['host']);
1453
+		$all_data = json_decode($buffer,true);
1454
+		if ($buffer != '' && is_array($all_data)) {
1455 1455
 		$reset = 0;
1456 1456
 		foreach ($all_data as $line) {
1457
-	    	    $data = array();
1458
-	    	    //$data['id'] = $line['id']; // id not usable
1459
-	    	    if (isset($line['pilotid']) && isset($line['registration'])) $data['id'] = $line['pilotid'].$line['flightnum'].trim($line['registration']);
1460
-	    	    elseif (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1461
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1462
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1463
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1464
-	    	    $data['ident'] = $line['flightnum']; // ident
1465
-	    	    $data['altitude'] = $line['alt']; // altitude
1466
-	    	    $data['speed'] = $line['gs']; // speed
1467
-	    	    $data['heading'] = $line['heading']; // heading
1468
-	    	    $data['latitude'] = $line['lat']; // lat
1469
-	    	    $data['longitude'] = $line['lng']; // long
1470
-	    	    $data['verticalrate'] = ''; // verticale rate
1471
-	    	    $data['squawk'] = ''; // squawk
1472
-	    	    $data['emergency'] = ''; // emergency
1473
-	    	    //$data['datetime'] = $line['lastupdate'];
1474
-	    	    //$data['last_update'] = $line['lastupdate'];
1475
-	    	    if (isset($value['timezone'])) {
1476
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1477
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1478
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1479
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1480
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1481
-	    	    $data['departure_airport_time'] = $line['deptime'];
1482
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1483
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1484
-    		    if (isset($line['registration'])) {
1485
-    			$data['registration'] = trim($line['registration']);
1486
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1487
-    		    } else $data['registration'] = $line['aircraft'];
1488
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1489
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1490
-		    if (isset($line['aircraftname'])) {
1457
+				$data = array();
1458
+				//$data['id'] = $line['id']; // id not usable
1459
+				if (isset($line['pilotid']) && isset($line['registration'])) $data['id'] = $line['pilotid'].$line['flightnum'].trim($line['registration']);
1460
+				elseif (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1461
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1462
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1463
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1464
+				$data['ident'] = $line['flightnum']; // ident
1465
+				$data['altitude'] = $line['alt']; // altitude
1466
+				$data['speed'] = $line['gs']; // speed
1467
+				$data['heading'] = $line['heading']; // heading
1468
+				$data['latitude'] = $line['lat']; // lat
1469
+				$data['longitude'] = $line['lng']; // long
1470
+				$data['verticalrate'] = ''; // verticale rate
1471
+				$data['squawk'] = ''; // squawk
1472
+				$data['emergency'] = ''; // emergency
1473
+				//$data['datetime'] = $line['lastupdate'];
1474
+				//$data['last_update'] = $line['lastupdate'];
1475
+				if (isset($value['timezone'])) {
1476
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1477
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1478
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1479
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1480
+				$data['departure_airport_icao'] = $line['depicao'];
1481
+				$data['departure_airport_time'] = $line['deptime'];
1482
+				$data['arrival_airport_icao'] = $line['arricao'];
1483
+				$data['arrival_airport_time'] = $line['arrtime'];
1484
+				if (isset($line['registration'])) {
1485
+				$data['registration'] = trim($line['registration']);
1486
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1487
+				} else $data['registration'] = $line['aircraft'];
1488
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1489
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1490
+			if (isset($line['aircraftname'])) {
1491 1491
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1492 1492
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1493
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1494
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1495
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1496
-	    		else {
1497
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1498
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1499
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1500
-	    		}
1501
-	    	    }
1502
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1503
-    		    $data['id_source'] = $id_source;
1504
-	    	    $data['format_source'] = 'phpvmacars';
1505
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1506
-		    $SI->add($data);
1507
-		    unset($data);
1493
+				$aircraft_data = explode('-',$line['aircraftname']);
1494
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1495
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1496
+				else {
1497
+					$aircraft_data = explode(' ',$line['aircraftname']);
1498
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1499
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1500
+				}
1501
+				}
1502
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1503
+				$data['id_source'] = $id_source;
1504
+				$data['format_source'] = 'phpvmacars';
1505
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1506
+			$SI->add($data);
1507
+			unset($data);
1508 1508
 		}
1509 1509
 		if ($globalDebug) echo 'No more data...'."\n";
1510 1510
 		unset($buffer);
1511 1511
 		unset($all_data);
1512
-	    }
1513
-	    //$last_exec['phpvmacars'] = time();
1514
-	    $last_exec[$id]['last'] = time();
1512
+		}
1513
+		//$last_exec['phpvmacars'] = time();
1514
+		$last_exec[$id]['last'] = time();
1515 1515
 	} elseif ($value['format'] === 'vaos' && 
1516
-	    (
1516
+		(
1517 1517
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1518 1518
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1519
-	    )
1519
+		)
1520 1520
 	) {
1521
-	    //$buffer = $Common->getData($hosts[$id]);
1522
-	    if ($globalDebug) echo 'Get Data...'."\n";
1523
-	    $buffer = $Common->getData($value['host']);
1524
-	    $all_data = json_decode($buffer,true);
1525
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1521
+		//$buffer = $Common->getData($hosts[$id]);
1522
+		if ($globalDebug) echo 'Get Data...'."\n";
1523
+		$buffer = $Common->getData($value['host']);
1524
+		$all_data = json_decode($buffer,true);
1525
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1526 1526
 		$reset = 0;
1527 1527
 		foreach ($all_data['ACARSData'] as $line) {
1528
-		    //print_r($line);
1529
-	    	    $data = array();
1530
-	    	    //$data['id'] = $line['id']; // id not usable
1531
-	    	    $data['id'] = $line['id'];
1532
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1533
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1534
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1535
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1536
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1537
-	    	    $data['altitude'] = $line['altitude']; // altitude
1538
-	    	    $data['speed'] = $line['groundspeed']; // speed
1539
-	    	    $data['heading'] = $line['heading']; // heading
1540
-	    	    $data['latitude'] = $line['lat']; // lat
1541
-	    	    $data['longitude'] = $line['lon']; // long
1542
-	    	    //$data['verticalrate'] = ''; // verticale rate
1543
-	    	    //$data['squawk'] = ''; // squawk
1544
-	    	    //$data['emergency'] = ''; // emergency
1545
-	    	    if (isset($value['timezone'])) {
1546
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1547
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1548
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1549
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1528
+			//print_r($line);
1529
+				$data = array();
1530
+				//$data['id'] = $line['id']; // id not usable
1531
+				$data['id'] = $line['id'];
1532
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1533
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1534
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1535
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1536
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1537
+				$data['altitude'] = $line['altitude']; // altitude
1538
+				$data['speed'] = $line['groundspeed']; // speed
1539
+				$data['heading'] = $line['heading']; // heading
1540
+				$data['latitude'] = $line['lat']; // lat
1541
+				$data['longitude'] = $line['lon']; // long
1542
+				//$data['verticalrate'] = ''; // verticale rate
1543
+				//$data['squawk'] = ''; // squawk
1544
+				//$data['emergency'] = ''; // emergency
1545
+				if (isset($value['timezone'])) {
1546
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1547
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1548
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1549
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1550 1550
 	    	    
1551
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1552
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1553
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1554
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1555
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1551
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1552
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1553
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1554
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1555
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1556 1556
 
1557
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1558
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1559
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1557
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1558
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1559
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1560 1560
 
1561
-    		    $data['id_source'] = $id_source;
1562
-	    	    $data['format_source'] = 'vaos';
1563
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1564
-		    $SI->add($data);
1565
-		    unset($data);
1561
+				$data['id_source'] = $id_source;
1562
+				$data['format_source'] = 'vaos';
1563
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1564
+			$SI->add($data);
1565
+			unset($data);
1566 1566
 		}
1567 1567
 		if ($globalDebug) echo 'No more data...'."\n";
1568 1568
 		unset($buffer);
1569 1569
 		unset($all_data);
1570
-	    }
1571
-	    //$last_exec['phpvmacars'] = time();
1572
-	    $last_exec[$id]['last'] = time();
1570
+		}
1571
+		//$last_exec['phpvmacars'] = time();
1572
+		$last_exec[$id]['last'] = time();
1573 1573
 	} elseif ($value['format'] === 'vam' && 
1574
-	    (
1574
+		(
1575 1575
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1576 1576
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1577
-	    )
1577
+		)
1578 1578
 	) {
1579
-	    //$buffer = $Common->getData($hosts[$id]);
1580
-	    if ($globalDebug) echo 'Get Data...'."\n";
1581
-	    $buffer = $Common->getData($value['host']);
1582
-	    $all_data = json_decode($buffer,true);
1583
-	    if ($buffer != '' && is_array($all_data)) {
1579
+		//$buffer = $Common->getData($hosts[$id]);
1580
+		if ($globalDebug) echo 'Get Data...'."\n";
1581
+		$buffer = $Common->getData($value['host']);
1582
+		$all_data = json_decode($buffer,true);
1583
+		if ($buffer != '' && is_array($all_data)) {
1584 1584
 		$reset = 0;
1585 1585
 		foreach ($all_data as $line) {
1586
-	    	    $data = array();
1587
-	    	    //$data['id'] = $line['id']; // id not usable
1588
-	    	    $data['id'] = trim($line['flight_id']);
1589
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1590
-	    	    $data['pilot_name'] = $line['pilot_name'];
1591
-	    	    $data['pilot_id'] = $line['pilot_id'];
1592
-	    	    $data['ident'] = trim($line['callsign']); // ident
1593
-	    	    $data['altitude'] = $line['altitude']; // altitude
1594
-	    	    $data['speed'] = $line['gs']; // speed
1595
-	    	    $data['heading'] = $line['heading']; // heading
1596
-	    	    $data['latitude'] = $line['latitude']; // lat
1597
-	    	    $data['longitude'] = $line['longitude']; // long
1598
-	    	    $data['verticalrate'] = ''; // verticale rate
1599
-	    	    $data['squawk'] = ''; // squawk
1600
-	    	    $data['emergency'] = ''; // emergency
1601
-	    	    //$data['datetime'] = $line['lastupdate'];
1602
-	    	    $data['last_update'] = $line['last_update'];
1603
-		    $data['datetime'] = date('Y-m-d H:i:s');
1604
-	    	    $data['departure_airport_icao'] = $line['departure'];
1605
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1606
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1607
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1608
-    		    //$data['registration'] = $line['aircraft'];
1609
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1610
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1611
-    		    $data['id_source'] = $id_source;
1612
-	    	    $data['format_source'] = 'vam';
1613
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1614
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1615
-		    $SI->add($data);
1616
-		    unset($data);
1586
+				$data = array();
1587
+				//$data['id'] = $line['id']; // id not usable
1588
+				$data['id'] = trim($line['flight_id']);
1589
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1590
+				$data['pilot_name'] = $line['pilot_name'];
1591
+				$data['pilot_id'] = $line['pilot_id'];
1592
+				$data['ident'] = trim($line['callsign']); // ident
1593
+				$data['altitude'] = $line['altitude']; // altitude
1594
+				$data['speed'] = $line['gs']; // speed
1595
+				$data['heading'] = $line['heading']; // heading
1596
+				$data['latitude'] = $line['latitude']; // lat
1597
+				$data['longitude'] = $line['longitude']; // long
1598
+				$data['verticalrate'] = ''; // verticale rate
1599
+				$data['squawk'] = ''; // squawk
1600
+				$data['emergency'] = ''; // emergency
1601
+				//$data['datetime'] = $line['lastupdate'];
1602
+				$data['last_update'] = $line['last_update'];
1603
+			$data['datetime'] = date('Y-m-d H:i:s');
1604
+				$data['departure_airport_icao'] = $line['departure'];
1605
+				//$data['departure_airport_time'] = $line['departure_time'];
1606
+				$data['arrival_airport_icao'] = $line['arrival'];
1607
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1608
+				//$data['registration'] = $line['aircraft'];
1609
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1610
+				$data['aircraft_icao'] = $line['plane_type'];
1611
+				$data['id_source'] = $id_source;
1612
+				$data['format_source'] = 'vam';
1613
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1614
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1615
+			$SI->add($data);
1616
+			unset($data);
1617 1617
 		}
1618 1618
 		if ($globalDebug) echo 'No more data...'."\n";
1619 1619
 		unset($buffer);
1620 1620
 		unset($all_data);
1621
-	    }
1622
-	    //$last_exec['phpvmacars'] = time();
1623
-	    $last_exec[$id]['last'] = time();
1621
+		}
1622
+		//$last_exec['phpvmacars'] = time();
1623
+		$last_exec[$id]['last'] = time();
1624 1624
 	} elseif ($value['format'] === 'blitzortung' && 
1625
-	    (
1625
+		(
1626 1626
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1627 1627
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1628
-	    )
1628
+		)
1629 1629
 	) {
1630
-	    //$buffer = $Common->getData($hosts[$id]);
1631
-	    if ($globalDebug) echo 'Get Data...'."\n";
1632
-	    $buffer = $Common->getData($value['host']);
1633
-	    $all_data = json_decode($buffer,true);
1634
-	    if ($buffer != '') {
1630
+		//$buffer = $Common->getData($hosts[$id]);
1631
+		if ($globalDebug) echo 'Get Data...'."\n";
1632
+		$buffer = $Common->getData($value['host']);
1633
+		$all_data = json_decode($buffer,true);
1634
+		if ($buffer != '') {
1635 1635
 		$Source->deleteLocationBySource('blitzortung');
1636 1636
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1637 1637
 		$buffer = explode('\n',$buffer);
1638 1638
 		foreach ($buffer as $buffer_line) {
1639
-		    $line = json_decode($buffer_line,true);
1640
-		    if (isset($line['time'])) {
1639
+			$line = json_decode($buffer_line,true);
1640
+			if (isset($line['time'])) {
1641 1641
 			$data = array();
1642 1642
 			$data['altitude'] = $line['alt']; // altitude
1643 1643
 			$data['latitude'] = $line['lat']; // lat
@@ -1649,92 +1649,92 @@  discard block
 block discarded – undo
1649 1649
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1650 1650
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1651 1651
 			unset($data);
1652
-		    }
1652
+			}
1653 1653
 		}
1654 1654
 		if ($globalDebug) echo 'No more data...'."\n";
1655 1655
 		unset($buffer);
1656
-	    }
1657
-	    $last_exec[$id]['last'] = time();
1656
+		}
1657
+		$last_exec[$id]['last'] = time();
1658 1658
 	} elseif ($value['format'] === 'acarsjson') {
1659
-        $arr = $httpfeeds;
1660
-        $w = $e = null;
1661
-        if (isset($arr[$id])) {
1662
-            $nn = stream_select($arr,$w,$e,$timeout);
1663
-            if ($nn > 0) {
1664
-                foreach ($httpfeeds as $feed) {
1665
-                    $buffer = stream_get_line($feed,2000,"\n");
1666
-                    if ($buffer === FALSE) {
1667
-                        connect_all($globalSources);
1668
-                    }
1669
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1670
-                    $buffer = explode('\n',$buffer);
1671
-                    foreach ($buffer as $line) {
1672
-                        if ($line != '') {
1673
-                            $line = json_decode($line, true);
1674
-                            if (!empty($line)) {
1675
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1676
-                                $ACARS->deleteLiveAcarsData();
1677
-                            }
1678
-                        }
1679
-                    }
1680
-                }
1681
-            } else {
1682
-                $format = $value['format'];
1683
-                if (isset($tt[$format])) $tt[$format]++;
1684
-                else $tt[$format] = 0;
1685
-                if ($tt[$format] > 30) {
1686
-                    if ($globalDebug) echo 'Reconnect...'."\n";
1687
-                    sleep(2);
1688
-                    //$sourceeen[] = $value;
1689
-                    //connect_all($sourceeen);
1690
-                    //$sourceeen = array();
1691
-                    connect_all($globalSources);
1692
-                }
1693
-            }
1694
-        }
1659
+		$arr = $httpfeeds;
1660
+		$w = $e = null;
1661
+		if (isset($arr[$id])) {
1662
+			$nn = stream_select($arr,$w,$e,$timeout);
1663
+			if ($nn > 0) {
1664
+				foreach ($httpfeeds as $feed) {
1665
+					$buffer = stream_get_line($feed,2000,"\n");
1666
+					if ($buffer === FALSE) {
1667
+						connect_all($globalSources);
1668
+					}
1669
+					$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1670
+					$buffer = explode('\n',$buffer);
1671
+					foreach ($buffer as $line) {
1672
+						if ($line != '') {
1673
+							$line = json_decode($line, true);
1674
+							if (!empty($line)) {
1675
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1676
+								$ACARS->deleteLiveAcarsData();
1677
+							}
1678
+						}
1679
+					}
1680
+				}
1681
+			} else {
1682
+				$format = $value['format'];
1683
+				if (isset($tt[$format])) $tt[$format]++;
1684
+				else $tt[$format] = 0;
1685
+				if ($tt[$format] > 30) {
1686
+					if ($globalDebug) echo 'Reconnect...'."\n";
1687
+					sleep(2);
1688
+					//$sourceeen[] = $value;
1689
+					//connect_all($sourceeen);
1690
+					//$sourceeen = array();
1691
+					connect_all($globalSources);
1692
+				}
1693
+			}
1694
+		}
1695 1695
 	//} elseif ($value === 'sbs' || $value === 'tsv' || $value === 'raw' || $value === 'aprs' || $value === 'beast') {
1696 1696
 	} 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'] === 'acarsjsonudp' || $value['format'] === 'acarssbs3' || $value['format'] === 'ais' || $value['format'] === 'vrstcp') {
1697
-	    //$last_exec[$id]['last'] = time();
1698
-	    //$read = array( $sockets[$id] );
1699
-	    $read = $sockets;
1700
-	    $write = NULL;
1701
-	    $e = NULL;
1702
-	    $n = socket_select($read, $write, $e, $timeout);
1703
-	    if ($e != NULL) var_dump($e);
1704
-	    if ($n > 0) {
1697
+		//$last_exec[$id]['last'] = time();
1698
+		//$read = array( $sockets[$id] );
1699
+		$read = $sockets;
1700
+		$write = NULL;
1701
+		$e = NULL;
1702
+		$n = socket_select($read, $write, $e, $timeout);
1703
+		if ($e != NULL) var_dump($e);
1704
+		if ($n > 0) {
1705 1705
 		$reset = 0;
1706 1706
 		foreach ($read as $nb => $r) {
1707
-		    //$value = $formats[$nb];
1708
-		    $format = $globalSources[$nb]['format'];
1709
-		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1707
+			//$value = $formats[$nb];
1708
+			$format = $globalSources[$nb]['format'];
1709
+			if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1710 1710
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1711
-		    } elseif ($format === 'vrstcp') {
1711
+			} elseif ($format === 'vrstcp') {
1712 1712
 			$buffer = @socket_read($r, 6000);
1713
-		    } else {
1713
+			} else {
1714 1714
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1715
-		    }
1716
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1717
-		    //echo $buffer."\n";
1718
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1719
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1720
-		    $error = false;
1721
-		    //$SI::del();
1722
-		    if ($buffer !== FALSE) {
1715
+			}
1716
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1717
+			//echo $buffer."\n";
1718
+			// lets play nice and handle signals such as ctrl-c/kill properly
1719
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1720
+			$error = false;
1721
+			//$SI::del();
1722
+			if ($buffer !== FALSE) {
1723 1723
 			if ($format === 'vrstcp') {
1724
-			    $buffer = explode('},{',$buffer);
1724
+				$buffer = explode('},{',$buffer);
1725 1725
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1726
-		    }
1727
-		    // SBS format is CSV format
1728
-		    if ($buffer !== FALSE && $buffer !== '') {
1726
+			}
1727
+			// SBS format is CSV format
1728
+			if ($buffer !== FALSE && $buffer !== '') {
1729 1729
 			$tt[$format] = 0;
1730 1730
 			if ($format === 'acarssbs3') {
1731
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1732
-			    $ACARS->add(trim($buffer));
1733
-			    $ACARS->deleteLiveAcarsData();
1731
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1732
+				$ACARS->add(trim($buffer));
1733
+				$ACARS->deleteLiveAcarsData();
1734 1734
 			} elseif ($format === 'raw') {
1735
-			    // AVR format
1736
-			    $data = $SBS->parse($buffer);
1737
-			    if (is_array($data)) {
1735
+				// AVR format
1736
+				$data = $SBS->parse($buffer);
1737
+				if (is_array($data)) {
1738 1738
 				//if (!empty($data)) print_r($data);
1739 1739
 				$data['datetime'] = date('Y-m-d H:i:s');
1740 1740
 				$data['format_source'] = 'raw';
@@ -1744,39 +1744,39 @@  discard block
 block discarded – undo
1744 1744
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1745 1745
 				$SI->add($data);
1746 1746
 				unset($data);
1747
-			    }
1747
+				}
1748 1748
 			} elseif ($format === 'ais') {
1749
-			    $ais_data = $AIS->parse_line(trim($buffer));
1750
-			    $data = array();
1751
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1752
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1753
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1754
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1755
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1756
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1757
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1758
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1759
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1760
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1761
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1762
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1763
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1764
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1765
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1766
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1749
+				$ais_data = $AIS->parse_line(trim($buffer));
1750
+				$data = array();
1751
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1752
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1753
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1754
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1755
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1756
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1757
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1758
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1759
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1760
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1761
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1762
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1763
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1764
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1765
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1766
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1767 1767
 
1768
-			    if (isset($ais_data['timestamp'])) {
1768
+				if (isset($ais_data['timestamp'])) {
1769 1769
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1770
-			    } else {
1770
+				} else {
1771 1771
 				$data['datetime'] = date('Y-m-d H:i:s');
1772
-			    }
1773
-			    $data['format_source'] = 'aisnmea';
1774
-    			    $data['id_source'] = $id_source;
1775
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1776
-			    unset($data);
1777
-                        } elseif ($format === 'flightgearsp') {
1778
-                    	    //echo $buffer."\n";
1779
-                    	    if (strlen($buffer) > 5) {
1772
+				}
1773
+				$data['format_source'] = 'aisnmea';
1774
+					$data['id_source'] = $id_source;
1775
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1776
+				unset($data);
1777
+						} elseif ($format === 'flightgearsp') {
1778
+							//echo $buffer."\n";
1779
+							if (strlen($buffer) > 5) {
1780 1780
 				$line = explode(',',$buffer);
1781 1781
 				$data = array();
1782 1782
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1793,47 +1793,47 @@  discard block
 block discarded – undo
1793 1793
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1794 1794
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1795 1795
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1796
-			    }
1797
-                        } elseif ($format === 'acars') {
1798
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1799
-			    $ACARS->add(trim($buffer));
1800
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1801
-			    $ACARS->deleteLiveAcarsData();
1796
+				}
1797
+						} elseif ($format === 'acars') {
1798
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1799
+				$ACARS->add(trim($buffer));
1800
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1801
+				$ACARS->deleteLiveAcarsData();
1802 1802
 			} elseif ($format === 'acarsjsonudp') {
1803
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1804
-                            $line = json_decode(trim($buffer), true);
1805
-                            if (!empty($line)) {
1803
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1804
+							$line = json_decode(trim($buffer), true);
1805
+							if (!empty($line)) {
1806 1806
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1807
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1808
-                                $ACARS->deleteLiveAcarsData();
1809
-                            }
1810
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1807
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1808
+								$ACARS->deleteLiveAcarsData();
1809
+							}
1810
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1811 1811
 			} elseif ($format === 'flightgearmp') {
1812
-			    if (substr($buffer,0,1) != '#') {
1812
+				if (substr($buffer,0,1) != '#') {
1813 1813
 				$data = array();
1814 1814
 				//echo $buffer."\n";
1815 1815
 				$line = explode(' ',$buffer);
1816 1816
 				if (count($line) === 11) {
1817
-				    $userserver = explode('@',$line[0]);
1818
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1819
-				    $data['ident'] = $userserver[0];
1820
-				    $data['registration'] = $userserver[0];
1821
-				    $data['latitude'] = $line[4];
1822
-				    $data['longitude'] = $line[5];
1823
-				    $data['altitude'] = $line[6];
1824
-				    $data['datetime'] = date('Y-m-d H:i:s');
1825
-				    $aircraft_type = $line[10];
1826
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1827
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1828
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1829
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1817
+					$userserver = explode('@',$line[0]);
1818
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1819
+					$data['ident'] = $userserver[0];
1820
+					$data['registration'] = $userserver[0];
1821
+					$data['latitude'] = $line[4];
1822
+					$data['longitude'] = $line[5];
1823
+					$data['altitude'] = $line[6];
1824
+					$data['datetime'] = date('Y-m-d H:i:s');
1825
+					$aircraft_type = $line[10];
1826
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1827
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1828
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1829
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1830
+				}
1830 1831
 				}
1831
-			    }
1832 1832
 			} elseif ($format === 'beast') {
1833
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1834
-			    die;
1833
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1834
+				die;
1835 1835
 			} elseif ($format === 'vrstcp') {
1836
-			    foreach($buffer as $all_data) {
1836
+				foreach($buffer as $all_data) {
1837 1837
 				$line = json_decode('{'.$all_data.'}',true);
1838 1838
 				$data = array();
1839 1839
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1853,158 +1853,158 @@  discard block
 block discarded – undo
1853 1853
 				*/
1854 1854
 				$data['datetime'] = date('Y-m-d H:i:s');
1855 1855
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1856
-		    		$data['format_source'] = 'vrstcp';
1856
+					$data['format_source'] = 'vrstcp';
1857 1857
 				$data['id_source'] = $id_source;
1858 1858
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1859 1859
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1860 1860
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1861 1861
 				unset($data);
1862
-			    }
1862
+				}
1863 1863
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1864
-			    $line = explode("\t", $buffer);
1865
-			    for($k = 0; $k < count($line); $k=$k+2) {
1864
+				$line = explode("\t", $buffer);
1865
+				for($k = 0; $k < count($line); $k=$k+2) {
1866 1866
 				$key = $line[$k];
1867
-			        $lined[$key] = $line[$k+1];
1868
-			    }
1869
-    			    if (count($lined) > 3) {
1870
-    				$data['hex'] = $lined['hexid'];
1871
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1872
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1873
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1874
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1875
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1876
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1877
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1878
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1879
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1880
-    				$data['id_source'] = $id_source;
1881
-    				$data['format_source'] = 'tsv';
1882
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1883
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1867
+					$lined[$key] = $line[$k+1];
1868
+				}
1869
+					if (count($lined) > 3) {
1870
+					$data['hex'] = $lined['hexid'];
1871
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1872
+					$data['datetime'] = date('Y-m-d H:i:s');;
1873
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1874
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1875
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1876
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1877
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1878
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1879
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1880
+					$data['id_source'] = $id_source;
1881
+					$data['format_source'] = 'tsv';
1882
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1883
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1884 1884
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1885
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1886
-    				unset($lined);
1887
-    				unset($data);
1888
-    			    } else $error = true;
1885
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1886
+					unset($lined);
1887
+					unset($data);
1888
+					} else $error = true;
1889 1889
 			} elseif ($format === 'aprs' && $use_aprs) {
1890
-			    if ($aprs_connect === 0) {
1890
+				if ($aprs_connect === 0) {
1891 1891
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1892 1892
 				$aprs_connect = 1;
1893
-			    }
1893
+				}
1894 1894
 			    
1895
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1895
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1896 1896
 				$aprs_last_tx = time();
1897 1897
 				$data_aprs = "# Keep alive";
1898 1898
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1899
-			    }
1899
+				}
1900 1900
 			    
1901
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1902
-			    //echo 'APRS data : '.$buffer."\n";
1903
-			    $buffer = str_replace('APRS <- ','',$buffer);
1904
-			    $buffer = str_replace('APRS -> ','',$buffer);
1905
-			    //echo $buffer."\n";
1906
-			    date_default_timezone_set('UTC');
1907
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1901
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1902
+				//echo 'APRS data : '.$buffer."\n";
1903
+				$buffer = str_replace('APRS <- ','',$buffer);
1904
+				$buffer = str_replace('APRS -> ','',$buffer);
1905
+				//echo $buffer."\n";
1906
+				date_default_timezone_set('UTC');
1907
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1908 1908
 				$line = $APRS->parse($buffer);
1909 1909
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1910 1910
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1911
-				    $aprs_last_tx = time();
1912
-				    $data = array();
1913
-				    //print_r($line);
1914
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1915
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1916
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1917
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1918
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1919
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1920
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1921
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1922
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1923
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1924
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1925
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1926
-				    $data['latitude'] = $line['latitude'];
1927
-				    $data['longitude'] = $line['longitude'];
1928
-				    //$data['verticalrate'] = $line[16];
1929
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1930
-				    //else $data['speed'] = 0;
1931
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1932
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1933
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1934
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1911
+					$aprs_last_tx = time();
1912
+					$data = array();
1913
+					//print_r($line);
1914
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1915
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1916
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1917
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1918
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1919
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1920
+					if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1921
+					if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1922
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1923
+					else $data['datetime'] = date('Y-m-d H:i:s');
1924
+					//$data['datetime'] = date('Y-m-d H:i:s');
1925
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1926
+					$data['latitude'] = $line['latitude'];
1927
+					$data['longitude'] = $line['longitude'];
1928
+					//$data['verticalrate'] = $line[16];
1929
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1930
+					//else $data['speed'] = 0;
1931
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1932
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1933
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1934
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1935 1935
 				    
1936
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1937
-				    //else echo 'No heading...'."\n";
1938
-				    //else $data['heading'] = 0;
1939
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1940
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1941
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1942
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1943
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1944
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1945
-    				    $data['id_source'] = $id_source;
1946
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1947
-				    else $data['format_source'] = 'aprs';
1948
-				    $data['source_name'] = $line['source'];
1949
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1950
-				    else $data['source_type'] = 'flarm';
1951
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1952
-				    $currentdate = date('Y-m-d H:i:s');
1953
-				    $aprsdate = strtotime($data['datetime']);
1954
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1955
-				    // Accept data if time <= system time + 20s
1956
-				    //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'])))) {
1957
-				    if (
1936
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1937
+					//else echo 'No heading...'."\n";
1938
+					//else $data['heading'] = 0;
1939
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1940
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1941
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1942
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1943
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1944
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1945
+						$data['id_source'] = $id_source;
1946
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1947
+					else $data['format_source'] = 'aprs';
1948
+					$data['source_name'] = $line['source'];
1949
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1950
+					else $data['source_type'] = 'flarm';
1951
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1952
+					$currentdate = date('Y-m-d H:i:s');
1953
+					$aprsdate = strtotime($data['datetime']);
1954
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1955
+					// Accept data if time <= system time + 20s
1956
+					//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'])))) {
1957
+					if (
1958 1958
 					($data['source_type'] === 'modes') || 
1959 1959
 					isset($line['stealth']) && 
1960 1960
 					(!isset($data['hex']) || $data['hex'] != 'FFFFFF') && 
1961 1961
 					 ($line['stealth'] === 0 || $line['stealth'] == '') && 
1962 1962
 					 (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1963 1963
 					$send = $SI->add($data);
1964
-				    } elseif ($data['source_type'] === 'ais') {
1964
+					} elseif ($data['source_type'] === 'ais') {
1965 1965
 					$data['type'] = '';
1966 1966
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1967
-				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1967
+					} elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1968 1968
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1969
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1970
-					    //$line['symbol'] === 'Balloon' ||
1971
-					    $line['symbol'] === 'Glider' || 
1972
-					    $line['symbol'] === 'No. Plane' || 
1973
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1974
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1975
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1976
-					    $send = $SI->add($data);
1977
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1978
-					    $line['symbol'] === 'Yacht (Sail)' || 
1979
-					    $line['symbol'] === 'Ship (Power Boat)')) {
1980
-					    $send = $MI->add($data);
1981
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1982
-					    $line['symbol'] === 'Car' || 
1983
-					    $line['symbol'] === 'Ambulance' || 
1984
-					    $line['symbol'] === 'Van' || 
1985
-					    $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1986
-					    $line['symbol'] === 'Motorcycle' || 
1987
-					    $line['symbol'] === 'Tractor' || 
1988
-					    $line['symbol'] === 'Police' || 
1989
-					    $line['symbol'] === 'Bike' || 
1990
-					    $line['symbol'] === 'Jogger' || 
1991
-					    $line['symbol'] === 'Horse' || 
1992
-					    $line['symbol'] === 'Bus' || 
1993
-					    $line['symbol'] === 'Jeep' || 
1994
-					    $line['symbol'] === 'Recreational Vehicle' || 
1995
-					    $line['symbol'] === 'Yacht (Sail)' || 
1996
-					    $line['symbol'] === 'Ship (Power Boat)' || 
1997
-					    $line['symbol'] === 'Firetruck' || 
1998
-					    $line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1999
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
2000
-					    $line['symbol'] === 'SUV' ||
2001
-					    $line['symbol'] === 'Snowmobile' ||
2002
-					    $line['symbol'] === 'Mobile Satellite Station')) {
2003
-				    //} 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') {
1969
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1970
+						//$line['symbol'] === 'Balloon' ||
1971
+						$line['symbol'] === 'Glider' || 
1972
+						$line['symbol'] === 'No. Plane' || 
1973
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1974
+						if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1975
+						if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1976
+						$send = $SI->add($data);
1977
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1978
+						$line['symbol'] === 'Yacht (Sail)' || 
1979
+						$line['symbol'] === 'Ship (Power Boat)')) {
1980
+						$send = $MI->add($data);
1981
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1982
+						$line['symbol'] === 'Car' || 
1983
+						$line['symbol'] === 'Ambulance' || 
1984
+						$line['symbol'] === 'Van' || 
1985
+						$line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1986
+						$line['symbol'] === 'Motorcycle' || 
1987
+						$line['symbol'] === 'Tractor' || 
1988
+						$line['symbol'] === 'Police' || 
1989
+						$line['symbol'] === 'Bike' || 
1990
+						$line['symbol'] === 'Jogger' || 
1991
+						$line['symbol'] === 'Horse' || 
1992
+						$line['symbol'] === 'Bus' || 
1993
+						$line['symbol'] === 'Jeep' || 
1994
+						$line['symbol'] === 'Recreational Vehicle' || 
1995
+						$line['symbol'] === 'Yacht (Sail)' || 
1996
+						$line['symbol'] === 'Ship (Power Boat)' || 
1997
+						$line['symbol'] === 'Firetruck' || 
1998
+						$line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1999
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
2000
+						$line['symbol'] === 'SUV' ||
2001
+						$line['symbol'] === 'Snowmobile' ||
2002
+						$line['symbol'] === 'Mobile Satellite Station')) {
2003
+					//} 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') {
2004 2004
 				//    } 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') {
2005 2005
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
2006 2006
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2007
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2007
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2008 2008
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2009 2009
 					$Source->deleteOldLocationByType('gs');
2010 2010
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
 					} else {
2013 2013
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2014 2014
 					}
2015
-				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2015
+					} elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2016 2016
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2017 2017
 					if ($globalDebug) echo '# Weather Station added'."\n";
2018 2018
 					$Source->deleteOldLocationByType('wx');
@@ -2022,7 +2022,7 @@  discard block
 block discarded – undo
2022 2022
 					} else {
2023 2023
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2024 2024
 					}
2025
-				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2025
+					} elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2026 2026
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2027 2027
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2028 2028
 					$Source->deleteOldLocationByType('lightning');
@@ -2031,11 +2031,11 @@  discard block
 block discarded – undo
2031 2031
 					} else {
2032 2032
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2033 2033
 					}
2034
-				    } elseif ($globalDebug) {
2035
-				    	echo '/!\ Not added: '.$buffer."\n";
2036
-				    	print_r($line);
2037
-				    }
2038
-				    unset($data);
2034
+					} elseif ($globalDebug) {
2035
+						echo '/!\ Not added: '.$buffer."\n";
2036
+						print_r($line);
2037
+					}
2038
+					unset($data);
2039 2039
 				}
2040 2040
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2041 2041
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -2054,13 +2054,13 @@  discard block
 block discarded – undo
2054 2054
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
2055 2055
 					$globalSources[$nb]['last_weather_clean'] = time();
2056 2056
 				}
2057
-			    }
2057
+				}
2058 2058
 			} else {
2059
-			    $line = explode(',', $buffer);
2060
-			    //print_r($line);
2061
-    			    if (count($line) > 20) {
2062
-    			    	$data['hex'] = $line[4];
2063
-    				/*
2059
+				$line = explode(',', $buffer);
2060
+				//print_r($line);
2061
+					if (count($line) > 20) {
2062
+						$data['hex'] = $line[4];
2063
+					/*
2064 2064
     				$data['datetime'] = $line[6].' '.$line[7];
2065 2065
     					date_default_timezone_set($globalTimezone);
2066 2066
     					$datetime = new DateTime($data['datetime']);
@@ -2068,31 +2068,31 @@  discard block
 block discarded – undo
2068 2068
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
2069 2069
     					date_default_timezone_set('UTC');
2070 2070
     				*/
2071
-    				// Force datetime to current UTC datetime
2072
-    				date_default_timezone_set('UTC');
2073
-    				$data['datetime'] = date('Y-m-d H:i:s');
2074
-    				$data['ident'] = trim($line[10]);
2075
-    				$data['latitude'] = $line[14];
2076
-    				$data['longitude'] = $line[15];
2077
-    				$data['verticalrate'] = $line[16];
2078
-    				$data['emergency'] = $line[20];
2079
-    				$data['speed'] = $line[12];
2080
-    				$data['squawk'] = $line[17];
2081
-    				$data['altitude'] = $line[11];
2082
-    				$data['heading'] = $line[13];
2083
-    				$data['ground'] = $line[21];
2084
-    				$data['emergency'] = $line[19];
2085
-    				$data['format_source'] = 'sbs';
2071
+					// Force datetime to current UTC datetime
2072
+					date_default_timezone_set('UTC');
2073
+					$data['datetime'] = date('Y-m-d H:i:s');
2074
+					$data['ident'] = trim($line[10]);
2075
+					$data['latitude'] = $line[14];
2076
+					$data['longitude'] = $line[15];
2077
+					$data['verticalrate'] = $line[16];
2078
+					$data['emergency'] = $line[20];
2079
+					$data['speed'] = $line[12];
2080
+					$data['squawk'] = $line[17];
2081
+					$data['altitude'] = $line[11];
2082
+					$data['heading'] = $line[13];
2083
+					$data['ground'] = $line[21];
2084
+					$data['emergency'] = $line[19];
2085
+					$data['format_source'] = 'sbs';
2086 2086
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2087 2087
 				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2088 2088
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2089 2089
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2090
-    				$data['id_source'] = $id_source;
2091
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2092
-    				else $error = true;
2093
-    				unset($data);
2094
-    			    } else $error = true;
2095
-			    if ($error) {
2090
+					$data['id_source'] = $id_source;
2091
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2092
+					else $error = true;
2093
+					unset($data);
2094
+					} else $error = true;
2095
+				if ($error) {
2096 2096
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2097 2097
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
2098 2098
 				} else {
@@ -2108,13 +2108,13 @@  discard block
 block discarded – undo
2108 2108
 					connect_all($sourceer);
2109 2109
 					$sourceer = array();
2110 2110
 				}
2111
-			    }
2111
+				}
2112 2112
 			}
2113 2113
 			// Sleep for xxx microseconds
2114 2114
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2115
-		    } else {
2115
+			} else {
2116 2116
 			if ($format === 'flightgearmp') {
2117
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2117
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
2118 2118
 				//@socket_close($r);
2119 2119
 				sleep($globalMinFetch);
2120 2120
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2123,9 +2123,9 @@  discard block
 block discarded – undo
2123 2123
 				break;
2124 2124
 				
2125 2125
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2126
-			    if (isset($tt[$format])) $tt[$format]++;
2127
-			    else $tt[$format] = 0;
2128
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
2126
+				if (isset($tt[$format])) $tt[$format]++;
2127
+				else $tt[$format] = 0;
2128
+				if ($tt[$format] > 30 || $buffer === FALSE) {
2129 2129
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2130 2130
 				//@socket_close($r);
2131 2131
 				sleep(2);
@@ -2136,24 +2136,24 @@  discard block
 block discarded – undo
2136 2136
 				//connect_all($globalSources);
2137 2137
 				$tt[$format]=0;
2138 2138
 				break;
2139
-			    } 
2140
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2139
+				} 
2140
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2141
+			}
2141 2142
 			}
2142
-		    }
2143 2143
 		}
2144
-	    } else {
2144
+		} else {
2145 2145
 		$error = socket_strerror(socket_last_error());
2146 2146
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2147 2147
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2148 2148
 			if (isset($globalDebug)) echo "Restarting...\n";
2149 2149
 			// Restart the script if possible
2150 2150
 			if (is_array($sockets)) {
2151
-			    if ($globalDebug) echo "Shutdown all sockets...";
2151
+				if ($globalDebug) echo "Shutdown all sockets...";
2152 2152
 			    
2153
-			    foreach ($sockets as $sock) {
2153
+				foreach ($sockets as $sock) {
2154 2154
 				@socket_shutdown($sock,2);
2155 2155
 				@socket_close($sock);
2156
-			    }
2156
+				}
2157 2157
 			    
2158 2158
 			}
2159 2159
 			if ($globalDebug) echo "Waiting...";
@@ -2166,15 +2166,15 @@  discard block
 block discarded – undo
2166 2166
 			if ($globalDebug) echo "Restart all connections...";
2167 2167
 			connect_all($globalSources);
2168 2168
 		}
2169
-	    }
2169
+		}
2170 2170
 	}
2171 2171
 	if ($globalDaemon === false) {
2172
-	    if ($globalDebug) echo 'Check all...'."\n";
2173
-	    if (isset($SI)) $SI->checkAll();
2174
-	    if (isset($TI)) $TI->checkAll();
2175
-	    if (isset($MI)) $MI->checkAll();
2172
+		if ($globalDebug) echo 'Check all...'."\n";
2173
+		if (isset($SI)) $SI->checkAll();
2174
+		if (isset($TI)) $TI->checkAll();
2175
+		if (isset($MI)) $MI->checkAll();
2176
+	}
2176 2177
 	}
2177
-    }
2178 2178
 }
2179 2179
 
2180 2180
 ?>
Please login to merge, or discard this patch.
Spacing   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 	    die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
62
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
63 63
     }
64 64
 }
65 65
 
66
-$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'));
66
+$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'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70 70
     $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
71
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
72 72
     else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74 74
     $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
76 76
     else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115 115
     if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
116
+    $SI = new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
120 120
     $SI->connect();
121 121
 */
122
-} else $SI=new SpotterImport($Connection->db);
122
+} else $SI = new SpotterImport($Connection->db);
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
     $MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136
-$SBS=new SBS();
136
+$SBS = new SBS();
137 137
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
138
-	$ACARS=new ACARS($Connection->db,true);
139
-	$Source=new Source($Connection->db);
138
+	$ACARS = new ACARS($Connection->db, true);
139
+	$Source = new Source($Connection->db);
140 140
 }
141
-$Common=new Common();
141
+$Common = new Common();
142 142
 date_default_timezone_set('UTC');
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
146
+    pcntl_signal(SIGINT, function() {
147 147
         global $sockets;
148 148
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149 149
         die("Bye!\n");
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
 function connect_all($hosts) {
161 161
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
162
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
163 163
     $reset++;
164 164
     if ($globalDebug) echo 'Connect to all...'."\n";
165 165
     foreach ($hosts as $id => $value) {
@@ -167,33 +167,33 @@  discard block
 block discarded – undo
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
170
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
+            if (preg_match('/deltadb.txt$/i', $host)) {
172 172
         	//$formats[$id] = 'deltadbtxt';
173 173
         	$globalSources[$id]['format'] = 'deltadbtxt';
174 174
         	//$last_exec['deltadbtxt'] = 0;
175 175
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
176
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
177 177
         	//$formats[$id] = 'vatsimtxt';
178 178
         	$globalSources[$id]['format'] = 'vatsimtxt';
179 179
         	//$last_exec['vatsimtxt'] = 0;
180 180
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
181
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
182 182
         	//$formats[$id] = 'aircraftlistjson';
183 183
         	$globalSources[$id]['format'] = 'aircraftlistjson';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
186
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftjson';
188 188
         	$globalSources[$id]['format'] = 'aircraftjson';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
190 190
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
191
+    	    } else if (preg_match('/aircraft$/i', $host)) {
192 192
         	//$formats[$id] = 'planefinderclient';
193 193
         	$globalSources[$id]['format'] = 'planefinderclient';
194 194
         	//$last_exec['aircraftlistjson'] = 0;
195 195
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
196
+    	    } else if (preg_match('/opensky/i', $host)) {
197 197
         	//$formats[$id] = 'aircraftlistjson';
198 198
         	$globalSources[$id]['format'] = 'opensky';
199 199
         	//$last_exec['aircraftlistjson'] = 0;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
213
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
214 214
         	//$formats[$id] = 'planeupdatefaa';
215 215
         	$globalSources[$id]['format'] = 'planeupdatefaa';
216 216
         	//$last_exec['planeupdatefaa'] = 0;
@@ -219,37 +219,37 @@  discard block
 block discarded – undo
219 219
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220 220
         	    exit(0);
221 221
         	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
222
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'phpvmacars';
225 225
         	//$last_exec['phpvmacars'] = 0;
226 226
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
227
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
228 228
         	//$formats[$id] = 'phpvmacars';
229 229
         	$globalSources[$id]['format'] = 'vaos';
230 230
         	//$last_exec['phpvmacars'] = 0;
231 231
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
232
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
233 233
         	//$formats[$id] = 'phpvmacars';
234 234
         	$globalSources[$id]['format'] = 'vam';
235 235
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
236
+            } else if (preg_match('/whazzup/i', $host)) {
237 237
         	//$formats[$id] = 'whazzup';
238 238
         	$globalSources[$id]['format'] = 'whazzup';
239 239
         	//$last_exec['whazzup'] = 0;
240 240
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
241
+            } else if (preg_match('/blitzortung/i', $host)) {
242 242
         	$globalSources[$id]['format'] = 'blitzortung';
243 243
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
244
+            } else if (preg_match('/airwhere/i', $host)) {
245 245
         	$globalSources[$id]['format'] = 'airwhere';
246 246
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
247
+            } else if (preg_match('/recentpireps/i', $host)) {
248 248
         	//$formats[$id] = 'pirepsjson';
249 249
         	$globalSources[$id]['format'] = 'pirepsjson';
250 250
         	//$last_exec['pirepsjson'] = 0;
251 251
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
252
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
253 253
         	//$formats[$id] = 'fr24json';
254 254
         	$globalSources[$id]['format'] = 'fr24json';
255 255
         	//$last_exec['fr24json'] = 0;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259 259
         	    exit(0);
260 260
         	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
261
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
262 262
         	//$formats[$id] = 'fr24json';
263 263
         	$globalSources[$id]['format'] = 'myshiptracking';
264 264
         	//$last_exec['fr24json'] = 0;
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
         	    exit(0);
269 269
         	}
270 270
             //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
271
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272 272
         	//$formats[$id] = 'tsv';
273 273
         	$globalSources[$id]['format'] = 'tsv';
274 274
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275 275
             }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
276
+        } elseif (filter_var($host, FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277 277
     		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
278
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
279 279
     		    if ($idf !== false) {
280 280
     			$httpfeeds[$id] = $idf;
281 281
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
     		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284 284
     		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285 285
     		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
286
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
287
+	    $hostport = explode(':', $host);
288 288
 	    if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
@@ -294,20 +294,20 @@  discard block
 block discarded – undo
294 294
 	    }
295 295
 	    $Common = new Common();
296 296
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
297
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
298 298
     	    } else {
299 299
     		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
300
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
301 301
 	    }
302 302
 	    if ($s) {
303 303
     	        $sockets[$id] = $s;
304 304
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
305
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312 312
     		    } elseif ($port == '10001') {
313 313
         		//$formats[$id] = 'tsv';
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
350 350
 else $timeout = 20;
351 351
 $errno = '';
352
-$errstr='';
352
+$errstr = '';
353 353
 
354 354
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
355 355
 /* Initiate connections to all the hosts simultaneously */
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
361 361
 } else {
362 362
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
@@ -387,16 +387,16 @@  discard block
 block discarded – undo
387 387
 
388 388
 if ($use_aprs) {
389 389
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
390
-	$APRS=new APRS();
390
+	$APRS = new APRS();
391 391
 	$aprs_connect = 0;
392 392
 	$aprs_keep = 120;
393 393
 	$aprs_last_tx = time();
394 394
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
395
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
395
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
396 396
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
397
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
397
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
398 398
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
399
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
399
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
400 400
 	if ($aprs_full) $aprs_filter = '';
401 401
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
402 402
 	else $aprs_pass = '-1';
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
 sleep(1);
411 411
 if ($globalDebug) echo "SCAN MODE \n\n";
412 412
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
413
-$endtime = time()+$globalCronEnd;
413
+$endtime = time() + $globalCronEnd;
414 414
 $i = 1;
415 415
 $tt = array();
416 416
 // Delete all ATC
417 417
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
418
-	$ATC=new ATC($Connection->db);
418
+	$ATC = new ATC($Connection->db);
419 419
 }
420 420
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
421 421
 	$ATC->deleteAll();
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 while ($i > 0) {
426 426
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
428
+    if (!$globalDaemon) $i = $endtime - time();
429 429
     // Delete old ATC
430 430
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441 441
 	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
442
+	    sleep($globalMinFetch - $max + 2);
443 443
 	}
444 444
     }
445 445
 
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
             //$buffer = $Common->getData($hosts[$id]);
495 495
             $buffer = $Common->getData($value['host']);
496 496
             if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
497
+                $all_data = json_decode($buffer, true);
498 498
                 foreach ($all_data as $line) {
499 499
                     $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
500
+                    $data['datetime'] = date('Y-m-d H:i:s', $line['uti']);
501 501
                     $data['hex'] = $line['hex']; // hex
502 502
                     $data['ident'] = $line['fli']; // ident
503 503
                     $data['altitude'] = $line['alt']; // altitude
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 	    )
533 533
 	) {
534 534
 	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
535
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
536 536
 	    date_default_timezone_set('UTC');
537 537
 	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
538
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
539
+	    $buffer = explode('\n', $buffer);
540 540
 	    foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542 542
 		    //echo "'".$line."'\n";
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 		    $ais_data = $AIS->parse_line(trim($line));
545 545
 		    $data = array();
546 546
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
547
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
548 548
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549 549
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550 550
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557 557
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558 558
 		    if (isset($ais_data['timestamp'])) {
559
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
559
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561 561
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562 562
 			    $add = true;
@@ -579,21 +579,21 @@  discard block
 block discarded – undo
579 579
 	    $w = $e = null;
580 580
 	    
581 581
 	    if (isset($arr[$id])) {
582
-		$nn = stream_select($arr,$w,$e,$timeout);
582
+		$nn = stream_select($arr, $w, $e, $timeout);
583 583
 		if ($nn > 0) {
584 584
 		    foreach ($httpfeeds as $feed) {
585
-			$buffer = stream_get_line($feed,2000,"\n");
585
+			$buffer = stream_get_line($feed, 2000, "\n");
586 586
 			if ($buffer === FALSE) {
587 587
 			    connect_all($globalSources);
588 588
 			}
589
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590
-			$buffer = explode('\n',$buffer);
589
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
590
+			$buffer = explode('\n', $buffer);
591 591
 			foreach ($buffer as $line) {
592 592
 			    if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
596
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
596
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
597 597
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
598 598
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
599 599
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -605,9 +605,9 @@  discard block
 block discarded – undo
605 605
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
606 606
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
608
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
611 611
 				} else {
612 612
 				    $data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640 640
 	    )
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
642
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
643 643
 	    if ($buffer != '') {
644 644
 		//echo $buffer;
645
-		$all_data = json_decode($buffer,true);
645
+		$all_data = json_decode($buffer, true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648 648
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 			    $data['ident'] = $line['NAME'];
652 652
 			    $data['mmsi'] = $line['MMSI'];
653 653
 			    if (strlen($data['mmsi']) > 9) {
654
-				$data['mmsi'] = substr($data['mmsi'],-9);
654
+				$data['mmsi'] = substr($data['mmsi'], -9);
655 655
 			    }
656 656
 			    $data['speed'] = $line['SOG'];
657 657
 			    $data['heading'] = $line['COG'];
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 			    //$data['type_id'] = $line['TYPE'];
662 662
 			    $data['imo'] = $line['IMO'];
663 663
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
664
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
665
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
666 666
 			    $data['format_source'] = 'myshiptracking';
667 667
 			    $data['id_source'] = $id_source;
668 668
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680 680
 	    )
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
682
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
683 683
 	    if ($buffer != '') {
684
-		$all_data = json_decode($buffer,true);
684
+		$all_data = json_decode($buffer, true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686 686
 		    foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688 688
 			    $data = array();
689 689
 			    $data['ident'] = $line['shipname'];
690 690
 			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
691
+			    $data['mmsi'] = substr($line['mmsi'], -9);
692 692
 			    $data['speed'] = $line['sog'];
693 693
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694 694
 			    $data['latitude'] = $line['latitude'];
@@ -715,14 +715,14 @@  discard block
 block discarded – undo
715 715
 	) {
716 716
 	    $buffer = $Common->getData($value['host']);
717 717
 	    if ($buffer != '') {
718
-		$all_data = json_decode($buffer,true);
718
+		$all_data = json_decode($buffer, true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720 720
 		    foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
724 724
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
725
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
725
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
726 726
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
727 727
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
728 728
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -749,31 +749,31 @@  discard block
 block discarded – undo
749 749
 	    )
750 750
 	) {
751 751
 	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
752
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
753 753
 	    if ($globalDebug) echo 'done !'."\n";
754 754
 	    // FIXME: Need more work
755 755
 	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
756
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
757
+	    $buffer = explode('\n', $buffer);
758 758
 	    foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760 760
 		    $data = array();
761 761
 		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
762
+		    $data['mmsi'] = (int) substr($line, 0, 9);
763
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
764
+		    $data['status_id'] = substr($line, 21, 2);
765
+		    $data['type_id'] = substr($line, 24, 3);
766
+		    $data['latitude'] = substr($line, 29, 9);
767
+		    $data['longitude'] = substr($line, 41, 9);
768
+		    $data['speed'] = round(substr($line, 51, 5));
769 769
 		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
770
+		    $data['heading'] = round(substr($line, 63, 3));
771 771
 		    //$data['draft'] = substr($line,67,4);
772 772
 		    //$data['length'] = substr($line,72,3);
773 773
 		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
774
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
775 775
 		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
776
+		    $data['arrival_code'] = substr($line, 108, 20);
777 777
 		    //$data['etaDate'] = substr($line,129,5);
778 778
 		    //$data['etaTime'] = substr($line,135,5);
779 779
 		    $data['format_source'] = 'shipplotter';
@@ -796,28 +796,28 @@  discard block
 block discarded – undo
796 796
 		exit(0);
797 797
 	    }
798 798
 	    $sailawayoption = array('key' => $globalSailaway['key']);
799
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
799
+	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption, array('usrnr' => $globalSailaway['usrnr']));
800
+	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption, array('ubtnr' => $globalSailaway['ubtnr']));
801 801
 
802 802
 	    for ($i = 0; $i <= 1; $i++) {
803 803
 		if ($globalDebug) echo '! Download... ';
804
-		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?'.http_build_query($sailawayoption).'&race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2','get','','','','',30);
804
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?'.http_build_query($sailawayoption).'&race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2', 'get', '', '', '', '', 30);
805 805
 		if ($globalDebug) echo 'done'."\n";
806 806
 		if ($buffer != '') {
807
-		    $all_data = json_decode($buffer,true);
807
+		    $all_data = json_decode($buffer, true);
808 808
 		    if (isset($all_data['missions'])) {
809 809
 			foreach ($all_data['missions'] as $mission) {
810 810
 				$mission_user = $mission['usrname'];
811
-				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
812
-				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
811
+				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle']));
812
+				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'], $globalFilter['sailway']['race']))) {
813 813
 					//print_r($mission);
814 814
 					$datar = array();
815 815
 					$datar['id'] = $mission['misnr'];
816 816
 					$datar['desc'] = $mission['misdescr'];
817 817
 					//$datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['usrname'])));
818 818
 					$datar['creator'] = '';
819
-					$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle'])));
820
-					if (isset($mission['misstart'])) $datar['startdate'] = date('Y-m-d H:i:s',strtotime($mission['misstart']));
819
+					$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle'])));
820
+					if (isset($mission['misstart'])) $datar['startdate'] = date('Y-m-d H:i:s', strtotime($mission['misstart']));
821 821
 					else $datar['startdate'] = '1970-01-01 00:00:00';
822 822
 					/*
823 823
 					$markers = array();
@@ -837,9 +837,9 @@  discard block
 block discarded – undo
837 837
 		if ($globalDebug) echo '=== Wait... ===';
838 838
 		sleep(10*60);
839 839
 	    }
840
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
840
+	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption), 'get', '', '', '', '', 30);
841 841
 	    if ($buffer != '') {
842
-		$data = json_decode($buffer,true);
842
+		$data = json_decode($buffer, true);
843 843
 		//print_r($data);
844 844
 		if (isset($data['boats'])) {
845 845
 		    foreach ($data['boats'] as $sail) {
@@ -851,12 +851,12 @@  discard block
 block discarded – undo
851 851
 			$data['longitude'] = $sail['ubtlon'];
852 852
 			$data['type_id'] = 36;
853 853
 			$data['heading'] = $sail['ubtheading'];
854
-			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
854
+			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
855 855
 			$data['captain_name'] = $sail['usrname'];
856
-			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat','32&#39; Offshore Racer');
856
+			$allboats = array('Sailaway Cruiser 38', 'Mini Transat', 'Caribbean Rose', '52&#39; Cruising Cat', '50&#39; Performance Cruiser', 'Nordic Folkboat', '32&#39; Offshore Racer');
857 857
 			$boattype = $sail['ubtbtpnr'];
858
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
859
-			$data['speed'] = round($sail['ubtspeed']*3.6,2);
858
+			if (isset($allboats[$boattype - 1])) $data['type'] = $allboats[$boattype - 1];
859
+			$data['speed'] = round($sail['ubtspeed']*3.6, 2);
860 860
 			$data['format_source'] = 'sailaway';
861 861
 			$data['id_source'] = $id_source;
862 862
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -889,12 +889,12 @@  discard block
 block discarded – undo
889 889
 	    }
890 890
 	    if ($globalDebug) echo '! Download... ';
891 891
 	    $sailawayoption = array('key' => $globalSailaway['key']);
892
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
893
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
894
-	    if (isset($globalSailaway['misnr'])) $sailawayoption = array_merge($sailawayoption,array('misnr' => $globalSailaway['misnr']));
895
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
892
+	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption, array('usrnr' => $globalSailaway['usrnr']));
893
+	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption, array('ubtnr' => $globalSailaway['ubtnr']));
894
+	    if (isset($globalSailaway['misnr'])) $sailawayoption = array_merge($sailawayoption, array('misnr' => $globalSailaway['misnr']));
895
+	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption), 'get', '', '', '', '', 30);
896 896
 	    if ($buffer != '') {
897
-		$data = json_decode($buffer,true);
897
+		$data = json_decode($buffer, true);
898 898
 		//print_r($data);
899 899
 		if (isset($data['boats'])) {
900 900
 		    foreach ($data['boats'] as $sail) {
@@ -906,12 +906,12 @@  discard block
 block discarded – undo
906 906
 			$data['longitude'] = $sail['ubtlon'];
907 907
 			$data['type_id'] = 36;
908 908
 			$data['heading'] = $sail['ubtheading'];
909
-			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
909
+			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
910 910
 			$data['captain_name'] = $sail['usrname'];
911
-			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat','32&#39; Offshore Racer');
911
+			$allboats = array('Sailaway Cruiser 38', 'Mini Transat', 'Caribbean Rose', '52&#39; Cruising Cat', '50&#39; Performance Cruiser', 'Nordic Folkboat', '32&#39; Offshore Racer');
912 912
 			$boattype = $sail['ubtbtpnr'];
913
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
914
-			$data['speed'] = round($sail['ubtspeed']*3.6,2);
913
+			if (isset($allboats[$boattype - 1])) $data['type'] = $allboats[$boattype - 1];
914
+			$data['speed'] = round($sail['ubtspeed']*3.6, 2);
915 915
 			$data['format_source'] = 'sailaway';
916 916
 			$data['id_source'] = $id_source;
917 917
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -939,8 +939,8 @@  discard block
 block discarded – undo
939 939
 	) {
940 940
 	    //$buffer = $Common->getData($hosts[$id]);
941 941
 	    $buffer = $Common->getData($value['host']);
942
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
943
-	    $buffer = explode('\n',$buffer);
942
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
943
+	    $buffer = explode('\n', $buffer);
944 944
 	    $reset = 0;
945 945
 	    foreach ($buffer as $line) {
946 946
     		if ($line != '') {
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
952 952
 			$data['pilot_id'] = $line[1];
953 953
 			$data['pilot_name'] = $line[2];
954
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
954
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
955 955
 			$data['ident'] = $line[0]; // ident
956 956
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
957 957
 			$data['speed'] = $line[8]; // speed
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
968 968
 			//if (isset($line[37])) $data['last_update'] = $line[37];
969 969
 		        $data['departure_airport_icao'] = $line[11];
970
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
970
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
971 971
 		        $data['arrival_airport_icao'] = $line[13];
972 972
 			$data['frequency'] = $line[4];
973 973
 			$data['type'] = $line[18];
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
     			$data['id_source'] = $id_source;
977 977
 	    		//$data['arrival_airport_time'] = ;
978 978
 	    		if ($line[9] != '') {
979
-	    		    $aircraft_data = explode('/',$line[9]);
979
+	    		    $aircraft_data = explode('/', $line[9]);
980 980
 	    		    if (count($aircraft_data) == 2) {
981 981
 				//line[9] may equal to something like 'B738/L' in old FSD server's whazzup.txt file
982 982
 	    			$data['aircraft_icao'] = $aircraft_data[0];
@@ -995,9 +995,9 @@  discard block
 block discarded – undo
995 995
     			if ($line[3] === 'PILOT') $SI->add($data);
996 996
 			elseif ($line[3] === 'ATC') {
997 997
 				//print_r($data);
998
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
999
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
1000
-				$typec = substr($data['ident'],-3);
998
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
999
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1000
+				$typec = substr($data['ident'], -3);
1001 1001
 				if ($typec === 'APP') $data['type'] = 'Approach';
1002 1002
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
1003 1003
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -1009,8 +1009,8 @@  discard block
 block discarded – undo
1009 1009
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
1010 1010
 				if (!isset($data['source_name'])) $data['source_name'] = '';
1011 1011
 				if (isset($ATC)) {
1012
-					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']);
1013
-					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']);
1012
+					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']);
1013
+					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']);
1014 1014
 				}
1015 1015
 			}
1016 1016
     			unset($data);
@@ -1026,24 +1026,24 @@  discard block
 block discarded – undo
1026 1026
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1027 1027
     	    )
1028 1028
     	) {
1029
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1029
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
1030 1030
 	    if ($buffer != '') {
1031 1031
 		$all_data = simplexml_load_string($buffer);
1032
-		foreach($all_data->children() as $childdata) {
1032
+		foreach ($all_data->children() as $childdata) {
1033 1033
 			$data = array();
1034 1034
 			$line = $childdata;
1035 1035
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
1036
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
1037
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
1038
-			$data['latitude'] = (float)$line['pktLatitude'];
1039
-			$data['longitude'] = (float)$line['pktLongitude'];
1040
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
1041
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1042
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
1036
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
1037
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
1038
+			$data['latitude'] = (float) $line['pktLatitude'];
1039
+			$data['longitude'] = (float) $line['pktLongitude'];
1040
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
1041
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
1042
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
1043 1043
 			$data['altitude_relative'] = 'AMSL';
1044
-			$data['pilot_id'] = (int)$line['pktPilotID'];
1044
+			$data['pilot_id'] = (int) $line['pktPilotID'];
1045 1045
 			$data['aircraft_icao'] = 'PARAGLIDER';
1046
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1046
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1047 1047
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1048 1048
 			$data['format_source'] = $value['format'];
1049 1049
 			$SI->add($data);
@@ -1051,22 +1051,22 @@  discard block
 block discarded – undo
1051 1051
 		}
1052 1052
 	    }
1053 1053
 	    $Source->deleteOldLocationByType('gs');
1054
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1054
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
1055 1055
 	    if ($buffer != '') {
1056 1056
 		$all_data = simplexml_load_string($buffer);
1057
-		foreach($all_data->children() as $childdata) {
1057
+		foreach ($all_data->children() as $childdata) {
1058 1058
 			$data = array();
1059 1059
 			$line = $childdata;
1060
-			$data['id'] = (int)$line['gsID'];
1061
-			$data['latitude'] = (float)$line['gsLatitude'];
1062
-			$data['longitude'] = (float)$line['gsLongitude'];
1063
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
1060
+			$data['id'] = (int) $line['gsID'];
1061
+			$data['latitude'] = (float) $line['gsLatitude'];
1062
+			$data['longitude'] = (float) $line['gsLongitude'];
1063
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
1064 1064
 			$data['altitude_relative'] = 'AMSL';
1065
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
1065
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
1066 1066
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
1067
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
1067
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
1068 1068
 			} else {
1069
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
1069
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
1070 1070
 			}
1071 1071
 			unset($data);
1072 1072
 		}
@@ -1084,9 +1084,9 @@  discard block
 block discarded – undo
1084 1084
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1085 1085
 	    )
1086 1086
 	) {
1087
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1087
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
1088 1088
 	    if ($buffer != '') {
1089
-	        $all_data = json_decode($buffer,true);
1089
+	        $all_data = json_decode($buffer, true);
1090 1090
 		if (isset($all_data['acList'])) {
1091 1091
 		    $reset = 0;
1092 1092
 		    foreach ($all_data['acList'] as $line) {
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1103 1103
 			$data['emergency'] = ''; // emergency
1104 1104
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1105
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1105
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1106 1106
 			else $data['datetime'] = date('Y-m-d H:i:s');
1107 1107
 			//$data['datetime'] = date('Y-m-d H:i:s');
1108 1108
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1128 1128
 			$data['squawk'] = $line['squawk']; // squawk
1129 1129
 			$data['emergency'] = ''; // emergency
1130
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1130
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1131 1131
 			else $data['datetime'] = date('Y-m-d H:i:s');
1132 1132
 			$data['format_source'] = 'aircraftlistjson';
1133 1133
 			$data['id_source'] = $id_source;
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
     	    )
1149 1149
     	) {
1150 1150
 	    $buffer = $Common->getData($value['host']);
1151
-	    $all_data = json_decode($buffer,true);
1151
+	    $all_data = json_decode($buffer, true);
1152 1152
 	    if (isset($all_data['planes'])) {
1153 1153
 		$reset = 0;
1154 1154
 		foreach ($all_data['planes'] as $key => $line) {
@@ -1165,12 +1165,12 @@  discard block
 block discarded – undo
1165 1165
 		    $data['emergency'] = ''; // emergency
1166 1166
 		    $data['registration'] = $line[2];
1167 1167
 		    $data['aircraft_icao'] = $line[0];
1168
-		    $deparr = explode('-',$line[1]);
1168
+		    $deparr = explode('-', $line[1]);
1169 1169
 		    if (count($deparr) === 2) {
1170 1170
 			$data['departure_airport_icao'] = $deparr[0];
1171 1171
 			$data['arrival_airport_icao'] = $deparr[1];
1172 1172
 		    }
1173
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1173
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
1174 1174
 	    	    $data['format_source'] = 'planeupdatefaa';
1175 1175
     		    $data['id_source'] = $id_source;
1176 1176
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 	    )
1189 1189
 	) {
1190 1190
 	    $buffer = $Common->getData($value['host']);
1191
-	    $all_data = json_decode($buffer,true);
1191
+	    $all_data = json_decode($buffer, true);
1192 1192
 	    if (isset($all_data['states'])) {
1193 1193
 		$reset = 0;
1194 1194
 		foreach ($all_data['states'] as $key => $line) {
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
 		    //$data['emergency'] = ''; // emergency
1206 1206
 		    //$data['registration'] = $line[2];
1207 1207
 		    //$data['aircraft_icao'] = $line[0];
1208
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1208
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1209 1209
 		    $data['format_source'] = 'opensky';
1210 1210
 		    $data['id_source'] = $id_source;
1211 1211
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1222,8 +1222,8 @@  discard block
 block discarded – undo
1222 1222
 	    )
1223 1223
 	) {
1224 1224
 	    $buffer = $Common->getData($value['host']);
1225
-	    $all_data = json_decode($buffer,true);
1226
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1225
+	    $all_data = json_decode($buffer, true);
1226
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1227 1227
 		$reset = 0;
1228 1228
 		foreach ($all_data['aircraft'] as $key => $line) {
1229 1229
 		    $data = array();
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 	    )
1262 1262
 	) {
1263 1263
 	    $buffer = $Common->getData($value['host']);
1264
-	    $all_data = json_decode($buffer,true);
1264
+	    $all_data = json_decode($buffer, true);
1265 1265
 	    if (isset($all_data['aircraft'])) {
1266 1266
 		$reset = 0;
1267 1267
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
 		    //$data['emergency'] = ''; // emergency
1279 1279
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1280 1280
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1281
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1281
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1282 1282
 		    $data['format_source'] = 'planefinderclient';
1283 1283
 		    $data['id_source'] = $id_source;
1284 1284
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 	) {
1298 1298
 	    //$buffer = $Common->getData($hosts[$id]);
1299 1299
 	    $buffer = $Common->getData($value['host']);
1300
-	    $all_data = json_decode($buffer,true);
1300
+	    $all_data = json_decode($buffer, true);
1301 1301
 	    if (!empty($all_data)) $reset = 0;
1302 1302
 	    foreach ($all_data as $key => $line) {
1303 1303
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1335,11 +1335,11 @@  discard block
 block discarded – undo
1335 1335
 	    )
1336 1336
 	) {
1337 1337
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1338
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1338
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1339 1339
 	    //echo $buffer;
1340
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1341
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1342
-	    $all_data = json_decode($buffer,true);
1340
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1341
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1342
+	    $all_data = json_decode($buffer, true);
1343 1343
 	    if (json_last_error() != JSON_ERROR_NONE) {
1344 1344
 		die(json_last_error_msg());
1345 1345
 	    }
@@ -1362,7 +1362,7 @@  discard block
 block discarded – undo
1362 1362
 			//$data['departure_airport_iata'] = $line[11];
1363 1363
 			//$data['arrival_airport_iata'] = $line[12];
1364 1364
 	    		//$data['emergency'] = ''; // emergency
1365
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1365
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1366 1366
 	    		$data['format_source'] = 'radarvirtueljson';
1367 1367
     			$data['id_source'] = $id_source;
1368 1368
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1383,14 +1383,14 @@  discard block
 block discarded – undo
1383 1383
 	) {
1384 1384
 	    //$buffer = $Common->getData($hosts[$id]);
1385 1385
 	    $buffer = $Common->getData($value['host'].'?'.time());
1386
-	    $all_data = json_decode(utf8_encode($buffer),true);
1386
+	    $all_data = json_decode(utf8_encode($buffer), true);
1387 1387
 	    
1388 1388
 	    if (isset($all_data['pireps'])) {
1389 1389
 		$reset = 0;
1390 1390
 	        foreach ($all_data['pireps'] as $line) {
1391 1391
 		    $data = array();
1392 1392
 		    $data['id'] = $line['id'];
1393
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1393
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1394 1394
 		    $data['ident'] = $line['callsign']; // ident
1395 1395
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1396 1396
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1420,9 +1420,9 @@  discard block
 block discarded – undo
1420 1420
 			$SI->add($data);
1421 1421
 		    //    print_r($data);
1422 1422
     		    } elseif ($line['icon'] === 'ct') {
1423
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1424
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1425
-			$typec = substr($data['ident'],-3);
1423
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1424
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1425
+			$typec = substr($data['ident'], -3);
1426 1426
 			$data['type'] = '';
1427 1427
 			if ($typec === 'APP') $data['type'] = 'Approach';
1428 1428
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1433,7 +1433,7 @@  discard block
 block discarded – undo
1433 1433
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1434 1434
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1435 1435
 			else $data['type'] = 'Observer';
1436
-			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']);
1436
+			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']);
1437 1437
 		    }
1438 1438
 		    unset($data);
1439 1439
 		}
@@ -1450,7 +1450,7 @@  discard block
 block discarded – undo
1450 1450
 	    //$buffer = $Common->getData($hosts[$id]);
1451 1451
 	    if ($globalDebug) echo 'Get Data...'."\n";
1452 1452
 	    $buffer = $Common->getData($value['host']);
1453
-	    $all_data = json_decode($buffer,true);
1453
+	    $all_data = json_decode($buffer, true);
1454 1454
 	    if ($buffer != '' && is_array($all_data)) {
1455 1455
 		$reset = 0;
1456 1456
 		foreach ($all_data as $line) {
@@ -1458,7 +1458,7 @@  discard block
 block discarded – undo
1458 1458
 	    	    //$data['id'] = $line['id']; // id not usable
1459 1459
 	    	    if (isset($line['pilotid']) && isset($line['registration'])) $data['id'] = $line['pilotid'].$line['flightnum'].trim($line['registration']);
1460 1460
 	    	    elseif (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1461
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1461
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1462 1462
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1463 1463
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1464 1464
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1473,7 +1473,7 @@  discard block
 block discarded – undo
1473 1473
 	    	    //$data['datetime'] = $line['lastupdate'];
1474 1474
 	    	    //$data['last_update'] = $line['lastupdate'];
1475 1475
 	    	    if (isset($value['timezone'])) {
1476
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1476
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1477 1477
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1478 1478
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1479 1479
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1489,14 +1489,14 @@  discard block
 block discarded – undo
1489 1489
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1490 1490
 		    if (isset($line['aircraftname'])) {
1491 1491
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1492
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1493
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1492
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1493
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1494 1494
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1495 1495
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1496 1496
 	    		else {
1497
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1498
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1499
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1497
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1498
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1499
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1500 1500
 	    		}
1501 1501
 	    	    }
1502 1502
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1521,7 +1521,7 @@  discard block
 block discarded – undo
1521 1521
 	    //$buffer = $Common->getData($hosts[$id]);
1522 1522
 	    if ($globalDebug) echo 'Get Data...'."\n";
1523 1523
 	    $buffer = $Common->getData($value['host']);
1524
-	    $all_data = json_decode($buffer,true);
1524
+	    $all_data = json_decode($buffer, true);
1525 1525
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1526 1526
 		$reset = 0;
1527 1527
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1533 1533
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1534 1534
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1535
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1535
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1536 1536
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1537 1537
 	    	    $data['altitude'] = $line['altitude']; // altitude
1538 1538
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1543,7 +1543,7 @@  discard block
 block discarded – undo
1543 1543
 	    	    //$data['squawk'] = ''; // squawk
1544 1544
 	    	    //$data['emergency'] = ''; // emergency
1545 1545
 	    	    if (isset($value['timezone'])) {
1546
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1546
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1547 1547
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1548 1548
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1549 1549
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1579,14 +1579,14 @@  discard block
 block discarded – undo
1579 1579
 	    //$buffer = $Common->getData($hosts[$id]);
1580 1580
 	    if ($globalDebug) echo 'Get Data...'."\n";
1581 1581
 	    $buffer = $Common->getData($value['host']);
1582
-	    $all_data = json_decode($buffer,true);
1582
+	    $all_data = json_decode($buffer, true);
1583 1583
 	    if ($buffer != '' && is_array($all_data)) {
1584 1584
 		$reset = 0;
1585 1585
 		foreach ($all_data as $line) {
1586 1586
 	    	    $data = array();
1587 1587
 	    	    //$data['id'] = $line['id']; // id not usable
1588 1588
 	    	    $data['id'] = trim($line['flight_id']);
1589
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1589
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1590 1590
 	    	    $data['pilot_name'] = $line['pilot_name'];
1591 1591
 	    	    $data['pilot_id'] = $line['pilot_id'];
1592 1592
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1630,24 +1630,24 @@  discard block
 block discarded – undo
1630 1630
 	    //$buffer = $Common->getData($hosts[$id]);
1631 1631
 	    if ($globalDebug) echo 'Get Data...'."\n";
1632 1632
 	    $buffer = $Common->getData($value['host']);
1633
-	    $all_data = json_decode($buffer,true);
1633
+	    $all_data = json_decode($buffer, true);
1634 1634
 	    if ($buffer != '') {
1635 1635
 		$Source->deleteLocationBySource('blitzortung');
1636
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1637
-		$buffer = explode('\n',$buffer);
1636
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1637
+		$buffer = explode('\n', $buffer);
1638 1638
 		foreach ($buffer as $buffer_line) {
1639
-		    $line = json_decode($buffer_line,true);
1639
+		    $line = json_decode($buffer_line, true);
1640 1640
 		    if (isset($line['time'])) {
1641 1641
 			$data = array();
1642 1642
 			$data['altitude'] = $line['alt']; // altitude
1643 1643
 			$data['latitude'] = $line['lat']; // lat
1644 1644
 			$data['longitude'] = $line['lon']; // long
1645
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1645
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1646 1646
 			$data['id_source'] = $id_source;
1647 1647
 			$data['format_source'] = 'blitzortung';
1648 1648
 			$SI->add($data);
1649 1649
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1650
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1650
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1651 1651
 			unset($data);
1652 1652
 		    }
1653 1653
 		}
@@ -1659,15 +1659,15 @@  discard block
 block discarded – undo
1659 1659
         $arr = $httpfeeds;
1660 1660
         $w = $e = null;
1661 1661
         if (isset($arr[$id])) {
1662
-            $nn = stream_select($arr,$w,$e,$timeout);
1662
+            $nn = stream_select($arr, $w, $e, $timeout);
1663 1663
             if ($nn > 0) {
1664 1664
                 foreach ($httpfeeds as $feed) {
1665
-                    $buffer = stream_get_line($feed,2000,"\n");
1665
+                    $buffer = stream_get_line($feed, 2000, "\n");
1666 1666
                     if ($buffer === FALSE) {
1667 1667
                         connect_all($globalSources);
1668 1668
                     }
1669
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1670
-                    $buffer = explode('\n',$buffer);
1669
+                    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1670
+                    $buffer = explode('\n', $buffer);
1671 1671
                     foreach ($buffer as $line) {
1672 1672
                         if ($line != '') {
1673 1673
                             $line = json_decode($line, true);
@@ -1707,11 +1707,11 @@  discard block
 block discarded – undo
1707 1707
 		    //$value = $formats[$nb];
1708 1708
 		    $format = $globalSources[$nb]['format'];
1709 1709
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1710
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1710
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1711 1711
 		    } elseif ($format === 'vrstcp') {
1712 1712
 			$buffer = @socket_read($r, 6000);
1713 1713
 		    } else {
1714
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1714
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1715 1715
 		    }
1716 1716
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1717 1717
 		    //echo $buffer."\n";
@@ -1721,8 +1721,8 @@  discard block
 block discarded – undo
1721 1721
 		    //$SI::del();
1722 1722
 		    if ($buffer !== FALSE) {
1723 1723
 			if ($format === 'vrstcp') {
1724
-			    $buffer = explode('},{',$buffer);
1725
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1724
+			    $buffer = explode('},{', $buffer);
1725
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1726 1726
 		    }
1727 1727
 		    // SBS format is CSV format
1728 1728
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1749,7 +1749,7 @@  discard block
 block discarded – undo
1749 1749
 			    $ais_data = $AIS->parse_line(trim($buffer));
1750 1750
 			    $data = array();
1751 1751
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1752
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1752
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1753 1753
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1754 1754
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1755 1755
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1760,13 +1760,13 @@  discard block
 block discarded – undo
1760 1760
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1761 1761
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1762 1762
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1763
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1763
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1764 1764
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1765 1765
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1766 1766
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1767 1767
 
1768 1768
 			    if (isset($ais_data['timestamp'])) {
1769
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1769
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1770 1770
 			    } else {
1771 1771
 				$data['datetime'] = date('Y-m-d H:i:s');
1772 1772
 			    }
@@ -1777,10 +1777,10 @@  discard block
 block discarded – undo
1777 1777
                         } elseif ($format === 'flightgearsp') {
1778 1778
                     	    //echo $buffer."\n";
1779 1779
                     	    if (strlen($buffer) > 5) {
1780
-				$line = explode(',',$buffer);
1780
+				$line = explode(',', $buffer);
1781 1781
 				$data = array();
1782 1782
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1783
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1783
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1784 1784
 				$data['ident'] = $line[6];
1785 1785
 				$data['aircraft_name'] = $line[7];
1786 1786
 				$data['longitude'] = $line[1];
@@ -1797,25 +1797,25 @@  discard block
 block discarded – undo
1797 1797
                         } elseif ($format === 'acars') {
1798 1798
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1799 1799
 			    $ACARS->add(trim($buffer));
1800
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1800
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1801 1801
 			    $ACARS->deleteLiveAcarsData();
1802 1802
 			} elseif ($format === 'acarsjsonudp') {
1803 1803
 			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1804 1804
                             $line = json_decode(trim($buffer), true);
1805 1805
                             if (!empty($line)) {
1806
-				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1806
+				$line = array_merge(array('text' => '', 'tail' => '', 'label' => '', 'block_id' => '', 'flight' => '', 'msgno' => ''), $line);
1807 1807
                                 $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1808 1808
                                 $ACARS->deleteLiveAcarsData();
1809 1809
                             }
1810
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1810
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1811 1811
 			} elseif ($format === 'flightgearmp') {
1812
-			    if (substr($buffer,0,1) != '#') {
1812
+			    if (substr($buffer, 0, 1) != '#') {
1813 1813
 				$data = array();
1814 1814
 				//echo $buffer."\n";
1815
-				$line = explode(' ',$buffer);
1815
+				$line = explode(' ', $buffer);
1816 1816
 				if (count($line) === 11) {
1817
-				    $userserver = explode('@',$line[0]);
1818
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1817
+				    $userserver = explode('@', $line[0]);
1818
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1819 1819
 				    $data['ident'] = $userserver[0];
1820 1820
 				    $data['registration'] = $userserver[0];
1821 1821
 				    $data['latitude'] = $line[4];
@@ -1823,8 +1823,8 @@  discard block
 block discarded – undo
1823 1823
 				    $data['altitude'] = $line[6];
1824 1824
 				    $data['datetime'] = date('Y-m-d H:i:s');
1825 1825
 				    $aircraft_type = $line[10];
1826
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1827
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1826
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1827
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1828 1828
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1829 1829
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1830 1830
 				}
@@ -1833,8 +1833,8 @@  discard block
 block discarded – undo
1833 1833
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1834 1834
 			    die;
1835 1835
 			} elseif ($format === 'vrstcp') {
1836
-			    foreach($buffer as $all_data) {
1837
-				$line = json_decode('{'.$all_data.'}',true);
1836
+			    foreach ($buffer as $all_data) {
1837
+				$line = json_decode('{'.$all_data.'}', true);
1838 1838
 				$data = array();
1839 1839
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1840 1840
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1860,16 +1860,16 @@  discard block
 block discarded – undo
1860 1860
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1861 1861
 				unset($data);
1862 1862
 			    }
1863
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1863
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1864 1864
 			    $line = explode("\t", $buffer);
1865
-			    for($k = 0; $k < count($line); $k=$k+2) {
1865
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1866 1866
 				$key = $line[$k];
1867
-			        $lined[$key] = $line[$k+1];
1867
+			        $lined[$key] = $line[$k + 1];
1868 1868
 			    }
1869 1869
     			    if (count($lined) > 3) {
1870 1870
     				$data['hex'] = $lined['hexid'];
1871 1871
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1872
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1872
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1873 1873
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1874 1874
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1875 1875
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1888,23 +1888,23 @@  discard block
 block discarded – undo
1888 1888
     			    } else $error = true;
1889 1889
 			} elseif ($format === 'aprs' && $use_aprs) {
1890 1890
 			    if ($aprs_connect === 0) {
1891
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1891
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1892 1892
 				$aprs_connect = 1;
1893 1893
 			    }
1894 1894
 			    
1895
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1895
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1896 1896
 				$aprs_last_tx = time();
1897 1897
 				$data_aprs = "# Keep alive";
1898
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1898
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1899 1899
 			    }
1900 1900
 			    
1901 1901
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1902 1902
 			    //echo 'APRS data : '.$buffer."\n";
1903
-			    $buffer = str_replace('APRS <- ','',$buffer);
1904
-			    $buffer = str_replace('APRS -> ','',$buffer);
1903
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1904
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1905 1905
 			    //echo $buffer."\n";
1906 1906
 			    date_default_timezone_set('UTC');
1907
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1907
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1908 1908
 				$line = $APRS->parse($buffer);
1909 1909
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1910 1910
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1919,7 +1919,7 @@  discard block
 block discarded – undo
1919 1919
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1920 1920
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1921 1921
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1922
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1922
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1923 1923
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1924 1924
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1925 1925
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -2007,29 +2007,29 @@  discard block
 block discarded – undo
2007 2007
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2008 2008
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2009 2009
 					$Source->deleteOldLocationByType('gs');
2010
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
2011
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2010
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
2011
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
2012 2012
 					} else {
2013
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2013
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
2014 2014
 					}
2015 2015
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2016 2016
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2017 2017
 					if ($globalDebug) echo '# Weather Station added'."\n";
2018 2018
 					$Source->deleteOldLocationByType('wx');
2019 2019
 					$weather_data = json_encode($line);
2020
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
2021
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2020
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
2021
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
2022 2022
 					} else {
2023
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2023
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
2024 2024
 					}
2025 2025
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2026 2026
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2027 2027
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2028 2028
 					$Source->deleteOldLocationByType('lightning');
2029
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
2030
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2029
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
2030
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
2031 2031
 					} else {
2032
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2032
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
2033 2033
 					}
2034 2034
 				    } elseif ($globalDebug) {
2035 2035
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -2038,7 +2038,7 @@  discard block
 block discarded – undo
2038 2038
 				    unset($data);
2039 2039
 				}
2040 2040
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2041
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
2041
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
2042 2042
 				}
2043 2043
 				/*
2044 2044
 				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')) {
@@ -2047,7 +2047,7 @@  discard block
 block discarded – undo
2047 2047
 				*/
2048 2048
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
2049 2049
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2050
-				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
2050
+				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
2051 2051
 					$Source->deleteOldLocationByType('lightning');
2052 2052
 					$Source->deleteOldLocationByType('wx');
2053 2053
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
 				connect_all($sourceee);
2135 2135
 				$sourceee = array();
2136 2136
 				//connect_all($globalSources);
2137
-				$tt[$format]=0;
2137
+				$tt[$format] = 0;
2138 2138
 				break;
2139 2139
 			    } 
2140 2140
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -2144,14 +2144,14 @@  discard block
 block discarded – undo
2144 2144
 	    } else {
2145 2145
 		$error = socket_strerror(socket_last_error());
2146 2146
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2147
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2147
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
2148 2148
 			if (isset($globalDebug)) echo "Restarting...\n";
2149 2149
 			// Restart the script if possible
2150 2150
 			if (is_array($sockets)) {
2151 2151
 			    if ($globalDebug) echo "Shutdown all sockets...";
2152 2152
 			    
2153 2153
 			    foreach ($sockets as $sock) {
2154
-				@socket_shutdown($sock,2);
2154
+				@socket_shutdown($sock, 2);
2155 2155
 				@socket_close($sock);
2156 2156
 			    }
2157 2157
 			    
Please login to merge, or discard this patch.
Braces   +1276 added lines, -430 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
26 28
 
27 29
 if ($globalInstalled === FALSE) {
28 30
     echo "This script MUST be run after install script. Use your web browser to run install/index.php";
@@ -68,66 +70,107 @@  discard block
 block discarded – undo
68 70
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 71
 if (isset($options['s'])) {
70 72
     $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
73
-} elseif (isset($options['source'])) {
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['s']);
77
+    }
78
+    } elseif (isset($options['source'])) {
74 79
     $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
77
-}
80
+    if (isset($options['format'])) {
81
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
82
+    } else {
83
+    	$globalSources[] = array('host' => $options['source']);
84
+    }
85
+    }
78 86
 if (isset($options['aprsserverhost'])) {
79 87
 	$globalServerAPRS = TRUE;
80 88
 	$globalServerAPRShost = $options['aprsserverhost'];
81 89
 }
82
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
83
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
84
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
85
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
90
+if (isset($options['aprsserverport'])) {
91
+	$globalServerAPRSport = $options['aprsserverport'];
92
+}
93
+if (isset($options['aprsserverssid'])) {
94
+	$globalServerAPRSssid = $options['aprsserverssid'];
95
+}
96
+if (isset($options['aprsserverpass'])) {
97
+	$globalServerAPRSpass = $options['aprsserverpass'];
98
+}
99
+if (isset($options['noaprsserver'])) {
100
+	$globalServerAPRS = FALSE;
101
+}
86 102
 if (isset($options['enable-aircraft'])) {
87
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
103
+	if ($globalDebug) {
104
+		echo 'Enable Aircraft mode'."\n";
105
+	}
88 106
 	$globalAircraft = TRUE; 
89 107
 }
90 108
 if (isset($options['disable-aircraft'])) {
91
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
109
+	if ($globalDebug) {
110
+		echo 'Disable Aircraft mode'."\n";
111
+	}
92 112
 	$globalAircraft = FALSE;
93 113
 }
94 114
 if (isset($options['enable-tracker'])) {
95
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
115
+	if ($globalDebug) {
116
+		echo 'Enable Tracker mode'."\n";
117
+	}
96 118
 	$globalTracker = TRUE; 
97 119
 }
98 120
 if (isset($options['disable-tracker'])) {
99
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
121
+	if ($globalDebug) {
122
+		echo 'Disable Tracker mode'."\n";
123
+	}
100 124
 	$globalTracker = FALSE;
101 125
 }
102 126
 if (isset($options['enable-marine'])) {
103
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
127
+	if ($globalDebug) {
128
+		echo 'Enable Marine mode'."\n";
129
+	}
104 130
 	$globalMarine = TRUE;
105 131
 }
106 132
 if (isset($options['disable-marine'])) {
107
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
133
+	if ($globalDebug) {
134
+		echo 'Disable Marine mode'."\n";
135
+	}
108 136
 	$globalMarine = FALSE;
109 137
 }
110
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
111
-if (isset($options['server'])) $globalServer = TRUE;
112
-if (isset($options['idsource'])) $id_source = $options['idsource'];
113
-else $id_source = 1;
138
+if (isset($options['nodaemon'])) {
139
+	$globalDaemon = FALSE;
140
+}
141
+if (isset($options['server'])) {
142
+	$globalServer = TRUE;
143
+}
144
+if (isset($options['idsource'])) {
145
+	$id_source = $options['idsource'];
146
+} else {
147
+	$id_source = 1;
148
+}
114 149
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
150
+    if ($globalDebug) {
151
+    	echo "Using Server Mode\n";
152
+    }
116 153
     $SI=new SpotterServer();
117 154
 /*
118 155
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 156
     $SI = new adsb2aprs();
120 157
     $SI->connect();
121 158
 */
122
-} else $SI=new SpotterImport($Connection->db);
159
+} else {
160
+	$SI=new SpotterImport($Connection->db);
161
+}
123 162
 
124
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
163
+if (isset($globalTracker) && $globalTracker) {
164
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
165
+}
125 166
 if (isset($globalMarine) && $globalMarine) {
126 167
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
127 168
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 169
 }
129 170
 
130
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
171
+if (isset($globalTracker) && $globalTracker) {
172
+	$TI = new TrackerImport($Connection->db);
173
+}
131 174
 if (isset($globalMarine) && $globalMarine) {
132 175
     $AIS = new AIS();
133 176
     $MI = new MarineImport($Connection->db);
@@ -152,7 +195,9 @@  discard block
 block discarded – undo
152 195
 }
153 196
 
154 197
 // let's try and connect
155
-if ($globalDebug) echo "Connecting...\n";
198
+if ($globalDebug) {
199
+	echo "Connecting...\n";
200
+}
156 201
 $use_aprs = false;
157 202
 $aprs_full = false;
158 203
 $reset = 0;
@@ -161,7 +206,9 @@  discard block
 block discarded – undo
161 206
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162 207
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163 208
     $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
209
+    if ($globalDebug) {
210
+    	echo 'Connect to all...'."\n";
211
+    }
165 212
     foreach ($hosts as $id => $value) {
166 213
 	$host = $value['host'];
167 214
 	$udp = false;
@@ -172,32 +219,44 @@  discard block
 block discarded – undo
172 219
         	//$formats[$id] = 'deltadbtxt';
173 220
         	$globalSources[$id]['format'] = 'deltadbtxt';
174 221
         	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to deltadb source (".$host.")...\n";
224
+        	}
176 225
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177 226
         	//$formats[$id] = 'vatsimtxt';
178 227
         	$globalSources[$id]['format'] = 'vatsimtxt';
179 228
         	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
229
+        	if ($globalDebug) {
230
+        		echo "Connect to vatsim source (".$host.")...\n";
231
+        	}
181 232
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182 233
         	//$formats[$id] = 'aircraftlistjson';
183 234
         	$globalSources[$id]['format'] = 'aircraftlistjson';
184 235
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
238
+        	}
186 239
     	    } else if (preg_match('/aircraft.json$/i',$host)) {
187 240
         	//$formats[$id] = 'aircraftjson';
188 241
         	$globalSources[$id]['format'] = 'aircraftjson';
189 242
         	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
243
+        	if ($globalDebug) {
244
+        		echo "Connect to aircraft.json source (".$host.")...\n";
245
+        	}
191 246
     	    } else if (preg_match('/aircraft$/i',$host)) {
192 247
         	//$formats[$id] = 'planefinderclient';
193 248
         	$globalSources[$id]['format'] = 'planefinderclient';
194 249
         	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
250
+        	if ($globalDebug) {
251
+        		echo "Connect to planefinderclient source (".$host.")...\n";
252
+        	}
196 253
     	    } else if (preg_match('/opensky/i',$host)) {
197 254
         	//$formats[$id] = 'aircraftlistjson';
198 255
         	$globalSources[$id]['format'] = 'opensky';
199 256
         	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
257
+        	if ($globalDebug) {
258
+        		echo "Connect to opensky source (".$host.")...\n";
259
+        	}
201 260
     	    /*
202 261
     	    // Disabled for now, site change source format
203 262
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -214,7 +273,9 @@  discard block
 block discarded – undo
214 273
         	//$formats[$id] = 'planeupdatefaa';
215 274
         	$globalSources[$id]['format'] = 'planeupdatefaa';
216 275
         	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
276
+        	if ($globalDebug) {
277
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
278
+        	}
218 279
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219 280
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220 281
         	    exit(0);
@@ -223,37 +284,53 @@  discard block
 block discarded – undo
223 284
         	//$formats[$id] = 'phpvmacars';
224 285
         	$globalSources[$id]['format'] = 'phpvmacars';
225 286
         	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
287
+        	if ($globalDebug) {
288
+        		echo "Connect to phpvmacars source (".$host.")...\n";
289
+        	}
227 290
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228 291
         	//$formats[$id] = 'phpvmacars';
229 292
         	$globalSources[$id]['format'] = 'vaos';
230 293
         	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
294
+        	if ($globalDebug) {
295
+        		echo "Connect to vaos source (".$host.")...\n";
296
+        	}
232 297
             } else if (preg_match('/VAM-json.php$/i',$host)) {
233 298
         	//$formats[$id] = 'phpvmacars';
234 299
         	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
300
+        	if ($globalDebug) {
301
+        		echo "Connect to Vam source (".$host.")...\n";
302
+        	}
236 303
             } else if (preg_match('/whazzup/i',$host)) {
237 304
         	//$formats[$id] = 'whazzup';
238 305
         	$globalSources[$id]['format'] = 'whazzup';
239 306
         	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
307
+        	if ($globalDebug) {
308
+        		echo "Connect to whazzup source (".$host.")...\n";
309
+        	}
241 310
             } else if (preg_match('/blitzortung/i',$host)) {
242 311
         	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
312
+        	if ($globalDebug) {
313
+        		echo "Connect to blitzortung source (".$host.")...\n";
314
+        	}
244 315
             } else if (preg_match('/airwhere/i',$host)) {
245 316
         	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
317
+        	if ($globalDebug) {
318
+        		echo "Connect to airwhere source (".$host.")...\n";
319
+        	}
247 320
             } else if (preg_match('/recentpireps/i',$host)) {
248 321
         	//$formats[$id] = 'pirepsjson';
249 322
         	$globalSources[$id]['format'] = 'pirepsjson';
250 323
         	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
324
+        	if ($globalDebug) {
325
+        		echo "Connect to pirepsjson source (".$host.")...\n";
326
+        	}
252 327
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253 328
         	//$formats[$id] = 'fr24json';
254 329
         	$globalSources[$id]['format'] = 'fr24json';
255 330
         	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
331
+        	if ($globalDebug) {
332
+        		echo "Connect to fr24 source (".$host.")...\n";
333
+        	}
257 334
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258 335
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259 336
         	    exit(0);
@@ -262,7 +339,9 @@  discard block
 block discarded – undo
262 339
         	//$formats[$id] = 'fr24json';
263 340
         	$globalSources[$id]['format'] = 'myshiptracking';
264 341
         	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
342
+        	if ($globalDebug) {
343
+        		echo "Connect to myshiptracking source (".$host.")...\n";
344
+        	}
266 345
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267 346
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268 347
         	    exit(0);
@@ -271,18 +350,28 @@  discard block
 block discarded – undo
271 350
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272 351
         	//$formats[$id] = 'tsv';
273 352
         	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
353
+        	if ($globalDebug) {
354
+        		echo "Connect to tsv source (".$host.")...\n";
355
+        	}
275 356
             }
276 357
         } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277 358
     		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278 359
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279 360
     		    if ($idf !== false) {
280 361
     			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
362
+        		if ($globalDebug) {
363
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
364
+        		}
365
+    		    } elseif ($globalDebug) {
366
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
367
+    		    }
368
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') {
369
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
370
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') {
371
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
372
+    		} elseif ($globalDebug) {
373
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
374
+    		}
286 375
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287 376
 	    $hostport = explode(':',$host);
288 377
 	    if (isset($hostport[1])) {
@@ -323,20 +412,29 @@  discard block
 block discarded – undo
323 412
         		//$formats[$id] = 'beast';
324 413
         		$globalSources[$id]['format'] = 'beast';
325 414
 		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
415
+		    } else {
416
+		    	$globalSources[$id]['format'] = 'sbs';
417
+		    }
327 418
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 419
 		}
329
-		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330
-		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
420
+		if ($globalDebug && $udp) {
421
+			echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
422
+		} elseif ($globalDebug) {
423
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
424
+		}
331 425
             } else {
332
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
426
+		if ($globalDebug) {
427
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
428
+		}
333 429
 		sleep(10);
334 430
 		connect_all($hosts);
335 431
     	    }
336 432
         }
337 433
     }
338 434
 }
339
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
435
+if (!isset($globalMinFetch)) {
436
+	$globalMinFetch = 15;
437
+}
340 438
 
341 439
 // Initialize all
342 440
 $status = array();
@@ -345,13 +443,19 @@  discard block
 block discarded – undo
345 443
 $formats = array();
346 444
 $last_exec = array();
347 445
 $time = time();
348
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
349
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
350
-else $timeout = 20;
446
+if (isset($globalSourcesTimeout)) {
447
+	$timeout = $globalSourcesTimeOut;
448
+} else if (isset($globalSBS1TimeOut)) {
449
+	$timeout = $globalSBS1TimeOut;
450
+} else {
451
+	$timeout = 20;
452
+}
351 453
 $errno = '';
352 454
 $errstr='';
353 455
 
354
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
456
+if (!isset($globalDaemon)) {
457
+	$globalDaemon = TRUE;
458
+}
355 459
 /* Initiate connections to all the hosts simultaneously */
356 460
 //connect_all($hosts);
357 461
 //connect_all($globalSources);
@@ -380,7 +484,9 @@  discard block
 block discarded – undo
380 484
     if (isset($source['format']) && $source['format'] == 'aprs') {
381 485
 	$aprs_connect = 0;
382 486
 	$use_aprs = true;
383
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
487
+	if (isset($source['port']) && $source['port'] == '10152') {
488
+		$aprs_full = true;
489
+	}
384 490
 	break;
385 491
     }
386 492
 }
@@ -391,25 +497,46 @@  discard block
 block discarded – undo
391 497
 	$aprs_connect = 0;
392 498
 	$aprs_keep = 120;
393 499
 	$aprs_last_tx = time();
394
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
395
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
396
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
397
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
398
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
399
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
400
-	if ($aprs_full) $aprs_filter = '';
401
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
402
-	else $aprs_pass = '-1';
500
+	if (isset($globalAPRSversion)) {
501
+		$aprs_version = $globalAPRSversion;
502
+	} else {
503
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
504
+	}
505
+	if (isset($globalAPRSssid)) {
506
+		$aprs_ssid = $globalAPRSssid;
507
+	} else {
508
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
509
+	}
510
+	if (isset($globalAPRSfilter)) {
511
+		$aprs_filter = $globalAPRSfilter;
512
+	} else {
513
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
514
+	}
515
+	if ($aprs_full) {
516
+		$aprs_filter = '';
517
+	}
518
+	if (isset($globalAPRSpass)) {
519
+		$aprs_pass = $globalAPRSpass;
520
+	} else {
521
+		$aprs_pass = '-1';
522
+	}
403 523
 
404
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
405
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
406
-}
524
+	if ($aprs_filter != '') {
525
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
526
+	} else {
527
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
528
+	}
529
+	}
407 530
 
408 531
 // connected - lets do some work
409 532
 //if ($globalDebug) echo "Connected!\n";
410 533
 sleep(1);
411
-if ($globalDebug) echo "SCAN MODE \n\n";
412
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
534
+if ($globalDebug) {
535
+	echo "SCAN MODE \n\n";
536
+}
537
+if (!isset($globalCronEnd)) {
538
+	$globalCronEnd = 60;
539
+}
413 540
 $endtime = time()+$globalCronEnd;
414 541
 $i = 1;
415 542
 $tt = array();
@@ -423,22 +550,32 @@  discard block
 block discarded – undo
423 550
 
424 551
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 552
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
553
+    if (function_exists('pcntl_fork')) {
554
+    	pcntl_signal_dispatch();
555
+    }
427 556
 
428
-    if (!$globalDaemon) $i = $endtime-time();
557
+    if (!$globalDaemon) {
558
+    	$i = $endtime-time();
559
+    }
429 560
     // Delete old ATC
430 561
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
562
+	if ($globalDebug) {
563
+		echo 'Delete old ATC...'."\n";
564
+	}
432 565
         $ATC->deleteOldATC();
433 566
     }
434 567
     
435 568
     if (count($last_exec) == count($globalSources)) {
436 569
 	$max = $globalMinFetch;
437 570
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
571
+	    if ((time() - $last['last']) < $max) {
572
+	    	$max = time() - $last['last'];
573
+	    }
439 574
 	}
440 575
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
576
+	    if ($globalDebug) {
577
+	    	echo 'Sleeping...'."\n";
578
+	    }
442 579
 	    sleep($globalMinFetch-$max+2);
443 580
 	}
444 581
     }
@@ -448,7 +585,9 @@  discard block
 block discarded – undo
448 585
     foreach ($globalSources as $id => $value) {
449 586
 	date_default_timezone_set('UTC');
450 587
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
588
+	if (!isset($last_exec[$id]['last'])) {
589
+		$last_exec[$id]['last'] = 0;
590
+	}
452 591
 	if ($value['format'] === 'deltadbtxt' && 
453 592
 	    (
454 593
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -457,7 +596,9 @@  discard block
 block discarded – undo
457 596
 	) {
458 597
         //$buffer = $Common->getData($hosts[$id]);
459 598
         $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
599
+        if ($buffer != '') {
600
+        	$reset = 0;
601
+        }
461 602
         $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462 603
         $buffer = explode('\n', $buffer);
463 604
         foreach ($buffer as $line) {
@@ -466,20 +607,41 @@  discard block
 block discarded – undo
466 607
                 $data = array();
467 608
                 $data['hex'] = $line[1]; // hex
468 609
                 $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
610
+                if (isset($line[3])) {
611
+                	$data['altitude'] = $line[3];
612
+                }
613
+                // altitude
614
+                if (isset($line[4])) {
615
+                	$data['speed'] = $line[4];
616
+                }
617
+                // speed
618
+                if (isset($line[5])) {
619
+                	$data['heading'] = $line[5];
620
+                }
621
+                // heading
622
+                if (isset($line[6])) {
623
+                	$data['latitude'] = $line[6];
624
+                }
625
+                // lat
626
+                if (isset($line[7])) {
627
+                	$data['longitude'] = $line[7];
628
+                }
629
+                // long
474 630
                 $data['verticalrate'] = ''; // vertical rate
475 631
                 //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476 632
                 $data['emergency'] = ''; // emergency
477 633
                 $data['datetime'] = date('Y-m-d H:i:s');
478 634
                 $data['format_source'] = 'deltadbtxt';
479 635
                 $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
636
+                if (isset($value['name']) && $value['name'] != '') {
637
+                	$data['source_name'] = $value['name'];
638
+                }
639
+                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
640
+                	$data['noarchive'] = true;
641
+                }
642
+                if (isset($value['sourcestats'])) {
643
+                	$data['sourcestats'] = $value['sourcestats'];
644
+                }
483 645
                 $SI->add($data);
484 646
                 unset($data);
485 647
             }
@@ -514,11 +676,20 @@  discard block
 block discarded – undo
514 676
                     $data['format_source'] = 'radarcapejson';
515 677
                     $data['id_source'] = $id_source;
516 678
                     if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
679
+                        if (isset($line['src']) && !$line['src'] == 'M') {
680
+                        	$data['source_name'] = $value['name'].'_MLAT';
681
+                        } else {
682
+                        	$data['source_name'] = $value['name'];
683
+                        }
684
+                    } elseif (isset($line['src']) && $line['src'] == 'M') {
685
+                    	$data['source_name'] = 'MLAT';
686
+                    }
687
+                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
688
+                    	$data['noarchive'] = true;
689
+                    }
690
+                    if (isset($value['sourcestats'])) {
691
+                    	$data['sourcestats'] = $value['sourcestats'];
692
+                    }
522 693
 
523 694
                     $SI->add($data);
524 695
                     unset($data);
@@ -534,7 +705,9 @@  discard block
 block discarded – undo
534 705
 	    date_default_timezone_set('CET');
535 706
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536 707
 	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
708
+	    if ($buffer != '') {
709
+	    	$reset = 0;
710
+	    }
538 711
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539 712
 	    $buffer = explode('\n',$buffer);
540 713
 	    foreach ($buffer as $line) {
@@ -543,18 +716,42 @@  discard block
 block discarded – undo
543 716
 		    $add = false;
544 717
 		    $ais_data = $AIS->parse_line(trim($line));
545 718
 		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
719
+		    if (isset($ais_data['ident'])) {
720
+		    	$data['ident'] = $ais_data['ident'];
721
+		    }
722
+		    if (isset($ais_data['mmsi'])) {
723
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
724
+		    }
725
+		    if (isset($ais_data['speed'])) {
726
+		    	$data['speed'] = $ais_data['speed'];
727
+		    }
728
+		    if (isset($ais_data['heading'])) {
729
+		    	$data['heading'] = $ais_data['heading'];
730
+		    }
731
+		    if (isset($ais_data['latitude'])) {
732
+		    	$data['latitude'] = $ais_data['latitude'];
733
+		    }
734
+		    if (isset($ais_data['longitude'])) {
735
+		    	$data['longitude'] = $ais_data['longitude'];
736
+		    }
737
+		    if (isset($ais_data['status'])) {
738
+		    	$data['status'] = $ais_data['status'];
739
+		    }
740
+		    if (isset($ais_data['statusid'])) {
741
+		    	$data['status_id'] = $ais_data['statusid'];
742
+		    }
743
+		    if (isset($ais_data['type'])) {
744
+		    	$data['type'] = $ais_data['type'];
745
+		    }
746
+		    if (isset($ais_data['typeid'])) {
747
+		    	$data['type_id'] = $ais_data['typeid'];
748
+		    }
749
+		    if (isset($ais_data['imo'])) {
750
+		    	$data['imo'] = $ais_data['imo'];
751
+		    }
752
+		    if (isset($ais_data['callsign'])) {
753
+		    	$data['callsign'] = $ais_data['callsign'];
754
+		    }
558 755
 		    if (isset($ais_data['timestamp'])) {
559 756
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 757
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -568,8 +765,12 @@  discard block
 block discarded – undo
568 765
 		    $data['format_source'] = 'aisnmeatxt';
569 766
     		    $data['id_source'] = $id_source;
570 767
 		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
768
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
769
+		    	$data['noarchive'] = true;
770
+		    }
771
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
772
+		    	$MI->add($data);
773
+		    }
573 774
 		    unset($data);
574 775
 		}
575 776
     	    }
@@ -592,20 +793,48 @@  discard block
 block discarded – undo
592 793
 			    if ($line != '') {
593 794
 				$ais_data = $AIS->parse_line(trim($line));
594 795
 				$data = array();
595
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
596
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
597
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
598
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
599
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
600
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
601
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
602
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
603
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
604
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
605
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
606
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
607
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
796
+				if (isset($ais_data['ident'])) {
797
+					$data['ident'] = $ais_data['ident'];
798
+				}
799
+				if (isset($ais_data['mmsi'])) {
800
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
801
+				}
802
+				if (isset($ais_data['speed'])) {
803
+					$data['speed'] = $ais_data['speed'];
804
+				}
805
+				if (isset($ais_data['heading'])) {
806
+					$data['heading'] = $ais_data['heading'];
807
+				}
808
+				if (isset($ais_data['latitude'])) {
809
+					$data['latitude'] = $ais_data['latitude'];
810
+				}
811
+				if (isset($ais_data['longitude'])) {
812
+					$data['longitude'] = $ais_data['longitude'];
813
+				}
814
+				if (isset($ais_data['status'])) {
815
+					$data['status'] = $ais_data['status'];
816
+				}
817
+				if (isset($ais_data['statusid'])) {
818
+					$data['status_id'] = $ais_data['statusid'];
819
+				}
820
+				if (isset($ais_data['type'])) {
821
+					$data['type'] = $ais_data['type'];
822
+				}
823
+				if (isset($ais_data['typeid'])) {
824
+					$data['type_id'] = $ais_data['typeid'];
825
+				}
826
+				if (isset($ais_data['imo'])) {
827
+					$data['imo'] = $ais_data['imo'];
828
+				}
829
+				if (isset($ais_data['callsign'])) {
830
+					$data['callsign'] = $ais_data['callsign'];
831
+				}
832
+				if (isset($ais_data['destination'])) {
833
+					$data['arrival_code'] = $ais_data['destination'];
834
+				}
835
+				if (isset($ais_data['eta_ts'])) {
836
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
837
+				}
609 838
 				if (isset($ais_data['timestamp'])) {
610 839
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 840
 				} else {
@@ -613,18 +842,27 @@  discard block
 block discarded – undo
613 842
 				}
614 843
 				$data['format_source'] = 'aisnmeahttp';
615 844
 				$data['id_source'] = $id_source;
616
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
845
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
846
+					$data['noarchive'] = true;
847
+				}
848
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
849
+					$MI->add($data);
850
+				}
618 851
 				unset($data);
619 852
 			    }
620 853
 			}
621 854
 		    }
622 855
 		} else {
623 856
 		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
857
+		    if (isset($tt[$format])) {
858
+		    	$tt[$format]++;
859
+		    } else {
860
+		    	$tt[$format] = 0;
861
+		    }
626 862
 		    if ($tt[$format] > 30) {
627
-			if ($globalDebug) echo 'Reconnect...'."\n";
863
+			if ($globalDebug) {
864
+				echo 'Reconnect...'."\n";
865
+			}
628 866
 			sleep(2);
629 867
 			//$sourceeen[] = $value;
630 868
 			//connect_all($sourceeen);
@@ -660,12 +898,18 @@  discard block
 block discarded – undo
660 898
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661 899
 			    //$data['type_id'] = $line['TYPE'];
662 900
 			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
901
+			    if ($line['DEST'] != '') {
902
+			    	$data['arrival_code'] = $line['DEST'];
903
+			    }
904
+			    if ($line['ARV'] != '') {
905
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
906
+			    }
665 907
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666 908
 			    $data['format_source'] = 'myshiptracking';
667 909
 			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
910
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
911
+			    	$data['noarchive'] = true;
912
+			    }
669 913
 			    $MI->add($data);
670 914
 			    unset($data);
671 915
 			}
@@ -690,7 +934,9 @@  discard block
 block discarded – undo
690 934
 			    $data['callsign'] = $line['callsign'];
691 935
 			    $data['mmsi'] = substr($line['mmsi'],-9);
692 936
 			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
937
+			    if ($line['heading'] != '511') {
938
+			    	$data['heading'] = $line['heading'];
939
+			    }
694 940
 			    $data['latitude'] = $line['latitude'];
695 941
 			    $data['longitude'] = $line['longitude'];
696 942
 			    $data['type_id'] = $line['shiptype'];
@@ -698,7 +944,9 @@  discard block
 block discarded – undo
698 944
 			    $data['datetime'] = $line['time'];
699 945
 			    $data['format_source'] = 'boatbeaconapp';
700 946
 			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
947
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
948
+			    	$data['noarchive'] = true;
949
+			    }
702 950
 			    $MI->add($data);
703 951
 			    unset($data);
704 952
 			}
@@ -720,22 +968,44 @@  discard block
 block discarded – undo
720 968
 		    foreach ($all_data['features'] as $line) {
721 969
 			print_r($line);
722 970
 			$data = array();
723
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
724
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
725
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
726
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
727
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
728
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
971
+			if (isset($line['properties']['name'])) {
972
+				$data['ident'] = $line['properties']['name'];
973
+			}
974
+			if (isset($line['properties']['callsign'])) {
975
+				$data['callsign'] = $line['properties']['callsign'];
976
+			}
977
+			if (isset($line['properties']['mmsi'])) {
978
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
979
+			}
980
+			if (isset($line['properties']['imo'])) {
981
+				$data['imo'] = $line['properties']['imo'];
982
+			}
983
+			if (isset($line['properties']['speed'])) {
984
+				$data['speed'] = $line['properties']['speed'];
985
+			}
986
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
987
+				$data['heading'] = $line['properties']['heading'];
988
+			}
729 989
 			$data['latitude'] = $line['geometry']['coordinates'][1];
730 990
 			$data['longitude'] = $line['geometry']['coordinates'][0];
731
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
732
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
733
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
991
+			if (isset($line['properties']['vesselType'])) {
992
+				$data['type'] = $line['properties']['vesselType'];
993
+			}
994
+			if (isset($line['properties']['destination'])) {
995
+				$data['arrival_code'] = $line['properties']['destination'];
996
+			}
997
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
998
+				$data['arrival_date'] = $line['properties']['eta'];
999
+			}
734 1000
 			$data['format_source'] = 'boatnerd';
735 1001
 			$data['id_source'] = $id_source;
736 1002
 			$data['datetime'] = date('Y-m-d H:i:s');
737
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
1003
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1004
+				$data['noarchive'] = true;
1005
+			}
1006
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
1007
+				$MI->add($data);
1008
+			}
739 1009
 			unset($data);
740 1010
 		    }
741 1011
 		}
@@ -748,11 +1018,17 @@  discard block
 block discarded – undo
748 1018
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749 1019
 	    )
750 1020
 	) {
751
-	    if ($globalDebug) echo 'download...';
1021
+	    if ($globalDebug) {
1022
+	    	echo 'download...';
1023
+	    }
752 1024
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
1025
+	    if ($globalDebug) {
1026
+	    	echo 'done !'."\n";
1027
+	    }
754 1028
 	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
1029
+	    if ($buffer != '') {
1030
+	    	$reset = 0;
1031
+	    }
756 1032
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757 1033
 	    $buffer = explode('\n',$buffer);
758 1034
 	    foreach ($buffer as $line) {
@@ -778,7 +1054,9 @@  discard block
 block discarded – undo
778 1054
 		    //$data['etaTime'] = substr($line,135,5);
779 1055
 		    $data['format_source'] = 'shipplotter';
780 1056
     		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1057
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1058
+		    	$data['noarchive'] = true;
1059
+		    }
782 1060
 		    //print_r($data);
783 1061
 		    //echo 'Add...'."\n";
784 1062
 		    $MI->add($data);
@@ -796,13 +1074,21 @@  discard block
 block discarded – undo
796 1074
 		exit(0);
797 1075
 	    }
798 1076
 	    $sailawayoption = array('key' => $globalSailaway['key']);
799
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1077
+	    if (isset($globalSailaway['usrnr'])) {
1078
+	    	$sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
1079
+	    }
1080
+	    if (isset($globalSailaway['ubtnr'])) {
1081
+	    	$sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1082
+	    }
801 1083
 
802 1084
 	    for ($i = 0; $i <= 1; $i++) {
803
-		if ($globalDebug) echo '! Download... ';
1085
+		if ($globalDebug) {
1086
+			echo '! Download... ';
1087
+		}
804 1088
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?'.http_build_query($sailawayoption).'&race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2','get','','','','',30);
805
-		if ($globalDebug) echo 'done'."\n";
1089
+		if ($globalDebug) {
1090
+			echo 'done'."\n";
1091
+		}
806 1092
 		if ($buffer != '') {
807 1093
 		    $all_data = json_decode($buffer,true);
808 1094
 		    if (isset($all_data['missions'])) {
@@ -817,8 +1103,11 @@  discard block
 block discarded – undo
817 1103
 					//$datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['usrname'])));
818 1104
 					$datar['creator'] = '';
819 1105
 					$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle'])));
820
-					if (isset($mission['misstart'])) $datar['startdate'] = date('Y-m-d H:i:s',strtotime($mission['misstart']));
821
-					else $datar['startdate'] = '1970-01-01 00:00:00';
1106
+					if (isset($mission['misstart'])) {
1107
+						$datar['startdate'] = date('Y-m-d H:i:s',strtotime($mission['misstart']));
1108
+					} else {
1109
+						$datar['startdate'] = '1970-01-01 00:00:00';
1110
+					}
822 1111
 					/*
823 1112
 					$markers = array();
824 1113
 					foreach ($race_data['mission']['course'] as $course) {
@@ -834,7 +1123,9 @@  discard block
 block discarded – undo
834 1123
 			}
835 1124
 		    }
836 1125
 		}
837
-		if ($globalDebug) echo '=== Wait... ===';
1126
+		if ($globalDebug) {
1127
+			echo '=== Wait... ===';
1128
+		}
838 1129
 		sleep(10*60);
839 1130
 	    }
840 1131
 	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
@@ -846,7 +1137,9 @@  discard block
 block discarded – undo
846 1137
 			$data = array();
847 1138
 			$data['id'] = $sail['ubtnr'];
848 1139
 			$data['datetime'] = date('Y-m-d H:i:s');
849
-			if ($sail['online'] == '1') $data['last_update'] = date('Y-m-d H:i:s');
1140
+			if ($sail['online'] == '1') {
1141
+				$data['last_update'] = date('Y-m-d H:i:s');
1142
+			}
850 1143
 			$data['latitude'] = $sail['ubtlat'];
851 1144
 			$data['longitude'] = $sail['ubtlon'];
852 1145
 			$data['type_id'] = 36;
@@ -855,16 +1148,24 @@  discard block
 block discarded – undo
855 1148
 			$data['captain_name'] = $sail['usrname'];
856 1149
 			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat','32&#39; Offshore Racer');
857 1150
 			$boattype = $sail['ubtbtpnr'];
858
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
1151
+			if (isset($allboats[$boattype-1])) {
1152
+				$data['type'] = $allboats[$boattype-1];
1153
+			}
859 1154
 			$data['speed'] = round($sail['ubtspeed']*3.6,2);
860 1155
 			$data['format_source'] = 'sailaway';
861 1156
 			$data['id_source'] = $id_source;
862
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1157
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1158
+				$data['noarchive'] = true;
1159
+			}
863 1160
 			$MI->add($data);
864 1161
 			unset($data);
865 1162
 		    }
866
-		} elseif ($globalDebug) echo 'Error in JSON parsing';
867
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
1163
+		} elseif ($globalDebug) {
1164
+			echo 'Error in JSON parsing';
1165
+		}
1166
+	    } elseif ($globalDebug) {
1167
+	    	echo 'Empty result !'."\n";
1168
+	    }
868 1169
 
869 1170
     	    $last_exec[$id]['last'] = time();
870 1171
 	} elseif ($value['format'] === 'sailaway' && 
@@ -887,11 +1188,19 @@  discard block
 block discarded – undo
887 1188
 		echo 'Sailaway API key MUST be defined';
888 1189
 		exit(0);
889 1190
 	    }
890
-	    if ($globalDebug) echo '! Download... ';
1191
+	    if ($globalDebug) {
1192
+	    	echo '! Download... ';
1193
+	    }
891 1194
 	    $sailawayoption = array('key' => $globalSailaway['key']);
892
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
893
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
894
-	    if (isset($globalSailaway['misnr'])) $sailawayoption = array_merge($sailawayoption,array('misnr' => $globalSailaway['misnr']));
1195
+	    if (isset($globalSailaway['usrnr'])) {
1196
+	    	$sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
1197
+	    }
1198
+	    if (isset($globalSailaway['ubtnr'])) {
1199
+	    	$sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1200
+	    }
1201
+	    if (isset($globalSailaway['misnr'])) {
1202
+	    	$sailawayoption = array_merge($sailawayoption,array('misnr' => $globalSailaway['misnr']));
1203
+	    }
895 1204
 	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
896 1205
 	    if ($buffer != '') {
897 1206
 		$data = json_decode($buffer,true);
@@ -901,7 +1210,9 @@  discard block
 block discarded – undo
901 1210
 			$data = array();
902 1211
 			$data['id'] = $sail['ubtnr'];
903 1212
 			$data['datetime'] = date('Y-m-d H:i:s');
904
-			if ($sail['online'] == '1') $data['last_update'] = date('Y-m-d H:i:s');
1213
+			if ($sail['online'] == '1') {
1214
+				$data['last_update'] = date('Y-m-d H:i:s');
1215
+			}
905 1216
 			$data['latitude'] = $sail['ubtlat'];
906 1217
 			$data['longitude'] = $sail['ubtlon'];
907 1218
 			$data['type_id'] = 36;
@@ -910,16 +1221,24 @@  discard block
 block discarded – undo
910 1221
 			$data['captain_name'] = $sail['usrname'];
911 1222
 			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat','32&#39; Offshore Racer');
912 1223
 			$boattype = $sail['ubtbtpnr'];
913
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
1224
+			if (isset($allboats[$boattype-1])) {
1225
+				$data['type'] = $allboats[$boattype-1];
1226
+			}
914 1227
 			$data['speed'] = round($sail['ubtspeed']*3.6,2);
915 1228
 			$data['format_source'] = 'sailaway';
916 1229
 			$data['id_source'] = $id_source;
917
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1230
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1231
+				$data['noarchive'] = true;
1232
+			}
918 1233
 			$MI->add($data);
919 1234
 			unset($data);
920 1235
 		    }
921
-		} elseif ($globalDebug) echo 'Error in JSON parsing';
922
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
1236
+		} elseif ($globalDebug) {
1237
+			echo 'Error in JSON parsing';
1238
+		}
1239
+	    } elseif ($globalDebug) {
1240
+	    	echo 'Empty result !'."\n";
1241
+	    }
923 1242
     	    $last_exec[$id]['last'] = time();
924 1243
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
925 1244
 	} elseif (
@@ -947,16 +1266,28 @@  discard block
 block discarded – undo
947 1266
     		    $line = explode(':', $line);
948 1267
     		    if (count($line) > 30 && $line[0] != 'callsign') {
949 1268
 			$data = array();
950
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
951
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1269
+			if (isset($line[37]) && $line[37] != '') {
1270
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1271
+			} else {
1272
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1273
+			}
952 1274
 			$data['pilot_id'] = $line[1];
953 1275
 			$data['pilot_name'] = $line[2];
954 1276
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
955 1277
 			$data['ident'] = $line[0]; // ident
956
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1278
+			if ($line[7] != '' && $line[7] != 0) {
1279
+				$data['altitude'] = $line[7];
1280
+			}
1281
+			// altitude
957 1282
 			$data['speed'] = $line[8]; // speed
958
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
959
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1283
+			if (isset($line[45])) {
1284
+				$data['heading'] = $line[45];
1285
+			}
1286
+			// heading
1287
+			elseif (isset($line[38])) {
1288
+				$data['heading'] = $line[38];
1289
+			}
1290
+			// heading
960 1291
 			$data['latitude'] = $line[5]; // lat
961 1292
 	        	$data['longitude'] = $line[6]; // long
962 1293
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -972,7 +1303,9 @@  discard block
 block discarded – undo
972 1303
 			$data['frequency'] = $line[4];
973 1304
 			$data['type'] = $line[18];
974 1305
 			$data['range'] = $line[19];
975
-			if (isset($line[35])) $data['info'] = $line[35];
1306
+			if (isset($line[35])) {
1307
+				$data['info'] = $line[35];
1308
+			}
976 1309
     			$data['id_source'] = $id_source;
977 1310
 	    		//$data['arrival_airport_time'] = ;
978 1311
 	    		if ($line[9] != '') {
@@ -990,27 +1323,47 @@  discard block
 block discarded – undo
990 1323
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
991 1324
 	    		*/
992 1325
 	    		$data['format_source'] = $value['format'];
993
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
994
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
995
-    			if ($line[3] === 'PILOT') $SI->add($data);
996
-			elseif ($line[3] === 'ATC') {
1326
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1327
+				$data['noarchive'] = true;
1328
+			}
1329
+			if (isset($value['name']) && $value['name'] != '') {
1330
+				$data['source_name'] = $value['name'];
1331
+			}
1332
+    			if ($line[3] === 'PILOT') {
1333
+    				$SI->add($data);
1334
+    			} elseif ($line[3] === 'ATC') {
997 1335
 				//print_r($data);
998 1336
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
999 1337
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
1000 1338
 				$typec = substr($data['ident'],-3);
1001
-				if ($typec === 'APP') $data['type'] = 'Approach';
1002
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
1003
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
1004
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
1005
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1006
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
1007
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1008
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1009
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
1010
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1339
+				if ($typec === 'APP') {
1340
+					$data['type'] = 'Approach';
1341
+				} elseif ($typec === 'TWR') {
1342
+					$data['type'] = 'Tower';
1343
+				} elseif ($typec === 'OBS') {
1344
+					$data['type'] = 'Observer';
1345
+				} elseif ($typec === 'GND') {
1346
+					$data['type'] = 'Ground';
1347
+				} elseif ($typec === 'DEL') {
1348
+					$data['type'] = 'Delivery';
1349
+				} elseif ($typec === 'DEP') {
1350
+					$data['type'] = 'Departure';
1351
+				} elseif ($typec === 'FSS') {
1352
+					$data['type'] = 'Flight Service Station';
1353
+				} elseif ($typec === 'CTR') {
1354
+					$data['type'] = 'Control Radar or Centre';
1355
+				} elseif ($data['type'] === '') {
1356
+					$data['type'] = 'Observer';
1357
+				}
1358
+				if (!isset($data['source_name'])) {
1359
+					$data['source_name'] = '';
1360
+				}
1011 1361
 				if (isset($ATC)) {
1012
-					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']);
1013
-					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']);
1362
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1363
+						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']);
1364
+					} else {
1365
+						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']);
1366
+					}
1014 1367
 				}
1015 1368
 			}
1016 1369
     			unset($data);
@@ -1037,14 +1390,20 @@  discard block
 block discarded – undo
1037 1390
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
1038 1391
 			$data['latitude'] = (float)$line['pktLatitude'];
1039 1392
 			$data['longitude'] = (float)$line['pktLongitude'];
1040
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
1041
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1393
+			if ((float)$line['pktTrack'] != 0) {
1394
+				$data['heading'] = (float)$line['pktTrack'];
1395
+			}
1396
+			if ((int)$line['pktSpeed'] != 0) {
1397
+				$data['speed'] = (int)$line['pktSpeed'];
1398
+			}
1042 1399
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
1043 1400
 			$data['altitude_relative'] = 'AMSL';
1044 1401
 			$data['pilot_id'] = (int)$line['pktPilotID'];
1045 1402
 			$data['aircraft_icao'] = 'PARAGLIDER';
1046 1403
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1047
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1404
+			if (isset($pilot_data[4])) {
1405
+				$data['pilot_name'] = $pilot_data[4];
1406
+			}
1048 1407
 			$data['format_source'] = $value['format'];
1049 1408
 			$SI->add($data);
1050 1409
 			unset($data);
@@ -1092,25 +1451,59 @@  discard block
 block discarded – undo
1092 1451
 		    foreach ($all_data['acList'] as $line) {
1093 1452
 			$data = array();
1094 1453
 			$data['hex'] = $line['Icao']; // hex
1095
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1096
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1097
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1098
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1099
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1100
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1454
+			if (isset($line['Call'])) {
1455
+				$data['ident'] = $line['Call'];
1456
+			}
1457
+			// ident
1458
+			if (isset($line['Alt'])) {
1459
+				$data['altitude'] = $line['Alt'];
1460
+			}
1461
+			// altitude
1462
+			if (isset($line['Spd'])) {
1463
+				$data['speed'] = $line['Spd'];
1464
+			}
1465
+			// speed
1466
+			if (isset($line['Trak'])) {
1467
+				$data['heading'] = $line['Trak'];
1468
+			}
1469
+			// heading
1470
+			if (isset($line['Lat'])) {
1471
+				$data['latitude'] = $line['Lat'];
1472
+			}
1473
+			// lat
1474
+			if (isset($line['Long'])) {
1475
+				$data['longitude'] = $line['Long'];
1476
+			}
1477
+			// long
1101 1478
 			//$data['verticalrate'] = $line['']; // verticale rate
1102
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1479
+			if (isset($line['Sqk'])) {
1480
+				$data['squawk'] = $line['Sqk'];
1481
+			}
1482
+			// squawk
1103 1483
 			$data['emergency'] = ''; // emergency
1104
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1105
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1106
-			else $data['datetime'] = date('Y-m-d H:i:s');
1484
+			if (isset($line['Reg'])) {
1485
+				$data['registration'] = $line['Reg'];
1486
+			}
1487
+			if (isset($line['PosTime'])) {
1488
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1489
+			} else {
1490
+				$data['datetime'] = date('Y-m-d H:i:s');
1491
+			}
1107 1492
 			//$data['datetime'] = date('Y-m-d H:i:s');
1108
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1493
+			if (isset($line['Type'])) {
1494
+				$data['aircraft_icao'] = $line['Type'];
1495
+			}
1109 1496
 			$data['format_source'] = 'aircraftlistjson';
1110 1497
 			$data['id_source'] = $id_source;
1111
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1112
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1113
-			if (isset($data['latitude'])) $SI->add($data);
1498
+			if (isset($value['name']) && $value['name'] != '') {
1499
+				$data['source_name'] = $value['name'];
1500
+			}
1501
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1502
+				$data['noarchive'] = true;
1503
+			}
1504
+			if (isset($data['latitude'])) {
1505
+				$SI->add($data);
1506
+			}
1114 1507
 			unset($data);
1115 1508
 		    }
1116 1509
 		} elseif (is_array($all_data)) {
@@ -1127,17 +1520,26 @@  discard block
 block discarded – undo
1127 1520
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1128 1521
 			$data['squawk'] = $line['squawk']; // squawk
1129 1522
 			$data['emergency'] = ''; // emergency
1130
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1131
-			else $data['datetime'] = date('Y-m-d H:i:s');
1523
+			if (isset($line['PosTime'])) {
1524
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1525
+			} else {
1526
+				$data['datetime'] = date('Y-m-d H:i:s');
1527
+			}
1132 1528
 			$data['format_source'] = 'aircraftlistjson';
1133 1529
 			$data['id_source'] = $id_source;
1134
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1135
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1530
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1531
+				$data['noarchive'] = true;
1532
+			}
1533
+			if (isset($value['name']) && $value['name'] != '') {
1534
+				$data['source_name'] = $value['name'];
1535
+			}
1136 1536
 			$SI->add($data);
1137 1537
 			unset($data);
1138 1538
 		    }
1139 1539
 		}
1140
-	    } elseif ($globalDebug) echo 'No data'."\n";
1540
+	    } elseif ($globalDebug) {
1541
+	    	echo 'No data'."\n";
1542
+	    }
1141 1543
     	    //$last_exec['aircraftlistjson'] = time();
1142 1544
     	    $last_exec[$id]['last'] = time();
1143 1545
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -1173,8 +1575,12 @@  discard block
 block discarded – undo
1173 1575
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1174 1576
 	    	    $data['format_source'] = 'planeupdatefaa';
1175 1577
     		    $data['id_source'] = $id_source;
1176
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1177
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1578
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1579
+		    	$data['noarchive'] = true;
1580
+		    }
1581
+		    if (isset($value['name']) && $value['name'] != '') {
1582
+		    	$data['source_name'] = $value['name'];
1583
+		    }
1178 1584
 		    $SI->add($data);
1179 1585
 		    unset($data);
1180 1586
 		}
@@ -1208,7 +1614,9 @@  discard block
 block discarded – undo
1208 1614
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1209 1615
 		    $data['format_source'] = 'opensky';
1210 1616
 		    $data['id_source'] = $id_source;
1211
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1617
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1618
+		    	$data['noarchive'] = true;
1619
+		    }
1212 1620
 		    $SI->add($data);
1213 1621
 		    unset($data);
1214 1622
 		}
@@ -1228,15 +1636,42 @@  discard block
 block discarded – undo
1228 1636
 		foreach ($all_data['aircraft'] as $key => $line) {
1229 1637
 		    $data = array();
1230 1638
 		    // add support for ground vehicule with ~ in front of hex
1231
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1232
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1233
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1234
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1235
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1236
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1237
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1238
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1239
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1639
+		    if (isset($line['hex'])) {
1640
+		    	$data['hex'] = $line['hex'];
1641
+		    }
1642
+		    // hex
1643
+		    if (isset($line['flight'])) {
1644
+		    	$data['ident'] = trim($line['flight']);
1645
+		    }
1646
+		    // ident
1647
+		    if (isset($line['altitude'])) {
1648
+		    	$data['altitude'] = $line['altitude'];
1649
+		    }
1650
+		    // altitude
1651
+		    if (isset($line['speed'])) {
1652
+		    	$data['speed'] = $line['speed'];
1653
+		    }
1654
+		    // speed
1655
+		    if (isset($line['track'])) {
1656
+		    	$data['heading'] = $line['track'];
1657
+		    }
1658
+		    // heading
1659
+		    if (isset($line['lat'])) {
1660
+		    	$data['latitude'] = $line['lat'];
1661
+		    }
1662
+		    // lat
1663
+		    if (isset($line['lon'])) {
1664
+		    	$data['longitude'] = $line['lon'];
1665
+		    }
1666
+		    // long
1667
+		    if (isset($line['vert_rate'])) {
1668
+		    	$data['verticalrate'] = $line['vert_rate'];
1669
+		    }
1670
+		    // verticale rate
1671
+		    if (isset($line['squawk'])) {
1672
+		    	$data['squawk'] = $line['squawk'];
1673
+		    }
1674
+		    // squawk
1240 1675
 		    //$data['emergency'] = ''; // emergency
1241 1676
 		    //$data['registration'] = $line[2];
1242 1677
 		    //$data['aircraft_icao'] = $line[0];
@@ -1244,10 +1679,17 @@  discard block
 block discarded – undo
1244 1679
 		    $data['format_source'] = 'aircraftjson';
1245 1680
 		    $data['id_source'] = $id_source;
1246 1681
 		    if (isset($value['name']) && $value['name'] != '') {
1247
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1248
-			    else $data['source_name'] = $value['name'];
1249
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1250
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1682
+			    if (isset($line['mlat']) && !empty($line['mlat'])) {
1683
+			    	$data['source_name'] = $value['name'].'_MLAT';
1684
+			    } else {
1685
+			    	$data['source_name'] = $value['name'];
1686
+			    }
1687
+		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) {
1688
+		    	$data['source_name'] = 'MLAT';
1689
+		    }
1690
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1691
+		    	$data['noarchive'] = true;
1692
+		    }
1251 1693
 		    $SI->add($data);
1252 1694
 		    unset($data);
1253 1695
 		}
@@ -1267,22 +1709,54 @@  discard block
 block discarded – undo
1267 1709
 		foreach ($all_data['aircraft'] as $key => $line) {
1268 1710
 		    $data = array();
1269 1711
 		    $data['hex'] = $key; // hex
1270
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1271
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1272
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1273
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1274
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1275
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1276
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1277
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1712
+		    if (isset($line['callsign'])) {
1713
+		    	$data['ident'] = trim($line['callsign']);
1714
+		    }
1715
+		    // ident
1716
+		    if (isset($line['altitude'])) {
1717
+		    	$data['altitude'] = $line['altitude'];
1718
+		    }
1719
+		    // altitude
1720
+		    if (isset($line['speed'])) {
1721
+		    	$data['speed'] = $line['speed'];
1722
+		    }
1723
+		    // speed
1724
+		    if (isset($line['heading'])) {
1725
+		    	$data['heading'] = $line['heading'];
1726
+		    }
1727
+		    // heading
1728
+		    if (isset($line['lat'])) {
1729
+		    	$data['latitude'] = $line['lat'];
1730
+		    }
1731
+		    // lat
1732
+		    if (isset($line['lon'])) {
1733
+		    	$data['longitude'] = $line['lon'];
1734
+		    }
1735
+		    // long
1736
+		    if (isset($line['vert_rate'])) {
1737
+		    	$data['verticalrate'] = $line['vert_rate'];
1738
+		    }
1739
+		    // verticale rate
1740
+		    if (isset($line['squawk'])) {
1741
+		    	$data['squawk'] = $line['squawk'];
1742
+		    }
1743
+		    // squawk
1278 1744
 		    //$data['emergency'] = ''; // emergency
1279
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1280
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1745
+		    if (isset($line['reg'])) {
1746
+		    	$data['registration'] = $line['reg'];
1747
+		    }
1748
+		    if (isset($line['type'])) {
1749
+		    	$data['aircraft_icao'] = $line['type'];
1750
+		    }
1281 1751
 		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1282 1752
 		    $data['format_source'] = 'planefinderclient';
1283 1753
 		    $data['id_source'] = $id_source;
1284
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1285
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1754
+		    if (isset($value['name']) && $value['name'] != '') {
1755
+		    	$data['source_name'] = $value['name'];
1756
+		    }
1757
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1758
+		    	$data['noarchive'] = true;
1759
+		    }
1286 1760
 		    $SI->add($data);
1287 1761
 		    unset($data);
1288 1762
 		}
@@ -1298,7 +1772,9 @@  discard block
 block discarded – undo
1298 1772
 	    //$buffer = $Common->getData($hosts[$id]);
1299 1773
 	    $buffer = $Common->getData($value['host']);
1300 1774
 	    $all_data = json_decode($buffer,true);
1301
-	    if (!empty($all_data)) $reset = 0;
1775
+	    if (!empty($all_data)) {
1776
+	    	$reset = 0;
1777
+	    }
1302 1778
 	    foreach ($all_data as $key => $line) {
1303 1779
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1304 1780
 		    $data = array();
@@ -1319,8 +1795,12 @@  discard block
 block discarded – undo
1319 1795
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1320 1796
 	    	    $data['format_source'] = 'fr24json';
1321 1797
     		    $data['id_source'] = $id_source;
1322
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1323
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1798
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1799
+		    	$data['noarchive'] = true;
1800
+		    }
1801
+		    if (isset($value['name']) && $value['name'] != '') {
1802
+		    	$data['source_name'] = $value['name'];
1803
+		    }
1324 1804
 		    $SI->add($data);
1325 1805
 		    unset($data);
1326 1806
 		}
@@ -1349,24 +1829,42 @@  discard block
 block discarded – undo
1349 1829
 		    if (isset($line['inf'])) {
1350 1830
 			$data = array();
1351 1831
 			$data['hex'] = $line['inf']['ia'];
1352
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1832
+			if (isset($line['inf']['cs'])) {
1833
+				$data['ident'] = $line['inf']['cs'];
1834
+			}
1835
+			//$line[13]
1353 1836
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1354
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1355
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1837
+	    		if (isset($line['inf']['gs'])) {
1838
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1839
+	    		}
1840
+	    		// speed
1841
+	    		if (isset($line['inf']['tr'])) {
1842
+	    			$data['heading'] = $line['inf']['tr'];
1843
+	    		}
1844
+	    		// heading
1356 1845
 	    		$data['latitude'] = $line['pt'][0]; // lat
1357 1846
 	    		$data['longitude'] = $line['pt'][1]; // long
1358 1847
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1359
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1848
+	    		if (isset($line['inf']['sq'])) {
1849
+	    			$data['squawk'] = $line['inf']['sq'];
1850
+	    		}
1851
+	    		// squawk
1360 1852
 	    		//$data['aircraft_icao'] = $line[8];
1361
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1853
+	    		if (isset($line['inf']['rc'])) {
1854
+	    			$data['registration'] = $line['inf']['rc'];
1855
+	    		}
1362 1856
 			//$data['departure_airport_iata'] = $line[11];
1363 1857
 			//$data['arrival_airport_iata'] = $line[12];
1364 1858
 	    		//$data['emergency'] = ''; // emergency
1365 1859
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1366 1860
 	    		$data['format_source'] = 'radarvirtueljson';
1367 1861
     			$data['id_source'] = $id_source;
1368
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1369
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1862
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1863
+				$data['noarchive'] = true;
1864
+			}
1865
+			if (isset($value['name']) && $value['name'] != '') {
1866
+				$data['source_name'] = $value['name'];
1867
+			}
1370 1868
 			$SI->add($data);
1371 1869
 			unset($data);
1372 1870
 		    }
@@ -1392,30 +1890,65 @@  discard block
 block discarded – undo
1392 1890
 		    $data['id'] = $line['id'];
1393 1891
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1394 1892
 		    $data['ident'] = $line['callsign']; // ident
1395
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1396
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1397
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1398
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1399
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1400
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1893
+		    if (isset($line['pilotid'])) {
1894
+		    	$data['pilot_id'] = $line['pilotid'];
1895
+		    }
1896
+		    // pilot id
1897
+		    if (isset($line['name'])) {
1898
+		    	$data['pilot_name'] = $line['name'];
1899
+		    }
1900
+		    // pilot name
1901
+		    if (isset($line['alt'])) {
1902
+		    	$data['altitude'] = $line['alt'];
1903
+		    }
1904
+		    // altitude
1905
+		    if (isset($line['gs'])) {
1906
+		    	$data['speed'] = $line['gs'];
1907
+		    }
1908
+		    // speed
1909
+		    if (isset($line['heading'])) {
1910
+		    	$data['heading'] = $line['heading'];
1911
+		    }
1912
+		    // heading
1913
+		    if (isset($line['route'])) {
1914
+		    	$data['waypoints'] = $line['route'];
1915
+		    }
1916
+		    // route
1401 1917
 		    $data['latitude'] = $line['lat']; // lat
1402 1918
 		    $data['longitude'] = $line['lon']; // long
1403 1919
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1404 1920
 		    //$data['squawk'] = $line['squawk']; // squawk
1405 1921
 		    //$data['emergency'] = ''; // emergency
1406
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1407
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1408
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1922
+		    if (isset($line['depicao'])) {
1923
+		    	$data['departure_airport_icao'] = $line['depicao'];
1924
+		    }
1925
+		    if (isset($line['deptime'])) {
1926
+		    	$data['departure_airport_time'] = $line['deptime'];
1927
+		    }
1928
+		    if (isset($line['arricao'])) {
1929
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1930
+		    }
1409 1931
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1410
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1411
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1412
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1413
-		    else $data['info'] = '';
1932
+		    if (isset($line['aircraft'])) {
1933
+		    	$data['aircraft_icao'] = $line['aircraft'];
1934
+		    }
1935
+		    if (isset($line['transponder'])) {
1936
+		    	$data['squawk'] = $line['transponder'];
1937
+		    }
1938
+		    if (isset($line['atis'])) {
1939
+		    	$data['info'] = $line['atis'];
1940
+		    } else {
1941
+		    	$data['info'] = '';
1942
+		    }
1414 1943
 		    $data['format_source'] = 'pireps';
1415 1944
     		    $data['id_source'] = $id_source;
1416 1945
 		    $data['datetime'] = date('Y-m-d H:i:s');
1417
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1418
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1946
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1947
+		    	$data['noarchive'] = true;
1948
+		    }
1949
+		    if (isset($value['name']) && $value['name'] != '') {
1950
+		    	$data['source_name'] = $value['name'];
1951
+		    }
1419 1952
 		    if ($line['icon'] === 'plane') {
1420 1953
 			$SI->add($data);
1421 1954
 		    //    print_r($data);
@@ -1424,16 +1957,28 @@  discard block
 block discarded – undo
1424 1957
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1425 1958
 			$typec = substr($data['ident'],-3);
1426 1959
 			$data['type'] = '';
1427
-			if ($typec === 'APP') $data['type'] = 'Approach';
1428
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1429
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1430
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1431
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1432
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1433
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1434
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1435
-			else $data['type'] = 'Observer';
1436
-			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']);
1960
+			if ($typec === 'APP') {
1961
+				$data['type'] = 'Approach';
1962
+			} elseif ($typec === 'TWR') {
1963
+				$data['type'] = 'Tower';
1964
+			} elseif ($typec === 'OBS') {
1965
+				$data['type'] = 'Observer';
1966
+			} elseif ($typec === 'GND') {
1967
+				$data['type'] = 'Ground';
1968
+			} elseif ($typec === 'DEL') {
1969
+				$data['type'] = 'Delivery';
1970
+			} elseif ($typec === 'DEP') {
1971
+				$data['type'] = 'Departure';
1972
+			} elseif ($typec === 'FSS') {
1973
+				$data['type'] = 'Flight Service Station';
1974
+			} elseif ($typec === 'CTR') {
1975
+				$data['type'] = 'Control Radar or Centre';
1976
+			} else {
1977
+				$data['type'] = 'Observer';
1978
+			}
1979
+			if (isset($ATC)) {
1980
+				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']);
1981
+			}
1437 1982
 		    }
1438 1983
 		    unset($data);
1439 1984
 		}
@@ -1448,7 +1993,9 @@  discard block
 block discarded – undo
1448 1993
 	    )
1449 1994
 	) {
1450 1995
 	    //$buffer = $Common->getData($hosts[$id]);
1451
-	    if ($globalDebug) echo 'Get Data...'."\n";
1996
+	    if ($globalDebug) {
1997
+	    	echo 'Get Data...'."\n";
1998
+	    }
1452 1999
 	    $buffer = $Common->getData($value['host']);
1453 2000
 	    $all_data = json_decode($buffer,true);
1454 2001
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1456,11 +2003,18 @@  discard block
 block discarded – undo
1456 2003
 		foreach ($all_data as $line) {
1457 2004
 	    	    $data = array();
1458 2005
 	    	    //$data['id'] = $line['id']; // id not usable
1459
-	    	    if (isset($line['pilotid']) && isset($line['registration'])) $data['id'] = $line['pilotid'].$line['flightnum'].trim($line['registration']);
1460
-	    	    elseif (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
2006
+	    	    if (isset($line['pilotid']) && isset($line['registration'])) {
2007
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'].trim($line['registration']);
2008
+	    	    } elseif (isset($line['pilotid'])) {
2009
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
2010
+	    	    }
1461 2011
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1462
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1463
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
2012
+	    	    if (isset($line['pilotname'])) {
2013
+	    	    	$data['pilot_name'] = $line['pilotname'];
2014
+	    	    }
2015
+	    	    if (isset($line['pilotid'])) {
2016
+	    	    	$data['pilot_id'] = $line['pilotid'];
2017
+	    	    }
1464 2018
 	    	    $data['ident'] = $line['flightnum']; // ident
1465 2019
 	    	    $data['altitude'] = $line['alt']; // altitude
1466 2020
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1476,7 +2030,9 @@  discard block
 block discarded – undo
1476 2030
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1477 2031
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1478 2032
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1479
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
2033
+	    	    } else {
2034
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
2035
+	    	    }
1480 2036
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1481 2037
 	    	    $data['departure_airport_time'] = $line['deptime'];
1482 2038
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1484,29 +2040,47 @@  discard block
 block discarded – undo
1484 2040
     		    if (isset($line['registration'])) {
1485 2041
     			$data['registration'] = trim($line['registration']);
1486 2042
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1487
-    		    } else $data['registration'] = $line['aircraft'];
1488
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1489
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2043
+    		    } else {
2044
+    		    	$data['registration'] = $line['aircraft'];
2045
+    		    }
2046
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2047
+		    	$data['noarchive'] = true;
2048
+		    }
2049
+		    if (isset($line['route'])) {
2050
+		    	$data['waypoints'] = $line['route'];
2051
+		    }
2052
+		    // route
1490 2053
 		    if (isset($line['aircraftname'])) {
1491 2054
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1492 2055
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1493 2056
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1494
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1495
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1496
-	    		else {
2057
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
2058
+	    			$data['aircraft_icao'] = $aircraft_data[0];
2059
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
2060
+	    			$data['aircraft_icao'] = $aircraft_data[1];
2061
+	    		} else {
1497 2062
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1498
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1499
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
2063
+	    		    if (isset($aircraft_data[1])) {
2064
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
2065
+	    		    } else {
2066
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
2067
+	    		    }
1500 2068
 	    		}
1501 2069
 	    	    }
1502
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
2070
+    		    if (isset($line['route'])) {
2071
+    		    	$data['waypoints'] = $line['route'];
2072
+    		    }
1503 2073
     		    $data['id_source'] = $id_source;
1504 2074
 	    	    $data['format_source'] = 'phpvmacars';
1505
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2075
+		    if (isset($value['name']) && $value['name'] != '') {
2076
+		    	$data['source_name'] = $value['name'];
2077
+		    }
1506 2078
 		    $SI->add($data);
1507 2079
 		    unset($data);
1508 2080
 		}
1509
-		if ($globalDebug) echo 'No more data...'."\n";
2081
+		if ($globalDebug) {
2082
+			echo 'No more data...'."\n";
2083
+		}
1510 2084
 		unset($buffer);
1511 2085
 		unset($all_data);
1512 2086
 	    }
@@ -1519,7 +2093,9 @@  discard block
 block discarded – undo
1519 2093
 	    )
1520 2094
 	) {
1521 2095
 	    //$buffer = $Common->getData($hosts[$id]);
1522
-	    if ($globalDebug) echo 'Get Data...'."\n";
2096
+	    if ($globalDebug) {
2097
+	    	echo 'Get Data...'."\n";
2098
+	    }
1523 2099
 	    $buffer = $Common->getData($value['host']);
1524 2100
 	    $all_data = json_decode($buffer,true);
1525 2101
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1530,10 +2106,16 @@  discard block
 block discarded – undo
1530 2106
 	    	    //$data['id'] = $line['id']; // id not usable
1531 2107
 	    	    $data['id'] = $line['id'];
1532 2108
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1533
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1534
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
2109
+	    	    if (isset($line['user']['username'])) {
2110
+	    	    	$data['pilot_name'] = $line['user']['username'];
2111
+	    	    }
2112
+	    	    if (isset($line['user_id'])) {
2113
+	    	    	$data['pilot_id'] = $line['user_id'];
2114
+	    	    }
1535 2115
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1536
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
2116
+	    	    if (is_numeric($data['ident'])) {
2117
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
2118
+	    	    }
1537 2119
 	    	    $data['altitude'] = $line['altitude']; // altitude
1538 2120
 	    	    $data['speed'] = $line['groundspeed']; // speed
1539 2121
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1546,7 +2128,9 @@  discard block
 block discarded – undo
1546 2128
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1547 2129
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1548 2130
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1549
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
2131
+	    	    } else {
2132
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
2133
+	    	    }
1550 2134
 	    	    
1551 2135
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1552 2136
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1554,17 +2138,26 @@  discard block
 block discarded – undo
1554 2138
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1555 2139
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1556 2140
 
1557
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1558
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
2141
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2142
+		    	$data['noarchive'] = true;
2143
+		    }
2144
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
2145
+		    	$data['waypoints'] = $line['bid']['route'];
2146
+		    }
2147
+		    // route
1559 2148
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1560 2149
 
1561 2150
     		    $data['id_source'] = $id_source;
1562 2151
 	    	    $data['format_source'] = 'vaos';
1563
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2152
+		    if (isset($value['name']) && $value['name'] != '') {
2153
+		    	$data['source_name'] = $value['name'];
2154
+		    }
1564 2155
 		    $SI->add($data);
1565 2156
 		    unset($data);
1566 2157
 		}
1567
-		if ($globalDebug) echo 'No more data...'."\n";
2158
+		if ($globalDebug) {
2159
+			echo 'No more data...'."\n";
2160
+		}
1568 2161
 		unset($buffer);
1569 2162
 		unset($all_data);
1570 2163
 	    }
@@ -1577,7 +2170,9 @@  discard block
 block discarded – undo
1577 2170
 	    )
1578 2171
 	) {
1579 2172
 	    //$buffer = $Common->getData($hosts[$id]);
1580
-	    if ($globalDebug) echo 'Get Data...'."\n";
2173
+	    if ($globalDebug) {
2174
+	    	echo 'Get Data...'."\n";
2175
+	    }
1581 2176
 	    $buffer = $Common->getData($value['host']);
1582 2177
 	    $all_data = json_decode($buffer,true);
1583 2178
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1606,16 +2201,25 @@  discard block
 block discarded – undo
1606 2201
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1607 2202
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1608 2203
     		    //$data['registration'] = $line['aircraft'];
1609
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2204
+		    if (isset($line['route'])) {
2205
+		    	$data['waypoints'] = $line['route'];
2206
+		    }
2207
+		    // route
1610 2208
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1611 2209
     		    $data['id_source'] = $id_source;
1612 2210
 	    	    $data['format_source'] = 'vam';
1613
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1614
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2211
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2212
+		    	$data['noarchive'] = true;
2213
+		    }
2214
+		    if (isset($value['name']) && $value['name'] != '') {
2215
+		    	$data['source_name'] = $value['name'];
2216
+		    }
1615 2217
 		    $SI->add($data);
1616 2218
 		    unset($data);
1617 2219
 		}
1618
-		if ($globalDebug) echo 'No more data...'."\n";
2220
+		if ($globalDebug) {
2221
+			echo 'No more data...'."\n";
2222
+		}
1619 2223
 		unset($buffer);
1620 2224
 		unset($all_data);
1621 2225
 	    }
@@ -1628,7 +2232,9 @@  discard block
 block discarded – undo
1628 2232
 	    )
1629 2233
 	) {
1630 2234
 	    //$buffer = $Common->getData($hosts[$id]);
1631
-	    if ($globalDebug) echo 'Get Data...'."\n";
2235
+	    if ($globalDebug) {
2236
+	    	echo 'Get Data...'."\n";
2237
+	    }
1632 2238
 	    $buffer = $Common->getData($value['host']);
1633 2239
 	    $all_data = json_decode($buffer,true);
1634 2240
 	    if ($buffer != '') {
@@ -1646,12 +2252,16 @@  discard block
 block discarded – undo
1646 2252
 			$data['id_source'] = $id_source;
1647 2253
 			$data['format_source'] = 'blitzortung';
1648 2254
 			$SI->add($data);
1649
-			if ($globalDebug) echo '☈ Lightning added'."\n";
2255
+			if ($globalDebug) {
2256
+				echo '☈ Lightning added'."\n";
2257
+			}
1650 2258
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1651 2259
 			unset($data);
1652 2260
 		    }
1653 2261
 		}
1654
-		if ($globalDebug) echo 'No more data...'."\n";
2262
+		if ($globalDebug) {
2263
+			echo 'No more data...'."\n";
2264
+		}
1655 2265
 		unset($buffer);
1656 2266
 	    }
1657 2267
 	    $last_exec[$id]['last'] = time();
@@ -1680,10 +2290,15 @@  discard block
 block discarded – undo
1680 2290
                 }
1681 2291
             } else {
1682 2292
                 $format = $value['format'];
1683
-                if (isset($tt[$format])) $tt[$format]++;
1684
-                else $tt[$format] = 0;
2293
+                if (isset($tt[$format])) {
2294
+                	$tt[$format]++;
2295
+                } else {
2296
+                	$tt[$format] = 0;
2297
+                }
1685 2298
                 if ($tt[$format] > 30) {
1686
-                    if ($globalDebug) echo 'Reconnect...'."\n";
2299
+                    if ($globalDebug) {
2300
+                    	echo 'Reconnect...'."\n";
2301
+                    }
1687 2302
                     sleep(2);
1688 2303
                     //$sourceeen[] = $value;
1689 2304
                     //connect_all($sourceeen);
@@ -1700,7 +2315,9 @@  discard block
 block discarded – undo
1700 2315
 	    $write = NULL;
1701 2316
 	    $e = NULL;
1702 2317
 	    $n = socket_select($read, $write, $e, $timeout);
1703
-	    if ($e != NULL) var_dump($e);
2318
+	    if ($e != NULL) {
2319
+	    	var_dump($e);
2320
+	    }
1704 2321
 	    if ($n > 0) {
1705 2322
 		$reset = 0;
1706 2323
 		foreach ($read as $nb => $r) {
@@ -1722,13 +2339,17 @@  discard block
 block discarded – undo
1722 2339
 		    if ($buffer !== FALSE) {
1723 2340
 			if ($format === 'vrstcp') {
1724 2341
 			    $buffer = explode('},{',$buffer);
1725
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2342
+			} else {
2343
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2344
+			}
1726 2345
 		    }
1727 2346
 		    // SBS format is CSV format
1728 2347
 		    if ($buffer !== FALSE && $buffer !== '') {
1729 2348
 			$tt[$format] = 0;
1730 2349
 			if ($format === 'acarssbs3') {
1731
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2350
+			    if ($globalDebug) {
2351
+			    	echo 'ACARS : '.$buffer."\n";
2352
+			    }
1732 2353
 			    $ACARS->add(trim($buffer));
1733 2354
 			    $ACARS->deleteLiveAcarsData();
1734 2355
 			} elseif ($format === 'raw') {
@@ -1738,9 +2359,15 @@  discard block
 block discarded – undo
1738 2359
 				//if (!empty($data)) print_r($data);
1739 2360
 				$data['datetime'] = date('Y-m-d H:i:s');
1740 2361
 				$data['format_source'] = 'raw';
1741
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1742
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1743
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2362
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2363
+					$data['source_name'] = $globalSources[$nb]['name'];
2364
+				}
2365
+				if (isset($globalSources[$nb]['sourcestats'])) {
2366
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2367
+				}
2368
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2369
+					$data['noarchive'] = true;
2370
+				}
1744 2371
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1745 2372
 				$SI->add($data);
1746 2373
 				unset($data);
@@ -1748,22 +2375,54 @@  discard block
 block discarded – undo
1748 2375
 			} elseif ($format === 'ais') {
1749 2376
 			    $ais_data = $AIS->parse_line(trim($buffer));
1750 2377
 			    $data = array();
1751
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1752
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1753
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1754
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1755
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1756
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1757
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1758
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1759
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1760
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1761
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1762
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1763
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1764
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1765
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1766
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2378
+			    if (isset($ais_data['ident'])) {
2379
+			    	$data['ident'] = $ais_data['ident'];
2380
+			    }
2381
+			    if (isset($ais_data['mmsi'])) {
2382
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2383
+			    }
2384
+			    if (isset($ais_data['speed'])) {
2385
+			    	$data['speed'] = $ais_data['speed'];
2386
+			    }
2387
+			    if (isset($ais_data['heading'])) {
2388
+			    	$data['heading'] = $ais_data['heading'];
2389
+			    }
2390
+			    if (isset($ais_data['latitude'])) {
2391
+			    	$data['latitude'] = $ais_data['latitude'];
2392
+			    }
2393
+			    if (isset($ais_data['longitude'])) {
2394
+			    	$data['longitude'] = $ais_data['longitude'];
2395
+			    }
2396
+			    if (isset($ais_data['status'])) {
2397
+			    	$data['status'] = $ais_data['status'];
2398
+			    }
2399
+			    if (isset($ais_data['statusid'])) {
2400
+			    	$data['status_id'] = $ais_data['statusid'];
2401
+			    }
2402
+			    if (isset($ais_data['type'])) {
2403
+			    	$data['type'] = $ais_data['type'];
2404
+			    }
2405
+			    if (isset($ais_data['imo'])) {
2406
+			    	$data['imo'] = $ais_data['imo'];
2407
+			    }
2408
+			    if (isset($ais_data['callsign'])) {
2409
+			    	$data['callsign'] = $ais_data['callsign'];
2410
+			    }
2411
+			    if (isset($ais_data['destination'])) {
2412
+			    	$data['arrival_code'] = $ais_data['destination'];
2413
+			    }
2414
+			    if (isset($ais_data['eta_ts'])) {
2415
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2416
+			    }
2417
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2418
+			    	$data['noarchive'] = true;
2419
+			    }
2420
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2421
+			    	$data['source_name'] = $globalSources[$nb]['name'];
2422
+			    }
2423
+			    if (isset($globalSources[$nb]['sourcestats'])) {
2424
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2425
+			    }
1767 2426
 
1768 2427
 			    if (isset($ais_data['timestamp'])) {
1769 2428
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1772,7 +2431,9 @@  discard block
 block discarded – undo
1772 2431
 			    }
1773 2432
 			    $data['format_source'] = 'aisnmea';
1774 2433
     			    $data['id_source'] = $id_source;
1775
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2434
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2435
+			    	$MI->add($data);
2436
+			    }
1776 2437
 			    unset($data);
1777 2438
                         } elseif ($format === 'flightgearsp') {
1778 2439
                     	    //echo $buffer."\n";
@@ -1790,17 +2451,25 @@  discard block
 block discarded – undo
1790 2451
 				$data['speed'] = round($line[5]*1.94384);
1791 2452
 				$data['datetime'] = date('Y-m-d H:i:s');
1792 2453
 				$data['format_source'] = 'flightgearsp';
1793
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1794
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2454
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2455
+					$data['noarchive'] = true;
2456
+				}
2457
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2458
+					$SI->add($data);
2459
+				}
1795 2460
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1796 2461
 			    }
1797 2462
                         } elseif ($format === 'acars') {
1798
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2463
+                    	    if ($globalDebug) {
2464
+                    	    	echo 'ACARS : '.$buffer."\n";
2465
+                    	    }
1799 2466
 			    $ACARS->add(trim($buffer));
1800 2467
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1801 2468
 			    $ACARS->deleteLiveAcarsData();
1802 2469
 			} elseif ($format === 'acarsjsonudp') {
1803
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2470
+			    if ($globalDebug) {
2471
+			    	echo 'ACARS : '.$buffer."\n";
2472
+			    }
1804 2473
                             $line = json_decode(trim($buffer), true);
1805 2474
                             if (!empty($line)) {
1806 2475
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
@@ -1825,8 +2494,12 @@  discard block
 block discarded – undo
1825 2494
 				    $aircraft_type = $line[10];
1826 2495
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1827 2496
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1828
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1829
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2497
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2498
+				    	$data['noarchive'] = true;
2499
+				    }
2500
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2501
+				    	$SI->add($data);
2502
+				    }
1830 2503
 				}
1831 2504
 			    }
1832 2505
 			} elseif ($format === 'beast') {
@@ -1836,28 +2509,62 @@  discard block
 block discarded – undo
1836 2509
 			    foreach($buffer as $all_data) {
1837 2510
 				$line = json_decode('{'.$all_data.'}',true);
1838 2511
 				$data = array();
1839
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1840
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1841
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1842
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1843
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1844
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1845
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2512
+				if (isset($line['Icao'])) {
2513
+					$data['hex'] = $line['Icao'];
2514
+				}
2515
+				// hex
2516
+				if (isset($line['Call'])) {
2517
+					$data['ident'] = $line['Call'];
2518
+				}
2519
+				// ident
2520
+				if (isset($line['Alt'])) {
2521
+					$data['altitude'] = $line['Alt'];
2522
+				}
2523
+				// altitude
2524
+				if (isset($line['Spd'])) {
2525
+					$data['speed'] = $line['Spd'];
2526
+				}
2527
+				// speed
2528
+				if (isset($line['Trak'])) {
2529
+					$data['heading'] = $line['Trak'];
2530
+				}
2531
+				// heading
2532
+				if (isset($line['Lat'])) {
2533
+					$data['latitude'] = $line['Lat'];
2534
+				}
2535
+				// lat
2536
+				if (isset($line['Long'])) {
2537
+					$data['longitude'] = $line['Long'];
2538
+				}
2539
+				// long
1846 2540
 				//$data['verticalrate'] = $line['']; // verticale rate
1847
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2541
+				if (isset($line['Sqk'])) {
2542
+					$data['squawk'] = $line['Sqk'];
2543
+				}
2544
+				// squawk
1848 2545
 				$data['emergency'] = ''; // emergency
1849
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2546
+				if (isset($line['Reg'])) {
2547
+					$data['registration'] = $line['Reg'];
2548
+				}
1850 2549
 				/*
1851 2550
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1852 2551
 				else $data['datetime'] = date('Y-m-d H:i:s');
1853 2552
 				*/
1854 2553
 				$data['datetime'] = date('Y-m-d H:i:s');
1855
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2554
+				if (isset($line['Type'])) {
2555
+					$data['aircraft_icao'] = $line['Type'];
2556
+				}
1856 2557
 		    		$data['format_source'] = 'vrstcp';
1857 2558
 				$data['id_source'] = $id_source;
1858
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1859
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1860
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2559
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2560
+					$data['noarchive'] = true;
2561
+				}
2562
+				if (isset($value['name']) && $value['name'] != '') {
2563
+					$data['source_name'] = $value['name'];
2564
+				}
2565
+				if (isset($data['latitude']) && isset($data['hex'])) {
2566
+					$SI->add($data);
2567
+				}
1861 2568
 				unset($data);
1862 2569
 			    }
1863 2570
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1870,22 +2577,46 @@  discard block
 block discarded – undo
1870 2577
     				$data['hex'] = $lined['hexid'];
1871 2578
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1872 2579
     				$data['datetime'] = date('Y-m-d H:i:s');;
1873
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1874
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1875
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1876
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1877
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1878
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1879
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2580
+    				if (isset($lined['ident'])) {
2581
+    					$data['ident'] = $lined['ident'];
2582
+    				}
2583
+    				if (isset($lined['lat'])) {
2584
+    					$data['latitude'] = $lined['lat'];
2585
+    				}
2586
+    				if (isset($lined['lon'])) {
2587
+    					$data['longitude'] = $lined['lon'];
2588
+    				}
2589
+    				if (isset($lined['speed'])) {
2590
+    					$data['speed'] = $lined['speed'];
2591
+    				}
2592
+    				if (isset($lined['squawk'])) {
2593
+    					$data['squawk'] = $lined['squawk'];
2594
+    				}
2595
+    				if (isset($lined['alt'])) {
2596
+    					$data['altitude'] = $lined['alt'];
2597
+    				}
2598
+    				if (isset($lined['heading'])) {
2599
+    					$data['heading'] = $lined['heading'];
2600
+    				}
1880 2601
     				$data['id_source'] = $id_source;
1881 2602
     				$data['format_source'] = 'tsv';
1882
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1883
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1884
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1885
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2603
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2604
+    					$data['source_name'] = $globalSources[$nb]['name'];
2605
+    				}
2606
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2607
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2608
+    				}
2609
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2610
+					$data['noarchive'] = true;
2611
+				}
2612
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2613
+    					$SI->add($data);
2614
+    				}
1886 2615
     				unset($lined);
1887 2616
     				unset($data);
1888
-    			    } else $error = true;
2617
+    			    } else {
2618
+    			    	$error = true;
2619
+    			    }
1889 2620
 			} elseif ($format === 'aprs' && $use_aprs) {
1890 2621
 			    if ($aprs_connect === 0) {
1891 2622
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1911,47 +2642,96 @@  discard block
 block discarded – undo
1911 2642
 				    $aprs_last_tx = time();
1912 2643
 				    $data = array();
1913 2644
 				    //print_r($line);
1914
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1915
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1916
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1917
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1918
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1919
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1920
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1921
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1922
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1923
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2645
+				    if (isset($line['address'])) {
2646
+				    	$data['hex'] = $line['address'];
2647
+				    }
2648
+				    if (isset($line['mmsi'])) {
2649
+				    	$data['mmsi'] = $line['mmsi'];
2650
+				    }
2651
+				    if (isset($line['imo'])) {
2652
+				    	$data['imo'] = $line['imo'];
2653
+				    }
2654
+				    if (isset($line['squawk'])) {
2655
+				    	$data['squawk'] = $line['squawk'];
2656
+				    }
2657
+				    if (isset($line['arrival_code'])) {
2658
+				    	$data['arrival_code'] = $line['arrival_code'];
2659
+				    }
2660
+				    if (isset($line['arrival_date'])) {
2661
+				    	$data['arrival_date'] = $line['arrival_date'];
2662
+				    }
2663
+				    if (isset($line['typeid'])) {
2664
+				    	$data['type_id'] = $line['typeid'];
2665
+				    }
2666
+				    if (isset($line['statusid'])) {
2667
+				    	$data['status_id'] = $line['statusid'];
2668
+				    }
2669
+				    if (isset($line['timestamp'])) {
2670
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2671
+				    } else {
2672
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2673
+				    }
1924 2674
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1925
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2675
+				    if (isset($line['ident'])) {
2676
+				    	$data['ident'] = $line['ident'];
2677
+				    }
1926 2678
 				    $data['latitude'] = $line['latitude'];
1927 2679
 				    $data['longitude'] = $line['longitude'];
1928 2680
 				    //$data['verticalrate'] = $line[16];
1929
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2681
+				    if (isset($line['speed'])) {
2682
+				    	$data['speed'] = $line['speed'];
2683
+				    }
1930 2684
 				    //else $data['speed'] = 0;
1931
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1932
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1933
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2685
+				    if (isset($line['altitude'])) {
2686
+				    	$data['altitude'] = $line['altitude'];
2687
+				    }
2688
+				    if (isset($line['comment'])) {
2689
+				    	$data['comment'] = $line['comment'];
2690
+				    }
2691
+				    if (isset($line['symbol'])) {
2692
+				    	$data['type'] = $line['symbol'];
2693
+				    }
1934 2694
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1935 2695
 				    
1936
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2696
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2697
+				    	$data['heading'] = $line['heading'];
2698
+				    }
1937 2699
 				    //else echo 'No heading...'."\n";
1938 2700
 				    //else $data['heading'] = 0;
1939
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2701
+				    if (isset($line['stealth'])) {
2702
+				    	$data['aircraft_type'] = $line['stealth'];
2703
+				    }
1940 2704
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1941
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1942
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1943
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1944
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2705
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2706
+				    	$data['noarchive'] = true;
2707
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2708
+				    	$data['noarchive'] = false;
2709
+				    }
2710
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2711
+				    	$data['noarchive'] = true;
2712
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2713
+				    	$data['noarchive'] = false;
2714
+				    }
1945 2715
     				    $data['id_source'] = $id_source;
1946
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1947
-				    else $data['format_source'] = 'aprs';
2716
+    				    if (isset($line['format_source'])) {
2717
+    				    	$data['format_source'] = $line['format_source'];
2718
+    				    } else {
2719
+				    	$data['format_source'] = 'aprs';
2720
+				    }
1948 2721
 				    $data['source_name'] = $line['source'];
1949
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1950
-				    else $data['source_type'] = 'flarm';
1951
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2722
+				    if (isset($line['source_type'])) {
2723
+				    	$data['source_type'] = $line['source_type'];
2724
+				    } else {
2725
+				    	$data['source_type'] = 'flarm';
2726
+				    }
2727
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2728
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2729
+    				    }
1952 2730
 				    $currentdate = date('Y-m-d H:i:s');
1953 2731
 				    $aprsdate = strtotime($data['datetime']);
1954
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2732
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2733
+				    	$data['altitude_relative'] = 'AMSL';
2734
+				    }
1955 2735
 				    // Accept data if time <= system time + 20s
1956 2736
 				    //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'])))) {
1957 2737
 				    if (
@@ -1963,7 +2743,9 @@  discard block
 block discarded – undo
1963 2743
 					$send = $SI->add($data);
1964 2744
 				    } elseif ($data['source_type'] === 'ais') {
1965 2745
 					$data['type'] = '';
1966
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2746
+					if (isset($globalMarine) && $globalMarine) {
2747
+						$send = $MI->add($data);
2748
+					}
1967 2749
 				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1968 2750
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1969 2751
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
@@ -1971,8 +2753,12 @@  discard block
 block discarded – undo
1971 2753
 					    $line['symbol'] === 'Glider' || 
1972 2754
 					    $line['symbol'] === 'No. Plane' || 
1973 2755
 					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1974
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1975
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2756
+					    if ($line['symbol'] === 'Ballon') {
2757
+					    	$data['aircraft_icao'] = 'BALL';
2758
+					    }
2759
+					    if ($line['symbol'] === 'Glider') {
2760
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2761
+					    }
1976 2762
 					    $send = $SI->add($data);
1977 2763
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1978 2764
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -2003,9 +2789,13 @@  discard block
 block discarded – undo
2003 2789
 				    //} 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') {
2004 2790
 				//    } 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') {
2005 2791
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
2006
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2792
+					if (isset($globalTracker) && $globalTracker) {
2793
+						$send = $TI->add($data);
2794
+					}
2007 2795
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2008
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2796
+					if (!isset($data['altitude'])) {
2797
+						$data['altitude'] = 0;
2798
+					}
2009 2799
 					$Source->deleteOldLocationByType('gs');
2010 2800
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
2011 2801
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -2014,7 +2804,9 @@  discard block
 block discarded – undo
2014 2804
 					}
2015 2805
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2016 2806
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2017
-					if ($globalDebug) echo '# Weather Station added'."\n";
2807
+					if ($globalDebug) {
2808
+						echo '# Weather Station added'."\n";
2809
+					}
2018 2810
 					$Source->deleteOldLocationByType('wx');
2019 2811
 					$weather_data = json_encode($line);
2020 2812
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -2024,7 +2816,9 @@  discard block
 block discarded – undo
2024 2816
 					}
2025 2817
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2026 2818
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2027
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2819
+					if ($globalDebug) {
2820
+						echo '☈ Lightning added'."\n";
2821
+					}
2028 2822
 					$Source->deleteOldLocationByType('lightning');
2029 2823
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
2030 2824
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -2036,8 +2830,7 @@  discard block
 block discarded – undo
2036 2830
 				    	print_r($line);
2037 2831
 				    }
2038 2832
 				    unset($data);
2039
-				}
2040
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2833
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2041 2834
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
2042 2835
 				}
2043 2836
 				/*
@@ -2046,7 +2839,9 @@  discard block
 block discarded – undo
2046 2839
 				}
2047 2840
 				*/
2048 2841
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
2049
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2842
+				elseif ($line === true && $globalDebug) {
2843
+					echo '!! Failed : '.$buffer."!!\n";
2844
+				}
2050 2845
 				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
2051 2846
 					$Source->deleteOldLocationByType('lightning');
2052 2847
 					$Source->deleteOldLocationByType('wx');
@@ -2083,27 +2878,47 @@  discard block
 block discarded – undo
2083 2878
     				$data['ground'] = $line[21];
2084 2879
     				$data['emergency'] = $line[19];
2085 2880
     				$data['format_source'] = 'sbs';
2086
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2087
-				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2088
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2089
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2881
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2882
+					$data['source_name'] = $globalSources[$nb]['name'];
2883
+				} elseif ($line[0] == 'MLAT') {
2884
+					$data['source_name'] = 'MLAT';
2885
+				}
2886
+				if (isset($globalSources[$nb]['sourcestats'])) {
2887
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2888
+				}
2889
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2890
+					$data['noarchive'] = true;
2891
+				}
2090 2892
     				$data['id_source'] = $id_source;
2091
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2092
-    				else $error = true;
2893
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2894
+    					$send = $SI->add($data);
2895
+    				} else {
2896
+    					$error = true;
2897
+    				}
2093 2898
     				unset($data);
2094
-    			    } else $error = true;
2899
+    			    } else {
2900
+    			    	$error = true;
2901
+    			    }
2095 2902
 			    if ($error) {
2096 2903
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2097
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2904
+					if ($globalDebug) {
2905
+						echo "Not a message. Ignoring... \n";
2906
+					}
2098 2907
 				} else {
2099
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2908
+					if ($globalDebug) {
2909
+						echo "Wrong line format. Ignoring... \n";
2910
+					}
2100 2911
 					if ($globalDebug) {
2101 2912
 						echo $buffer;
2102 2913
 						//print_r($line);
2103 2914
 					}
2104 2915
 					//socket_close($r);
2105
-					if ($globalDebug) echo "Reconnect after an error...\n";
2106
-					if ($format === 'aprs') $aprs_connect = 0;
2916
+					if ($globalDebug) {
2917
+						echo "Reconnect after an error...\n";
2918
+					}
2919
+					if ($format === 'aprs') {
2920
+						$aprs_connect = 0;
2921
+					}
2107 2922
 					$sourceer[$nb] = $globalSources[$nb];
2108 2923
 					connect_all($sourceer);
2109 2924
 					$sourceer = array();
@@ -2111,10 +2926,14 @@  discard block
 block discarded – undo
2111 2926
 			    }
2112 2927
 			}
2113 2928
 			// Sleep for xxx microseconds
2114
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2929
+			if (isset($globalSBSSleep)) {
2930
+				usleep($globalSBSSleep);
2931
+			}
2115 2932
 		    } else {
2116 2933
 			if ($format === 'flightgearmp') {
2117
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2934
+			    	if ($globalDebug) {
2935
+			    		echo "Reconnect FlightGear MP...";
2936
+			    	}
2118 2937
 				//@socket_close($r);
2119 2938
 				sleep($globalMinFetch);
2120 2939
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2123,10 +2942,15 @@  discard block
 block discarded – undo
2123 2942
 				break;
2124 2943
 				
2125 2944
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2126
-			    if (isset($tt[$format])) $tt[$format]++;
2127
-			    else $tt[$format] = 0;
2945
+			    if (isset($tt[$format])) {
2946
+			    	$tt[$format]++;
2947
+			    } else {
2948
+			    	$tt[$format] = 0;
2949
+			    }
2128 2950
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
2129
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2951
+				if ($globalDebug) {
2952
+					echo "ERROR : Reconnect ".$format."...";
2953
+				}
2130 2954
 				//@socket_close($r);
2131 2955
 				sleep(2);
2132 2956
 				$aprs_connect = 0;
@@ -2144,11 +2968,17 @@  discard block
 block discarded – undo
2144 2968
 	    } else {
2145 2969
 		$error = socket_strerror(socket_last_error());
2146 2970
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2147
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2148
-			if (isset($globalDebug)) echo "Restarting...\n";
2971
+			if ($globalDebug) {
2972
+				echo "ERROR : socket_select give this error ".$error . "\n";
2973
+			}
2974
+			if (isset($globalDebug)) {
2975
+				echo "Restarting...\n";
2976
+			}
2149 2977
 			// Restart the script if possible
2150 2978
 			if (is_array($sockets)) {
2151
-			    if ($globalDebug) echo "Shutdown all sockets...";
2979
+			    if ($globalDebug) {
2980
+			    	echo "Shutdown all sockets...";
2981
+			    }
2152 2982
 			    
2153 2983
 			    foreach ($sockets as $sock) {
2154 2984
 				@socket_shutdown($sock,2);
@@ -2156,23 +2986,39 @@  discard block
 block discarded – undo
2156 2986
 			    }
2157 2987
 			    
2158 2988
 			}
2159
-			if ($globalDebug) echo "Waiting...";
2989
+			if ($globalDebug) {
2990
+				echo "Waiting...";
2991
+			}
2160 2992
 			sleep(2);
2161 2993
 			$time = time();
2162 2994
 			//connect_all($hosts);
2163 2995
 			$aprs_connect = 0;
2164
-			if ($reset%5 === 0) sleep(20);
2165
-			if ($reset > 100) exit('Too many attempts...');
2166
-			if ($globalDebug) echo "Restart all connections...";
2996
+			if ($reset%5 === 0) {
2997
+				sleep(20);
2998
+			}
2999
+			if ($reset > 100) {
3000
+				exit('Too many attempts...');
3001
+			}
3002
+			if ($globalDebug) {
3003
+				echo "Restart all connections...";
3004
+			}
2167 3005
 			connect_all($globalSources);
2168 3006
 		}
2169 3007
 	    }
2170 3008
 	}
2171 3009
 	if ($globalDaemon === false) {
2172
-	    if ($globalDebug) echo 'Check all...'."\n";
2173
-	    if (isset($SI)) $SI->checkAll();
2174
-	    if (isset($TI)) $TI->checkAll();
2175
-	    if (isset($MI)) $MI->checkAll();
3010
+	    if ($globalDebug) {
3011
+	    	echo 'Check all...'."\n";
3012
+	    }
3013
+	    if (isset($SI)) {
3014
+	    	$SI->checkAll();
3015
+	    }
3016
+	    if (isset($TI)) {
3017
+	    	$TI->checkAll();
3018
+	    }
3019
+	    if (isset($MI)) {
3020
+	    	$MI->checkAll();
3021
+	    }
2176 3022
 	}
2177 3023
     }
2178 3024
 }
Please login to merge, or discard this patch.