Completed
Push — master ( 873309...5e8324 )
by Yannick
06:25
created
require/class.APRS.php 4 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -89,6 +89,10 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
+    /**
93
+     * @param integer $n
94
+     * @param integer $s
95
+     */
92 96
     private function urshift($n, $s) {
93 97
 	return ($n >= 0) ? ($n >> $s) :
94 98
 	    (($n & 0x7fffffff) >> $s) | 
@@ -475,6 +479,9 @@  discard block
 block discarded – undo
475 479
 	socket_close($this->socket);
476 480
     }
477 481
     
482
+    /**
483
+     * @param string $data
484
+     */
478 485
     public function send($data) {
479 486
 	if ($this->connected === false) $this->connect();
480 487
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
Please login to merge, or discard this patch.
Indentation   +140 added lines, -140 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,89 +276,89 @@  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
318
+			// DAO
319 319
 		    
320
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
320
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
321 321
 			    
322
-			    $dao = $matches[1];
323
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
322
+				$dao = $matches[1];
323
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
324 324
 				$dao_split = str_split($dao);
325
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
326
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
325
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
326
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
327 327
 			    
328 328
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
329 329
 				else $result['latitude'] += $lat_off;
330 330
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
331 331
 				else $result['longitude'] += $lon_off;
332
-			    }
332
+				}
333 333
 			    
334
-		            $body_parse = substr($body_parse,6);
335
-		    }
334
+					$body_parse = substr($body_parse,6);
335
+			}
336 336
 		    
337
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
337
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
338 338
 			$result['ident'] = $matches[1];
339
-		    }
340
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
339
+			}
340
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
341 341
 			$result['squawk'] = $matches[1];
342
-		    }
343
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
342
+			}
343
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
344 344
 			$result['aircraft_icao'] = $matches[1];
345
-		    }
346
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
345
+			}
346
+			if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
347 347
 			$result['typeid'] = $matches[1];
348
-		    }
349
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
348
+			}
349
+			if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
350 350
 			$result['imo'] = $matches[1];
351
-		    }
352
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
351
+			}
352
+			if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
353 353
 			$result['arrival_date'] = $matches[1];
354
-		    }
355
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
354
+			}
355
+			if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
356 356
 			$result['arrival_code'] = $matches[1];
357
-		    }
358
-		    // OGN comment
357
+			}
358
+			// OGN comment
359 359
 		   // echo "Before OGN : ".$body_parse."\n";
360
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
361
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
360
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
361
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
362 362
 			$id = $matches[1];
363 363
 			//$mode = substr($id,0,2);
364 364
 			$address = substr($id,2);
@@ -388,53 +388,53 @@  discard block
 block discarded – undo
388 388
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
389 389
 			$result['stealth'] = $stealth;
390 390
 			$result['address'] = $address;
391
-		    }
391
+			}
392 392
 		    
393
-		    //Comment
394
-		    $result['comment'] = trim($body_parse);
393
+			//Comment
394
+			$result['comment'] = trim($body_parse);
395 395
 		} else {
396
-		    // parse weather
397
-		    //$body_parse = substr($body_parse,1);
398
-		    //$body_parse_len = strlen($body_parse);
396
+			// parse weather
397
+			//$body_parse = substr($body_parse,1);
398
+			//$body_parse_len = strlen($body_parse);
399 399
 
400
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
401
-			    $result['wind_dir'] = intval($matches[1]);
402
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
403
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
404
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
405
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
406
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
400
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
401
+				$result['wind_dir'] = intval($matches[1]);
402
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
403
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
404
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
405
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
406
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
407 407
 			$result['wind_dir'] = intval($matches[1]);
408 408
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
409 409
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
410 410
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
411
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
412
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
411
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
412
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
413 413
 			$result['wind_dir'] = intval($matches[1]);
414 414
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
415 415
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
416
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
417
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
416
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
417
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
418 418
 			$result['wind_dir'] = intval($matches[1]);
419 419
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
420 420
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
421
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
422
-		    }
423
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
421
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
422
+			}
423
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
424 424
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
425
-		    }
425
+			}
426 426
 		}
427 427
 		} else $result['comment'] = trim($body_parse);
428 428
 
429
-	    }
429
+		}
430 430
 	//}
431 431
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
432 432
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
433 433
 	if ($debug) print_r($result);
434 434
 	return $result;
435
-    }
435
+	}
436 436
     
