Completed
Push — master ( 60bf6d...c26593 )
by Yannick
08:12
created
require/class.APRS.php 3 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
6
-    private $connected = false;
5
+	private $socket;
6
+	private $connected = false;
7 7
 
8
-    protected $symbols = array('!' => 'Police',
8
+	protected $symbols = array('!' => 'Police',
9 9
 	'#' => 'DIGI',
10 10
 	'$' => 'Phone',
11 11
 	'%' => 'DX Cluster',
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
-    private function urshift($n, $s) {
92
+	private function urshift($n, $s) {
93 93
 	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
94
+		(($n & 0x7fffffff) >> $s) | 
95 95
 		(0x40000000 >> ($s - 1));
96
-    }
96
+	}
97 97
 
98
-    public function parse($input) {
98
+	public function parse($input) {
99 99
 	global $globalDebug;
100 100
 	$debug = false;
101 101
 	$result = array();
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
-	    return false;
110
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
+		return false;
112 112
 	}
113 113
 	
114 114
 	if ($debug) echo 'input : '.$input."\n";
@@ -122,31 +122,31 @@  discard block
 block discarded – undo
122 122
 	/* Parse source, target and path. */
123 123
 	//FLRDF0A52>APRS,qAS,LSTB
124 124
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
125
-	    $ident = $matches[1];
126
-	    $all_elements = $matches[2];
127
-	    if ($ident == 'AIRCRAFT') {
125
+		$ident = $matches[1];
126
+		$all_elements = $matches[2];
127
+		if ($ident == 'AIRCRAFT') {
128 128
 		$result['format_source'] = 'famaprs';
129 129
 		$result['source_type'] = 'modes';
130
-	    } elseif ($ident == 'MARINE') {
130
+		} elseif ($ident == 'MARINE') {
131 131
 		$result['format_source'] = 'famaprs';
132 132
 		$result['source_type'] = 'ais';
133
-	    } else {
133
+		} else {
134 134
 		if ($debug) echo 'ident : '.$ident."\n";
135 135
 		$result['ident'] = $ident;
136
-	    }
136
+		}
137 137
 	} else return false;
138 138
 	$elements = explode(',',$all_elements);
139 139
 	$source = end($elements);
140 140
 	$result['source'] = $source;
141 141
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
-	        //echo "ok";
144
-	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
142
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
+			//echo "ok";
144
+			//if ($element == 'TCPIP*') return false;
145
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146 146
 		if ($debug) echo 'element : '.$element."\n";
147 147
 		return false;
148
-	    }
149
-	    /*
148
+		}
149
+		/*
150 150
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
151 151
 		//echo "ok";
152 152
 	    } else {
@@ -171,49 +171,49 @@  discard block
 block discarded – undo
171 171
 	$body_parse = substr($body,1);
172 172
 	//echo 'Body : '.$body."\n";
173 173
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
175
-	    $find = true;
176
-	    //echo $body_parse."\n";
174
+		$body_parse = substr($body_parse,10);
175
+		$find = true;
176
+		//echo $body_parse."\n";
177 177
 	}
178 178
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
180
-	    $find = true;
181
-	    //echo $body_parse."\n";
179
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
180
+		$find = true;
181
+		//echo $body_parse."\n";
182 182
 	}
183 183
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
185
-	    $find = true;
186
-	    //echo $body_parse."\n";
184
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
185
+		$find = true;
186
+		//echo $body_parse."\n";
187 187
 	}
188 188
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
189
-	    $find = true;
190
-	    //print_r($matches);
191
-	    $timestamp = $matches[0];
192
-	    if ($matches[4] == 'h') {
189
+		$find = true;
190
+		//print_r($matches);
191
+		$timestamp = $matches[0];
192
+		if ($matches[4] == 'h') {
193 193
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
194 194
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
195 195
 		/*
196 196
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
197 197
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
198 198
 		*/
199
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
199
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
200 200
 		// This work or not ?
201 201
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202
-	    }
203
-	    $body_parse = substr($body_parse,7);
204
-	    $result['timestamp'] = $timestamp;
205
-	    //echo date('Ymd H:i:s',$timestamp);
202
+		}
203
+		$body_parse = substr($body_parse,7);
204
+		$result['timestamp'] = $timestamp;
205
+		//echo date('Ymd H:i:s',$timestamp);
206 206
 	}
207 207
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
208
-	    $find = true;
209
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
211
-	    $result['timestamp'] = $timestamp;
212
-	    //echo date('Ymd H:i:s',$timestamp);
208
+		$find = true;
209
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
+		$body_parse = substr($body_parse,8);
211
+		$result['timestamp'] = $timestamp;
212
+		//echo date('Ymd H:i:s',$timestamp);
213 213
 	}
