Completed
Push — master ( 3d34c0...2806fa )
by Yannick
11:43
created
scripts/daemon-spotter.php 1 patch
Braces   +920 added lines, -316 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,35 +58,62 @@  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']);
63
-}
68
+    if (isset($options['format'])) {
69
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
70
+    } else {
71
+    	$globalSources[] = array('host' => $options['source']);
72
+    }
73
+    }
64 74
 if (isset($options['aprsserverhost'])) {
65 75
 	$globalServerAPRS = TRUE;
66 76
 	$globalServerAPRShost = $options['aprsserverhost'];
67 77
 }
68
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
69
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
70
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
71
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
72
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
73
-if (isset($options['server'])) $globalServer = TRUE;
74
-if (isset($options['idsource'])) $id_source = $options['idsource'];
75
-else $id_source = 1;
78
+if (isset($options['aprsserverport'])) {
79
+	$globalServerAPRSport = $options['aprsserverport'];
80
+}
81
+if (isset($options['aprsserverssid'])) {
82
+	$globalServerAPRSssid = $options['aprsserverssid'];
83
+}
84
+if (isset($options['aprsserverpass'])) {
85
+	$globalServerAPRSpass = $options['aprsserverpass'];
86
+}
87
+if (isset($options['noaprsserver'])) {
88
+	$globalServerAPRS = FALSE;
89
+}
90
+if (isset($options['nodaemon'])) {
91
+	$globalDaemon = FALSE;
92
+}
93
+if (isset($options['server'])) {
94
+	$globalServer = TRUE;
95
+}
96
+if (isset($options['idsource'])) {
97
+	$id_source = $options['idsource'];
98
+} else {
99
+	$id_source = 1;
100
+}
76 101
 if (isset($globalServer) && $globalServer) {
77
-    if ($globalDebug) echo "Using Server Mode\n";
102
+    if ($globalDebug) {
103
+    	echo "Using Server Mode\n";
104
+    }
78 105
     $SI=new SpotterServer();
79 106
 /*
80 107
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
81 108
     $SI = new adsb2aprs();
82 109
     $SI->connect();
83 110
 */
84
-} else $SI=new SpotterImport($Connection->db);
85
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
111
+} else {
112
+	$SI=new SpotterImport($Connection->db);
113
+}
114
+if (isset($globalTracker) && $globalTracker) {
115
+	$TI = new TrackerImport($Connection->db);
116
+}
86 117
 if (isset($globalMarine) && $globalMarine) {
87 118
     $AIS = new AIS();
88 119
     $MI = new MarineImport($Connection->db);
@@ -104,7 +135,9 @@  discard block
 block discarded – undo
104 135
 }
105 136
 
106 137
 // let's try and connect
107
-if ($globalDebug) echo "Connecting...\n";
138
+if ($globalDebug) {
139
+	echo "Connecting...\n";
140
+}
108 141
 $use_aprs = false;
109 142
 $aprs_full = false;
110 143
 $reset = 0;
@@ -113,7 +146,9 @@  discard block
 block discarded – undo
113 146
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114 147
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115 148
     $reset++;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
149
+    if ($globalDebug) {
150
+    	echo 'Connect to all...'."\n";
151
+    }
117 152
     foreach ($hosts as $id => $value) {
118 153
 	$host = $value['host'];
119 154
 	$globalSources[$id]['last_exec'] = 0;
@@ -123,27 +158,37 @@  discard block
 block discarded – undo
123 158
         	//$formats[$id] = 'deltadbtxt';
124 159
         	$globalSources[$id]['format'] = 'deltadbtxt';
125 160
         	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
161
+        	if ($globalDebug) {
162
+        		echo "Connect to deltadb source (".$host.")...\n";
163
+        	}
127 164
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128 165
         	//$formats[$id] = 'vatsimtxt';
129 166
         	$globalSources[$id]['format'] = 'vatsimtxt';
130 167
         	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
168
+        	if ($globalDebug) {
169
+        		echo "Connect to vatsim source (".$host.")...\n";
170
+        	}
132 171
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133 172
         	//$formats[$id] = 'aircraftlistjson';
134 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
135 174
         	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
175
+        	if ($globalDebug) {
176
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
177
+        	}
137 178
     	    } else if (preg_match('/opensky/i',$host)) {
138 179
         	//$formats[$id] = 'aircraftlistjson';
139 180
         	$globalSources[$id]['format'] = 'opensky';
140 181
         	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
182
+        	if ($globalDebug) {
183
+        		echo "Connect to opensky source (".$host.")...\n";
184
+        	}
142 185
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143 186
         	//$formats[$id] = 'radarvirtueljson';
144 187
         	$globalSources[$id]['format'] = 'radarvirtueljson';
145 188
         	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
189
+        	if ($globalDebug) {
190
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
191
+        	}
147 192
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148 193
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149 194
         	    exit(0);
@@ -152,7 +197,9 @@  discard block
 block discarded – undo
152 197
         	//$formats[$id] = 'planeupdatefaa';
153 198
         	$globalSources[$id]['format'] = 'planeupdatefaa';
154 199
         	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
200
+        	if ($globalDebug) {
201
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
202
+        	}
156 203
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157 204
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158 205
         	    exit(0);
@@ -161,26 +208,36 @@  discard block
 block discarded – undo
161 208
         	//$formats[$id] = 'phpvmacars';
162 209
         	$globalSources[$id]['format'] = 'phpvmacars';
163 210
         	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to phpvmacars source (".$host.")...\n";
213
+        	}
165 214
             } else if (preg_match('/VAM-json.php$/i',$host)) {
166 215
         	//$formats[$id] = 'phpvmacars';
167 216
         	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
217
+        	if ($globalDebug) {
218
+        		echo "Connect to Vam source (".$host.")...\n";
219
+        	}
169 220
             } else if (preg_match('/whazzup/i',$host)) {
170 221
         	//$formats[$id] = 'whazzup';
171 222
         	$globalSources[$id]['format'] = 'whazzup';
172 223
         	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
224
+        	if ($globalDebug) {
225
+        		echo "Connect to whazzup source (".$host.")...\n";
226
+        	}
174 227
             } else if (preg_match('/recentpireps/i',$host)) {
175 228
         	//$formats[$id] = 'pirepsjson';
176 229
         	$globalSources[$id]['format'] = 'pirepsjson';
177 230
         	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
231
+        	if ($globalDebug) {
232
+        		echo "Connect to pirepsjson source (".$host.")...\n";
233
+        	}
179 234
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180 235
         	//$formats[$id] = 'fr24json';
181 236
         	$globalSources[$id]['format'] = 'fr24json';
182 237
         	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
238
+        	if ($globalDebug) {
239
+        		echo "Connect to fr24 source (".$host.")...\n";
240
+        	}
184 241
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185 242
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186 243
         	    exit(0);
@@ -189,7 +246,9 @@  discard block
 block discarded – undo
189 246
         	//$formats[$id] = 'fr24json';
190 247
         	$globalSources[$id]['format'] = 'myshiptracking';
191 248
         	//$last_exec['fr24json'] = 0;
192
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
249
+        	if ($globalDebug) {
250
+        		echo "Connect to myshiptracking source (".$host.")...\n";
251
+        	}
193 252
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194 253
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195 254
         	    exit(0);
@@ -198,17 +257,24 @@  discard block
 block discarded – undo
198 257
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199 258
         	//$formats[$id] = 'tsv';
200 259
         	$globalSources[$id]['format'] = 'tsv';
201
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
260
+        	if ($globalDebug) {
261
+        		echo "Connect to tsv source (".$host.")...\n";
262
+        	}
202 263
             }
203 264
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204 265
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205 266
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
206 267
     		    if ($idf !== false) {
207 268
     			$httpfeeds[$id] = $idf;
208
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
269
+        		if ($globalDebug) {
270
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
271
+        		}
272
+    		    } elseif ($globalDebug) {
273
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
209 274
     		    }
210
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
+    		} elseif ($globalDebug) {
276
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
277
+    		}
212 278
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213 279
 	    $hostport = explode(':',$host);
214 280
 	    if (isset($hostport[1])) {
@@ -248,17 +314,25 @@  discard block
 block discarded – undo
248 314
         		//$formats[$id] = 'beast';
249 315
         		$globalSources[$id]['format'] = 'beast';
250 316
 		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
317
+		    } else {
318
+		    	$globalSources[$id]['format'] = 'sbs';
319
+		    }
252 320
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 321
 		}
254
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
322
+		if ($globalDebug) {
323
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
324
+		}
255 325
             } else {
256
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
326
+		if ($globalDebug) {
327
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
328
+		}
257 329
     	    }
258 330
         }
259 331
     }
260 332
 }
261
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
333
+if (!isset($globalMinFetch)) {
334
+	$globalMinFetch = 15;
335
+}
262 336
 
263 337
 // Initialize all
264 338
 $status = array();
@@ -267,13 +341,19 @@  discard block
 block discarded – undo
267 341
 $formats = array();
268 342
 $last_exec = array();
269 343
 $time = time();
270
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
271
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272
-else $timeout = 20;
344
+if (isset($globalSourcesTimeout)) {
345
+	$timeout = $globalSourcesTimeOut;
346
+} else if (isset($globalSBS1TimeOut)) {
347
+	$timeout = $globalSBS1TimeOut;
348
+} else {
349
+	$timeout = 20;
350
+}
273 351
 $errno = '';
274 352
 $errstr='';
275 353
 
276
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
354
+if (!isset($globalDaemon)) {
355
+	$globalDaemon = TRUE;
356
+}
277 357
 /* Initiate connections to all the hosts simultaneously */
278 358
 //connect_all($hosts);
279 359
 //connect_all($globalSources);
@@ -299,7 +379,9 @@  discard block
 block discarded – undo
299 379
     if (isset($source['format']) && $source['format'] == 'aprs') {
300 380
 	$aprs_connect = 0;
301 381
 	$use_aprs = true;
302
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
382
+	if (isset($source['port']) && $source['port'] == '10152') {
383
+		$aprs_full = true;
384
+	}
303 385
 	break;
304 386
     }
305 387
 }
@@ -310,25 +392,48 @@  discard block
 block discarded – undo
310 392
 	$aprs_connect = 0;
311 393
 	$aprs_keep = 120;
312 394
 	$aprs_last_tx = time();
313
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
314
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
315
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
316
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
317
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
318
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
319
-	if ($aprs_full) $aprs_filter = '';
320
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
321
-	else $aprs_pass = '-1';
395
+	if (isset($globalAPRSversion)) {
396
+		$aprs_version = $globalAPRSversion;
397
+	} else {
398
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
399
+	}
400
+	if (isset($globalAPRSssid)) {
401
+		$aprs_ssid = $globalAPRSssid;
402
+	} else {
403
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
404
+	}
405
+	if (isset($globalAPRSfilter)) {
406
+		$aprs_filter = $globalAPRSfilter;
407
+	} else {
408
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
409
+	}
410
+	if ($aprs_full) {
411
+		$aprs_filter = '';
412
+	}
413
+	if (isset($globalAPRSpass)) {
414
+		$aprs_pass = $globalAPRSpass;
415
+	} else {
416
+		$aprs_pass = '-1';
417
+	}
322 418
 
323
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
324
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
325
-}
419
+	if ($aprs_filter != '') {
420
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
421
+	} else {
422
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
423
+	}
424
+	}
326 425
 
327 426
 // connected - lets do some work
328
-if ($globalDebug) echo "Connected!\n";
427
+if ($globalDebug) {
428
+	echo "Connected!\n";
429
+}
329 430
 sleep(1);
330
-if ($globalDebug) echo "SCAN MODE \n\n";
331
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
431
+if ($globalDebug) {
432
+	echo "SCAN MODE \n\n";
433
+}
434
+if (!isset($globalCronEnd)) {
435
+	$globalCronEnd = 60;
436
+}
332 437
 $endtime = time()+$globalCronEnd;
333 438
 $i = 1;
334 439
 $tt = array();
@@ -342,10 +447,14 @@  discard block
 block discarded – undo
342 447
 
343 448
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
344 449
 while ($i > 0) {
345
-    if (!$globalDaemon) $i = $endtime-time();
450
+    if (!$globalDaemon) {
451
+    	$i = $endtime-time();
452
+    }
346 453
     // Delete old ATC
347 454
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
348
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
455
+	if ($globalDebug) {
456
+		echo 'Delete old ATC...'."\n";
457
+	}
349 458
         $ATC->deleteOldATC();
350 459
     }
351 460
     
@@ -353,10 +462,14 @@  discard block
 block discarded – undo
353 462
     if (count($last_exec) == count($globalSources)) {
354 463
 	$max = $globalMinFetch;
355 464
 	foreach ($last_exec as $last) {
356
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
465
+	    if ((time() - $last['last']) < $max) {
466
+	    	$max = time() - $last['last'];
467
+	    }
357 468
 	}
358 469
 	if ($max != $globalMinFetch) {
359
-	    if ($globalDebug) echo 'Sleeping...'."\n";
470
+	    if ($globalDebug) {
471
+	    	echo 'Sleeping...'."\n";
472
+	    }
360 473
 	    sleep($globalMinFetch-$max+2);
361 474
 	}
362 475
     }
@@ -365,11 +478,15 @@  discard block
 block discarded – undo
365 478
     //foreach ($formats as $id => $value) {