437
-    public function connect() {
437
+	public function connect() {
438 438
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
439 439
 	$aprs_connect = 0;
440 440
 	$aprs_keep = 120;
@@ -457,32 +457,32 @@  discard block
 block discarded – undo
457 457
 		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
458 458
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
459 459
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
460
-			    echo 'APRS user verified !'."\n";
461
-			    $this->connected = true;
462
-			    return true;
463
-			    break;
460
+				echo 'APRS user verified !'."\n";
461
+				$this->connected = true;
462
+				return true;
463
+				break;
464 464
 			}
465 465
 			if (time()-$authstart > 5) {
466
-			    echo 'APRS timeout'."\n";
467
-			    break;
466
+				echo 'APRS timeout'."\n";
467
+				break;
468 468
 			}
469 469
 		}
470 470
 		socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE);
471 471
 	}
472
-    }
472
+	}
473 473
 
474
-    public function disconnect() {
474
+	public function disconnect() {
475 475
 	socket_close($this->socket);
476
-    }
476
+	}
477 477
     
478
-    public function send($data) {
478
+	public function send($data) {
479 479
 	if ($this->connected === false) $this->connect();
480 480
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
481 481
 	if ($send === FALSE) {
482 482
 		socket_close($this->socket);
483 483
 		$this->connect();
484 484
 	}
485
-    }
485
+	}
486 486
 }
487 487
 
488 488
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Spacing   +96 added lines, -97 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
 		    
@@ -317,13 +316,13 @@  discard block
 block discarded – undo
317 316
 		    */
318 317
 		    // DAO
319 318
 		    
320
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
319
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
321 320
 			    
322 321
 			    $dao = $matches[1];
323
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
322
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
324 323
 				$dao_split = str_split($dao);
325
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
326
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
324
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
325
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
327 326
 			    
328 327
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
329 328
 				else $result['latitude'] += $lat_off;
@@ -331,44 +330,44 @@  discard block
 block discarded – undo
331 330
 				else $result['longitude'] += $lon_off;
332 331
 			    }
333 332
 			    
334
-		            $body_parse = substr($body_parse,6);
333
+		            $body_parse = substr($body_parse, 6);
335 334
 		    }
336 335
 		    
337
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
336
+		    if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) {
338 337
 			$result['ident'] = $matches[1];
339 338
 		    }
340
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
339
+		    if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) {
341 340
 			$result['squawk'] = $matches[1];
342 341
 		    }
343
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
342
+		    if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) {
344 343
 			$result['aircraft_icao'] = $matches[1];
345 344
 		    }
346
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
345
+		    if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) {
347 346
 			$result['typeid'] = $matches[1];
348 347
 		    }
349
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
348
+		    if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) {
350 349
 			$result['imo'] = $matches[1];
351 350
 		    }
352
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
351
+		    if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) {
353 352
 			$result['arrival_date'] = $matches[1];
354 353
 		    }
355
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
354
+		    if (preg_match('/AC=([0-9A-Z]*)/', $body_parse, $matches)) {
356 355
 			$result['arrival_code'] = $matches[1];
357 356
 		    }
358 357
 		    // OGN comment
359 358
 		   // echo "Before OGN : ".$body_parse."\n";
360 359
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
361
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
360
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
362 361
 			$id = $matches[1];
363 362
 			//$mode = substr($id,0,2);
364
-			$address = substr($id,2);
363
+			$address = substr($id, 2);
365 364
 			//print_r($matches);
366
-			$addressType = (intval(substr($id,0,2),16))&3;
365
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
367 366
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
368 367
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
369 368
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
370 369
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
371
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
370
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
372 371
 			$result['aircrafttype_code'] = $aircraftType;
373 372
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
374 373
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -385,7 +384,7 @@  discard block
 block discarded – undo
385 384
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
386 385
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
387 386
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
388
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
387
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
389 388
 			$result['stealth'] = $stealth;
390 389
 			$result['address'] = $address;
391 390
 		    }
@@ -397,77 +396,77 @@  discard block
 block discarded – undo
397 396
 		    //$body_parse = substr($body_parse,1);
398 397
 		    //$body_parse_len = strlen($body_parse);
399 398
 
400
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
399
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
401 400
 			    $result['wind_dir'] = intval($matches[1]);
402
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
403
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
404
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
405
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
406
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
401
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
402
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
403
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
404
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
405
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
407 406
 			$result['wind_dir'] = intval($matches[1]);
408
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
409
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
410
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
411
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
412
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
407
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
408
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
409
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
410
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
411
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
413 412
 			$result['wind_dir'] = intval($matches[1]);
414
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
415
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
416
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
417
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
413
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
414
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
415
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
416
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
418 417
 			$result['wind_dir'] = intval($matches[1]);