214 214
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
-	    $find = true;
215
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
+		$find = true;
217 217
 		// 4658.70N/00707.78Ez
218 218
 		//print_r(str_split($body_parse));
219 219
 		
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		$lon = intval($lon_deg);
231 231
 		if ($lat > 89 || $lon > 179) return false;
232 232
 	    
233
-	    /*
233
+		/*
234 234
 	    $tmp_5b = str_replace('.','',$lat_min);
235 235
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
236 236
 	        print_r($matches);
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 		$result['longitude'] = $longitude;
245 245
 		$body_parse = substr($body_parse,18);
246 246
 		$body_parse_len = strlen($body_parse);
247
-	    }
248
-	    $body_parse_len = strlen($body_parse);
249
-	    if ($body_parse_len > 0) {
247
+		}
248
+		$body_parse_len = strlen($body_parse);
249
+		if ($body_parse_len > 0) {
250 250
 		/*
251 251
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
252 252
 			$body_split = str_split($body);
@@ -276,86 +276,86 @@  discard block
 block discarded – undo
276 276
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
277 277
 			if ($symbol_code != '_') {
278 278
 			}
279
-		    //$body_parse = substr($body_parse,1);
280
-		    //$body_parse = trim($body_parse);
281
-		    //$body_parse_len = strlen($body_parse);
282
-		    if ($body_parse_len >= 7) {
279
+			//$body_parse = substr($body_parse,1);
280
+			//$body_parse = trim($body_parse);
281
+			//$body_parse_len = strlen($body_parse);
282
+			if ($body_parse_len >= 7) {
283 283
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
286
-		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
289
-		    	    if ($speed != '...') {
290
-		    		//$result['speed'] = round($speed*1.852);
291
-		    		$result['speed'] = intval($speed);
292
-		    	    }
293
-		    	    $body_parse = substr($body_parse,7);
294
-		        }
295
-		        // Check PHGR, PHG, RNG
296
-		    } 
297
-		    /*
284
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
+					$course = substr($body_parse,0,3);
286
+					$tmp_s = intval($course);
287
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
+					$speed = substr($body_parse,4,3);
289
+					if ($speed != '...') {
290
+					//$result['speed'] = round($speed*1.852);
291
+					$result['speed'] = intval($speed);
292
+					}
293
+					$body_parse = substr($body_parse,7);
294
+				}
295
+				// Check PHGR, PHG, RNG
296
+			} 
297
+			/*
298 298
 		    else if ($body_parse_len > 0) {
299 299
 			$rest = $body_parse;
300 300
 		    }
301 301
 		    */
302
-		    if (strlen($body_parse) > 0) {
303
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
-		            $altitude = intval($matches[1]);
305
-		            //$result['altitude'] = round($altitude*0.3048);
306
-		            $result['altitude'] = $altitude;
307
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
-		        }
310
-		    }
302
+			if (strlen($body_parse) > 0) {
303
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
304
+					$altitude = intval($matches[1]);
305
+					//$result['altitude'] = round($altitude*0.3048);
306
+					$result['altitude'] = $altitude;
307
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
309
+				}
310
+			}
311 311
 		    
312
-		    // Telemetry
313
-		    /*
312
+			// Telemetry
313
+			/*
314 314
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
315 315
 		        // Nothing yet...
316 316
 		    }
317 317
 		    */
318
-		    // DAO
319
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
-			    $dao = $matches[1];
321
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
318
+			// DAO
319
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
+				$dao = $matches[1];
321
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
322 322
 				$dao_split = str_split($dao);
323
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
323
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325 325
 			    
326 326
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327 327
 				else $result['latitude'] += $lat_off;
328 328
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329 329
 				else $result['longitude'] += $lon_off;
330
-			    }
331
-		            $body_parse = substr($body_parse,6);
332
-		    }
330
+				}
331
+					$body_parse = substr($body_parse,6);
332
+			}
333 333
 		    
334
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
334
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
335 335
 			$result['ident'] = $matches[1];
336
-		    }
337
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
336
+			}
337
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
338 338
 			$result['squawk'] = $matches[1];
339
-		    }
340
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
339
+			}
340
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
341 341
 			$result['aircraft_icao'] = $matches[1];
342
-		    }
343
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
342
+			}
343
+			if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
344 344
 			$result['typeid'] = $matches[1];
345
-		    }
346
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
345
+			}
346
+			if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
347 347
 			$result['imo'] = $matches[1];
348
-		    }
349
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
348
+			}
349
+			if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
350 350
 			$result['arrival_date'] = $matches[1];
351
-		    }
352
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
351
+			}
352
+			if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
353 353
 			$result['arrival_code'] = $matches[1];
