Completed
Push — master ( 06162a...440e6b )
by Yannick
08:02
created
scripts/daemon-spotter.php 3 patches
Indentation   +859 added lines, -859 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,42 +24,42 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
+	else $globalSources[] = array('host' => $options['s']);
59 59
 } elseif (isset($options['source'])) {
60
-    $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
60
+	$globalSources = array();
61
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
+	else $globalSources[] = array('host' => $options['source']);
63 63
 }
64 64
 if (isset($options['aprsserverhost'])) $globalServerAPRShost = $options['aprsserverhost'];
65 65
 if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 if (isset($options['idsource'])) $id_source = $options['idsource'];
71 71
 else $id_source = 1;
72 72
 if (isset($globalServer) && $globalServer) {
73
-    if ($globalDebug) echo "Using Server Mode\n";
74
-    $SI=new SpotterServer();
73
+	if ($globalDebug) echo "Using Server Mode\n";
74
+	$SI=new SpotterServer();
75 75
 /*
76 76
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
77 77
     $SI = new adsb2aprs();
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 } else $SI=new SpotterImport($Connection->db);
81 81
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
82 82
 if (isset($globalMarine) && $globalMarine) {
83
-    $AIS = new AIS();
84
-    $MI = new MarineImport($Connection->db);
83
+	$AIS = new AIS();
84
+	$MI = new MarineImport($Connection->db);
85 85
 }
86 86
 //$APRS=new APRS($Connection->db);
87 87
 $SBS=new SBS();
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
 //$servertz = system('date +%Z');
92 92
 // signal handler - playing nice with sockets and dump1090
93 93
 if (function_exists('pcntl_fork')) {
94
-    pcntl_signal(SIGINT,  function() {
95
-        global $sockets;
96
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
97
-        die("Bye!\n");
98
-    });
99
-    pcntl_signal_dispatch();
94
+	pcntl_signal(SIGINT,  function() {
95
+		global $sockets;
96
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
97
+		die("Bye!\n");
98
+	});
99
+	pcntl_signal_dispatch();
100 100
 }
101 101
 
102 102
 // let's try and connect
@@ -106,153 +106,153 @@  discard block
 block discarded – undo
106 106
 $reset = 0;
107 107
 
108 108
 function connect_all($hosts) {
109
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
110
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
111
-    $reset++;
112
-    if ($globalDebug) echo 'Connect to all...'."\n";
113
-    foreach ($hosts as $id => $value) {
109
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
110
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
111
+	$reset++;
112
+	if ($globalDebug) echo 'Connect to all...'."\n";
113
+	foreach ($hosts as $id => $value) {
114 114
 	$host = $value['host'];
115 115
 	$globalSources[$id]['last_exec'] = 0;
116 116
 	// Here we check type of source(s)
117 117
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
118
-            if (preg_match('/deltadb.txt$/i',$host)) {
119
-        	//$formats[$id] = 'deltadbtxt';
120
-        	$globalSources[$id]['format'] = 'deltadbtxt';
121
-        	//$last_exec['deltadbtxt'] = 0;
122
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
123
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
124
-        	//$formats[$id] = 'vatsimtxt';
125
-        	$globalSources[$id]['format'] = 'vatsimtxt';
126
-        	//$last_exec['vatsimtxt'] = 0;
127
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
128
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
129
-        	//$formats[$id] = 'aircraftlistjson';
130
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
131
-        	//$last_exec['aircraftlistjson'] = 0;
132
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
133
-    	    } else if (preg_match('/opensky/i',$host)) {
134
-        	//$formats[$id] = 'aircraftlistjson';
135
-        	$globalSources[$id]['format'] = 'opensky';
136
-        	//$last_exec['aircraftlistjson'] = 0;
137
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
138
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
139
-        	//$formats[$id] = 'radarvirtueljson';
140
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
141
-        	//$last_exec['radarvirtueljson'] = 0;
142
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
143
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
144
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
145
-        	    exit(0);
146
-        	}
147
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
148
-        	//$formats[$id] = 'planeupdatefaa';
149
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
150
-        	//$last_exec['planeupdatefaa'] = 0;
151
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
152
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
153
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
154
-        	    exit(0);
155
-        	}
156
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
157
-        	//$formats[$id] = 'phpvmacars';
158
-        	$globalSources[$id]['format'] = 'phpvmacars';
159
-        	//$last_exec['phpvmacars'] = 0;
160
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
161
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
162
-        	//$formats[$id] = 'phpvmacars';
163
-        	$globalSources[$id]['format'] = 'vam';
164
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
165
-            } else if (preg_match('/whazzup/i',$host)) {
166
-        	//$formats[$id] = 'whazzup';
167
-        	$globalSources[$id]['format'] = 'whazzup';
168
-        	//$last_exec['whazzup'] = 0;
169
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
170
-            } else if (preg_match('/recentpireps/i',$host)) {
171
-        	//$formats[$id] = 'pirepsjson';
172
-        	$globalSources[$id]['format'] = 'pirepsjson';
173
-        	//$last_exec['pirepsjson'] = 0;
174
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
175
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
176
-        	//$formats[$id] = 'fr24json';
177
-        	$globalSources[$id]['format'] = 'fr24json';
178
-        	//$last_exec['fr24json'] = 0;
179
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
180
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
181
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
182
-        	    exit(0);
183
-        	}
184
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
185
-        	//$formats[$id] = 'fr24json';
186
-        	$globalSources[$id]['format'] = 'myshiptracking';
187
-        	//$last_exec['fr24json'] = 0;
188
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
189
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
190
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
191
-        	    exit(0);
192
-        	}
193
-            //} else if (preg_match('/10001/',$host)) {
194
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
195
-        	//$formats[$id] = 'tsv';
196
-        	$globalSources[$id]['format'] = 'tsv';
197
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
198
-            }
199
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
200
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
201
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
202
-    		    if ($idf !== false) {
203
-    			$httpfeeds[$id] = $idf;
204
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
205
-    		    }
206
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
207
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
208
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
209
-	    $hostport = explode(':',$host);
210
-	    if (isset($hostport[1])) {
118
+			if (preg_match('/deltadb.txt$/i',$host)) {
119
+			//$formats[$id] = 'deltadbtxt';
120
+			$globalSources[$id]['format'] = 'deltadbtxt';
121
+			//$last_exec['deltadbtxt'] = 0;
122
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
123
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
124
+			//$formats[$id] = 'vatsimtxt';
125
+			$globalSources[$id]['format'] = 'vatsimtxt';
126
+			//$last_exec['vatsimtxt'] = 0;
127
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
128
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
129
+			//$formats[$id] = 'aircraftlistjson';
130
+			$globalSources[$id]['format'] = 'aircraftlistjson';
131
+			//$last_exec['aircraftlistjson'] = 0;
132
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
133
+			} else if (preg_match('/opensky/i',$host)) {
134
+			//$formats[$id] = 'aircraftlistjson';
135
+			$globalSources[$id]['format'] = 'opensky';
136
+			//$last_exec['aircraftlistjson'] = 0;
137
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
138
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
139
+			//$formats[$id] = 'radarvirtueljson';
140
+			$globalSources[$id]['format'] = 'radarvirtueljson';
141
+			//$last_exec['radarvirtueljson'] = 0;
142
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
143
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
144
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
145
+				exit(0);
146
+			}
147
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
148
+			//$formats[$id] = 'planeupdatefaa';
149
+			$globalSources[$id]['format'] = 'planeupdatefaa';
150
+			//$last_exec['planeupdatefaa'] = 0;
151
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
152
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
153
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
154
+				exit(0);
155
+			}
156
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
157
+			//$formats[$id] = 'phpvmacars';
158
+			$globalSources[$id]['format'] = 'phpvmacars';
159
+			//$last_exec['phpvmacars'] = 0;
160
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
161
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
162
+			//$formats[$id] = 'phpvmacars';
163
+			$globalSources[$id]['format'] = 'vam';
164
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
165
+			} else if (preg_match('/whazzup/i',$host)) {
166
+			//$formats[$id] = 'whazzup';
167
+			$globalSources[$id]['format'] = 'whazzup';
168
+			//$last_exec['whazzup'] = 0;
169
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
170
+			} else if (preg_match('/recentpireps/i',$host)) {
171
+			//$formats[$id] = 'pirepsjson';
172
+			$globalSources[$id]['format'] = 'pirepsjson';
173
+			//$last_exec['pirepsjson'] = 0;
174
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
175
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
176
+			//$formats[$id] = 'fr24json';
177
+			$globalSources[$id]['format'] = 'fr24json';
178
+			//$last_exec['fr24json'] = 0;
179
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
180
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
181
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
182
+				exit(0);
183
+			}
184
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
185
+			//$formats[$id] = 'fr24json';
186
+			$globalSources[$id]['format'] = 'myshiptracking';
187
+			//$last_exec['fr24json'] = 0;
188
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
189
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
190
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
191
+				exit(0);
192
+			}
193
+			//} else if (preg_match('/10001/',$host)) {
194
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
195
+			//$formats[$id] = 'tsv';
196
+			$globalSources[$id]['format'] = 'tsv';
197
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
198
+			}
199
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
200
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
201
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
202
+				if ($idf !== false) {
203
+				$httpfeeds[$id] = $idf;
204
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
205
+				}
206
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
207
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
208
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
209
+		$hostport = explode(':',$host);
210
+		if (isset($hostport[1])) {
211 211
 		$port = $hostport[1];
212 212
 		$hostn = $hostport[0];
213
-	    } else {
213
+		} else {
214 214
 		$port = $globalSources[$id]['port'];
215 215
 		$hostn = $globalSources[$id]['host'];
216
-	    }
217
-	    $Common = new Common();
218
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
219
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
220
-    	    } else {
221
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
222
-	    }
223
-	    if ($s) {
224
-    	        $sockets[$id] = $s;
225
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
226
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
216
+		}
217
+		$Common = new Common();
218
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
219
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
220
+			} else {
221
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
222
+		}
223
+		if ($s) {
224
+				$sockets[$id] = $s;
225
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
226
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
227 227
 			//$formats[$id] = 'aprs';
228 228
 			$globalSources[$id]['format'] = 'aprs';
229 229
 			//$aprs_connect = 0;
230 230
 			//$use_aprs = true;
231
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
231
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
232 232
 			$globalSources[$id]['format'] = 'vrstcp';
233
-    		    } elseif ($port == '10001') {
234
-        		//$formats[$id] = 'tsv';
235
-        		$globalSources[$id]['format'] = 'tsv';
236
-		    } elseif ($port == '30002') {
237
-        		//$formats[$id] = 'raw';
238
-        		$globalSources[$id]['format'] = 'raw';
239
-		    } elseif ($port == '5001') {
240
-        		//$formats[$id] = 'raw';
241
-        		$globalSources[$id]['format'] = 'flightgearmp';
242
-		    } elseif ($port == '30005') {
233
+				} elseif ($port == '10001') {
234
+				//$formats[$id] = 'tsv';
235
+				$globalSources[$id]['format'] = 'tsv';
236
+			} elseif ($port == '30002') {
237
+				//$formats[$id] = 'raw';
238
+				$globalSources[$id]['format'] = 'raw';
239
+			} elseif ($port == '5001') {
240
+				//$formats[$id] = 'raw';
241
+				$globalSources[$id]['format'] = 'flightgearmp';
242
+			} elseif ($port == '30005') {
243 243
 			// Not yet supported
244
-        		//$formats[$id] = 'beast';
245
-        		$globalSources[$id]['format'] = 'beast';
246
-		    //} else $formats[$id] = 'sbs';
247
-		    } else $globalSources[$id]['format'] = 'sbs';
248
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
244
+				//$formats[$id] = 'beast';
245
+				$globalSources[$id]['format'] = 'beast';
246
+			//} else $formats[$id] = 'sbs';
247
+			} else $globalSources[$id]['format'] = 'sbs';
248
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
249 249
 		}
250 250
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
251
-            } else {
251
+			} else {
252 252
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
253
-    	    }
254
-        }
255
-    }
253
+			}
254
+		}
255
+	}
256 256
 }
257 257
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
258 258
 
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 //connect_all($globalSources);
276 276
 
277 277
 if (isset($globalProxy) && $globalProxy) {
278
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
278
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
279 279
 } else {
280
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
280
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
281 281
 }
282 282
 
283 283
 // APRS Configuration
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
 	die;
287 287
 }
288 288
 foreach ($globalSources as $key => $source) {
289
-    if (!isset($source['format'])) {
290
-        $globalSources[$key]['format'] = 'auto';
291
-    }
289
+	if (!isset($source['format'])) {
290
+		$globalSources[$key]['format'] = 'auto';
291
+	}
292 292
 }
293 293
 connect_all($globalSources);
294 294
 foreach ($globalSources as $key => $source) {
295
-    if (isset($source['format']) && $source['format'] == 'aprs') {
295
+	if (isset($source['format']) && $source['format'] == 'aprs') {
296 296
 	$aprs_connect = 0;
297 297
 	$use_aprs = true;
298 298
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
299 299
 	break;
300
-    }
300
+	}
301 301
 }
302 302
 
303 303
 if ($use_aprs) {
@@ -338,152 +338,152 @@  discard block
 block discarded – undo
338 338
 
339 339
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
340 340
 while ($i > 0) {
341
-    if (!$globalDaemon) $i = $endtime-time();
342
-    // Delete old ATC
343
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
341
+	if (!$globalDaemon) $i = $endtime-time();
342
+	// Delete old ATC
343
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
344 344
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
345
-        $ATC->deleteOldATC();
346
-    }
345
+		$ATC->deleteOldATC();
346
+	}
347 347
     
348
-    //if (count($last_exec) > 0) {
349
-    if (count($last_exec) == count($globalSources)) {
348
+	//if (count($last_exec) > 0) {
349
+	if (count($last_exec) == count($globalSources)) {
350 350
 	$max = $globalMinFetch;
351 351
 	foreach ($last_exec as $last) {
352
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
352
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
353 353
 	}
354 354
 	if ($max != $globalMinFetch) {
355
-	    if ($globalDebug) echo 'Sleeping...'."\n";
356
-	    sleep($globalMinFetch-$max+2);
355
+		if ($globalDebug) echo 'Sleeping...'."\n";
356
+		sleep($globalMinFetch-$max+2);
357
+	}
357 358
 	}
358
-    }
359 359
 
360 360
     
361
-    //foreach ($formats as $id => $value) {
362
-    foreach ($globalSources as $id => $value) {
361
+	//foreach ($formats as $id => $value) {
362
+	foreach ($globalSources as $id => $value) {
363 363
 	date_default_timezone_set('UTC');
364 364
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
365 365
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
366
-	    //$buffer = $Common->getData($hosts[$id]);
367
-	    $buffer = $Common->getData($value['host']);
368
-	    if ($buffer != '') $reset = 0;
369
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
370
-	    $buffer = explode('\n',$buffer);
371
-	    foreach ($buffer as $line) {
372
-    		if ($line != '' && count($line) > 7) {
373
-    		    $line = explode(',', $line);
374
-	            $data = array();
375
-	            $data['hex'] = $line[1]; // hex
376
-	            $data['ident'] = $line[2]; // ident
377
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
378
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
379
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
380
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
381
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
382
-	            $data['verticalrate'] = ''; // vertical rate
383
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
384
-	            $data['emergency'] = ''; // emergency
385
-		    $data['datetime'] = date('Y-m-d H:i:s');
386
-		    $data['format_source'] = 'deltadbtxt';
387
-    		    $data['id_source'] = $id_source;
388
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
389
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
390
-    		    $SI->add($data);
391
-		    unset($data);
392
-    		}
393
-    	    }
394
-    	    $last_exec[$id]['last'] = time();
366
+		//$buffer = $Common->getData($hosts[$id]);
367
+		$buffer = $Common->getData($value['host']);
368
+		if ($buffer != '') $reset = 0;
369
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
370
+		$buffer = explode('\n',$buffer);
371
+		foreach ($buffer as $line) {
372
+			if ($line != '' && count($line) > 7) {
373
+				$line = explode(',', $line);
374
+				$data = array();
375
+				$data['hex'] = $line[1]; // hex
376
+				$data['ident'] = $line[2]; // ident
377
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
378
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
379
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
380
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
381
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
382
+				$data['verticalrate'] = ''; // vertical rate
383
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
384
+				$data['emergency'] = ''; // emergency
385
+			$data['datetime'] = date('Y-m-d H:i:s');
386
+			$data['format_source'] = 'deltadbtxt';
387
+				$data['id_source'] = $id_source;
388
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
389
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
390
+				$SI->add($data);
391
+			unset($data);
392
+			}
393
+			}
394
+			$last_exec[$id]['last'] = time();
395 395
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
396
-	    date_default_timezone_set('CET');
397
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
398
-	    date_default_timezone_set('UTC');
399
-	    if ($buffer != '') $reset = 0;
400
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
401
-	    $buffer = explode('\n',$buffer);
402
-	    foreach ($buffer as $line) {
396
+		date_default_timezone_set('CET');
397
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
398
+		date_default_timezone_set('UTC');
399
+		if ($buffer != '') $reset = 0;
400
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
401
+		$buffer = explode('\n',$buffer);
402
+		foreach ($buffer as $line) {
403 403
 		if ($line != '') {
404
-		    echo "'".$line."'\n";
405
-		    $add = false;
406
-		    $ais_data = $AIS->parse_line(trim($line));
407
-		    $data = array();
408
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
409
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
410
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
411
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
412
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
413
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
414
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
415
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
416
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
417
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
418
-		    if (isset($ais_data['timestamp'])) {
404
+			echo "'".$line."'\n";
405
+			$add = false;
406
+			$ais_data = $AIS->parse_line(trim($line));
407
+			$data = array();
408
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
409
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
410
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
411
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
412
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
413
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
414
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
415
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
416
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
417
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
418
+			if (isset($ais_data['timestamp'])) {
419 419
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
420 420
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
421
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
422
-			    $add = true;
421
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
422
+				$add = true;
423 423
 			}
424
-		    } else {
424
+			} else {
425 425
 			$data['datetime'] = date('Y-m-d H:i:s');
426 426
 			$add = true;
427
-		    }
428
-		    $data['format_source'] = 'aisnmeatxt';
429
-    		    $data['id_source'] = $id_source;
430
-		    print_r($data);
431
-		    echo 'Add...'."\n";
432
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
433
-		    unset($data);
427
+			}
428
+			$data['format_source'] = 'aisnmeatxt';
429
+				$data['id_source'] = $id_source;
430
+			print_r($data);
431
+			echo 'Add...'."\n";
432
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
433
+			unset($data);
434 434
 		}
435
-    	    }
436
-    	    $last_exec[$id]['last'] = time();
435
+			}
436
+			$last_exec[$id]['last'] = time();
437 437
 	} elseif ($value['format'] == 'aisnmeahttp') {
438
-	    $arr = $httpfeeds;
439
-	    $w = $e = null;
438
+		$arr = $httpfeeds;
439
+		$w = $e = null;
440 440
 	    
441
-	    if (isset($arr[$id])) {
442
-	    $nn = stream_select($arr,$w,$e,$timeout);
443
-	    if ($nn > 0) {
441
+		if (isset($arr[$id])) {
442
+		$nn = stream_select($arr,$w,$e,$timeout);
443
+		if ($nn > 0) {
444 444
 		foreach ($httpfeeds as $feed) {
445
-		    $buffer = stream_get_line($feed,2000,"\n");
446
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
447
-		    $buffer = explode('\n',$buffer);
448
-		    foreach ($buffer as $line) {
445
+			$buffer = stream_get_line($feed,2000,"\n");
446
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
447
+			$buffer = explode('\n',$buffer);
448
+			foreach ($buffer as $line) {
449 449
 			if ($line != '') {
450
-			    $ais_data = $AIS->parse_line(trim($line));
451
-			    $data = array();
452
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
453
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
454
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
455
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
456
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
457
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
458
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
459
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
460
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
461
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
462
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
463
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
464
-			    if (isset($ais_data['timestamp'])) {
450
+				$ais_data = $AIS->parse_line(trim($line));
451
+				$data = array();
452
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
453
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
454
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
455
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
456
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
457
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
458
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
459
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
460
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
461
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
462
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
463
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
464
+				if (isset($ais_data['timestamp'])) {
465 465
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
466
-			    } else {
466
+				} else {
467 467
 				$data['datetime'] = date('Y-m-d H:i:s');
468
-			    }
469
-			    $data['format_source'] = 'aisnmeahttp';
470
-			    $data['id_source'] = $id_source;
471
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
472
-			    unset($data);
468
+				}
469
+				$data['format_source'] = 'aisnmeahttp';
470
+				$data['id_source'] = $id_source;
471
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
472
+				unset($data);
473 473
 			}
474
-		    }
474
+			}
475
+		}
475 476
 		}
476 477
 		}
477
-	    }
478 478
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
479
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
480
-	    if ($buffer != '') {
479
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
480
+		if ($buffer != '') {
481 481
 		//echo $buffer;
482 482
 		$all_data = json_decode($buffer,true);
483 483
 		//print_r($all_data);
484 484
 		if (isset($all_data[0]['DATA'])) {
485 485
 		foreach ($all_data[0]['DATA'] as $line) {
486
-		    if ($line != '') {
486
+			if ($line != '') {
487 487
 			$data = array();
488 488
 			$data['ident'] = $line['NAME'];
489 489
 			$data['mmsi'] = $line['MMSI'];
@@ -499,87 +499,87 @@  discard block
 block discarded – undo
499 499
 			$data['id_source'] = $id_source;
500 500
 			$MI->add($data);
501 501
 			unset($data);
502
-		    }
502
+			}
503 503
 		}
504 504
 		}
505 505
 		
506
-	    }
507
-    	    $last_exec[$id]['last'] = time();
506
+		}
507
+			$last_exec[$id]['last'] = time();
508 508
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
509
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
510
-	    if ($buffer != '') {
509
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
510
+		if ($buffer != '') {
511 511
 		$all_data = json_decode($buffer,true);
512 512
 		if (isset($all_data[0]['mmsi'])) {
513
-		    foreach ($all_data as $line) {
513
+			foreach ($all_data as $line) {
514 514
 			if ($line != '') {
515
-			    $data = array();
516
-			    $data['ident'] = $line['shipname'];
517
-			    $data['callsign'] = $line['callsign'];
518
-			    $data['mmsi'] = $line['mmsi'];
519
-			    $data['speed'] = $line['sog'];
520
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
521
-			    $data['latitude'] = $line['latitude'];
522
-			    $data['longitude'] = $line['longitude'];
523
-			    $data['type_id'] = $line['shiptype'];
524
-			    $data['arrival_code'] = $line['destination'];
525
-			    $data['datetime'] = $line['time'];
526
-			    $data['format_source'] = 'boatbeaconapp';
527
-			    $data['id_source'] = $id_source;
528
-			    $MI->add($data);
529
-			    unset($data);
515
+				$data = array();
516
+				$data['ident'] = $line['shipname'];
517
+				$data['callsign'] = $line['callsign'];
518
+				$data['mmsi'] = $line['mmsi'];
519
+				$data['speed'] = $line['sog'];
520
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
521
+				$data['latitude'] = $line['latitude'];
522
+				$data['longitude'] = $line['longitude'];
523
+				$data['type_id'] = $line['shiptype'];
524
+				$data['arrival_code'] = $line['destination'];
525
+				$data['datetime'] = $line['time'];
526
+				$data['format_source'] = 'boatbeaconapp';
527
+				$data['id_source'] = $id_source;
528
+				$MI->add($data);
529
+				unset($data);
530
+			}
530 531
 			}
531
-		    }
532 532
 		}
533 533
 		
534
-	    }
535
-    	    $last_exec[$id]['last'] = time();
534
+		}
535
+			$last_exec[$id]['last'] = time();
536 536
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
537
-	    echo 'download...';
538
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
539
-	    echo 'done !'."\n";
540
-	    if ($buffer != '') $reset = 0;
541
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
542
-	    $buffer = explode('\n',$buffer);
543
-	    foreach ($buffer as $line) {
537
+		echo 'download...';
538
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
539
+		echo 'done !'."\n";
540
+		if ($buffer != '') $reset = 0;
541
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
542
+		$buffer = explode('\n',$buffer);
543
+		foreach ($buffer as $line) {
544 544
 		if ($line != '') {
545
-		    $data = array();
546
-		    $data['mmsi'] = (int)substr($line,0,9);
547
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
548
-		    //$data['status'] = substr($line,21,2);
549
-		    //$data['type'] = substr($line,24,3);
550
-		    $data['latitude'] = substr($line,29,9);
551
-		    $data['longitude'] = substr($line,41,9);
552
-		    $data['speed'] = round(substr($line,51,5));
553
-		    //$data['course'] = substr($line,57,5);
554
-		    $data['heading'] = round(substr($line,63,3));
555
-		    //$data['draft'] = substr($line,67,4);
556
-		    //$data['length'] = substr($line,72,3);
557
-		    //$data['beam'] = substr($line,76,2);
558
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
559
-		    //$data['callsign'] = trim(substr($line,100,7);
560
-		    //$data['dest'] = substr($line,108,20);
561
-		    //$data['etaDate'] = substr($line,129,5);
562
-		    //$data['etaTime'] = substr($line,135,5);
563
-		    $data['format_source'] = 'shipplotter';
564
-    		    $data['id_source'] = $id_source;
565
-		    print_r($data);
566
-		    echo 'Add...'."\n";
567
-		    $MI->add($data);
568
-		    unset($data);
545
+			$data = array();
546
+			$data['mmsi'] = (int)substr($line,0,9);
547
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
548
+			//$data['status'] = substr($line,21,2);
549
+			//$data['type'] = substr($line,24,3);
550
+			$data['latitude'] = substr($line,29,9);
551
+			$data['longitude'] = substr($line,41,9);
552
+			$data['speed'] = round(substr($line,51,5));
553
+			//$data['course'] = substr($line,57,5);
554
+			$data['heading'] = round(substr($line,63,3));
555
+			//$data['draft'] = substr($line,67,4);
556
+			//$data['length'] = substr($line,72,3);
557
+			//$data['beam'] = substr($line,76,2);
558
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
559
+			//$data['callsign'] = trim(substr($line,100,7);
560
+			//$data['dest'] = substr($line,108,20);
561
+			//$data['etaDate'] = substr($line,129,5);
562
+			//$data['etaTime'] = substr($line,135,5);
563
+			$data['format_source'] = 'shipplotter';
564
+				$data['id_source'] = $id_source;
565
+			print_r($data);
566
+			echo 'Add...'."\n";
567
+			$MI->add($data);
568
+			unset($data);
569 569
 		}
570
-    	    }
571
-    	    $last_exec[$id]['last'] = time();
570
+			}
571
+			$last_exec[$id]['last'] = time();
572 572
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
573 573
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
574
-	    //$buffer = $Common->getData($hosts[$id]);
575
-	    $buffer = $Common->getData($value['host']);
576
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
577
-	    $buffer = explode('\n',$buffer);
578
-	    $reset = 0;
579
-	    foreach ($buffer as $line) {
580
-    		if ($line != '') {
581
-    		    $line = explode(':', $line);
582
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
574
+		//$buffer = $Common->getData($hosts[$id]);
575
+		$buffer = $Common->getData($value['host']);
576
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
577
+		$buffer = explode('\n',$buffer);
578
+		$reset = 0;
579
+		foreach ($buffer as $line) {
580
+			if ($line != '') {
581
+				$line = explode(':', $line);
582
+				if (count($line) > 30 && $line[0] != 'callsign') {
583 583
 			$data = array();
584 584
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
585 585
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -592,36 +592,36 @@  discard block
 block discarded – undo
592 592
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
593 593
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
594 594
 			$data['latitude'] = $line[5]; // lat
595
-	        	$data['longitude'] = $line[6]; // long
596
-	        	$data['verticalrate'] = ''; // vertical rate
597
-	        	$data['squawk'] = ''; // squawk
598
-	        	$data['emergency'] = ''; // emergency
599
-	        	$data['waypoints'] = $line[30];
595
+				$data['longitude'] = $line[6]; // long
596
+				$data['verticalrate'] = ''; // vertical rate
597
+				$data['squawk'] = ''; // squawk
598
+				$data['emergency'] = ''; // emergency
599
+				$data['waypoints'] = $line[30];
600 600
 			$data['datetime'] = date('Y-m-d H:i:s');
601 601
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
602 602
 			//if (isset($line[37])) $data['last_update'] = $line[37];
603
-		        $data['departure_airport_icao'] = $line[11];
604
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
605
-		        $data['arrival_airport_icao'] = $line[13];
603
+				$data['departure_airport_icao'] = $line[11];
604
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
605
+				$data['arrival_airport_icao'] = $line[13];
606 606
 			$data['frequency'] = $line[4];
607 607
 			$data['type'] = $line[18];
608 608
 			$data['range'] = $line[19];
609 609
 			if (isset($line[35])) $data['info'] = $line[35];
610
-    			$data['id_source'] = $id_source;
611
-	    		//$data['arrival_airport_time'] = ;
612
-	    		if ($line[9] != '') {
613
-	    		    $aircraft_data = explode('/',$line[9]);
614
-	    		    if (isset($aircraft_data[1])) {
615
-	    			$data['aircraft_icao'] = $aircraft_data[1];
616
-	    		    }
617
-        		}
618
-	    		/*
610
+				$data['id_source'] = $id_source;
611
+				//$data['arrival_airport_time'] = ;
612
+				if ($line[9] != '') {
613
+					$aircraft_data = explode('/',$line[9]);
614
+					if (isset($aircraft_data[1])) {
615
+					$data['aircraft_icao'] = $aircraft_data[1];
616
+					}
617
+				}
618
+				/*
619 619
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
620 620
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
621 621
 	    		*/
622
-	    		$data['format_source'] = $value['format'];
622
+				$data['format_source'] = $value['format'];
623 623
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
624
-    			if ($line[3] == 'PILOT') $SI->add($data);
624
+				if ($line[3] == 'PILOT') $SI->add($data);
625 625
 			elseif ($line[3] == 'ATC') {
626 626
 				//print_r($data);
627 627
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -639,247 +639,247 @@  discard block
 block discarded – undo
639 639
 				if (!isset($data['source_name'])) $data['source_name'] = '';
640 640
 				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
641 641
 			}
642
-    			unset($data);
643
-    		    }
644
-    		}
645
-    	    }
646
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
647
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
648
-    	    $last_exec[$id]['last'] = time();
649
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
650
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
651
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
652
-	    if ($buffer != '') {
653
-	    $all_data = json_decode($buffer,true);
654
-	    if (isset($all_data['acList'])) {
642
+				unset($data);
643
+				}
644
+			}
645
+			}
646
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
647
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
648
+			$last_exec[$id]['last'] = time();
649
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
650
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
651
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
652
+		if ($buffer != '') {
653
+		$all_data = json_decode($buffer,true);
654
+		if (isset($all_data['acList'])) {
655 655
 		$reset = 0;
656 656
 		foreach ($all_data['acList'] as $line) {
657
-		    $data = array();
658
-		    $data['hex'] = $line['Icao']; // hex
659
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
660
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
661
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
662
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
663
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
664
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
665
-		    //$data['verticalrate'] = $line['']; // verticale rate
666
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
667
-		    $data['emergency'] = ''; // emergency
668
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
669
-		    /*
657
+			$data = array();
658
+			$data['hex'] = $line['Icao']; // hex
659
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
660
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
661
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
662
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
663
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
664
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
665
+			//$data['verticalrate'] = $line['']; // verticale rate
666
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
667
+			$data['emergency'] = ''; // emergency
668
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
669
+			/*
670 670
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
671 671
 		    else $data['datetime'] = date('Y-m-d H:i:s');
672 672
 		    */
673
-		    $data['datetime'] = date('Y-m-d H:i:s');
674
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
675
-	    	    $data['format_source'] = 'aircraftlistjson';
676
-		    $data['id_source'] = $id_source;
677
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
-		    if (isset($data['latitude'])) $SI->add($data);
679
-		    unset($data);
673
+			$data['datetime'] = date('Y-m-d H:i:s');
674
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
675
+				$data['format_source'] = 'aircraftlistjson';
676
+			$data['id_source'] = $id_source;
677
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
+			if (isset($data['latitude'])) $SI->add($data);
679
+			unset($data);
680 680
 		}
681
-	    } elseif (is_array($all_data)) {
681
+		} elseif (is_array($all_data)) {
682 682
 		$reset = 0;
683 683
 		foreach ($all_data as $line) {
684
-		    $data = array();
685
-		    $data['hex'] = $line['hex']; // hex
686
-		    $data['ident'] = $line['flight']; // ident
687
-		    $data['altitude'] = $line['altitude']; // altitude
688
-		    $data['speed'] = $line['speed']; // speed
689
-		    $data['heading'] = $line['track']; // heading
690
-		    $data['latitude'] = $line['lat']; // lat
691
-		    $data['longitude'] = $line['lon']; // long
692
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
693
-		    $data['squawk'] = $line['squawk']; // squawk
694
-		    $data['emergency'] = ''; // emergency
695
-		    $data['datetime'] = date('Y-m-d H:i:s');
696
-	    	    $data['format_source'] = 'aircraftlistjson';
697
-    		    $data['id_source'] = $id_source;
698
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
699
-		    $SI->add($data);
700
-		    unset($data);
684
+			$data = array();
685
+			$data['hex'] = $line['hex']; // hex
686
+			$data['ident'] = $line['flight']; // ident
687
+			$data['altitude'] = $line['altitude']; // altitude
688
+			$data['speed'] = $line['speed']; // speed
689
+			$data['heading'] = $line['track']; // heading
690
+			$data['latitude'] = $line['lat']; // lat
691
+			$data['longitude'] = $line['lon']; // long
692
+			$data['verticalrate'] = $line['vrt']; // verticale rate
693
+			$data['squawk'] = $line['squawk']; // squawk
694
+			$data['emergency'] = ''; // emergency
695
+			$data['datetime'] = date('Y-m-d H:i:s');
696
+				$data['format_source'] = 'aircraftlistjson';
697
+				$data['id_source'] = $id_source;
698
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
699
+			$SI->add($data);
700
+			unset($data);
701
+		}
702
+		}
701 703
 		}
