Completed
Push — master ( 04cf69...7bb360 )
by Yannick
26:49
created
require/class.Marine.php 1 patch
Braces   +162 added lines, -58 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) {
@@ -68,8 +70,11 @@  discard block
 block discarded – undo
68 70
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
69 71
 			}
70 72
 		}
71
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
72
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
73
+		if ($filter_query_where == '' && $where) {
74
+			$filter_query_where = ' WHERE';
75
+		} elseif ($filter_query_where != '' && $and) {
76
+			$filter_query_where .= ' AND';
77
+		}
73 78
 		if ($filter_query_where != '') {
74 79
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
75 80
 		}
@@ -123,32 +128,54 @@  discard block
 block discarded – undo
123 128
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
124 129
 			} elseif (isset($row['spotter_archive_output_id'])) {
125 130
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
126
-			*/} 
127
-			elseif (isset($row['marineid'])) {
131
+			*/} elseif (isset($row['marineid'])) {
128 132
 				$temp_array['marine_id'] = $row['marineid'];
129 133
 			} else {
130 134
 				$temp_array['marine_id'] = '';
131 135
 			}
132
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
133
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
134
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
135
-			if (isset($row['type_id'])) $temp_array['type_id'] = $row['type_id'];
136
-			if (isset($row['ident'])) $temp_array['ident'] = $row['ident'];
137
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
138
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
139
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
136
+			if (isset($row['fammarine_id'])) {
137
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
138
+			}
139
+			if (isset($row['mmsi'])) {
140
+				$temp_array['mmsi'] = $row['mmsi'];
141
+			}
142
+			if (isset($row['type'])) {
143
+				$temp_array['type'] = $row['type'];
144
+			}
145
+			if (isset($row['type_id'])) {
146
+				$temp_array['type_id'] = $row['type_id'];
147
+			}
148
+			if (isset($row['ident'])) {
149
+				$temp_array['ident'] = $row['ident'];
150
+			}
151
+			if (isset($row['latitude'])) {
152
+				$temp_array['latitude'] = $row['latitude'];
153
+			}
154
+			if (isset($row['longitude'])) {
155
+				$temp_array['longitude'] = $row['longitude'];
156
+			}
157
+			if (isset($row['format_source'])) {
158
+				$temp_array['format_source'] = $row['format_source'];
159
+			}
140 160
 			if (isset($row['heading'])) {
141 161
 				$temp_array['heading'] = $row['heading'];
142 162
 				$heading_direction = $this->parseDirection($row['heading']);
143
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
163
+				if (isset($heading_direction[0]['direction_fullname'])) {
164
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
165
+				}
166
+			}
167
+			if (isset($row['ground_speed'])) {
168
+				$temp_array['ground_speed'] = $row['ground_speed'];
144 169
 			}
145
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
146 170
 
147 171
 			if($temp_array['mmsi'] != "")
148 172
 			{
149 173
 				$Image = new Image($this->db);
150
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
151
-				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
174
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') {
175
+					$image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
176
+				} else {
177
+					$image_array = $Image->getMarineImage($temp_array['mmsi']);
178
+				}
152 179
 				unset($Image);
153 180
 				if (count($image_array) > 0) {
154 181
 					$temp_array['image'] = $image_array[0]['image'];
@@ -200,13 +227,21 @@  discard block
 block discarded – undo
200 227
 			}
201 228
 			
202 229
 			$fromsource = NULL;
203
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
204
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
205
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
230
+			if (isset($row['source_name']) && $row['source_name'] != '') {
231
+				$temp_array['source_name'] = $row['source_name'];
232
+			}
233
+			if (isset($row['over_country']) && $row['over_country'] != '') {
234
+				$temp_array['over_country'] = $row['over_country'];
235
+			}
236
+			if (isset($row['distance']) && $row['distance'] != '') {
237
+				$temp_array['distance'] = $row['distance'];
238
+			}
206 239
 			$temp_array['query_number_rows'] = $num_rows;
207 240
 			$spotter_array[] = $temp_array;
208 241
 		}
209
-		if ($num_rows == 0) return array();
242
+		if ($num_rows == 0) {
243
+			return array();
244
+		}
210 245
 		$spotter_array[0]['query_number_rows'] = $num_rows;
211 246
 		return $spotter_array;