354
-		    }
355
-		    // OGN comment
354
+			}
355
+			// OGN comment
356 356
 		   // echo "Before OGN : ".$body_parse."\n";
357
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
357
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
359 359
 			$id = $matches[1];
360 360
 			//$mode = substr($id,0,2);
361 361
 			$address = substr($id,2);
@@ -385,53 +385,53 @@  discard block
 block discarded – undo
385 385
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
386 386
 			$result['stealth'] = $stealth;
387 387
 			$result['address'] = $address;
388
-		    }
388
+			}
389 389
 		    
390
-		    //Comment
391
-		    $result['comment'] = trim($body_parse);
390
+			//Comment
391
+			$result['comment'] = trim($body_parse);
392 392
 		} else {
393
-		    // parse weather
394
-		    //$body_parse = substr($body_parse,1);
395
-		    //$body_parse_len = strlen($body_parse);
393
+			// parse weather
394
+			//$body_parse = substr($body_parse,1);
395
+			//$body_parse_len = strlen($body_parse);
396 396
 
397
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
-			    $result['wind_dir'] = intval($matches[1]);
399
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
403
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
397
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
+				$result['wind_dir'] = intval($matches[1]);
399
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
403
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
404 404
 			$result['wind_dir'] = intval($matches[1]);
405 405
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
406 406
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
407 407
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
408
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
409
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
408
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
409
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
410 410
 			$result['wind_dir'] = intval($matches[1]);
411 411
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
412 412
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
413
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
414
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
415 415
 			$result['wind_dir'] = intval($matches[1]);
416 416
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
417 417
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
418
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
419
-		    }
420
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
418
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
419
+			}
420
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
421 421
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
422
-		    }
422
+			}
423 423
 		}
424 424
 		} else $result['comment'] = trim($body_parse);
425 425
 
426
-	    }
426
+		}
427 427
 	//}
428 428
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429 429
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430 430
 	if ($debug) print_r($result);
431 431
 	return $result;
432
-    }
432
+	}
433 433
     
434
-    function connect() {
434
+	function connect() {
435 435
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
436 436
 	$aprs_connect = 0;
437 437
 	$aprs_keep = 120;
@@ -454,24 +454,24 @@  discard block
 block discarded – undo
454 454
 		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
455 455
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
456 456
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
457
-			    echo 'APRS user verified !'."\n";
458
-			    $this->connected = true;
459
-			    return true;
460
-			    break;
457
+				echo 'APRS user verified !'."\n";
458
+				$this->connected = true;
459
+				return true;
460
+				break;
461 461
 			}
462 462
 			if (time()-$authstart > 5) {
463
-			    echo 'APRS timeout'."\n";
464
-			    break;
463
+				echo 'APRS timeout'."\n";
464
+				break;
465 465
 			}
466 466
 		}
467 467
 	}
468
-    }
468
+	}
469 469
     
470
-    function send($data) {
470
+	function send($data) {
471 471
 	if ($this->connected === false) $this->connect();
472 472
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
473 473
 	if ($send === FALSE) $this->connect();
474
-    }
474
+	}
475 475
 }
476 476
 
477 477
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Spacing   +95 added lines, -96 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 	
91 91
 
92 92
     private function urshift($n, $s) {
93
-	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
93
+	return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| 
95 94
 		(0x40000000 >> ($s - 1));
96 95
     }
97 96
 
@@ -103,7 +102,7 @@  discard block
 block discarded – undo
103 102
 	//$split_input = str_split($input);
104 103
 
105 104
 	/* Find the end of header checking for NULL bytes while doing it. */
106
-	$splitpos = strpos($input,':');
105
+	$splitpos = strpos($input, ':');
107 106
 	
108 107
 	/* Check that end was found and body has at least one byte. */
109 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
@@ -113,15 +112,15 @@  discard block
 block discarded – undo
113 112
 	
114 113
 	if ($debug) echo 'input : '.$input."\n";
115 114
 	/* Save header and body. */
116
-	$body = substr($input,$splitpos+1,$input_len);
115
+	$body = substr($input, $splitpos + 1, $input_len);
117 116
 	$body_len = strlen($body);
118
-	$header = substr($input,0,$splitpos);
117
+	$header = substr($input, 0, $splitpos);
119 118
 	//$header_len = strlen($header);
120 119
 	if ($debug) echo 'header : '.$header."\n";
121 120
 	
122 121
 	/* Parse source, target and path. */
123 122
 	//FLRDF0A52>APRS,qAS,LSTB
124
-	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
123
+	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) {
125 124
 	    $ident = $matches[1];
126 125
 	    $all_elements = $matches[2];
127 126
 	    if ($ident == 'AIRCRAFT') {
@@ -135,14 +134,14 @@  discard block
 block discarded – undo
135 134
 		$result['ident'] = $ident;
136 135
 	    }
137 136
 	} else return false;