366 479
     foreach ($globalSources as $id => $value) {
367 480
 	date_default_timezone_set('UTC');
368
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
481
+	if (!isset($last_exec[$id]['last'])) {
482
+		$last_exec[$id]['last'] = 0;
483
+	}
369 484
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
370 485
 	    //$buffer = $Common->getData($hosts[$id]);
371 486
 	    $buffer = $Common->getData($value['host']);
372
-	    if ($buffer != '') $reset = 0;
487
+	    if ($buffer != '') {
488
+	    	$reset = 0;
489
+	    }
373 490
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374 491
 	    $buffer = explode('\n',$buffer);
375 492
 	    foreach ($buffer as $line) {
@@ -378,20 +495,41 @@  discard block
 block discarded – undo
378 495
 	            $data = array();
379 496
 	            $data['hex'] = $line[1]; // hex
380 497
 	            $data['ident'] = $line[2]; // ident
381
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
498
+	            if (isset($line[3])) {
499
+	            	$data['altitude'] = $line[3];
500
+	            }
501
+	            // altitude
502
+	            if (isset($line[4])) {
503
+	            	$data['speed'] = $line[4];
504
+	            }
505
+	            // speed
506
+	            if (isset($line[5])) {
507
+	            	$data['heading'] = $line[5];
508
+	            }
509
+	            // heading
510
+	            if (isset($line[6])) {
511
+	            	$data['latitude'] = $line[6];
512
+	            }
513
+	            // lat
514
+	            if (isset($line[7])) {
515
+	            	$data['longitude'] = $line[7];
516
+	            }
517
+	            // long
386 518
 	            $data['verticalrate'] = ''; // vertical rate
387 519
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388 520
 	            $data['emergency'] = ''; // emergency
389 521
 		    $data['datetime'] = date('Y-m-d H:i:s');
390 522
 		    $data['format_source'] = 'deltadbtxt';
391 523
     		    $data['id_source'] = $id_source;
392
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
524
+		    if (isset($value['name']) && $value['name'] != '') {
525
+		    	$data['source_name'] = $value['name'];
526
+		    }
527
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
528
+		    	$data['noarchive'] = true;
529
+		    }
530
+		    if (isset($value['sourcestats'])) {
531
+		    	$data['sourcestats'] = $value['sourcestats'];
532
+		    }
395 533
     		    $SI->add($data);
396 534
 		    unset($data);
397 535
     		}
@@ -401,7 +539,9 @@  discard block
 block discarded – undo
401 539
 	    date_default_timezone_set('CET');
402 540
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403 541
 	    date_default_timezone_set('UTC');
404
-	    if ($buffer != '') $reset = 0;
542
+	    if ($buffer != '') {
543
+	    	$reset = 0;
544
+	    }
405 545
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406 546
 	    $buffer = explode('\n',$buffer);
407 547
 	    foreach ($buffer as $line) {
@@ -410,16 +550,36 @@  discard block
 block discarded – undo
410 550
 		    $add = false;
411 551
 		    $ais_data = $AIS->parse_line(trim($line));
412 552
 		    $data = array();
413
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
553
+		    if (isset($ais_data['ident'])) {
554
+		    	$data['ident'] = $ais_data['ident'];
555
+		    }
556
+		    if (isset($ais_data['mmsi'])) {
557
+		    	$data['mmsi'] = $ais_data['mmsi'];
558
+		    }
559
+		    if (isset($ais_data['speed'])) {
560
+		    	$data['speed'] = $ais_data['speed'];
561
+		    }
562
+		    if (isset($ais_data['heading'])) {
563
+		    	$data['heading'] = $ais_data['heading'];
564
+		    }
565
+		    if (isset($ais_data['latitude'])) {
566
+		    	$data['latitude'] = $ais_data['latitude'];
567
+		    }
568
+		    if (isset($ais_data['longitude'])) {
569
+		    	$data['longitude'] = $ais_data['longitude'];
570
+		    }
571
+		    if (isset($ais_data['status'])) {
572
+		    	$data['status'] = $ais_data['status'];
573
+		    }
574
+		    if (isset($ais_data['type'])) {
575
+		    	$data['type'] = $ais_data['type'];
576
+		    }
577
+		    if (isset($ais_data['imo'])) {
578
+		    	$data['imo'] = $ais_data['imo'];
579
+		    }
580
+		    if (isset($ais_data['callsign'])) {
581
+		    	$data['callsign'] = $ais_data['callsign'];
582
+		    }
423 583
 		    if (isset($ais_data['timestamp'])) {
424 584
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
425 585
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -434,8 +594,12 @@  discard block
 block discarded – undo
434 594
     		    $data['id_source'] = $id_source;
435 595
 		    //print_r($data);
436 596
 		    echo 'Add...'."\n";
437
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
438
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
597
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
598
+		    	$data['noarchive'] = true;
599
+		    }
600
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
601
+		    	$MI->add($data);
602
+		    }
439 603
 		    unset($data);
440 604
 		}
441 605
     	    }
@@ -455,20 +619,48 @@  discard block
 block discarded – undo
455 619
 			    if ($line != '') {
456 620
 				$ais_data = $AIS->parse_line(trim($line));
457 621
 				$data = array();
458
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
459
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
460
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
461
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
462
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
463
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
464
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
465
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
466
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
467
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
468
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
469
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
470
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
471
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
622
+				if (isset($ais_data['ident'])) {
623
+					$data['ident'] = $ais_data['ident'];
624
+				}
625
+				if (isset($ais_data['mmsi'])) {
626
+					$data['mmsi'] = $ais_data['mmsi'];
627
+				}
628
+				if (isset($ais_data['speed'])) {
629
+					$data['speed'] = $ais_data['speed'];
630
+				}
631
+				if (isset($ais_data['heading'])) {
632
+					$data['heading'] = $ais_data['heading'];
633
+				}
634
+				if (isset($ais_data['latitude'])) {
635
+					$data['latitude'] = $ais_data['latitude'];
636
+				}
637
+				if (isset($ais_data['longitude'])) {
638
+					$data['longitude'] = $ais_data['longitude'];
639
+				}
640
+				if (isset($ais_data['status'])) {
641
+					$data['status'] = $ais_data['status'];
642
+				}
643
+				if (isset($ais_data['statusid'])) {
644
+					$data['status_id'] = $ais_data['statusid'];
645
+				}
646
+				if (isset($ais_data['type'])) {
647
+					$data['type'] = $ais_data['type'];
648
+				}
649
+				if (isset($ais_data['typeid'])) {
650
+					$data['type_id'] = $ais_data['typeid'];
651
+				}
652
+				if (isset($ais_data['imo'])) {
653
+					$data['imo'] = $ais_data['imo'];
654
+				}
655
+				if (isset($ais_data['callsign'])) {
656
+					$data['callsign'] = $ais_data['callsign'];
657
+				}
658
+				if (isset($ais_data['destination'])) {
659
+					$data['arrival_code'] = $ais_data['destination'];
660
+				}
661
+				if (isset($ais_data['eta_ts'])) {
662
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
663
+				}
472 664
 				if (isset($ais_data['timestamp'])) {
473 665
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
474 666
 				} else {
@@ -476,16 +668,23 @@  discard block
 block discarded – undo
476 668
 				}
477 669
 				$data['format_source'] = 'aisnmeahttp';
478 670
 				$data['id_source'] = $id_source;
479
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
480
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
671
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
672
+					$data['noarchive'] = true;
673
+				}
674
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
675
+					$MI->add($data);
676
+				}
481 677
 				unset($data);
482 678
 			    }
483 679
 			}
484 680
 		    }
485 681
 		} else {
486 682
 		    $format = $value['format'];
487
-		    if (isset($tt[$format])) $tt[$format]++;
488
-		    else $tt[$format] = 0;
683
+		    if (isset($tt[$format])) {
684
+		    	$tt[$format]++;
685
+		    } else {
686
+		    	$tt[$format] = 0;
687
+		    }
489 688
 		    if ($tt[$format] > 30) {
490 689
 			sleep(2);
491 690
 			$sourceeen[] = $value;
@@ -516,7 +715,9 @@  discard block
 block discarded – undo
516 715
 			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
517 716
 			$data['format_source'] = 'myshiptracking';
518 717
 			$data['id_source'] = $id_source;
519
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
718
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
719
+				$data['noarchive'] = true;
720
+			}
520 721
 			$MI->add($data);
521 722
 			unset($data);
522 723
 		    }
@@ -537,7 +738,9 @@  discard block
 block discarded – undo
537 738
 			    $data['callsign'] = $line['callsign'];
538 739
 			    $data['mmsi'] = $line['mmsi'];
539 740
 			    $data['speed'] = $line['sog'];
540
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
741
+			    if ($line['heading'] != '511') {
742
+			    	$data['heading'] = $line['heading'];
743
+			    }
541 744
 			    $data['latitude'] = $line['latitude'];
542 745
 			    $data['longitude'] = $line['longitude'];
543 746
 			    $data['type_id'] = $line['shiptype'];
@@ -545,7 +748,9 @@  discard block
 block discarded – undo
545 748
 			    $data['datetime'] = $line['time'];
546 749
 			    $data['format_source'] = 'boatbeaconapp';
547 750
 			    $data['id_source'] = $id_source;
548
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
751
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
752
+			    	$data['noarchive'] = true;
753
+			    }
549 754
 			    $MI->add($data);
550 755
 			    unset($data);
551 756
 			}
@@ -558,7 +763,9 @@  discard block
 block discarded – undo
558 763
 	    echo 'download...';
559 764
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
560 765
 	    echo 'done !'."\n";
561
-	    if ($buffer != '') $reset = 0;
766
+	    if ($buffer != '') {
767
+	    	$reset = 0;
768
+	    }
562 769
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563 770
 	    $buffer = explode('\n',$buffer);
564 771
 	    foreach ($buffer as $line) {
@@ -583,7 +790,9 @@  discard block
 block discarded – undo
583 790
 		    //$data['etaTime'] = substr($line,135,5);
584 791
 		    $data['format_source'] = 'shipplotter';
585 792
     		    $data['id_source'] = $id_source;
586
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
793
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
794
+		    	$data['noarchive'] = true;
795
+		    }
587 796
 		    //print_r($data);
588 797
 		    echo 'Add...'."\n";
589 798
 		    $MI->add($data);
@@ -603,16 +812,28 @@  discard block
 block discarded – undo
603 812
     		    $line = explode(':', $line);
604 813
     		    if (count($line) > 30 && $line[0] != 'callsign') {
605 814
 			$data = array();
606
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
607
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
815
+			if (isset($line[37]) && $line[37] != '') {
816
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
817
+			} else {
818
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
819
+			}
608 820
 			$data['pilot_id'] = $line[1];
609 821
 			$data['pilot_name'] = $line[2];
610 822
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
611 823
 			$data['ident'] = $line[0]; // ident
612
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
824
+			if ($line[7] != '' && $line[7] != 0) {
825
+				$data['altitude'] = $line[7];
826
+			}
827
+			// altitude
613 828
 			$data['speed'] = $line[8]; // speed
614
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
615
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
829
+			if (isset($line[45])) {
830
+				$data['heading'] = $line[45];
831
+			}
832
+			// heading
833
+			elseif (isset($line[38])) {
834
+				$data['heading'] = $line[38];
835
+			}
836
+			// heading
616 837
 			$data['latitude'] = $line[5]; // lat
617 838
 	        	$data['longitude'] = $line[6]; // long
618 839
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -628,7 +849,9 @@  discard block
 block discarded – undo
628 849
 			$data['frequency'] = $line[4];
629 850
 			$data['type'] = $line[18];
630 851
 			$data['range'] = $line[19];
631
-			if (isset($line[35])) $data['info'] = $line[35];
852
+			if (isset($line[35])) {
853
+				$data['info'] = $line[35];
854
+			}
632 855
     			$data['id_source'] = $id_source;
633 856
 	    		//$data['arrival_airport_time'] = ;
634 857
 	    		if ($line[9] != '') {
@@ -642,25 +865,44 @@  discard block
 block discarded – undo
642 865
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
643 866
 	    		*/
644 867
 	    		$data['format_source'] = $value['format'];
645
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
646
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
647
-    			if ($line[3] == 'PILOT') $SI->add($data);
648
-			elseif ($line[3] == 'ATC') {
868
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
869
+				$data['noarchive'] = true;
870
+			}
871
+			if (isset($value['name']) && $value['name'] != '') {
872
+				$data['source_name'] = $value['name'];
873
+			}
874
+    			if ($line[3] == 'PILOT') {
875
+    				$SI->add($data);
876
+    			} elseif ($line[3] == 'ATC') {
649 877
 				//print_r($data);
650 878
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
651 879
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
652 880
 				$typec = substr($data['ident'],-3);
653
-				if ($typec == 'APP') $data['type'] = 'Approach';
654
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
655
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
656
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
657
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
658
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
659
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
660
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
661
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
662
-				if (!isset($data['source_name'])) $data['source_name'] = '';
663
-				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']);
881
+				if ($typec == 'APP') {
882
+					$data['type'] = 'Approach';
883
+				} elseif ($typec == 'TWR') {
884
+					$data['type'] = 'Tower';
885
+				} elseif ($typec == 'OBS') {
886
+					$data['type'] = 'Observer';
887
+				} elseif ($typec == 'GND') {
888
+					$data['type'] = 'Ground';
889
+				} elseif ($typec == 'DEL') {
890
+					$data['type'] = 'Delivery';
891
+				} elseif ($typec == 'DEP') {
892
+					$data['type'] = 'Departure';
893
+				} elseif ($typec == 'FSS') {
894
+					$data['type'] = 'Flight Service Station';
895
+				} elseif ($typec == 'CTR') {
896
+					$data['type'] = 'Control Radar or Centre';
897
+				} elseif ($data['type'] == '') {
898
+					$data['type'] = 'Observer';
899
+				}
900
+				if (!isset($data['source_name'])) {
901
+					$data['source_name'] = '';
902
+				}
903
+				if (isset($ATC)) {
904
+					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']);
905
+				}
664 906
 			}
665 907
     			unset($data);
666 908
     		    }
@@ -679,27 +921,61 @@  discard block
 block discarded – undo
679 921
 		foreach ($all_data['acList'] as $line) {
680 922
 		    $data = array();
681 923
 		    $data['hex'] = $line['Icao']; // hex
682
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
683
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
684
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
685
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
686
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
687
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
924
+		    if (isset($line['Call'])) {
925
+		    	$data['ident'] = $line['Call'];
926
+		    }
927
+		    // ident
928
+		    if (isset($line['Alt'])) {
929
+		    	$data['altitude'] = $line['Alt'];
930
+		    }
931
+		    // altitude
932
+		    if (isset($line['Spd'])) {
933
+		    	$data['speed'] = $line['Spd'];
934
+		    }
935
+		    // speed
936
+		    if (isset($line['Trak'])) {
937
+		    	$data['heading'] = $line['Trak'];
938
+		    }
939
+		    // heading
940
+		    if (isset($line['Lat'])) {
941
+		    	$data['latitude'] = $line['Lat'];
942
+		    }
943
+		    // lat
944
+		    if (isset($line['Long'])) {
945
+		    	$data['longitude'] = $line['Long'];
946
+		    }
947
+		    // long
688 948
 		    //$data['verticalrate'] = $line['']; // verticale rate
689
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
949
+		    if (isset($line['Sqk'])) {
950
+		    	$data['squawk'] = $line['Sqk'];
951
+		    }
952
+		    // squawk
690 953
 		    $data['emergency'] = ''; // emergency
691
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
954
+		    if (isset($line['Reg'])) {
955
+		    	$data['registration'] = $line['Reg'];
956
+		    }
692 957
 		    
693
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
694
-		    else $data['datetime'] = date('Y-m-d H:i:s');
958
+		    if (isset($line['PosTime'])) {
959
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
960
+		    } else {
961
+		    	$data['datetime'] = date('Y-m-d H:i:s');
962
+		    }
695 963
 		    
696 964
 		    //$data['datetime'] = date('Y-m-d H:i:s');
697
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
965
+		    if (isset($line['Type'])) {
966
+		    	$data['aircraft_icao'] = $line['Type'];
967
+		    }
698 968
 	    	    $data['format_source'] = 'aircraftlistjson';
699 969
 		    $data['id_source'] = $id_source;
700
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
701
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-		    if (isset($data['latitude'])) $SI->add($data);
970
+		    if (isset($value['name']) && $value['name'] != '') {
971
+		    	$data['source_name'] = $value['name'];
972
+		    }
973
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
974
+		    	$data['noarchive'] = true;
975
+		    }
976
+		    if (isset($data['latitude'])) {
977
+		    	$SI->add($data);
978
+		    }
703 979
 		    unset($data);
704 980
 		}