212 247
 	}	
@@ -232,8 +267,12 @@  discard block
 block discarded – undo
232 267
 			{
233 268
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
234 269
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
235
-			} else $limit_query = "";
236
-		} else $limit_query = "";
270
+			} else {
271
+				$limit_query = "";
272
+			}
273
+		} else {
274
+			$limit_query = "";
275
+		}
237 276
 		if ($sort != "")
238 277
 		{
239 278
 			$search_orderby_array = $this->getOrderBy();
@@ -257,7 +296,9 @@  discard block
 block discarded – undo
257 296
 		global $global_query;
258 297
 		
259 298
 		date_default_timezone_set('UTC');
260
-		if ($id == '') return array();
299
+		if ($id == '') {
300
+			return array();
301
+		}
261 302
 		$additional_query = "marine_output.fammarine_id = :id";
262 303
 		$query_values = array(':id' => $id);
263 304
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -400,8 +441,11 @@  discard block
 block discarded – undo
400 441
 		$query .= " ORDER BY marine_output.source_name ASC";
401 442
 
402 443
 		$sth = $this->db->prepare($query);
403
-		if (!empty($query_values)) $sth->execute($query_values);
404
-		else $sth->execute();
444
+		if (!empty($query_values)) {
445
+			$sth->execute($query_values);
446
+		} else {
447
+			$sth->execute();
448
+		}
405 449
 
406 450
 		$source_array = array();
407 451
 		$temp_array = array();
@@ -456,8 +500,11 @@  discard block
 block discarded – undo
456 500
 		$sth = $this->db->prepare($query);
457 501
 		$sth->execute(array(':mmsi' => $mmsi));
458 502
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
459
-		if (isset($result[0])) return $result[0];
460
-		else return array();
503
+		if (isset($result[0])) {
504
+			return $result[0];
505
+		} else {
506
+			return array();
507
+		}
461 508
 	}
462 509
 