138
-	$elements = explode(',',$all_elements);
137
+	$elements = explode(',', $all_elements);
139 138
 	$source = end($elements);
140 139
 	$result['source'] = $source;
141 140
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
141
+	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) {
143 142
 	        //echo "ok";
144 143
 	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
144
+	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) {
146 145
 		if ($debug) echo 'element : '.$element."\n";
147 146
 		return false;
148 147
 	    }
@@ -155,12 +154,12 @@  discard block
 block discarded – undo
155 154
 	    */
156 155
 	}
157 156
 	
158
-	$type = substr($body,0,1);
157
+	$type = substr($body, 0, 1);
159 158
 	if ($debug) echo 'type : '.$type."\n";
160 159
 	if ($type == ';') {
161 160
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162
-			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
161
+			$result['address'] = trim(substr($body, 1, 9));
162
+		} else $result['ident'] = trim(substr($body, 1, 9));
164 163
 	} elseif ($type == ',') {
165 164
 		// Invalid data or test data
166 165
 		return false;
@@ -168,24 +167,24 @@  discard block
 block discarded – undo
168 167
 	
169 168
 	// Check for Timestamp
170 169
 	$find = false;
171
-	$body_parse = substr($body,1);
170
+	$body_parse = substr($body, 1);
172 171
 	//echo 'Body : '.$body."\n";
173
-	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
172
+	if (preg_match('/^;(.){9}\*/', $body, $matches)) {
173
+	    $body_parse = substr($body_parse, 10);
175 174
 	    $find = true;
176 175
 	    //echo $body_parse."\n";
177 176
 	}
178
-	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
177
+	if (preg_match('/^`(.*)\//', $body, $matches)) {
178
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
180 179
 	    $find = true;
181 180
 	    //echo $body_parse."\n";
182 181
 	}
183
-	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
182
+	if (preg_match("/^'(.*)\//", $body, $matches)) {
183
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
185 184
 	    $find = true;
186 185
 	    //echo $body_parse."\n";
187 186
 	}
188
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
187
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) {
189 188
 	    $find = true;
190 189
 	    //print_r($matches);
191 190
 	    $timestamp = $matches[0];
@@ -200,19 +199,19 @@  discard block
 block discarded – undo
200 199
 		// This work or not ?
201 200
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202 201
 	    }
203
-	    $body_parse = substr($body_parse,7);
202
+	    $body_parse = substr($body_parse, 7);
204 203
 	    $result['timestamp'] = $timestamp;
205 204
 	    //echo date('Ymd H:i:s',$timestamp);
206 205
 	}
207
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
206
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) {
208 207
 	    $find = true;
209 208
 	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
209
+	    $body_parse = substr($body_parse, 8);
211 210
 	    $result['timestamp'] = $timestamp;
212 211
 	    //echo date('Ymd H:i:s',$timestamp);
213 212
 	}
214 213
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
214
+	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) {
216 215
 	    $find = true;
217 216
 		// 4658.70N/00707.78Ez
218 217
 		//print_r(str_split($body_parse));
@@ -238,11 +237,11 @@  discard block
 block discarded – undo
238 237
 	    */
239 238
 		$latitude = $lat + floatval($lat_min)/60;
240 239
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
240
+		if ($sind == 'S') $latitude = 0 - $latitude;
241
+		if ($wind == 'W') $longitude = 0 - $longitude;
243 242
 		$result['latitude'] = $latitude;
244 243
 		$result['longitude'] = $longitude;
245
-		$body_parse = substr($body_parse,18);
244
+		$body_parse = substr($body_parse, 18);
246 245
 		$body_parse_len = strlen($body_parse);
247 246
 	    }
248 247
 	    $body_parse_len = strlen($body_parse);
@@ -270,7 +269,7 @@  discard block
 block discarded – undo
270 269
 		//echo $body_parse;
271 270
 			//if ($type != ';' && $type != '>') {
272 271
 			if ($type != '') {
273
-			$body_parse = substr($body_parse,1);
272
+			$body_parse = substr($body_parse, 1);
274 273
 			$body_parse_len = strlen($body_parse);
275 274
 			$result['symbol_code'] = $symbol_code;
276 275
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
@@ -281,16 +280,16 @@  discard block
 block discarded – undo
281 280
 		    //$body_parse_len = strlen($body_parse);
282 281
 		    if ($body_parse_len >= 7) {
283 282
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
283
+		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) {
284
+		    	    $course = substr($body_parse, 0, 3);
286 285
 		    	    $tmp_s = intval($course);
287 286
 		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
287
+		    	    $speed = substr($body_parse, 4, 3);
289 288
 		    	    if ($speed != '...') {
290 289
 		    		//$result['speed'] = round($speed*1.852);
291 290
 		    		$result['speed'] = intval($speed);
292 291
 		    	    }
293
-		    	    $body_parse = substr($body_parse,7);
292
+		    	    $body_parse = substr($body_parse, 7);
294 293
 		        }
295 294
 		        // Check PHGR, PHG, RNG
296 295
 		    } 
