Completed
Push — master ( 4c247d...ce17c6 )
by Yannick
07:53
created
require/class.SpotterLive.php 1 patch
Braces   +80 added lines, -27 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -118,8 +120,11 @@  discard block
 block discarded – undo
118 120
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
119 121
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
120 122
 		}
121
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
122
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
123
+		if ($filter_query_where == '' && $where) {
124
+			$filter_query_where = ' WHERE';
125
+		} elseif ($filter_query_where != '' && $and) {
126
+			$filter_query_where .= ' AND';
127
+		}
123 128
 		if ($filter_query_where != '') {
124 129
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
125 130
 		}
@@ -161,7 +166,9 @@  discard block
 block discarded – undo
161 166
 			}
162 167
 		}
163 168
 
164
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
169
+		if (!isset($globalLiveInterval)) {
170
+			$globalLiveInterval = '200';
171
+		}
165 172
 		if ($globalDBdriver == 'mysql') {
166 173
 			//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
167 174
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -184,7 +191,9 @@  discard block
 block discarded – undo
184 191
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
185 192
 		date_default_timezone_set('UTC');
186 193
 		$filter_query = $this->getFilter($filter,true,true);
187
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
194
+		if (!isset($globalLiveInterval)) {
195
+			$globalLiveInterval = '200';
196
+		}
188 197
 		if ($globalDBdriver == 'mysql') {
189 198
 			if (isset($globalArchive) && $globalArchive === TRUE) {
190 199
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -227,7 +236,9 @@  discard block
 block discarded – undo
227 236
 
228 237
 		$filter_query = $this->getFilter($filter,true,true);
229 238
 
230
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
239
+		if (!isset($globalLiveInterval)) {
240
+			$globalLiveInterval = '200';
241
+		}
231 242
 		if ($globalDBdriver == 'mysql') {
232 243
 			if (isset($globalArchive) && $globalArchive === TRUE) {
233 244
 				$query  = 'SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source 
@@ -272,7 +283,9 @@  discard block
 block discarded – undo
272 283
 		global $globalDBdriver, $globalLiveInterval;
273 284
 		$filter_query = $this->getFilter($filter,true,true);
274 285
 
275
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
286
+		if (!isset($globalLiveInterval)) {
287
+			$globalLiveInterval = '200';
288
+		}
276 289
 		if ($globalDBdriver == 'mysql') {
277 290
 			//$query  = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
278 291
 			$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
@@ -302,7 +315,9 @@  discard block
 block discarded – undo
302 315
 	{
303 316
 		global $globalDBdriver, $globalLiveInterval;
304 317
 		$Spotter = new Spotter($this->db);
305
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
318
+		if (!isset($globalLiveInterval)) {
319
+			$globalLiveInterval = '200';
320
+		}
306 321
 		$filter_query = $this->getFilter($filter);
307 322
 
308 323
 		if (is_array($coord)) {
@@ -310,7 +325,9 @@  discard block
 block discarded – undo
310 325
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
311 326
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
312 327
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
313
-		} else return array();
328
+		} else {
329
+			return array();
330
+		}
314 331
 		if ($globalDBdriver == 'mysql') {
315 332
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query;
316 333
 		} else {
@@ -331,7 +348,9 @@  discard block
 block discarded – undo
331 348
 	{
332 349
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
333 350
 		$Spotter = new Spotter($this->db);
334
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
351
+		if (!isset($globalLiveInterval)) {
352
+			$globalLiveInterval = '200';
353
+		}
335 354
 		$filter_query = $this->getFilter($filter,true,true);
336 355
 
337 356
 		if (is_array($coord)) {
@@ -339,7 +358,9 @@  discard block
 block discarded – undo
339 358
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
340 359
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
341 360
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
342
-		} else return array();
361
+		} else {
362
+			return array();
363
+		}
343 364
 		if ($globalDBdriver == 'mysql') {
344 365
 			if (isset($globalArchive) && $globalArchive === TRUE) {
345 366
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -570,11 +591,15 @@  discard block
 block discarded – undo
570 591
 		//$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
571 592
 		if ($globalDBdriver == 'mysql') {
572 593
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
573
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
594
+			if ($liveinterval) {
595
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
596
+			}
574 597
 			$query .= ' ORDER BY date';
575 598
 		} else {
576 599
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
577
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
600
+			if ($liveinterval) {
601
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
602
+			}
578 603
 			$query .= ' ORDER BY date';
579 604
 		}
580 605
 
@@ -669,7 +694,9 @@  discard block
 block discarded – undo
669 694
 				$i++;
670 695
 				$j++;
671 696
 				if ($j == 30) {
672
-					if ($globalDebug) echo ".";
697
+					if ($globalDebug) {
698
+						echo ".";
699
+					}
673 700
 				    	try {
674 701
 						
675 702
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -976,7 +1003,9 @@  discard block
 block discarded – undo
976 1003
 			{
977 1004
 				return false;
978 1005
 			}
979
-		} else return '';
1006
+		} else {
1007
+			return '';
1008
+		}
980 1009
 
981 1010
 		if ($longitude != '')
982 1011
 		{
@@ -984,7 +1013,9 @@  discard block
 block discarded – undo
984 1013
 			{
985 1014
 				return false;
986 1015
 			}
987
-		} else return '';
1016
+		} else {
1017
+			return '';
1018
+		}
988 1019
 
989 1020
 		if ($waypoints != '')
990 1021
 		{
@@ -1000,7 +1031,9 @@  discard block
 block discarded – undo
1000 1031
 			{
1001 1032
 				return false;
1002 1033
 			}
1003
-		} else $altitude = 0;
1034
+		} else {
1035
+			$altitude = 0;
1036
+		}
1004 1037
 
1005 1038
 		if ($heading != '')
1006 1039
 		{
@@ -1008,7 +1041,9 @@  discard block
 block discarded – undo
1008 1041
 			{
1009 1042
 				return false;
1010 1043
 			}
1011
-		} else $heading = 0;
1044
+		} else {
1045
+			$heading = 0;
1046
+		}
1012 1047
 
1013 1048
 		if ($groundspeed != '')
1014 1049
 		{
@@ -1016,9 +1051,13 @@  discard block
 block discarded – undo
1016 1051
 			{
1017 1052
 				return false;
1018 1053
 			}
1019
-		} else $groundspeed = 0;
1054
+		} else {
1055
+			$groundspeed = 0;
1056
+		}
1020 1057
 		date_default_timezone_set('UTC');
1021
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1058
+		if ($date == '') {
1059
+			$date = date("Y-m-d H:i:s", time());
1060
+		}
1022 1061
 
1023 1062
         
1024 1063
 		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
@@ -1062,14 +1101,24 @@  discard block
 block discarded – undo
1062 1101
 		$arrival_airport_country = '';
1063 1102
 		
1064 1103
             	
1065
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1066
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1067
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1068
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1104
+            	if ($squawk == '' || $Common->isInteger($squawk) === false ) {
1105
+            		$squawk = NULL;
1106
+            	}
1107
+            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) {
1108
+            		$verticalrate = NULL;
1109
+            	}
1110
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1111
+            		$groundspeed = 0;
1112
+            	}
1113
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1114
+            		$heading = 0;
1115
+            	}
1069 1116
 		
1070 1117
 		$query = '';
1071 1118
 		if ($globalArchive) {
1072
-			if ($globalDebug) echo '-- Delete previous data -- ';
1119
+			if ($globalDebug) {
1120
+				echo '-- Delete previous data -- ';
1121
+			}
1073 1122
 			$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;';
1074 1123
 		}
1075 1124
 
@@ -1086,10 +1135,14 @@  discard block
 block discarded – undo
1086 1135
 			return "error : ".$e->getMessage();
1087 1136
 		}
1088 1137
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1089
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1138
+		    if ($globalDebug) {
1139
+		    	echo '(Add to SBS archive : ';
1140
+		    }
1090 1141
 		    $SpotterArchive = new SpotterArchive($this->db);
1091 1142
 		    $result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1092
-		    if ($globalDebug) echo $result.')';
1143
+		    if ($globalDebug) {
1144
+		    	echo $result.')';
1145
+		    }
1093 1146
 		}
1094 1147
 		return "success";
1095 1148
 
Please login to merge, or discard this patch.