702
-	    }
703
-	    }
704
-    	    //$last_exec['aircraftlistjson'] = time();
705
-    	    $last_exec[$id]['last'] = time();
706
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
707
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
708
-	    $buffer = $Common->getData($value['host']);
709
-	    $all_data = json_decode($buffer,true);
710
-	    if (isset($all_data['planes'])) {
704
+			//$last_exec['aircraftlistjson'] = time();
705
+			$last_exec[$id]['last'] = time();
706
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
707
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
708
+		$buffer = $Common->getData($value['host']);
709
+		$all_data = json_decode($buffer,true);
710
+		if (isset($all_data['planes'])) {
711 711
 		$reset = 0;
712 712
 		foreach ($all_data['planes'] as $key => $line) {
713
-		    $data = array();
714
-		    $data['hex'] = $key; // hex
715
-		    $data['ident'] = $line[3]; // ident
716
-		    $data['altitude'] = $line[6]; // altitude
717
-		    $data['speed'] = $line[8]; // speed
718
-		    $data['heading'] = $line[7]; // heading
719
-		    $data['latitude'] = $line[4]; // lat
720
-		    $data['longitude'] = $line[5]; // long
721
-		    //$data['verticalrate'] = $line[]; // verticale rate
722
-		    $data['squawk'] = $line[10]; // squawk
723
-		    $data['emergency'] = ''; // emergency
724
-		    $data['registration'] = $line[2];
725
-		    $data['aircraft_icao'] = $line[0];
726
-		    $deparr = explode('-',$line[1]);
727
-		    if (count($deparr) == 2) {
713
+			$data = array();
714
+			$data['hex'] = $key; // hex
715
+			$data['ident'] = $line[3]; // ident
716
+			$data['altitude'] = $line[6]; // altitude
717
+			$data['speed'] = $line[8]; // speed
718
+			$data['heading'] = $line[7]; // heading
719
+			$data['latitude'] = $line[4]; // lat
720
+			$data['longitude'] = $line[5]; // long
721
+			//$data['verticalrate'] = $line[]; // verticale rate
722
+			$data['squawk'] = $line[10]; // squawk
723
+			$data['emergency'] = ''; // emergency
724
+			$data['registration'] = $line[2];
725
+			$data['aircraft_icao'] = $line[0];
726
+			$deparr = explode('-',$line[1]);
727
+			if (count($deparr) == 2) {
728 728
 			$data['departure_airport_icao'] = $deparr[0];
729 729
 			$data['arrival_airport_icao'] = $deparr[1];
730
-		    }
731
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
732
-	    	    $data['format_source'] = 'planeupdatefaa';
733
-    		    $data['id_source'] = $id_source;
734
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
735
-		    $SI->add($data);
736
-		    unset($data);
730
+			}
731
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
732
+				$data['format_source'] = 'planeupdatefaa';
733
+				$data['id_source'] = $id_source;
734
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
735
+			$SI->add($data);
736
+			unset($data);
737
+		}
737 738
 		}
738
-	    }
739
-    	    //$last_exec['planeupdatefaa'] = time();
740
-    	    $last_exec[$id]['last'] = time();
741
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
742
-	    $buffer = $Common->getData($value['host']);
743
-	    $all_data = json_decode($buffer,true);
744
-	    if (isset($all_data['states'])) {
739
+			//$last_exec['planeupdatefaa'] = time();
740
+			$last_exec[$id]['last'] = time();
741
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
742
+		$buffer = $Common->getData($value['host']);
743
+		$all_data = json_decode($buffer,true);
744
+		if (isset($all_data['states'])) {
745 745
 		$reset = 0;
746 746
 		foreach ($all_data['states'] as $key => $line) {
747
-		    $data = array();
748
-		    $data['hex'] = $line[0]; // hex
749
-		    $data['ident'] = trim($line[1]); // ident
750
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
751
-		    $data['speed'] = round($line[9]*1.94384); // speed
752
-		    $data['heading'] = round($line[10]); // heading
753
-		    $data['latitude'] = $line[5]; // lat
754
-		    $data['longitude'] = $line[6]; // long
755
-		    $data['verticalrate'] = $line[11]; // verticale rate
756
-		    //$data['squawk'] = $line[10]; // squawk
757
-		    //$data['emergency'] = ''; // emergency
758
-		    //$data['registration'] = $line[2];
759
-		    //$data['aircraft_icao'] = $line[0];
760
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
761
-	    	    $data['format_source'] = 'opensky';
762
-    		    $data['id_source'] = $id_source;
763
-		    $SI->add($data);
764
-		    unset($data);
747
+			$data = array();
748
+			$data['hex'] = $line[0]; // hex
749
+			$data['ident'] = trim($line[1]); // ident
750
+			$data['altitude'] = round($line[7]*3.28084); // altitude
751
+			$data['speed'] = round($line[9]*1.94384); // speed
752
+			$data['heading'] = round($line[10]); // heading
753
+			$data['latitude'] = $line[5]; // lat
754
+			$data['longitude'] = $line[6]; // long
755
+			$data['verticalrate'] = $line[11]; // verticale rate
756
+			//$data['squawk'] = $line[10]; // squawk
757
+			//$data['emergency'] = ''; // emergency
758
+			//$data['registration'] = $line[2];
759
+			//$data['aircraft_icao'] = $line[0];
760
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
761
+				$data['format_source'] = 'opensky';
762
+				$data['id_source'] = $id_source;
763
+			$SI->add($data);
764
+			unset($data);
765 765
 		}
766
-	    }
767
-    	    //$last_exec['planeupdatefaa'] = time();
768
-    	    $last_exec[$id]['last'] = time();
769
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
770
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
771
-	    //$buffer = $Common->getData($hosts[$id]);
772
-	    $buffer = $Common->getData($value['host']);
773
-	    $all_data = json_decode($buffer,true);
774
-	    if (!empty($all_data)) $reset = 0;
775
-	    foreach ($all_data as $key => $line) {
766
+		}
767
+			//$last_exec['planeupdatefaa'] = time();
768
+			$last_exec[$id]['last'] = time();
769
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
770
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
771
+		//$buffer = $Common->getData($hosts[$id]);
772
+		$buffer = $Common->getData($value['host']);
773
+		$all_data = json_decode($buffer,true);
774
+		if (!empty($all_data)) $reset = 0;
775
+		foreach ($all_data as $key => $line) {
776 776
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
777
-		    $data = array();
778
-		    $data['hex'] = $line[0];
779
-		    $data['ident'] = $line[16]; //$line[13]
780
-	    	    $data['altitude'] = $line[4]; // altitude
781
-	    	    $data['speed'] = $line[5]; // speed
782
-	    	    $data['heading'] = $line[3]; // heading
783
-	    	    $data['latitude'] = $line[1]; // lat
784
-	    	    $data['longitude'] = $line[2]; // long
785
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
786
-	    	    $data['squawk'] = $line[6]; // squawk
787
-	    	    $data['aircraft_icao'] = $line[8];
788
-	    	    $data['registration'] = $line[9];
789
-		    $data['departure_airport_iata'] = $line[11];
790
-		    $data['arrival_airport_iata'] = $line[12];
791
-	    	    $data['emergency'] = ''; // emergency
792
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
793
-	    	    $data['format_source'] = 'fr24json';
794
-    		    $data['id_source'] = $id_source;
795
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
796
-		    $SI->add($data);
797
-		    unset($data);
777
+			$data = array();
778
+			$data['hex'] = $line[0];
779
+			$data['ident'] = $line[16]; //$line[13]
780
+				$data['altitude'] = $line[4]; // altitude
781
+				$data['speed'] = $line[5]; // speed
782
+				$data['heading'] = $line[3]; // heading
783
+				$data['latitude'] = $line[1]; // lat
784
+				$data['longitude'] = $line[2]; // long
785
+				$data['verticalrate'] = $line[15]; // verticale rate
786
+				$data['squawk'] = $line[6]; // squawk
787
+				$data['aircraft_icao'] = $line[8];
788
+				$data['registration'] = $line[9];
789
+			$data['departure_airport_iata'] = $line[11];
790
+			$data['arrival_airport_iata'] = $line[12];
791
+				$data['emergency'] = ''; // emergency
792
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
793
+				$data['format_source'] = 'fr24json';
794
+				$data['id_source'] = $id_source;
795
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
796
+			$SI->add($data);
797
+			unset($data);
798
+		}
798 799
 		}
799
-	    }
800
-    	    //$last_exec['fr24json'] = time();
801
-    	    $last_exec[$id]['last'] = time();
802
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
803
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
804
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
805
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
806
-	    //echo $buffer;
807
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
808
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
809
-	    $all_data = json_decode($buffer,true);
810
-	    if (json_last_error() != JSON_ERROR_NONE) {
800
+			//$last_exec['fr24json'] = time();
801
+			$last_exec[$id]['last'] = time();
802
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
803
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
804
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
805
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
806
+		//echo $buffer;
807
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
808
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
809
+		$all_data = json_decode($buffer,true);
810
+		if (json_last_error() != JSON_ERROR_NONE) {
811 811
 		die(json_last_error_msg());
812
-	    }
813
-	    if (isset($all_data['mrkrs'])) {
812
+		}
813
+		if (isset($all_data['mrkrs'])) {
814 814
 		$reset = 0;
815 815
 		foreach ($all_data['mrkrs'] as $key => $line) {
816
-		    if (isset($line['inf'])) {
816
+			if (isset($line['inf'])) {
817 817
 			$data = array();
818 818
 			$data['hex'] = $line['inf']['ia'];
819 819
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
820
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
821
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
822
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
823
-	    		$data['latitude'] = $line['pt'][0]; // lat
824
-	    		$data['longitude'] = $line['pt'][1]; // long
825
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
826
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
827
-	    		//$data['aircraft_icao'] = $line[8];
828
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
820
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
821
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
822
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
823
+				$data['latitude'] = $line['pt'][0]; // lat
824
+				$data['longitude'] = $line['pt'][1]; // long
825
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
826
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
827
+				//$data['aircraft_icao'] = $line[8];
828
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
829 829
 			//$data['departure_airport_iata'] = $line[11];
830 830
 			//$data['arrival_airport_iata'] = $line[12];
831
-	    		//$data['emergency'] = ''; // emergency
831
+				//$data['emergency'] = ''; // emergency
832 832
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
833
-	    		$data['format_source'] = 'radarvirtueljson';
834
-    			$data['id_source'] = $id_source;
833
+				$data['format_source'] = 'radarvirtueljson';
834
+				$data['id_source'] = $id_source;
835 835
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
836 836
 			$SI->add($data);
837 837
 			unset($data);
838
-		    }
838
+			}
839
+		}
839 840
 		}
840
-	    }
841
-    	    //$last_exec['radarvirtueljson'] = time();
842
-    	    $last_exec[$id]['last'] = time();
843
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
844
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
845
-	    //$buffer = $Common->getData($hosts[$id]);
846
-	    $buffer = $Common->getData($value['host'].'?'.time());
847
-	    $all_data = json_decode(utf8_encode($buffer),true);
841
+			//$last_exec['radarvirtueljson'] = time();
842
+			$last_exec[$id]['last'] = time();
843
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
844
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
845
+		//$buffer = $Common->getData($hosts[$id]);
846
+		$buffer = $Common->getData($value['host'].'?'.time());
847
+		$all_data = json_decode(utf8_encode($buffer),true);
848 848
 	    