@@ -300,12 +299,12 @@  discard block
 block discarded – undo
300 299
 		    }
301 300
 		    */
302 301
 		    if (strlen($body_parse) > 0) {
303
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
302
+		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) {
304 303
 		            $altitude = intval($matches[1]);
305 304
 		            //$result['altitude'] = round($altitude*0.3048);
306 305
 		            $result['altitude'] = $altitude;
307 306
 		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
308
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
307
+		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse));
309 308
 		        }
310 309
 		    }
311 310
 		    
@@ -316,56 +315,56 @@  discard block
 block discarded – undo
316 315
 		    }
317 316
 		    */
318 317
 		    // DAO
319
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
318
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
320 319
 			    $dao = $matches[1];
321
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
320
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
322 321
 				$dao_split = str_split($dao);
323
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
322
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
323
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
325 324
 			    
326 325
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327 326
 				else $result['latitude'] += $lat_off;
328 327
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329 328
 				else $result['longitude'] += $lon_off;
330 329
 			    }
331
-		            $body_parse = substr($body_parse,6);
330
+		            $body_parse = substr($body_parse, 6);
332 331
 		    }
333 332
 		    
334
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
333
+		    if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) {
335 334
 			$result['ident'] = $matches[1];
336 335
 		    }
337
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
336
+		    if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) {
338 337
 			$result['squawk'] = $matches[1];
339 338
 		    }
340
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
339
+		    if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) {
341 340
 			$result['aircraft_icao'] = $matches[1];
342 341
 		    }
343
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
342
+		    if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) {
344 343
 			$result['typeid'] = $matches[1];
345 344
 		    }
346
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
345
+		    if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) {
347 346
 			$result['imo'] = $matches[1];
348 347
 		    }
349
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
348
+		    if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) {
350 349
 			$result['arrival_date'] = $matches[1];
351 350
 		    }
352
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
351
+		    if (preg_match('/AC=([0-9A-Z]*)/', $body_parse, $matches)) {
353 352
 			$result['arrival_code'] = $matches[1];
354 353
 		    }
355 354
 		    // OGN comment
356 355
 		   // echo "Before OGN : ".$body_parse."\n";
357 356
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
358
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
357
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
359 358
 			$id = $matches[1];
360 359
 			//$mode = substr($id,0,2);
361
-			$address = substr($id,2);
360
+			$address = substr($id, 2);
362 361
 			//print_r($matches);
363
-			$addressType = (intval(substr($id,0,2),16))&3;
362
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
364 363
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
365 364
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
366 365
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
367 366
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
368
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
367
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
369 368
 			$result['aircrafttype_code'] = $aircraftType;
370 369
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
371 370
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -382,7 +381,7 @@  discard block
 block discarded – undo
382 381
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
383 382
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
384 383
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
385
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
384
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
386 385
 			$result['stealth'] = $stealth;
387 386
 			$result['address'] = $address;
388 387
 		    }
@@ -394,72 +393,72 @@  discard block
 block discarded – undo
394 393
 		    //$body_parse = substr($body_parse,1);
395 394
 		    //$body_parse_len = strlen($body_parse);
396 395
 
397
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
396
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
398 397
 			    $result['wind_dir'] = intval($matches[1]);
399
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
400
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
401
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
402
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
403
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
398
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
399
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
400
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
401
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
402
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
404 403
 			$result['wind_dir'] = intval($matches[1]);
405
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
406
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
407
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
408
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
409
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
404
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
405
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
406
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
407
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
408
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
410 409
 			$result['wind_dir'] = intval($matches[1]);
411
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
412
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
413
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
410
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
411
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
412
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
413
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
415 414
 			$result['wind_dir'] = intval($matches[1]);
416
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
417
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
418
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
415
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
416
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
417
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
419 418
 		    }
420
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
421
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
419
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
420
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
422 421
 		    }
423 422
 		}
424 423
 		} else $result['comment'] = trim($body_parse);
425 424
 
426 425
 	    }
427 426
 	//}
428
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
427
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
428
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
430 429
 	if ($debug) print_r($result);
431 430
 	return $result;
432 431
     }
433 432
     