463 510
 	/*
@@ -473,7 +520,9 @@  discard block
 block discarded – undo
473 520
 			date_default_timezone_set($globalTimezone);
474 521
 			$datetime = new DateTime();
475 522
 			$offset = $datetime->format('P');
476
-		} else $offset = '+00:00';
523
+		} else {
524
+			$offset = '+00:00';
525
+		}
477 526
 
478 527
 		if ($globalDBdriver == 'mysql') {
479 528
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -703,9 +752,15 @@  discard block
 block discarded – undo
703 752
             		$latitude = 0;
704 753
             		$longitude = 0;
705 754
             	}
706
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
707
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
708
-                if ($arrival_date == '') $arrival_date = NULL;
755
+                if ($heading == '' || $Common->isInteger($heading) === false) {
756
+                	$heading = 0;
757
+                }
758
+                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
759
+                	$groundspeed = 0;
760
+                }
761
+                if ($arrival_date == '') {
762
+                	$arrival_date = NULL;
763
+                }
709 764
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
710 765
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
711 766
 
@@ -813,7 +868,9 @@  discard block
 block discarded – undo
813 868
 		global $globalDBdriver, $globalArchive;
814 869
 		//$filter_query = $this->getFilter($filters,true,true);
815 870
 		$Connection= new Connection($this->db);
816
-		if (!$Connection->tableExists('countries')) return array();
871
+		if (!$Connection->tableExists('countries')) {
872
+			return array();
873
+		}
817 874
 		require_once('class.SpotterLive.php');
818 875
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
819 876
 			$MarineLive = new MarineLive();
@@ -857,7 +914,9 @@  discard block
 block discarded – undo
857 914
 			$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT fammarine_id,over_country FROM marine_archive".$filter_query.") l ON c.iso2 = l.over_country ";
858 915
 		}
859 916
 		$query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC";
860
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
917
+		if ($limit) {
918
+			$query .= " LIMIT 10 OFFSET 0";
919
+		}
861 920
       
862 921
 		
863 922
 		$sth = $this->db->prepare($query);
@@ -892,12 +951,18 @@  discard block
 block discarded – undo
892 951
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
893 952
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
894 953
 		 if ($olderthanmonths > 0) {
895
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
896
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
954
+			if ($globalDBdriver == 'mysql') {
955
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
956
+			} else {
957
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
958
+			}
897 959
 		}
898 960
 		if ($sincedate != '') {
899
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
900
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
961
+			if ($globalDBdriver == 'mysql') {
962
+				$query .= " AND marine_output.date > '".$sincedate."'";
963
+			} else {
964
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
965
+			}
901 966
 		}
902 967
 		$query_values = array();
903 968
 		if ($year != '') {
@@ -928,7 +993,9 @@  discard block
 block discarded – undo
928 993
 			}
929 994
 		}
930 995
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
931
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
996
+		if ($limit) {
997
+			$query .= " LIMIT 10 OFFSET 0";
998
+		}
932 999
       		
933 1000
 		$sth = $this->db->prepare($query);
934 1001
 		$sth->execute($query_values);
@@ -963,7 +1030,9 @@  discard block
 block discarded – undo
963 1030
 			date_default_timezone_set($globalTimezone);
964 1031
 			$datetime = new DateTime();
965 1032
 			$offset = $datetime->format('P');
966
-		} else $offset = '+00:00';
1033
+		} else {
1034
+			$offset = '+00:00';
1035
+		}
967 1036
 
968 1037
 		if ($globalDBdriver == 'mysql') {
969 1038
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1013,7 +1082,9 @@  discard block
 block discarded – undo
1013 1082
 			date_default_timezone_set($globalTimezone);
1014 1083
 			$datetime = new DateTime();
1015 1084
 			$offset = $datetime->format('P');
1016
-		} else $offset = '+00:00';
1085
+		} else {
1086
+			$offset = '+00:00';
1087
+		}
1017 1088
 		$filter_query = $this->getFilter($filters,true,true);
1018 1089
 		if ($globalDBdriver == 'mysql') {
1019 1090
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1059,7 +1130,9 @@  discard block
 block discarded – undo
1059 1130
 			date_default_timezone_set($globalTimezone);
1060 1131
 			$datetime = new DateTime();
1061 1132
 			$offset = $datetime->format('P');
1062
-		} else $offset = '+00:00';
1133
+		} else {
1134
+			$offset = '+00:00';
1135
+		}
1063 1136
 		$filter_query = $this->getFilter($filters,true,true);
1064 1137
 		if ($globalDBdriver == 'mysql') {
1065 1138
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1107,7 +1180,9 @@  discard block
 block discarded – undo
1107 1180
 			date_default_timezone_set($globalTimezone);
1108 1181
 			$datetime = new DateTime();
1109 1182
 			$offset = $datetime->format('P');
1110
-		} else $offset = '+00:00';
1183
+		} else {
1184
+			$offset = '+00:00';
1185
+		}
1111 1186
 
1112 1187
 		if ($globalDBdriver == 'mysql') {
1113 1188
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1156,7 +1231,9 @@  discard block
 block discarded – undo
1156 1231
 			date_default_timezone_set($globalTimezone);
1157 1232
 			$datetime = new DateTime();
1158 1233
 			$offset = $datetime->format('P');
1159
-		} else $offset = '+00:00';
1234
+		} else {
1235
+			$offset = '+00:00';
1236
+		}
1160 1237
 		$filter_query = $this->getFilter($filters,true,true);
1161 1238
 		if ($globalDBdriver == 'mysql') {
1162 1239
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
@@ -1205,7 +1282,9 @@  discard block
 block discarded – undo
1205 1282
 			date_default_timezone_set($globalTimezone);
1206 1283
 			$datetime = new DateTime();
1207 1284
 			$offset = $datetime->format('P');
1208
-		} else $offset = '+00:00';
1285
+		} else {
1286
+			$offset = '+00:00';
1287
+		}
1209 1288
 
1210 1289
 		$orderby_sql = '';
1211 1290
 		if ($orderby == "hour")
@@ -1274,7 +1353,9 @@  discard block
 block discarded – undo
1274 1353
 			date_default_timezone_set($globalTimezone);
1275 1354
 			$datetime = new DateTime($date);
1276 1355
 			$offset = $datetime->format('P');
1277
-		} else $offset = '+00:00';
1356
+		} else {
1357
+			$offset = '+00:00';
1358
+		}
1278 1359
 
1279 1360
 		if ($globalDBdriver == 'mysql') {
1280 1361
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1322,7 +1403,9 @@  discard block
 block discarded – undo
1322 1403
 			date_default_timezone_set($globalTimezone);
1323 1404
 			$datetime = new DateTime();
1324 1405
 			$offset = $datetime->format('P');
1325
-		} else $offset = '+00:00';
1406
+		} else {
1407
+			$offset = '+00:00';
1408
+		}
1326 1409
 
1327 1410
 		if ($globalDBdriver == 'mysql') {
1328 1411
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1387,8 +1470,11 @@  discard block
 block discarded – undo
1387 1470
 				$query_values = array_merge($query_values,array(':month' => $month));
1388 1471
 			}
1389 1472
 		}
1390
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1391
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1473
+		if (empty($query_values)) {
1474
+			$queryi .= $this->getFilter($filters);
1475
+		} else {
1476
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1477
+		}
1392 1478
 		
1393 1479
 		$sth = $this->db->prepare($queryi);
1394 1480
 		$sth->execute($query_values);
@@ -1410,7 +1496,9 @@  discard block
 block discarded – undo
1410 1496
 			date_default_timezone_set($globalTimezone);
1411 1497
 			$datetime = new DateTime();
1412 1498
 			$offset = $datetime->format('P');
1413
-		} else $offset = '+00:00';
1499
+		} else {
1500
+			$offset = '+00:00';
1501
+		}
1414 1502
 
1415 1503
 		if ($globalDBdriver == 'mysql') {
1416 1504
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1514,7 +1602,9 @@  discard block
 block discarded – undo
1514 1602
 	*/