705 981
 	    } elseif (is_array($all_data)) {
@@ -716,12 +992,19 @@  discard block
 block discarded – undo
716 992
 		    $data['verticalrate'] = $line['vrt']; // verticale rate
717 993
 		    $data['squawk'] = $line['squawk']; // squawk
718 994
 		    $data['emergency'] = ''; // emergency
719
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
720
-		    else $data['datetime'] = date('Y-m-d H:i:s');
995
+		    if (isset($line['PosTime'])) {
996
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
997
+		    } else {
998
+		    	$data['datetime'] = date('Y-m-d H:i:s');
999
+		    }
721 1000
 	    	    $data['format_source'] = 'aircraftlistjson';
722 1001
     		    $data['id_source'] = $id_source;
723
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
724
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1002
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1003
+		    	$data['noarchive'] = true;
1004
+		    }
1005
+		    if (isset($value['name']) && $value['name'] != '') {
1006
+		    	$data['source_name'] = $value['name'];
1007
+		    }
725 1008
 		    $SI->add($data);
726 1009
 		    unset($data);
727 1010
 		}
@@ -757,8 +1040,12 @@  discard block
 block discarded – undo
757 1040
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
758 1041
 	    	    $data['format_source'] = 'planeupdatefaa';
759 1042
     		    $data['id_source'] = $id_source;
760
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
761
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1043
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1044
+		    	$data['noarchive'] = true;
1045
+		    }
1046
+		    if (isset($value['name']) && $value['name'] != '') {
1047
+		    	$data['source_name'] = $value['name'];
1048
+		    }
762 1049
 		    $SI->add($data);
763 1050
 		    unset($data);
764 1051
 		}
@@ -787,7 +1074,9 @@  discard block
 block discarded – undo
787 1074
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
788 1075
 	    	    $data['format_source'] = 'opensky';
789 1076
     		    $data['id_source'] = $id_source;
790
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1077
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1078
+		    	$data['noarchive'] = true;
1079
+		    }
791 1080
 		    $SI->add($data);
792 1081
 		    unset($data);
793 1082
 		}
@@ -799,7 +1088,9 @@  discard block
 block discarded – undo
799 1088
 	    //$buffer = $Common->getData($hosts[$id]);
800 1089
 	    $buffer = $Common->getData($value['host']);
801 1090
 	    $all_data = json_decode($buffer,true);
802
-	    if (!empty($all_data)) $reset = 0;
1091
+	    if (!empty($all_data)) {
1092
+	    	$reset = 0;
1093
+	    }
803 1094
 	    foreach ($all_data as $key => $line) {
804 1095
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
805 1096
 		    $data = array();
@@ -820,8 +1111,12 @@  discard block
 block discarded – undo
820 1111
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
821 1112
 	    	    $data['format_source'] = 'fr24json';
822 1113
     		    $data['id_source'] = $id_source;
823
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
824
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1114
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1115
+		    	$data['noarchive'] = true;
1116
+		    }
1117
+		    if (isset($value['name']) && $value['name'] != '') {
1118
+		    	$data['source_name'] = $value['name'];
1119
+		    }
825 1120
 		    $SI->add($data);
826 1121
 		    unset($data);
827 1122
 		}
@@ -845,24 +1140,42 @@  discard block
 block discarded – undo
845 1140
 		    if (isset($line['inf'])) {
846 1141
 			$data = array();
847 1142
 			$data['hex'] = $line['inf']['ia'];
848
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1143
+			if (isset($line['inf']['cs'])) {
1144
+				$data['ident'] = $line['inf']['cs'];
1145
+			}
1146
+			//$line[13]
849 1147
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
850
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
851
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1148
+	    		if (isset($line['inf']['gs'])) {
1149
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1150
+	    		}
1151
+	    		// speed
1152
+	    		if (isset($line['inf']['tr'])) {
1153
+	    			$data['heading'] = $line['inf']['tr'];
1154
+	    		}
1155
+	    		// heading
852 1156
 	    		$data['latitude'] = $line['pt'][0]; // lat
853 1157
 	    		$data['longitude'] = $line['pt'][1]; // long
854 1158
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
855
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1159
+	    		if (isset($line['inf']['sq'])) {
1160
+	    			$data['squawk'] = $line['inf']['sq'];
1161
+	    		}
1162
+	    		// squawk
856 1163
 	    		//$data['aircraft_icao'] = $line[8];
857
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1164
+	    		if (isset($line['inf']['rc'])) {
1165
+	    			$data['registration'] = $line['inf']['rc'];
1166
+	    		}
858 1167
 			//$data['departure_airport_iata'] = $line[11];
859 1168
 			//$data['arrival_airport_iata'] = $line[12];
860 1169
 	    		//$data['emergency'] = ''; // emergency
861 1170
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
862 1171
 	    		$data['format_source'] = 'radarvirtueljson';
863 1172
     			$data['id_source'] = $id_source;
864
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
865
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1173
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1174
+				$data['noarchive'] = true;
1175
+			}
1176
+			if (isset($value['name']) && $value['name'] != '') {
1177
+				$data['source_name'] = $value['name'];
1178
+			}
866 1179
 			$SI->add($data);
867 1180
 			unset($data);
868 1181
 		    }
@@ -883,30 +1196,65 @@  discard block
 block discarded – undo
883 1196
 		    $data['id'] = $line['id'];
884 1197
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
885 1198
 		    $data['ident'] = $line['callsign']; // ident
886
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
888
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
889
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
890
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
891
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1199
+		    if (isset($line['pilotid'])) {
1200
+		    	$data['pilot_id'] = $line['pilotid'];
1201
+		    }
1202
+		    // pilot id
1203
+		    if (isset($line['name'])) {
1204
+		    	$data['pilot_name'] = $line['name'];
1205
+		    }
1206
+		    // pilot name
1207
+		    if (isset($line['alt'])) {
1208
+		    	$data['altitude'] = $line['alt'];
1209
+		    }
1210
+		    // altitude
1211
+		    if (isset($line['gs'])) {
1212
+		    	$data['speed'] = $line['gs'];
1213
+		    }
1214
+		    // speed
1215
+		    if (isset($line['heading'])) {
1216
+		    	$data['heading'] = $line['heading'];
1217
+		    }
1218
+		    // heading
1219
+		    if (isset($line['route'])) {
1220
+		    	$data['waypoints'] = $line['route'];
1221
+		    }
1222
+		    // route
892 1223
 		    $data['latitude'] = $line['lat']; // lat
893 1224
 		    $data['longitude'] = $line['lon']; // long
894 1225
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
895 1226
 		    //$data['squawk'] = $line['squawk']; // squawk
896 1227
 		    //$data['emergency'] = ''; // emergency
897
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
898
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
899
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1228
+		    if (isset($line['depicao'])) {
1229
+		    	$data['departure_airport_icao'] = $line['depicao'];
1230
+		    }
1231
+		    if (isset($line['deptime'])) {
1232
+		    	$data['departure_airport_time'] = $line['deptime'];
1233
+		    }
1234
+		    if (isset($line['arricao'])) {
1235
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1236
+		    }
900 1237
 		    //$data['arrival_airport_time'] = $line['arrtime'];
901
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
902
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
903
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
904
-		    else $data['info'] = '';
1238
+		    if (isset($line['aircraft'])) {
1239
+		    	$data['aircraft_icao'] = $line['aircraft'];
1240
+		    }
1241
+		    if (isset($line['transponder'])) {
1242
+		    	$data['squawk'] = $line['transponder'];
1243
+		    }
1244
+		    if (isset($line['atis'])) {
1245
+		    	$data['info'] = $line['atis'];
1246
+		    } else {
1247
+		    	$data['info'] = '';
1248
+		    }
905 1249
 		    $data['format_source'] = 'pireps';
906 1250
     		    $data['id_source'] = $id_source;
907 1251
 		    $data['datetime'] = date('Y-m-d H:i:s');
908
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
909
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1252
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1253
+		    	$data['noarchive'] = true;
1254
+		    }
1255
+		    if (isset($value['name']) && $value['name'] != '') {
1256
+		    	$data['source_name'] = $value['name'];
1257
+		    }
910 1258
 		    if ($line['icon'] == 'plane') {
911 1259
 			$SI->add($data);
912 1260
 		    //    print_r($data);
@@ -915,16 +1263,28 @@  discard block
 block discarded – undo
915 1263
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
916 1264
 			$typec = substr($data['ident'],-3);
917 1265
 			$data['type'] = '';
918
-			if ($typec == 'APP') $data['type'] = 'Approach';
919
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
920
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
921
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
922
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
923
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
924
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
925
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
926
-			else $data['type'] = 'Observer';
927
-			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']);
1266
+			if ($typec == 'APP') {
1267
+				$data['type'] = 'Approach';
1268
+			} elseif ($typec == 'TWR') {
1269
+				$data['type'] = 'Tower';
1270
+			} elseif ($typec == 'OBS') {
1271
+				$data['type'] = 'Observer';
1272
+			} elseif ($typec == 'GND') {
1273
+				$data['type'] = 'Ground';
1274
+			} elseif ($typec == 'DEL') {
1275
+				$data['type'] = 'Delivery';
1276
+			} elseif ($typec == 'DEP') {
1277
+				$data['type'] = 'Departure';
1278
+			} elseif ($typec == 'FSS') {
1279
+				$data['type'] = 'Flight Service Station';
1280
+			} elseif ($typec == 'CTR') {
1281
+				$data['type'] = 'Control Radar or Centre';
1282
+			} else {
1283
+				$data['type'] = 'Observer';
1284
+			}
1285
+			if (isset($ATC)) {
1286
+				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']);
1287
+			}
928 1288
 		    }
929 1289
 		    unset($data);
930 1290
 		}
@@ -934,7 +1294,9 @@  discard block
 block discarded – undo
934 1294
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
935 1295
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
936 1296
 	    //$buffer = $Common->getData($hosts[$id]);
937
-	    if ($globalDebug) echo 'Get Data...'."\n";
1297
+	    if ($globalDebug) {
1298
+	    	echo 'Get Data...'."\n";
1299
+	    }
938 1300
 	    $buffer = $Common->getData($value['host']);
939 1301
 	    $all_data = json_decode($buffer,true);
940 1302
 	    if ($buffer != '' && is_array($all_data)) {
@@ -942,10 +1304,16 @@  discard block
 block discarded – undo
942 1304
 		foreach ($all_data as $line) {
943 1305
 	    	    $data = array();
944 1306
 	    	    //$data['id'] = $line['id']; // id not usable
945
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1307
+	    	    if (isset($line['pilotid'])) {
1308
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1309
+	    	    }
946 1310
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
947
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1311
+	    	    if (isset($line['pilotname'])) {
1312
+	    	    	$data['pilot_name'] = $line['pilotname'];
1313
+	    	    }
1314
+	    	    if (isset($line['pilotid'])) {
1315
+	    	    	$data['pilot_id'] = $line['pilotid'];
1316
+	    	    }
949 1317
 	    	    $data['ident'] = $line['flightnum']; // ident
950 1318
 	    	    $data['altitude'] = $line['alt']; // altitude
951 1319
 	    	    $data['speed'] = $line['gs']; // speed
@@ -963,28 +1331,44 @@  discard block
 block discarded – undo
963 1331
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
964 1332
     		    $data['arrival_airport_time'] = $line['arrtime'];
965 1333
     		    $data['registration'] = $line['aircraft'];
966
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
967
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1334
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1335
+		    	$data['noarchive'] = true;
1336
+		    }
1337
+		    if (isset($line['route'])) {
1338
+		    	$data['waypoints'] = $line['route'];
1339
+		    }
1340
+		    // route
968 1341
 		    if (isset($line['aircraftname'])) {
969 1342
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
970 1343
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
971 1344
 	    		$aircraft_data = explode('-',$line['aircraftname']);
972
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974
-	    		else {
1345
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1346
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1347
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1348
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1349
+	    		} else {
975 1350
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
976
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1351
+	    		    if (isset($aircraft_data[1])) {
1352
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1353
+	    		    } else {
1354
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1355
+	    		    }
978 1356
 	    		}
979 1357
 	    	    }
980
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1358
+    		    if (isset($line['route'])) {
1359
+    		    	$data['waypoints'] = $line['route'];
1360
+    		    }
981 1361
     		    $data['id_source'] = $id_source;
982 1362
 	    	    $data['format_source'] = 'phpvmacars';
983
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1363
+		    if (isset($value['name']) && $value['name'] != '') {
1364
+		    	$data['source_name'] = $value['name'];
1365
+		    }
984 1366
 		    $SI->add($data);
985 1367
 		    unset($data);
986 1368
 		}