849
-	    if (isset($all_data['pireps'])) {
849
+		if (isset($all_data['pireps'])) {
850 850
 		$reset = 0;
851
-	        foreach ($all_data['pireps'] as $line) {
852
-		    $data = array();
853
-		    $data['id'] = $line['id'];
854
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
855
-		    $data['ident'] = $line['callsign']; // ident
856
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
857
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
858
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
859
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
860
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
861
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
862
-		    $data['latitude'] = $line['lat']; // lat
863
-		    $data['longitude'] = $line['lon']; // long
864
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
865
-		    //$data['squawk'] = $line['squawk']; // squawk
866
-		    //$data['emergency'] = ''; // emergency
867
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
868
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
869
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
870
-		    //$data['arrival_airport_time'] = $line['arrtime'];
871
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
872
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
873
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
874
-		    else $data['info'] = '';
875
-		    $data['format_source'] = 'pireps';
876
-    		    $data['id_source'] = $id_source;
877
-		    $data['datetime'] = date('Y-m-d H:i:s');
878
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
879
-		    if ($line['icon'] == 'plane') {
851
+			foreach ($all_data['pireps'] as $line) {
852
+			$data = array();
853
+			$data['id'] = $line['id'];
854
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
855
+			$data['ident'] = $line['callsign']; // ident
856
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
857
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
858
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
859
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
860
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
861
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
862
+			$data['latitude'] = $line['lat']; // lat
863
+			$data['longitude'] = $line['lon']; // long
864
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
865
+			//$data['squawk'] = $line['squawk']; // squawk
866
+			//$data['emergency'] = ''; // emergency
867
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
868
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
869
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
870
+			//$data['arrival_airport_time'] = $line['arrtime'];
871
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
872
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
873
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
874
+			else $data['info'] = '';
875
+			$data['format_source'] = 'pireps';
876
+				$data['id_source'] = $id_source;
877
+			$data['datetime'] = date('Y-m-d H:i:s');
878
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
879
+			if ($line['icon'] == 'plane') {
880 880
 			$SI->add($data);
881
-		    //    print_r($data);
882
-    		    } elseif ($line['icon'] == 'ct') {
881
+			//    print_r($data);
882
+				} elseif ($line['icon'] == 'ct') {
883 883
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
884 884
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
885 885
 			$typec = substr($data['ident'],-3);
@@ -894,192 +894,192 @@  discard block
 block discarded – undo
894 894
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
895 895
 			else $data['type'] = 'Observer';
896 896
 			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']);
897
-		    }
898
-		    unset($data);
897
+			}
898
+			unset($data);
899
+		}
899 900
 		}
900
-	    }
901
-    	    //$last_exec['pirepsjson'] = time();
902
-    	    $last_exec[$id]['last'] = time();
903
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
904
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
905
-	    //$buffer = $Common->getData($hosts[$id]);
906
-	    if ($globalDebug) echo 'Get Data...'."\n";
907
-	    $buffer = $Common->getData($value['host']);
908
-	    $all_data = json_decode($buffer,true);
909
-	    if ($buffer != '' && is_array($all_data)) {
901
+			//$last_exec['pirepsjson'] = time();
902
+			$last_exec[$id]['last'] = time();
903
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
904
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
905
+		//$buffer = $Common->getData($hosts[$id]);
906
+		if ($globalDebug) echo 'Get Data...'."\n";
907
+		$buffer = $Common->getData($value['host']);
908
+		$all_data = json_decode($buffer,true);
909
+		if ($buffer != '' && is_array($all_data)) {
910 910
 		$reset = 0;
911 911
 		foreach ($all_data as $line) {
912
-	    	    $data = array();
913
-	    	    //$data['id'] = $line['id']; // id not usable
914
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
915
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
916
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
917
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
918
-	    	    $data['ident'] = $line['flightnum']; // ident
919
-	    	    $data['altitude'] = $line['alt']; // altitude
920
-	    	    $data['speed'] = $line['gs']; // speed
921
-	    	    $data['heading'] = $line['heading']; // heading
922
-	    	    $data['latitude'] = $line['lat']; // lat
923
-	    	    $data['longitude'] = $line['lng']; // long
924
-	    	    $data['verticalrate'] = ''; // verticale rate
925
-	    	    $data['squawk'] = ''; // squawk
926
-	    	    $data['emergency'] = ''; // emergency
927
-	    	    //$data['datetime'] = $line['lastupdate'];
928
-	    	    $data['last_update'] = $line['lastupdate'];
929
-		    $data['datetime'] = date('Y-m-d H:i:s');
930
-	    	    $data['departure_airport_icao'] = $line['depicao'];
931
-	    	    $data['departure_airport_time'] = $line['deptime'];
932
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
933
-    		    $data['arrival_airport_time'] = $line['arrtime'];
934
-    		    $data['registration'] = $line['aircraft'];
935
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
936
-		    if (isset($line['aircraftname'])) {
912
+				$data = array();
913
+				//$data['id'] = $line['id']; // id not usable
914
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
915
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
916
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
917
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
918
+				$data['ident'] = $line['flightnum']; // ident
919
+				$data['altitude'] = $line['alt']; // altitude
920
+				$data['speed'] = $line['gs']; // speed
921
+				$data['heading'] = $line['heading']; // heading
922
+				$data['latitude'] = $line['lat']; // lat
923
+				$data['longitude'] = $line['lng']; // long
924
+				$data['verticalrate'] = ''; // verticale rate
925
+				$data['squawk'] = ''; // squawk
926
+				$data['emergency'] = ''; // emergency
927
+				//$data['datetime'] = $line['lastupdate'];
928
+				$data['last_update'] = $line['lastupdate'];
929
+			$data['datetime'] = date('Y-m-d H:i:s');
930
+				$data['departure_airport_icao'] = $line['depicao'];
931
+				$data['departure_airport_time'] = $line['deptime'];
932
+				$data['arrival_airport_icao'] = $line['arricao'];
933
+				$data['arrival_airport_time'] = $line['arrtime'];
934
+				$data['registration'] = $line['aircraft'];
935
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
936
+			if (isset($line['aircraftname'])) {
937 937
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
938 938
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
939
-	    		$aircraft_data = explode('-',$line['aircraftname']);
940
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
941
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
942
-	    		else {
943
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
944
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
945
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
946
-	    		}
947
-	    	    }
948
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
949
-    		    $data['id_source'] = $id_source;
950
-	    	    $data['format_source'] = 'phpvmacars';
951
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
952
-		    $SI->add($data);
953
-		    unset($data);
939
+				$aircraft_data = explode('-',$line['aircraftname']);
940
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
941
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
942
+				else {
943
+					$aircraft_data = explode(' ',$line['aircraftname']);
944
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
945
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
946
+				}
947
+				}
948
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
949
+				$data['id_source'] = $id_source;
950
+				$data['format_source'] = 'phpvmacars';
951
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
952
+			$SI->add($data);
953
+			unset($data);
954 954
 		}
955 955
 		if ($globalDebug) echo 'No more data...'."\n";
956 956
 		unset($buffer);
957 957
 		unset($all_data);
958
-	    }
959
-    	    //$last_exec['phpvmacars'] = time();
960
-    	    $last_exec[$id]['last'] = time();
961
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
962
-	    //$buffer = $Common->getData($hosts[$id]);
963
-	    if ($globalDebug) echo 'Get Data...'."\n";
964
-	    $buffer = $Common->getData($value['host']);
965
-	    $all_data = json_decode($buffer,true);
966
-	    if ($buffer != '' && is_array($all_data)) {
958
+		}
959
+			//$last_exec['phpvmacars'] = time();
960
+			$last_exec[$id]['last'] = time();
961
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
962
+		//$buffer = $Common->getData($hosts[$id]);
963
+		if ($globalDebug) echo 'Get Data...'."\n";
964
+		$buffer = $Common->getData($value['host']);
965
+		$all_data = json_decode($buffer,true);
966
+		if ($buffer != '' && is_array($all_data)) {
967 967
 		$reset = 0;
968 968
 		foreach ($all_data as $line) {
969
-	    	    $data = array();
970
-	    	    //$data['id'] = $line['id']; // id not usable
971
-	    	    $data['id'] = trim($line['flight_id']);
972
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
973
-	    	    $data['pilot_name'] = $line['pilot_name'];
974
-	    	    $data['pilot_id'] = $line['pilot_id'];
975
-	    	    $data['ident'] = trim($line['callsign']); // ident
976
-	    	    $data['altitude'] = $line['altitude']; // altitude
977
-	    	    $data['speed'] = $line['gs']; // speed
978
-	    	    $data['heading'] = $line['heading']; // heading
979
-	    	    $data['latitude'] = $line['latitude']; // lat
980
-	    	    $data['longitude'] = $line['longitude']; // long
981
-	    	    $data['verticalrate'] = ''; // verticale rate
982
-	    	    $data['squawk'] = ''; // squawk
983
-	    	    $data['emergency'] = ''; // emergency
984
-	    	    //$data['datetime'] = $line['lastupdate'];
985
-	    	    $data['last_update'] = $line['last_update'];
986
-		    $data['datetime'] = date('Y-m-d H:i:s');
987
-	    	    $data['departure_airport_icao'] = $line['departure'];
988
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
989
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
990
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
991
-    		    //$data['registration'] = $line['aircraft'];
992
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
993
-	    	    $data['aircraft_icao'] = $line['plane_type'];
994
-    		    $data['id_source'] = $id_source;
995
-	    	    $data['format_source'] = 'vam';
996
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
997
-		    $SI->add($data);
998
-		    unset($data);
969
+				$data = array();
970
+				//$data['id'] = $line['id']; // id not usable
971
+				$data['id'] = trim($line['flight_id']);
972
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
973
+				$data['pilot_name'] = $line['pilot_name'];
974
+				$data['pilot_id'] = $line['pilot_id'];
975
+				$data['ident'] = trim($line['callsign']); // ident
976
+				$data['altitude'] = $line['altitude']; // altitude
977
+				$data['speed'] = $line['gs']; // speed
978
+				$data['heading'] = $line['heading']; // heading
979
+				$data['latitude'] = $line['latitude']; // lat
980
+				$data['longitude'] = $line['longitude']; // long
981
+				$data['verticalrate'] = ''; // verticale rate
982
+				$data['squawk'] = ''; // squawk
983
+				$data['emergency'] = ''; // emergency
984
+				//$data['datetime'] = $line['lastupdate'];
985
+				$data['last_update'] = $line['last_update'];
986
+			$data['datetime'] = date('Y-m-d H:i:s');
987
+				$data['departure_airport_icao'] = $line['departure'];
988
+				//$data['departure_airport_time'] = $line['departure_time'];
989
+				$data['arrival_airport_icao'] = $line['arrival'];
990
+				//$data['arrival_airport_time'] = $line['arrival_time'];
991
+				//$data['registration'] = $line['aircraft'];
992
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
993
+				$data['aircraft_icao'] = $line['plane_type'];
994
+				$data['id_source'] = $id_source;
995
+				$data['format_source'] = 'vam';
996
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
997
+			$SI->add($data);
998
+			unset($data);
999 999
 		}
1000 1000
 		if ($globalDebug) echo 'No more data...'."\n";
1001 1001
 		unset($buffer);
1002 1002
 		unset($all_data);
1003
-	    }
1004
-    	    //$last_exec['phpvmacars'] = time();
1005
-    	    $last_exec[$id]['last'] = time();
1003
+		}
1004
+			//$last_exec['phpvmacars'] = time();
1005
+			$last_exec[$id]['last'] = time();
1006 1006
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1007 1007
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1008
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1009
-    	    //$last_exec[$id]['last'] = time();
1008
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1009
+			//$last_exec[$id]['last'] = time();
1010 1010
 
1011
-	    //$read = array( $sockets[$id] );
1012
-	    $read = $sockets;
1013
-	    $write = NULL;
1014
-	    $e = NULL;
1015
-	    $n = socket_select($read, $write, $e, $timeout);
1016
-	    if ($e != NULL) var_dump($e);
1017
-	    if ($n > 0) {
1011
+		//$read = array( $sockets[$id] );
1012
+		$read = $sockets;
1013
+		$write = NULL;
1014
+		$e = NULL;
1015
+		$n = socket_select($read, $write, $e, $timeout);
1016
+		if ($e != NULL) var_dump($e);
1017
+		if ($n > 0) {
1018 1018
 		$reset = 0;
1019 1019
 		foreach ($read as $nb => $r) {
1020
-		    //$value = $formats[$nb];
1021
-		    $format = $globalSources[$nb]['format'];
1022
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1020
+			//$value = $formats[$nb];
1021
+			$format = $globalSources[$nb]['format'];
1022
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1023 1023
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1024
-		    } elseif ($format == 'vrstcp') {
1024
+			} elseif ($format == 'vrstcp') {
1025 1025
 			$buffer = @socket_read($r, 6000);
1026
-		    } else {
1026
+			} else {
1027 1027
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1028
-		    }
1029
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1030
-		    //echo $buffer."\n";
1031
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1032
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1033
-		    $error = false;
1034
-		    //$SI::del();
1035
-		    if ($format == 'vrstcp') {
1028
+			}
1029
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1030
+			//echo $buffer."\n";
1031
+			// lets play nice and handle signals such as ctrl-c/kill properly
1032
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1033
+			$error = false;
1034
+			//$SI::del();
1035
+			if ($format == 'vrstcp') {
1036 1036
 			$buffer = explode('},{',$buffer);
1037
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1038
-		    // SBS format is CSV format
1039
-		    if ($buffer !== FALSE && $buffer != '') {
1037
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1038
+			// SBS format is CSV format
1039
+			if ($buffer !== FALSE && $buffer != '') {
1040 1040
 			$tt[$format] = 0;
1041 1041
 			if ($format == 'acarssbs3') {
1042
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1043
-			    $ACARS->add(trim($buffer));
1044
-			    $ACARS->deleteLiveAcarsData();
1042
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1043
+				$ACARS->add(trim($buffer));
1044
+				$ACARS->deleteLiveAcarsData();
1045 1045
 			} elseif ($format == 'raw') {
1046
-			    // AVR format
1047
-			    $data = $SBS->parse($buffer);
1048
-			    if (is_array($data)) {
1046
+				// AVR format
1047
+				$data = $SBS->parse($buffer);
1048
+				if (is_array($data)) {
1049 1049
 				$data['datetime'] = date('Y-m-d H:i:s');
1050 1050
 				$data['format_source'] = 'raw';
1051 1051
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1052 1052
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1053 1053
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1054
-			    }
1054
+				}
1055 1055
 			} elseif ($format == 'ais') {
1056
-			    $ais_data = $AIS->parse_line(trim($buffer));
1057
-			    $data = array();
1058
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1059
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1060
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1061
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1062
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1063
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1064
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1065
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1066
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1067
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1068
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1069
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1056
+				$ais_data = $AIS->parse_line(trim($buffer));
1057
+				$data = array();
1058
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1059
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1060
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1061
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1062
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1063
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1064
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1065
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1066
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1067
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1068
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1069
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1070 1070
 
1071
-			    if (isset($ais_data['timestamp'])) {
1071
+				if (isset($ais_data['timestamp'])) {
1072 1072
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1073
-			    } else {
1073
+				} else {
1074 1074
 				$data['datetime'] = date('Y-m-d H:i:s');
1075
-			    }
1076
-			    $data['format_source'] = 'aisnmea';
1077
-    			    $data['id_source'] = $id_source;
1078
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1079
-			    unset($data);
1080
-                        } elseif ($format == 'flightgearsp') {
1081
-                    	    //echo $buffer."\n";
1082
-                    	    if (strlen($buffer) > 5) {
1075
+				}
1076
+				$data['format_source'] = 'aisnmea';
1077
+					$data['id_source'] = $id_source;
1078
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1079
+				unset($data);
1080
+						} elseif ($format == 'flightgearsp') {
1081
+							//echo $buffer."\n";
1082
+							if (strlen($buffer) > 5) {
1083 1083
 				$line = explode(',',$buffer);
1084 1084
 				$data = array();
1085 1085
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1095,37 +1095,37 @@  discard block
 block discarded – undo
1095 1095
 				$data['format_source'] = 'flightgearsp';
1096 1096
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1097 1097
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1098
-			    }
1099
-                        } elseif ($format == 'acars') {
1100
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1101
-			    $ACARS->add(trim($buffer));
1102
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1103
-			    $ACARS->deleteLiveAcarsData();
1098
+				}
1099
+						} elseif ($format == 'acars') {
1100
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1101
+				$ACARS->add(trim($buffer));
1102
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1103
+				$ACARS->deleteLiveAcarsData();
1104 1104
 			} elseif ($format == 'flightgearmp') {
1105
-			    if (substr($buffer,0,1) != '#') {
1105
+				if (substr($buffer,0,1) != '#') {
1106 1106
 				$data = array();
1107 1107
 				//echo $buffer."\n";
1108 1108
 				$line = explode(' ',$buffer);
1109 1109
 				if (count($line) == 11) {
1110
-				    $userserver = explode('@',$line[0]);
1111
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1112
-				    $data['ident'] = $userserver[0];
1113
-				    $data['registration'] = $userserver[0];
1114
-				    $data['latitude'] = $line[4];
1115
-				    $data['longitude'] = $line[5];
1116
-				    $data['altitude'] = $line[6];
1117
-				    $data['datetime'] = date('Y-m-d H:i:s');
1118
-				    $aircraft_type = $line[10];
1119
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1120
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1121
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1110
+					$userserver = explode('@',$line[0]);
1111
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1112
+					$data['ident'] = $userserver[0];
1113
+					$data['registration'] = $userserver[0];
1114
+					$data['latitude'] = $line[4];
1115
+					$data['longitude'] = $line[5];
1116
+					$data['altitude'] = $line[6];
1117
+					$data['datetime'] = date('Y-m-d H:i:s');
1118
+					$aircraft_type = $line[10];
1119
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1120
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1121
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1122
+				}
1122 1123
 				}
1123
-			    }
1124 1124
 			} elseif ($format == 'beast') {
1125
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1126
-			    die;
1125
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1126
+				die;
1127 1127
 			} elseif ($format == 'vrstcp') {
1128
-			    foreach($buffer as $all_data) {
1128
+				foreach($buffer as $all_data) {
1129 1129
 				$line = json_decode('{'.$all_data.'}',true);
1130 1130
 				$data = array();
1131 1131
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1145,103 +1145,103 @@  discard block
 block discarded – undo
1145 1145
 				*/
1146 1146
 				$data['datetime'] = date('Y-m-d H:i:s');
1147 1147
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1148
-		    		$data['format_source'] = 'vrstcp';
1148
+					$data['format_source'] = 'vrstcp';
1149 1149
 				$data['id_source'] = $id_source;
1150 1150
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1151 1151
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1152 1152
 				unset($data);
1153
-			    }
1153
+				}
1154 1154
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1155
-			    $line = explode("\t", $buffer);
1156
-			    for($k = 0; $k < count($line); $k=$k+2) {
1155
+				$line = explode("\t", $buffer);
1156
+				for($k = 0; $k < count($line); $k=$k+2) {
1157 1157
 				$key = $line[$k];
1158
-			        $lined[$key] = $line[$k+1];
1159
-			    }
1160
-    			    if (count($lined) > 3) {
1161
-    				$data['hex'] = $lined['hexid'];
1162
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1163
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1164
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1165
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1166
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1167
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1168
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1169
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1170
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1171
-    				$data['id_source'] = $id_source;
1172
-    				$data['format_source'] = 'tsv';
1173
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1174
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1175
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1176
-    				unset($lined);
1177
-    				unset($data);
1178
-    			    } else $error = true;
1158
+					$lined[$key] = $line[$k+1];
1159
+				}
1160
+					if (count($lined) > 3) {
1161
+					$data['hex'] = $lined['hexid'];
1162
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1163
+					$data['datetime'] = date('Y-m-d H:i:s');;
1164
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1165
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1166
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1167
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1168
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1169
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1170
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1171
+					$data['id_source'] = $id_source;
1172
+					$data['format_source'] = 'tsv';
1173
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1174
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1175
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1176
+					unset($lined);
1177
+					unset($data);
1178
+					} else $error = true;
1179 1179
 			} elseif ($format == 'aprs' && $use_aprs) {
1180
-			    if ($aprs_connect == 0) {
1180
+				if ($aprs_connect == 0) {
1181 1181
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1182 1182
 				$aprs_connect = 1;
1183
-			    }
1183
+				}
1184 1184
 			    
1185
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1185
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1186 1186
 				$aprs_last_tx = time();
1187 1187
 				$data_aprs = "# Keep alive";
1188 1188
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1189
-			    }
1189
+				}
1190 1190
 			    
1191
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1192
-			    //echo 'APRS data : '.$buffer."\n";
1193
-			    $buffer = str_replace('APRS <- ','',$buffer);
1194
-			    $buffer = str_replace('APRS -> ','',$buffer);
1195
-			    //echo $buffer."\n";
1196
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1191
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1192
+				//echo 'APRS data : '.$buffer."\n";
1193
+				$buffer = str_replace('APRS <- ','',$buffer);
1194
+				$buffer = str_replace('APRS -> ','',$buffer);
1195
+				//echo $buffer."\n";
1196
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1197 1197
 				$line = $APRS->parse($buffer);
1198 1198
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1199 1199
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1200
-				    $aprs_last_tx = time();
1201
-				    $data = array();
1202
-				    //print_r($line);
1203
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1204
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1205
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1206
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1207
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1208
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1209
-				    $data['latitude'] = $line['latitude'];
1210
-				    $data['longitude'] = $line['longitude'];
1211
-				    //$data['verticalrate'] = $line[16];
1212
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1213
-				    else $data['speed'] = 0;
1214
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1215
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1216
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1217
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1218
-				    //else $data['heading'] = 0;
1219
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1220
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1221
-    				    $data['id_source'] = $id_source;
1222
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1223
-				    else $data['format_source'] = 'aprs';
1224
-				    $data['source_name'] = $line['source'];
1225
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1226
-				    else $data['source_type'] = 'flarm';
1227
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1228
-				    $currentdate = date('Y-m-d H:i:s');
1229
-				    $aprsdate = strtotime($data['datetime']);
1230
-				    // Accept data if time <= system time + 20s
1231
-				    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'])))) {
1200
+					$aprs_last_tx = time();
1201
+					$data = array();
1202
+					//print_r($line);
1203
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1204
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1205
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1206
+					else $data['datetime'] = date('Y-m-d H:i:s');
1207
+					//$data['datetime'] = date('Y-m-d H:i:s');
1208
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1209
+					$data['latitude'] = $line['latitude'];
1210
+					$data['longitude'] = $line['longitude'];
1211
+					//$data['verticalrate'] = $line[16];
1212
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1213
+					else $data['speed'] = 0;
1214
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1215
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1216
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1217
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1218
+					//else $data['heading'] = 0;
1219
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1220
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1221
+						$data['id_source'] = $id_source;
1222
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1223
+					else $data['format_source'] = 'aprs';
1224
+					$data['source_name'] = $line['source'];
1225
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1226
+					else $data['source_type'] = 'flarm';
1227
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1228
+					$currentdate = date('Y-m-d H:i:s');
1229
+					$aprsdate = strtotime($data['datetime']);
1230
+					// Accept data if time <= system time + 20s
1231
+					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'])))) {
1232 1232
 					$send = $SI->add($data);
1233
-				    } elseif ($data['source_type'] == 'ais') {
1233
+					} elseif ($data['source_type'] == 'ais') {
1234 1234
 					echo 'add...'."\n";
1235 1235
 					$send = $MI->add($data);
1236
-				    } elseif (isset($line['stealth'])) {
1236
+					} elseif (isset($line['stealth'])) {
1237 1237
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1238 1238
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1239
-				    //} elseif (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' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1240
-				    } 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') {
1239
+					//} elseif (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' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1240
+					} 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') {
1241 1241
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1242 1242
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1243
-				    }
1244
-				    unset($data);
1243
+					}
1244
+					unset($data);
1245 1245
 				} 
1246 1246
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1247 1247
 					echo '!! Weather Station not yet supported'."\n";
@@ -1251,12 +1251,12 @@  discard block
 block discarded – undo
1251 1251
 				}
1252 1252
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1253 1253
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1254
-			    }
1254
+				}
1255 1255
 			} else {
1256
-			    $line = explode(',', $buffer);
1257
-    			    if (count($line) > 20) {
1258
-    			    	$data['hex'] = $line[4];
1259
-    				/*
1256
+				$line = explode(',', $buffer);
1257
+					if (count($line) > 20) {
1258
+						$data['hex'] = $line[4];
1259
+					/*
1260 1260
     				$data['datetime'] = $line[6].' '.$line[7];
1261 1261
     					date_default_timezone_set($globalTimezone);
1262 1262
     					$datetime = new DateTime($data['datetime']);
@@ -1264,29 +1264,29 @@  discard block
 block discarded – undo
1264 1264
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1265 1265
     					date_default_timezone_set('UTC');
1266 1266
     				*/
1267
-    				// Force datetime to current UTC datetime
1268
-    				date_default_timezone_set('UTC');
1269
-    				$data['datetime'] = date('Y-m-d H:i:s');
1270
-    				$data['ident'] = trim($line[10]);
1271
-    				$data['latitude'] = $line[14];
1272
-    				$data['longitude'] = $line[15];
1273
-    				$data['verticalrate'] = $line[16];
1274
-    				$data['emergency'] = $line[20];
1275
-    				$data['speed'] = $line[12];
1276
-    				$data['squawk'] = $line[17];
1277
-    				$data['altitude'] = $line[11];
1278
-    				$data['heading'] = $line[13];
1279
-    				$data['ground'] = $line[21];
1280
-    				$data['emergency'] = $line[19];
1281
-    				$data['format_source'] = 'sbs';
1267
+					// Force datetime to current UTC datetime
1268
+					date_default_timezone_set('UTC');
1269
+					$data['datetime'] = date('Y-m-d H:i:s');
1270
+					$data['ident'] = trim($line[10]);
1271
+					$data['latitude'] = $line[14];
1272
+					$data['longitude'] = $line[15];
1273
+					$data['verticalrate'] = $line[16];
1274
+					$data['emergency'] = $line[20];
1275
+					$data['speed'] = $line[12];
1276
+					$data['squawk'] = $line[17];
1277
+					$data['altitude'] = $line[11];
1278
+					$data['heading'] = $line[13];
1279
+					$data['ground'] = $line[21];
1280
+					$data['emergency'] = $line[19];
1281
+					$data['format_source'] = 'sbs';
1282 1282
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1283
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1284
-    				$data['id_source'] = $id_source;
1285
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1286
-    				else $error = true;
1287
-    				unset($data);
1288
-    			    } else $error = true;
1289
-			    if ($error) {
1283
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1284
+					$data['id_source'] = $id_source;
1285
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1286
+					else $error = true;
1287
+					unset($data);
1288
+					} else $error = true;
1289
+				if ($error) {
1290 1290
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1291 1291
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1292 1292
 				} else {
@@ -1302,13 +1302,13 @@  discard block
 block discarded – undo
1302 1302
 					connect_all($sourceer);
1303 1303
 					$sourceer = array();
1304 1304
 				}
1305
-			    }
1305
+				}
1306 1306
 			}
1307 1307
 			// Sleep for xxx microseconds