419
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
420
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
421
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
418
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
419
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
420
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
422 421
 		    }
423
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
424
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
422
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
423
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
425 424
 		    }
426 425
 		}
427 426
 		} else $result['comment'] = trim($body_parse);
428 427
 
429 428
 	    }
430 429
 	//}
431
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
432
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
430
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
431
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
433 432
 	if ($debug) print_r($result);
434 433
 	return $result;
435 434
     }
436 435
     
437 436
     public function connect() {
438
-	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
437
+	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport;
439 438
 	$aprs_connect = 0;
440 439
 	$aprs_keep = 120;
441 440
 	$aprs_last_tx = time();
442 441
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
443
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
442
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
444 443
 	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
445
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
444
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
446 445
 	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
447 446
 	else $aprs_pass = '-1';
448 447
 	
449
-	$aprs_filter  = '';
448
+	$aprs_filter = '';
450 449
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
451 450
 	$Common = new Common();
452
-	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
451
+	$s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr);
453 452
 	if ($s !== false) {
454 453
 		echo 'Connected to APRS server! '."\n";
455 454
 		$authstart = time();
456 455
 		$this->socket = $s;
457
-		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
458
-		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
456
+		$send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0);
457
+		while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) {
459 458
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
460 459
 			    echo 'APRS user verified !'."\n";
461 460
 			    $this->connected = true;
462 461
 			    return true;
463 462
 			    break;
464 463
 			}
465
-			if (time()-$authstart > 5) {
464
+			if (time() - $authstart > 5) {
466 465
 			    echo 'APRS timeout'."\n";
467 466
 			    break;
468 467
 			}
469 468
 		}
470
-		socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE);
469
+		socket_set_option($this->socket, SOL_SOCKET, SO_KEEPALIVE);
471 470
 	}
472 471
     }
473 472
 
@@ -477,7 +476,7 @@  discard block
 block discarded – undo
477 476
     
478 477
     public function send($data) {
479 478
 	if ($this->connected === false) $this->connect();
480
-	$send = socket_send( $this->socket  , $data , strlen($data),0);
479
+	$send = socket_send($this->socket, $data, strlen($data), 0);
481 480
 	if ($send === FALSE) {
482 481
 		socket_close($this->socket);
483 482
 		$this->connect();
@@ -486,14 +485,14 @@  discard block
 block discarded – undo
486 485
 }
487 486
 
488 487
 class APRSSpotter extends APRS {
489
-	public function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
488
+	public function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) {
490 489
 		$Common = new Common();
491 490
 		if ($latitude != '' && $longitude != '') {
492
-			$latitude = $Common->convertDM($latitude,'latitude');
493
-			$longitude = $Common->convertDM($longitude,'longitude');
494
-			$coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW'];
495
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
496
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
491
+			$latitude = $Common->convertDM($latitude, 'latitude');
492
+			$longitude = $Common->convertDM($longitude, 'longitude');
493
+			$coordinate = sprintf("%02d", $latitude['deg']).str_pad(number_format($latitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d", $longitude['deg']).str_pad(number_format($longitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$longitude['NSEW'];
494
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
495
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
497 496
 			$w = $w1.$w2;
498 497
 			//$w = '00';
499 498
 			$custom = '';
@@ -510,19 +509,19 @@  discard block
 block discarded – undo
510 509
 				$custom .= 'AI='.$aircraft_icao;
511 510
 			}
512 511
 			if ($custom != '') $custom = ' '.$custom;
513
-			$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");
512
+			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His', strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
514 513
 		}
515 514
 	}
516 515
 }
517 516
 class APRSMarine extends APRS {
518
-	public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
517
+	public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) {
519 518
 		$Common = new Common();
520 519
 		if ($latitude != '' && $longitude != '') {
521
-			$latitude = $Common->convertDM($latitude,'latitude');
522
-			$longitude = $Common->convertDM($longitude,'longitude');
523
-			$coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW'];
524
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
525
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
520
+			$latitude = $Common->convertDM($latitude, 'latitude');
521
+			$longitude = $Common->convertDM($longitude, 'longitude');
522
+			$coordinate = sprintf("%02d", $latitude['deg']).str_pad(number_format($latitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d", $longitude['deg']).str_pad(number_format($longitude['min'], 2, '.', ''), 5, '0', STR_PAD_LEFT).$longitude['NSEW'];
523
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
524
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
526 525
 			$w = $w1.$w2;
527 526
 			//$w = '00';
528 527
 			$custom = '';
@@ -548,7 +547,7 @@  discard block
 block discarded – undo
548 547
 			}
549 548
 			if ($custom != '') $custom = ' '.$custom;
550 549
 			$altitude = 0;
551
-			$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");
550
+			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
552 551
 		}
553 552
 	}
554 553
 }
Please login to merge, or discard this patch.
Braces   +149 added lines, -57 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,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);
@@ -325,10 +351,16 @@  discard block
 block discarded – undo