987
-		if ($globalDebug) echo 'No more data...'."\n";
1369
+		if ($globalDebug) {
1370
+			echo 'No more data...'."\n";
1371
+		}
988 1372
 		unset($buffer);
989 1373
 		unset($all_data);
990 1374
 	    }
@@ -992,7 +1376,9 @@  discard block
 block discarded – undo
992 1376
     	    $last_exec[$id]['last'] = time();
993 1377
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
994 1378
 	    //$buffer = $Common->getData($hosts[$id]);
995
-	    if ($globalDebug) echo 'Get Data...'."\n";
1379
+	    if ($globalDebug) {
1380
+	    	echo 'Get Data...'."\n";
1381
+	    }
996 1382
 	    $buffer = $Common->getData($value['host']);
997 1383
 	    $all_data = json_decode($buffer,true);
998 1384
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1021,16 +1407,25 @@  discard block
 block discarded – undo
1021 1407
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1022 1408
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1023 1409
     		    //$data['registration'] = $line['aircraft'];
1024
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1410
+		    if (isset($line['route'])) {
1411
+		    	$data['waypoints'] = $line['route'];
1412
+		    }
1413
+		    // route
1025 1414
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1026 1415
     		    $data['id_source'] = $id_source;
1027 1416
 	    	    $data['format_source'] = 'vam';
1028
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1417
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1418
+		    	$data['noarchive'] = true;
1419
+		    }
1420
+		    if (isset($value['name']) && $value['name'] != '') {
1421
+		    	$data['source_name'] = $value['name'];
1422
+		    }
1030 1423
 		    $SI->add($data);
1031 1424
 		    unset($data);
1032 1425
 		}
1033
-		if ($globalDebug) echo 'No more data...'."\n";
1426
+		if ($globalDebug) {
1427
+			echo 'No more data...'."\n";
1428
+		}
1034 1429
 		unset($buffer);
1035 1430
 		unset($all_data);
1036 1431
 	    }
@@ -1038,7 +1433,9 @@  discard block
 block discarded – undo
1038 1433
     	    $last_exec[$id]['last'] = time();
1039 1434
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1040 1435
 	} 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') {
1041
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1436
+	    if (function_exists('pcntl_fork')) {
1437
+	    	pcntl_signal_dispatch();
1438
+	    }
1042 1439
     	    //$last_exec[$id]['last'] = time();
1043 1440
 
1044 1441
 	    //$read = array( $sockets[$id] );
@@ -1046,7 +1443,9 @@  discard block
 block discarded – undo
1046 1443
 	    $write = NULL;
1047 1444
 	    $e = NULL;
1048 1445
 	    $n = socket_select($read, $write, $e, $timeout);
1049
-	    if ($e != NULL) var_dump($e);
1446
+	    if ($e != NULL) {
1447
+	    	var_dump($e);
1448
+	    }
1050 1449
 	    if ($n > 0) {
1051 1450
 		$reset = 0;
1052 1451
 		foreach ($read as $nb => $r) {
@@ -1067,12 +1466,16 @@  discard block
 block discarded – undo
1067 1466
 		    //$SI::del();
1068 1467
 		    if ($format == 'vrstcp') {
1069 1468
 			$buffer = explode('},{',$buffer);
1070
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1469
+		    } else {
1470
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1471
+		    }
1071 1472
 		    // SBS format is CSV format
1072 1473
 		    if ($buffer !== FALSE && $buffer != '') {
1073 1474
 			$tt[$format] = 0;
1074 1475
 			if ($format == 'acarssbs3') {
1075
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1476
+			    if ($globalDebug) {
1477
+			    	echo 'ACARS : '.$buffer."\n";
1478
+			    }
1076 1479
 			    $ACARS->add(trim($buffer));
1077 1480
 			    $ACARS->deleteLiveAcarsData();
1078 1481
 			} elseif ($format == 'raw') {
@@ -1081,28 +1484,64 @@  discard block
 block discarded – undo
1081 1484
 			    if (is_array($data)) {
1082 1485
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1486
 				$data['format_source'] = 'raw';
1084
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1085
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1086
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1087
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1487
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1488
+					$data['source_name'] = $globalSources[$nb]['name'];
1489
+				}
1490
+				if (isset($globalSources[$nb]['sourcestats'])) {
1491
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1492
+				}
1493
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1494
+					$data['noarchive'] = true;
1495
+				}
1496
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1497
+					$SI->add($data);
1498
+				}
1088 1499
 			    }
1089 1500
 			} elseif ($format == 'ais') {
1090 1501
 			    $ais_data = $AIS->parse_line(trim($buffer));
1091 1502
 			    $data = array();
1092
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1093
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1094
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1095
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1096
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1097
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1098
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1099
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1100
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1101
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1105
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1503
+			    if (isset($ais_data['ident'])) {
1504
+			    	$data['ident'] = $ais_data['ident'];
1505
+			    }
1506
+			    if (isset($ais_data['mmsi'])) {
1507
+			    	$data['mmsi'] = $ais_data['mmsi'];
1508
+			    }
1509
+			    if (isset($ais_data['speed'])) {
1510
+			    	$data['speed'] = $ais_data['speed'];
1511
+			    }
1512
+			    if (isset($ais_data['heading'])) {
1513
+			    	$data['heading'] = $ais_data['heading'];
1514
+			    }
1515
+			    if (isset($ais_data['latitude'])) {
1516
+			    	$data['latitude'] = $ais_data['latitude'];
1517
+			    }
1518
+			    if (isset($ais_data['longitude'])) {
1519
+			    	$data['longitude'] = $ais_data['longitude'];
1520
+			    }
1521
+			    if (isset($ais_data['status'])) {
1522
+			    	$data['status'] = $ais_data['status'];
1523
+			    }
1524
+			    if (isset($ais_data['statusid'])) {
1525
+			    	$data['status_id'] = $ais_data['statusid'];
1526
+			    }
1527
+			    if (isset($ais_data['type'])) {
1528
+			    	$data['type'] = $ais_data['type'];
1529
+			    }
1530
+			    if (isset($ais_data['imo'])) {
1531
+			    	$data['imo'] = $ais_data['imo'];
1532
+			    }
1533
+			    if (isset($ais_data['callsign'])) {
1534
+			    	$data['callsign'] = $ais_data['callsign'];
1535
+			    }
1536
+			    if (isset($ais_data['destination'])) {
1537
+			    	$data['arrival_code'] = $ais_data['destination'];
1538
+			    }
1539
+			    if (isset($ais_data['eta_ts'])) {
1540
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1541
+			    }
1542
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1543
+			    	$data['noarchive'] = true;
1544
+			    }
1106 1545
 
1107 1546
 			    if (isset($ais_data['timestamp'])) {
1108 1547
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1111,7 +1550,9 @@  discard block
 block discarded – undo
1111 1550
 			    }
1112 1551
 			    $data['format_source'] = 'aisnmea';
1113 1552
     			    $data['id_source'] = $id_source;
1114
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1553
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1554
+			    	$MI->add($data);
1555
+			    }
1115 1556
 			    unset($data);
1116 1557
                         } elseif ($format == 'flightgearsp') {
1117 1558
                     	    //echo $buffer."\n";
@@ -1129,12 +1570,18 @@  discard block
 block discarded – undo
1129 1570
 				$data['speed'] = round($line[5]*1.94384);
1130 1571
 				$data['datetime'] = date('Y-m-d H:i:s');
1131 1572
 				$data['format_source'] = 'flightgearsp';
1132
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1133
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1573
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1574
+					$data['noarchive'] = true;
1575
+				}
1576
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1577
+					$SI->add($data);
1578
+				}
1134 1579
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1135 1580
 			    }
1136 1581
                         } elseif ($format == 'acars') {
1137
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1582
+                    	    if ($globalDebug) {
1583
+                    	    	echo 'ACARS : '.$buffer."\n";
1584
+                    	    }
1138 1585
 			    $ACARS->add(trim($buffer));
1139 1586
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1140 1587
 			    $ACARS->deleteLiveAcarsData();
@@ -1155,8 +1602,12 @@  discard block
 block discarded – undo
1155 1602
 				    $aircraft_type = $line[10];
1156 1603
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1157 1604
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1158
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1159
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1605
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1606
+				    	$data['noarchive'] = true;
1607
+				    }
1608
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1609
+				    	$SI->add($data);
1610
+				    }
1160 1611
 				}
1161 1612
 			    }
1162 1613
 			} elseif ($format == 'beast') {
@@ -1166,28 +1617,62 @@  discard block
 block discarded – undo
1166 1617
 			    foreach($buffer as $all_data) {
1167 1618
 				$line = json_decode('{'.$all_data.'}',true);
1168 1619
 				$data = array();
1169
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1170
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1171
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1172
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1173
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1174
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1175
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1620
+				if (isset($line['Icao'])) {
1621
+					$data['hex'] = $line['Icao'];
1622
+				}
1623
+				// hex
1624
+				if (isset($line['Call'])) {
1625
+					$data['ident'] = $line['Call'];
1626
+				}
1627
+				// ident
1628
+				if (isset($line['Alt'])) {
1629
+					$data['altitude'] = $line['Alt'];
1630
+				}
1631
+				// altitude
1632
+				if (isset($line['Spd'])) {
1633
+					$data['speed'] = $line['Spd'];
1634
+				}
1635
+				// speed
1636
+				if (isset($line['Trak'])) {
1637
+					$data['heading'] = $line['Trak'];
1638
+				}
1639
+				// heading
1640
+				if (isset($line['Lat'])) {
1641
+					$data['latitude'] = $line['Lat'];
1642
+				}
1643
+				// lat
1644
+				if (isset($line['Long'])) {
1645
+					$data['longitude'] = $line['Long'];
1646
+				}
1647
+				// long
1176 1648
 				//$data['verticalrate'] = $line['']; // verticale rate
1177
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1649
+				if (isset($line['Sqk'])) {
1650
+					$data['squawk'] = $line['Sqk'];
1651
+				}
1652
+				// squawk
1178 1653
 				$data['emergency'] = ''; // emergency
1179
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1654
+				if (isset($line['Reg'])) {
1655
+					$data['registration'] = $line['Reg'];
1656
+				}
1180 1657
 				/*
1181 1658
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1182 1659
 				else $data['datetime'] = date('Y-m-d H:i:s');
1183 1660
 				*/
1184 1661
 				$data['datetime'] = date('Y-m-d H:i:s');
1185
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1662
+				if (isset($line['Type'])) {
1663
+					$data['aircraft_icao'] = $line['Type'];
1664
+				}
1186 1665
 		    		$data['format_source'] = 'vrstcp';
1187 1666
 				$data['id_source'] = $id_source;
1188
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1189
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1190
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1667
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1668
+					$data['noarchive'] = true;
1669
+				}
1670
+				if (isset($value['name']) && $value['name'] != '') {
1671
+					$data['source_name'] = $value['name'];
1672
+				}
1673
+				if (isset($data['latitude']) && isset($data['hex'])) {
1674
+					$SI->add($data);
1675
+				}
1191 1676
 				unset($data);
1192 1677
 			    }
1193 1678
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1200,22 +1685,46 @@  discard block
 block discarded – undo
1200 1685
     				$data['hex'] = $lined['hexid'];
1201 1686
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1202 1687
     				$data['datetime'] = date('Y-m-d H:i:s');;
1203
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1204
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1205
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1206
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1207
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1208
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1209
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1688
+    				if (isset($lined['ident'])) {
1689
+    					$data['ident'] = $lined['ident'];
1690
+    				}
1691
+    				if (isset($lined['lat'])) {
1692
+    					$data['latitude'] = $lined['lat'];
1693
+    				}
1694
+    				if (isset($lined['lon'])) {
1695
+    					$data['longitude'] = $lined['lon'];
1696
+    				}
1697
+    				if (isset($lined['speed'])) {
1698
+    					$data['speed'] = $lined['speed'];
1699
+    				}
1700
+    				if (isset($lined['squawk'])) {
1701
+    					$data['squawk'] = $lined['squawk'];
1702
+    				}
1703
+    				if (isset($lined['alt'])) {
1704
+    					$data['altitude'] = $lined['alt'];
1705
+    				}
1706
+    				if (isset($lined['heading'])) {
1707
+    					$data['heading'] = $lined['heading'];
1708
+    				}
1210 1709
     				$data['id_source'] = $id_source;
1211 1710
     				$data['format_source'] = 'tsv';
1212
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1213
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1214
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1215
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1711
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1712
+    					$data['source_name'] = $globalSources[$nb]['name'];
1713
+    				}
1714
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1715
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1716
+    				}
1717
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1718
+					$data['noarchive'] = true;
1719
+				}
1720
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1721
+    					$SI->add($data);
1722
+    				}
1216 1723
     				unset($lined);
1217 1724
     				unset($data);