1308 1308
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1309
-		    } else {
1309
+			} else {
1310 1310
 			if ($format == 'flightgearmp') {
1311
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1311
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1312 1312
 				//@socket_close($r);
1313 1313
 				sleep($globalMinFetch);
1314 1314
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1317,9 +1317,9 @@  discard block
 block discarded – undo
1317 1317
 				break;
1318 1318
 				
1319 1319
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1320
-			    if (isset($tt[$format])) $tt[$format]++;
1321
-			    else $tt[$format] = 0;
1322
-			    if ($tt[$format] > 30) {
1320
+				if (isset($tt[$format])) $tt[$format]++;
1321
+				else $tt[$format] = 0;
1322
+				if ($tt[$format] > 30) {
1323 1323
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1324 1324
 				//@socket_close($r);
1325 1325
 				sleep(2);
@@ -1330,23 +1330,23 @@  discard block
 block discarded – undo
1330 1330
 				//connect_all($globalSources);
1331 1331
 				$tt[$format]=0;
1332 1332
 				break;
1333
-			    }
1333
+				}
1334
+			}
1334 1335
 			}
1335
-		    }
1336 1336
 		}
1337
-	    } else {
1337
+		} else {
1338 1338
 		$error = socket_strerror(socket_last_error());
1339 1339
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1340 1340
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1341 1341
 			if (isset($globalDebug)) echo "Restarting...\n";
1342 1342
 			// Restart the script if possible
1343 1343
 			if (is_array($sockets)) {
1344
-			    if ($globalDebug) echo "Shutdown all sockets...";
1344
+				if ($globalDebug) echo "Shutdown all sockets...";
1345 1345
 			    
1346
-			    foreach ($sockets as $sock) {
1346
+				foreach ($sockets as $sock) {
1347 1347
 				@socket_shutdown($sock,2);
1348 1348
 				@socket_close($sock);
1349
-			    }
1349
+				}
1350 1350
 			    
1351 1351
 			}
1352 1352
 			if ($globalDebug) echo "Restart all connections...";
@@ -1360,13 +1360,13 @@  discard block
 block discarded – undo
1360 1360
 			if ($reset > 100) exit('Too many attempts...');
1361 1361
 			connect_all($globalSources);
1362 1362
 		}
1363
-	    }
1363
+		}
1364 1364
 	}
1365 1365
 	if ($globalDaemon === false) {
1366
-	    if ($globalDebug) echo 'Check all...'."\n";
1367
-	    $SI->checkAll();
1366
+		if ($globalDebug) echo 'Check all...'."\n";
1367
+		$SI->checkAll();
1368
+	}
1368 1369
 	}
1369
-    }
1370 1370
 }
1371 1371
 
1372 1372
 ?>
Please login to merge, or discard this patch.
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -45,20 +45,20 @@  discard block
 block discarded – undo
45 45
 	    die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
48
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
49 49
     }
50 50
 }
51 51
 
52
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56 56
     $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
57
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
58 58
     else $globalSources[] = array('host' => $options['s']);
59 59
 } elseif (isset($options['source'])) {
60 60
     $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
61
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
62 62
     else $globalSources[] = array('host' => $options['source']);
63 63
 }
64 64
 if (isset($options['aprsserverhost'])) $globalServerAPRShost = $options['aprsserverhost'];
@@ -71,27 +71,27 @@  discard block
 block discarded – undo
71 71
 else $id_source = 1;
72 72
 if (isset($globalServer) && $globalServer) {
73 73
     if ($globalDebug) echo "Using Server Mode\n";
74
-    $SI=new SpotterServer();
74
+    $SI = new SpotterServer();
75 75
 /*
76 76
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
77 77
     $SI = new adsb2aprs();
78 78
     $SI->connect();
79 79
 */
80
-} else $SI=new SpotterImport($Connection->db);
80
+} else $SI = new SpotterImport($Connection->db);
81 81
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
82 82
 if (isset($globalMarine) && $globalMarine) {
83 83
     $AIS = new AIS();
84 84
     $MI = new MarineImport($Connection->db);
85 85
 }
86 86
 //$APRS=new APRS($Connection->db);
87
-$SBS=new SBS();
88
-$ACARS=new ACARS($Connection->db);
89
-$Common=new Common();
87
+$SBS = new SBS();
88
+$ACARS = new ACARS($Connection->db);
89
+$Common = new Common();
90 90
 date_default_timezone_set('UTC');
91 91
 //$servertz = system('date +%Z');
92 92
 // signal handler - playing nice with sockets and dump1090