325 351
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
326 352
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
327 353
 			    
328
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
329
-				else $result['latitude'] += $lat_off;
330
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
331
-				else $result['longitude'] += $lon_off;
354
+				if ($result['latitude'] < 0) {
355
+					$result['latitude'] -= $lat_off;
356
+				} else {
357
+					$result['latitude'] += $lat_off;
358
+				}
359
+				if ($result['longitude'] < 0) {
360
+					$result['longitude'] -= $lon_off;
361
+				} else {
362
+					$result['longitude'] += $lon_off;
363
+				}
332 364
 			    }
333 365
 			    
334 366
 		            $body_parse = substr($body_parse,6);
@@ -364,27 +396,48 @@  discard block
 block discarded – undo
364 396
 			$address = substr($id,2);
365 397
 			//print_r($matches);
366 398
 			$addressType = (intval(substr($id,0,2),16))&3;
367
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
368
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
369
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
370
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
399
+			if ($addressType == 0) {
400
+				$result['addresstype'] = "RANDOM";
401
+			} elseif ($addressType == 1) {
402
+				$result['addresstype'] = "ICAO";
403
+			} elseif ($addressType == 2) {
404
+				$result['addresstype'] = "FLARM";
405
+			} elseif ($addressType == 3) {
406
+				$result['addresstype'] = "OGN";
407
+			}
371 408
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
372 409
 			$result['aircrafttype_code'] = $aircraftType;
373
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
374
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
375
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
376
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
377
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
378
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
379
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
380
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
381
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
382
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
383
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
384
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
385
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
386
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
387
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
410
+			if ($aircraftType == 0) {
411
+				$result['aircrafttype'] = "UNKNOWN";
412
+			} elseif ($aircraftType == 1) {
413
+				$result['aircrafttype'] = "GLIDER";
414
+			} elseif ($aircraftType == 2) {
415
+				$result['aircrafttype'] = "TOW_PLANE";
416
+			} elseif ($aircraftType == 3) {
417
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
418
+			} elseif ($aircraftType == 4) {
419
+				$result['aircrafttype'] = "PARACHUTE";
420
+			} elseif ($aircraftType == 5) {
421
+				$result['aircrafttype'] = "DROP_PLANE";
422
+			} elseif ($aircraftType == 6) {
423
+				$result['aircrafttype'] = "HANG_GLIDER";
424
+			} elseif ($aircraftType == 7) {
425
+				$result['aircrafttype'] = "PARA_GLIDER";
426
+			} elseif ($aircraftType == 8) {
427
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
428
+			} elseif ($aircraftType == 9) {
429
+				$result['aircrafttype'] = "JET_AIRCRAFT";
430
+			} elseif ($aircraftType == 10) {
431
+				$result['aircrafttype'] = "UFO";
432
+			} elseif ($aircraftType == 11) {
433
+				$result['aircrafttype'] = "BALLOON";
434
+			} elseif ($aircraftType == 12) {
435
+				$result['aircrafttype'] = "AIRSHIP";
436
+			} elseif ($aircraftType == 13) {
437
+				$result['aircrafttype'] = "UAV";
438
+			} elseif ($aircraftType == 15) {
439
+				$result['aircrafttype'] = "STATIC_OBJECT";
440
+			}
388 441
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
389 442
 			$result['stealth'] = $stealth;
390 443
 			$result['address'] = $address;
@@ -424,13 +477,21 @@  discard block
 block discarded – undo
424 477
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
425 478
 		    }
426 479
 		}
427
-		} else $result['comment'] = trim($body_parse);
480
+		} else {
481
+			$result['comment'] = trim($body_parse);
482
+		}
428 483
 
429 484
 	    }
430 485
 	//}
431
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
432
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
433
-	if ($debug) print_r($result);
486
+	if (isset($result['latitude'])) {
487
+		$result['latitude'] = round($result['latitude'],4);
488
+	}
489
+	if (isset($result['longitude'])) {
490
+		$result['longitude'] = round($result['longitude'],4);
491
+	}
492
+	if ($debug) {
493
+		print_r($result);
494
+	}
434 495
 	return $result;
435 496
     }
436 497
     
@@ -439,12 +500,21 @@  discard block
 block discarded – undo