434 433
     function connect() {
435
-	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
434
+	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport;
436 435
 	$aprs_connect = 0;
437 436
 	$aprs_keep = 120;
438 437
 	$aprs_last_tx = time();
439 438
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
440
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
439
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
441 440
 	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
442
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
441
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
443 442
 	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
444 443
 	else $aprs_pass = '-1';
445 444
 	
446
-	$aprs_filter  = '';
445
+	$aprs_filter = '';
447 446
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
448 447
 	$Common = new Common();
449
-	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
448
+	$s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr);
450 449
 	if ($s !== false) {
451 450
 		echo 'Connected to APRS server! '."\n";
452 451
 		$authstart = time();
453 452
 		$this->socket = $s;
454
-		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
455
-		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
453
+		$send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0);
454
+		while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) {
456 455
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
457 456
 			    echo 'APRS user verified !'."\n";
458 457
 			    $this->connected = true;
459 458
 			    return true;
460 459
 			    break;
461 460
 			}
462
-			if (time()-$authstart > 5) {
461
+			if (time() - $authstart > 5) {
463 462
 			    echo 'APRS timeout'."\n";
464 463
 			    break;
465 464
 			}
@@ -469,20 +468,20 @@  discard block
 block discarded – undo
469 468
     
470 469
     function send($data) {
471 470
 	if ($this->connected === false) $this->connect();
472
-	$send = socket_send( $this->socket  , $data , strlen($data),0);
471
+	$send = socket_send($this->socket, $data, strlen($data), 0);
473 472
 	if ($send === FALSE) $this->connect();
474 473
     }
475 474
 }
476 475
 
477 476
 class APRSSpotter extends APRS {
478
-	function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
477
+	function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) {
479 478
 		$Common = new Common();
480 479
 		if ($latitude != '' && $longitude != '') {
481
-			$latitude = $Common->convertDM($latitude,'latitude');
482
-			$longitude = $Common->convertDM($longitude,'longitude');
483
-			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
484
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
485
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
480
+			$latitude = $Common->convertDM($latitude, 'latitude');
481
+			$longitude = $Common->convertDM($longitude, 'longitude');
482
+			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
483
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
484
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
486 485
 			$w = $w1.$w2;
487 486
 			//$w = '00';
488 487
 			$custom = '';
@@ -499,19 +498,19 @@  discard block
 block discarded – undo
499 498
 				$custom .= 'AI='.$aircraft_icao;
500 499
 			}
501 500
 			if ($custom != '') $custom = ' '.$custom;
502
-			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
501
+			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His', strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
503 502
 		}
504 503
 	}
505 504
 }
506 505
 class APRSMarine extends APRS {
507
-	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
506
+	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) {
508 507
 		$Common = new Common();
509 508
 		if ($latitude != '' && $longitude != '') {
510
-			$latitude = $Common->convertDM($latitude,'latitude');
511
-			$longitude = $Common->convertDM($longitude,'longitude');
512
-			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
513
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
514
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
509
+			$latitude = $Common->convertDM($latitude, 'latitude');
510
+			$longitude = $Common->convertDM($longitude, 'longitude');
511
+			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
512
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
513
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
515 514
 			$w = $w1.$w2;
516 515
 			//$w = '00';
517 516
 			$custom = '';
@@ -537,7 +536,7 @@  discard block
 block discarded – undo
537 536
 			}
538 537
 			if ($custom != '') $custom = ' '.$custom;
539 538
 			$altitude = 0;
540
-			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
539
+			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
541 540
 		}
542 541
 	}
543 542
 }
Please login to merge, or discard this patch.
Braces   +152 added lines, -58 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,11 +168,15 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
177
+		} else {
178
+			$result['ident'] = trim(substr($body,1,9));
179
+		}
164 180
 	} elseif ($type == ',') {
165 181
 		// Invalid data or test data
166 182
 		return false;
@@ -228,7 +244,9 @@  discard block
 block discarded – undo
228 244
 		//$symbol_table = $matches[4];
229 245
 		$lat = intval($lat_deg);
230 246
 		$lon = intval($lon_deg);
231
-		if ($lat > 89 || $lon > 179) return false;
247
+		if ($lat > 89 || $lon > 179) {
248
+			return false;
249
+		}
232 250
 	    
233 251
 	    /*
234 252
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -238,8 +256,12 @@  discard block
 block discarded – undo
238 256
 	    */
239 257
 		$latitude = $lat + floatval($lat_min)/60;
240 258
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
259
+		if ($sind == 'S') {
260
+			$latitude = 0-$latitude;
261
+		}
262
+		if ($wind == 'W') {
263
+			$longitude = 0-$longitude;
264
+		}
243 265
 		$result['latitude'] = $latitude;
244 266
 		$result['longitude'] = $longitude;
245 267
 		$body_parse = substr($body_parse,18);
@@ -273,7 +295,9 @@  discard block
 block discarded – undo
273 295
 			$body_parse = substr($body_parse,1);
274 296
 			$body_parse_len = strlen($body_parse);
275 297
 			$result['symbol_code'] = $symbol_code;
276
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
298
+			if (isset($this->symbols[$symbol_code])) {
299
+				$result['symbol'] = $this->symbols[$symbol_code];
300
+			}
277 301
 			if ($symbol_code != '_') {
278 302
 			}
279 303
 		    //$body_parse = substr($body_parse,1);
@@ -284,7 +308,9 @@  discard block
 block discarded – undo
284 308
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285 309
 		    	    $course = substr($body_parse,0,3);
286 310
 		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
311
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
312
+		    	    	$result['heading'] = intval($course);
313
+		    	    }
288 314
 		    	    $speed = substr($body_parse,4,3);