1515 1603
 	public function parseDirection($direction = 0)
1516 1604
 	{
1517
-		if ($direction == '') $direction = 0;
1605
+		if ($direction == '') {
1606
+			$direction = 0;
1607
+		}
1518 1608
 		$direction_array = array();
1519 1609
 		$temp_array = array();
1520 1610
 
@@ -1603,7 +1693,9 @@  discard block
 block discarded – undo
1603 1693
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1604 1694
 	
1605 1695
 		$Connection = new Connection($this->db);
1606
-		if (!$Connection->tableExists('countries')) return '';
1696
+		if (!$Connection->tableExists('countries')) {
1697
+			return '';
1698
+		}
1607 1699
 	
1608 1700
 		try {
1609 1701
 			/*
@@ -1623,9 +1715,13 @@  discard block
 block discarded – undo
1623 1715
 			$sth->closeCursor();
1624 1716
 			if (count($row) > 0) {
1625 1717
 				return $row;
1626
-			} else return '';
1718
+			} else {
1719
+				return '';
1720
+			}
1627 1721
 		} catch (PDOException $e) {
1628
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1722
+			if (isset($globalDebug) && $globalDebug) {
1723
+				echo 'Error : '.$e->getMessage()."\n";
1724
+			}
1629 1725
 			return '';
1630 1726
 		}
1631 1727
 	
@@ -1643,7 +1739,9 @@  discard block
 block discarded – undo
1643 1739
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1644 1740
 	
1645 1741
 		$Connection = new Connection($this->db);
1646
-		if (!$Connection->tableExists('countries')) return '';
1742
+		if (!$Connection->tableExists('countries')) {
1743
+			return '';
1744
+		}
1647 1745
 	
1648 1746
 		try {
1649 1747
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1655,9 +1753,13 @@  discard block
 block discarded – undo
1655 1753
 			$sth->closeCursor();
1656 1754
 			if (count($row) > 0) {
1657 1755
 				return $row;
1658
-			} else return '';
1756
+			} else {
1757
+				return '';
1758
+			}
1659 1759
 		} catch (PDOException $e) {
1660
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1760
+			if (isset($globalDebug) && $globalDebug) {
1761
+				echo 'Error : '.$e->getMessage()."\n";
1762
+			}
1661 1763
 			return '';
1662 1764
 		}
1663 1765
 	
@@ -1675,7 +1777,9 @@  discard block
 block discarded – undo
1675 1777
 	{
1676 1778
 		global $globalBitlyAccessToken;
1677 1779
 		
1678
-		if ($globalBitlyAccessToken == '') return $url;
1780
+		if ($globalBitlyAccessToken == '') {
1781
+			return $url;
1782
+		}
1679 1783
         
1680 1784
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1681 1785
 		
Please login to merge, or discard this patch.