439 500
 	$aprs_connect = 0;
440 501
 	$aprs_keep = 120;
441 502
 	$aprs_last_tx = time();
442
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
443
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
444
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
445
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
446
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
447
-	else $aprs_pass = '-1';
503
+	if (isset($globalAPRSversion)) {
504
+		$aprs_version = $globalAPRSversion;
505
+	} else {
506
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
507
+	}
508
+	if (isset($globalServerAPRSssid)) {
509
+		$aprs_ssid = $globalServerAPRSssid;
510
+	} else {
511
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
512
+	}
513
+	if (isset($globalServerAPRSpass)) {
514
+		$aprs_pass = $globalServerAPRSpass;
515
+	} else {
516
+		$aprs_pass = '-1';
517
+	}
448 518
 	
449 519
 	$aprs_filter  = '';
450 520
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -476,7 +546,9 @@  discard block
 block discarded – undo
476 546
     }
477 547
     
478 548
     public function send($data) {
479
-	if ($this->connected === false) $this->connect();
549
+	if ($this->connected === false) {
550
+		$this->connect();
551
+	}
480 552
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
481 553
 	if ($send === FALSE) {
482 554
 		socket_close($this->socket);
@@ -498,18 +570,26 @@  discard block
 block discarded – undo
498 570
 			//$w = '00';
499 571
 			$custom = '';
500 572
 			if ($ident != '') {
501
-				if ($custom != '') $custom .= '/';
573
+				if ($custom != '') {
574
+					$custom .= '/';
575
+				}
502 576
 				$custom .= 'CS='.$ident;
503 577
 			}
504 578
 			if ($squawk != '') {
505
-				if ($custom != '') $custom .= '/';
579
+				if ($custom != '') {
580
+					$custom .= '/';
581
+				}
506 582
 				$custom .= 'SQ='.$squawk;
507 583
 			}
508 584
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
509
-				if ($custom != '') $custom .= '/';
585
+				if ($custom != '') {
586
+					$custom .= '/';
587
+				}
510 588
 				$custom .= 'AI='.$aircraft_icao;
511 589
 			}
512
-			if ($custom != '') $custom = ' '.$custom;
590
+			if ($custom != '') {
591
+				$custom = ' '.$custom;
592
+			}
513 593
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
514 594
 		}
515 595
 	}
@@ -527,26 +607,38 @@  discard block
 block discarded – undo
527 607
 			//$w = '00';
528 608
 			$custom = '';
529 609
 			if ($ident != '') {
530
-				if ($custom != '') $custom .= '/';
610
+				if ($custom != '') {
611
+					$custom .= '/';
612
+				}
531 613
 				$custom .= 'CS='.$ident;
532 614
 			}
533 615
 			if ($typeid != '') {
534
-				if ($custom != '') $custom .= '/';
616
+				if ($custom != '') {
617
+					$custom .= '/';
618
+				}
535 619
 				$custom .= 'TI='.$typeid;
536 620
 			}
537 621
 			if ($imo != '') {
538
-				if ($custom != '') $custom .= '/';
622
+				if ($custom != '') {
623
+					$custom .= '/';
624
+				}
539 625
 				$custom .= 'IMO='.$imo;
540 626
 			}
541 627
 			if ($arrival_date != '') {
542
-				if ($custom != '') $custom .= '/';
628
+				if ($custom != '') {
629
+					$custom .= '/';
630
+				}
543 631
 				$custom .= 'AD='.strtotime($arrival_date);
544 632
 			}
545 633
 			if ($arrival_code != '') {
546
-				if ($custom != '') $custom .= '/';
634
+				if ($custom != '') {
635
+					$custom .= '/';
636
+				}
547 637
 				$custom .= 'AC='.$arrival_code;
548 638
 			}
549
-			if ($custom != '') $custom = ' '.$custom;
639
+			if ($custom != '') {
640
+				$custom = ' '.$custom;
641
+			}
550 642
 			$altitude = 0;
551 643
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
552 644
 		}
Please login to merge, or discard this patch.
incident.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3
-$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
3
+$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING);
4 4
 if ($date == '') $date = date('Y-m-d');
5 5
 header('Location: '.$globalURL.'/incident/'.$date);
6 6
 ?>
7 7
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3 3
 $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
4
-if ($date == '') $date = date('Y-m-d');
4
+if ($date == '') {
5
+	$date = date('Y-m-d');
6
+}
5 7
 header('Location: '.$globalURL.'/incident/'.$date);
6 8
 ?>
7 9
\ No newline at end of file
Please login to merge, or discard this patch.