93 93
 if (function_exists('pcntl_fork')) {
94
-    pcntl_signal(SIGINT,  function() {
94
+    pcntl_signal(SIGINT, function() {
95 95
         global $sockets;
96 96
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
97 97
         die("Bye!\n");
@@ -107,35 +107,35 @@  discard block
 block discarded – undo
107 107
 
108 108
 function connect_all($hosts) {
109 109
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
110
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
110
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
111 111
     $reset++;
112 112
     if ($globalDebug) echo 'Connect to all...'."\n";
113 113
     foreach ($hosts as $id => $value) {
114 114
 	$host = $value['host'];
115 115
 	$globalSources[$id]['last_exec'] = 0;
116 116
 	// Here we check type of source(s)
117
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
118
-            if (preg_match('/deltadb.txt$/i',$host)) {
117
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
118
+            if (preg_match('/deltadb.txt$/i', $host)) {
119 119
         	//$formats[$id] = 'deltadbtxt';
120 120
         	$globalSources[$id]['format'] = 'deltadbtxt';
121 121
         	//$last_exec['deltadbtxt'] = 0;
122 122
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
123
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
123
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
124 124
         	//$formats[$id] = 'vatsimtxt';
125 125
         	$globalSources[$id]['format'] = 'vatsimtxt';
126 126
         	//$last_exec['vatsimtxt'] = 0;
127 127
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
128
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
128
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
129 129
         	//$formats[$id] = 'aircraftlistjson';
130 130
         	$globalSources[$id]['format'] = 'aircraftlistjson';
131 131
         	//$last_exec['aircraftlistjson'] = 0;
132 132
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
133
-    	    } else if (preg_match('/opensky/i',$host)) {
133
+    	    } else if (preg_match('/opensky/i', $host)) {
134 134
         	//$formats[$id] = 'aircraftlistjson';
135 135
         	$globalSources[$id]['format'] = 'opensky';
136 136
         	//$last_exec['aircraftlistjson'] = 0;
137 137
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
138
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
138
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
139 139
         	//$formats[$id] = 'radarvirtueljson';
140 140
         	$globalSources[$id]['format'] = 'radarvirtueljson';
141 141
         	//$last_exec['radarvirtueljson'] = 0;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
145 145
         	    exit(0);
146 146
         	}
147
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
147
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
148 148
         	//$formats[$id] = 'planeupdatefaa';
149 149
         	$globalSources[$id]['format'] = 'planeupdatefaa';
150 150
         	//$last_exec['planeupdatefaa'] = 0;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
154 154
         	    exit(0);
155 155
         	}
156
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
156
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
157 157
         	//$formats[$id] = 'phpvmacars';
158 158
         	$globalSources[$id]['format'] = 'phpvmacars';
159 159
         	//$last_exec['phpvmacars'] = 0;
160 160
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
161
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
161
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
162 162
         	//$formats[$id] = 'phpvmacars';
163 163
         	$globalSources[$id]['format'] = 'vam';
164 164
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
165
-            } else if (preg_match('/whazzup/i',$host)) {
165
+            } else if (preg_match('/whazzup/i', $host)) {
166 166
         	//$formats[$id] = 'whazzup';
167 167
         	$globalSources[$id]['format'] = 'whazzup';
168 168
         	//$last_exec['whazzup'] = 0;
169 169
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
170
-            } else if (preg_match('/recentpireps/i',$host)) {
170
+            } else if (preg_match('/recentpireps/i', $host)) {
171 171
         	//$formats[$id] = 'pirepsjson';
172 172
         	$globalSources[$id]['format'] = 'pirepsjson';
173 173
         	//$last_exec['pirepsjson'] = 0;
174 174
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
175
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
175
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
176 176
         	//$formats[$id] = 'fr24json';
177 177
         	$globalSources[$id]['format'] = 'fr24json';
178 178
         	//$last_exec['fr24json'] = 0;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
182 182
         	    exit(0);
183 183
         	}
184
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
184
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
185 185
         	//$formats[$id] = 'fr24json';
186 186
         	$globalSources[$id]['format'] = 'myshiptracking';
187 187
         	//$last_exec['fr24json'] = 0;
@@ -191,22 +191,22 @@  discard block
 block discarded – undo
191 191
         	    exit(0);
192 192
         	}
193 193
             //} else if (preg_match('/10001/',$host)) {
194
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
194
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
195 195
         	//$formats[$id] = 'tsv';
196 196
         	$globalSources[$id]['format'] = 'tsv';
197 197
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
198 198
             }
199
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
199
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
200 200
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
201
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
201
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
202 202
     		    if ($idf !== false) {
203 203
     			$httpfeeds[$id] = $idf;
204 204
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
205 205
     		    }
206 206
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
207 207
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
208
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
209
-	    $hostport = explode(':',$host);
208
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
209
+	    $hostport = explode(':', $host);
210 210
 	    if (isset($hostport[1])) {
211 211
 		$port = $hostport[1];
212 212
 		$hostn = $hostport[0];
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 	    }
217 217
 	    $Common = new Common();
218 218
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
219
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
219
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
220 220
     	    } else {
221
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
221
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
222 222
 	    }
223 223
 	    if ($s) {
224 224
     	        $sockets[$id] = $s;
225 225
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
226
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
226
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
227 227
 			//$formats[$id] = 'aprs';
228 228
 			$globalSources[$id]['format'] = 'aprs';
229 229
 			//$aprs_connect = 0;
230 230
 			//$use_aprs = true;
231
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
231
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
232 232
 			$globalSources[$id]['format'] = 'vrstcp';
233 233
     		    } elseif ($port == '10001') {
234 234
         		//$formats[$id] = 'tsv';
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
268 268
 else $timeout = 20;
269 269
 $errno = '';
270
-$errstr='';
270
+$errstr = '';
271 271
 
272 272
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
273 273
 /* Initiate connections to all the hosts simultaneously */
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 //connect_all($globalSources);
276 276
 
277 277
 if (isset($globalProxy) && $globalProxy) {
278
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
278
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
279 279
 } else {
280 280
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
281 281
 }
@@ -302,16 +302,16 @@  discard block
 block discarded – undo
302 302
 
303 303
 if ($use_aprs) {
304 304
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
305
-	$APRS=new APRS();
305
+	$APRS = new APRS();
306 306
 	$aprs_connect = 0;
307 307
 	$aprs_keep = 120;
308 308
 	$aprs_last_tx = time();
309 309
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
310
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
310
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
311 311
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
312
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
312
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
313 313
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
314
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
314
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
315 315
 	if ($aprs_full) $aprs_filter = '';
316 316
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
317 317
 	else $aprs_pass = '-1';
@@ -325,12 +325,12 @@  discard block
 block discarded – undo
325 325
 sleep(1);
326 326
 if ($globalDebug) echo "SCAN MODE \n\n";
327 327
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
328
-$endtime = time()+$globalCronEnd;
328
+$endtime = time() + $globalCronEnd;
329 329
 $i = 1;
330 330
 $tt = array();
331 331
 // Delete all ATC
332 332
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
333
-	$ATC=new ATC($Connection->db);
333
+	$ATC = new ATC($Connection->db);
334 334
 }
335 335
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336 336
 	$ATC->deleteAll();
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 
339 339
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
340 340
 while ($i > 0) {
341
-    if (!$globalDaemon) $i = $endtime-time();
341
+    if (!$globalDaemon) $i = $endtime - time();
342 342
     // Delete old ATC
343 343
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
344 344
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 	}
354 354
 	if ($max != $globalMinFetch) {
355 355
 	    if ($globalDebug) echo 'Sleeping...'."\n";
356
-	    sleep($globalMinFetch-$max+2);
356
+	    sleep($globalMinFetch - $max + 2);
357 357
 	}
358 358
     }
359 359
 
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	    //$buffer = $Common->getData($hosts[$id]);
367 367
 	    $buffer = $Common->getData($value['host']);
368 368
 	    if ($buffer != '') $reset = 0;
369
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
370
-	    $buffer = explode('\n',$buffer);
369
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
370
+	    $buffer = explode('\n', $buffer);
371 371
 	    foreach ($buffer as $line) {
372 372
     		if ($line != '' && count($line) > 7) {
373 373
     		    $line = explode(',', $line);
@@ -394,11 +394,11 @@  discard block
 block discarded – undo
394 394
     	    $last_exec[$id]['last'] = time();
395 395
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
396 396
 	    date_default_timezone_set('CET');
397
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
397
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
398 398
 	    date_default_timezone_set('UTC');
399 399
 	    if ($buffer != '') $reset = 0;
400
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
401
-	    $buffer = explode('\n',$buffer);
400
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
401
+	    $buffer = explode('\n', $buffer);
402 402
 	    foreach ($buffer as $line) {
403 403
 		if ($line != '') {
404 404
 		    echo "'".$line."'\n";
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
417 417
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
418 418
 		    if (isset($ais_data['timestamp'])) {
419
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
419
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
420 420
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
421 421
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
422 422
 			    $add = true;
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 	    $w = $e = null;
440 440
 	    
441 441
 	    if (isset($arr[$id])) {
442
-	    $nn = stream_select($arr,$w,$e,$timeout);
442
+	    $nn = stream_select($arr, $w, $e, $timeout);
443 443
 	    if ($nn > 0) {
444 444
 		foreach ($httpfeeds as $feed) {
445
-		    $buffer = stream_get_line($feed,2000,"\n");
446
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
447
-		    $buffer = explode('\n',$buffer);
445
+		    $buffer = stream_get_line($feed, 2000, "\n");
446
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
447
+		    $buffer = explode('\n', $buffer);
448 448
 		    foreach ($buffer as $line) {
449 449
 			if ($line != '') {
450 450
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -460,9 +460,9 @@  discard block
 block discarded – undo
460 460
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
461 461
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
462 462
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
463
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
463
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
464 464
 			    if (isset($ais_data['timestamp'])) {
465
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
465
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
466 466
 			    } else {
467 467
 				$data['datetime'] = date('Y-m-d H:i:s');
468 468
 			    }
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 		}
477 477
 	    }
478 478
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
479
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
479
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
480 480
 	    if ($buffer != '') {
481 481
 		//echo $buffer;
482
-		$all_data = json_decode($buffer,true);
482
+		$all_data = json_decode($buffer, true);
483 483
 		//print_r($all_data);
484 484
 		if (isset($all_data[0]['DATA'])) {
485 485
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
495 495
 			$data['imo'] = $line['IMO'];
496 496
 			//$data['arrival_code'] = $ais_data['destination'];
497
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
497
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
498 498
 			$data['format_source'] = 'myshiptracking';
499 499
 			$data['id_source'] = $id_source;
500 500
 			$MI->add($data);
@@ -506,9 +506,9 @@  discard block
 block discarded – undo
506 506
 	    }
507 507
     	    $last_exec[$id]['last'] = time();
508 508
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
509
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
509
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
510 510
 	    if ($buffer != '') {
511
-		$all_data = json_decode($buffer,true);
511
+		$all_data = json_decode($buffer, true);
512 512
 		if (isset($all_data[0]['mmsi'])) {
513 513
 		    foreach ($all_data as $line) {
514 514
 			if ($line != '') {
@@ -535,27 +535,27 @@  discard block
 block discarded – undo
535 535
     	    $last_exec[$id]['last'] = time();
536 536
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
537 537
 	    echo 'download...';
538
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
538
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
539 539
 	    echo 'done !'."\n";
540 540
 	    if ($buffer != '') $reset = 0;
541
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
542
-	    $buffer = explode('\n',$buffer);
541
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
542
+	    $buffer = explode('\n', $buffer);
543 543
 	    foreach ($buffer as $line) {
544 544
 		if ($line != '') {
545 545
 		    $data = array();
546
-		    $data['mmsi'] = (int)substr($line,0,9);
547
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
546
+		    $data['mmsi'] = (int) substr($line, 0, 9);
547
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
548 548
 		    //$data['status'] = substr($line,21,2);
549 549
 		    //$data['type'] = substr($line,24,3);
550
-		    $data['latitude'] = substr($line,29,9);
551
-		    $data['longitude'] = substr($line,41,9);
552
-		    $data['speed'] = round(substr($line,51,5));
550
+		    $data['latitude'] = substr($line, 29, 9);
551
+		    $data['longitude'] = substr($line, 41, 9);
552
+		    $data['speed'] = round(substr($line, 51, 5));
553 553
 		    //$data['course'] = substr($line,57,5);
554
-		    $data['heading'] = round(substr($line,63,3));
554
+		    $data['heading'] = round(substr($line, 63, 3));
555 555
 		    //$data['draft'] = substr($line,67,4);
556 556
 		    //$data['length'] = substr($line,72,3);
557 557
 		    //$data['beam'] = substr($line,76,2);
558
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
558
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
559 559
 		    //$data['callsign'] = trim(substr($line,100,7);
560 560
 		    //$data['dest'] = substr($line,108,20);
561 561
 		    //$data['etaDate'] = substr($line,129,5);
@@ -573,8 +573,8 @@  discard block
 block discarded – undo
573 573
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
574 574
 	    //$buffer = $Common->getData($hosts[$id]);
575 575
 	    $buffer = $Common->getData($value['host']);
576
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
577
-	    $buffer = explode('\n',$buffer);
576
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
577
+	    $buffer = explode('\n', $buffer);
578 578
 	    $reset = 0;
579 579
 	    foreach ($buffer as $line) {
580 580
     		if ($line != '') {
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
586 586
 			$data['pilot_id'] = $line[1];
587 587
 			$data['pilot_name'] = $line[2];
588
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
588
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
589 589
 			$data['ident'] = $line[0]; // ident
590 590
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
591 591
 			$data['speed'] = $line[8]; // speed
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
602 602
 			//if (isset($line[37])) $data['last_update'] = $line[37];
603 603
 		        $data['departure_airport_icao'] = $line[11];
604
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
604
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
605 605
 		        $data['arrival_airport_icao'] = $line[13];
606 606
 			$data['frequency'] = $line[4];
607 607
 			$data['type'] = $line[18];
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
     			$data['id_source'] = $id_source;
611 611
 	    		//$data['arrival_airport_time'] = ;
612 612
 	    		if ($line[9] != '') {
613
-	    		    $aircraft_data = explode('/',$line[9]);
613
+	    		    $aircraft_data = explode('/', $line[9]);
614 614
 	    		    if (isset($aircraft_data[1])) {
615 615
 	    			$data['aircraft_icao'] = $aircraft_data[1];
616 616
 	    		    }
@@ -624,9 +624,9 @@  discard block
 block discarded – undo
624 624
     			if ($line[3] == 'PILOT') $SI->add($data);
625 625
 			elseif ($line[3] == 'ATC') {
626 626
 				//print_r($data);
627
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
628
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
629
-				$typec = substr($data['ident'],-3);
627
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
628
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
629
+				$typec = substr($data['ident'], -3);
630 630
 				if ($typec == 'APP') $data['type'] = 'Approach';
631 631
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
632 632
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
638 638
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
639 639
 				if (!isset($data['source_name'])) $data['source_name'] = '';
640
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
640
+				if (isset($ATC)) echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
641 641
 			}
642 642
     			unset($data);
643 643
     		    }
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
     	    $last_exec[$id]['last'] = time();
649 649
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
650 650
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
651
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
651
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
652 652
 	    if ($buffer != '') {
653
-	    $all_data = json_decode($buffer,true);
653
+	    $all_data = json_decode($buffer, true);
654 654
 	    if (isset($all_data['acList'])) {
655 655
 		$reset = 0;
656 656
 		foreach ($all_data['acList'] as $line) {
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
707 707
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
708 708
 	    $buffer = $Common->getData($value['host']);
709
-	    $all_data = json_decode($buffer,true);
709
+	    $all_data = json_decode($buffer, true);
710 710
 	    if (isset($all_data['planes'])) {
711 711
 		$reset = 0;
712 712
 		foreach ($all_data['planes'] as $key => $line) {
@@ -723,12 +723,12 @@  discard block
 block discarded – undo
723 723
 		    $data['emergency'] = ''; // emergency
724 724
 		    $data['registration'] = $line[2];
725 725
 		    $data['aircraft_icao'] = $line[0];
726
-		    $deparr = explode('-',$line[1]);
726
+		    $deparr = explode('-', $line[1]);
727 727
 		    if (count($deparr) == 2) {
728 728
 			$data['departure_airport_icao'] = $deparr[0];
729 729
 			$data['arrival_airport_icao'] = $deparr[1];
730 730
 		    }
731
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
731
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
732 732
 	    	    $data['format_source'] = 'planeupdatefaa';
733 733
     		    $data['id_source'] = $id_source;
734 734
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
     	    $last_exec[$id]['last'] = time();
741 741
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
742 742
 	    $buffer = $Common->getData($value['host']);
743
-	    $all_data = json_decode($buffer,true);
743
+	    $all_data = json_decode($buffer, true);
744 744
 	    if (isset($all_data['states'])) {
745 745
 		$reset = 0;
746 746
 		foreach ($all_data['states'] as $key => $line) {
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 		    //$data['emergency'] = ''; // emergency
758 758
 		    //$data['registration'] = $line[2];
759 759
 		    //$data['aircraft_icao'] = $line[0];
760
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
760
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
761 761
 	    	    $data['format_source'] = 'opensky';
762 762
     		    $data['id_source'] = $id_source;
763 763
 		    $SI->add($data);
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
771 771
 	    //$buffer = $Common->getData($hosts[$id]);
772 772
 	    $buffer = $Common->getData($value['host']);
773
-	    $all_data = json_decode($buffer,true);
773
+	    $all_data = json_decode($buffer, true);
774 774
 	    if (!empty($all_data)) $reset = 0;
775 775
 	    foreach ($all_data as $key => $line) {
776 776
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -802,11 +802,11 @@  discard block
 block discarded – undo
802 802
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
803 803
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
804 804
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
805
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
805
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
806 806
 	    //echo $buffer;
807
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
808
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
809
-	    $all_data = json_decode($buffer,true);
807
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
808
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
809
+	    $all_data = json_decode($buffer, true);
810 810
 	    if (json_last_error() != JSON_ERROR_NONE) {
811 811
 		die(json_last_error_msg());
812 812
 	    }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 			//$data['departure_airport_iata'] = $line[11];
830 830
 			//$data['arrival_airport_iata'] = $line[12];
831 831
 	    		//$data['emergency'] = ''; // emergency
832
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
832
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
833 833
 	    		$data['format_source'] = 'radarvirtueljson';
834 834
     			$data['id_source'] = $id_source;
835 835
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -844,14 +844,14 @@  discard block
 block discarded – undo
844 844
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
845 845
 	    //$buffer = $Common->getData($hosts[$id]);
846 846
 	    $buffer = $Common->getData($value['host'].'?'.time());
847
-	    $all_data = json_decode(utf8_encode($buffer),true);
847
+	    $all_data = json_decode(utf8_encode($buffer), true);
848 848
 	    
849 849
 	    if (isset($all_data['pireps'])) {
850 850
 		$reset = 0;
851 851
 	        foreach ($all_data['pireps'] as $line) {
852 852
 		    $data = array();
853 853
 		    $data['id'] = $line['id'];
854
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
854
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
855 855
 		    $data['ident'] = $line['callsign']; // ident
856 856
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
857 857
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -880,9 +880,9 @@  discard block
 block discarded – undo
880 880
 			$SI->add($data);
881 881
 		    //    print_r($data);
882 882
     		    } elseif ($line['icon'] == 'ct') {
883
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
884
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
885
-			$typec = substr($data['ident'],-3);
883
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
884
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
885
+			$typec = substr($data['ident'], -3);
886 886
 			$data['type'] = '';
887 887
 			if ($typec == 'APP') $data['type'] = 'Approach';
888 888
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
894 894
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
895 895
 			else $data['type'] = 'Observer';
896
-			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']);
896
+			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']);
897 897
 		    }
898 898
 		    unset($data);
899 899
 		}
@@ -905,14 +905,14 @@  discard block
 block discarded – undo
905 905
 	    //$buffer = $Common->getData($hosts[$id]);
906 906
 	    if ($globalDebug) echo 'Get Data...'."\n";
907 907
 	    $buffer = $Common->getData($value['host']);
908
-	    $all_data = json_decode($buffer,true);
908
+	    $all_data = json_decode($buffer, true);
909 909
 	    if ($buffer != '' && is_array($all_data)) {
910 910
 		$reset = 0;
911 911
 		foreach ($all_data as $line) {
912 912
 	    	    $data = array();
913 913
 	    	    //$data['id'] = $line['id']; // id not usable
914 914
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
915
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
915
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
916 916
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
917 917
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
918 918
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -935,14 +935,14 @@  discard block
 block discarded – undo
935 935
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
936 936
 		    if (isset($line['aircraftname'])) {
937 937
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
938
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
939
-	    		$aircraft_data = explode('-',$line['aircraftname']);
938
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
939
+	    		$aircraft_data = explode('-', $line['aircraftname']);
940 940
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
941 941
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
942 942
 	    		else {
943
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
944
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
945
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
943
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
944
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
945
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
946 946
 	    		}
947 947
 	    	    }
948 948
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -962,14 +962,14 @@  discard block
 block discarded – undo
962 962
 	    //$buffer = $Common->getData($hosts[$id]);
963 963
 	    if ($globalDebug) echo 'Get Data...'."\n";
964 964
 	    $buffer = $Common->getData($value['host']);
965
-	    $all_data = json_decode($buffer,true);
965
+	    $all_data = json_decode($buffer, true);
966 966
 	    if ($buffer != '' && is_array($all_data)) {
967 967
 		$reset = 0;
968 968
 		foreach ($all_data as $line) {
969 969
 	    	    $data = array();
970 970
 	    	    //$data['id'] = $line['id']; // id not usable
971 971
 	    	    $data['id'] = trim($line['flight_id']);
972
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
972
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
973 973
 	    	    $data['pilot_name'] = $line['pilot_name'];
974 974
 	    	    $data['pilot_id'] = $line['pilot_id'];
975 975
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1020,11 +1020,11 @@  discard block
 block discarded – undo
1020 1020
 		    //$value = $formats[$nb];
1021 1021
 		    $format = $globalSources[$nb]['format'];
1022 1022
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1023
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1023
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1024 1024
 		    } elseif ($format == 'vrstcp') {
1025 1025
 			$buffer = @socket_read($r, 6000);
1026 1026
 		    } else {
1027
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1027
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1028 1028
 		    }
1029 1029
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1030 1030
 		    //echo $buffer."\n";
@@ -1033,8 +1033,8 @@  discard block
 block discarded – undo
1033 1033
 		    $error = false;
1034 1034
 		    //$SI::del();
1035 1035
 		    if ($format == 'vrstcp') {
1036
-			$buffer = explode('},{',$buffer);
1037
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1036
+			$buffer = explode('},{', $buffer);
1037
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1038 1038
 		    // SBS format is CSV format
1039 1039
 		    if ($buffer !== FALSE && $buffer != '') {
1040 1040
 			$tt[$format] = 0;
@@ -1066,10 +1066,10 @@  discard block
 block discarded – undo
1066 1066
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1067 1067
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1068 1068
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1069
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1069
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1070 1070
 
1071 1071
 			    if (isset($ais_data['timestamp'])) {
1072
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1072
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1073 1073
 			    } else {
1074 1074
 				$data['datetime'] = date('Y-m-d H:i:s');
1075 1075
 			    }
@@ -1080,10 +1080,10 @@  discard block
 block discarded – undo
1080 1080
                         } elseif ($format == 'flightgearsp') {
1081 1081
                     	    //echo $buffer."\n";
1082 1082
                     	    if (strlen($buffer) > 5) {
1083
-				$line = explode(',',$buffer);
1083
+				$line = explode(',', $buffer);
1084 1084
 				$data = array();
1085 1085
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1086
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1086
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1087 1087
 				$data['ident'] = $line[6];
1088 1088
 				$data['aircraft_name'] = $line[7];
1089 1089
 				$data['longitude'] = $line[1];
@@ -1094,21 +1094,21 @@  discard block
 block discarded – undo
1094 1094
 				$data['datetime'] = date('Y-m-d H:i:s');
1095 1095
 				$data['format_source'] = 'flightgearsp';
1096 1096
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1097
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1097
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1098 1098
 			    }
1099 1099
                         } elseif ($format == 'acars') {
1100 1100
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1101 1101
 			    $ACARS->add(trim($buffer));
1102
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1102
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1103 1103
 			    $ACARS->deleteLiveAcarsData();
1104 1104
 			} elseif ($format == 'flightgearmp') {
1105
-			    if (substr($buffer,0,1) != '#') {
1105
+			    if (substr($buffer, 0, 1) != '#') {
1106 1106
 				$data = array();
1107 1107
 				//echo $buffer."\n";
1108
-				$line = explode(' ',$buffer);
1108
+				$line = explode(' ', $buffer);
1109 1109
 				if (count($line) == 11) {
1110
-				    $userserver = explode('@',$line[0]);
1111
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1110
+				    $userserver = explode('@', $line[0]);
1111
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1112 1112
 				    $data['ident'] = $userserver[0];
1113 1113
 				    $data['registration'] = $userserver[0];
1114 1114
 				    $data['latitude'] = $line[4];
@@ -1116,8 +1116,8 @@  discard block
 block discarded – undo
1116 1116
 				    $data['altitude'] = $line[6];
1117 1117
 				    $data['datetime'] = date('Y-m-d H:i:s');
1118 1118
 				    $aircraft_type = $line[10];
1119
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1120
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1119
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1120
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1121 1121
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1122 1122
 				}
1123 1123
 			    }
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1126 1126
 			    die;
1127 1127
 			} elseif ($format == 'vrstcp') {
1128
-			    foreach($buffer as $all_data) {
1129
-				$line = json_decode('{'.$all_data.'}',true);
1128
+			    foreach ($buffer as $all_data) {
1129
+				$line = json_decode('{'.$all_data.'}', true);
1130 1130
 				$data = array();
1131 1131
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1132 1132
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1151,16 +1151,16 @@  discard block
 block discarded – undo
1151 1151
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1152 1152
 				unset($data);
1153 1153
 			    }
1154
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1154
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1155 1155
 			    $line = explode("\t", $buffer);
1156
-			    for($k = 0; $k < count($line); $k=$k+2) {
1156
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1157 1157
 				$key = $line[$k];
1158
-			        $lined[$key] = $line[$k+1];
1158
+			        $lined[$key] = $line[$k + 1];
1159 1159
 			    }
1160 1160
     			    if (count($lined) > 3) {
1161 1161
     				$data['hex'] = $lined['hexid'];
1162 1162
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1163
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1163
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1164 1164
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1165 1165
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1166 1166
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1178,22 +1178,22 @@  discard block
 block discarded – undo
1178 1178
     			    } else $error = true;
1179 1179
 			} elseif ($format == 'aprs' && $use_aprs) {
1180 1180
 			    if ($aprs_connect == 0) {
1181
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1181
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1182 1182
 				$aprs_connect = 1;
1183 1183
 			    }
1184 1184
 			    
1185
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1185
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1186 1186
 				$aprs_last_tx = time();
1187 1187
 				$data_aprs = "# Keep alive";
1188
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1188
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1189 1189
 			    }
1190 1190
 			    
1191 1191
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1192 1192
 			    //echo 'APRS data : '.$buffer."\n";
1193
-			    $buffer = str_replace('APRS <- ','',$buffer);
1194
-			    $buffer = str_replace('APRS -> ','',$buffer);
1193
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1194
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1195 1195
 			    //echo $buffer."\n";
1196
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1196
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1197 1197
 				$line = $APRS->parse($buffer);
1198 1198
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1199 1199
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
 				    //print_r($line);
1203 1203
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1204 1204
 				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1205
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1205
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1206 1206
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1207 1207
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1208 1208
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
 				    $currentdate = date('Y-m-d H:i:s');
1229 1229
 				    $aprsdate = strtotime($data['datetime']);
1230 1230
 				    // Accept data if time <= system time + 20s
1231
-				    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'])))) {
1231
+				    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'])))) {
1232 1232
 					$send = $SI->add($data);
1233 1233
 				    } elseif ($data['source_type'] == 'ais') {
1234 1234
 					echo 'add...'."\n";
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
 				connect_all($sourceee);
1329 1329
 				$sourceee = array();
1330 1330
 				//connect_all($globalSources);
1331
-				$tt[$format]=0;
1331
+				$tt[$format] = 0;
1332 1332
 				break;
1333 1333
 			    }
1334 1334
 			}
@@ -1337,14 +1337,14 @@  discard block
 block discarded – undo
1337 1337
 	    } else {
1338 1338
 		$error = socket_strerror(socket_last_error());
1339 1339
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1340
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1340
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1341 1341
 			if (isset($globalDebug)) echo "Restarting...\n";
1342 1342
 			// Restart the script if possible
1343 1343
 			if (is_array($sockets)) {
1344 1344
 			    if ($globalDebug) echo "Shutdown all sockets...";
1345 1345
 			    
1346 1346
 			    foreach ($sockets as $sock) {
1347
-				@socket_shutdown($sock,2);
1347
+				@socket_shutdown($sock, 2);
1348 1348
 				@socket_close($sock);
1349 1349
 			    }
1350 1350
 			    
Please login to merge, or discard this patch.
Braces   +805 added lines, -276 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -54,31 +58,58 @@  discard block
 block discarded – undo
54 58
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 59
 if (isset($options['s'])) {
56 60
     $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
59
-} elseif (isset($options['source'])) {
61
+    if (isset($options['format'])) {
62
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+    } else {
64
+    	$globalSources[] = array('host' => $options['s']);
65
+    }
66
+    } elseif (isset($options['source'])) {
60 67
     $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
68
+    if (isset($options['format'])) {
69
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
70
+    } else {
71
+    	$globalSources[] = array('host' => $options['source']);
72
+    }
73
+    }
74
+if (isset($options['aprsserverhost'])) {
75
+	$globalServerAPRShost = $options['aprsserverhost'];
76
+}
77
+if (isset($options['aprsserverport'])) {
78
+	$globalServerAPRSport = $options['aprsserverport'];
79
+}
80
+if (isset($options['aprsserverssid'])) {
81
+	$globalServerAPRSssid = $options['aprsserverssid'];
82
+}
83
+if (isset($options['aprsserverpass'])) {
84
+	$globalServerAPRSpass = $options['aprsserverpass'];
85
+}
86
+if (isset($options['nodaemon'])) {
87
+	$globalDaemon = FALSE;
88
+}
89
+if (isset($options['server'])) {
90
+	$globalServer = TRUE;
91
+}
92
+if (isset($options['idsource'])) {
93
+	$id_source = $options['idsource'];
94
+} else {
95
+	$id_source = 1;
63 96
 }
64
-if (isset($options['aprsserverhost'])) $globalServerAPRShost = $options['aprsserverhost'];
65
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
66
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
67
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
68
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
69
-if (isset($options['server'])) $globalServer = TRUE;
70
-if (isset($options['idsource'])) $id_source = $options['idsource'];
71
-else $id_source = 1;
72 97
 if (isset($globalServer) && $globalServer) {
73
-    if ($globalDebug) echo "Using Server Mode\n";
98
+    if ($globalDebug) {
99
+    	echo "Using Server Mode\n";
100
+    }
74 101
     $SI=new SpotterServer();
75 102
 /*
76 103
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
77 104
     $SI = new adsb2aprs();
78 105
     $SI->connect();
79 106
 */
80
-} else $SI=new SpotterImport($Connection->db);
81
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
107
+} else {
108
+	$SI=new SpotterImport($Connection->db);
109
+}
110
+if (isset($globalTracker) && $globalTracker) {
111
+	$TI = new TrackerImport($Connection->db);
112
+}
82 113
 if (isset($globalMarine) && $globalMarine) {
83 114
     $AIS = new AIS();
84 115
     $MI = new MarineImport($Connection->db);
@@ -100,7 +131,9 @@  discard block
 block discarded – undo
100 131
 }
101 132
 
102 133
 // let's try and connect
103
-if ($globalDebug) echo "Connecting...\n";
134
+if ($globalDebug) {
135
+	echo "Connecting...\n";
136
+}
104 137
 $use_aprs = false;
105 138
 $aprs_full = false;
106 139
 $reset = 0;
@@ -109,7 +142,9 @@  discard block
 block discarded – undo
109 142
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
110 143
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
111 144
     $reset++;
112
-    if ($globalDebug) echo 'Connect to all...'."\n";
145
+    if ($globalDebug) {
146
+    	echo 'Connect to all...'."\n";
147
+    }
113 148
     foreach ($hosts as $id => $value) {
114 149
 	$host = $value['host'];
115 150
 	$globalSources[$id]['last_exec'] = 0;
@@ -119,27 +154,37 @@  discard block
 block discarded – undo
119 154
         	//$formats[$id] = 'deltadbtxt';
120 155
         	$globalSources[$id]['format'] = 'deltadbtxt';
121 156
         	//$last_exec['deltadbtxt'] = 0;
122
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
157
+        	if ($globalDebug) {
158
+        		echo "Connect to deltadb source (".$host.")...\n";
159
+        	}
123 160
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
124 161
         	//$formats[$id] = 'vatsimtxt';
125 162
         	$globalSources[$id]['format'] = 'vatsimtxt';
126 163
         	//$last_exec['vatsimtxt'] = 0;
127
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
164
+        	if ($globalDebug) {
165
+        		echo "Connect to vatsim source (".$host.")...\n";
166
+        	}
128 167
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
129 168
         	//$formats[$id] = 'aircraftlistjson';
130 169
         	$globalSources[$id]['format'] = 'aircraftlistjson';
131 170
         	//$last_exec['aircraftlistjson'] = 0;
132
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
171
+        	if ($globalDebug) {
172
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
173
+        	}
133 174
     	    } else if (preg_match('/opensky/i',$host)) {
134 175
         	//$formats[$id] = 'aircraftlistjson';
135 176
         	$globalSources[$id]['format'] = 'opensky';
136 177
         	//$last_exec['aircraftlistjson'] = 0;
137
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
178
+        	if ($globalDebug) {
179
+        		echo "Connect to opensky source (".$host.")...\n";
180
+        	}
138 181
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
139 182
         	//$formats[$id] = 'radarvirtueljson';
140 183
         	$globalSources[$id]['format'] = 'radarvirtueljson';
141 184
         	//$last_exec['radarvirtueljson'] = 0;
142
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
185
+        	if ($globalDebug) {
186
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
187
+        	}
143 188
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
144 189
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
145 190
         	    exit(0);
@@ -148,7 +193,9 @@  discard block
 block discarded – undo
148 193
         	//$formats[$id] = 'planeupdatefaa';
149 194
         	$globalSources[$id]['format'] = 'planeupdatefaa';
150 195
         	//$last_exec['planeupdatefaa'] = 0;
151
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
196
+        	if ($globalDebug) {
197
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
+        	}
152 199
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
153 200
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
154 201
         	    exit(0);
@@ -157,26 +204,36 @@  discard block
 block discarded – undo
157 204
         	//$formats[$id] = 'phpvmacars';
158 205
         	$globalSources[$id]['format'] = 'phpvmacars';
159 206
         	//$last_exec['phpvmacars'] = 0;
160
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
+        	if ($globalDebug) {
208
+        		echo "Connect to phpvmacars source (".$host.")...\n";
209
+        	}
161 210
             } else if (preg_match('/VAM-json.php$/i',$host)) {
162 211
         	//$formats[$id] = 'phpvmacars';
163 212
         	$globalSources[$id]['format'] = 'vam';
164
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
213
+        	if ($globalDebug) {
214
+        		echo "Connect to Vam source (".$host.")...\n";
215
+        	}
165 216
             } else if (preg_match('/whazzup/i',$host)) {
166 217
         	//$formats[$id] = 'whazzup';
167 218
         	$globalSources[$id]['format'] = 'whazzup';
168 219
         	//$last_exec['whazzup'] = 0;
169
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
220
+        	if ($globalDebug) {
221
+        		echo "Connect to whazzup source (".$host.")...\n";
222
+        	}
170 223
             } else if (preg_match('/recentpireps/i',$host)) {
171 224
         	//$formats[$id] = 'pirepsjson';
172 225
         	$globalSources[$id]['format'] = 'pirepsjson';
173 226
         	//$last_exec['pirepsjson'] = 0;
174
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
227
+        	if ($globalDebug) {
228
+        		echo "Connect to pirepsjson source (".$host.")...\n";
229
+        	}
175 230
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
176 231
         	//$formats[$id] = 'fr24json';
177 232
         	$globalSources[$id]['format'] = 'fr24json';
178 233
         	//$last_exec['fr24json'] = 0;
179
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
234
+        	if ($globalDebug) {
235
+        		echo "Connect to fr24 source (".$host.")...\n";
236
+        	}
180 237
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
181 238
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
182 239
         	    exit(0);
@@ -185,7 +242,9 @@  discard block
 block discarded – undo
185 242
         	//$formats[$id] = 'fr24json';
186 243
         	$globalSources[$id]['format'] = 'myshiptracking';
187 244
         	//$last_exec['fr24json'] = 0;
188
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
245
+        	if ($globalDebug) {
246
+        		echo "Connect to myshiptracking source (".$host.")...\n";
247
+        	}
189 248
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
190 249
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
191 250
         	    exit(0);
@@ -194,17 +253,24 @@  discard block
 block discarded – undo
194 253
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
195 254
         	//$formats[$id] = 'tsv';
196 255
         	$globalSources[$id]['format'] = 'tsv';
197
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
256
+        	if ($globalDebug) {
257
+        		echo "Connect to tsv source (".$host.")...\n";
258
+        	}
198 259
             }
199 260
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
200 261
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
201 262
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
202 263
     		    if ($idf !== false) {
203 264
     			$httpfeeds[$id] = $idf;
204
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
265
+        		if ($globalDebug) {
266
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
267
+        		}
268
+    		    } elseif ($globalDebug) {
269
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
205 270
     		    }
206
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
207
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
271
+    		} elseif ($globalDebug) {
272
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
273
+    		}
208 274
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
209 275
 	    $hostport = explode(':',$host);
210 276
 	    if (isset($hostport[1])) {
@@ -244,17 +310,25 @@  discard block
 block discarded – undo
244 310
         		//$formats[$id] = 'beast';
245 311
         		$globalSources[$id]['format'] = 'beast';
246 312
 		    //} else $formats[$id] = 'sbs';
247
-		    } else $globalSources[$id]['format'] = 'sbs';
313
+		    } else {
314
+		    	$globalSources[$id]['format'] = 'sbs';
315
+		    }
248 316
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
249 317
 		}
250
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
318
+		if ($globalDebug) {
319
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
320
+		}
251 321
             } else {
252
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
322
+		if ($globalDebug) {
323
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
324
+		}
253 325
     	    }
254 326
         }
255 327
     }
256 328
 }
257
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
329
+if (!isset($globalMinFetch)) {
330
+	$globalMinFetch = 15;
331
+}
258 332
 
259 333
 // Initialize all
260 334
 $status = array();
@@ -263,13 +337,19 @@  discard block
 block discarded – undo
263 337
 $formats = array();
264 338
 $last_exec = array();
265 339
 $time = time();
266
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
267
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
268
-else $timeout = 20;
340
+if (isset($globalSourcesTimeout)) {
341
+	$timeout = $globalSourcesTimeOut;
342
+} else if (isset($globalSBS1TimeOut)) {
343
+	$timeout = $globalSBS1TimeOut;
344
+} else {
345
+	$timeout = 20;
346
+}
269 347
 $errno = '';
270 348
 $errstr='';
271 349
 
272
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
350
+if (!isset($globalDaemon)) {
351
+	$globalDaemon = TRUE;
352
+}
273 353
 /* Initiate connections to all the hosts simultaneously */
274 354
 //connect_all($hosts);
275 355
 //connect_all($globalSources);
@@ -295,7 +375,9 @@  discard block
 block discarded – undo
295 375
     if (isset($source['format']) && $source['format'] == 'aprs') {
296 376
 	$aprs_connect = 0;
297 377
 	$use_aprs = true;
298
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
378
+	if (isset($source['port']) && $source['port'] == '10152') {
379
+		$aprs_full = true;
380
+	}
299 381
 	break;
300 382
     }
301 383
 }
@@ -306,25 +388,48 @@  discard block
 block discarded – undo
306 388
 	$aprs_connect = 0;
307 389
 	$aprs_keep = 120;
308 390
 	$aprs_last_tx = time();
309
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
310
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
311
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
312
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
313
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
314
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
315
-	if ($aprs_full) $aprs_filter = '';
316
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
317
-	else $aprs_pass = '-1';
391
+	if (isset($globalAPRSversion)) {
392
+		$aprs_version = $globalAPRSversion;
393
+	} else {
394
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
395
+	}
396
+	if (isset($globalAPRSssid)) {
397
+		$aprs_ssid = $globalAPRSssid;
398
+	} else {
399
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
400
+	}
401
+	if (isset($globalAPRSfilter)) {
402
+		$aprs_filter = $globalAPRSfilter;
403
+	} else {
404
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
405
+	}
406
+	if ($aprs_full) {
407
+		$aprs_filter = '';
408
+	}
409
+	if (isset($globalAPRSpass)) {
410
+		$aprs_pass = $globalAPRSpass;
411
+	} else {
412
+		$aprs_pass = '-1';
413
+	}
318 414
 
319
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
320
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
321
-}
415
+	if ($aprs_filter != '') {
416
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
417
+	} else {
418
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
419
+	}
420
+	}
322 421
 
323 422
 // connected - lets do some work
324
-if ($globalDebug) echo "Connected!\n";
423
+if ($globalDebug) {
424
+	echo "Connected!\n";
425
+}
325 426
 sleep(1);
326
-if ($globalDebug) echo "SCAN MODE \n\n";
327
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
427
+if ($globalDebug) {
428
+	echo "SCAN MODE \n\n";
429
+}
430
+if (!isset($globalCronEnd)) {
431
+	$globalCronEnd = 60;
432
+}
328 433
 $endtime = time()+$globalCronEnd;
329 434
 $i = 1;
330 435
 $tt = array();
@@ -338,10 +443,14 @@  discard block
 block discarded – undo
338 443
 
339 444
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
340 445
 while ($i > 0) {
341
-    if (!$globalDaemon) $i = $endtime-time();
446
+    if (!$globalDaemon) {
447
+    	$i = $endtime-time();
448
+    }
342 449
     // Delete old ATC
343 450
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
344
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
451
+	if ($globalDebug) {
452
+		echo 'Delete old ATC...'."\n";
453
+	}
345 454
         $ATC->deleteOldATC();
346 455
     }
347 456
     
@@ -349,10 +458,14 @@  discard block
 block discarded – undo
349 458
     if (count($last_exec) == count($globalSources)) {
350 459
 	$max = $globalMinFetch;
351 460
 	foreach ($last_exec as $last) {
352
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
461
+	    if ((time() - $last['last']) < $max) {
462
+	    	$max = time() - $last['last'];
463
+	    }
353 464
 	}
354 465
 	if ($max != $globalMinFetch) {
355
-	    if ($globalDebug) echo 'Sleeping...'."\n";
466
+	    if ($globalDebug) {
467
+	    	echo 'Sleeping...'."\n";
468
+	    }
356 469
 	    sleep($globalMinFetch-$max+2);
357 470
 	}
358 471
     }
@@ -361,11 +474,15 @@  discard block
 block discarded – undo
361 474
     //foreach ($formats as $id => $value) {
362 475
     foreach ($globalSources as $id => $value) {
363 476
 	date_default_timezone_set('UTC');
364
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
477
+	if (!isset($last_exec[$id]['last'])) {
478
+		$last_exec[$id]['last'] = 0;
479
+	}
365 480
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
366 481
 	    //$buffer = $Common->getData($hosts[$id]);
367 482
 	    $buffer = $Common->getData($value['host']);
368
-	    if ($buffer != '') $reset = 0;
483
+	    if ($buffer != '') {
484
+	    	$reset = 0;
485
+	    }
369 486
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
370 487
 	    $buffer = explode('\n',$buffer);
371 488
 	    foreach ($buffer as $line) {
@@ -374,19 +491,38 @@  discard block
 block discarded – undo
374 491
 	            $data = array();
375 492
 	            $data['hex'] = $line[1]; // hex
376 493
 	            $data['ident'] = $line[2]; // ident
377
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
378
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
379
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
380
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
381
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
494
+	            if (isset($line[3])) {
495
+	            	$data['altitude'] = $line[3];
496
+	            }
497
+	            // altitude
498
+	            if (isset($line[4])) {
499
+	            	$data['speed'] = $line[4];
500
+	            }
501
+	            // speed
502
+	            if (isset($line[5])) {
503
+	            	$data['heading'] = $line[5];
504
+	            }
505
+	            // heading
506
+	            if (isset($line[6])) {
507
+	            	$data['latitude'] = $line[6];
508
+	            }
509
+	            // lat
510
+	            if (isset($line[7])) {
511
+	            	$data['longitude'] = $line[7];
512
+	            }
513
+	            // long
382 514
 	            $data['verticalrate'] = ''; // vertical rate
383 515
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
384 516
 	            $data['emergency'] = ''; // emergency
385 517
 		    $data['datetime'] = date('Y-m-d H:i:s');
386 518
 		    $data['format_source'] = 'deltadbtxt';
387 519
     		    $data['id_source'] = $id_source;
388
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
389
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
520
+		    if (isset($value['name']) && $value['name'] != '') {
521
+		    	$data['source_name'] = $value['name'];
522
+		    }
523
+		    if (isset($value['sourcestats'])) {
524
+		    	$data['sourcestats'] = $value['sourcestats'];
525
+		    }
390 526
     		    $SI->add($data);
391 527
 		    unset($data);
392 528
     		}
@@ -396,7 +532,9 @@  discard block
 block discarded – undo
396 532
 	    date_default_timezone_set('CET');
397 533
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
398 534
 	    date_default_timezone_set('UTC');
399
-	    if ($buffer != '') $reset = 0;
535
+	    if ($buffer != '') {
536
+	    	$reset = 0;
537
+	    }
400 538
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
401 539
 	    $buffer = explode('\n',$buffer);
402 540
 	    foreach ($buffer as $line) {
@@ -405,16 +543,36 @@  discard block
 block discarded – undo
405 543
 		    $add = false;
406 544
 		    $ais_data = $AIS->parse_line(trim($line));
407 545
 		    $data = array();
408
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
409
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
410
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
411
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
412
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
413
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
414
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
415
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
416
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
417
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
546
+		    if (isset($ais_data['ident'])) {
547
+		    	$data['ident'] = $ais_data['ident'];
548
+		    }
549
+		    if (isset($ais_data['mmsi'])) {
550
+		    	$data['mmsi'] = $ais_data['mmsi'];
551
+		    }
552
+		    if (isset($ais_data['speed'])) {
553
+		    	$data['speed'] = $ais_data['speed'];
554
+		    }
555
+		    if (isset($ais_data['heading'])) {
556
+		    	$data['heading'] = $ais_data['heading'];
557
+		    }
558
+		    if (isset($ais_data['latitude'])) {
559
+		    	$data['latitude'] = $ais_data['latitude'];
560
+		    }
561
+		    if (isset($ais_data['longitude'])) {
562
+		    	$data['longitude'] = $ais_data['longitude'];
563
+		    }
564
+		    if (isset($ais_data['status'])) {
565
+		    	$data['status'] = $ais_data['status'];
566
+		    }
567
+		    if (isset($ais_data['type'])) {
568
+		    	$data['type'] = $ais_data['type'];
569
+		    }
570
+		    if (isset($ais_data['imo'])) {
571
+		    	$data['imo'] = $ais_data['imo'];
572
+		    }
573
+		    if (isset($ais_data['callsign'])) {
574
+		    	$data['callsign'] = $ais_data['callsign'];
575
+		    }
418 576
 		    if (isset($ais_data['timestamp'])) {
419 577
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
420 578
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -429,7 +587,9 @@  discard block
 block discarded – undo
429 587
     		    $data['id_source'] = $id_source;
430 588
 		    print_r($data);
431 589
 		    echo 'Add...'."\n";
432
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
590
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
591
+		    	$MI->add($data);
592
+		    }
433 593
 		    unset($data);
434 594
 		}
435 595
     	    }
@@ -449,18 +609,42 @@  discard block
 block discarded – undo
449 609
 			if ($line != '') {
450 610
 			    $ais_data = $AIS->parse_line(trim($line));
451 611
 			    $data = array();
452
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
453
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
454
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
455
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
456
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
457
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
458
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
459
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
460
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
461
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
462
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
463
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
612
+			    if (isset($ais_data['ident'])) {
613
+			    	$data['ident'] = $ais_data['ident'];
614
+			    }
615
+			    if (isset($ais_data['mmsi'])) {
616
+			    	$data['mmsi'] = $ais_data['mmsi'];
617
+			    }
618
+			    if (isset($ais_data['speed'])) {
619
+			    	$data['speed'] = $ais_data['speed'];
620
+			    }
621
+			    if (isset($ais_data['heading'])) {
622
+			    	$data['heading'] = $ais_data['heading'];
623
+			    }
624
+			    if (isset($ais_data['latitude'])) {
625
+			    	$data['latitude'] = $ais_data['latitude'];
626
+			    }
627
+			    if (isset($ais_data['longitude'])) {
628
+			    	$data['longitude'] = $ais_data['longitude'];
629
+			    }
630
+			    if (isset($ais_data['status'])) {
631
+			    	$data['status'] = $ais_data['status'];
632
+			    }
633
+			    if (isset($ais_data['type'])) {
634
+			    	$data['type'] = $ais_data['type'];
635
+			    }
636
+			    if (isset($ais_data['imo'])) {
637
+			    	$data['imo'] = $ais_data['imo'];
638
+			    }
639
+			    if (isset($ais_data['callsign'])) {
640
+			    	$data['callsign'] = $ais_data['callsign'];
641
+			    }
642
+			    if (isset($ais_data['destination'])) {
643
+			    	$data['arrival_code'] = $ais_data['destination'];
644
+			    }
645
+			    if (isset($ais_data['eta_ts'])) {
646
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
647
+			    }
464 648
 			    if (isset($ais_data['timestamp'])) {
465 649
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
466 650
 			    } else {
@@ -468,7 +652,9 @@  discard block
 block discarded – undo
468 652
 			    }
469 653
 			    $data['format_source'] = 'aisnmeahttp';
470 654
 			    $data['id_source'] = $id_source;
471
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
655
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
656
+			    	$MI->add($data);
657
+			    }
472 658
 			    unset($data);
473 659
 			}
474 660
 		    }
@@ -517,7 +703,9 @@  discard block
 block discarded – undo
517 703
 			    $data['callsign'] = $line['callsign'];
518 704
 			    $data['mmsi'] = $line['mmsi'];
519 705
 			    $data['speed'] = $line['sog'];
520
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
706
+			    if ($line['heading'] != '511') {
707
+			    	$data['heading'] = $line['heading'];
708
+			    }
521 709
 			    $data['latitude'] = $line['latitude'];
522 710
 			    $data['longitude'] = $line['longitude'];
523 711
 			    $data['type_id'] = $line['shiptype'];
@@ -537,7 +725,9 @@  discard block
 block discarded – undo
537 725
 	    echo 'download...';
538 726
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
539 727
 	    echo 'done !'."\n";
540
-	    if ($buffer != '') $reset = 0;
728
+	    if ($buffer != '') {
729
+	    	$reset = 0;
730
+	    }
541 731
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
542 732
 	    $buffer = explode('\n',$buffer);
543 733
 	    foreach ($buffer as $line) {
@@ -581,16 +771,28 @@  discard block
 block discarded – undo
581 771
     		    $line = explode(':', $line);
582 772
     		    if (count($line) > 30 && $line[0] != 'callsign') {
583 773
 			$data = array();
584
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
585
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
774
+			if (isset($line[37]) && $line[37] != '') {
775
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
776
+			} else {
777
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
778
+			}
586 779
 			$data['pilot_id'] = $line[1];
587 780
 			$data['pilot_name'] = $line[2];
588 781
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
589 782
 			$data['ident'] = $line[0]; // ident
590
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
783
+			if ($line[7] != '' && $line[7] != 0) {
784
+				$data['altitude'] = $line[7];
785
+			}
786
+			// altitude
591 787
 			$data['speed'] = $line[8]; // speed
592
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
593
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
788
+			if (isset($line[45])) {
789
+				$data['heading'] = $line[45];
790
+			}
791
+			// heading
792
+			elseif (isset($line[38])) {
793
+				$data['heading'] = $line[38];
794
+			}
795
+			// heading
594 796
 			$data['latitude'] = $line[5]; // lat
595 797
 	        	$data['longitude'] = $line[6]; // long
596 798
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -606,7 +808,9 @@  discard block
 block discarded – undo
606 808
 			$data['frequency'] = $line[4];
607 809
 			$data['type'] = $line[18];
608 810
 			$data['range'] = $line[19];
609
-			if (isset($line[35])) $data['info'] = $line[35];
811
+			if (isset($line[35])) {
812
+				$data['info'] = $line[35];
813
+			}
610 814
     			$data['id_source'] = $id_source;
611 815
 	    		//$data['arrival_airport_time'] = ;
612 816
 	    		if ($line[9] != '') {
@@ -620,24 +824,41 @@  discard block
 block discarded – undo
620 824
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
621 825
 	    		*/
622 826
 	    		$data['format_source'] = $value['format'];
623
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
624
-    			if ($line[3] == 'PILOT') $SI->add($data);
625
-			elseif ($line[3] == 'ATC') {
827
+			if (isset($value['name']) && $value['name'] != '') {
828
+				$data['source_name'] = $value['name'];
829
+			}
830
+    			if ($line[3] == 'PILOT') {
831
+    				$SI->add($data);
832
+    			} elseif ($line[3] == 'ATC') {
626 833
 				//print_r($data);
627 834
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
628 835
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
629 836
 				$typec = substr($data['ident'],-3);
630
-				if ($typec == 'APP') $data['type'] = 'Approach';
631
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
632
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
633
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
634
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
635
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
636
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
637
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
638
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
639
-				if (!isset($data['source_name'])) $data['source_name'] = '';
640
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
837
+				if ($typec == 'APP') {
838
+					$data['type'] = 'Approach';
839
+				} elseif ($typec == 'TWR') {
840
+					$data['type'] = 'Tower';
841
+				} elseif ($typec == 'OBS') {
842
+					$data['type'] = 'Observer';
843
+				} elseif ($typec == 'GND') {
844
+					$data['type'] = 'Ground';
845
+				} elseif ($typec == 'DEL') {
846
+					$data['type'] = 'Delivery';
847
+				} elseif ($typec == 'DEP') {
848
+					$data['type'] = 'Departure';
849
+				} elseif ($typec == 'FSS') {
850
+					$data['type'] = 'Flight Service Station';
851
+				} elseif ($typec == 'CTR') {
852
+					$data['type'] = 'Control Radar or Centre';
853
+				} elseif ($data['type'] == '') {
854
+					$data['type'] = 'Observer';
855
+				}
856
+				if (!isset($data['source_name'])) {
857
+					$data['source_name'] = '';
858
+				}
859
+				if (isset($ATC)) {
860
+					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']);
861
+				}
641 862
 			}
642 863
     			unset($data);
643 864
     		    }
@@ -656,26 +877,55 @@  discard block
 block discarded – undo
656 877
 		foreach ($all_data['acList'] as $line) {
657 878
 		    $data = array();
658 879
 		    $data['hex'] = $line['Icao']; // hex
659
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
660
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
661
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
662
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
663
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
664
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
880
+		    if (isset($line['Call'])) {
881
+		    	$data['ident'] = $line['Call'];
882
+		    }
883
+		    // ident
884
+		    if (isset($line['Alt'])) {
885
+		    	$data['altitude'] = $line['Alt'];
886
+		    }
887
+		    // altitude
888
+		    if (isset($line['Spd'])) {
889
+		    	$data['speed'] = $line['Spd'];
890
+		    }
891
+		    // speed
892
+		    if (isset($line['Trak'])) {
893
+		    	$data['heading'] = $line['Trak'];
894
+		    }
895
+		    // heading
896
+		    if (isset($line['Lat'])) {
897
+		    	$data['latitude'] = $line['Lat'];
898
+		    }
899
+		    // lat
900
+		    if (isset($line['Long'])) {
901
+		    	$data['longitude'] = $line['Long'];
902
+		    }
903
+		    // long
665 904
 		    //$data['verticalrate'] = $line['']; // verticale rate
666
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
905
+		    if (isset($line['Sqk'])) {
906
+		    	$data['squawk'] = $line['Sqk'];
907
+		    }
908
+		    // squawk
667 909
 		    $data['emergency'] = ''; // emergency
668
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
910
+		    if (isset($line['Reg'])) {
911
+		    	$data['registration'] = $line['Reg'];
912
+		    }
669 913
 		    /*
670 914
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
671 915
 		    else $data['datetime'] = date('Y-m-d H:i:s');
672 916
 		    */
673 917
 		    $data['datetime'] = date('Y-m-d H:i:s');
674
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
918
+		    if (isset($line['Type'])) {
919
+		    	$data['aircraft_icao'] = $line['Type'];
920
+		    }
675 921
 	    	    $data['format_source'] = 'aircraftlistjson';
676 922
 		    $data['id_source'] = $id_source;
677
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
678
-		    if (isset($data['latitude'])) $SI->add($data);
923
+		    if (isset($value['name']) && $value['name'] != '') {
924
+		    	$data['source_name'] = $value['name'];
925
+		    }
926
+		    if (isset($data['latitude'])) {
927
+		    	$SI->add($data);
928
+		    }
679 929
 		    unset($data);
680 930
 		}
681 931
 	    } elseif (is_array($all_data)) {
@@ -695,7 +945,9 @@  discard block
 block discarded – undo
695 945
 		    $data['datetime'] = date('Y-m-d H:i:s');
696 946
 	    	    $data['format_source'] = 'aircraftlistjson';
697 947
     		    $data['id_source'] = $id_source;
698
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
948
+		    if (isset($value['name']) && $value['name'] != '') {
949
+		    	$data['source_name'] = $value['name'];
950
+		    }
699 951
 		    $SI->add($data);
700 952
 		    unset($data);
701 953
 		}
@@ -731,7 +983,9 @@  discard block
 block discarded – undo
731 983
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
732 984
 	    	    $data['format_source'] = 'planeupdatefaa';
733 985
     		    $data['id_source'] = $id_source;
734
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
986
+		    if (isset($value['name']) && $value['name'] != '') {
987
+		    	$data['source_name'] = $value['name'];
988
+		    }
735 989
 		    $SI->add($data);
736 990
 		    unset($data);
737 991
 		}
@@ -771,7 +1025,9 @@  discard block
 block discarded – undo
771 1025
 	    //$buffer = $Common->getData($hosts[$id]);
772 1026
 	    $buffer = $Common->getData($value['host']);
773 1027
 	    $all_data = json_decode($buffer,true);
774
-	    if (!empty($all_data)) $reset = 0;
1028
+	    if (!empty($all_data)) {
1029
+	    	$reset = 0;
1030
+	    }
775 1031
 	    foreach ($all_data as $key => $line) {
776 1032
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
777 1033
 		    $data = array();
@@ -792,7 +1048,9 @@  discard block
 block discarded – undo
792 1048
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
793 1049
 	    	    $data['format_source'] = 'fr24json';
794 1050
     		    $data['id_source'] = $id_source;
795
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1051
+		    if (isset($value['name']) && $value['name'] != '') {
1052
+		    	$data['source_name'] = $value['name'];
1053
+		    }
796 1054
 		    $SI->add($data);
797 1055
 		    unset($data);
798 1056
 		}
@@ -816,23 +1074,39 @@  discard block
 block discarded – undo
816 1074
 		    if (isset($line['inf'])) {
817 1075
 			$data = array();
818 1076
 			$data['hex'] = $line['inf']['ia'];
819
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1077
+			if (isset($line['inf']['cs'])) {
1078
+				$data['ident'] = $line['inf']['cs'];
1079
+			}
1080
+			//$line[13]
820 1081
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
821
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
822
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1082
+	    		if (isset($line['inf']['gs'])) {
1083
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1084
+	    		}
1085
+	    		// speed
1086
+	    		if (isset($line['inf']['tr'])) {
1087
+	    			$data['heading'] = $line['inf']['tr'];
1088
+	    		}
1089
+	    		// heading
823 1090
 	    		$data['latitude'] = $line['pt'][0]; // lat
824 1091
 	    		$data['longitude'] = $line['pt'][1]; // long
825 1092
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
826
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1093
+	    		if (isset($line['inf']['sq'])) {
1094
+	    			$data['squawk'] = $line['inf']['sq'];
1095
+	    		}
1096
+	    		// squawk
827 1097
 	    		//$data['aircraft_icao'] = $line[8];
828
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1098
+	    		if (isset($line['inf']['rc'])) {
1099
+	    			$data['registration'] = $line['inf']['rc'];
1100
+	    		}
829 1101
 			//$data['departure_airport_iata'] = $line[11];
830 1102
 			//$data['arrival_airport_iata'] = $line[12];
831 1103
 	    		//$data['emergency'] = ''; // emergency
832 1104
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
833 1105
 	    		$data['format_source'] = 'radarvirtueljson';
834 1106
     			$data['id_source'] = $id_source;
835
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1107
+			if (isset($value['name']) && $value['name'] != '') {
1108
+				$data['source_name'] = $value['name'];
1109
+			}
836 1110
 			$SI->add($data);
837 1111
 			unset($data);
838 1112
 		    }
@@ -853,29 +1127,62 @@  discard block
 block discarded – undo
853 1127
 		    $data['id'] = $line['id'];
854 1128
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
855 1129
 		    $data['ident'] = $line['callsign']; // ident
856
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
857
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
858
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
859
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
860
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
861
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1130
+		    if (isset($line['pilotid'])) {
1131
+		    	$data['pilot_id'] = $line['pilotid'];
1132
+		    }
1133
+		    // pilot id
1134
+		    if (isset($line['name'])) {
1135
+		    	$data['pilot_name'] = $line['name'];
1136
+		    }
1137
+		    // pilot name
1138
+		    if (isset($line['alt'])) {
1139
+		    	$data['altitude'] = $line['alt'];
1140
+		    }
1141
+		    // altitude
1142
+		    if (isset($line['gs'])) {
1143
+		    	$data['speed'] = $line['gs'];
1144
+		    }
1145
+		    // speed
1146
+		    if (isset($line['heading'])) {
1147
+		    	$data['heading'] = $line['heading'];
1148
+		    }
1149
+		    // heading
1150
+		    if (isset($line['route'])) {
1151
+		    	$data['waypoints'] = $line['route'];
1152
+		    }
1153
+		    // route
862 1154
 		    $data['latitude'] = $line['lat']; // lat
863 1155
 		    $data['longitude'] = $line['lon']; // long
864 1156
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
865 1157
 		    //$data['squawk'] = $line['squawk']; // squawk
866 1158
 		    //$data['emergency'] = ''; // emergency
867
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
868
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
869
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1159
+		    if (isset($line['depicao'])) {
1160
+		    	$data['departure_airport_icao'] = $line['depicao'];
1161
+		    }
1162
+		    if (isset($line['deptime'])) {
1163
+		    	$data['departure_airport_time'] = $line['deptime'];
1164
+		    }
1165
+		    if (isset($line['arricao'])) {
1166
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1167
+		    }
870 1168
 		    //$data['arrival_airport_time'] = $line['arrtime'];
871
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
872
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
873
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
874
-		    else $data['info'] = '';
1169
+		    if (isset($line['aircraft'])) {
1170
+		    	$data['aircraft_icao'] = $line['aircraft'];
1171
+		    }
1172
+		    if (isset($line['transponder'])) {
1173
+		    	$data['squawk'] = $line['transponder'];
1174
+		    }
1175
+		    if (isset($line['atis'])) {
1176
+		    	$data['info'] = $line['atis'];
1177
+		    } else {
1178
+		    	$data['info'] = '';
1179
+		    }
875 1180
 		    $data['format_source'] = 'pireps';
876 1181
     		    $data['id_source'] = $id_source;
877 1182
 		    $data['datetime'] = date('Y-m-d H:i:s');
878
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1183
+		    if (isset($value['name']) && $value['name'] != '') {
1184
+		    	$data['source_name'] = $value['name'];
1185
+		    }
879 1186
 		    if ($line['icon'] == 'plane') {
880 1187
 			$SI->add($data);
881 1188
 		    //    print_r($data);
@@ -884,16 +1191,28 @@  discard block
 block discarded – undo
884 1191
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
885 1192
 			$typec = substr($data['ident'],-3);
886 1193
 			$data['type'] = '';
887
-			if ($typec == 'APP') $data['type'] = 'Approach';
888
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
889
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
890
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
891
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
892
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
893
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
894
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
895
-			else $data['type'] = 'Observer';
896
-			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']);
1194
+			if ($typec == 'APP') {
1195
+				$data['type'] = 'Approach';
1196
+			} elseif ($typec == 'TWR') {
1197
+				$data['type'] = 'Tower';
1198
+			} elseif ($typec == 'OBS') {
1199
+				$data['type'] = 'Observer';
1200
+			} elseif ($typec == 'GND') {
1201
+				$data['type'] = 'Ground';
1202
+			} elseif ($typec == 'DEL') {
1203
+				$data['type'] = 'Delivery';
1204
+			} elseif ($typec == 'DEP') {
1205
+				$data['type'] = 'Departure';
1206
+			} elseif ($typec == 'FSS') {
1207
+				$data['type'] = 'Flight Service Station';
1208
+			} elseif ($typec == 'CTR') {
1209
+				$data['type'] = 'Control Radar or Centre';
1210
+			} else {
1211
+				$data['type'] = 'Observer';
1212
+			}
1213
+			if (isset($ATC)) {
1214
+				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']);
1215
+			}
897 1216
 		    }
898 1217
 		    unset($data);
899 1218
 		}
@@ -903,7 +1222,9 @@  discard block
 block discarded – undo
903 1222
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
904 1223
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
905 1224
 	    //$buffer = $Common->getData($hosts[$id]);
906
-	    if ($globalDebug) echo 'Get Data...'."\n";
1225
+	    if ($globalDebug) {
1226
+	    	echo 'Get Data...'."\n";
1227
+	    }
907 1228
 	    $buffer = $Common->getData($value['host']);
908 1229
 	    $all_data = json_decode($buffer,true);
909 1230
 	    if ($buffer != '' && is_array($all_data)) {
@@ -911,10 +1232,16 @@  discard block
 block discarded – undo
911 1232
 		foreach ($all_data as $line) {
912 1233
 	    	    $data = array();
913 1234
 	    	    //$data['id'] = $line['id']; // id not usable
914
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1235
+	    	    if (isset($line['pilotid'])) {
1236
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1237
+	    	    }
915 1238
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
916
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
917
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1239
+	    	    if (isset($line['pilotname'])) {
1240
+	    	    	$data['pilot_name'] = $line['pilotname'];
1241
+	    	    }
1242
+	    	    if (isset($line['pilotid'])) {
1243
+	    	    	$data['pilot_id'] = $line['pilotid'];
1244
+	    	    }
918 1245
 	    	    $data['ident'] = $line['flightnum']; // ident
919 1246
 	    	    $data['altitude'] = $line['alt']; // altitude
920 1247
 	    	    $data['speed'] = $line['gs']; // speed
@@ -932,27 +1259,41 @@  discard block
 block discarded – undo
932 1259
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
933 1260
     		    $data['arrival_airport_time'] = $line['arrtime'];
934 1261
     		    $data['registration'] = $line['aircraft'];
935
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1262
+		    if (isset($line['route'])) {
1263
+		    	$data['waypoints'] = $line['route'];
1264
+		    }
1265
+		    // route
936 1266
 		    if (isset($line['aircraftname'])) {
937 1267
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
938 1268
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
939 1269
 	    		$aircraft_data = explode('-',$line['aircraftname']);
940
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
941
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
942
-	    		else {
1270
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1271
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1272
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1273
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1274
+	    		} else {
943 1275
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
944
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
945
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1276
+	    		    if (isset($aircraft_data[1])) {
1277
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1278
+	    		    } else {
1279
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1280
+	    		    }
946 1281
 	    		}
947 1282
 	    	    }
948
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1283
+    		    if (isset($line['route'])) {
1284
+    		    	$data['waypoints'] = $line['route'];
1285
+    		    }
949 1286
     		    $data['id_source'] = $id_source;
950 1287
 	    	    $data['format_source'] = 'phpvmacars';
951
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1288
+		    if (isset($value['name']) && $value['name'] != '') {
1289
+		    	$data['source_name'] = $value['name'];
1290
+		    }
952 1291
 		    $SI->add($data);
953 1292
 		    unset($data);
954 1293
 		}
955
-		if ($globalDebug) echo 'No more data...'."\n";
1294
+		if ($globalDebug) {
1295
+			echo 'No more data...'."\n";
1296
+		}
956 1297
 		unset($buffer);
957 1298
 		unset($all_data);
958 1299
 	    }
@@ -960,7 +1301,9 @@  discard block
 block discarded – undo
960 1301
     	    $last_exec[$id]['last'] = time();
961 1302
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
962 1303
 	    //$buffer = $Common->getData($hosts[$id]);
963
-	    if ($globalDebug) echo 'Get Data...'."\n";
1304
+	    if ($globalDebug) {
1305
+	    	echo 'Get Data...'."\n";
1306
+	    }
964 1307
 	    $buffer = $Common->getData($value['host']);
965 1308
 	    $all_data = json_decode($buffer,true);
966 1309
 	    if ($buffer != '' && is_array($all_data)) {
@@ -989,15 +1332,22 @@  discard block
 block discarded – undo
989 1332
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
990 1333
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
991 1334
     		    //$data['registration'] = $line['aircraft'];
992
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1335
+		    if (isset($line['route'])) {
1336
+		    	$data['waypoints'] = $line['route'];
1337
+		    }
1338
+		    // route
993 1339
 	    	    $data['aircraft_icao'] = $line['plane_type'];
994 1340
     		    $data['id_source'] = $id_source;
995 1341
 	    	    $data['format_source'] = 'vam';
996
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1342
+		    if (isset($value['name']) && $value['name'] != '') {
1343
+		    	$data['source_name'] = $value['name'];
1344
+		    }
997 1345
 		    $SI->add($data);
998 1346
 		    unset($data);
999 1347
 		}
1000
-		if ($globalDebug) echo 'No more data...'."\n";
1348
+		if ($globalDebug) {
1349
+			echo 'No more data...'."\n";
1350
+		}
1001 1351
 		unset($buffer);
1002 1352
 		unset($all_data);
1003 1353
 	    }
@@ -1005,7 +1355,9 @@  discard block
 block discarded – undo
1005 1355
     	    $last_exec[$id]['last'] = time();
1006 1356
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1007 1357
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1008
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1358
+	    if (function_exists('pcntl_fork')) {
1359
+	    	pcntl_signal_dispatch();
1360
+	    }
1009 1361
     	    //$last_exec[$id]['last'] = time();
1010 1362
 
1011 1363
 	    //$read = array( $sockets[$id] );
@@ -1013,7 +1365,9 @@  discard block
 block discarded – undo
1013 1365
 	    $write = NULL;
1014 1366
 	    $e = NULL;
1015 1367
 	    $n = socket_select($read, $write, $e, $timeout);
1016
-	    if ($e != NULL) var_dump($e);
1368
+	    if ($e != NULL) {
1369
+	    	var_dump($e);
1370
+	    }
1017 1371
 	    if ($n > 0) {
1018 1372
 		$reset = 0;
1019 1373
 		foreach ($read as $nb => $r) {
@@ -1034,12 +1388,16 @@  discard block
 block discarded – undo
1034 1388
 		    //$SI::del();
1035 1389
 		    if ($format == 'vrstcp') {
1036 1390
 			$buffer = explode('},{',$buffer);
1037
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1391
+		    } else {
1392
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1393
+		    }
1038 1394
 		    // SBS format is CSV format
1039 1395
 		    if ($buffer !== FALSE && $buffer != '') {
1040 1396
 			$tt[$format] = 0;
1041 1397
 			if ($format == 'acarssbs3') {
1042
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1398
+			    if ($globalDebug) {
1399
+			    	echo 'ACARS : '.$buffer."\n";
1400
+			    }
1043 1401
 			    $ACARS->add(trim($buffer));
1044 1402
 			    $ACARS->deleteLiveAcarsData();
1045 1403
 			} elseif ($format == 'raw') {
@@ -1048,25 +1406,55 @@  discard block
 block discarded – undo
1048 1406
 			    if (is_array($data)) {
1049 1407
 				$data['datetime'] = date('Y-m-d H:i:s');
1050 1408
 				$data['format_source'] = 'raw';
1051
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1052
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1053
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1409
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1410
+					$data['source_name'] = $globalSources[$nb]['name'];
1411
+				}
1412
+				if (isset($globalSources[$nb]['sourcestats'])) {
1413
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1414
+				}
1415
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1416
+					$SI->add($data);
1417
+				}
1054 1418
 			    }
1055 1419
 			} elseif ($format == 'ais') {
1056 1420
 			    $ais_data = $AIS->parse_line(trim($buffer));
1057 1421
 			    $data = array();
1058
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1059
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1060
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1061
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1062
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1063
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1064
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1065
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1066
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1067
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1068
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1069
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1422
+			    if (isset($ais_data['ident'])) {
1423
+			    	$data['ident'] = $ais_data['ident'];
1424
+			    }
1425
+			    if (isset($ais_data['mmsi'])) {
1426
+			    	$data['mmsi'] = $ais_data['mmsi'];
1427
+			    }
1428
+			    if (isset($ais_data['speed'])) {
1429
+			    	$data['speed'] = $ais_data['speed'];
1430
+			    }
1431
+			    if (isset($ais_data['heading'])) {
1432
+			    	$data['heading'] = $ais_data['heading'];
1433
+			    }
1434
+			    if (isset($ais_data['latitude'])) {
1435
+			    	$data['latitude'] = $ais_data['latitude'];
1436
+			    }
1437
+			    if (isset($ais_data['longitude'])) {
1438
+			    	$data['longitude'] = $ais_data['longitude'];
1439
+			    }
1440
+			    if (isset($ais_data['status'])) {
1441
+			    	$data['status'] = $ais_data['status'];
1442
+			    }
1443
+			    if (isset($ais_data['type'])) {
1444
+			    	$data['type'] = $ais_data['type'];
1445
+			    }
1446
+			    if (isset($ais_data['imo'])) {
1447
+			    	$data['imo'] = $ais_data['imo'];
1448
+			    }
1449
+			    if (isset($ais_data['callsign'])) {
1450
+			    	$data['callsign'] = $ais_data['callsign'];
1451
+			    }
1452
+			    if (isset($ais_data['destination'])) {
1453
+			    	$data['arrival_code'] = $ais_data['destination'];
1454
+			    }
1455
+			    if (isset($ais_data['eta_ts'])) {
1456
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1457
+			    }
1070 1458
 
1071 1459
 			    if (isset($ais_data['timestamp'])) {
1072 1460
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1075,7 +1463,9 @@  discard block
 block discarded – undo
1075 1463
 			    }
1076 1464
 			    $data['format_source'] = 'aisnmea';
1077 1465
     			    $data['id_source'] = $id_source;
1078
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1466
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1467
+			    	$MI->add($data);
1468
+			    }
1079 1469
 			    unset($data);
1080 1470
                         } elseif ($format == 'flightgearsp') {
1081 1471
                     	    //echo $buffer."\n";
@@ -1093,11 +1483,15 @@  discard block
 block discarded – undo
1093 1483
 				$data['speed'] = round($line[5]*1.94384);
1094 1484
 				$data['datetime'] = date('Y-m-d H:i:s');
1095 1485
 				$data['format_source'] = 'flightgearsp';
1096
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1486
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1487
+					$SI->add($data);
1488
+				}
1097 1489
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1098 1490
 			    }
1099 1491
                         } elseif ($format == 'acars') {
1100
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1492
+                    	    if ($globalDebug) {
1493
+                    	    	echo 'ACARS : '.$buffer."\n";
1494
+                    	    }
1101 1495
 			    $ACARS->add(trim($buffer));
1102 1496
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1103 1497
 			    $ACARS->deleteLiveAcarsData();
@@ -1118,7 +1512,9 @@  discard block
 block discarded – undo
1118 1512
 				    $aircraft_type = $line[10];
1119 1513
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1120 1514
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1121
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1515
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1516
+				    	$SI->add($data);
1517
+				    }
1122 1518
 				}
1123 1519
 			    }
1124 1520
 			} elseif ($format == 'beast') {
@@ -1128,27 +1524,59 @@  discard block
 block discarded – undo
1128 1524
 			    foreach($buffer as $all_data) {
1129 1525
 				$line = json_decode('{'.$all_data.'}',true);
1130 1526
 				$data = array();
1131
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1132
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1133
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1134
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1135
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1136
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1137
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1527
+				if (isset($line['Icao'])) {
1528
+					$data['hex'] = $line['Icao'];
1529
+				}
1530
+				// hex
1531
+				if (isset($line['Call'])) {
1532
+					$data['ident'] = $line['Call'];
1533
+				}
1534
+				// ident
1535
+				if (isset($line['Alt'])) {
1536
+					$data['altitude'] = $line['Alt'];
1537
+				}
1538
+				// altitude
1539
+				if (isset($line['Spd'])) {
1540
+					$data['speed'] = $line['Spd'];
1541
+				}
1542
+				// speed
1543
+				if (isset($line['Trak'])) {
1544
+					$data['heading'] = $line['Trak'];
1545
+				}
1546
+				// heading
1547
+				if (isset($line['Lat'])) {
1548
+					$data['latitude'] = $line['Lat'];
1549
+				}
1550
+				// lat
1551
+				if (isset($line['Long'])) {
1552
+					$data['longitude'] = $line['Long'];
1553
+				}
1554
+				// long
1138 1555
 				//$data['verticalrate'] = $line['']; // verticale rate
1139
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1556
+				if (isset($line['Sqk'])) {
1557
+					$data['squawk'] = $line['Sqk'];
1558
+				}
1559
+				// squawk
1140 1560
 				$data['emergency'] = ''; // emergency
1141
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1561
+				if (isset($line['Reg'])) {
1562
+					$data['registration'] = $line['Reg'];
1563
+				}
1142 1564
 				/*
1143 1565
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1144 1566
 				else $data['datetime'] = date('Y-m-d H:i:s');
1145 1567
 				*/
1146 1568
 				$data['datetime'] = date('Y-m-d H:i:s');
1147
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1569
+				if (isset($line['Type'])) {
1570
+					$data['aircraft_icao'] = $line['Type'];
1571
+				}
1148 1572
 		    		$data['format_source'] = 'vrstcp';
1149 1573
 				$data['id_source'] = $id_source;
1150
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1151
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1574
+				if (isset($value['name']) && $value['name'] != '') {
1575
+					$data['source_name'] = $value['name'];
1576
+				}
1577
+				if (isset($data['latitude']) && isset($data['hex'])) {
1578
+					$SI->add($data);
1579
+				}
1152 1580
 				unset($data);
1153 1581
 			    }
1154 1582
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1161,21 +1589,43 @@  discard block
 block discarded – undo
1161 1589
     				$data['hex'] = $lined['hexid'];
1162 1590
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1163 1591
     				$data['datetime'] = date('Y-m-d H:i:s');;
1164
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1165
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1166
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1167
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1168
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1169
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1170
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1592
+    				if (isset($lined['ident'])) {
1593
+    					$data['ident'] = $lined['ident'];
1594
+    				}
1595
+    				if (isset($lined['lat'])) {
1596
+    					$data['latitude'] = $lined['lat'];
1597
+    				}
1598
+    				if (isset($lined['lon'])) {
1599
+    					$data['longitude'] = $lined['lon'];
1600
+    				}
1601
+    				if (isset($lined['speed'])) {
1602
+    					$data['speed'] = $lined['speed'];
1603
+    				}
1604
+    				if (isset($lined['squawk'])) {
1605
+    					$data['squawk'] = $lined['squawk'];
1606
+    				}
1607
+    				if (isset($lined['alt'])) {
1608
+    					$data['altitude'] = $lined['alt'];
1609
+    				}
1610
+    				if (isset($lined['heading'])) {
1611
+    					$data['heading'] = $lined['heading'];
1612
+    				}
1171 1613
     				$data['id_source'] = $id_source;
1172 1614
     				$data['format_source'] = 'tsv';
1173
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1174
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1175
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1615
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1616
+    					$data['source_name'] = $globalSources[$nb]['name'];
1617
+    				}
1618
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1619
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1620
+    				}
1621
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1622
+    					$SI->add($data);
1623
+    				}
1176 1624
     				unset($lined);
1177 1625
     				unset($data);
1178
-    			    } else $error = true;
1626
+    			    } else {
1627
+    			    	$error = true;
1628
+    			    }
1179 1629
 			} elseif ($format == 'aprs' && $use_aprs) {
1180 1630
 			    if ($aprs_connect == 0) {
1181 1631
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1200,31 +1650,63 @@  discard block
 block discarded – undo
1200 1650
 				    $aprs_last_tx = time();
1201 1651
 				    $data = array();
1202 1652
 				    //print_r($line);
1203
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1204
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1205
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1206
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1653
+				    if (isset($line['address'])) {
1654
+				    	$data['hex'] = $line['address'];
1655
+				    }
1656
+				    if (isset($line['mmsi'])) {
1657
+				    	$data['mmsi'] = $line['mmsi'];
1658
+				    }
1659
+				    if (isset($line['timestamp'])) {
1660
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1661
+				    } else {
1662
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1663
+				    }
1207 1664
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1208
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1665
+				    if (isset($line['ident'])) {
1666
+				    	$data['ident'] = $line['ident'];
1667
+				    }
1209 1668
 				    $data['latitude'] = $line['latitude'];
1210 1669
 				    $data['longitude'] = $line['longitude'];
1211 1670
 				    //$data['verticalrate'] = $line[16];
1212
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1213
-				    else $data['speed'] = 0;
1214
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1215
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1216
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1217
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1671
+				    if (isset($line['speed'])) {
1672
+				    	$data['speed'] = $line['speed'];
1673
+				    } else {
1674
+				    	$data['speed'] = 0;
1675
+				    }
1676
+				    if (isset($line['altitude'])) {
1677
+				    	$data['altitude'] = $line['altitude'];
1678
+				    }
1679
+				    if (isset($line['comment'])) {
1680
+				    	$data['comment'] = $line['comment'];
1681
+				    }
1682
+				    if (isset($line['symbol'])) {
1683
+				    	$data['type'] = $line['symbol'];
1684
+				    }
1685
+				    if (isset($line['heading'])) {
1686
+				    	$data['heading'] = $line['heading'];
1687
+				    }
1218 1688
 				    //else $data['heading'] = 0;
1219
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1220
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1689
+				    if (isset($line['stealth'])) {
1690
+				    	$data['aircraft_type'] = $line['stealth'];
1691
+				    }
1692
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1693
+				    	$data['noarchive'] = true;
1694
+				    }
1221 1695
     				    $data['id_source'] = $id_source;
1222
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1223
-				    else $data['format_source'] = 'aprs';
1696
+    				    if (isset($line['format_source'])) {
1697
+    				    	$data['format_source'] = $line['format_source'];
1698
+    				    } else {
1699
+				    	$data['format_source'] = 'aprs';
1700
+				    }
1224 1701
 				    $data['source_name'] = $line['source'];
1225
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1226
-				    else $data['source_type'] = 'flarm';
1227
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1702
+				    if (isset($line['source_type'])) {
1703
+				    	$data['source_type'] = $line['source_type'];
1704
+				    } else {
1705
+				    	$data['source_type'] = 'flarm';
1706
+				    }
1707
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1708
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1709
+    				    }
1228 1710
 				    $currentdate = date('Y-m-d H:i:s');
1229 1711
 				    $aprsdate = strtotime($data['datetime']);
1230 1712
 				    // Accept data if time <= system time + 20s
@@ -1234,19 +1716,22 @@  discard block
 block discarded – undo
1234 1716
 					echo 'add...'."\n";
1235 1717
 					$send = $MI->add($data);
1236 1718
 				    } elseif (isset($line['stealth'])) {
1237
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1238
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1719
+					if ($line['stealth'] != 0) {
1720
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1721
+					} else {
1722
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1723
+					}
1239 1724
 				    //} elseif (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' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1240 1725
 				    } 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') {
1241 1726
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1242
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1727
+					if (isset($globalTracker) && $globalTracker) {
1728
+						$send = $TI->add($data);
1729
+					}
1243 1730
 				    }
1244 1731
 				    unset($data);
1245
-				} 
1246
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1732
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1247 1733
 					echo '!! Weather Station not yet supported'."\n";
1248
-				}
1249
-				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')) {
1734
+				} 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')) {
1250 1735
 					echo '!! Car & Trucks not yet supported'."\n";
1251 1736
 				}
1252 1737
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1279,25 +1764,42 @@  discard block
 block discarded – undo
1279 1764
     				$data['ground'] = $line[21];
1280 1765
     				$data['emergency'] = $line[19];
1281 1766
     				$data['format_source'] = 'sbs';
1282
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1283
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1767
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1768
+					$data['source_name'] = $globalSources[$nb]['name'];
1769
+				}
1770
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1771
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1772
+    				}
1284 1773
     				$data['id_source'] = $id_source;
1285
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1286
-    				else $error = true;
1774
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1775
+    					$send = $SI->add($data);
1776
+    				} else {
1777
+    					$error = true;
1778
+    				}
1287 1779
     				unset($data);