1218
-    			    } else $error = true;
1725
+    			    } else {
1726
+    			    	$error = true;
1727
+    			    }
1219 1728
 			} elseif ($format == 'aprs' && $use_aprs) {
1220 1729
 			    if ($aprs_connect == 0) {
1221 1730
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1240,37 +1749,81 @@  discard block
 block discarded – undo
1240 1749
 				    $aprs_last_tx = time();
1241 1750
 				    $data = array();
1242 1751
 				    //print_r($line);
1243
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1244
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1245
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1246
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1247
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1248
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1249
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1250
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1251
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1752
+				    if (isset($line['address'])) {
1753
+				    	$data['hex'] = $line['address'];
1754
+				    }
1755
+				    if (isset($line['mmsi'])) {
1756
+				    	$data['mmsi'] = $line['mmsi'];
1757
+				    }
1758
+				    if (isset($line['imo'])) {
1759
+				    	$data['imo'] = $line['imo'];
1760
+				    }
1761
+				    if (isset($line['arrival_code'])) {
1762
+				    	$data['arrical_code'] = $line['arrival_code'];
1763
+				    }
1764
+				    if (isset($line['arrival_date'])) {
1765
+				    	$data['arrical_date'] = $line['arrival_date'];
1766
+				    }
1767
+				    if (isset($line['type_id'])) {
1768
+				    	$data['type_id'] = $line['typeid'];
1769
+				    }
1770
+				    if (isset($line['status_id'])) {
1771
+				    	$data['status_id'] = $line['statusid'];
1772
+				    }
1773
+				    if (isset($line['timestamp'])) {
1774
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1775
+				    } else {
1776
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1777
+				    }
1252 1778
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1253
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1779
+				    if (isset($line['ident'])) {
1780
+				    	$data['ident'] = $line['ident'];
1781
+				    }
1254 1782
 				    $data['latitude'] = $line['latitude'];
1255 1783
 				    $data['longitude'] = $line['longitude'];
1256 1784
 				    //$data['verticalrate'] = $line[16];
1257
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1258
-				    else $data['speed'] = 0;
1259
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1260
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1261
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1262
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1785
+				    if (isset($line['speed'])) {
1786
+				    	$data['speed'] = $line['speed'];
1787
+				    } else {
1788
+				    	$data['speed'] = 0;
1789
+				    }
1790
+				    if (isset($line['altitude'])) {
1791
+				    	$data['altitude'] = $line['altitude'];
1792
+				    }
1793
+				    if (isset($line['comment'])) {
1794
+				    	$data['comment'] = $line['comment'];
1795
+				    }
1796
+				    if (isset($line['symbol'])) {
1797
+				    	$data['type'] = $line['symbol'];
1798
+				    }
1799
+				    if (isset($line['heading'])) {
1800
+				    	$data['heading'] = $line['heading'];
1801
+				    }
1263 1802
 				    //else $data['heading'] = 0;
1264
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1265
-				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1266
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1803
+				    if (isset($line['stealth'])) {
1804
+				    	$data['aircraft_type'] = $line['stealth'];
1805
+				    }
1806
+				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) {
1807
+				    	$data['noarchive'] = true;
1808
+				    }
1809
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1810
+				    	$data['noarchive'] = true;
1811
+				    }
1267 1812
     				    $data['id_source'] = $id_source;
1268
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1269
-				    else $data['format_source'] = 'aprs';
1813
+    				    if (isset($line['format_source'])) {
1814
+    				    	$data['format_source'] = $line['format_source'];
1815
+    				    } else {
1816
+				    	$data['format_source'] = 'aprs';
1817
+				    }
1270 1818
 				    $data['source_name'] = $line['source'];
1271
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1272
-				    else $data['source_type'] = 'flarm';
1273
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1819
+				    if (isset($line['source_type'])) {
1820
+				    	$data['source_type'] = $line['source_type'];
1821
+				    } else {
1822
+				    	$data['source_type'] = 'flarm';
1823
+				    }
1824
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1825
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1826
+    				    }
1274 1827
 				    $currentdate = date('Y-m-d H:i:s');
1275 1828
 				    $aprsdate = strtotime($data['datetime']);
1276 1829
 				    // Accept data if time <= system time + 20s
@@ -1281,19 +1834,22 @@  discard block
 block discarded – undo
1281 1834
 					echo 'add...'."\n";
1282 1835
 					$send = $MI->add($data);
1283 1836
 				    } elseif (isset($line['stealth'])) {
1284
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1285
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1837
+					if ($line['stealth'] != 0) {
1838
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1839
+					} else {
1840
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1841
+					}
1286 1842
 				    //} 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')) {
1287 1843
 				    } 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') {
1288 1844
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1289
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1845
+					if (isset($globalTracker) && $globalTracker) {
1846
+						$send = $TI->add($data);
1847
+					}
1290 1848
 				    }
1291 1849
 				    unset($data);
1292
-				} 
1293
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1850
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1294 1851
 					echo '!! Weather Station not yet supported'."\n";
1295
-				}
1296
-				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')) {
1852
+				} 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')) {
1297 1853
 					echo '!! Car & Trucks not yet supported'."\n";
1298 1854
 				}
1299 1855
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1326,26 +1882,45 @@  discard block
 block discarded – undo
1326 1882
     				$data['ground'] = $line[21];
1327 1883
     				$data['emergency'] = $line[19];
1328 1884
     				$data['format_source'] = 'sbs';
1329
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1330
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1331
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1885
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1886
+					$data['source_name'] = $globalSources[$nb]['name'];
1887
+				}
1888
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1889
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1890
+    				}
1891
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1892
+					$data['noarchive'] = true;
1893
+				}
1332 1894
     				$data['id_source'] = $id_source;
1333
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1334
-    				else $error = true;
1895
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1896
+    					$send = $SI->add($data);
1897
+    				} else {
1898
+    					$error = true;
1899
+    				}
1335 1900
     				unset($data);
1336
-    			    } else $error = true;
1901
+    			    } else {
1902
+    			    	$error = true;
1903
+    			    }
1337 1904
 			    if ($error) {
1338 1905
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1339
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1906
+					if ($globalDebug) {
1907
+						echo "Not a message. Ignoring... \n";
1908
+					}
1340 1909
 				} else {
1341
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1910
+					if ($globalDebug) {
1911
+						echo "Wrong line format. Ignoring... \n";
1912
+					}
1342 1913
 					if ($globalDebug) {
1343 1914
 						echo $buffer;
1344 1915
 						//print_r($line);
1345 1916
 					}
1346 1917
 					//socket_close($r);
1347
-					if ($globalDebug) echo "Reconnect after an error...\n";
1348
-					if ($format == 'aprs') $aprs_connect = 0;
1918
+					if ($globalDebug) {
1919
+						echo "Reconnect after an error...\n";
1920
+					}
1921
+					if ($format == 'aprs') {
1922
+						$aprs_connect = 0;
1923
+					}
1349 1924
 					$sourceer[$nb] = $globalSources[$nb];
1350 1925
 					connect_all($sourceer);
1351 1926
 					$sourceer = array();
@@ -1353,10 +1928,14 @@  discard block
 block discarded – undo
1353 1928
 			    }
1354 1929
 			}
1355 1930
 			// Sleep for xxx microseconds
1356
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1931
+			if (isset($globalSBSSleep)) {
1932
+				usleep($globalSBSSleep);
1933
+			}
1357 1934
 		    } else {
1358 1935
 			if ($format == 'flightgearmp') {
1359
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1936
+			    	if ($globalDebug) {
1937
+			    		echo "Reconnect FlightGear MP...";
1938
+			    	}
1360 1939
 				//@socket_close($r);
1361 1940
 				sleep($globalMinFetch);
1362 1941
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1365,10 +1944,15 @@  discard block
 block discarded – undo
1365 1944
 				break;
1366 1945
 				
1367 1946
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1368
-			    if (isset($tt[$format])) $tt[$format]++;
1369
-			    else $tt[$format] = 0;
1947
+			    if (isset($tt[$format])) {
1948
+			    	$tt[$format]++;
1949
+			    } else {
1950
+			    	$tt[$format] = 0;
1951
+			    }
1370 1952
 			    if ($tt[$format] > 30) {
1371
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1953
+				if ($globalDebug) {
1954
+					echo "ERROR : Reconnect ".$format."...";
1955
+				}
1372 1956
 				//@socket_close($r);
1373 1957
 				sleep(2);
1374 1958
 				$aprs_connect = 0;
@@ -1385,11 +1969,17 @@  discard block
 block discarded – undo
1385 1969
 	    } else {
1386 1970
 		$error = socket_strerror(socket_last_error());
1387 1971
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1388
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1389
-			if (isset($globalDebug)) echo "Restarting...\n";
1972
+			if ($globalDebug) {
1973
+				echo "ERROR : socket_select give this error ".$error . "\n";
1974
+			}
1975
+			if (isset($globalDebug)) {
1976
+				echo "Restarting...\n";
1977
+			}
1390 1978
 			// Restart the script if possible
1391 1979
 			if (is_array($sockets)) {
1392
-			    if ($globalDebug) echo "Shutdown all sockets...";
1980
+			    if ($globalDebug) {
1981
+			    	echo "Shutdown all sockets...";
1982
+			    }
1393 1983
 			    
1394 1984
 			    foreach ($sockets as $sock) {
1395 1985
 				@socket_shutdown($sock,2);
@@ -1397,22 +1987,36 @@  discard block
 block discarded – undo
1397 1987
 			    }
1398 1988
 			    
1399 1989
 			}
1400
-			if ($globalDebug) echo "Waiting...";
1990
+			if ($globalDebug) {
1991
+				echo "Waiting...";
1992
+			}
1401 1993
 			sleep(2);
1402 1994
 			$time = time();
1403 1995
 			//connect_all($hosts);
1404 1996
 			$aprs_connect = 0;
1405
-			if ($reset%5 == 0) sleep(20);
1406
-			if ($reset%10 == 0) sleep(100);
1407
-			if ($reset%20 == 0) sleep(200);
1408
-			if ($reset > 100) exit('Too many attempts...');
1409
-			if ($globalDebug) echo "Restart all connections...";
1997
+			if ($reset%5 == 0) {
1998
+				sleep(20);
1999
+			}
2000
+			if ($reset%10 == 0) {
2001
+				sleep(100);
2002
+			}
2003
+			if ($reset%20 == 0) {
2004
+				sleep(200);
2005
+			}
2006
+			if ($reset > 100) {
2007
+				exit('Too many attempts...');
2008
+			}
2009
+			if ($globalDebug) {
2010
+				echo "Restart all connections...";
2011
+			}
1410 2012
 			connect_all($globalSources);
1411 2013
 		}
1412 2014
 	    }
1413 2015
 	}
1414 2016
 	if ($globalDaemon === false) {
1415
-	    if ($globalDebug) echo 'Check all...'."\n";
2017
+	    if ($globalDebug) {
2018
+	    	echo 'Check all...'."\n";
2019
+	    }
1416 2020
 	    $SI->checkAll();
1417 2021
 	}
1418 2022
     }
Please login to merge, or discard this patch.
require/class.AIS.php 1 patch
Braces   +331 added lines, -143 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 			$temp += 1;
36 36
 			$flat = (float)($temp / (60.0 * 10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else {
39
+			$flat = (float)($temp / (60.0 * 10000.0));
40
+		}
39 41
 		return $flat; // float
40 42
 	}
41 43
 
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 			$temp += 1;
48 50
 			$flon = (float)($temp / (60.0 * 10000.0));
49 51
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
52
+		} else {
53
+			$flon = (float)($temp / (60.0 * 10000.0));
54
+		}
51 55
 		return $flon;
52 56
 	}
53 57
 
@@ -70,10 +74,8 @@  discard block
 block discarded – undo
70 74
     */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73