289 315
 		    	    if ($speed != '...') {
290 316
 		    		//$result['speed'] = round($speed*1.852);
@@ -323,10 +349,16 @@  discard block
 block discarded – undo
323 349
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
324 350
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325 351
 			    
326
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
327
-				else $result['latitude'] += $lat_off;
328
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
329
-				else $result['longitude'] += $lon_off;
352
+				if ($result['latitude'] < 0) {
353
+					$result['latitude'] -= $lat_off;
354
+				} else {
355
+					$result['latitude'] += $lat_off;
356
+				}
357
+				if ($result['longitude'] < 0) {
358
+					$result['longitude'] -= $lon_off;
359
+				} else {
360
+					$result['longitude'] += $lon_off;
361
+				}
330 362
 			    }
331 363
 		            $body_parse = substr($body_parse,6);
332 364
 		    }
@@ -361,27 +393,48 @@  discard block
 block discarded – undo
361 393
 			$address = substr($id,2);
362 394
 			//print_r($matches);
363 395
 			$addressType = (intval(substr($id,0,2),16))&3;
364
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
365
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
366
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
367
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
396
+			if ($addressType == 0) {
397
+				$result['addresstype'] = "RANDOM";
398
+			} elseif ($addressType == 1) {
399
+				$result['addresstype'] = "ICAO";
400
+			} elseif ($addressType == 2) {
401
+				$result['addresstype'] = "FLARM";
402
+			} elseif ($addressType == 3) {
403
+				$result['addresstype'] = "OGN";
404
+			}
368 405
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
369 406
 			$result['aircrafttype_code'] = $aircraftType;
370
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
371
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
372
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
373
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
374
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
375
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
376
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
377
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
378
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
379
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
380
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
381
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
382
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
383
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
384
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
407
+			if ($aircraftType == 0) {
408
+				$result['aircrafttype'] = "UNKNOWN";
409
+			} elseif ($aircraftType == 1) {
410
+				$result['aircrafttype'] = "GLIDER";
411
+			} elseif ($aircraftType == 2) {
412
+				$result['aircrafttype'] = "TOW_PLANE";
413
+			} elseif ($aircraftType == 3) {
414
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
415
+			} elseif ($aircraftType == 4) {
416
+				$result['aircrafttype'] = "PARACHUTE";
417
+			} elseif ($aircraftType == 5) {
418
+				$result['aircrafttype'] = "DROP_PLANE";
419
+			} elseif ($aircraftType == 6) {
420
+				$result['aircrafttype'] = "HANG_GLIDER";
421
+			} elseif ($aircraftType == 7) {
422
+				$result['aircrafttype'] = "PARA_GLIDER";
423
+			} elseif ($aircraftType == 8) {
424
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
425
+			} elseif ($aircraftType == 9) {
426
+				$result['aircrafttype'] = "JET_AIRCRAFT";
427
+			} elseif ($aircraftType == 10) {
428
+				$result['aircrafttype'] = "UFO";
429
+			} elseif ($aircraftType == 11) {
430
+				$result['aircrafttype'] = "BALLOON";
431
+			} elseif ($aircraftType == 12) {
432
+				$result['aircrafttype'] = "AIRSHIP";
433
+			} elseif ($aircraftType == 13) {
434
+				$result['aircrafttype'] = "UAV";
435
+			} elseif ($aircraftType == 15) {
436
+				$result['aircrafttype'] = "STATIC_OBJECT";
437
+			}
385 438
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
386 439
 			$result['stealth'] = $stealth;
387 440
 			$result['address'] = $address;
@@ -421,13 +474,21 @@  discard block
 block discarded – undo
421 474
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
422 475
 		    }
423 476
 		}
424
-		} else $result['comment'] = trim($body_parse);
477
+		} else {
478
+			$result['comment'] = trim($body_parse);
479
+		}
425 480
 