1288
-    			    } else $error = true;
1780
+    			    } else {
1781
+    			    	$error = true;
1782
+    			    }
1289 1783
 			    if ($error) {
1290 1784
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1291
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1785
+					if ($globalDebug) {
1786
+						echo "Not a message. Ignoring... \n";
1787
+					}
1292 1788
 				} else {
1293
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1789
+					if ($globalDebug) {
1790
+						echo "Wrong line format. Ignoring... \n";
1791
+					}
1294 1792
 					if ($globalDebug) {
1295 1793
 						echo $buffer;
1296 1794
 						//print_r($line);
1297 1795
 					}
1298 1796
 					//socket_close($r);
1299
-					if ($globalDebug) echo "Reconnect after an error...\n";
1300
-					if ($format == 'aprs') $aprs_connect = 0;
1797
+					if ($globalDebug) {
1798
+						echo "Reconnect after an error...\n";
1799
+					}
1800
+					if ($format == 'aprs') {
1801
+						$aprs_connect = 0;
1802
+					}
1301 1803
 					$sourceer[$nb] = $globalSources[$nb];
1302 1804
 					connect_all($sourceer);
1303 1805
 					$sourceer = array();
@@ -1305,10 +1807,14 @@  discard block
 block discarded – undo
1305 1807
 			    }