-		if ($ascii < 48) { }
74
-		else {
75
-			if($ascii>119) { }
76
-			else {
77
+		if ($ascii < 48) { } else {
78
+			if($ascii>119) { } else {
77 79
 				if ($ascii>87 && $ascii<96) ;
78 80
 				else {
79 81
 					$ascii=$ascii+40;
@@ -175,7 +177,9 @@  discard block
 block discarded – undo
175 177
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176 178
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177 179
 			$ro->heading = bindec(substr($_aisdata,124,9));
178
-			if ($ro->heading == 511) $ro->heading = '';
180
+			if ($ro->heading == 511) {
181
+				$ro->heading = '';
182
+			}
179 183
 			$ro->cls = 2; // class B
180 184
 		} else if ($ro->id == 19) {
181 185
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -185,7 +189,9 @@  discard block
 block discarded – undo
185 189
 			$ro->name = $this->binchar($_aisdata,143,120);
186 190
 			$ro->cls = 2; // class B
187 191
 			$ro->heading = bindec(substr($_aisdata,124,9));
188
-			if ($ro->heading == 511) $ro->heading = '';
192
+			if ($ro->heading == 511) {
193
+				$ro->heading = '';
194
+			}
189 195
 			$ro->typeid = bindec(substr($_aisdata,263,8));
190 196
 			$ro->type = $this->getShipType($ro->typeid);
191 197
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -216,9 +222,13 @@  discard block
 block discarded – undo
216 222
 			$ro->cls = 2; // class B
217 223
 		} else if ($ro->id == 27) {
218 224
 			$ro->cog = bindec(substr($_aisdata,85,9));
219
-			if ($ro->cog == 511) $ro->cog = 0.0;
225
+			if ($ro->cog == 511) {
226
+				$ro->cog = 0.0;
227
+			}
220 228
 			$ro->sog = bindec(substr($_aisdata,79,6));
221
-			if ($ro->sog == 63) $ro->sog = 0.0;
229
+			if ($ro->sog == 63) {
230
+				$ro->sog = 0.0;
231
+			}
222 232
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223 233
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
224 234
 			$ro->cls = 1; // class A
@@ -267,88 +277,171 @@  discard block
 block discarded – undo
267 277
 	}
268 278
 	
269 279
 	public function getShipType($code) {
270
-		if ($code == 0) return 'Not available (default)';
271
-		elseif ($code >= 1 && $code <= 19) return 'Reserved for future use';
272
-		elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type';
273
-		elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A';
274
-		elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B';
275
-		elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C';
276
-		elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D';
277
-		elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use';
278
-		elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use';
279
-		elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use';
280
-		elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use';
281
-		elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use';
282
-		elseif ($code == 30) return 'Fishing';
283
-		elseif ($code == 31) return 'Towing';
284
-		elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m';
285
-		elseif ($code == 33) return 'Dredging or underwater ops';
286
-		elseif ($code == 34) return 'Diving ops';
287
-		elseif ($code == 35) return 'Military ops';
288
-		elseif ($code == 36) return 'Sailing';
289
-		elseif ($code == 37) return 'Pleasure Craft';
290
-		elseif ($code == 38) return 'Reserved';
291
-		elseif ($code == 39) return 'Reserved';
292
-		elseif ($code == 40) return 'High speed craft (HSC), all ships of this type';
293
-		elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A';
294
-		elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B';
295
-		elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C';
296
-		elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D';
297
-		elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use';
298
-		elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use';
299
-		elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use';
300
-		elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use';
301
-		elseif ($code == 49) return 'High speed craft (HSC), No additional information';
302
-		elseif ($code == 50) return 'Pilot Vessel';
303
-		elseif ($code == 51) return 'Search and Rescue vessel';
304
-		elseif ($code == 52) return 'Tug';
305
-		elseif ($code == 53) return 'Port Tender';
306
-		elseif ($code == 54) return 'Anti-pollution equipment';
307
-		elseif ($code == 55) return 'Law Enforcement';
308
-		elseif ($code == 56) return 'Spare - Local Vessel';
309
-		elseif ($code == 57) return 'Spare - Local Vessel';
310
-		elseif ($code == 58) return 'Medical Transport';
311
-		elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18';
312
-		elseif ($code == 60) return 'Passenger, all ships of this type';
313
-		elseif ($code == 61) return 'Passenger, Hazardous category A';
314
-		elseif ($code == 62) return 'Passenger, Hazardous category B';
315
-		elseif ($code == 63) return 'Passenger, Hazardous category C';
316
-		elseif ($code == 64) return 'Passenger, Hazardous category D';
317
-		elseif ($code == 65) return 'Passenger, Reserved for future use';
318
-		elseif ($code == 66) return 'Passenger, Reserved for future use';
319
-		elseif ($code == 67) return 'Passenger, Reserved for future use';
320
-		elseif ($code == 68) return 'Passenger, Reserved for future use';
321
-		elseif ($code == 69) return 'Passenger, No additional information';
322
-		elseif ($code == 70) return 'Cargo, all ships of this type';
323
-		elseif ($code == 71) return 'Cargo, Hazardous category A';
324
-		elseif ($code == 72) return 'Cargo, Hazardous category B';
325
-		elseif ($code == 73) return 'Cargo, Hazardous category C';
326
-		elseif ($code == 74) return 'Cargo, Hazardous category D';
327
-		elseif ($code == 75) return 'Cargo, Reserved for future use';
328
-		elseif ($code == 76) return 'Cargo, Reserved for future use';
329
-		elseif ($code == 77) return 'Cargo, Reserved for future use';
330
-		elseif ($code == 78) return 'Cargo, Reserved for future use';
331
-		elseif ($code == 79) return 'Cargo, No additional information';
332
-		elseif ($code == 80) return 'Tanker, all ships of this type';
333
-		elseif ($code == 81) return 'Tanker, Hazardous category A';
334
-		elseif ($code == 82) return 'Tanker, Hazardous category B';
335
-		elseif ($code == 83) return 'Tanker, Hazardous category C';
336
-		elseif ($code == 84) return 'Tanker, Hazardous category D';
337
-		elseif ($code == 85) return 'Tanker, Reserved for future use';
338
-		elseif ($code == 86) return 'Tanker, Reserved for future use';
339
-		elseif ($code == 87) return 'Tanker, Reserved for future use';
340
-		elseif ($code == 88) return 'Tanker, Reserved for future use';
341
-		elseif ($code == 89) return 'Tanker, No additional information';
342
-		elseif ($code == 90) return 'Other Type, all ships of this type';
343
-		elseif ($code == 91) return 'Other Type, Hazardous category A';
344
-		elseif ($code == 92) return 'Other Type, Hazardous category B';
345
-		elseif ($code == 93) return 'Other Type, Hazardous category C';
346
-		elseif ($code == 94) return 'Other Type, Hazardous category D';
347
-		elseif ($code == 95) return 'Other Type, Reserved for future use';
348
-		elseif ($code == 96) return 'Other Type, Reserved for future use';
349
-		elseif ($code == 97) return 'Other Type, Reserved for future use';
350
-		elseif ($code == 98) return 'Other Type, Reserved for future use';
351
-		elseif ($code == 99) return 'Other Type, no additional information';
280
+		if ($code == 0) {
281
+			return 'Not available (default)';
282
+		} elseif ($code >= 1 && $code <= 19) {
283
+			return 'Reserved for future use';
284
+		} elseif ($code == 20) {
285
+			return 'Wing in ground (WIG), all ships of this type';
286
+		} elseif ($code == 21) {
287
+			return 'Wing in ground (WIG), Hazardous category A';
288
+		} elseif ($code == 22) {
289
+			return 'Wing in ground (WIG), Hazardous category B';
290
+		} elseif ($code == 23) {
291
+			return 'Wing in ground (WIG), Hazardous category C';
292
+		} elseif ($code == 24) {
293
+			return 'Wing in ground (WIG), Hazardous category D';
294
+		} elseif ($code == 25) {
295
+			return 'Wing in ground (WIG), Reserved for future use';
296
+		} elseif ($code == 26) {
297
+			return 'Wing in ground (WIG), Reserved for future use';
298
+		} elseif ($code == 27) {
299
+			return 'Wing in ground (WIG), Reserved for future use';
300
+		} elseif ($code == 28) {
301
+			return 'Wing in ground (WIG), Reserved for future use';
302
+		} elseif ($code == 29) {
303
+			return 'Wing in ground (WIG), Reserved for future use';
304
+		} elseif ($code == 30) {
305
+			return 'Fishing';
306
+		} elseif ($code == 31) {
307
+			return 'Towing';
308
+		} elseif ($code == 32) {
309
+			return 'Towing: length exceeds 200m or breadth exceeds 25m';
310
+		} elseif ($code == 33) {
311
+			return 'Dredging or underwater ops';
312
+		} elseif ($code == 34) {
313
+			return 'Diving ops';
314
+		} elseif ($code == 35) {
315
+			return 'Military ops';
316
+		} elseif ($code == 36) {
317
+			return 'Sailing';
318
+		} elseif ($code == 37) {
319
+			return 'Pleasure Craft';
320
+		} elseif ($code == 38) {
321
+			return 'Reserved';
322
+		} elseif ($code == 39) {
323
+			return 'Reserved';
324
+		} elseif ($code == 40) {
325
+			return 'High speed craft (HSC), all ships of this type';
326
+		} elseif ($code == 41) {
327
+			return 'High speed craft (HSC), Hazardous category A';
328
+		} elseif ($code == 42) {
329
+			return 'High speed craft (HSC), Hazardous category B';
330
+		} elseif ($code == 43) {
331
+			return 'High speed craft (HSC), Hazardous category C';
332
+		} elseif ($code == 44) {
333
+			return 'High speed craft (HSC), Hazardous category D';
334
+		} elseif ($code == 45) {
335
+			return 'High speed craft (HSC), Reserved for future use';
336
+		} elseif ($code == 46) {
337
+			return 'High speed craft (HSC), Reserved for future use';
338
+		} elseif ($code == 47) {
339
+			return 'High speed craft (HSC), Reserved for future use';
340
+		} elseif ($code == 48) {
341
+			return 'High speed craft (HSC), Reserved for future use';
342
+		} elseif ($code == 49) {
343
+			return 'High speed craft (HSC), No additional information';
344
+		} elseif ($code == 50) {
345
+			return 'Pilot Vessel';
346
+		} elseif ($code == 51) {
347
+			return 'Search and Rescue vessel';
348
+		} elseif ($code == 52) {
349
+			return 'Tug';
350
+		} elseif ($code == 53) {
351
+			return 'Port Tender';
352
+		} elseif ($code == 54) {
353
+			return 'Anti-pollution equipment';
354
+		} elseif ($code == 55) {
355
+			return 'Law Enforcement';
356
+		} elseif ($code == 56) {
357
+			return 'Spare - Local Vessel';
358
+		} elseif ($code == 57) {
359
+			return 'Spare - Local Vessel';
360
+		} elseif ($code == 58) {
361
+			return 'Medical Transport';
362
+		} elseif ($code == 59) {
363
+			return 'Noncombatant ship according to RR Resolution No. 18';
364
+		} elseif ($code == 60) {
365
+			return 'Passenger, all ships of this type';
366
+		} elseif ($code == 61) {
367
+			return 'Passenger, Hazardous category A';
368
+		} elseif ($code == 62) {
369
+			return 'Passenger, Hazardous category B';
370
+		} elseif ($code == 63) {
371
+			return 'Passenger, Hazardous category C';
372
+		} elseif ($code == 64) {
373
+			return 'Passenger, Hazardous category D';
374
+		} elseif ($code == 65) {
375
+			return 'Passenger, Reserved for future use';
376
+		} elseif ($code == 66) {
377
+			return 'Passenger, Reserved for future use';
378
+		} elseif ($code == 67) {
379
+			return 'Passenger, Reserved for future use';
380
+		} elseif ($code == 68) {
381
+			return 'Passenger, Reserved for future use';
382
+		} elseif ($code == 69) {
383
+			return 'Passenger, No additional information';
384
+		} elseif ($code == 70) {
385
+			return 'Cargo, all ships of this type';
386
+		} elseif ($code == 71) {
387
+			return 'Cargo, Hazardous category A';
388
+		} elseif ($code == 72) {
389
+			return 'Cargo, Hazardous category B';
390
+		} elseif ($code == 73) {
391
+			return 'Cargo, Hazardous category C';
392
+		} elseif ($code == 74) {
393
+			return 'Cargo, Hazardous category D';
394
+		} elseif ($code == 75) {
395
+			return 'Cargo, Reserved for future use';
396
+		} elseif ($code == 76) {
397
+			return 'Cargo, Reserved for future use';
398
+		} elseif ($code == 77) {
399
+			return 'Cargo, Reserved for future use';
400
+		} elseif ($code == 78) {
401
+			return 'Cargo, Reserved for future use';
402
+		} elseif ($code == 79) {
403
+			return 'Cargo, No additional information';
404
+		} elseif ($code == 80) {
405
+			return 'Tanker, all ships of this type';
406
+		} elseif ($code == 81) {
407
+			return 'Tanker, Hazardous category A';
408
+		} elseif ($code == 82) {
409
+			return 'Tanker, Hazardous category B';
410
+		} elseif ($code == 83) {
411
+			return 'Tanker, Hazardous category C';
412
+		} elseif ($code == 84) {
413
+			return 'Tanker, Hazardous category D';
414
+		} elseif ($code == 85) {
415
+			return 'Tanker, Reserved for future use';
416
+		} elseif ($code == 86) {
417
+			return 'Tanker, Reserved for future use';
418
+		} elseif ($code == 87) {
419
+			return 'Tanker, Reserved for future use';
420
+		} elseif ($code == 88) {
421
+			return 'Tanker, Reserved for future use';
422
+		} elseif ($code == 89) {
423
+			return 'Tanker, No additional information';
424
+		} elseif ($code == 90) {
425
+			return 'Other Type, all ships of this type';
426
+		} elseif ($code == 91) {
427
+			return 'Other Type, Hazardous category A';
428
+		} elseif ($code == 92) {
429
+			return 'Other Type, Hazardous category B';
430
+		} elseif ($code == 93) {
431
+			return 'Other Type, Hazardous category C';
432
+		} elseif ($code == 94) {
433
+			return 'Other Type, Hazardous category D';
434
+		} elseif ($code == 95) {
435
+			return 'Other Type, Reserved for future use';
436
+		} elseif ($code == 96) {
437
+			return 'Other Type, Reserved for future use';
438
+		} elseif ($code == 97) {
439
+			return 'Other Type, Reserved for future use';
440
+		} elseif ($code == 98) {
441
+			return 'Other Type, Reserved for future use';
442
+		} elseif ($code == 99) {
443
+			return 'Other Type, no additional information';
444
+		}
352 445
 	}
353 446
 
354 447
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -386,19 +479,34 @@  discard block
 block discarded – undo
386 479
 		// assume 1st ! is valid
387 480
 		// find * ensure that it is at correct position
388 481
 		$end = strrpos ( $rawdata , '*' );
389
-		if ($end === FALSE) return -1; // check for NULLS!!!
482
+		if ($end === FALSE) {
483
+			return -1;
484
+		}
485
+		// check for NULLS!!!
390 486
 		$cs = substr( $rawdata, $end + 1 );
391
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
487
+		if ( strlen($cs) != 2 ) {
488
+			return -1;
489
+		}
490
+		// correct cs length
392 491
 		$dcs = (int)hexdec( $cs );
393
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
492
+		for ( $alias=1; $alias<$end; $alias++) {
493
+			$chksum ^= ord( $rawdata[$alias] );
494
+		}
495
+		// perform XOR for NMEA checksum
394 496
 		if ( $chksum == $dcs ) { // NMEA checksum pass
395 497
 			$pcs = explode(',', $rawdata);
396 498
 			// !AI??? identifier
397 499
 			$num_seq = (int)$pcs[1]; // number of sequences
398 500
 			$seq = (int)$pcs[2]; // get sequence
399 501
 			// get msg sequence id
400
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
401
-			else $msg_sid = (int)$pcs[3]; // multipart message
502
+			if ($pcs[3] == '') {
503
+				$msg_sid = -1;
504
+			}
505
+			// non-multipart message, set to -1
506
+			else {
507
+				$msg_sid = (int)$pcs[3];
508
+			}
509
+			// multipart message
402 510
 			$ais_ch = $pcs[4]; // get AIS channel
403 511
 			// message sequence checking
404 512
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -459,10 +567,18 @@  discard block
 block discarded – undo
459 567
 				//DEBUG echo "[$start $end $tst]\n";
460 568
 				$result = $this->process_ais_raw( $tst, "" );
461 569
 				$last_pos = $end + 1;
462
-			} else break;
570
+			} else {
571
+				break;
572
+			}
573
+		}
574
+		if ($last_pos > 0) {
575
+			$cbuf = substr($cbuf, $last_pos);
576
+		}
577
+		// move...
578
+		if (strlen($cbuf) > 1024) {
579
+			$cbuf = "";
463 580
 		}
464
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
465
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
581
+		// prevent overflow simple mode...
466 582
 		return $result;
467 583
 	}
468 584
 
@@ -482,7 +598,9 @@  discard block
 block discarded – undo
482 598
 		if ($lat<0.0) {
483 599
 			$lat = -$lat;
484 600
 			$neg=true;
485
-		} else $neg=false;
601
+		} else {
602
+			$neg=false;
603
+		}
486 604
 		$latd = 0x00000000;
487 605
 		$latd = intval ($lat * 600000.0);