426 481
 	    }
427 482
 	//}
428
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
429
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430
-	if ($debug) print_r($result);
483
+	if (isset($result['latitude'])) {
484
+		$result['latitude'] = round($result['latitude'],4);
485
+	}
486
+	if (isset($result['longitude'])) {
487
+		$result['longitude'] = round($result['longitude'],4);
488
+	}
489
+	if ($debug) {
490
+		print_r($result);
491
+	}
431 492
 	return $result;
432 493
     }
433 494
     
@@ -436,12 +497,21 @@  discard block
 block discarded – undo
436 497
 	$aprs_connect = 0;
437 498
 	$aprs_keep = 120;
438 499
 	$aprs_last_tx = time();
439
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
440
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
441
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
442
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
443
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
444
-	else $aprs_pass = '-1';
500
+	if (isset($globalAPRSversion)) {
501
+		$aprs_version = $globalAPRSversion;
502
+	} else {
503
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
504
+	}
505
+	if (isset($globalServerAPRSssid)) {
506
+		$aprs_ssid = $globalServerAPRSssid;
507
+	} else {
508
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
509
+	}
510
+	if (isset($globalServerAPRSpass)) {
511
+		$aprs_pass = $globalServerAPRSpass;
512
+	} else {
513
+		$aprs_pass = '-1';
514
+	}
445 515
 	
446 516
 	$aprs_filter  = '';
447 517
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -468,9 +538,13 @@  discard block
 block discarded – undo
468 538
     }
469 539
     
470 540
     function send($data) {
471
-	if ($this->connected === false) $this->connect();
541
+	if ($this->connected === false) {
542
+		$this->connect();
543
+	}
472 544
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
473
-	if ($send === FALSE) $this->connect();
545
+	if ($send === FALSE) {
546
+		$this->connect();
547
+	}
474 548
     }
475 549
 }
476 550
 
@@ -487,18 +561,26 @@  discard block
 block discarded – undo
487 561
 			//$w = '00';
488 562
 			$custom = '';
489 563
 			if ($ident != '') {
490
-				if ($custom != '') $custom .= '/';
564
+				if ($custom != '') {
565
+					$custom .= '/';
566
+				}
491 567
 				$custom .= 'CS='.$ident;
492 568
 			}
493 569
 			if ($squawk != '') {
494
-				if ($custom != '') $custom .= '/';
570
+				if ($custom != '') {
571
+					$custom .= '/';
572
+				}
495 573
 				$custom .= 'SQ='.$squawk;
496 574
 			}
497 575
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
498
-				if ($custom != '') $custom .= '/';
576
+				if ($custom != '') {
577
+					$custom .= '/';
578
+				}
499 579
 				$custom .= 'AI='.$aircraft_icao;
500 580
 			}
501
-			if ($custom != '') $custom = ' '.$custom;
581
+			if ($custom != '') {
582
+				$custom = ' '.$custom;
583
+			}
502 584
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
503 585
 		}
504 586
 	}
@@ -516,26 +598,38 @@  discard block
 block discarded – undo
516 598
 			//$w = '00';
517 599
 			$custom = '';
518 600
 			if ($ident != '') {
519
-				if ($custom != '') $custom .= '/';
601
+				if ($custom != '') {
602
+					$custom .= '/';
603
+				}
520 604
 				$custom .= 'CS='.$ident;
521 605
 			}
522 606
 			if ($typeid != '') {
523
-				if ($custom != '') $custom .= '/';
607
+				if ($custom != '') {
608
+					$custom .= '/';
609
+				}
524 610
 				$custom .= 'TI='.$typeid;
525 611
 			}
526 612
 			if ($imo != '') {
527
-				if ($custom != '') $custom .= '/';
613
+				if ($custom != '') {
614
+					$custom .= '/';
615
+				}
528 616
 				$custom .= 'IMO='.$imo;
529 617
 			}
530 618
 			if ($arrival_date != '') {
531
-				if ($custom != '') $custom .= '/';
619
+				if ($custom != '') {
620
+					$custom .= '/';
621
+				}
532 622
 				$custom .= 'AD='.strtotime($arrival_date);
533 623
 			}
534 624
 			if ($arrival_code != '') {
535
-				if ($custom != '') $custom .= '/';
625
+				if ($custom != '') {
626
+					$custom .= '/';
627
+				}
536 628
 				$custom .= 'AC='.$arrival_code;
537 629
 			}
538
-			if ($custom != '') $custom = ' '.$custom;
630
+			if ($custom != '') {
631
+				$custom = ' '.$custom;
632
+			}
539 633
 			$altitude = 0;
540 634
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
541 635
 		}
Please login to merge, or discard this patch.