1306 1808
 			}
1307 1809
 			// Sleep for xxx microseconds
1308
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1810
+			if (isset($globalSBSSleep)) {
1811
+				usleep($globalSBSSleep);
1812
+			}
1309 1813
 		    } else {
1310 1814
 			if ($format == 'flightgearmp') {
1311
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1815
+			    	if ($globalDebug) {
1816
+			    		echo "Reconnect FlightGear MP...";
1817
+			    	}
1312 1818
 				//@socket_close($r);
1313 1819
 				sleep($globalMinFetch);
1314 1820
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1317,10 +1823,15 @@  discard block
 block discarded – undo
1317 1823
 				break;
1318 1824
 				
1319 1825
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1320
-			    if (isset($tt[$format])) $tt[$format]++;
1321
-			    else $tt[$format] = 0;
1826
+			    if (isset($tt[$format])) {
1827
+			    	$tt[$format]++;
1828
+			    } else {
1829
+			    	$tt[$format] = 0;
1830
+			    }
1322 1831
 			    if ($tt[$format] > 30) {
1323
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1832
+				if ($globalDebug) {
1833
+					echo "ERROR : Reconnect ".$format."...";
1834
+				}
1324 1835
 				//@socket_close($r);
1325 1836
 				sleep(2);
1326 1837
 				$aprs_connect = 0;
@@ -1337,11 +1848,17 @@  discard block
 block discarded – undo
1337 1848
 	    } else {
1338 1849
 		$error = socket_strerror(socket_last_error());
1339 1850
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1340
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1341
-			if (isset($globalDebug)) echo "Restarting...\n";
1851
+			if ($globalDebug) {
1852
+				echo "ERROR : socket_select give this error ".$error . "\n";
1853
+			}
1854
+			if (isset($globalDebug)) {
1855
+				echo "Restarting...\n";
1856
+			}
1342 1857
 			// Restart the script if possible
1343 1858
 			if (is_array($sockets)) {
1344
-			    if ($globalDebug) echo "Shutdown all sockets...";
1859
+			    if ($globalDebug) {
1860
+			    	echo "Shutdown all sockets...";
1861
+			    }
1345 1862
 			    
1346 1863
 			    foreach ($sockets as $sock) {
1347 1864
 				@socket_shutdown($sock,2);
@@ -1349,21 +1866,33 @@  discard block
 block discarded – undo
1349 1866
 			    }
1350 1867
 			    
1351 1868
 			}
1352
-			if ($globalDebug) echo "Restart all connections...";
1869
+			if ($globalDebug) {
1870
+				echo "Restart all connections...";
1871
+			}
1353 1872
 			sleep(2);
1354 1873
 			$time = time();
1355 1874
 			//connect_all($hosts);
1356 1875
 			$aprs_connect = 0;
1357
-			if ($reset%5 == 0) sleep(20);
1358
-			if ($reset%10 == 0) sleep(100);
1359
-			if ($reset%20 == 0) sleep(200);
1360
-			if ($reset > 100) exit('Too many attempts...');
1876
+			if ($reset%5 == 0) {
1877
+				sleep(20);
1878
+			}
1879
+			if ($reset%10 == 0) {
1880
+				sleep(100);
1881
+			}
1882
+			if ($reset%20 == 0) {
1883
+				sleep(200);
1884
+			}
1885
+			if ($reset > 100) {
1886
+				exit('Too many attempts...');
1887
+			}
1361 1888
 			connect_all($globalSources);
1362 1889
 		}
1363 1890
 	    }
1364 1891
 	}
1365 1892
 	if ($globalDaemon === false) {
1366
-	    if ($globalDebug) echo 'Check all...'."\n";
1893
+	    if ($globalDebug) {
1894
+	    	echo 'Check all...'."\n";
1895
+	    }
1367 1896
 	    $SI->checkAll();
1368 1897
 	}
1369 1898
     }
Please login to merge, or discard this patch.
require/class.APRS.php 2 patches
Spacing   +97 added lines, -98 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 	
91 91
 
92 92
     private function urshift($n, $s) {
93
-	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
93
+	return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| 
95 94
 		(0x40000000 >> ($s - 1));
96 95
     }
97 96
 
@@ -103,7 +102,7 @@  discard block
 block discarded – undo
103 102
 	//$split_input = str_split($input);
104 103
 
105 104
 	/* Find the end of header checking for NULL bytes while doing it. */
106
-	$splitpos = strpos($input,':');
105
+	$splitpos = strpos($input, ':');
107 106
 	
108 107
 	/* Check that end was found and body has at least one byte. */
109 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
@@ -113,15 +112,15 @@  discard block
 block discarded – undo
113 112
 	
114 113
 	if ($debug) echo 'input : '.$input."\n";
115 114
 	/* Save header and body. */
116
-	$body = substr($input,$splitpos+1,$input_len);
115
+	$body = substr($input, $splitpos + 1, $input_len);
117 116
 	$body_len = strlen($body);
118
-	$header = substr($input,0,$splitpos);
117
+	$header = substr($input, 0, $splitpos);
119 118
 	//$header_len = strlen($header);
120 119
 	if ($debug) echo 'header : '.$header."\n";
121 120
 	
122 121
 	/* Parse source, target and path. */
123 122
 	//FLRDF0A52>APRS,qAS,LSTB
124
-	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
123
+	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) {
125 124
 	    $ident = $matches[1];
126 125
 	    $all_elements = $matches[2];
127 126
 	    if ($ident == 'AIRCRAFT') {
@@ -135,14 +134,14 @@  discard block
 block discarded – undo
135 134
 		$result['ident'] = $ident;
136 135
 	    }
137 136
 	} else return false;
138
-	$elements = explode(',',$all_elements);
137
+	$elements = explode(',', $all_elements);
139 138
 	$source = end($elements);
140 139
 	$result['source'] = $source;
141 140
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
141
+	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) {
143 142
 	        //echo "ok";
144 143
 	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
144
+	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) {
146 145
 		if ($debug) echo 'element : '.$element."\n";
147 146
 		return false;
148 147
 	    }