488 606
 		if ($neg==true) {
@@ -498,7 +616,9 @@  discard block
 block discarded – undo
498 616
 		if ($lon<0.0) {
499 617
 			$lon = -$lon;
500 618
 			$neg=true;
501
-		} else $neg=false;
619
+		} else {
620
+			$neg=false;
621
+		}
502 622
 		$lond = 0x00000000;
503 623
 		$lond = intval ($lon * 600000.0);
504 624
 		if ($neg==true) {
@@ -511,9 +631,14 @@  discard block
 block discarded – undo
511 631
 
512 632
 	private function char2bin($name, $max_len) {
513 633
 		$len = strlen($name);
514
-		if ($len > $max_len) $name = substr($name,0,$max_len);
515
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
516
-		else $pad = '';
634
+		if ($len > $max_len) {
635
+			$name = substr($name,0,$max_len);
636
+		}
637
+		if ($len < $max_len) {
638
+			$pad = str_repeat('0', ($max_len - $len) * 6);
639
+		} else {
640
+			$pad = '';
641
+		}
517 642
 		$rv = '';
518 643
 		$ais_chars = array(
519 644
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -526,9 +651,12 @@  discard block
 block discarded – undo
526 651
 		);
527 652
 		// "
528 653
 		$_a = str_split($name);
529
-		if ($_a) foreach ($_a as $_1) {
654
+		if ($_a) {
655
+			foreach ($_a as $_1) {
530 656
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
531
-			else $dec = 0;
657
+		} else {
658
+				$dec = 0;
659
+			}
532 660
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
533 661
 			$rv .= $bin;
534 662
 			//echo "$_1 $dec ($bin)<br/>";
@@ -540,7 +668,9 @@  discard block
 block discarded – undo
540 668
 		$len_bit = strlen($_enc);
541 669
 		$rem6 = $len_bit % 6;
542 670
 		$pad6_len = 0;
543
-		if ($rem6) $pad6_len = 6 - $rem6;
671
+		if ($rem6) {
672
+			$pad6_len = 6 - $rem6;
673
+		}
544 674
 		//echo  $pad6_len.'<br>';
545 675
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
546 676
 		$len_enc = strlen($_enc) / 6;
@@ -549,8 +679,11 @@  discard block
 block discarded – undo
549 679
 		for ($i=0; $i<$len_enc; $i++) {
550 680
 			$offset = $i * 6;
551 681
 			$dec = bindec(substr($_enc,$offset,6));
552
-			if ($dec < 40) $dec += 48;
553
-			else $dec += 56;
682
+			if ($dec < 40) {
683
+				$dec += 48;
684
+			} else {
685
+				$dec += 56;
686
+			}
554 687
 			//echo chr($dec)." $dec<br/>";
555 688
 			$itu .= chr($dec);
556 689
 		}
@@ -563,25 +696,41 @@  discard block
 block discarded – undo
563 696
 		}
564 697
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
565 698
 		$lsb = $chksum & 0x0F;
566
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
567
-		else $lsbc = '0';
699
+		if ($lsb >=0 && $lsb <= 15 ) {
700
+			$lsbc = $hex_arr[$lsb];
701
+		} else {
702
+			$lsbc = '0';
703
+		}
568 704
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
569
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
570
-		else $msbc = '0';
705
+		if ($msb >=0 && $msb <= 15 ) {
706
+			$msbc = $hex_arr[$msb];
707
+		} else {
708
+			$msbc = '0';
709
+		}
571 710
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
572 711
 		return $itu;
573 712
 	}
574 713
 
575 714
 	public function parse($buffer) {
576 715
 		$data = $this->process_ais_buf($buffer);
577
-		if (!is_object($data)) return array();
578
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
579
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
716
+		if (!is_object($data)) {
717
+			return array();
718
+		}
719
+		if ($data->lon != 0) {
720
+			$result['longitude'] = $data->lon;
721
+		}
722
+		if ($data->lat != 0) {
723
+			$result['latitude'] = $data->lat;
724
+		}
580 725
 		$result['ident'] = trim($data->name);
581 726
 		$result['timestamp'] = $data->ts;
582 727
 		$result['mmsi'] = $data->mmsi;
583
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
584
-		if ($data->cog != 0) $result['heading'] = $data->cog;
728
+		if ($data->sog != -1.0) {
729
+			$result['speed'] = $data->sog;
730
+		}
731
+		if ($data->cog != 0) {
732
+			$result['heading'] = $data->cog;
733
+		}
585 734
 		/*
586 735
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
587 736
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -591,15 +740,25 @@  discard block
 block discarded – undo
591 740
 
592 741
 	public function mmsitype($mmsi) {
593 742
 		if (strlen($mmsi) == 9) {
594
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
596
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
598
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
599
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
600
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
601
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
602
-			else return 'Ship';
743
+			if (substr($mmsi,0,3) == '974') {
744
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
745
+			} elseif (substr($mmsi,0,3) == '972') {
746
+				return 'MOB (Man Overboard) device';
747
+			} elseif (substr($mmsi,0,3) == '970') {
748
+				return 'AIS SART (Search and Rescue Transmitter)';
749
+			} elseif (substr($mmsi,0,3) == '111') {
750
+				return 'SAR (Search and Rescue) aircraft';
751
+			} elseif (substr($mmsi,0,2) == '98') {
752
+				return 'Auxiliary craft associated with a parent ship';
753
+			} elseif (substr($mmsi,0,2) == '99') {
754
+				return 'Aids to Navigation';
755
+			} elseif (substr($mmsi,0,2) == '00') {
756
+				return 'Coastal stations';
757
+			} elseif (substr($mmsi,0,1) == '0') {
758
+				return 'Group of ships';
759
+			} else {
760
+				return 'Ship';
761
+			}
603 762
 		}
604 763
 
605 764
 	
@@ -616,32 +775,61 @@  discard block
 block discarded – undo
616 775
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
617 776
 			return array();
618 777
 		}
619
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
620
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
778
+		if ($data->lon != 0) {
779
+			$result['longitude'] = $data->lon;
780
+		}
781
+		if ($data->lat != 0) {
782
+			$result['latitude'] = $data->lat;
783
+		}
621 784
 		$result['ident'] = trim(str_replace('@','',$data->name));
622 785
 		$result['timestamp'] = $data->ts;
623 786
 		$result['mmsi'] = $data->mmsi;
624
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
787
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') {
788
+			$result['mmsi'] = '3'.$result['mmsi'];
789
+		}
625 790
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
626
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
627
-		if ($data->heading !== '') $result['heading'] = $data->heading;
628
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
629
-		if ($data->status != '') $result['status'] = $data->status;
630
-		if ($data->statusid !== '') $result['statusid'] = $data->statusid;
631
-		if ($data->type !== '') $result['type'] = $data->type;
632
-		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
633
-		if ($data->imo !== '') $result['imo'] = $data->imo;
634
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
791
+		if ($data->sog != -1.0) {
792
+			$result['speed'] = $data->sog;
793
+		}
794
+		if ($data->heading !== '') {
795
+			$result['heading'] = $data->heading;
796
+		} elseif ($data->cog != 0) {
797
+			$result['heading'] = $data->cog;
798
+		}
799
+		if ($data->status != '') {
800
+			$result['status'] = $data->status;
801
+		}
802
+		if ($data->statusid !== '') {
803
+			$result['statusid'] = $data->statusid;
804
+		}
805
+		if ($data->type !== '') {
806
+			$result['type'] = $data->type;
807
+		}
808
+		if ($data->typeid !== '') {
809
+			$result['typeid'] = $data->typeid;
810
+		}
811
+		if ($data->imo !== '') {
812
+			$result['imo'] = $data->imo;
813
+		}
814
+		if ($data->callsign !== '') {
815
+			$result['callsign'] = trim(str_replace('@','',$data->callsign));
816
+		}
635 817
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
636 818
 			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
637
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
819
+			if ($eta_ts != '') {
820
+				$result['eta_ts'] = $eta_ts;
821
+			}
638 822
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
639 823
 			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
640
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
824
+			if ($eta_ts != '') {
825
+				$result['eta_ts'] = $eta_ts;
826
+			}
641 827
 		}
642 828
 		if ($data->destination != '') {
643 829
 			$dest = trim(str_replace('@','',$data->destination));
644
-			if ($dest != '') $result['destination'] = $dest;
830
+			if ($dest != '') {
831
+				$result['destination'] = $dest;
832
+			}
645 833
 		}
646 834
 		$result['all'] = (array) $data;
647 835
 		/*
Please login to merge, or discard this patch.
require/class.Image.php 1 patch
Braces   +208 added lines, -77 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@  discard block
 block discarded – undo
23 23
 		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
24 24
 		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
25 25
 		$reg = $registration;
26
-		if ($reg == '' && $aircraft_icao != '') $reg = $aircraft_icao.$airline_icao;
26
+		if ($reg == '' && $aircraft_icao != '') {
27
+			$reg = $aircraft_icao.$airline_icao;
28
+		}
27 29
 		$reg = trim($reg);
28 30
 		$query  = "SELECT spotter_image.image, spotter_image.image_thumbnail, spotter_image.image_source, spotter_image.image_source_website,spotter_image.image_copyright, spotter_image.registration 
29 31
 			FROM spotter_image 
@@ -31,9 +33,13 @@  discard block
 block discarded – undo
31 33
 		$sth = $this->db->prepare($query);
32 34
 		$sth->execute(array(':registration' => $reg));
33 35
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
34
-		if (!empty($result)) return $result;
35
-		elseif ($registration != '') return $this->getSpotterImage('',$aircraft_icao,$airline_icao);
36
-		else return array();
36
+		if (!empty($result)) {
37
+			return $result;
38
+		} elseif ($registration != '') {
39
+			return $this->getSpotterImage('',$aircraft_icao,$airline_icao);
40
+		} else {
41
+			return array();
42
+		}
37 43
 	}
38 44
 
39 45
 	/**
@@ -76,8 +82,11 @@  discard block
 block discarded – undo
76 82
 	public function getExifCopyright($url) {
77 83
 		$exif = exif_read_data($url);
78 84
 		$copyright = '';
79
-		if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright'];
80
-		elseif (isset($exif['copyright'])) $copyright = $exif['copyright'];
85
+		if (isset($exif['COMPUTED']['copyright'])) {
86
+			$copyright = $exif['COMPUTED']['copyright'];
87
+		} elseif (isset($exif['copyright'])) {
88
+			$copyright = $exif['copyright'];
89
+		}
81 90
 		if ($copyright != '') {
82 91
 			$copyright = str_replace('Copyright ','',$copyright);
83 92
 			$copyright = str_replace('© ','',$copyright);
@@ -95,17 +104,27 @@  discard block
 block discarded – undo
95 104
 	public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '')
96 105
 	{
97 106
 		global $globalDebug,$globalAircraftImageFetch;
98
-		if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) return '';
107
+		if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) {
108
+			return '';
109
+		}
99 110
 		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
100 111
 		$registration = trim($registration);
101 112
 		//getting the aircraft image
102
-		if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...';
103
-		elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...';
104
-		elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...';
113
+		if ($globalDebug && $registration != '') {
114
+			echo 'Try to find an aircraft image for '.$registration.'...';
115
+		} elseif ($globalDebug && $aircraft_icao != '') {
116
+			echo 'Try to find an aircraft image for '.$aircraft_icao.'...';
117
+		} elseif ($globalDebug && $airline_icao != '') {
118
+			echo 'Try to find an aircraft image for '.$airline_icao.'...';
119
+		}
105 120
 		$image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao);
106
-		if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao;
121
+		if ($registration == '' && $aircraft_icao != '') {
122
+			$registration = $aircraft_icao.$airline_icao;
123
+		}
107 124
 		if ($image_url['original'] != '') {
108
-			if ($globalDebug) echo 'Found !'."\n";
125
+			if ($globalDebug) {
126
+				echo 'Found !'."\n";
127
+			}
109 128
 			$query  = "INSERT INTO spotter_image (registration, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:registration,:image,:image_thumbnail,:copyright,:source,:source_website)";
110 129
 			try {
111 130
 				$sth = $this->db->prepare($query);
@@ -114,7 +133,9 @@  discard block
 block discarded – undo
114 133
 				echo $e->getMessage()."\n";
115 134
 				return "error";
116 135
 			}
117
-		} elseif ($globalDebug) echo "Not found :'(\n";
136
+		} elseif ($globalDebug) {
137
+			echo "Not found :'(\n";
138
+		}
118 139
 		return "success";
119 140
 	}
120 141
 
@@ -127,7 +148,9 @@  discard block
 block discarded – undo
127 148
 	public function addMarineImage($mmsi,$imo = '',$name = '')
128 149
 	{
129 150
 		global $globalDebug,$globalMarineImageFetch;
130
-		if (isset($globalMarineImageFetch) && !$globalMarineImageFetch) return '';
151
+		if (isset($globalMarineImageFetch) && !$globalMarineImageFetch) {
152
+			return '';
153
+		}
131 154
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
132 155
 		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
133 156
 		$name = filter_var($name,FILTER_SANITIZE_STRING);
@@ -137,16 +160,22 @@  discard block
 block discarded – undo
137 160
 			$identity = $Marine->getIdentity($mmsi);
138 161
 			if (isset($identity[0]['mmsi'])) {
139 162
 				$imo = $identity[0]['imo'];
140
-				if ($identity[0]['ship_name'] != '') $name = $identity[0]['ship_name'];
163
+				if ($identity[0]['ship_name'] != '') {
164
+					$name = $identity[0]['ship_name'];
165
+				}
141 166
 			}
142 167
 		}
143 168
 		unset($Marine);
144 169
 
145 170
 		//getting the aircraft image
146
-		if ($globalDebug && $name != '') echo 'Try to find an vessel image for '.$name.'...';
171
+		if ($globalDebug && $name != '') {
172
+			echo 'Try to find an vessel image for '.$name.'...';
173
+		}
147 174
 		$image_url = $this->findMarineImage($mmsi,$imo,$name);
148 175
 		if ($image_url['original'] != '') {
149
-			if ($globalDebug) echo 'Found !'."\n";
176
+			if ($globalDebug) {
177
+				echo 'Found !'."\n";
178
+			}
150 179
 			$query  = "INSERT INTO marine_image (mmsi,imo,name, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:mmsi,:imo,:name,:image,:image_thumbnail,:copyright,:source,:source_website)";
151 180
 			try {
152 181
 				$sth = $this->db->prepare($query);
@@ -155,7 +184,9 @@  discard block
 block discarded – undo
155 184
 				echo $e->getMessage()."\n";
156 185
 				return "error";
157 186
 			}
158
-		} elseif ($globalDebug) echo "Not found :'(\n";
187
+		} elseif ($globalDebug) {
188
+			echo "Not found :'(\n";
189
+		}
159 190
 		return "success";
160 191
 	}
161 192
 
@@ -170,41 +201,85 @@  discard block
 block discarded – undo
170 201
 	{
171 202
 		global $globalAircraftImageSources, $globalIVAO, $globalAircraftImageCheckICAO, $globalVA;
172 203
 		$Spotter = new Spotter($this->db);
173
-		if (!isset($globalIVAO)) $globalIVAO = FALSE;
204
+		if (!isset($globalIVAO)) {
205
+			$globalIVAO = FALSE;
206
+		}
174 207
 		$aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING);
175 208
 		if ($aircraft_registration != '' && (!isset($globalVA) || $globalVA !== TRUE)) {
176
-			if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
209
+			if (strpos($aircraft_registration,'/') !== false) {
210
+				return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
211
+			}
177 212
 			$aircraft_registration = urlencode(trim($aircraft_registration));
178 213
 			$aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration);
179
-			if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name'];
180
-			else $aircraft_name = '';
181
-			if (isset($aircraft_info[0]['aircraft_icao'])) $aircraft_name = $aircraft_info[0]['aircraft_icao'];
182
-			else $aircraft_icao = '';
183
-			if (isset($aircraft_info[0]['airline_icao'])) $airline_icao = $aircraft_info[0]['airline_icao'];
184
-			else $airline_icao = '';
214
+			if (isset($aircraft_info[0]['aircraft_name'])) {
215
+				$aircraft_name = $aircraft_info[0]['aircraft_name'];
216
+			} else {
217
+				$aircraft_name = '';
218
+			}
219
+			if (isset($aircraft_info[0]['aircraft_icao'])) {
220
+				$aircraft_name = $aircraft_info[0]['aircraft_icao'];
221
+			} else {
222
+				$aircraft_icao = '';
223
+			}
224
+			if (isset($aircraft_info[0]['airline_icao'])) {
225
+				$airline_icao = $aircraft_info[0]['airline_icao'];
226
+			} else {
227
+				$airline_icao = '';
228
+			}
185 229
 		} elseif ($aircraft_icao != '') {
186 230
 			$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_icao);
187
-			if (isset($aircraft_info[0]['type'])) $aircraft_name = $aircraft_info[0]['type'];
188
-			else $aircraft_name = '';
231
+			if (isset($aircraft_info[0]['type'])) {
232
+				$aircraft_name = $aircraft_info[0]['type'];
233
+			} else {
234
+				$aircraft_name = '';
235
+			}
189 236
 			$aircraft_registration = $aircraft_icao;
190
-		} else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
237
+		} else {
238
+			return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
239
+		}
191 240
 		unset($Spotter);
192
-		if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
241
+		if (!isset($globalAircraftImageSources)) {
242
+			$globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
243
+		}
193 244
 		foreach ($globalAircraftImageSources as $source) {
194 245
 			$source = strtolower($source);
195
-			if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao);
196
-			if ($source == 'planespotters' && !$globalIVAO) $images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name);
197
-			if ($source == 'flickr') $images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name);
198
-			if ($source == 'bing') $images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name);
199
-			if ($source == 'deviantart') $images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name);
200
-			if ($source == 'wikimedia') $images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name);
201
-			if ($source == 'jetphotos' && !$globalIVAO) $images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name);
202
-			if ($source == 'planepictures' && !$globalIVAO) $images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name);
203
-			if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name);
204
-			if ($source == 'customsources') $images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name);
205
-			if (isset($images_array) && $images_array['original'] != '') return $images_array;
206
-		}
207
-		if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) return $this->findAircraftImage($aircraft_icao);
246
+			if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') {
247
+				$images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao);
248
+			}
249
+			if ($source == 'planespotters' && !$globalIVAO) {
250
+				$images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name);
251
+			}
252
+			if ($source == 'flickr') {
253
+				$images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name);
254
+			}
255
+			if ($source == 'bing') {
256
+				$images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name);
257
+			}
258
+			if ($source == 'deviantart') {
259
+				$images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name);
260
+			}
261
+			if ($source == 'wikimedia') {
262
+				$images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name);
263
+			}
264
+			if ($source == 'jetphotos' && !$globalIVAO) {
265
+				$images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name);
266
+			}
267
+			if ($source == 'planepictures' && !$globalIVAO) {
268
+				$images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name);
269
+			}
270
+			if ($source == 'airportdata' && !$globalIVAO) {
271
+				$images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name);
272
+			}
273
+			if ($source == 'customsources') {
274
+				$images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name);
275
+			}
276
+			if (isset($images_array) && $images_array['original'] != '') {
277
+				return $images_array;
278
+			}
279
+		}
280
+		if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) {
281
+			return $this->findAircraftImage($aircraft_icao);
282
+		}
208 283
 		return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
209 284
 	}
210 285
 
@@ -224,7 +299,9 @@  discard block
 block discarded – undo
224 299
 		//$imo = filter_var($imo,FILTER_SANITIZE_STRING);
225 300
 		$name = filter_var($name,FILTER_SANITIZE_STRING);
226 301
 		$name = trim($name);
227
-		if (strlen($name) < 4) return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
302
+		if (strlen($name) < 4) {
303
+			return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
304
+		}
228 305
 		/*
229 306
 		$Marine = new Marine($this->db);
230 307
 		if ($imo == '' || $name == '') {
@@ -236,15 +313,29 @@  discard block
 block discarded – undo
236 313
 		}
237 314
 		unset($Marine);
238 315
 		*/
239
-		if (!isset($globalMarineImageSources)) $globalMarineImageSources = array('wikimedia','deviantart','flickr','bing');
316
+		if (!isset($globalMarineImageSources)) {
317
+			$globalMarineImageSources = array('wikimedia','deviantart','flickr','bing');
318
+		}
240 319
 		foreach ($globalMarineImageSources as $source) {
241 320
 			$source = strtolower($source);
242
-			if ($source == 'flickr') $images_array = $this->fromFlickr('marine',$mmsi,$name);
243
-			if ($source == 'bing') $images_array = $this->fromBing('marine',$mmsi,$name);
244
-			if ($source == 'deviantart') $images_array = $this->fromDeviantart('marine',$mmsi,$name);
245
-			if ($source == 'wikimedia') $images_array = $this->fromWikimedia('marine',$mmsi,$name);
246
-			if ($source == 'customsources') $images_array = $this->fromCustomSource('marine',$mmsi,$name);
247
-			if (isset($images_array) && $images_array['original'] != '') return $images_array;
321
+			if ($source == 'flickr') {
322
+				$images_array = $this->fromFlickr('marine',$mmsi,$name);
323
+			}
324
+			if ($source == 'bing') {
325
+				$images_array = $this->fromBing('marine',$mmsi,$name);
326
+			}
327
+			if ($source == 'deviantart') {
328
+				$images_array = $this->fromDeviantart('marine',$mmsi,$name);
329
+			}
330
+			if ($source == 'wikimedia') {
331
+				$images_array = $this->fromWikimedia('marine',$mmsi,$name);
332
+			}
333
+			if ($source == 'customsources') {
334
+				$images_array = $this->fromCustomSource('marine',$mmsi,$name);
335
+			}
336
+			if (isset($images_array) && $images_array['original'] != '') {
337
+				return $images_array;
338
+			}
248 339
 		}
249 340
 		return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
250 341
 	}
@@ -407,11 +498,17 @@  discard block
 block discarded – undo
407 498
 	public function fromFlickr($type,$registration,$name='') {
408 499
 		$Common = new Common();
409 500
 		if ($type == 'aircraft') {
410
-			if ($name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.','.urlencode($name);
411
-			else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',aircraft';
501
+			if ($name != '') {
502
+				$url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.','.urlencode($name);
503
+			} else {
504
+				$url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',aircraft';
505
+			}
412 506
 		} elseif ($type == 'marine') {
413
-			if ($name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags=ship,'.urlencode($name);
414
-			else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',ship';
507
+			if ($name != '') {
508
+				$url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags=ship,'.urlencode($name);
509
+			} else {
510
+				$url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$registration.',ship';
511
+			}
415 512
 		}
416 513
 		$data = $Common->getData($url);
417 514
 		if ($xml = simplexml_load_string($data)) {
@@ -456,13 +553,21 @@  discard block
 block discarded – undo
456 553
 	public function fromBing($type,$aircraft_registration,$aircraft_name='') {
457 554
 		global $globalImageBingKey;
458 555
 		$Common = new Common();
459
-		if (!isset($globalImageBingKey) || $globalImageBingKey == '') return false;
556
+		if (!isset($globalImageBingKey) || $globalImageBingKey == '') {
557
+			return false;
558
+		}
460 559
 		if ($type == 'aircraft') {
461
-			if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27';
462
-			else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27';
560
+			if ($aircraft_name != '') {
561
+				$url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27';
562
+			} else {
563
+				$url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27';
564
+			}
463 565
 		} elseif ($type == 'marine') {
464
-			if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.urlencode($aircraft_name).'%20%2Bship%20-site:flickr.com%27';
465
-			else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Bship%20-site:flickr.com%27';
566
+			if ($aircraft_name != '') {
567
+				$url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.urlencode($aircraft_name).'%20%2Bship%20-site:flickr.com%27';
568
+			} else {
569
+				$url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Bship%20-site:flickr.com%27';
570
+			}
466 571
 		}
467 572
 		$headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey));
468 573
 		$data = $Common->getData($url,'get','',$headers);
@@ -518,17 +623,25 @@  discard block
 block discarded – undo
518 623
 	public function fromWikimedia($type,$registration,$name='') {
519 624
 		$Common = new Common();
520 625
 		if ($type == 'aircraft') {
521
-			if ($name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20'.urlencode($name);
522
-			else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft';
626
+			if ($name != '') {
627
+				$url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20'.urlencode($name);
628
+			} else {
629
+				$url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft';
630
+			}
523 631
 		} elseif ($type == 'marine') {
524
-			if ($name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.urlencode($name).'%20ship"';
525
-			else return false;
632
+			if ($name != '') {
633
+				$url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.urlencode($name).'%20ship"';
634
+			} else {
635
+				return false;
636
+			}
526 637
 		}
527 638
 		$data = $Common->getData($url);
528 639
 		$result = json_decode($data);
529 640
 		if (isset($result->query->search[0]->title)) {
530 641
 			$fileo = $result->query->search[0]->title;
531
-			if (substr($fileo,-3) == 'pdf') return false;
642
+			if (substr($fileo,-3) == 'pdf') {
643
+				return false;
644
+			}
532 645
 			$file = urlencode($fileo);
533 646
 			$url2 = 'https://commons.wikimedia.org/w/api.php?action=query&format=json&continue&iilimit=500&prop=imageinfo&iiprop=user|url|size|mime|sha1|timestamp&iiurlwidth=200%27&titles='.$file;
534 647
 			$data2 = $Common->getData($url2);
@@ -599,18 +712,27 @@  discard block
 block discarded – undo
599 712
 					$image_url = array();
600 713
 					$image_url['thumbnail'] = $url_thumbnail;
601 714
 					$image_url['original'] = $url;
602
-					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url);
603
-					else $exifCopyright = '';
604
-					if ($exifCopyright  != '') $image_url['copyright'] = $exifCopyright;
605
-					elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright'];
606
-					else $image_url['copyright'] = $source['source_website'];
715
+					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) {
716
+						$exifCopyright = $this->getExifCopyright($url);
717
+					} else {
718
+						$exifCopyright = '';
719
+					}
720
+					if ($exifCopyright  != '') {
721
+						$image_url['copyright'] = $exifCopyright;
722
+					} elseif (isset($source['copyright'])) {
723
+						$image_url['copyright'] = $source['copyright'];
724
+					} else {
725
+						$image_url['copyright'] = $source['source_website'];
726
+					}
607 727
 					$image_url['source_website'] = $source['source_website'];
608 728
 					$image_url['source'] = $source['source'];
609 729
 					return $image_url;
610 730
 				}
611 731
 			}
612 732
 			return false;
613
-		} else return false;
733
+		} else {
734
+			return false;
735
+		}
614 736
 		if (!empty($globalMarineImageCustomSources) && $type == 'marine') {
615 737
 			$customsources = array();
616 738
 			if (!isset($globalMarineImageCustomSources[0])) {
@@ -635,18 +757,27 @@  discard block
 block discarded – undo
635 757
 					$image_url = array();
636 758
 					$image_url['thumbnail'] = $url_thumbnail;
637 759
 					$image_url['original'] = $url;
638
-					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url);
639
-					else $exifCopyright = '';
640
-					if ($exifCopyright  != '') $image_url['copyright'] = $exifCopyright;
641
-					elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright'];
642
-					else $image_url['copyright'] = $source['source_website'];
760
+					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) {
761
+						$exifCopyright = $this->getExifCopyright($url);
762
+					} else {
763
+						$exifCopyright = '';
764
+					}
765
+					if ($exifCopyright  != '') {
766
+						$image_url['copyright'] = $exifCopyright;
767
+					} elseif (isset($source['copyright'])) {
768
+						$image_url['copyright'] = $source['copyright'];
769
+					} else {
770
+						$image_url['copyright'] = $source['source_website'];
771
+					}
643 772
 					$image_url['source_website'] = $source['source_website'];
644 773
 					$image_url['source'] = $source['source'];
645 774
 					return $image_url;
646 775
 				}
647 776
 			}
648 777
 			return false;
649
-		} else return false;
778
+		} else {
779
+			return false;
780
+		}
650 781
 	}
651 782
 }
652 783
 
Please login to merge, or discard this patch.