@@ -155,14 +154,14 @@  discard block
 block discarded – undo
155 154
 	    */
156 155
 	}
157 156
 	
158
-	$type = substr($body,0,1);
157
+	$type = substr($body, 0, 1);
159 158
 	if ($debug) echo 'type : '.$type."\n";
160 159
 	if ($type == ';') {
161 160
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162
-			$result['address'] = trim(substr($body,1,9));
161
+			$result['address'] = trim(substr($body, 1, 9));
163 162
 		} elseif (isset($result['source_type']) && $result['source_type'] == 'ais') {
164
-			$result['mmsi'] = trim(substr($body,1,9));
165
-		} else $result['ident'] = trim(substr($body,1,9));
163
+			$result['mmsi'] = trim(substr($body, 1, 9));
164
+		} else $result['ident'] = trim(substr($body, 1, 9));
166 165
 	} elseif ($type == ',') {
167 166
 		// Invalid data or test data
168 167
 		return false;
@@ -170,24 +169,24 @@  discard block
 block discarded – undo
170 169
 	
171 170
 	// Check for Timestamp
172 171
 	$find = false;
173
-	$body_parse = substr($body,1);
172
+	$body_parse = substr($body, 1);
174 173
 	//echo 'Body : '.$body."\n";
175
-	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
176
-	    $body_parse = substr($body_parse,10);
174
+	if (preg_match('/^;(.){9}\*/', $body, $matches)) {
175
+	    $body_parse = substr($body_parse, 10);
177 176
 	    $find = true;
178 177
 	    //echo $body_parse."\n";
179 178
 	}
180
-	if (preg_match('/^`(.*)\//',$body,$matches)) {
181
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
179
+	if (preg_match('/^`(.*)\//', $body, $matches)) {
180
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
182 181
 	    $find = true;
183 182
 	    //echo $body_parse."\n";
184 183
 	}
185
-	if (preg_match("/^'(.*)\//",$body,$matches)) {
186
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
184
+	if (preg_match("/^'(.*)\//", $body, $matches)) {
185
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
187 186
 	    $find = true;
188 187
 	    //echo $body_parse."\n";
189 188
 	}
190
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
189
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) {
191 190
 	    $find = true;
192 191
 	    //print_r($matches);
193 192
 	    $timestamp = $matches[0];
@@ -202,19 +201,19 @@  discard block
 block discarded – undo
202 201
 		// This work or not ?
203 202
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
204 203
 	    }
205
-	    $body_parse = substr($body_parse,7);
204
+	    $body_parse = substr($body_parse, 7);
206 205
 	    $result['timestamp'] = $timestamp;
207 206
 	    //echo date('Ymd H:i:s',$timestamp);
208 207
 	}
209
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
208
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) {
210 209
 	    $find = true;
211 210
 	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
212
-	    $body_parse = substr($body_parse,8);
211
+	    $body_parse = substr($body_parse, 8);
213 212
 	    $result['timestamp'] = $timestamp;
214 213
 	    //echo date('Ymd H:i:s',$timestamp);
215 214
 	}
216 215
 	//if (strlen($body_parse) > 19) {
217
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
+	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) {
218 217
 	    $find = true;
219 218
 		// 4658.70N/00707.78Ez
220 219
 		//print_r(str_split($body_parse));
@@ -240,11 +239,11 @@  discard block
 block discarded – undo
240 239
 	    */
241 240
 		$latitude = $lat + floatval($lat_min)/60;
242 241
 		$longitude = $lon + floatval($lon_min)/60;
243
-		if ($sind == 'S') $latitude = 0-$latitude;
244
-		if ($wind == 'W') $longitude = 0-$longitude;
242
+		if ($sind == 'S') $latitude = 0 - $latitude;
243
+		if ($wind == 'W') $longitude = 0 - $longitude;
245 244
 		$result['latitude'] = $latitude;
246 245
 		$result['longitude'] = $longitude;
247
-		$body_parse = substr($body_parse,18);
246
+		$body_parse = substr($body_parse, 18);
248 247
 		$body_parse_len = strlen($body_parse);
249 248
 	    }
250 249
 	    $body_parse_len = strlen($body_parse);
@@ -272,7 +271,7 @@  discard block
 block discarded – undo
272 271
 		//echo $body_parse;
273 272
 			//if ($type != ';' && $type != '>') {
274 273
 			if ($type != '') {
275
-			$body_parse = substr($body_parse,1);
274
+			$body_parse = substr($body_parse, 1);
276 275
 			$body_parse_len = strlen($body_parse);
277 276
 			$result['symbol_code'] = $symbol_code;
278 277
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
@@ -283,16 +282,16 @@  discard block
 block discarded – undo
283 282
 		    //$body_parse_len = strlen($body_parse);
284 283
 		    if ($body_parse_len >= 7) {
285 284
 			
286
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
287
-		    	    $course = substr($body_parse,0,3);
285
+		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) {
286
+		    	    $course = substr($body_parse, 0, 3);
288 287
 		    	    $tmp_s = intval($course);
289 288
 		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
290
-		    	    $speed = substr($body_parse,4,3);
289
+		    	    $speed = substr($body_parse, 4, 3);
291 290
 		    	    if ($speed != '...') {
292 291
 		    		//$result['speed'] = round($speed*1.852);
293 292
 		    		$result['speed'] = intval($speed);
294 293
 		    	    }
295
-		    	    $body_parse = substr($body_parse,7);
294
+		    	    $body_parse = substr($body_parse, 7);
296 295
 		        }
297 296
 		        // Check PHGR, PHG, RNG
298 297
 		    } 
@@ -302,12 +301,12 @@  discard block
 block discarded – undo
302 301
 		    }
303 302
 		    */
304 303
 		    if (strlen($body_parse) > 0) {
305
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
+		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) {
306 305
 		            $altitude = intval($matches[1]);
307 306
 		            //$result['altitude'] = round($altitude*0.3048);
308 307
 		            $result['altitude'] = $altitude;
309 308
 		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
310
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
+		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse));
311 310
 		        }
312 311
 		    }
313 312
 		    
@@ -319,13 +318,13 @@  discard block
 block discarded – undo
319 318
 		    */
320 319
 		    // DAO
321 320
 		    
322
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
321
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
323 322
 			    
324 323
 			    $dao = $matches[1];
325
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
324
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
326 325
 				$dao_split = str_split($dao);
327
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
328
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
326
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
327
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
329 328
 			    
330 329
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
331 330
 				else $result['latitude'] += $lat_off;
@@ -333,44 +332,44 @@  discard block
 block discarded – undo
333 332
 				else $result['longitude'] += $lon_off;
334 333
 			    }
335 334
 			    
336
-		            $body_parse = substr($body_parse,6);
335
+		            $body_parse = substr($body_parse, 6);
337 336
 		    }
338 337
 		    
339
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
338
+		    if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) {
340 339
 			$result['ident'] = $matches[1];
341 340
 		    }
342
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
341
+		    if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) {
343 342
 			$result['squawk'] = $matches[1];
344 343
 		    }
345
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
344
+		    if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) {
346 345
 			$result['aircraft_icao'] = $matches[1];
347 346
 		    }
348
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
347
+		    if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) {
349 348
 			$result['typeid'] = $matches[1];
350 349
 		    }
351
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
350
+		    if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) {
352 351
 			$result['imo'] = $matches[1];
353 352
 		    }
354
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
353
+		    if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) {
355 354
 			$result['arrival_date'] = $matches[1];
356 355
 		    }
357
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
356
+		    if (preg_match('/AC=([0-9A-Z]*)/', $body_parse, $matches)) {
358 357
 			$result['arrival_code'] = $matches[1];
359 358
 		    }
360 359
 		    // OGN comment
361 360
 		   // echo "Before OGN : ".$body_parse."\n";
362 361
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
363
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
362
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
364 363
 			$id = $matches[1];
365 364
 			//$mode = substr($id,0,2);
366
-			$address = substr($id,2);
365
+			$address = substr($id, 2);
367 366
 			//print_r($matches);
368
-			$addressType = (intval(substr($id,0,2),16))&3;
367
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
369 368
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
370 369
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
371 370
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
372 371
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
373
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
372
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
374 373
 			$result['aircrafttype_code'] = $aircraftType;
375 374
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
376 375
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -387,7 +386,7 @@  discard block
 block discarded – undo
387 386
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
388 387
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
389 388
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
390
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
389
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
391 390
 			$result['stealth'] = $stealth;
392 391
 			$result['address'] = $address;
393 392
 		    }
@@ -399,77 +398,77 @@  discard block
 block discarded – undo
399 398
 		    //$body_parse = substr($body_parse,1);
400 399
 		    //$body_parse_len = strlen($body_parse);
401 400
 
402
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
401
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
403 402
 			    $result['wind_dir'] = intval($matches[1]);
404
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
405
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
406
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
407
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
408
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
403
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
404
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
405
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
406
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
407
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
409 408
 			$result['wind_dir'] = intval($matches[1]);
410
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
411
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
412
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
409
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
410
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
411
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
412
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
413
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
415 414
 			$result['wind_dir'] = intval($matches[1]);
416
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
417
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
418
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
419
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
415
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
416
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
417
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
418
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
420 419
 			$result['wind_dir'] = intval($matches[1]);
421
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
422
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
423
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
420
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
421
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
422
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
424 423
 		    }
425
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
426
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
424
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
425
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
427 426
 		    }
428 427
 		}
429 428
 		} else $result['comment'] = trim($body_parse);
430 429
 
431 430
 	    }
432 431
 	//}
433
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
434
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
432
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
433
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
435 434
 	if ($debug) print_r($result);
436 435
 	return $result;
437 436
     }
438 437
     
439 438
     public function connect() {
440
-	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
439
+	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport;
441 440
 	$aprs_connect = 0;
442 441
 	$aprs_keep = 120;
443 442
 	$aprs_last_tx = time();
444 443
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
445
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
444
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
446 445
 	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
447
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
446
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
448 447
 	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
449 448
 	else $aprs_pass = '-1';
450 449
 	
451
-	$aprs_filter  = '';
450
+	$aprs_filter = '';
452 451
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
453 452
 	$Common = new Common();
454
-	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
453
+	$s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr);
455 454
 	if ($s !== false) {
456 455
 		echo 'Connected to APRS server! '."\n";
457 456
 		$authstart = time();
458 457
 		$this->socket = $s;
459
-		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
460
-		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
458
+		$send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0);
459
+		while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) {
461 460
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
462 461
 			    echo 'APRS user verified !'."\n";
463 462
 			    $this->connected = true;
464 463
 			    return true;
465 464
 			    break;
466 465
 			}
467
-			if (time()-$authstart > 5) {
466
+			if (time() - $authstart > 5) {
468 467
 			    echo 'APRS timeout'."\n";
469 468
 			    break;
470 469
 			}
471 470
 		}
472
-		socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE);
471
+		socket_set_option($this->socket, SOL_SOCKET, SO_KEEPALIVE);
473 472
 	}
474 473
     }
475 474
 
@@ -479,7 +478,7 @@  discard block
 block discarded – undo
479 478
     
480 479
     public function send($data) {
481 480
 	if ($this->connected === false) $this->connect();
482
-	$send = socket_send( $this->socket  , $data , strlen($data),0);
481
+	$send = socket_send($this->socket, $data, strlen($data), 0);
483 482
 	if ($send === FALSE) {
484 483
 		socket_close($this->socket);
485 484
 		$this->connect();
@@ -488,14 +487,14 @@  discard block
 block discarded – undo
488 487
 }
489 488
 
490 489
 class APRSSpotter extends APRS {
491
-	public function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
490
+	public function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) {
492 491
 		$Common = new Common();
493 492
 		if ($latitude != '' && $longitude != '') {
494
-			$latitude = $Common->convertDM($latitude,'latitude');
495
-			$longitude = $Common->convertDM($longitude,'longitude');
496
-			$coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW'];
497
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
498
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
493
+			$latitude = $Common->convertDM($latitude, 'latitude');
494
+			$longitude = $Common->convertDM($longitude, 'longitude');
495
+			$coordinate = sprintf("%02d", $latitude['deg']).str_pad(number_format($latitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d", $longitude['deg']).str_pad(number_format($longitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$longitude['NSEW'];
496
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
497
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
499 498
 			$w = $w1.$w2;
500 499
 			//$w = '00';
501 500
 			$custom = '';
@@ -512,19 +511,19 @@  discard block
 block discarded – undo
512 511
 				$custom .= 'AI='.$aircraft_icao;
513 512
 			}
514 513
 			if ($custom != '') $custom = ' '.$custom;
515
-			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
514
+			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His', strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
516 515
 		}
517 516
 	}
518 517
 }
519 518
 class APRSMarine extends APRS {
520
-	public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
519
+	public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) {
521 520
 		$Common = new Common();
522 521
 		if ($latitude != '' && $longitude != '') {
523
-			$latitude = $Common->convertDM($latitude,'latitude');
524
-			$longitude = $Common->convertDM($longitude,'longitude');
525
-			$coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW'];
526
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
527
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
522
+			$latitude = $Common->convertDM($latitude, 'latitude');
523
+			$longitude = $Common->convertDM($longitude, 'longitude');
524
+			$coordinate = sprintf("%02d", $latitude['deg']).str_pad(number_format($latitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d", $longitude['deg']).str_pad(number_format($longitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$longitude['NSEW'];
525
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
526
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
528 527
 			$w = $w1.$w2;
529 528
 			//$w = '00';
530 529
 			$custom = '';
@@ -550,7 +549,7 @@  discard block
 block discarded – undo
550 549
 			}
551 550
 			if ($custom != '') $custom = ' '.$custom;
552 551
 			$altitude = 0;
553
-			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
552
+			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
554 553
 		}
555 554
 	}
556 555
 }
Please login to merge, or discard this patch.
Braces   +149 added lines, -57 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,13 +168,17 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163 177
 		} elseif (isset($result['source_type']) && $result['source_type'] == 'ais') {
164 178
 			$result['mmsi'] = trim(substr($body,1,9));
165
-		} else $result['ident'] = trim(substr($body,1,9));
179
+		} else {
180
+			$result['ident'] = trim(substr($body,1,9));
181
+		}
166 182
 	} elseif ($type == ',') {
167 183
 		// Invalid data or test data
168 184
 		return false;
@@ -230,7 +246,9 @@  discard block
 block discarded – undo
230 246
 		//$symbol_table = $matches[4];
231 247
 		$lat = intval($lat_deg);
232 248
 		$lon = intval($lon_deg);
233
-		if ($lat > 89 || $lon > 179) return false;
249
+		if ($lat > 89 || $lon > 179) {
250
+			return false;
251
+		}
234 252
 	    
235 253
 	    /*
236 254
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -240,8 +258,12 @@  discard block
 block discarded – undo
240 258
 	    */
241 259
 		$latitude = $lat + floatval($lat_min)/60;
242 260
 		$longitude = $lon + floatval($lon_min)/60;
243
-		if ($sind == 'S') $latitude = 0-$latitude;
244
-		if ($wind == 'W') $longitude = 0-$longitude;
261
+		if ($sind == 'S') {
262
+			$latitude = 0-$latitude;
263
+		}
264
+		if ($wind == 'W') {
265
+			$longitude = 0-$longitude;
266
+		}
245 267
 		$result['latitude'] = $latitude;
246 268
 		$result['longitude'] = $longitude;
247 269
 		$body_parse = substr($body_parse,18);
@@ -275,7 +297,9 @@  discard block
 block discarded – undo
275 297
 			$body_parse = substr($body_parse,1);
276 298
 			$body_parse_len = strlen($body_parse);
277 299
 			$result['symbol_code'] = $symbol_code;
278
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
300
+			if (isset($this->symbols[$symbol_code])) {
301
+				$result['symbol'] = $this->symbols[$symbol_code];
302
+			}
279 303
 			if ($symbol_code != '_') {
280 304
 			}
281 305
 		    //$body_parse = substr($body_parse,1);
@@ -286,7 +310,9 @@  discard block
 block discarded – undo
286 310
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
287 311
 		    	    $course = substr($body_parse,0,3);
288 312
 		    	    $tmp_s = intval($course);
289
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
313
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
314
+		    	    	$result['heading'] = intval($course);
315
+		    	    }
290 316
 		    	    $speed = substr($body_parse,4,3);
291 317
 		    	    if ($speed != '...') {
292 318
 		    		//$result['speed'] = round($speed*1.852);
@@ -327,10 +353,16 @@  discard block
 block discarded – undo
327 353
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
328 354
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
329 355
 			    
330
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
331
-				else $result['latitude'] += $lat_off;
332
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
333
-				else $result['longitude'] += $lon_off;
356
+				if ($result['latitude'] < 0) {
357
+					$result['latitude'] -= $lat_off;
358
+				} else {
359
+					$result['latitude'] += $lat_off;
360
+				}
361
+				if ($result['longitude'] < 0) {
362
+					$result['longitude'] -= $lon_off;
363
+				} else {
364
+					$result['longitude'] += $lon_off;
365
+				}
334 366
 			    }
335 367
 			    
336 368
 		            $body_parse = substr($body_parse,6);
@@ -366,27 +398,48 @@  discard block
 block discarded – undo
366 398
 			$address = substr($id,2);
367 399
 			//print_r($matches);
368 400
 			$addressType = (intval(substr($id,0,2),16))&3;
369
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
370
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
371
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
372
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
401
+			if ($addressType == 0) {
402
+				$result['addresstype'] = "RANDOM";
403
+			} elseif ($addressType == 1) {
404
+				$result['addresstype'] = "ICAO";
405
+			} elseif ($addressType == 2) {
406
+				$result['addresstype'] = "FLARM";
407
+			} elseif ($addressType == 3) {
408
+				$result['addresstype'] = "OGN";
409
+			}
373 410
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
374 411
 			$result['aircrafttype_code'] = $aircraftType;
375
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
376
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
377
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
378
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
379
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
380
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
381
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
382
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
383
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
384
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
385
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
386
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
387
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
388
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
389
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
412
+			if ($aircraftType == 0) {
413
+				$result['aircrafttype'] = "UNKNOWN";
414
+			} elseif ($aircraftType == 1) {
415
+				$result['aircrafttype'] = "GLIDER";
416
+			} elseif ($aircraftType == 2) {
417
+				$result['aircrafttype'] = "TOW_PLANE";
418
+			} elseif ($aircraftType == 3) {
419
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
420
+			} elseif ($aircraftType == 4) {
421
+				$result['aircrafttype'] = "PARACHUTE";
422
+			} elseif ($aircraftType == 5) {
423
+				$result['aircrafttype'] = "DROP_PLANE";
424
+			} elseif ($aircraftType == 6) {
425
+				$result['aircrafttype'] = "HANG_GLIDER";
426
+			} elseif ($aircraftType == 7) {
427
+				$result['aircrafttype'] = "PARA_GLIDER";
428
+			} elseif ($aircraftType == 8) {
429
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
430
+			} elseif ($aircraftType == 9) {
431
+				$result['aircrafttype'] = "JET_AIRCRAFT";
432
+			} elseif ($aircraftType == 10) {
433
+				$result['aircrafttype'] = "UFO";
434
+			} elseif ($aircraftType == 11) {
435
+				$result['aircrafttype'] = "BALLOON";
436
+			} elseif ($aircraftType == 12) {
437
+				$result['aircrafttype'] = "AIRSHIP";
438
+			} elseif ($aircraftType == 13) {
439
+				$result['aircrafttype'] = "UAV";
440
+			} elseif ($aircraftType == 15) {
441
+				$result['aircrafttype'] = "STATIC_OBJECT";
442
+			}
390 443
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
391 444
 			$result['stealth'] = $stealth;
392 445
 			$result['address'] = $address;
@@ -426,13 +479,21 @@  discard block
 block discarded – undo
426 479
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
427 480
 		    }
428 481
 		}
429
-		} else $result['comment'] = trim($body_parse);
482
+		} else {
483
+			$result['comment'] = trim($body_parse);
484
+		}
430 485
 
431 486
 	    }
432 487
 	//}
433
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
434
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
435
-	if ($debug) print_r($result);
488
+	if (isset($result['latitude'])) {
489
+		$result['latitude'] = round($result['latitude'],4);
490
+	}
491
+	if (isset($result['longitude'])) {
492
+		$result['longitude'] = round($result['longitude'],4);
493
+	}
494
+	if ($debug) {
495
+		print_r($result);
496
+	}
436 497
 	return $result;
437 498
     }
438 499
     
@@ -441,12 +502,21 @@  discard block
 block discarded – undo
441 502
 	$aprs_connect = 0;
442 503
 	$aprs_keep = 120;
443 504
 	$aprs_last_tx = time();
444
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
445
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
446
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
447
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
448
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
449
-	else $aprs_pass = '-1';
505
+	if (isset($globalAPRSversion)) {
506
+		$aprs_version = $globalAPRSversion;
507
+	} else {
508
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
509
+	}
510
+	if (isset($globalServerAPRSssid)) {
511
+		$aprs_ssid = $globalServerAPRSssid;
512
+	} else {
513
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
514
+	}
515
+	if (isset($globalServerAPRSpass)) {
516
+		$aprs_pass = $globalServerAPRSpass;
517
+	} else {
518
+		$aprs_pass = '-1';
519
+	}
450 520
 	
451 521
 	$aprs_filter  = '';
452 522
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -478,7 +548,9 @@  discard block
 block discarded – undo
478 548
     }
479 549
     
480 550
     public function send($data) {
481
-	if ($this->connected === false) $this->connect();
551
+	if ($this->connected === false) {
552
+		$this->connect();
553
+	}
482 554
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
483 555
 	if ($send === FALSE) {
484 556
 		socket_close($this->socket);
@@ -500,18 +572,26 @@  discard block
 block discarded – undo
500 572
 			//$w = '00';
501 573
 			$custom = '';
502 574
 			if ($ident != '') {
503
-				if ($custom != '') $custom .= '/';
575
+				if ($custom != '') {
576
+					$custom .= '/';
577
+				}
504 578
 				$custom .= 'CS='.$ident;
505 579
 			}
506 580
 			if ($squawk != '') {
507
-				if ($custom != '') $custom .= '/';
581
+				if ($custom != '') {
582
+					$custom .= '/';
583
+				}
508 584
 				$custom .= 'SQ='.$squawk;
509 585
 			}
510 586
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
511
-				if ($custom != '') $custom .= '/';
587
+				if ($custom != '') {
588
+					$custom .= '/';
589
+				}
512 590
 				$custom .= 'AI='.$aircraft_icao;
513 591
 			}
514
-			if ($custom != '') $custom = ' '.$custom;
592
+			if ($custom != '') {
593
+				$custom = ' '.$custom;
594
+			}
515 595
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
516 596
 		}
517 597
 	}
@@ -529,26 +609,38 @@  discard block
 block discarded – undo
529 609
 			//$w = '00';
530 610
 			$custom = '';
531 611
 			if ($ident != '') {
532
-				if ($custom != '') $custom .= '/';
612
+				if ($custom != '') {
613
+					$custom .= '/';
614
+				}
533 615
 				$custom .= 'CS='.$ident;
534 616
 			}
535 617
 			if ($typeid != '') {
536
-				if ($custom != '') $custom .= '/';
618
+				if ($custom != '') {
619
+					$custom .= '/';
620
+				}
537 621
 				$custom .= 'TI='.$typeid;
538 622
 			}
539 623
 			if ($imo != '') {
540
-				if ($custom != '') $custom .= '/';
624
+				if ($custom != '') {
625
+					$custom .= '/';
626
+				}
541 627
 				$custom .= 'IMO='.$imo;
542 628
 			}
543 629
 			if ($arrival_date != '') {
544
-				if ($custom != '') $custom .= '/';
630
+				if ($custom != '') {
631
+					$custom .= '/';
632
+				}
545 633
 				$custom .= 'AD='.strtotime($arrival_date);
546 634
 			}
547 635
 			if ($arrival_code != '') {
548
-				if ($custom != '') $custom .= '/';
636
+				if ($custom != '') {
637
+					$custom .= '/';
638
+				}
549 639
 				$custom .= 'AC='.$arrival_code;
550 640
 			}
551
-			if ($custom != '') $custom = ' '.$custom;
641
+			if ($custom != '') {
642
+				$custom = ' '.$custom;
643
+			}
552 644
 			$altitude = 0;
553 645
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
554 646
 		}
Please login to merge, or discard this patch.