@@ -7,13 +7,13 @@ discard block |
||
| 7 | 7 | die(); |
| 8 | 8 | } |
| 9 | 9 | $Spotter = new Spotter(); |
| 10 | -$manufacturer = ucwords(str_replace("-", " ", filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING))); |
|
| 11 | -$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING); |
|
| 12 | -$spotter_array = $Spotter->getSpotterDataByManufacturer($manufacturer,"0,1", $sort); |
|
| 10 | +$manufacturer = ucwords(str_replace("-", " ", filter_input(INPUT_GET, 'aircraft_manufacturer', FILTER_SANITIZE_STRING))); |
|
| 11 | +$sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING); |
|
| 12 | +$spotter_array = $Spotter->getSpotterDataByManufacturer($manufacturer, "0,1", $sort); |
|
| 13 | 13 | |
| 14 | 14 | if (!empty($spotter_array)) |
| 15 | 15 | { |
| 16 | - $title = sprintf(_("Most Common Departure Airports from %s"),$manufacturer); |
|
| 16 | + $title = sprintf(_("Most Common Departure Airports from %s"), $manufacturer); |
|
| 17 | 17 | |
| 18 | 18 | require_once('header.php'); |
| 19 | 19 | print '<div class="select-item">'; |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | print '<select name="aircraft_manufacturer" class="selectpicker" data-live-search="true">'; |
| 22 | 22 | print '<option></option>'; |
| 23 | 23 | $all_manufacturers = $Spotter->getAllManufacturers(); |
| 24 | - foreach($all_manufacturers as $all_manufacturer) |
|
| 24 | + foreach ($all_manufacturers as $all_manufacturer) |
|
| 25 | 25 | { |
| 26 | - if($_GET['aircraft_manufacturer'] == strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer']))) |
|
| 26 | + if ($_GET['aircraft_manufacturer'] == strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer']))) |
|
| 27 | 27 | { |
| 28 | 28 | print '<option value="'.strtolower(str_replace(" ", "-", $all_manufacturer['aircraft_manufacturer'])).'" selected="selected">'.$all_manufacturer['aircraft_manufacturer'].'</option>'; |
| 29 | 29 | } else { |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | include('manufacturer-sub-menu.php'); |
| 43 | 43 | print '<div class="column">'; |
| 44 | 44 | print '<h2>'._("Most Common Departure Airports").'</h2>'; |
| 45 | - print '<p>'.sprintf(_("The statistic below shows all departure airports of flights from <strong>%s</strong>."),$manufacturer).'</p>'; |
|
| 45 | + print '<p>'.sprintf(_("The statistic below shows all departure airports of flights from <strong>%s</strong>."), $manufacturer).'</p>'; |
|
| 46 | 46 | $airport_airport_array = $Spotter->countAllDepartureAirportsByManufacturer($manufacturer); |
| 47 | 47 | print '<script type="text/javascript" src="https://www.google.com/jsapi"></script> |
| 48 | 48 | <script> |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | ["'._("Airport").'", "'._("# of times").'"],'; |
| 58 | 58 | |
| 59 | 59 | $airport_data = ''; |
| 60 | - foreach($airport_airport_array as $airport_item) |
|
| 60 | + foreach ($airport_airport_array as $airport_item) |
|
| 61 | 61 | { |
| 62 | 62 | $name = $airport_item['airport_departure_city'].', '.$airport_item['airport_departure_country'].' ('.$airport_item['airport_departure_icao'].')'; |
| 63 | 63 | $name = str_replace("'", "", $name); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | print '</thead>'; |
| 97 | 97 | print '<tbody>'; |
| 98 | 98 | $i = 1; |
| 99 | - foreach($airport_airport_array as $airport_item) |
|
| 99 | + foreach ($airport_airport_array as $airport_item) |
|
| 100 | 100 | { |
| 101 | 101 | print '<tr>'; |
| 102 | 102 | print '<td><strong>'.$i.'</strong></td>'; |
@@ -3,8 +3,8 @@ |
||
| 3 | 3 | require_once('require/class.Spotter.php'); |
| 4 | 4 | require_once('require/class.Language.php'); |
| 5 | 5 | if (!isset($_GET['aircraft_manufacturer'])) { |
| 6 | - header('Location: '.$globalURL.'/manufacturer'); |
|
| 7 | - die(); |
|
| 6 | + header('Location: '.$globalURL.'/manufacturer'); |
|
| 7 | + die(); |
|
| 8 | 8 | } |
| 9 | 9 | $Spotter = new Spotter(); |
| 10 | 10 | $manufacturer = ucwords(str_replace("-", " ", filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING))); |
@@ -11,11 +11,11 @@ discard block |
||
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | - * Gets all the spotter information based on the latest data entry |
|
| 15 | - * |
|
| 16 | - * @return Array the spotter information |
|
| 17 | - * |
|
| 18 | - */ |
|
| 14 | + * Gets all the spotter information based on the latest data entry |
|
| 15 | + * |
|
| 16 | + * @return Array the spotter information |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | 19 | public function getLiveSpotterData($limit = '', $sort = '', $filter = array()) |
| 20 | 20 | { |
| 21 | 21 | global $globalDBdriver, $globalLiveInterval; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | if ($globalDBdriver == 'mysql') { |
| 59 | 59 | //$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"; |
| 60 | 60 | $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; |
| 61 | - } else if ($globalDBdriver == 'pgsql') { |
|
| 61 | + } else if ($globalDBdriver == 'pgsql') { |
|
| 62 | 62 | $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= 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; |
| 63 | 63 | } |
| 64 | 64 | $spotter_array = $Spotter->getDataFromDB($query.$limit_query); |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | - * Gets Minimal Live Spotter data |
|
| 71 | - * |
|
| 72 | - * @return Array the spotter information |
|
| 73 | - * |
|
| 74 | - */ |
|
| 70 | + * Gets Minimal Live Spotter data |
|
| 71 | + * |
|
| 72 | + * @return Array the spotter information |
|
| 73 | + * |
|
| 74 | + */ |
|
| 75 | 75 | public function getMinLiveSpotterData($filter = array()) |
| 76 | 76 | { |
| 77 | 77 | global $globalDBdriver, $globalLiveInterval; |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | // $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 FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date ORDER BY spotter_live.date GROUP BY spotter_live.flightaware_id'.$filter_query; |
| 105 | 105 | |
| 106 | 106 | //$query = 'SELECT a.aircraft_shadow, 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 FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
| 107 | - } else if ($globalDBdriver == 'pgsql') { |
|
| 108 | - //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
|
| 109 | - //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
|
| 107 | + } else if ($globalDBdriver == 'pgsql') { |
|
| 108 | + //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
|
| 109 | + //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
|
| 110 | 110 | //$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, a.aircraft_shadow 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.'INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
| 111 | 111 | $query = "SELECT a.aircraft_shadow, 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 |
| 112 | 112 | FROM spotter_live |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | // $spotter_array = Spotter->getDataFromDB($query.$limit_query); |
| 116 | 116 | //echo $query; |
| 117 | 117 | |
| 118 | - try { |
|
| 118 | + try { |
|
| 119 | 119 | $sth = $this->db->prepare($query); |
| 120 | 120 | $sth->execute(); |
| 121 | 121 | } catch(PDOException $e) { |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * Gets number of latest data entry |
|
| 131 | - * |
|
| 132 | - * @return String number of entry |
|
| 133 | - * |
|
| 134 | - */ |
|
| 130 | + * Gets number of latest data entry |
|
| 131 | + * |
|
| 132 | + * @return String number of entry |
|
| 133 | + * |
|
| 134 | + */ |
|
| 135 | 135 | public function getLiveSpotterCount($filter = array()) |
| 136 | 136 | { |
| 137 | 137 | global $globalDBdriver, $globalLiveInterval; |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
| 153 | 153 | if ($globalDBdriver == 'mysql') { |
| 154 | - //$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; |
|
| 154 | + //$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; |
|
| 155 | 155 | $query = 'SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'.$filter_query; |
| 156 | - } elseif ($globalDBdriver == 'pgsql') { |
|
| 157 | - //$query = "SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query; |
|
| 156 | + } elseif ($globalDBdriver == 'pgsql') { |
|
| 157 | + //$query = "SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query; |
|
| 158 | 158 | $query = "SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_live WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date".$filter_query; |
| 159 | - } |
|
| 160 | - try { |
|
| 159 | + } |
|
| 160 | + try { |
|
| 161 | 161 | $sth = $this->db->prepare($query); |
| 162 | 162 | $sth->execute(); |
| 163 | 163 | } catch(PDOException $e) { |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | - * Gets all the spotter information based on the latest data entry and coord |
|
| 172 | - * |
|
| 173 | - * @return Array the spotter information |
|
| 174 | - * |
|
| 175 | - */ |
|
| 171 | + * Gets all the spotter information based on the latest data entry and coord |
|
| 172 | + * |
|
| 173 | + * @return Array the spotter information |
|
| 174 | + * |
|
| 175 | + */ |
|
| 176 | 176 | public function getLiveSpotterDatabyCoord($coord, $filter = array()) |
| 177 | 177 | { |
| 178 | 178 | global $globalDBdriver, $globalLiveInterval; |
@@ -193,140 +193,140 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (is_array($coord)) { |
| 196 | - $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 197 | - $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 198 | - $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 199 | - $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 200 | - } else return array(); |
|
| 201 | - if ($globalDBdriver == 'mysql') { |
|
| 202 | - //$query = "SELECT spotter_output.* FROM spotter_output WHERE spotter_output.flightaware_id IN (SELECT spotter_live.flightaware_id 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.")"; |
|
| 203 | - $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; |
|
| 204 | - } else if ($globalDBdriver == 'pgsql') { |
|
| 205 | - $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= 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; |
|
| 206 | - } |
|
| 207 | - $spotter_array = $Spotter->getDataFromDB($query); |
|
| 208 | - return $spotter_array; |
|
| 209 | - } |
|
| 196 | + $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 197 | + $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 198 | + $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 199 | + $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 200 | + } else return array(); |
|
| 201 | + if ($globalDBdriver == 'mysql') { |
|
| 202 | + //$query = "SELECT spotter_output.* FROM spotter_output WHERE spotter_output.flightaware_id IN (SELECT spotter_live.flightaware_id 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.")"; |
|
| 203 | + $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; |
|
| 204 | + } else if ($globalDBdriver == 'pgsql') { |
|
| 205 | + $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= 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; |
|
| 206 | + } |
|
| 207 | + $spotter_array = $Spotter->getDataFromDB($query); |
|
| 208 | + return $spotter_array; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Gets all the spotter information based on a user's latitude and longitude |
|
| 213 | - * |
|
| 214 | - * @return Array the spotter information |
|
| 215 | - * |
|
| 216 | - */ |
|
| 217 | - public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
|
| 218 | - { |
|
| 219 | - $Spotter = new Spotter($this->db); |
|
| 220 | - date_default_timezone_set('UTC'); |
|
| 221 | - |
|
| 222 | - if ($lat != '') |
|
| 223 | - { |
|
| 224 | - if (!is_numeric($lat)) |
|
| 225 | - { |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - } |
|
| 212 | + * Gets all the spotter information based on a user's latitude and longitude |
|
| 213 | + * |
|
| 214 | + * @return Array the spotter information |
|
| 215 | + * |
|
| 216 | + */ |
|
| 217 | + public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
|
| 218 | + { |
|
| 219 | + $Spotter = new Spotter($this->db); |
|
| 220 | + date_default_timezone_set('UTC'); |
|
| 221 | + |
|
| 222 | + if ($lat != '') |
|
| 223 | + { |
|
| 224 | + if (!is_numeric($lat)) |
|
| 225 | + { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - if ($lng != '') |
|
| 231 | - { |
|
| 232 | - if (!is_numeric($lng)) |
|
| 233 | - { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - if ($radius != '') |
|
| 239 | - { |
|
| 240 | - if (!is_numeric($radius)) |
|
| 241 | - { |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - } |
|
| 230 | + if ($lng != '') |
|
| 231 | + { |
|
| 232 | + if (!is_numeric($lng)) |
|
| 233 | + { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + if ($radius != '') |
|
| 239 | + { |
|
| 240 | + if (!is_numeric($radius)) |
|
| 241 | + { |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - if ($interval != '') |
|
| 247 | - { |
|
| 248 | - if (!is_string($interval)) |
|
| 249 | - { |
|
| 250 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
| 251 | - return false; |
|
| 252 | - } else { |
|
| 253 | - if ($interval == '1m') |
|
| 254 | - { |
|
| 255 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
| 256 | - } else if ($interval == '15m'){ |
|
| 257 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } else { |
|
| 261 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
|
| 246 | + if ($interval != '') |
|
| 247 | + { |
|
| 248 | + if (!is_string($interval)) |
|
| 249 | + { |
|
| 250 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
| 251 | + return false; |
|
| 252 | + } else { |
|
| 253 | + if ($interval == '1m') |
|
| 254 | + { |
|
| 255 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
| 256 | + } else if ($interval == '15m'){ |
|
| 257 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } else { |
|
| 261 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
|
| 265 | 265 | WHERE spotter_live.latitude <> '' |
| 266 | 266 | AND spotter_live.longitude <> '' |
| 267 | 267 | ".$additional_query." |
| 268 | 268 | HAVING distance < :radius |
| 269 | 269 | ORDER BY distance"; |
| 270 | 270 | |
| 271 | - $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius),$limit_query); |
|
| 271 | + $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius),$limit_query); |
|
| 272 | 272 | |
| 273 | - return $spotter_array; |
|
| 274 | - } |
|
| 273 | + return $spotter_array; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Gets all the spotter information based on a particular callsign |
|
| 279 | - * |
|
| 280 | - * @return Array the spotter information |
|
| 281 | - * |
|
| 282 | - */ |
|
| 277 | + /** |
|
| 278 | + * Gets all the spotter information based on a particular callsign |
|
| 279 | + * |
|
| 280 | + * @return Array the spotter information |
|
| 281 | + * |
|
| 282 | + */ |
|
| 283 | 283 | public function getLastLiveSpotterDataByIdent($ident) |
| 284 | 284 | { |
| 285 | 285 | $Spotter = new Spotter($this->db); |
| 286 | 286 | date_default_timezone_set('UTC'); |
| 287 | 287 | |
| 288 | 288 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 289 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 289 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 290 | 290 | |
| 291 | 291 | $spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident)); |
| 292 | 292 | |
| 293 | 293 | return $spotter_array; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Gets last spotter information based on a particular callsign |
|
| 298 | - * |
|
| 299 | - * @return Array the spotter information |
|
| 300 | - * |
|
| 301 | - */ |
|
| 296 | + /** |
|
| 297 | + * Gets last spotter information based on a particular callsign |
|
| 298 | + * |
|
| 299 | + * @return Array the spotter information |
|
| 300 | + * |
|
| 301 | + */ |
|
| 302 | 302 | public function getLastLiveSpotterDataById($id) |
| 303 | 303 | { |
| 304 | 304 | $Spotter = new Spotter($this->db); |
| 305 | 305 | date_default_timezone_set('UTC'); |
| 306 | 306 | |
| 307 | 307 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
| 308 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 308 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 309 | 309 | |
| 310 | 310 | $spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id)); |
| 311 | 311 | |
| 312 | 312 | return $spotter_array; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Gets altitude information based on a particular callsign |
|
| 317 | - * |
|
| 318 | - * @return Array the spotter information |
|
| 319 | - * |
|
| 320 | - */ |
|
| 315 | + /** |
|
| 316 | + * Gets altitude information based on a particular callsign |
|
| 317 | + * |
|
| 318 | + * @return Array the spotter information |
|
| 319 | + * |
|
| 320 | + */ |
|
| 321 | 321 | public function getAltitudeLiveSpotterDataByIdent($ident) |
| 322 | 322 | { |
| 323 | 323 | |
| 324 | 324 | date_default_timezone_set('UTC'); |
| 325 | 325 | |
| 326 | 326 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 327 | - $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
|
| 327 | + $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
|
| 328 | 328 | |
| 329 | - try { |
|
| 329 | + try { |
|
| 330 | 330 | |
| 331 | 331 | $sth = $this->db->prepare($query); |
| 332 | 332 | $sth->execute(array(':ident' => $ident)); |
@@ -338,12 +338,12 @@ discard block |
||
| 338 | 338 | return $spotter_array; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Gets all the spotter information based on a particular id |
|
| 343 | - * |
|
| 344 | - * @return Array the spotter information |
|
| 345 | - * |
|
| 346 | - */ |
|
| 341 | + /** |
|
| 342 | + * Gets all the spotter information based on a particular id |
|
| 343 | + * |
|
| 344 | + * @return Array the spotter information |
|
| 345 | + * |
|
| 346 | + */ |
|
| 347 | 347 | public function getAllLiveSpotterDataById($id) |
| 348 | 348 | { |
| 349 | 349 | date_default_timezone_set('UTC'); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | $query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
| 352 | 352 | // $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id)); |
| 353 | 353 | |
| 354 | - try { |
|
| 354 | + try { |
|
| 355 | 355 | |
| 356 | 356 | $sth = $this->db->prepare($query); |
| 357 | 357 | $sth->execute(array(':id' => $id)); |
@@ -363,18 +363,18 @@ discard block |
||
| 363 | 363 | return $spotter_array; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Gets all the spotter information based on a particular ident |
|
| 368 | - * |
|
| 369 | - * @return Array the spotter information |
|
| 370 | - * |
|
| 371 | - */ |
|
| 366 | + /** |
|
| 367 | + * Gets all the spotter information based on a particular ident |
|
| 368 | + * |
|
| 369 | + * @return Array the spotter information |
|
| 370 | + * |
|
| 371 | + */ |
|
| 372 | 372 | public function getAllLiveSpotterDataByIdent($ident) |
| 373 | 373 | { |
| 374 | 374 | date_default_timezone_set('UTC'); |
| 375 | 375 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 376 | 376 | $query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
| 377 | - try { |
|
| 377 | + try { |
|
| 378 | 378 | |
| 379 | 379 | $sth = $this->db->prepare($query); |
| 380 | 380 | $sth->execute(array(':ident' => $ident)); |
@@ -387,24 +387,24 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | /** |
| 390 | - * Deletes all info in the table |
|
| 391 | - * |
|
| 392 | - * @return String success or false |
|
| 393 | - * |
|
| 394 | - */ |
|
| 390 | + * Deletes all info in the table |
|
| 391 | + * |
|
| 392 | + * @return String success or false |
|
| 393 | + * |
|
| 394 | + */ |
|
| 395 | 395 | public function deleteLiveSpotterData() |
| 396 | 396 | { |
| 397 | 397 | global $globalDBdriver; |
| 398 | 398 | if ($globalDBdriver == 'mysql') { |
| 399 | 399 | //$query = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date"; |
| 400 | 400 | $query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
| 401 | - //$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
|
| 401 | + //$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
|
| 402 | 402 | |
| 403 | 403 | } elseif ($globalDBdriver == 'pgsql') { |
| 404 | 404 | $query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - try { |
|
| 407 | + try { |
|
| 408 | 408 | |
| 409 | 409 | $sth = $this->db->prepare($query); |
| 410 | 410 | $sth->execute(); |
@@ -416,18 +416,18 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
| 419 | - * Deletes all info in the table for aircraft not seen since 2 HOUR |
|
| 420 | - * |
|
| 421 | - * @return String success or false |
|
| 422 | - * |
|
| 423 | - */ |
|
| 419 | + * Deletes all info in the table for aircraft not seen since 2 HOUR |
|
| 420 | + * |
|
| 421 | + * @return String success or false |
|
| 422 | + * |
|
| 423 | + */ |
|
| 424 | 424 | public function deleteLiveSpotterDataNotUpdated() |
| 425 | 425 | { |
| 426 | 426 | global $globalDBdriver, $globalDebug; |
| 427 | 427 | if ($globalDBdriver == 'mysql') { |
| 428 | 428 | //$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0'; |
| 429 | - $query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0"; |
|
| 430 | - try { |
|
| 429 | + $query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0"; |
|
| 430 | + try { |
|
| 431 | 431 | |
| 432 | 432 | $sth = $this->db->prepare($query); |
| 433 | 433 | $sth->execute(); |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | return "error"; |
| 436 | 436 | } |
| 437 | 437 | $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
| 438 | - $i = 0; |
|
| 439 | - $j =0; |
|
| 438 | + $i = 0; |
|
| 439 | + $j =0; |
|
| 440 | 440 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 441 | 441 | foreach($all as $row) |
| 442 | 442 | { |
@@ -444,20 +444,20 @@ discard block |
||
| 444 | 444 | $j++; |
| 445 | 445 | if ($j == 30) { |
| 446 | 446 | if ($globalDebug) echo "."; |
| 447 | - try { |
|
| 447 | + try { |
|
| 448 | 448 | |
| 449 | 449 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
| 450 | 450 | $sth->execute(); |
| 451 | 451 | } catch(PDOException $e) { |
| 452 | 452 | return "error"; |
| 453 | 453 | } |
| 454 | - $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
|
| 455 | - $j = 0; |
|
| 454 | + $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
|
| 455 | + $j = 0; |
|
| 456 | 456 | } |
| 457 | 457 | $query_delete .= "'".$row['flightaware_id']."',"; |
| 458 | 458 | } |
| 459 | 459 | if ($i > 0) { |
| 460 | - try { |
|
| 460 | + try { |
|
| 461 | 461 | |
| 462 | 462 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
| 463 | 463 | $sth->execute(); |
@@ -468,9 +468,9 @@ discard block |
||
| 468 | 468 | return "success"; |
| 469 | 469 | } elseif ($globalDBdriver == 'pgsql') { |
| 470 | 470 | //$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0"; |
| 471 | - //$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0"; |
|
| 472 | - $query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)"; |
|
| 473 | - try { |
|
| 471 | + //$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0"; |
|
| 472 | + $query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)"; |
|
| 473 | + try { |
|
| 474 | 474 | |
| 475 | 475 | $sth = $this->db->prepare($query); |
| 476 | 476 | $sth->execute(); |
@@ -514,17 +514,17 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
| 517 | - * Deletes all info in the table for an ident |
|
| 518 | - * |
|
| 519 | - * @return String success or false |
|
| 520 | - * |
|
| 521 | - */ |
|
| 517 | + * Deletes all info in the table for an ident |
|
| 518 | + * |
|
| 519 | + * @return String success or false |
|
| 520 | + * |
|
| 521 | + */ |
|
| 522 | 522 | public function deleteLiveSpotterDataByIdent($ident) |
| 523 | 523 | { |
| 524 | 524 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 525 | 525 | $query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
| 526 | 526 | |
| 527 | - try { |
|
| 527 | + try { |
|
| 528 | 528 | |
| 529 | 529 | $sth = $this->db->prepare($query); |
| 530 | 530 | $sth->execute(array(':ident' => $ident)); |
@@ -536,17 +536,17 @@ discard block |
||
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
| 539 | - * Deletes all info in the table for an id |
|
| 540 | - * |
|
| 541 | - * @return String success or false |
|
| 542 | - * |
|
| 543 | - */ |
|
| 539 | + * Deletes all info in the table for an id |
|
| 540 | + * |
|
| 541 | + * @return String success or false |
|
| 542 | + * |
|
| 543 | + */ |
|
| 544 | 544 | public function deleteLiveSpotterDataById($id) |
| 545 | 545 | { |
| 546 | 546 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
| 547 | 547 | $query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
| 548 | 548 | |
| 549 | - try { |
|
| 549 | + try { |
|
| 550 | 550 | |
| 551 | 551 | $sth = $this->db->prepare($query); |
| 552 | 552 | $sth->execute(array(':id' => $id)); |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | |
| 560 | 560 | |
| 561 | 561 | /** |
| 562 | - * Gets the aircraft ident within the last hour |
|
| 563 | - * |
|
| 564 | - * @return String the ident |
|
| 565 | - * |
|
| 566 | - */ |
|
| 562 | + * Gets the aircraft ident within the last hour |
|
| 563 | + * |
|
| 564 | + * @return String the ident |
|
| 565 | + * |
|
| 566 | + */ |
|
| 567 | 567 | public function getIdentFromLastHour($ident) |
| 568 | 568 | { |
| 569 | 569 | global $globalDBdriver, $globalTimezone; |
@@ -589,14 +589,14 @@ discard block |
||
| 589 | 589 | $ident_result = $row['ident']; |
| 590 | 590 | } |
| 591 | 591 | return $ident_result; |
| 592 | - } |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | 594 | /** |
| 595 | - * Check recent aircraft |
|
| 596 | - * |
|
| 597 | - * @return String the ident |
|
| 598 | - * |
|
| 599 | - */ |
|
| 595 | + * Check recent aircraft |
|
| 596 | + * |
|
| 597 | + * @return String the ident |
|
| 598 | + * |
|
| 599 | + */ |
|
| 600 | 600 | public function checkIdentRecent($ident) |
| 601 | 601 | { |
| 602 | 602 | global $globalDBdriver, $globalTimezone; |
@@ -622,14 +622,14 @@ discard block |
||
| 622 | 622 | $ident_result = $row['flightaware_id']; |
| 623 | 623 | } |
| 624 | 624 | return $ident_result; |
| 625 | - } |
|
| 625 | + } |
|
| 626 | 626 | |
| 627 | 627 | /** |
| 628 | - * Check recent aircraft by ModeS |
|
| 629 | - * |
|
| 630 | - * @return String the ModeS |
|
| 631 | - * |
|
| 632 | - */ |
|
| 628 | + * Check recent aircraft by ModeS |
|
| 629 | + * |
|
| 630 | + * @return String the ModeS |
|
| 631 | + * |
|
| 632 | + */ |
|
| 633 | 633 | public function checkModeSRecent($modes) |
| 634 | 634 | { |
| 635 | 635 | global $globalDBdriver, $globalTimezone; |
@@ -656,19 +656,19 @@ discard block |
||
| 656 | 656 | $ident_result = $row['flightaware_id']; |
| 657 | 657 | } |
| 658 | 658 | return $ident_result; |
| 659 | - } |
|
| 659 | + } |
|
| 660 | 660 | |
| 661 | 661 | /** |
| 662 | - * Adds a new spotter data |
|
| 663 | - * |
|
| 664 | - * @param String $flightaware_id the ID from flightaware |
|
| 665 | - * @param String $ident the flight ident |
|
| 666 | - * @param String $aircraft_icao the aircraft type |
|
| 667 | - * @param String $departure_airport_icao the departure airport |
|
| 668 | - * @param String $arrival_airport_icao the arrival airport |
|
| 669 | - * @return String success or false |
|
| 670 | - * |
|
| 671 | - */ |
|
| 662 | + * Adds a new spotter data |
|
| 663 | + * |
|
| 664 | + * @param String $flightaware_id the ID from flightaware |
|
| 665 | + * @param String $ident the flight ident |
|
| 666 | + * @param String $aircraft_icao the aircraft type |
|
| 667 | + * @param String $departure_airport_icao the departure airport |
|
| 668 | + * @param String $arrival_airport_icao the arrival airport |
|
| 669 | + * @return String success or false |
|
| 670 | + * |
|
| 671 | + */ |
|
| 672 | 672 | public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '') |
| 673 | 673 | { |
| 674 | 674 | global $globalURL, $globalArchive, $globalDebug; |
@@ -894,10 +894,10 @@ discard block |
||
| 894 | 894 | $arrival_airport_country = ''; |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | - if ($squawk == '' || $Common->isInteger($squawk) == false ) $squawk = NULL; |
|
| 898 | - if ($verticalrate == '' || $Common->isInteger($verticalrate) == false ) $verticalrate = NULL; |
|
| 899 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) == false ) $groundspeed = 0; |
|
| 900 | - if ($heading == '' || $Common->isInteger($heading) == false ) $heading = 0; |
|
| 897 | + if ($squawk == '' || $Common->isInteger($squawk) == false ) $squawk = NULL; |
|
| 898 | + if ($verticalrate == '' || $Common->isInteger($verticalrate) == false ) $verticalrate = NULL; |
|
| 899 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) == false ) $groundspeed = 0; |
|
| 900 | + if ($heading == '' || $Common->isInteger($heading) == false ) $heading = 0; |
|
| 901 | 901 | |
| 902 | 902 | $query = 'INSERT INTO spotter_live (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, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) |
| 903 | 903 | VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country)'; |
@@ -908,13 +908,13 @@ discard block |
||
| 908 | 908 | |
| 909 | 909 | $sth = $this->db->prepare($query); |
| 910 | 910 | $sth->execute($query_values); |
| 911 | - } catch(PDOException $e) { |
|
| 912 | - return "error : ".$e->getMessage(); |
|
| 913 | - } |
|
| 911 | + } catch(PDOException $e) { |
|
| 912 | + return "error : ".$e->getMessage(); |
|
| 913 | + } |
|
| 914 | 914 | if (isset($globalArchive) && $globalArchive && $putinarchive && !$noarchive) { |
| 915 | - if ($globalDebug) echo '(Add to SBS archive : '; |
|
| 916 | - $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); |
|
| 917 | - if ($globalDebug) echo $result.')'; |
|
| 915 | + if ($globalDebug) echo '(Add to SBS archive : '; |
|
| 916 | + $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); |
|
| 917 | + if ($globalDebug) echo $result.')'; |
|
| 918 | 918 | } |
| 919 | 919 | return "success"; |
| 920 | 920 | |
@@ -24,24 +24,24 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | $filter_query = ''; |
| 26 | 26 | if (isset($filter['source']) && !empty($filter['source'])) { |
| 27 | - $filter_query = " AND format_source IN ('".implode("','",$filter['source'])."')"; |
|
| 27 | + $filter_query = " AND format_source IN ('".implode("','", $filter['source'])."')"; |
|
| 28 | 28 | } |
| 29 | 29 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
| 30 | - $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
|
| 30 | + $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
|
| 31 | 31 | } |
| 32 | 32 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
| 33 | 33 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
| 34 | 34 | } |
| 35 | 35 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 36 | - $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
|
| 36 | + $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')"; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $limit_query = ''; |
| 40 | 40 | if ($limit != '') |
| 41 | 41 | { |
| 42 | 42 | $limit_array = explode(',', $limit); |
| 43 | - $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
| 44 | - $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
| 43 | + $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT); |
|
| 44 | + $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT); |
|
| 45 | 45 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
| 46 | 46 | { |
| 47 | 47 | $limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0]; |
@@ -79,16 +79,16 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $filter_query = ''; |
| 81 | 81 | if (isset($filter['source']) && !empty($filter['source'])) { |
| 82 | - $filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
|
| 82 | + $filter_query .= " AND format_source IN ('".implode("','", $filter['source'])."') "; |
|
| 83 | 83 | } |
| 84 | 84 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
| 85 | - $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id "; |
|
| 85 | + $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id "; |
|
| 86 | 86 | } |
| 87 | 87 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
| 88 | 88 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
| 89 | 89 | } |
| 90 | 90 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 91 | - $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
|
| 91 | + $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')"; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | // $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, a.aircraft_shadow 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 INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
| 98 | 98 | // $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 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; |
| 99 | 99 | |
| 100 | - $query = 'SELECT a.aircraft_shadow, 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 |
|
| 100 | + $query = 'SELECT a.aircraft_shadow, 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 |
|
| 101 | 101 | FROM spotter_live |
| 102 | 102 | 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.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
| 103 | 103 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
| 109 | 109 | //$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
| 110 | 110 | //$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, a.aircraft_shadow 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.'INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
| 111 | - $query = "SELECT a.aircraft_shadow, 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 |
|
| 111 | + $query = "SELECT a.aircraft_shadow, 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 |
|
| 112 | 112 | FROM spotter_live |
| 113 | 113 | INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ".$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
| 114 | 114 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | try { |
| 119 | 119 | $sth = $this->db->prepare($query); |
| 120 | 120 | $sth->execute(); |
| 121 | - } catch(PDOException $e) { |
|
| 121 | + } catch (PDOException $e) { |
|
| 122 | 122 | return "error"; |
| 123 | 123 | } |
| 124 | 124 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -137,16 +137,16 @@ discard block |
||
| 137 | 137 | global $globalDBdriver, $globalLiveInterval; |
| 138 | 138 | $filter_query = ''; |
| 139 | 139 | if (isset($filter['source']) && !empty($filter['source'])) { |
| 140 | - $filter_query = " AND format_source IN ('".implode("','",$filter['source'])."')"; |
|
| 140 | + $filter_query = " AND format_source IN ('".implode("','", $filter['source'])."')"; |
|
| 141 | 141 | } |
| 142 | 142 | if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
| 143 | - $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
|
| 143 | + $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
|
| 144 | 144 | } |
| 145 | 145 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
| 146 | 146 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
| 147 | 147 | } |
| 148 | 148 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 149 | - $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
|
| 149 | + $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')"; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | try { |
| 161 | 161 | $sth = $this->db->prepare($query); |
| 162 | 162 | $sth->execute(); |
| 163 | - } catch(PDOException $e) { |
|
| 163 | + } catch (PDOException $e) { |
|
| 164 | 164 | return "error"; |
| 165 | 165 | } |
| 166 | 166 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -180,29 +180,29 @@ discard block |
||
| 180 | 180 | if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
| 181 | 181 | $filter_query = ''; |
| 182 | 182 | if (isset($filter['source'])) { |
| 183 | - $filter_query = " AND format_source IN ('".implode(',',$filter['source'])."')"; |
|
| 183 | + $filter_query = " AND format_source IN ('".implode(',', $filter['source'])."')"; |
|
| 184 | 184 | } |
| 185 | 185 | if (isset($filter['airlines'])) { |
| 186 | - $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
|
| 186 | + $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','", $filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id"; |
|
| 187 | 187 | } |
| 188 | 188 | if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
| 189 | 189 | $filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
| 190 | 190 | } |
| 191 | 191 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 192 | - $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
|
| 192 | + $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')"; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if (is_array($coord)) { |
| 196 | - $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 197 | - $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 198 | - $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 199 | - $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 196 | + $minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 197 | + $minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 198 | + $maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 199 | + $maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 200 | 200 | } else return array(); |
| 201 | 201 | if ($globalDBdriver == 'mysql') { |
| 202 | 202 | //$query = "SELECT spotter_output.* FROM spotter_output WHERE spotter_output.flightaware_id IN (SELECT spotter_live.flightaware_id 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.")"; |
| 203 | - $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; |
|
| 203 | + $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; |
|
| 204 | 204 | } else if ($globalDBdriver == 'pgsql') { |
| 205 | - $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= 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; |
|
| 205 | + $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= 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; |
|
| 206 | 206 | } |
| 207 | 207 | $spotter_array = $Spotter->getDataFromDB($query); |
| 208 | 208 | return $spotter_array; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | if ($interval == '1m') |
| 254 | 254 | { |
| 255 | 255 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
| 256 | - } else if ($interval == '15m'){ |
|
| 256 | + } else if ($interval == '15m') { |
|
| 257 | 257 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
|
| 264 | + $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
|
| 265 | 265 | WHERE spotter_live.latitude <> '' |
| 266 | 266 | AND spotter_live.longitude <> '' |
| 267 | 267 | ".$additional_query." |
| 268 | 268 | HAVING distance < :radius |
| 269 | 269 | ORDER BY distance"; |
| 270 | 270 | |
| 271 | - $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius),$limit_query); |
|
| 271 | + $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng, ':radius' => $radius), $limit_query); |
|
| 272 | 272 | |
| 273 | 273 | return $spotter_array; |
| 274 | 274 | } |
@@ -286,9 +286,9 @@ discard block |
||
| 286 | 286 | date_default_timezone_set('UTC'); |
| 287 | 287 | |
| 288 | 288 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 289 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 289 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 290 | 290 | |
| 291 | - $spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident)); |
|
| 291 | + $spotter_array = $Spotter->getDataFromDB($query, array(':ident' => $ident)); |
|
| 292 | 292 | |
| 293 | 293 | return $spotter_array; |
| 294 | 294 | } |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | date_default_timezone_set('UTC'); |
| 306 | 306 | |
| 307 | 307 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
| 308 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 308 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
| 309 | 309 | |
| 310 | - $spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id)); |
|
| 310 | + $spotter_array = $Spotter->getDataFromDB($query, array(':id' => $id)); |
|
| 311 | 311 | |
| 312 | 312 | return $spotter_array; |
| 313 | 313 | } |
@@ -324,13 +324,13 @@ discard block |
||
| 324 | 324 | date_default_timezone_set('UTC'); |
| 325 | 325 | |
| 326 | 326 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 327 | - $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
|
| 327 | + $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
|
| 328 | 328 | |
| 329 | 329 | try { |
| 330 | 330 | |
| 331 | 331 | $sth = $this->db->prepare($query); |
| 332 | 332 | $sth->execute(array(':ident' => $ident)); |
| 333 | - } catch(PDOException $e) { |
|
| 333 | + } catch (PDOException $e) { |
|
| 334 | 334 | return "error"; |
| 335 | 335 | } |
| 336 | 336 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -348,14 +348,14 @@ discard block |
||
| 348 | 348 | { |
| 349 | 349 | date_default_timezone_set('UTC'); |
| 350 | 350 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
| 351 | - $query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
|
| 351 | + $query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
|
| 352 | 352 | // $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id)); |
| 353 | 353 | |
| 354 | 354 | try { |
| 355 | 355 | |
| 356 | 356 | $sth = $this->db->prepare($query); |
| 357 | 357 | $sth->execute(array(':id' => $id)); |
| 358 | - } catch(PDOException $e) { |
|
| 358 | + } catch (PDOException $e) { |
|
| 359 | 359 | return "error"; |
| 360 | 360 | } |
| 361 | 361 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -373,12 +373,12 @@ discard block |
||
| 373 | 373 | { |
| 374 | 374 | date_default_timezone_set('UTC'); |
| 375 | 375 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 376 | - $query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
|
| 376 | + $query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
|
| 377 | 377 | try { |
| 378 | 378 | |
| 379 | 379 | $sth = $this->db->prepare($query); |
| 380 | 380 | $sth->execute(array(':ident' => $ident)); |
| 381 | - } catch(PDOException $e) { |
|
| 381 | + } catch (PDOException $e) { |
|
| 382 | 382 | return "error"; |
| 383 | 383 | } |
| 384 | 384 | $spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -397,18 +397,18 @@ discard block |
||
| 397 | 397 | global $globalDBdriver; |
| 398 | 398 | if ($globalDBdriver == 'mysql') { |
| 399 | 399 | //$query = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date"; |
| 400 | - $query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
|
| 400 | + $query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
|
| 401 | 401 | //$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
| 402 | 402 | |
| 403 | 403 | } elseif ($globalDBdriver == 'pgsql') { |
| 404 | - $query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
|
| 404 | + $query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | try { |
| 408 | 408 | |
| 409 | 409 | $sth = $this->db->prepare($query); |
| 410 | 410 | $sth->execute(); |
| 411 | - } catch(PDOException $e) { |
|
| 411 | + } catch (PDOException $e) { |
|
| 412 | 412 | return "error"; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -431,14 +431,14 @@ discard block |
||
| 431 | 431 | |
| 432 | 432 | $sth = $this->db->prepare($query); |
| 433 | 433 | $sth->execute(); |
| 434 | - } catch(PDOException $e) { |
|
| 434 | + } catch (PDOException $e) { |
|
| 435 | 435 | return "error"; |
| 436 | 436 | } |
| 437 | 437 | $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
| 438 | 438 | $i = 0; |
| 439 | - $j =0; |
|
| 439 | + $j = 0; |
|
| 440 | 440 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 441 | - foreach($all as $row) |
|
| 441 | + foreach ($all as $row) |
|
| 442 | 442 | { |
| 443 | 443 | $i++; |
| 444 | 444 | $j++; |
@@ -446,9 +446,9 @@ discard block |
||
| 446 | 446 | if ($globalDebug) echo "."; |
| 447 | 447 | try { |
| 448 | 448 | |
| 449 | - $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
|
| 449 | + $sth = $this->db->prepare(substr($query_delete, 0, -1).")"); |
|
| 450 | 450 | $sth->execute(); |
| 451 | - } catch(PDOException $e) { |
|
| 451 | + } catch (PDOException $e) { |
|
| 452 | 452 | return "error"; |
| 453 | 453 | } |
| 454 | 454 | $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
@@ -459,9 +459,9 @@ discard block |
||
| 459 | 459 | if ($i > 0) { |
| 460 | 460 | try { |
| 461 | 461 | |
| 462 | - $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
|
| 462 | + $sth = $this->db->prepare(substr($query_delete, 0, -1).")"); |
|
| 463 | 463 | $sth->execute(); |
| 464 | - } catch(PDOException $e) { |
|
| 464 | + } catch (PDOException $e) { |
|
| 465 | 465 | return "error"; |
| 466 | 466 | } |
| 467 | 467 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | |
| 475 | 475 | $sth = $this->db->prepare($query); |
| 476 | 476 | $sth->execute(); |
| 477 | - } catch(PDOException $e) { |
|
| 477 | + } catch (PDOException $e) { |
|
| 478 | 478 | return "error"; |
| 479 | 479 | } |
| 480 | 480 | /* $query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
@@ -522,13 +522,13 @@ discard block |
||
| 522 | 522 | public function deleteLiveSpotterDataByIdent($ident) |
| 523 | 523 | { |
| 524 | 524 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
| 525 | - $query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
|
| 525 | + $query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
|
| 526 | 526 | |
| 527 | 527 | try { |
| 528 | 528 | |
| 529 | 529 | $sth = $this->db->prepare($query); |
| 530 | 530 | $sth->execute(array(':ident' => $ident)); |
| 531 | - } catch(PDOException $e) { |
|
| 531 | + } catch (PDOException $e) { |
|
| 532 | 532 | return "error"; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -544,13 +544,13 @@ discard block |
||
| 544 | 544 | public function deleteLiveSpotterDataById($id) |
| 545 | 545 | { |
| 546 | 546 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
| 547 | - $query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
|
| 547 | + $query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
|
| 548 | 548 | |
| 549 | 549 | try { |
| 550 | 550 | |
| 551 | 551 | $sth = $this->db->prepare($query); |
| 552 | 552 | $sth->execute(array(':id' => $id)); |
| 553 | - } catch(PDOException $e) { |
|
| 553 | + } catch (PDOException $e) { |
|
| 554 | 554 | return "error"; |
| 555 | 555 | } |
| 556 | 556 | |
@@ -568,13 +568,13 @@ discard block |
||
| 568 | 568 | { |
| 569 | 569 | global $globalDBdriver, $globalTimezone; |
| 570 | 570 | if ($globalDBdriver == 'mysql') { |
| 571 | - $query = 'SELECT spotter_live.ident FROM spotter_live |
|
| 571 | + $query = 'SELECT spotter_live.ident FROM spotter_live |
|
| 572 | 572 | WHERE spotter_live.ident = :ident |
| 573 | 573 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
| 574 | 574 | AND spotter_live.date < UTC_TIMESTAMP()'; |
| 575 | 575 | $query_data = array(':ident' => $ident); |
| 576 | 576 | } elseif ($globalDBdriver == 'pgsql') { |
| 577 | - $query = "SELECT spotter_live.ident FROM spotter_live |
|
| 577 | + $query = "SELECT spotter_live.ident FROM spotter_live |
|
| 578 | 578 | WHERE spotter_live.ident = :ident |
| 579 | 579 | AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
| 580 | 580 | AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
@@ -583,8 +583,8 @@ discard block |
||
| 583 | 583 | |
| 584 | 584 | $sth = $this->db->prepare($query); |
| 585 | 585 | $sth->execute($query_data); |
| 586 | - $ident_result=''; |
|
| 587 | - while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 586 | + $ident_result = ''; |
|
| 587 | + while ($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 588 | 588 | { |
| 589 | 589 | $ident_result = $row['ident']; |
| 590 | 590 | } |
@@ -601,13 +601,13 @@ discard block |
||
| 601 | 601 | { |
| 602 | 602 | global $globalDBdriver, $globalTimezone; |
| 603 | 603 | if ($globalDBdriver == 'mysql') { |
| 604 | - $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
|
| 604 | + $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
|
| 605 | 605 | WHERE spotter_live.ident = :ident |
| 606 | 606 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; |
| 607 | 607 | // AND spotter_live.date < UTC_TIMESTAMP()"; |
| 608 | 608 | $query_data = array(':ident' => $ident); |
| 609 | 609 | } elseif ($globalDBdriver == 'pgsql') { |
| 610 | - $query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
|
| 610 | + $query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
|
| 611 | 611 | WHERE spotter_live.ident = :ident |
| 612 | 612 | AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'"; |
| 613 | 613 | // AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
@@ -616,8 +616,8 @@ discard block |
||
| 616 | 616 | |
| 617 | 617 | $sth = $this->db->prepare($query); |
| 618 | 618 | $sth->execute($query_data); |
| 619 | - $ident_result=''; |
|
| 620 | - while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 619 | + $ident_result = ''; |
|
| 620 | + while ($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 621 | 621 | { |
| 622 | 622 | $ident_result = $row['flightaware_id']; |
| 623 | 623 | } |
@@ -634,13 +634,13 @@ discard block |
||
| 634 | 634 | { |
| 635 | 635 | global $globalDBdriver, $globalTimezone; |
| 636 | 636 | if ($globalDBdriver == 'mysql') { |
| 637 | - $query = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
|
| 637 | + $query = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
|
| 638 | 638 | WHERE spotter_live.ModeS = :modes |
| 639 | 639 | AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; |
| 640 | 640 | // AND spotter_live.date < UTC_TIMESTAMP()"; |
| 641 | 641 | $query_data = array(':modes' => $modes); |
| 642 | 642 | } elseif ($globalDBdriver == 'pgsql') { |
| 643 | - $query = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
|
| 643 | + $query = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
|
| 644 | 644 | WHERE spotter_live.ModeS = :modes |
| 645 | 645 | AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '30 MINUTE'"; |
| 646 | 646 | // // AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
@@ -649,8 +649,8 @@ discard block |
||
| 649 | 649 | |
| 650 | 650 | $sth = $this->db->prepare($query); |
| 651 | 651 | $sth->execute($query_data); |
| 652 | - $ident_result=''; |
|
| 653 | - while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 652 | + $ident_result = ''; |
|
| 653 | + while ($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
| 654 | 654 | { |
| 655 | 655 | //$ident_result = $row['spotter_live_id']; |
| 656 | 656 | $ident_result = $row['flightaware_id']; |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | * @return String success or false |
| 670 | 670 | * |
| 671 | 671 | */ |
| 672 | - public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '') |
|
| 672 | + public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '', $departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false, $registration = '', $pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false, $format_source = '', $source_name = '', $over_country = '') |
|
| 673 | 673 | { |
| 674 | 674 | global $globalURL, $globalArchive, $globalDebug; |
| 675 | 675 | $Common = new Common(); |
@@ -827,26 +827,26 @@ discard block |
||
| 827 | 827 | } |
| 828 | 828 | */ |
| 829 | 829 | |
| 830 | - $flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
|
| 831 | - $ident = filter_var($ident,FILTER_SANITIZE_STRING); |
|
| 832 | - $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
|
| 833 | - $departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
|
| 834 | - $arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
|
| 835 | - $latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 836 | - $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 837 | - $waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
|
| 838 | - $altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 839 | - $heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
|
| 840 | - $groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
|
| 841 | - $squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
|
| 842 | - $route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
|
| 843 | - $ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
|
| 844 | - $pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
|
| 845 | - $pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
|
| 846 | - $format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
|
| 847 | - $source_name = filter_var($source_name,FILTER_SANITIZE_STRING); |
|
| 848 | - $over_country = filter_var($over_country,FILTER_SANITIZE_STRING); |
|
| 849 | - $verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
|
| 830 | + $flightaware_id = filter_var($flightaware_id, FILTER_SANITIZE_STRING); |
|
| 831 | + $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
|
| 832 | + $aircraft_icao = filter_var($aircraft_icao, FILTER_SANITIZE_STRING); |
|
| 833 | + $departure_airport_icao = filter_var($departure_airport_icao, FILTER_SANITIZE_STRING); |
|
| 834 | + $arrival_airport_icao = filter_var($arrival_airport_icao, FILTER_SANITIZE_STRING); |
|
| 835 | + $latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 836 | + $longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 837 | + $waypoints = filter_var($waypoints, FILTER_SANITIZE_STRING); |
|
| 838 | + $altitude = filter_var($altitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 839 | + $heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT); |
|
| 840 | + $groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
| 841 | + $squawk = filter_var($squawk, FILTER_SANITIZE_NUMBER_INT); |
|
| 842 | + $route_stop = filter_var($route_stop, FILTER_SANITIZE_STRING); |
|
| 843 | + $ModeS = filter_var($ModeS, FILTER_SANITIZE_STRING); |
|
| 844 | + $pilot_id = filter_var($pilot_id, FILTER_SANITIZE_STRING); |
|
| 845 | + $pilot_name = filter_var($pilot_name, FILTER_SANITIZE_STRING); |
|
| 846 | + $format_source = filter_var($format_source, FILTER_SANITIZE_STRING); |
|
| 847 | + $source_name = filter_var($source_name, FILTER_SANITIZE_STRING); |
|
| 848 | + $over_country = filter_var($over_country, FILTER_SANITIZE_STRING); |
|
| 849 | + $verticalrate = filter_var($verticalrate, FILTER_SANITIZE_NUMBER_INT); |
|
| 850 | 850 | |
| 851 | 851 | /* |
| 852 | 852 | if (!isset($airline_array) || count($airline_array) == 0) { |
@@ -894,26 +894,26 @@ discard block |
||
| 894 | 894 | $arrival_airport_country = ''; |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | - if ($squawk == '' || $Common->isInteger($squawk) == false ) $squawk = NULL; |
|
| 898 | - if ($verticalrate == '' || $Common->isInteger($verticalrate) == false ) $verticalrate = NULL; |
|
| 899 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) == false ) $groundspeed = 0; |
|
| 900 | - if ($heading == '' || $Common->isInteger($heading) == false ) $heading = 0; |
|
| 897 | + if ($squawk == '' || $Common->isInteger($squawk) == false) $squawk = NULL; |
|
| 898 | + if ($verticalrate == '' || $Common->isInteger($verticalrate) == false) $verticalrate = NULL; |
|
| 899 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) == false) $groundspeed = 0; |
|
| 900 | + if ($heading == '' || $Common->isInteger($heading) == false) $heading = 0; |
|
| 901 | 901 | |
| 902 | - $query = 'INSERT INTO spotter_live (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, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) |
|
| 902 | + $query = 'INSERT INTO spotter_live (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, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) |
|
| 903 | 903 | VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country)'; |
| 904 | 904 | |
| 905 | - $query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,':aircraft_icao' => $aircraft_icao,':aircraft_shadow' => $aircraft_shadow,':aircraft_type' => $aircraft_type,':aircraft_manufacturer' => $aircraft_manufacturer,':departure_airport_icao' => $departure_airport_icao,':departure_airport_name' => $departure_airport_name,':departure_airport_city' => $departure_airport_city,':departure_airport_country' => $departure_airport_country,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_name' => $arrival_airport_name,':arrival_airport_city' => $arrival_airport_city,':arrival_airport_country' => $arrival_airport_country,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':departure_airport_time' => $departure_airport_time,':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk,':route_stop' => $route_stop,':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source,':ground' => $ground, ':source_name' => $source_name, ':over_country' => $over_country); |
|
| 905 | + $query_values = array(':flightaware_id' => $flightaware_id, ':ident' => $ident, ':registration' => $registration, ':airline_name' => $airline_name, ':airline_icao' => $airline_icao, ':airline_country' => $airline_country, ':airline_type' => $airline_type, ':aircraft_icao' => $aircraft_icao, ':aircraft_shadow' => $aircraft_shadow, ':aircraft_type' => $aircraft_type, ':aircraft_manufacturer' => $aircraft_manufacturer, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_name' => $departure_airport_name, ':departure_airport_city' => $departure_airport_city, ':departure_airport_country' => $departure_airport_country, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk, ':route_stop' => $route_stop, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source, ':ground' => $ground, ':source_name' => $source_name, ':over_country' => $over_country); |
|
| 906 | 906 | //$query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_array[0]['name'],':airline_icao' => $airline_array[0]['icao'],':airline_country' => $airline_array[0]['country'],':airline_type' => $airline_array[0]['type'],':aircraft_icao' => $aircraft_icao,':aircraft_type' => $aircraft_array[0]['type'],':aircraft_manufacturer' => $aircraft_array[0]['manufacturer'],':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date); |
| 907 | 907 | try { |
| 908 | 908 | |
| 909 | 909 | $sth = $this->db->prepare($query); |
| 910 | 910 | $sth->execute($query_values); |
| 911 | - } catch(PDOException $e) { |
|
| 911 | + } catch (PDOException $e) { |
|
| 912 | 912 | return "error : ".$e->getMessage(); |
| 913 | 913 | } |
| 914 | 914 | if (isset($globalArchive) && $globalArchive && $putinarchive && !$noarchive) { |
| 915 | 915 | if ($globalDebug) echo '(Add to SBS archive : '; |
| 916 | - $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); |
|
| 916 | + $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); |
|
| 917 | 917 | if ($globalDebug) echo $result.')'; |
| 918 | 918 | } |
| 919 | 919 | return "success"; |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | |
| 923 | 923 | public function getOrderBy() |
| 924 | 924 | { |
| 925 | - $orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_live.date DESC")); |
|
| 925 | + $orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_live.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_live.date DESC")); |
|
| 926 | 926 | return $orderby; |
| 927 | 927 | } |
| 928 | 928 | |
@@ -54,7 +54,9 @@ discard block |
||
| 54 | 54 | $orderby_query = ' '.$search_orderby_array[$sort]['sql']; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 57 | + if (!isset($globalLiveInterval)) { |
|
| 58 | + $globalLiveInterval = '200'; |
|
| 59 | + } |
|
| 58 | 60 | if ($globalDBdriver == 'mysql') { |
| 59 | 61 | //$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"; |
| 60 | 62 | $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; |
@@ -91,7 +93,9 @@ discard block |
||
| 91 | 93 | $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
| 92 | 94 | } |
| 93 | 95 | |
| 94 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 96 | + if (!isset($globalLiveInterval)) { |
|
| 97 | + $globalLiveInterval = '200'; |
|
| 98 | + } |
|
| 95 | 99 | if ($globalDBdriver == 'mysql') { |
| 96 | 100 | // $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$orderby_query"; |
| 97 | 101 | // $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, a.aircraft_shadow 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 INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
@@ -149,7 +153,9 @@ discard block |
||
| 149 | 153 | $filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
| 150 | 154 | } |
| 151 | 155 | |
| 152 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 156 | + if (!isset($globalLiveInterval)) { |
|
| 157 | + $globalLiveInterval = '200'; |
|
| 158 | + } |
|
| 153 | 159 | if ($globalDBdriver == 'mysql') { |
| 154 | 160 | //$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; |
| 155 | 161 | $query = 'SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'.$filter_query; |
@@ -177,7 +183,9 @@ discard block |
||
| 177 | 183 | { |
| 178 | 184 | global $globalDBdriver, $globalLiveInterval; |
| 179 | 185 | $Spotter = new Spotter($this->db); |
| 180 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
| 186 | + if (!isset($globalLiveInterval)) { |
|
| 187 | + $globalLiveInterval = '200'; |
|
| 188 | + } |
|
| 181 | 189 | $filter_query = ''; |
| 182 | 190 | if (isset($filter['source'])) { |
| 183 | 191 | $filter_query = " AND format_source IN ('".implode(',',$filter['source'])."')"; |
@@ -197,7 +205,9 @@ discard block |
||
| 197 | 205 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 198 | 206 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 199 | 207 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
| 200 | - } else return array(); |
|
| 208 | + } else { |
|
| 209 | + return array(); |
|
| 210 | + } |
|
| 201 | 211 | if ($globalDBdriver == 'mysql') { |
| 202 | 212 | //$query = "SELECT spotter_output.* FROM spotter_output WHERE spotter_output.flightaware_id IN (SELECT spotter_live.flightaware_id 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.")"; |
| 203 | 213 | $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; |
@@ -443,7 +453,9 @@ discard block |
||
| 443 | 453 | $i++; |
| 444 | 454 | $j++; |
| 445 | 455 | if ($j == 30) { |
| 446 | - if ($globalDebug) echo "."; |
|
| 456 | + if ($globalDebug) { |
|
| 457 | + echo "."; |
|
| 458 | + } |
|
| 447 | 459 | try { |
| 448 | 460 | |
| 449 | 461 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
@@ -795,7 +807,9 @@ discard block |
||
| 795 | 807 | { |
| 796 | 808 | return false; |
| 797 | 809 | } |
| 798 | - } else $altitude = 0; |
|
| 810 | + } else { |
|
| 811 | + $altitude = 0; |
|
| 812 | + } |
|
| 799 | 813 | |
| 800 | 814 | if ($heading != '') |
| 801 | 815 | { |
@@ -813,7 +827,9 @@ discard block |
||
| 813 | 827 | } |
| 814 | 828 | } |
| 815 | 829 | date_default_timezone_set('UTC'); |
| 816 | - if ($date == '') $date = date("Y-m-d H:i:s", time()); |
|
| 830 | + if ($date == '') { |
|
| 831 | + $date = date("Y-m-d H:i:s", time()); |
|
| 832 | + } |
|
| 817 | 833 | |
| 818 | 834 | /* |
| 819 | 835 | //getting the aircraft image |
@@ -894,10 +910,18 @@ discard block |
||
| 894 | 910 | $arrival_airport_country = ''; |
| 895 | 911 | } |
| 896 | 912 | |
| 897 | - if ($squawk == '' || $Common->isInteger($squawk) == false ) $squawk = NULL; |
|
| 898 | - if ($verticalrate == '' || $Common->isInteger($verticalrate) == false ) $verticalrate = NULL; |
|
| 899 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) == false ) $groundspeed = 0; |
|
| 900 | - if ($heading == '' || $Common->isInteger($heading) == false ) $heading = 0; |
|
| 913 | + if ($squawk == '' || $Common->isInteger($squawk) == false ) { |
|
| 914 | + $squawk = NULL; |
|
| 915 | + } |
|
| 916 | + if ($verticalrate == '' || $Common->isInteger($verticalrate) == false ) { |
|
| 917 | + $verticalrate = NULL; |
|
| 918 | + } |
|
| 919 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) == false ) { |
|
| 920 | + $groundspeed = 0; |
|
| 921 | + } |
|
| 922 | + if ($heading == '' || $Common->isInteger($heading) == false ) { |
|
| 923 | + $heading = 0; |
|
| 924 | + } |
|
| 901 | 925 | |
| 902 | 926 | $query = 'INSERT INTO spotter_live (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, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) |
| 903 | 927 | VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country)'; |
@@ -912,9 +936,13 @@ discard block |
||
| 912 | 936 | return "error : ".$e->getMessage(); |
| 913 | 937 | } |
| 914 | 938 | if (isset($globalArchive) && $globalArchive && $putinarchive && !$noarchive) { |
| 915 | - if ($globalDebug) echo '(Add to SBS archive : '; |
|
| 939 | + if ($globalDebug) { |
|
| 940 | + echo '(Add to SBS archive : '; |
|
| 941 | + } |
|
| 916 | 942 | $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); |
| 917 | - if ($globalDebug) echo $result.')'; |
|
| 943 | + if ($globalDebug) { |
|
| 944 | + echo $result.')'; |
|
| 945 | + } |
|
| 918 | 946 | } |
| 919 | 947 | return "success"; |
| 920 | 948 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $globalLongitudeMin = '1.0'; //the minimum longitude (east) |
| 30 | 30 | |
| 31 | 31 | $globalCenterLatitude = '46.38'; //the latitude center of your coverage area |
| 32 | -$globalCenterLongitude = '5.29';//the longitude center of your coverage area |
|
| 32 | +$globalCenterLongitude = '5.29'; //the longitude center of your coverage area |
|
| 33 | 33 | |
| 34 | 34 | $globalLiveZoom = '9'; //default zoom on Live Map |
| 35 | 35 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $globalACARS = FALSE; |
| 127 | 127 | $globalACARSHost = '0.0.0.0'; // Local IP to listen |
| 128 | 128 | $globalACARSPort = '9999'; |
| 129 | -$globalACARSArchive = array('10','80','81','82','3F'); // labels of messages to archive |
|
| 129 | +$globalACARSArchive = array('10', '80', '81', '82', '3F'); // labels of messages to archive |
|
| 130 | 130 | $globalACARSArchiveKeepMonths = '0'; |
| 131 | 131 | |
| 132 | 132 | //APRS configuration (for glidernet) |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | //Retrieve Image from externals sources |
| 202 | 202 | $globalAircraftImageFetch = TRUE; |
| 203 | 203 | //Sources for Aircraft image |
| 204 | -$globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters','customsources'); |
|
| 204 | +$globalAircraftImageSources = array('ivaomtl', 'wikimedia', 'airportdata', 'deviantart', 'flickr', 'bing', 'jetphotos', 'planepictures', 'planespotters', 'customsources'); |
|
| 205 | 205 | // Custom source configuration {registration} will be replaced by aircraft registration (exif get copyright from exif data for each pic) |
| 206 | 206 | // example of config : $globalAircraftImageCustomSources = array('thumbnail' => 'http://pics.myurl.com/thumbnail/{registration}.jpg','original' => 'http://myurl/original/{registration}.jpg','source_website' => 'https://www.myurl.com', 'source' => 'customsite', 'exif' => true); |
| 207 | 207 | // ************************ |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | //Retrieve schedules from externals sources (set to FALSE for IVAO or if $globalFork = FALSE) |
| 210 | 210 | $globalSchedulesFetch = TRUE; |
| 211 | 211 | //Sources for airline schedule if not official airline site |
| 212 | -$globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware'); |
|
| 212 | +$globalSchedulesSources = array('flightmapper', 'costtotravel', 'flightradar24', 'flightaware'); |
|
| 213 | 213 | |
| 214 | 214 | //Retrieve translation from external sources (set to FALSE for IVAO) |
| 215 | 215 | $globalTranslationFetch = TRUE; |
@@ -7,107 +7,107 @@ discard block |
||
| 7 | 7 | public $db; |
| 8 | 8 | |
| 9 | 9 | protected $texts = Array( |
| 10 | - 'MI' => 'Shallow', |
|
| 11 | - 'PR' => 'Partial', |
|
| 12 | - 'BC' => 'Low drifting', |
|
| 13 | - 'BL' => 'Blowing', |
|
| 14 | - 'SH' => 'Showers', |
|
| 15 | - 'TS' => 'Thunderstorm', |
|
| 16 | - 'FZ' => 'Freezing', |
|
| 17 | - 'DZ' => 'Drizzle', |
|
| 18 | - 'RA' => 'Rain', |
|
| 19 | - 'SN' => 'Snow', |
|
| 20 | - 'SG' => 'Snow Grains', |
|
| 21 | - 'IC' => 'Ice crystals', |
|
| 22 | - 'PL' => 'Ice pellets', |
|
| 23 | - 'GR' => 'Hail', |
|
| 24 | - 'GS' => 'Small hail', |
|
| 25 | - 'UP' => 'Unknown', |
|
| 26 | - 'BR' => 'Mist', |
|
| 27 | - 'FG' => 'Fog', |
|
| 28 | - 'FU' => 'Smoke', |
|
| 29 | - 'VA' => 'Volcanic ash', |
|
| 30 | - 'DU' => 'Widespread dust', |
|
| 31 | - 'SA' => 'Sand', |
|
| 32 | - 'HZ' => 'Haze', |
|
| 33 | - 'PY' => 'Spray', |
|
| 34 | - 'PO' => 'Well developed dust / sand whirls', |
|
| 35 | - 'SQ' => 'Squalls', |
|
| 36 | - 'FC' => 'Funnel clouds inc tornadoes or waterspouts', |
|
| 37 | - 'SS' => 'Sandstorm', |
|
| 38 | - 'DS' => 'Duststorm' |
|
| 10 | + 'MI' => 'Shallow', |
|
| 11 | + 'PR' => 'Partial', |
|
| 12 | + 'BC' => 'Low drifting', |
|
| 13 | + 'BL' => 'Blowing', |
|
| 14 | + 'SH' => 'Showers', |
|
| 15 | + 'TS' => 'Thunderstorm', |
|
| 16 | + 'FZ' => 'Freezing', |
|
| 17 | + 'DZ' => 'Drizzle', |
|
| 18 | + 'RA' => 'Rain', |
|
| 19 | + 'SN' => 'Snow', |
|
| 20 | + 'SG' => 'Snow Grains', |
|
| 21 | + 'IC' => 'Ice crystals', |
|
| 22 | + 'PL' => 'Ice pellets', |
|
| 23 | + 'GR' => 'Hail', |
|
| 24 | + 'GS' => 'Small hail', |
|
| 25 | + 'UP' => 'Unknown', |
|
| 26 | + 'BR' => 'Mist', |
|
| 27 | + 'FG' => 'Fog', |
|
| 28 | + 'FU' => 'Smoke', |
|
| 29 | + 'VA' => 'Volcanic ash', |
|
| 30 | + 'DU' => 'Widespread dust', |
|
| 31 | + 'SA' => 'Sand', |
|
| 32 | + 'HZ' => 'Haze', |
|
| 33 | + 'PY' => 'Spray', |
|
| 34 | + 'PO' => 'Well developed dust / sand whirls', |
|
| 35 | + 'SQ' => 'Squalls', |
|
| 36 | + 'FC' => 'Funnel clouds inc tornadoes or waterspouts', |
|
| 37 | + 'SS' => 'Sandstorm', |
|
| 38 | + 'DS' => 'Duststorm' |
|
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | function __construct($dbc = null) { |
| 42 | - $Connection = new Connection($dbc); |
|
| 43 | - $this->db = $Connection->db; |
|
| 44 | - } |
|
| 42 | + $Connection = new Connection($dbc); |
|
| 43 | + $this->db = $Connection->db; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public static function check_last_update() { |
|
| 47 | - global $globalDBdriver; |
|
| 48 | - if ($globalDBdriver == 'mysql') { |
|
| 46 | + public static function check_last_update() { |
|
| 47 | + global $globalDBdriver; |
|
| 48 | + if ($globalDBdriver == 'mysql') { |
|
| 49 | 49 | $query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value > DATE_SUB(DATE(NOW()), INTERVAL 1 HOUR)"; |
| 50 | 50 | } else { |
| 51 | 51 | $query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '1 HOURS'"; |
| 52 | 52 | } |
| 53 | - try { |
|
| 54 | - $Connection = new Connection(); |
|
| 55 | - $sth = $Connection->db->prepare($query); |
|
| 56 | - $sth->execute(); |
|
| 57 | - } catch(PDOException $e) { |
|
| 58 | - return "error : ".$e->getMessage(); |
|
| 59 | - } |
|
| 60 | - $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
| 61 | - if ($row['nb'] > 0) return false; |
|
| 62 | - else return true; |
|
| 63 | - } |
|
| 53 | + try { |
|
| 54 | + $Connection = new Connection(); |
|
| 55 | + $sth = $Connection->db->prepare($query); |
|
| 56 | + $sth->execute(); |
|
| 57 | + } catch(PDOException $e) { |
|
| 58 | + return "error : ".$e->getMessage(); |
|
| 59 | + } |
|
| 60 | + $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
| 61 | + if ($row['nb'] > 0) return false; |
|
| 62 | + else return true; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public static function insert_last_update() { |
|
| 66 | - $query = "DELETE FROM config WHERE name = 'last_update_metar'; |
|
| 65 | + public static function insert_last_update() { |
|
| 66 | + $query = "DELETE FROM config WHERE name = 'last_update_metar'; |
|
| 67 | 67 | INSERT INTO config (name,value) VALUES ('last_update_metar',NOW());"; |
| 68 | - try { |
|
| 69 | - $Connection = new Connection(); |
|
| 70 | - $sth = $Connection->db->prepare($query); |
|
| 71 | - $sth->execute(); |
|
| 72 | - } catch(PDOException $e) { |
|
| 73 | - return "error : ".$e->getMessage(); |
|
| 74 | - } |
|
| 75 | - } |
|
| 68 | + try { |
|
| 69 | + $Connection = new Connection(); |
|
| 70 | + $sth = $Connection->db->prepare($query); |
|
| 71 | + $sth->execute(); |
|
| 72 | + } catch(PDOException $e) { |
|
| 73 | + return "error : ".$e->getMessage(); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - public function parse($data) { |
|
| 80 | - //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
|
| 81 | - $codes = implode('|', array_keys($this->texts)); |
|
| 82 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 83 | - //$pieces = explode(' ',$data); |
|
| 84 | - $pieces = preg_split('/\s/',$data); |
|
| 85 | - $pos = 0; |
|
| 86 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 87 | - elseif ($pieces[0] == 'SPECI') $pos++; |
|
| 88 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 89 | - $result['location'] = $pieces[$pos]; |
|
| 90 | - $pos++; |
|
| 91 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 92 | - $result['time'] = substr($pieces[$pos],2,4); |
|
| 93 | - $c = count($pieces); |
|
| 94 | - for($pos++; $pos < $c; $pos++) { |
|
| 95 | - $piece = $pieces[$pos]; |
|
| 96 | - if ($piece == 'RMK') break; |
|
| 97 | - if ($piece == 'AUTO') $result['auto'] = true; |
|
| 98 | - if ($piece == 'COR') $result['correction'] = true; |
|
| 99 | - // Wind Speed |
|
| 100 | - if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
|
| 101 | - $result['wind']['direction'] = (float)$matches[1]; |
|
| 79 | + public function parse($data) { |
|
| 80 | + //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
|
| 81 | + $codes = implode('|', array_keys($this->texts)); |
|
| 82 | + $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 83 | + //$pieces = explode(' ',$data); |
|
| 84 | + $pieces = preg_split('/\s/',$data); |
|
| 85 | + $pos = 0; |
|
| 86 | + if ($pieces[0] == 'METAR') $pos++; |
|
| 87 | + elseif ($pieces[0] == 'SPECI') $pos++; |
|
| 88 | + if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 89 | + $result['location'] = $pieces[$pos]; |
|
| 90 | + $pos++; |
|
| 91 | + $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 92 | + $result['time'] = substr($pieces[$pos],2,4); |
|
| 93 | + $c = count($pieces); |
|
| 94 | + for($pos++; $pos < $c; $pos++) { |
|
| 95 | + $piece = $pieces[$pos]; |
|
| 96 | + if ($piece == 'RMK') break; |
|
| 97 | + if ($piece == 'AUTO') $result['auto'] = true; |
|
| 98 | + if ($piece == 'COR') $result['correction'] = true; |
|
| 99 | + // Wind Speed |
|
| 100 | + if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
|
| 101 | + $result['wind']['direction'] = (float)$matches[1]; |
|
| 102 | 102 | $result['wind']['unit'] = $matches[4]; |
| 103 | - if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 104 | - elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 105 | - elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 103 | + if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 104 | + elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 105 | + elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 106 | 106 | $result['wind']['gust'] = (float)$matches[3]; |
| 107 | 107 | $result['wind']['unit'] = $matches[4]; |
| 108 | 108 | $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
| 109 | 109 | $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
| 110 | - } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
| 113 | 113 | $result['wind_direction'] = (float)$matches[1]; |
@@ -124,35 +124,35 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | */ |
| 127 | - // Temperature |
|
| 128 | - if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
|
| 129 | - $temp = (float)$matches[1]; |
|
| 127 | + // Temperature |
|
| 128 | + if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
|
| 129 | + $temp = (float)$matches[1]; |
|
| 130 | 130 | if ($matches[1]{0} == 'M') { |
| 131 | 131 | $temp = ((float)substr($matches[1], 1)) * -1; |
| 132 | 132 | } |
| 133 | - $result['temperature'] = $temp; |
|
| 134 | - $dew = (float)$matches[2]; |
|
| 133 | + $result['temperature'] = $temp; |
|
| 134 | + $dew = (float)$matches[2]; |
|
| 135 | 135 | if ($matches[2]{0} == 'M') { |
| 136 | 136 | $dew = ((float)substr($matches[2], 1)) * -1; |
| 137 | 137 | } |
| 138 | 138 | $result['dew'] = $dew; |
| 139 | - } |
|
| 140 | - // QNH |
|
| 141 | - if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
|
| 142 | - // #^(Q|A)(////|[0-9]{4})( )# |
|
| 143 | - if ($matches[1] == 'Q') { |
|
| 144 | - // hPa |
|
| 145 | - $result['QNH'] = $matches[2]; |
|
| 146 | - } else { |
|
| 147 | - // inHg |
|
| 148 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 149 | 139 | } |
| 150 | - /* |
|
| 140 | + // QNH |
|
| 141 | + if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
|
| 142 | + // #^(Q|A)(////|[0-9]{4})( )# |
|
| 143 | + if ($matches[1] == 'Q') { |
|
| 144 | + // hPa |
|
| 145 | + $result['QNH'] = $matches[2]; |
|
| 146 | + } else { |
|
| 147 | + // inHg |
|
| 148 | + $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 149 | + } |
|
| 150 | + /* |
|
| 151 | 151 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
| 152 | 152 | $result['QNH_format'] = $matches[1] == 'Q' ? 'hPa' : 'inHg'; |
| 153 | 153 | */ |
| 154 | - } |
|
| 155 | - /* |
|
| 154 | + } |
|
| 155 | + /* |
|
| 156 | 156 | // Wind Direction |
| 157 | 157 | if (preg_match('#^([0-9]{3})V([0-9]{3})$#', $piece, $matches)) { |
| 158 | 158 | $result['wind_direction'] = $matches[1]; |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | $result['speed_variable'] = $matches[1]; |
| 164 | 164 | } |
| 165 | 165 | */ |
| 166 | - // Visibility |
|
| 167 | - if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
|
| 168 | - if (isset($matches[3]) && strlen($matches[3]) > 0) { |
|
| 166 | + // Visibility |
|
| 167 | + if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
|
| 168 | + if (isset($matches[3]) && strlen($matches[3]) > 0) { |
|
| 169 | 169 | $result['visibility'] = (float)$matches[3] * 1609.34; |
| 170 | 170 | } else { |
| 171 | 171 | if ($matches[1] == '9999') { |
@@ -178,26 +178,26 @@ discard block |
||
| 178 | 178 | $result['visibility'] = '> 10000'; |
| 179 | 179 | $result['weather'] = "CAVOK"; |
| 180 | 180 | } |
| 181 | - } |
|
| 182 | - // Cloud Coverage |
|
| 183 | - if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) { |
|
| 184 | - //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
|
| 185 | - $type = $matches[1]; |
|
| 186 | - if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear'; |
|
| 187 | - elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
| 188 | - elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud'; |
|
| 189 | - elseif ($type == 'FEW') $cloud['type'] = 'Few'; |
|
| 190 | - elseif ($type == 'SCT') $cloud['type'] = 'Scattered'; |
|
| 191 | - elseif ($type == 'BKN') $cloud['type'] = 'Broken'; |
|
| 192 | - elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
| 193 | - elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
|
| 194 | - $cloud['type_code'] = $type; |
|
| 195 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 196 | - $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
|
| 197 | - $result['cloud'][] = $cloud; |
|
| 198 | - } |
|
| 199 | - // RVR |
|
| 200 | - if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) { |
|
| 181 | + } |
|
| 182 | + // Cloud Coverage |
|
| 183 | + if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) { |
|
| 184 | + //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
|
| 185 | + $type = $matches[1]; |
|
| 186 | + if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear'; |
|
| 187 | + elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
| 188 | + elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud'; |
|
| 189 | + elseif ($type == 'FEW') $cloud['type'] = 'Few'; |
|
| 190 | + elseif ($type == 'SCT') $cloud['type'] = 'Scattered'; |
|
| 191 | + elseif ($type == 'BKN') $cloud['type'] = 'Broken'; |
|
| 192 | + elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
| 193 | + elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
|
| 194 | + $cloud['type_code'] = $type; |
|
| 195 | + $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 196 | + $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
|
| 197 | + $result['cloud'][] = $cloud; |
|
| 198 | + } |
|
| 199 | + // RVR |
|
| 200 | + if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) { |
|
| 201 | 201 | $rvr['runway'] = $matches[1]; |
| 202 | 202 | $rvr['assessment'] = $matches[2]; |
| 203 | 203 | $rvr['rvr'] = $matches[3]; |
@@ -206,33 +206,33 @@ discard block |
||
| 206 | 206 | $result['RVR'] = $rvr; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 210 | - if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) { |
|
| 211 | - //print_r($matches); |
|
| 212 | - // https://github.com/davidmegginson/metar-taf/blob/master/Metar.php |
|
| 213 | - $result['RVR']['runway'] = $matches[1]; |
|
| 214 | - $result['RVR']['deposits'] = $matches[2]; |
|
| 215 | - $result['RVR']['extent'] = $matches[3]; |
|
| 216 | - $result['RVR']['depth'] = $matches[4]; |
|
| 217 | - $result['RVR']['friction'] = $matches[5]; |
|
| 218 | - } |
|
| 219 | - if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 220 | - //echo $piece; |
|
| 221 | - //print_r($matches); |
|
| 222 | - if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 223 | - else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 209 | + //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 210 | + if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) { |
|
| 211 | + //print_r($matches); |
|
| 212 | + // https://github.com/davidmegginson/metar-taf/blob/master/Metar.php |
|
| 213 | + $result['RVR']['runway'] = $matches[1]; |
|
| 214 | + $result['RVR']['deposits'] = $matches[2]; |
|
| 215 | + $result['RVR']['extent'] = $matches[3]; |
|
| 216 | + $result['RVR']['depth'] = $matches[4]; |
|
| 217 | + $result['RVR']['friction'] = $matches[5]; |
|
| 218 | + } |
|
| 219 | + if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
|
| 220 | + //echo $piece; |
|
| 221 | + //print_r($matches); |
|
| 222 | + if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 223 | + else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 224 | 224 | if (isset($matches[3])) { |
| 225 | 225 | $range = Array( |
| 226 | - 'from' => (float)$matches[2], |
|
| 227 | - 'to' => (float)$matches[4], |
|
| 228 | - 'unit' => $matches[5] ? 'FT' : 'M' |
|
| 226 | + 'from' => (float)$matches[2], |
|
| 227 | + 'to' => (float)$matches[4], |
|
| 228 | + 'unit' => $matches[5] ? 'FT' : 'M' |
|
| 229 | 229 | ); |
| 230 | 230 | } |
| 231 | 231 | $result['RVR'] = $matches[1]; |
| 232 | 232 | $result['RVR_range'] = $range; |
| 233 | - } |
|
| 234 | - // Weather |
|
| 235 | - if (preg_match($regWeather, $piece, $matches)) { |
|
| 233 | + } |
|
| 234 | + // Weather |
|
| 235 | + if (preg_match($regWeather, $piece, $matches)) { |
|
| 236 | 236 | $text = Array(); |
| 237 | 237 | switch ($matches[1]) { |
| 238 | 238 | case '+': |
@@ -255,35 +255,35 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | if (!isset($result['weather'])) $result['weather'] = implode(' ', $text); |
| 257 | 257 | else $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
| 258 | - } |
|
| 259 | - } |
|
| 260 | - return $result; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + return $result; |
|
| 261 | 261 | |
| 262 | - } |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | 264 | public function getMETAR($icao) { |
| 265 | - global $globalMETARcycle, $globalDBdriver; |
|
| 266 | - if (isset($globalMETARcycle) && $globalMETARcycle) { |
|
| 267 | - $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
|
| 268 | - } else { |
|
| 269 | - if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
| 270 | - elseif ($globalDBdriver == 'pgsql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
| 271 | - } |
|
| 272 | - $query_values = array(':icao' => $icao); |
|
| 273 | - try { |
|
| 274 | - $sth = $this->db->prepare($query); |
|
| 275 | - $sth->execute($query_values); |
|
| 276 | - } catch(PDOException $e) { |
|
| 277 | - return "error : ".$e->getMessage(); |
|
| 278 | - } |
|
| 279 | - $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 280 | - if ((!isset($globalMETARcyle) || $globalMETARcycle === false) && count($all) == 0) { |
|
| 281 | - $all = $this->downloadMETAR($icao); |
|
| 282 | - } |
|
| 283 | - return $all; |
|
| 284 | - } |
|
| 265 | + global $globalMETARcycle, $globalDBdriver; |
|
| 266 | + if (isset($globalMETARcycle) && $globalMETARcycle) { |
|
| 267 | + $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
|
| 268 | + } else { |
|
| 269 | + if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
| 270 | + elseif ($globalDBdriver == 'pgsql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
| 271 | + } |
|
| 272 | + $query_values = array(':icao' => $icao); |
|
| 273 | + try { |
|
| 274 | + $sth = $this->db->prepare($query); |
|
| 275 | + $sth->execute($query_values); |
|
| 276 | + } catch(PDOException $e) { |
|
| 277 | + return "error : ".$e->getMessage(); |
|
| 278 | + } |
|
| 279 | + $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 280 | + if ((!isset($globalMETARcyle) || $globalMETARcycle === false) && count($all) == 0) { |
|
| 281 | + $all = $this->downloadMETAR($icao); |
|
| 282 | + } |
|
| 283 | + return $all; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - public function addMETAR($location,$metar,$date) { |
|
| 286 | + public function addMETAR($location,$metar,$date) { |
|
| 287 | 287 | global $globalDBdriver; |
| 288 | 288 | $date = date('Y-m-d H:i:s',strtotime($date)); |
| 289 | 289 | if ($globalDBdriver == 'mysql') { |
@@ -291,98 +291,98 @@ discard block |
||
| 291 | 291 | } else { |
| 292 | 292 | $query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);"; |
| 293 | 293 | } |
| 294 | - $query_values = array(':location' => $location,':date' => $date,':metar' => $metar); |
|
| 295 | - try { |
|
| 296 | - $sth = $this->db->prepare($query); |
|
| 297 | - $sth->execute($query_values); |
|
| 298 | - } catch(PDOException $e) { |
|
| 299 | - return "error : ".$e->getMessage(); |
|
| 300 | - } |
|
| 301 | - } |
|
| 294 | + $query_values = array(':location' => $location,':date' => $date,':metar' => $metar); |
|
| 295 | + try { |
|
| 296 | + $sth = $this->db->prepare($query); |
|
| 297 | + $sth->execute($query_values); |
|
| 298 | + } catch(PDOException $e) { |
|
| 299 | + return "error : ".$e->getMessage(); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - public function deleteMETAR($id) { |
|
| 304 | - $query = "DELETE FROM metar WHERE id = :id"; |
|
| 305 | - $query_values = array(':id' => $id); |
|
| 306 | - try { |
|
| 307 | - $sth = $this->db->prepare($query); |
|
| 308 | - $sth->execute($query_values); |
|
| 309 | - } catch(PDOException $e) { |
|
| 310 | - return "error : ".$e->getMessage(); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - public function deleteAllMETARLocation() { |
|
| 314 | - $query = "DELETE FROM metar"; |
|
| 315 | - try { |
|
| 316 | - $sth = $this->db->prepare($query); |
|
| 317 | - $sth->execute(); |
|
| 318 | - } catch(PDOException $e) { |
|
| 319 | - return "error : ".$e->getMessage(); |
|
| 320 | - } |
|
| 321 | - } |
|
| 303 | + public function deleteMETAR($id) { |
|
| 304 | + $query = "DELETE FROM metar WHERE id = :id"; |
|
| 305 | + $query_values = array(':id' => $id); |
|
| 306 | + try { |
|
| 307 | + $sth = $this->db->prepare($query); |
|
| 308 | + $sth->execute($query_values); |
|
| 309 | + } catch(PDOException $e) { |
|
| 310 | + return "error : ".$e->getMessage(); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + public function deleteAllMETARLocation() { |
|
| 314 | + $query = "DELETE FROM metar"; |
|
| 315 | + try { |
|
| 316 | + $sth = $this->db->prepare($query); |
|
| 317 | + $sth->execute(); |
|
| 318 | + } catch(PDOException $e) { |
|
| 319 | + return "error : ".$e->getMessage(); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - public function addMETARCycle() { |
|
| 324 | - global $globalDebug, $globalIVAO; |
|
| 325 | - if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
| 326 | - date_default_timezone_set("UTC"); |
|
| 327 | - $Common = new Common(); |
|
| 328 | - if (isset($globalIVAO) && $globalIVAO) { |
|
| 329 | - $cycle = $Common->getData('http://wx.ivao.aero/metar.php'); |
|
| 330 | - } else { |
|
| 323 | + public function addMETARCycle() { |
|
| 324 | + global $globalDebug, $globalIVAO; |
|
| 325 | + if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
| 326 | + date_default_timezone_set("UTC"); |
|
| 327 | + $Common = new Common(); |
|
| 328 | + if (isset($globalIVAO) && $globalIVAO) { |
|
| 329 | + $cycle = $Common->getData('http://wx.ivao.aero/metar.php'); |
|
| 330 | + } else { |
|
| 331 | 331 | $cycle = $Common->getData('http://weather.noaa.gov/pub/data/observations/metar/cycles/'.date('H').'Z.TXT'); |
| 332 | - } |
|
| 333 | - if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
| 334 | - $date = ''; |
|
| 335 | - foreach(explode("\n",$cycle) as $line) { |
|
| 336 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 337 | - //echo "date : ".$line."\n"; |
|
| 338 | - $date = $line; |
|
| 339 | - } elseif ($line != '') { |
|
| 340 | - //$this->parse($line); |
|
| 341 | - //echo $line; |
|
| 342 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 343 | - $pos = 0; |
|
| 344 | - $pieces = preg_split('/\s/',$line); |
|
| 345 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 346 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 347 | - $location = $pieces[$pos]; |
|
| 348 | - echo $this->addMETAR($location,$line,$date); |
|
| 349 | - } |
|
| 350 | - //echo $line."\n"; |
|
| 351 | - } |
|
| 352 | - if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
| 332 | + } |
|
| 333 | + if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
| 334 | + $date = ''; |
|
| 335 | + foreach(explode("\n",$cycle) as $line) { |
|
| 336 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 337 | + //echo "date : ".$line."\n"; |
|
| 338 | + $date = $line; |
|
| 339 | + } elseif ($line != '') { |
|
| 340 | + //$this->parse($line); |
|
| 341 | + //echo $line; |
|
| 342 | + if ($date == '') $date = date('Y/m/d H:m'); |
|
| 343 | + $pos = 0; |
|
| 344 | + $pieces = preg_split('/\s/',$line); |
|
| 345 | + if ($pieces[0] == 'METAR') $pos++; |
|
| 346 | + if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 347 | + $location = $pieces[$pos]; |
|
| 348 | + echo $this->addMETAR($location,$line,$date); |
|
| 349 | + } |
|
| 350 | + //echo $line."\n"; |
|
| 351 | + } |
|
| 352 | + if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
| 353 | 353 | |
| 354 | - } |
|
| 355 | - public function downloadMETAR($icao) { |
|
| 356 | - global $globalMETARurl; |
|
| 357 | - if ($globalMETARurl == '') return array(); |
|
| 358 | - date_default_timezone_set("UTC"); |
|
| 359 | - $Common = new Common(); |
|
| 360 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 361 | - $cycle = $Common->getData($url); |
|
| 362 | - $date = ''; |
|
| 363 | - foreach(explode("\n",$cycle) as $line) { |
|
| 364 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 365 | - echo "date : ".$line."\n"; |
|
| 366 | - $date = $line; |
|
| 367 | - } elseif ($line != '') { |
|
| 368 | - //$this->parse($line); |
|
| 369 | - //echo $line; |
|
| 370 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 371 | - $pos = 0; |
|
| 372 | - $pieces = preg_split('/\s/',$line); |
|
| 373 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 374 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 375 | - $location = $pieces[$pos]; |
|
| 376 | - if (strlen($location == 4)) { |
|
| 377 | - $this->addMETAR($location,$line,$date); |
|
| 378 | - return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
|
| 379 | - } else return array(); |
|
| 380 | - } |
|
| 381 | - //echo $line."\n"; |
|
| 382 | - } |
|
| 383 | - return array(); |
|
| 354 | + } |
|
| 355 | + public function downloadMETAR($icao) { |
|
| 356 | + global $globalMETARurl; |
|
| 357 | + if ($globalMETARurl == '') return array(); |
|
| 358 | + date_default_timezone_set("UTC"); |
|
| 359 | + $Common = new Common(); |
|
| 360 | + $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 361 | + $cycle = $Common->getData($url); |
|
| 362 | + $date = ''; |
|
| 363 | + foreach(explode("\n",$cycle) as $line) { |
|
| 364 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 365 | + echo "date : ".$line."\n"; |
|
| 366 | + $date = $line; |
|
| 367 | + } elseif ($line != '') { |
|
| 368 | + //$this->parse($line); |
|
| 369 | + //echo $line; |
|
| 370 | + if ($date == '') $date = date('Y/m/d H:m'); |
|
| 371 | + $pos = 0; |
|
| 372 | + $pieces = preg_split('/\s/',$line); |
|
| 373 | + if ($pieces[0] == 'METAR') $pos++; |
|
| 374 | + if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 375 | + $location = $pieces[$pos]; |
|
| 376 | + if (strlen($location == 4)) { |
|
| 377 | + $this->addMETAR($location,$line,$date); |
|
| 378 | + return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
|
| 379 | + } else return array(); |
|
| 380 | + } |
|
| 381 | + //echo $line."\n"; |
|
| 382 | + } |
|
| 383 | + return array(); |
|
| 384 | 384 | |
| 385 | - } |
|
| 385 | + } |
|
| 386 | 386 | } |
| 387 | 387 | /* |
| 388 | 388 | $METAR = new METAR(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $Connection = new Connection(); |
| 55 | 55 | $sth = $Connection->db->prepare($query); |
| 56 | 56 | $sth->execute(); |
| 57 | - } catch(PDOException $e) { |
|
| 57 | + } catch (PDOException $e) { |
|
| 58 | 58 | return "error : ".$e->getMessage(); |
| 59 | 59 | } |
| 60 | 60 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $Connection = new Connection(); |
| 70 | 70 | $sth = $Connection->db->prepare($query); |
| 71 | 71 | $sth->execute(); |
| 72 | - } catch(PDOException $e) { |
|
| 72 | + } catch (PDOException $e) { |
|
| 73 | 73 | return "error : ".$e->getMessage(); |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -79,34 +79,34 @@ discard block |
||
| 79 | 79 | public function parse($data) { |
| 80 | 80 | //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
| 81 | 81 | $codes = implode('|', array_keys($this->texts)); |
| 82 | - $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
|
| 82 | + $regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#'; |
|
| 83 | 83 | //$pieces = explode(' ',$data); |
| 84 | - $pieces = preg_split('/\s/',$data); |
|
| 84 | + $pieces = preg_split('/\s/', $data); |
|
| 85 | 85 | $pos = 0; |
| 86 | 86 | if ($pieces[0] == 'METAR') $pos++; |
| 87 | 87 | elseif ($pieces[0] == 'SPECI') $pos++; |
| 88 | 88 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 89 | 89 | $result['location'] = $pieces[$pos]; |
| 90 | 90 | $pos++; |
| 91 | - $result['dayofmonth'] = substr($pieces[$pos],0,2); |
|
| 92 | - $result['time'] = substr($pieces[$pos],2,4); |
|
| 91 | + $result['dayofmonth'] = substr($pieces[$pos], 0, 2); |
|
| 92 | + $result['time'] = substr($pieces[$pos], 2, 4); |
|
| 93 | 93 | $c = count($pieces); |
| 94 | - for($pos++; $pos < $c; $pos++) { |
|
| 94 | + for ($pos++; $pos < $c; $pos++) { |
|
| 95 | 95 | $piece = $pieces[$pos]; |
| 96 | 96 | if ($piece == 'RMK') break; |
| 97 | 97 | if ($piece == 'AUTO') $result['auto'] = true; |
| 98 | 98 | if ($piece == 'COR') $result['correction'] = true; |
| 99 | 99 | // Wind Speed |
| 100 | 100 | if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
| 101 | - $result['wind']['direction'] = (float)$matches[1]; |
|
| 101 | + $result['wind']['direction'] = (float) $matches[1]; |
|
| 102 | 102 | $result['wind']['unit'] = $matches[4]; |
| 103 | - if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 104 | - elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 105 | - elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 106 | - $result['wind']['gust'] = (float)$matches[3]; |
|
| 103 | + if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float) $matches[2])*0.51444444444, 2); |
|
| 104 | + elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float) $matches[2])*1000, 2); |
|
| 105 | + elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float) $matches[2]), 2); |
|
| 106 | + $result['wind']['gust'] = (float) $matches[3]; |
|
| 107 | 107 | $result['wind']['unit'] = $matches[4]; |
| 108 | - $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
|
| 109 | - $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
|
| 108 | + $result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0; |
|
| 109 | + $result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | // Temperature |
| 128 | 128 | if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
| 129 | - $temp = (float)$matches[1]; |
|
| 129 | + $temp = (float) $matches[1]; |
|
| 130 | 130 | if ($matches[1]{0} == 'M') { |
| 131 | - $temp = ((float)substr($matches[1], 1)) * -1; |
|
| 131 | + $temp = ((float) substr($matches[1], 1))*-1; |
|
| 132 | 132 | } |
| 133 | 133 | $result['temperature'] = $temp; |
| 134 | - $dew = (float)$matches[2]; |
|
| 134 | + $dew = (float) $matches[2]; |
|
| 135 | 135 | if ($matches[2]{0} == 'M') { |
| 136 | - $dew = ((float)substr($matches[2], 1)) * -1; |
|
| 136 | + $dew = ((float) substr($matches[2], 1))*-1; |
|
| 137 | 137 | } |
| 138 | 138 | $result['dew'] = $dew; |
| 139 | 139 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $result['QNH'] = $matches[2]; |
| 146 | 146 | } else { |
| 147 | 147 | // inHg |
| 148 | - $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
|
| 148 | + $result['QNH'] = round(($matches[2]/100)*33.86389, 2); |
|
| 149 | 149 | } |
| 150 | 150 | /* |
| 151 | 151 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | // Visibility |
| 167 | 167 | if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
| 168 | 168 | if (isset($matches[3]) && strlen($matches[3]) > 0) { |
| 169 | - $result['visibility'] = (float)$matches[3] * 1609.34; |
|
| 169 | + $result['visibility'] = (float) $matches[3]*1609.34; |
|
| 170 | 170 | } else { |
| 171 | 171 | if ($matches[1] == '9999') { |
| 172 | 172 | $result['visibility'] = '> 10000'; |
| 173 | 173 | } else { |
| 174 | - $result['visibility'] = (float)$matches[1]; |
|
| 174 | + $result['visibility'] = (float) $matches[1]; |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | if (preg_match('#^CAVOK$#', $piece, $matches)) { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
| 193 | 193 | elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
| 194 | 194 | $cloud['type_code'] = $type; |
| 195 | - $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
|
| 195 | + $cloud['level'] = round(((float) $matches[2])*100*0.3048); |
|
| 196 | 196 | $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
| 197 | 197 | $result['cloud'][] = $cloud; |
| 198 | 198 | } |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | $rvr['runway'] = $matches[1]; |
| 202 | 202 | $rvr['assessment'] = $matches[2]; |
| 203 | 203 | $rvr['rvr'] = $matches[3]; |
| 204 | - $rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0; |
|
| 205 | - $rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : ''; |
|
| 204 | + $rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0; |
|
| 205 | + $rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : ''; |
|
| 206 | 206 | $result['RVR'] = $rvr; |
| 207 | 207 | } |
| 208 | 208 | |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
| 220 | 220 | //echo $piece; |
| 221 | 221 | //print_r($matches); |
| 222 | - if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 223 | - else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 222 | + if (isset($matches[5])) $range = array('exact' => (float) $matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 223 | + else $range = array('exact' => (float) $matches[2], 'unit' => 'M'); |
|
| 224 | 224 | if (isset($matches[3])) { |
| 225 | 225 | $range = Array( |
| 226 | - 'from' => (float)$matches[2], |
|
| 227 | - 'to' => (float)$matches[4], |
|
| 226 | + 'from' => (float) $matches[2], |
|
| 227 | + 'to' => (float) $matches[4], |
|
| 228 | 228 | 'unit' => $matches[5] ? 'FT' : 'M' |
| 229 | 229 | ); |
| 230 | 230 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | try { |
| 274 | 274 | $sth = $this->db->prepare($query); |
| 275 | 275 | $sth->execute($query_values); |
| 276 | - } catch(PDOException $e) { |
|
| 276 | + } catch (PDOException $e) { |
|
| 277 | 277 | return "error : ".$e->getMessage(); |
| 278 | 278 | } |
| 279 | 279 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -283,19 +283,19 @@ discard block |
||
| 283 | 283 | return $all; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - public function addMETAR($location,$metar,$date) { |
|
| 286 | + public function addMETAR($location, $metar, $date) { |
|
| 287 | 287 | global $globalDBdriver; |
| 288 | - $date = date('Y-m-d H:i:s',strtotime($date)); |
|
| 288 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 289 | 289 | if ($globalDBdriver == 'mysql') { |
| 290 | 290 | $query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar"; |
| 291 | 291 | } else { |
| 292 | 292 | $query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);"; |
| 293 | 293 | } |
| 294 | - $query_values = array(':location' => $location,':date' => $date,':metar' => $metar); |
|
| 294 | + $query_values = array(':location' => $location, ':date' => $date, ':metar' => $metar); |
|
| 295 | 295 | try { |
| 296 | 296 | $sth = $this->db->prepare($query); |
| 297 | 297 | $sth->execute($query_values); |
| 298 | - } catch(PDOException $e) { |
|
| 298 | + } catch (PDOException $e) { |
|
| 299 | 299 | return "error : ".$e->getMessage(); |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | try { |
| 307 | 307 | $sth = $this->db->prepare($query); |
| 308 | 308 | $sth->execute($query_values); |
| 309 | - } catch(PDOException $e) { |
|
| 309 | + } catch (PDOException $e) { |
|
| 310 | 310 | return "error : ".$e->getMessage(); |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | try { |
| 316 | 316 | $sth = $this->db->prepare($query); |
| 317 | 317 | $sth->execute(); |
| 318 | - } catch(PDOException $e) { |
|
| 318 | + } catch (PDOException $e) { |
|
| 319 | 319 | return "error : ".$e->getMessage(); |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
| 334 | 334 | $date = ''; |
| 335 | - foreach(explode("\n",$cycle) as $line) { |
|
| 336 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 335 | + foreach (explode("\n", $cycle) as $line) { |
|
| 336 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 337 | 337 | //echo "date : ".$line."\n"; |
| 338 | 338 | $date = $line; |
| 339 | 339 | } elseif ($line != '') { |
@@ -341,11 +341,11 @@ discard block |
||
| 341 | 341 | //echo $line; |
| 342 | 342 | if ($date == '') $date = date('Y/m/d H:m'); |
| 343 | 343 | $pos = 0; |
| 344 | - $pieces = preg_split('/\s/',$line); |
|
| 344 | + $pieces = preg_split('/\s/', $line); |
|
| 345 | 345 | if ($pieces[0] == 'METAR') $pos++; |
| 346 | 346 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 347 | 347 | $location = $pieces[$pos]; |
| 348 | - echo $this->addMETAR($location,$line,$date); |
|
| 348 | + echo $this->addMETAR($location, $line, $date); |
|
| 349 | 349 | } |
| 350 | 350 | //echo $line."\n"; |
| 351 | 351 | } |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | if ($globalMETARurl == '') return array(); |
| 358 | 358 | date_default_timezone_set("UTC"); |
| 359 | 359 | $Common = new Common(); |
| 360 | - $url = str_replace('{icao}',$icao,$globalMETARurl); |
|
| 360 | + $url = str_replace('{icao}', $icao, $globalMETARurl); |
|
| 361 | 361 | $cycle = $Common->getData($url); |
| 362 | 362 | $date = ''; |
| 363 | - foreach(explode("\n",$cycle) as $line) { |
|
| 364 | - if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
|
| 363 | + foreach (explode("\n", $cycle) as $line) { |
|
| 364 | + if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) { |
|
| 365 | 365 | echo "date : ".$line."\n"; |
| 366 | 366 | $date = $line; |
| 367 | 367 | } elseif ($line != '') { |
@@ -369,12 +369,12 @@ discard block |
||
| 369 | 369 | //echo $line; |
| 370 | 370 | if ($date == '') $date = date('Y/m/d H:m'); |
| 371 | 371 | $pos = 0; |
| 372 | - $pieces = preg_split('/\s/',$line); |
|
| 372 | + $pieces = preg_split('/\s/', $line); |
|
| 373 | 373 | if ($pieces[0] == 'METAR') $pos++; |
| 374 | 374 | if (strlen($pieces[$pos]) != 4) $pos++; |
| 375 | 375 | $location = $pieces[$pos]; |
| 376 | 376 | if (strlen($location == 4)) { |
| 377 | - $this->addMETAR($location,$line,$date); |
|
| 377 | + $this->addMETAR($location, $line, $date); |
|
| 378 | 378 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
| 379 | 379 | } else return array(); |
| 380 | 380 | } |
@@ -58,8 +58,11 @@ discard block |
||
| 58 | 58 | return "error : ".$e->getMessage(); |
| 59 | 59 | } |
| 60 | 60 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 61 | - if ($row['nb'] > 0) return false; |
|
| 62 | - else return true; |
|
| 61 | + if ($row['nb'] > 0) { |
|
| 62 | + return false; |
|
| 63 | + } else { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 63 | 66 | } |
| 64 | 67 | |
| 65 | 68 | public static function insert_last_update() { |
@@ -83,9 +86,14 @@ discard block |
||
| 83 | 86 | //$pieces = explode(' ',$data); |
| 84 | 87 | $pieces = preg_split('/\s/',$data); |
| 85 | 88 | $pos = 0; |
| 86 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 87 | - elseif ($pieces[0] == 'SPECI') $pos++; |
|
| 88 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 89 | + if ($pieces[0] == 'METAR') { |
|
| 90 | + $pos++; |
|
| 91 | + } elseif ($pieces[0] == 'SPECI') { |
|
| 92 | + $pos++; |
|
| 93 | + } |
|
| 94 | + if (strlen($pieces[$pos]) != 4) { |
|
| 95 | + $pos++; |
|
| 96 | + } |
|
| 89 | 97 | $result['location'] = $pieces[$pos]; |
| 90 | 98 | $pos++; |
| 91 | 99 | $result['dayofmonth'] = substr($pieces[$pos],0,2); |
@@ -93,16 +101,26 @@ discard block |
||
| 93 | 101 | $c = count($pieces); |
| 94 | 102 | for($pos++; $pos < $c; $pos++) { |
| 95 | 103 | $piece = $pieces[$pos]; |
| 96 | - if ($piece == 'RMK') break; |
|
| 97 | - if ($piece == 'AUTO') $result['auto'] = true; |
|
| 98 | - if ($piece == 'COR') $result['correction'] = true; |
|
| 104 | + if ($piece == 'RMK') { |
|
| 105 | + break; |
|
| 106 | + } |
|
| 107 | + if ($piece == 'AUTO') { |
|
| 108 | + $result['auto'] = true; |
|
| 109 | + } |
|
| 110 | + if ($piece == 'COR') { |
|
| 111 | + $result['correction'] = true; |
|
| 112 | + } |
|
| 99 | 113 | // Wind Speed |
| 100 | 114 | if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
| 101 | 115 | $result['wind']['direction'] = (float)$matches[1]; |
| 102 | 116 | $result['wind']['unit'] = $matches[4]; |
| 103 | - if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 104 | - elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 105 | - elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 117 | + if ($result['wind']['unit'] == 'KT') { |
|
| 118 | + $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
|
| 119 | + } elseif ($result['wind']['unit'] == 'KPH') { |
|
| 120 | + $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
|
| 121 | + } elseif ($result['wind']['unit'] == 'MPS') { |
|
| 122 | + $result['wind']['speed'] = round(((float)$matches[2]),2); |
|
| 123 | + } |
|
| 106 | 124 | $result['wind']['gust'] = (float)$matches[3]; |
| 107 | 125 | $result['wind']['unit'] = $matches[4]; |
| 108 | 126 | $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
@@ -183,14 +201,23 @@ discard block |
||
| 183 | 201 | if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) { |
| 184 | 202 | //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
| 185 | 203 | $type = $matches[1]; |
| 186 | - if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear'; |
|
| 187 | - elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
| 188 | - elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud'; |
|
| 189 | - elseif ($type == 'FEW') $cloud['type'] = 'Few'; |
|
| 190 | - elseif ($type == 'SCT') $cloud['type'] = 'Scattered'; |
|
| 191 | - elseif ($type == 'BKN') $cloud['type'] = 'Broken'; |
|
| 192 | - elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
| 193 | - elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
|
| 204 | + if ($type == 'SKC') { |
|
| 205 | + $cloud['type'] = 'No cloud/Sky clear'; |
|
| 206 | + } elseif ($type == 'CLR') { |
|
| 207 | + $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
|
| 208 | + } elseif ($type == 'NSC') { |
|
| 209 | + $cloud['type'] = 'No significant cloud'; |
|
| 210 | + } elseif ($type == 'FEW') { |
|
| 211 | + $cloud['type'] = 'Few'; |
|
| 212 | + } elseif ($type == 'SCT') { |
|
| 213 | + $cloud['type'] = 'Scattered'; |
|
| 214 | + } elseif ($type == 'BKN') { |
|
| 215 | + $cloud['type'] = 'Broken'; |
|
| 216 | + } elseif ($type == 'OVC') { |
|
| 217 | + $cloud['type'] = 'Overcast/Full cloud coverage'; |
|
| 218 | + } elseif ($type == 'VV') { |
|
| 219 | + $cloud['type'] = 'Vertical visibility'; |
|
| 220 | + } |
|
| 194 | 221 | $cloud['type_code'] = $type; |
| 195 | 222 | $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
| 196 | 223 | $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
@@ -219,8 +246,11 @@ discard block |
||
| 219 | 246 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
| 220 | 247 | //echo $piece; |
| 221 | 248 | //print_r($matches); |
| 222 | - if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 223 | - else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 249 | + if (isset($matches[5])) { |
|
| 250 | + $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
|
| 251 | + } else { |
|
| 252 | + $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
|
| 253 | + } |
|
| 224 | 254 | if (isset($matches[3])) { |
| 225 | 255 | $range = Array( |
| 226 | 256 | 'from' => (float)$matches[2], |
@@ -253,8 +283,11 @@ discard block |
||
| 253 | 283 | if (isset($matches[3])) { |
| 254 | 284 | $text[] = $this->texts[$matches[3]]; |
| 255 | 285 | } |
| 256 | - if (!isset($result['weather'])) $result['weather'] = implode(' ', $text); |
|
| 257 | - else $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
|
| 286 | + if (!isset($result['weather'])) { |
|
| 287 | + $result['weather'] = implode(' ', $text); |
|
| 288 | + } else { |
|
| 289 | + $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
|
| 290 | + } |
|
| 258 | 291 | } |
| 259 | 292 | } |
| 260 | 293 | return $result; |
@@ -266,8 +299,11 @@ discard block |
||
| 266 | 299 | if (isset($globalMETARcycle) && $globalMETARcycle) { |
| 267 | 300 | $query = "SELECT * FROM metar WHERE metar_location = :icao"; |
| 268 | 301 | } else { |
| 269 | - if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
| 270 | - elseif ($globalDBdriver == 'pgsql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
| 302 | + if ($globalDBdriver == 'mysql') { |
|
| 303 | + $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1"; |
|
| 304 | + } elseif ($globalDBdriver == 'pgsql') { |
|
| 305 | + $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1"; |
|
| 306 | + } |
|
| 271 | 307 | } |
| 272 | 308 | $query_values = array(':icao' => $icao); |
| 273 | 309 | try { |
@@ -322,7 +358,9 @@ discard block |
||
| 322 | 358 | |
| 323 | 359 | public function addMETARCycle() { |
| 324 | 360 | global $globalDebug, $globalIVAO; |
| 325 | - if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle..."; |
|
| 361 | + if (isset($globalDebug) && $globalDebug) { |
|
| 362 | + echo "Downloading METAR cycle..."; |
|
| 363 | + } |
|
| 326 | 364 | date_default_timezone_set("UTC"); |
| 327 | 365 | $Common = new Common(); |
| 328 | 366 | if (isset($globalIVAO) && $globalIVAO) { |
@@ -330,7 +368,9 @@ discard block |
||
| 330 | 368 | } else { |
| 331 | 369 | $cycle = $Common->getData('http://weather.noaa.gov/pub/data/observations/metar/cycles/'.date('H').'Z.TXT'); |
| 332 | 370 | } |
| 333 | - if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB..."; |
|
| 371 | + if (isset($globalDebug) && $globalDebug) { |
|
| 372 | + echo "Done - Updating DB..."; |
|
| 373 | + } |
|
| 334 | 374 | $date = ''; |
| 335 | 375 | foreach(explode("\n",$cycle) as $line) { |
| 336 | 376 | if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) { |
@@ -339,22 +379,32 @@ discard block |
||
| 339 | 379 | } elseif ($line != '') { |
| 340 | 380 | //$this->parse($line); |
| 341 | 381 | //echo $line; |
| 342 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 382 | + if ($date == '') { |
|
| 383 | + $date = date('Y/m/d H:m'); |
|
| 384 | + } |
|
| 343 | 385 | $pos = 0; |
| 344 | 386 | $pieces = preg_split('/\s/',$line); |
| 345 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 346 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 387 | + if ($pieces[0] == 'METAR') { |
|
| 388 | + $pos++; |
|
| 389 | + } |
|
| 390 | + if (strlen($pieces[$pos]) != 4) { |
|
| 391 | + $pos++; |
|
| 392 | + } |
|
| 347 | 393 | $location = $pieces[$pos]; |
| 348 | 394 | echo $this->addMETAR($location,$line,$date); |
| 349 | 395 | } |
| 350 | 396 | //echo $line."\n"; |
| 351 | 397 | } |
| 352 | - if (isset($globalDebug) && $globalDebug) echo "Done\n"; |
|
| 398 | + if (isset($globalDebug) && $globalDebug) { |
|
| 399 | + echo "Done\n"; |
|
| 400 | + } |
|
| 353 | 401 | |
| 354 | 402 | } |
| 355 | 403 | public function downloadMETAR($icao) { |
| 356 | 404 | global $globalMETARurl; |
| 357 | - if ($globalMETARurl == '') return array(); |
|
| 405 | + if ($globalMETARurl == '') { |
|
| 406 | + return array(); |
|
| 407 | + } |
|
| 358 | 408 | date_default_timezone_set("UTC"); |
| 359 | 409 | $Common = new Common(); |
| 360 | 410 | $url = str_replace('{icao}',$icao,$globalMETARurl); |
@@ -367,16 +417,24 @@ discard block |
||
| 367 | 417 | } elseif ($line != '') { |
| 368 | 418 | //$this->parse($line); |
| 369 | 419 | //echo $line; |
| 370 | - if ($date == '') $date = date('Y/m/d H:m'); |
|
| 420 | + if ($date == '') { |
|
| 421 | + $date = date('Y/m/d H:m'); |
|
| 422 | + } |
|
| 371 | 423 | $pos = 0; |
| 372 | 424 | $pieces = preg_split('/\s/',$line); |
| 373 | - if ($pieces[0] == 'METAR') $pos++; |
|
| 374 | - if (strlen($pieces[$pos]) != 4) $pos++; |
|
| 425 | + if ($pieces[0] == 'METAR') { |
|
| 426 | + $pos++; |
|
| 427 | + } |
|
| 428 | + if (strlen($pieces[$pos]) != 4) { |
|
| 429 | + $pos++; |
|
| 430 | + } |
|
| 375 | 431 | $location = $pieces[$pos]; |
| 376 | 432 | if (strlen($location == 4)) { |
| 377 | 433 | $this->addMETAR($location,$line,$date); |
| 378 | 434 | return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line)); |
| 379 | - } else return array(); |
|
| 435 | + } else { |
|
| 436 | + return array(); |
|
| 437 | + } |
|
| 380 | 438 | } |
| 381 | 439 | //echo $line."\n"; |
| 382 | 440 | } |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | / @param String $source source of data |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') { |
|
| 28 | + public function addSchedule($ident, $departure_airport_icao, $departure_airport_time, $arrival_airport_icao, $arrival_airport_time, $source = 'website') { |
|
| 29 | 29 | date_default_timezone_set('UTC'); |
| 30 | - $date = date("Y-m-d H:i:s",time()); |
|
| 30 | + $date = date("Y-m-d H:i:s", time()); |
|
| 31 | 31 | //if ($departure_airport_time == '' && $arrival_airport_time == '') exit; |
| 32 | 32 | //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident"; |
| 33 | 33 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident"; |
@@ -35,70 +35,70 @@ discard block |
||
| 35 | 35 | try { |
| 36 | 36 | $sth = $this->db->prepare($query); |
| 37 | 37 | $sth->execute($query_values); |
| 38 | - } catch(PDOException $e) { |
|
| 38 | + } catch (PDOException $e) { |
|
| 39 | 39 | return "error : ".$e->getMessage(); |
| 40 | 40 | } |
| 41 | 41 | if ($sth->fetchColumn() > 0) { |
| 42 | 42 | if ($departure_airport_time == '' && $arrival_airport_time == '') { |
| 43 | 43 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao"; |
| 44 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao); |
|
| 44 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao); |
|
| 45 | 45 | } elseif ($arrival_airport_time == '') { |
| 46 | 46 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao"; |
| 47 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao); |
|
| 47 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao); |
|
| 48 | 48 | } elseif ($departure_airport_time == '') { |
| 49 | 49 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
| 50 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
|
| 50 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time); |
|
| 51 | 51 | } else { |
| 52 | 52 | //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time"; |
| 53 | 53 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
| 54 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
|
| 54 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time); |
|
| 55 | 55 | } |
| 56 | 56 | try { |
| 57 | 57 | $sth = $this->db->prepare($query); |
| 58 | 58 | $sth->execute($query_values); |
| 59 | - } catch(PDOException $e) { |
|
| 59 | + } catch (PDOException $e) { |
|
| 60 | 60 | return "error : ".$e->getMessage(); |
| 61 | 61 | } |
| 62 | 62 | if ($sth->fetchColumn() == 0) { |
| 63 | 63 | //$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident'; |
| 64 | 64 | if ($departure_airport_time == '' && $arrival_airport_time == '') { |
| 65 | 65 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
| 66 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 66 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 67 | 67 | } elseif ($arrival_airport_time == '') { |
| 68 | 68 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
| 69 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 69 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 70 | 70 | } elseif ($departure_airport_time == '') { |
| 71 | 71 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
| 72 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 72 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 73 | 73 | } else { |
| 74 | 74 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
| 75 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 75 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 76 | 76 | } |
| 77 | 77 | try { |
| 78 | 78 | $sth = $this->db->prepare($query); |
| 79 | 79 | $sth->execute($query_values); |
| 80 | - } catch(PDOException $e) { |
|
| 80 | + } catch (PDOException $e) { |
|
| 81 | 81 | return "error : ".$e->getMessage(); |
| 82 | 82 | } |
| 83 | 83 | } else { |
| 84 | 84 | //$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident'; |
| 85 | 85 | $query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident'; |
| 86 | - $query_values = array(':ident' => $ident,':date' => $date); |
|
| 86 | + $query_values = array(':ident' => $ident, ':date' => $date); |
|
| 87 | 87 | try { |
| 88 | 88 | $sth = $this->db->prepare($query); |
| 89 | 89 | $sth->execute($query_values); |
| 90 | - } catch(PDOException $e) { |
|
| 90 | + } catch (PDOException $e) { |
|
| 91 | 91 | return "error : ".$e->getMessage(); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } else { |
| 95 | 95 | //$query = 'INSERT INTO schedule (ident,departure_airport_icao, departure_airport_time, arrival_airport_icao, arrival_airport_time,date_added,source) VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)'; |
| 96 | 96 | $query = 'INSERT INTO routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source) VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)'; |
| 97 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 97 | + $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 98 | 98 | try { |
| 99 | 99 | $sth = $this->db->prepare($query); |
| 100 | 100 | $sth->execute($query_values); |
| 101 | - } catch(PDOException $e) { |
|
| 101 | + } catch (PDOException $e) { |
|
| 102 | 102 | return "error : ".$e->getMessage(); |
| 103 | 103 | } |
| 104 | 104 | // FIXME : add to routes |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | public function getSchedule($ident) { |
| 110 | 110 | //$query = "SELECT * FROM schedule WHERE ident = :ident LIMIT 1"; |
| 111 | 111 | $Translation = new Translation($this->db); |
| 112 | - $operator = $Translation->checkTranslation($ident,false); |
|
| 112 | + $operator = $Translation->checkTranslation($ident, false); |
|
| 113 | 113 | if ($ident != $operator) { |
| 114 | 114 | $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1"; |
| 115 | - $query_values = array(':ident' => $ident,'operator' => $operator); |
|
| 115 | + $query_values = array(':ident' => $ident, 'operator' => $operator); |
|
| 116 | 116 | } else { |
| 117 | 117 | $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1"; |
| 118 | 118 | $query_values = array(':ident' => $ident); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | try { |
| 121 | 121 | $sth = $this->db->prepare($query); |
| 122 | 122 | $sth->execute($query_values); |
| 123 | - } catch(PDOException $e) { |
|
| 123 | + } catch (PDOException $e) { |
|
| 124 | 124 | return "error : ".$e->getMessage(); |
| 125 | 125 | } |
| 126 | 126 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | try { |
| 144 | 144 | $sth = $this->db->prepare($query); |
| 145 | 145 | $sth->execute($query_values); |
| 146 | - } catch(PDOException $e) { |
|
| 146 | + } catch (PDOException $e) { |
|
| 147 | 147 | return "error : ".$e->getMessage(); |
| 148 | 148 | } |
| 149 | 149 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | * @param String $carrier IATA code |
| 158 | 158 | * @return Flight departure and arrival airports and time |
| 159 | 159 | */ |
| 160 | - private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') { |
|
| 160 | + private function getAirFrance($callsign, $date = 'NOW', $carrier = 'AF') { |
|
| 161 | 161 | $Common = new Common(); |
| 162 | 162 | $check_date = new Datetime($date); |
| 163 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 164 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 163 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 164 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 165 | 165 | $url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym'); |
| 166 | 166 | $json = $Common->getData($url); |
| 167 | 167 | |
| 168 | 168 | $parsed_json = json_decode($json); |
| 169 | - if (property_exists($parsed_json,'errors') === false) { |
|
| 169 | + if (property_exists($parsed_json, 'errors') === false) { |
|
| 170 | 170 | $originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'}; |
| 171 | 171 | $originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'}; |
| 172 | 172 | $departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'}; |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | $arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'}; |
| 177 | 177 | $arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'}; |
| 178 | 178 | |
| 179 | - preg_match('/\((.*?)\)/',$originShort,$originiata); |
|
| 179 | + preg_match('/\((.*?)\)/', $originShort, $originiata); |
|
| 180 | 180 | $DepartureAirportIata = $originiata[1]; |
| 181 | - preg_match('/\((.*?)\)/',$destinationShort,$destinationiata); |
|
| 181 | + preg_match('/\((.*?)\)/', $destinationShort, $destinationiata); |
|
| 182 | 182 | $ArrivalAirportIata = $destinationiata[1]; |
| 183 | 183 | |
| 184 | 184 | /* |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $arrivalTime = gmdate('H:i',strtotime($arrivalTime)); |
| 188 | 188 | */ |
| 189 | 189 | |
| 190 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance'); |
|
| 190 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airfrance'); |
|
| 191 | 191 | } else return array(); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | $Common = new Common(); |
| 203 | 203 | date_default_timezone_set($globalTimezone); |
| 204 | 204 | $check_date = new Datetime($date); |
| 205 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 206 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 205 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 206 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 207 | 207 | $url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign; |
| 208 | 208 | $json = $Common->getData($url); |
| 209 | 209 | $parsed_json = json_decode($json); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'}; |
| 216 | 216 | $arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'}; |
| 217 | 217 | |
| 218 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet'); |
|
| 218 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_easyjet'); |
|
| 219 | 219 | } else return array(); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | private function getRyanair($callsign) { |
| 228 | 228 | $Common = new Common(); |
| 229 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 230 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 229 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 230 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 231 | 231 | $url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/"; |
| 232 | 232 | $post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}'; |
| 233 | - $headers = array('Content-Type: application/json','Content-Length: ' . strlen($post)); |
|
| 234 | - $json = $Common->getData($url,'post',$post,$headers); |
|
| 233 | + $headers = array('Content-Type: application/json', 'Content-Length: '.strlen($post)); |
|
| 234 | + $json = $Common->getData($url, 'post', $post, $headers); |
|
| 235 | 235 | $parsed_json = json_decode($json); |
| 236 | 236 | if (isset($parsed_json->{'flightInfo'})) { |
| 237 | 237 | $flights = $parsed_json->{'flightInfo'}; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name |
| 241 | 241 | $departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'}; |
| 242 | 242 | $arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'}; |
| 243 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair'); |
|
| 243 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair'); |
|
| 244 | 244 | } else return array(); |
| 245 | 245 | } else return array(); |
| 246 | 246 | } |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | private function getSwiss($callsign) { |
| 254 | 254 | $Common = new Common(); |
| 255 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 256 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 255 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 256 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 257 | 257 | $url = "http://www.world-of-swiss.com/fr/routenetwork.json"; |
| 258 | 258 | $json = $Common->getData($url); |
| 259 | 259 | $parsed_json = json_decode($json); |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | if ($flight->{'no'} == "Vol LX ".$numvol) { |
| 266 | 266 | $DepartureAirportIata = $flight->{'from'}->{'code'}; //city |
| 267 | 267 | $ArrivalAirportIata = $flight->{'to'}->{'code'}; //city |
| 268 | - $departureTime = substr($flight->{'from'}->{'hour'},0,5); |
|
| 269 | - $arrivalTime = substr($flight->{'to'}->{'hour'},0,5); |
|
| 268 | + $departureTime = substr($flight->{'from'}->{'hour'},0, 5); |
|
| 269 | + $arrivalTime = substr($flight->{'to'}->{'hour'},0, 5); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | if (isset($DepartureAirportIata)) { |
| 273 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss'); |
|
| 273 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_swiss'); |
|
| 274 | 274 | } else return array(); |
| 275 | 275 | } else return array(); |
| 276 | 276 | } |
@@ -285,21 +285,21 @@ discard block |
||
| 285 | 285 | global $globalBritishAirwaysKey; |
| 286 | 286 | $Common = new Common(); |
| 287 | 287 | $check_date = new Datetime($date); |
| 288 | - $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
|
| 289 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 288 | + $numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign)); |
|
| 289 | + if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array(); |
|
| 290 | 290 | if ($globalBritishAirwaysKey == '') return array(); |
| 291 | 291 | $url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json"; |
| 292 | 292 | $headers = array('Client-Key: '.$globalBritishAirwaysKey); |
| 293 | - $json = $Common->getData($url,'get','',$headers); |
|
| 293 | + $json = $Common->getData($url, 'get', '', $headers); |
|
| 294 | 294 | if ($json == '') return array(); |
| 295 | 295 | $parsed_json = json_decode($json); |
| 296 | 296 | $flights = $parsed_json->{'FlightsResponse'}; |
| 297 | 297 | if (count($flights) > 0) { |
| 298 | 298 | $DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'}; |
| 299 | 299 | $ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'}; |
| 300 | - $departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'})); |
|
| 301 | - $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'})); |
|
| 302 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways'); |
|
| 300 | + $departureTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'})); |
|
| 301 | + $arrivalTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'})); |
|
| 302 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_britishairways'); |
|
| 303 | 303 | } else return array(); |
| 304 | 304 | } |
| 305 | 305 | |
@@ -313,27 +313,27 @@ discard block |
||
| 313 | 313 | global $globalLufthansaKey; |
| 314 | 314 | $Common = new Common(); |
| 315 | 315 | $check_date = new Datetime($date); |
| 316 | - $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
|
| 317 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 316 | + $numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign)); |
|
| 317 | + if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array(); |
|
| 318 | 318 | if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array(); |
| 319 | 319 | $url = "https://api.lufthansa.com/v1/oauth/token"; |
| 320 | - $post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials'); |
|
| 321 | - $data = $Common->getData($url,'post',$post); |
|
| 320 | + $post = array('client_id' => $globalLufthansaKey['key'], 'client_secret' => $globalLufthansaKey['secret'], 'grant_type' => 'client_credentials'); |
|
| 321 | + $data = $Common->getData($url, 'post', $post); |
|
| 322 | 322 | $parsed_data = json_decode($data); |
| 323 | 323 | if (!isset($parsed_data->{'access_token'})) return array(); |
| 324 | 324 | $token = $parsed_data->{'access_token'}; |
| 325 | 325 | |
| 326 | 326 | $url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d'); |
| 327 | - $headers = array('Authorization: Bearer '.$token,'Accept: application/json'); |
|
| 328 | - $json = $Common->getData($url,'get','',$headers); |
|
| 327 | + $headers = array('Authorization: Bearer '.$token, 'Accept: application/json'); |
|
| 328 | + $json = $Common->getData($url, 'get', '', $headers); |
|
| 329 | 329 | if ($json == '') return array(); |
| 330 | 330 | $parsed_json = json_decode($json); |
| 331 | 331 | if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) { |
| 332 | 332 | $DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'}; |
| 333 | - $departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
|
| 333 | + $departureTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
|
| 334 | 334 | $ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'}; |
| 335 | - $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
|
| 336 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
|
| 335 | + $arrivalTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
|
| 336 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_lufthansa'); |
|
| 337 | 337 | } else return array(); |
| 338 | 338 | } |
| 339 | 339 | |
@@ -347,21 +347,21 @@ discard block |
||
| 347 | 347 | global $globalTransaviaKey; |
| 348 | 348 | $Common = new Common(); |
| 349 | 349 | $check_date = new Datetime($date); |
| 350 | - $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
|
| 351 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 350 | + $numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign)); |
|
| 351 | + if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array(); |
|
| 352 | 352 | if ($globalTransaviaKey == '') return array(); |
| 353 | 353 | $url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
| 354 | 354 | $headers = array('apikey: '.$globalTransaviaKey); |
| 355 | - $json = $Common->getData($url,'get','',$headers); |
|
| 355 | + $json = $Common->getData($url, 'get', '', $headers); |
|
| 356 | 356 | if ($json == '') return array(); |
| 357 | 357 | $parsed_json = json_decode($json); |
| 358 | 358 | |
| 359 | 359 | if (isset($parsed_json->{'data'}[0])) { |
| 360 | 360 | $DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'}; |
| 361 | - $departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'})); |
|
| 361 | + $departureTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'})); |
|
| 362 | 362 | $ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'}; |
| 363 | - $arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'})); |
|
| 364 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia'); |
|
| 363 | + $arrivalTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'})); |
|
| 364 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_transavia'); |
|
| 365 | 365 | } else return array(); |
| 366 | 366 | } |
| 367 | 367 | |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | private function getTunisair($callsign) { |
| 374 | 374 | $Common = new Common(); |
| 375 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 376 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 375 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 376 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 377 | 377 | $url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp"; |
| 378 | 378 | $data = $Common->getData($url); |
| 379 | 379 | $table = $Common->table2array($data); |
| 380 | 380 | foreach ($table as $flight) { |
| 381 | - if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) { |
|
| 382 | - return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair'); |
|
| 381 | + if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d', $numvol)) { |
|
| 382 | + return array('DepartureAirportIATA' => $flight[2], 'DepartureTime' => str_replace('.', ':', $flight[5]), 'ArrivalAirportIATA' => $flight[3], 'ArrivalTime' => str_replace('.', ':', $flight[6]), 'Source' => 'website_tunisair'); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | return array(); |
@@ -392,19 +392,19 @@ discard block |
||
| 392 | 392 | */ |
| 393 | 393 | private function getVueling($callsign) { |
| 394 | 394 | $Common = new Common(); |
| 395 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 396 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 395 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 396 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 397 | 397 | $url = "https://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=DailyFlights&OriginSelected=&DestinationSelected=&idioma=en-GB&pageid=30694&ItemsByPage=50&FlightNumberFilter=".$numvol; |
| 398 | 398 | $data = $Common->getData($url); |
| 399 | 399 | if ($data != '') { |
| 400 | 400 | $table = $Common->table2array($data); |
| 401 | 401 | foreach ($table as $flight) { |
| 402 | 402 | if (count($flight) > 0 && $flight[0] == "VY".$numvol && isset($flight[13])) { |
| 403 | - preg_match('/flightOri=[A-Z]{3}/',$flight[13],$result); |
|
| 404 | - $DepartureAirportIata = str_replace('flightOri=','',$result[0]); |
|
| 405 | - preg_match('/flightDest=[A-Z]{3}/',$flight[13],$result); |
|
| 406 | - $ArrivalAirportIata = str_replace('flightDest=','',$result[0]); |
|
| 407 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $flight[3],'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $flight[4],'Source' => 'website_vueling'); |
|
| 403 | + preg_match('/flightOri=[A-Z]{3}/', $flight[13], $result); |
|
| 404 | + $DepartureAirportIata = str_replace('flightOri=', '', $result[0]); |
|
| 405 | + preg_match('/flightDest=[A-Z]{3}/', $flight[13], $result); |
|
| 406 | + $ArrivalAirportIata = str_replace('flightDest=', '', $result[0]); |
|
| 407 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $flight[3], 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $flight[4], 'Source' => 'website_vueling'); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -419,27 +419,27 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | private function getIberia($callsign, $date = 'NOW') { |
| 421 | 421 | $Common = new Common(); |
| 422 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 422 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 423 | 423 | $check_date = new Datetime($date); |
| 424 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 424 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 425 | 425 | $url = "https://www.iberia.com/web/flightDetail.do"; |
| 426 | - $post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB'); |
|
| 427 | - $data = $Common->getData($url,'post',$post); |
|
| 426 | + $post = array('numvuelo' => $numvol, 'fecha' => $check_date->format('Ymd'), 'airlineID' => 'IB'); |
|
| 427 | + $data = $Common->getData($url, 'post', $post); |
|
| 428 | 428 | if ($data != '') { |
| 429 | 429 | $table = $Common->table2array($data); |
| 430 | 430 | //print_r($table); |
| 431 | 431 | if (count($table) > 0) { |
| 432 | 432 | $flight = $table; |
| 433 | - preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch); |
|
| 434 | - preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch); |
|
| 433 | + preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch); |
|
| 434 | + preg_match('/([A-Z]{3})/', $flight[5][0], $ArrivalAirportIataMatch); |
|
| 435 | 435 | $DepartureAirportIata = $DepartureAirportIataMatch[0]; |
| 436 | 436 | $ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
| 437 | - $departureTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[3][2]))),0,5); |
|
| 438 | - $arrivalTime = trim(str_replace(' lunes','',str_replace(' ','',$flight[5][1]))); |
|
| 437 | + $departureTime = substr(trim(str_replace(' lunes', '', str_replace(' ', '', $flight[3][2]))), 0, 5); |
|
| 438 | + $arrivalTime = trim(str_replace(' lunes', '', str_replace(' ', '', $flight[5][1]))); |
|
| 439 | 439 | if ($arrivalTime == 'Hora estimada de llegada') { |
| 440 | - $arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[5][2]))),0,5); |
|
| 441 | - } else $arrivalTime = substr($arrivalTime,0,5); |
|
| 442 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia'); |
|
| 440 | + $arrivalTime = substr(trim(str_replace(' lunes', '', str_replace(' ', '', $flight[5][2]))), 0, 5); |
|
| 441 | + } else $arrivalTime = substr($arrivalTime, 0, 5); |
|
| 442 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_iberia'); |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | return array(); |
@@ -451,11 +451,11 @@ discard block |
||
| 451 | 451 | * @param String $date date we want flight number info |
| 452 | 452 | * @return Flight departure and arrival airports and time |
| 453 | 453 | */ |
| 454 | - private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') { |
|
| 454 | + private function getStarAlliance($callsign, $date = 'NOW', $carrier = '') { |
|
| 455 | 455 | $Common = new Common(); |
| 456 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 456 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 457 | 457 | $check_date = new Datetime($date); |
| 458 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 458 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 459 | 459 | $url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y'); |
| 460 | 460 | $data = $Common->getData($url); |
| 461 | 461 | if ($data != '') { |
@@ -464,13 +464,13 @@ discard block |
||
| 464 | 464 | $flight = $table; |
| 465 | 465 | //print_r($table); |
| 466 | 466 | if (isset($flight[25]) && isset($flight[29])) { |
| 467 | - preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch); |
|
| 468 | - preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch); |
|
| 467 | + preg_match('/([A-Z]{3})/', $flight[25][1], $DepartureAirportIataMatch); |
|
| 468 | + preg_match('/([A-Z]{3})/', $flight[25][3], $ArrivalAirportIataMatch); |
|
| 469 | 469 | $DepartureAirportIata = $DepartureAirportIataMatch[0]; |
| 470 | 470 | $ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
| 471 | - $departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5); |
|
| 472 | - $arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5); |
|
| 473 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance'); |
|
| 471 | + $departureTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][0])), 0, 5); |
|
| 472 | + $arrivalTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][1])), 0, 5); |
|
| 473 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_staralliance'); |
|
| 474 | 474 | } else return array(); |
| 475 | 475 | } |
| 476 | 476 | |
@@ -487,10 +487,10 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | private function getAlitalia($callsign, $date = 'NOW') { |
| 489 | 489 | $Common = new Common(); |
| 490 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 490 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 491 | 491 | $check_date = new Datetime($date); |
| 492 | - $url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y'); |
|
| 493 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 492 | + $url = "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y'); |
|
| 493 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 494 | 494 | $data = $Common->getData($url); |
| 495 | 495 | if ($data != '') { |
| 496 | 496 | $table = $Common->text2array($data); |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | $ArrivalAirportIata = ''; |
| 499 | 499 | $departureTime = $table[4]; |
| 500 | 500 | $arrivalTime = $table[5]; |
| 501 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia'); |
|
| 501 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_alitalia'); |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | */ |
| 511 | 511 | private function getBrussels($callsign, $date = 'NOW') { |
| 512 | 512 | $Common = new Common(); |
| 513 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 513 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 514 | 514 | $check_date = new Datetime($date); |
| 515 | - $url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302"; |
|
| 515 | + $url = "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302"; |
|
| 516 | 516 | //http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber"; |
| 517 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 517 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 518 | 518 | $data = $Common->getData($url); |
| 519 | 519 | if ($data != '') { |
| 520 | 520 | //echo $data; |
@@ -522,9 +522,9 @@ discard block |
||
| 522 | 522 | if (isset($parsed_json[0]->FromAirportCode)) { |
| 523 | 523 | $DepartureAirportIata = $parsed_json[0]->FromAirportCode; |
| 524 | 524 | $ArrivalAirportIata = $parsed_json[0]->ToAirportCode; |
| 525 | - $departureTime = date('H:i',strtotime($parsed_json[0]->ScheduledDepatureDate)); |
|
| 526 | - $arrivalTime = date('H:i',strtotime($parsed_json[0]->ScheduledArrivalDate)); |
|
| 527 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels'); |
|
| 525 | + $departureTime = date('H:i', strtotime($parsed_json[0]->ScheduledDepatureDate)); |
|
| 526 | + $arrivalTime = date('H:i', strtotime($parsed_json[0]->ScheduledArrivalDate)); |
|
| 527 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_brussels'); |
|
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | } |
@@ -602,21 +602,21 @@ discard block |
||
| 602 | 602 | */ |
| 603 | 603 | private function getFlyTap($callsign, $date = 'NOW') { |
| 604 | 604 | $Common = new Common(); |
| 605 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 606 | - $url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees"; |
|
| 605 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 606 | + $url = "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees"; |
|
| 607 | 607 | $check_date = new Datetime($date); |
| 608 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 609 | - $post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1'); |
|
| 610 | - $data = $Common->getData($url,'post',$post); |
|
| 608 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 609 | + $post = array('arrivalsdepartures_content' => 'number', 'arrivalsdepartures_tp' => $numvol, 'arrivalsdepartures_trk' => 'ARR', 'arrivalsdepartures_date_trk' => '1', 'aptCode' => '', 'arrivalsdepartures' => 'DEP', 'arrivalsdepartures_date' => '1', 'aptCodeFrom' => '', 'aptCodeTo' => '', 'arrivalsdepartures2' => 'DEP', 'arrivalsdepartures_date2' => '1'); |
|
| 610 | + $data = $Common->getData($url, 'post', $post); |
|
| 611 | 611 | if ($data != '') { |
| 612 | 612 | $table = $Common->table2array($data); |
| 613 | - $departureTime = trim(substr($table[15][0],0,5)); |
|
| 614 | - $arrivalTime = trim(substr($table[35][0],0,5)); |
|
| 615 | - preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch); |
|
| 616 | - preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch); |
|
| 613 | + $departureTime = trim(substr($table[15][0], 0, 5)); |
|
| 614 | + $arrivalTime = trim(substr($table[35][0], 0, 5)); |
|
| 615 | + preg_match('/([A-Z]{3})/', $table[11][0], $DepartureAirportIataMatch); |
|
| 616 | + preg_match('/([A-Z]{3})/', $table[31][0], $ArrivalAirportIataMatch); |
|
| 617 | 617 | $DepartureAirportIata = $DepartureAirportIataMatch[0]; |
| 618 | 618 | $ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
| 619 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap'); |
|
| 619 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flytap'); |
|
| 620 | 620 | } |
| 621 | 621 | return array(); |
| 622 | 622 | } |
@@ -637,22 +637,22 @@ discard block |
||
| 637 | 637 | $airline_icao = substr($callsign, 0, 3); |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 641 | - $url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol; |
|
| 640 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 641 | + $url = "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol; |
|
| 642 | 642 | $check_date = new Datetime($date); |
| 643 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 643 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 644 | 644 | $data = $Common->getData($url); |
| 645 | 645 | if ($data != '') { |
| 646 | 646 | $table = $Common->table2array($data); |
| 647 | 647 | if (isset($table[5][0])) { |
| 648 | 648 | $sched = $table[5][0]; |
| 649 | - $n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr); |
|
| 649 | + $n = sscanf($sched, '%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])', $dhour, $darr, $ahour, $aarr); |
|
| 650 | 650 | if ($n == 7) { |
| 651 | 651 | $departureTime = $dhour; |
| 652 | 652 | $arrivalTime = $ahour; |
| 653 | - $DepartureAirportIata = str_replace(array('(',')'),'',$darr); |
|
| 654 | - $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr); |
|
| 655 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper'); |
|
| 653 | + $DepartureAirportIata = str_replace(array('(', ')'), '', $darr); |
|
| 654 | + $ArrivalAirportIata = str_replace(array('(', ')'), '', $aarr); |
|
| 655 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightmapper'); |
|
| 656 | 656 | } |
| 657 | 657 | } |
| 658 | 658 | } |
@@ -675,20 +675,20 @@ discard block |
||
| 675 | 675 | $airline_icao = substr($callsign, 0, 3); |
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 679 | - $url= "http://fr.flightaware.com/live/flight/".$callsign; |
|
| 678 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 679 | + $url = "http://fr.flightaware.com/live/flight/".$callsign; |
|
| 680 | 680 | $check_date = new Datetime($date); |
| 681 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 681 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 682 | 682 | $data = $Common->getData($url); |
| 683 | 683 | if ($data != '') { |
| 684 | 684 | $table = $Common->table2array($data); |
| 685 | 685 | if (isset($table[11][0])) { |
| 686 | - $departureTime = str_replace('h',':',substr($table[5][0],0,5)); |
|
| 687 | - $arrivalTime = str_replace('h',':',substr($table[5][1],0,5)); |
|
| 686 | + $departureTime = str_replace('h', ':', substr($table[5][0], 0, 5)); |
|
| 687 | + $arrivalTime = str_replace('h', ':', substr($table[5][1], 0, 5)); |
|
| 688 | 688 | echo $table[3][0]; |
| 689 | - sscanf($table[3][0],'%*[^(] (%3[A-Z] / %*4[A-Z])',$DepartureAirportIata); |
|
| 690 | - sscanf($table[3][1],'%*[^(] (%3[A-Z] / %*4[A-Z])',$ArrivalAirportIata); |
|
| 691 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightaware'); |
|
| 689 | + sscanf($table[3][0], '%*[^(] (%3[A-Z] / %*4[A-Z])', $DepartureAirportIata); |
|
| 690 | + sscanf($table[3][1], '%*[^(] (%3[A-Z] / %*4[A-Z])', $ArrivalAirportIata); |
|
| 691 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightaware'); |
|
| 692 | 692 | } |
| 693 | 693 | } |
| 694 | 694 | return array(); |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | public function getCostToTravel($callsign, $date = 'NOW') { |
| 704 | 704 | $Common = new Common(); |
| 705 | - $url= "http://www.costtotravel.com/flight-number/".$callsign; |
|
| 705 | + $url = "http://www.costtotravel.com/flight-number/".$callsign; |
|
| 706 | 706 | $check_date = new Datetime($date); |
| 707 | 707 | //if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
| 708 | 708 | $data = $Common->getData($url); |
@@ -710,11 +710,11 @@ discard block |
||
| 710 | 710 | $table = $Common->table2array($data); |
| 711 | 711 | //print_r($table); |
| 712 | 712 | if (isset($table[11][1])) { |
| 713 | - $departureTime = substr($table[11][1],0,5); |
|
| 714 | - $arrivalTime = substr($table[17][1],0,5); |
|
| 715 | - $DepartureAirportIata = substr($table[13][1],0,3); |
|
| 716 | - $ArrivalAirportIata = substr($table[15][1],0,3); |
|
| 717 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel'); |
|
| 713 | + $departureTime = substr($table[11][1], 0, 5); |
|
| 714 | + $arrivalTime = substr($table[17][1], 0, 5); |
|
| 715 | + $DepartureAirportIata = substr($table[13][1], 0, 3); |
|
| 716 | + $ArrivalAirportIata = substr($table[15][1], 0, 3); |
|
| 717 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_costtotravel'); |
|
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | return array(); |
@@ -726,13 +726,13 @@ discard block |
||
| 726 | 726 | * @param String $date date we want flight number info |
| 727 | 727 | * @return Flight departure and arrival airports and time |
| 728 | 728 | */ |
| 729 | - private function getAirCanada($callsign,$date = 'NOW') { |
|
| 729 | + private function getAirCanada($callsign, $date = 'NOW') { |
|
| 730 | 730 | $Common = new Common(); |
| 731 | 731 | date_default_timezone_set('UTC'); |
| 732 | 732 | $check_date = new Datetime($date); |
| 733 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 734 | - $url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249"; |
|
| 735 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 733 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 734 | + $url = "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249"; |
|
| 735 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 736 | 736 | $data = $Common->getData($url); |
| 737 | 737 | $dom = new DomDocument(); |
| 738 | 738 | $dom->loadXML($data); |
@@ -740,11 +740,11 @@ discard block |
||
| 740 | 740 | $departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0); |
| 741 | 741 | if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) { |
| 742 | 742 | $DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
| 743 | - $departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
|
| 743 | + $departureTime = date('H:i', strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
|
| 744 | 744 | $arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0); |
| 745 | 745 | $ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
| 746 | - $arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
|
| 747 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada'); |
|
| 746 | + $arrivalTime = date('H:i', strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
|
| 747 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_aircanada'); |
|
| 748 | 748 | } else return array(); |
| 749 | 749 | } |
| 750 | 750 | |
@@ -756,21 +756,21 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | private function getVietnamAirlines($callsign, $date = 'NOW') { |
| 758 | 758 | $Common = new Common(); |
| 759 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 759 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 760 | 760 | $check_date = new Datetime($date); |
| 761 | - $url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&"; |
|
| 762 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 761 | + $url = "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&"; |
|
| 762 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 763 | 763 | $data = $Common->getData($url); |
| 764 | 764 | if ($data != '') { |
| 765 | 765 | $table = $Common->table2array($data); |
| 766 | 766 | $flight = $table; |
| 767 | - preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch); |
|
| 768 | - preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch); |
|
| 767 | + preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch); |
|
| 768 | + preg_match('/([A-Z]{3})/', $flight[21][0], $ArrivalAirportIataMatch); |
|
| 769 | 769 | $DepartureAirportIata = $DepartureAirportIataMatch[0]; |
| 770 | 770 | $ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
| 771 | 771 | $departureTime = $flight[5][1]; |
| 772 | 772 | $arrivalTime = $flight[23][1]; |
| 773 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines'); |
|
| 773 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_vietnamairlines'); |
|
| 774 | 774 | } |
| 775 | 775 | } |
| 776 | 776 | |
@@ -785,12 +785,12 @@ discard block |
||
| 785 | 785 | $Common = new Common(); |
| 786 | 786 | date_default_timezone_set('UTC'); |
| 787 | 787 | //AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair |
| 788 | - $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
|
| 788 | + $numvol = preg_replace('/^[A-Z]*/', '', $callsign); |
|
| 789 | 789 | $check_date = new Datetime($date); |
| 790 | - $url= "http://www.airberlin.com/en-US/site/aims.php"; |
|
| 791 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 792 | - $post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB'); |
|
| 793 | - $data = $Common->getData($url,'post',$post); |
|
| 790 | + $url = "http://www.airberlin.com/en-US/site/aims.php"; |
|
| 791 | + if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array(); |
|
| 792 | + $post = array('type' => 'departure', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => 'AB'); |
|
| 793 | + $data = $Common->getData($url, 'post', $post); |
|
| 794 | 794 | //echo $data; |
| 795 | 795 | $DepartureAirportIata = ''; |
| 796 | 796 | $ArrivalAirportIata = ''; |
@@ -803,8 +803,8 @@ discard block |
||
| 803 | 803 | if (isset($flight[5][2])) $departureAirport = $flight[5][2]; |
| 804 | 804 | else $departureAirport = ''; |
| 805 | 805 | } |
| 806 | - $post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB'); |
|
| 807 | - $data = $Common->getData($url,'post',$post); |
|
| 806 | + $post = array('type' => 'arrival', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => 'AB'); |
|
| 807 | + $data = $Common->getData($url, 'post', $post); |
|
| 808 | 808 | if ($data != '') { |
| 809 | 809 | $table = $Common->table2array($data); |
| 810 | 810 | $flight = $table; |
@@ -832,13 +832,13 @@ discard block |
||
| 832 | 832 | } |
| 833 | 833 | } |
| 834 | 834 | if (isset($DepartureAirportIata)) { |
| 835 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin'); |
|
| 835 | + return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airberlin'); |
|
| 836 | 836 | } else return array(); |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | |
| 840 | 840 | |
| 841 | - public function fetchSchedule($ident,$date = 'NOW') { |
|
| 841 | + public function fetchSchedule($ident, $date = 'NOW') { |
|
| 842 | 842 | global $globalSchedulesSources, $globalSchedulesFetch; |
| 843 | 843 | $Common = new Common(); |
| 844 | 844 | if (!$globalSchedulesFetch) return array(); |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | // Brussels Airlines |
| 909 | 909 | case "BEL": |
| 910 | 910 | case "SN": |
| 911 | - return $this->getBrussels($ident,$date,'SN'); |
|
| 911 | + return $this->getBrussels($ident, $date, 'SN'); |
|
| 912 | 912 | break; |
| 913 | 913 | /* |
| 914 | 914 | // Copa Airlines |
@@ -971,7 +971,7 @@ discard block |
||
| 971 | 971 | // TAP Portugal |
| 972 | 972 | case "TAP": |
| 973 | 973 | case "TP": |
| 974 | - return $this->getFlyTap($ident,$date); |
|
| 974 | + return $this->getFlyTap($ident, $date); |
|
| 975 | 975 | break; |
| 976 | 976 | /* |
| 977 | 977 | // Thai Airways International |
@@ -993,19 +993,19 @@ discard block |
||
| 993 | 993 | // Air France |
| 994 | 994 | case "AF": |
| 995 | 995 | case "AFR": |
| 996 | - return $this->getAirFrance($ident,$date,'AF'); |
|
| 996 | + return $this->getAirFrance($ident, $date, 'AF'); |
|
| 997 | 997 | break; |
| 998 | 998 | // HOP |
| 999 | 999 | case "A5": |
| 1000 | 1000 | case "HOP": |
| 1001 | - return $this->getAirFrance($ident,$date,'A5'); |
|
| 1001 | + return $this->getAirFrance($ident, $date, 'A5'); |
|
| 1002 | 1002 | break; |
| 1003 | 1003 | // EasyJet |
| 1004 | 1004 | case "U2": |
| 1005 | 1005 | case "DS": |
| 1006 | 1006 | case "EZY": |
| 1007 | 1007 | case "EZS": |
| 1008 | - return $this->getEasyJet($ident,$date); |
|
| 1008 | + return $this->getEasyJet($ident, $date); |
|
| 1009 | 1009 | break; |
| 1010 | 1010 | // Ryanair |
| 1011 | 1011 | case "FR": |
@@ -1063,34 +1063,34 @@ discard block |
||
| 1063 | 1063 | break; |
| 1064 | 1064 | // Vietnam Airlines |
| 1065 | 1065 | case "HVN": |
| 1066 | - return $this->getVietnamAirlines($ident,$date); |
|
| 1066 | + return $this->getVietnamAirlines($ident, $date); |
|
| 1067 | 1067 | break; |
| 1068 | 1068 | // Air Berlin |
| 1069 | 1069 | case "AB": |
| 1070 | 1070 | case "BER": |
| 1071 | - return $this->getAirBerlin($ident,$date,'AB'); |
|
| 1071 | + return $this->getAirBerlin($ident, $date, 'AB'); |
|
| 1072 | 1072 | break; |
| 1073 | 1073 | // NIKI |
| 1074 | 1074 | case "HG": |
| 1075 | 1075 | case "NLY": |
| 1076 | - return $this->getAirBerlin($ident,$date,'HG'); |
|
| 1076 | + return $this->getAirBerlin($ident, $date, 'HG'); |
|
| 1077 | 1077 | break; |
| 1078 | 1078 | // BelAir |
| 1079 | 1079 | case "4T": |
| 1080 | 1080 | case "BHP": |
| 1081 | - return $this->getAirBerlin($ident,$date,'4T'); |
|
| 1081 | + return $this->getAirBerlin($ident, $date, '4T'); |
|
| 1082 | 1082 | break; |
| 1083 | 1083 | default: |
| 1084 | 1084 | // Randomly use a generic function to get hours |
| 1085 | 1085 | if (strlen($airline_icao) == 2) { |
| 1086 | - if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware'); |
|
| 1086 | + if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper', 'costtotravel', 'flightradar24', 'flightaware'); |
|
| 1087 | 1087 | if (count($globalSchedulesSources) > 0) { |
| 1088 | - $rand = mt_rand(0,count($globalSchedulesSources)-1); |
|
| 1088 | + $rand = mt_rand(0, count($globalSchedulesSources) - 1); |
|
| 1089 | 1089 | $source = $globalSchedulesSources[$rand]; |
| 1090 | - if ($source == 'flightmapper') return $this->getFlightMapper($ident,$date); |
|
| 1091 | - elseif ($source == 'costtotravel') return $this->getCostToTravel($ident,$date); |
|
| 1090 | + if ($source == 'flightmapper') return $this->getFlightMapper($ident, $date); |
|
| 1091 | + elseif ($source == 'costtotravel') return $this->getCostToTravel($ident, $date); |
|
| 1092 | 1092 | //elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date); |
| 1093 | - elseif ($source == 'flightaware') return $this->getFlightAware($ident,$date); |
|
| 1093 | + elseif ($source == 'flightaware') return $this->getFlightAware($ident, $date); |
|
| 1094 | 1094 | } |
| 1095 | 1095 | } |
| 1096 | 1096 | } |
@@ -126,7 +126,9 @@ discard block |
||
| 126 | 126 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 127 | 127 | if (count($row) > 0) { |
| 128 | 128 | return $row; |
| 129 | - } else return array(); |
|
| 129 | + } else { |
|
| 130 | + return array(); |
|
| 131 | + } |
|
| 130 | 132 | } |
| 131 | 133 | |
| 132 | 134 | public function checkSchedule($ident) { |
@@ -161,7 +163,9 @@ discard block |
||
| 161 | 163 | $Common = new Common(); |
| 162 | 164 | $check_date = new Datetime($date); |
| 163 | 165 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 164 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 166 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 167 | + return array(); |
|
| 168 | + } |
|
| 165 | 169 | $url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym'); |
| 166 | 170 | $json = $Common->getData($url); |
| 167 | 171 | |
@@ -188,7 +192,9 @@ discard block |
||
| 188 | 192 | */ |
| 189 | 193 | |
| 190 | 194 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance'); |
| 191 | - } else return array(); |
|
| 195 | + } else { |
|
| 196 | + return array(); |
|
| 197 | + } |
|
| 192 | 198 | } |
| 193 | 199 | |
| 194 | 200 | /** |
@@ -203,7 +209,9 @@ discard block |
||
| 203 | 209 | date_default_timezone_set($globalTimezone); |
| 204 | 210 | $check_date = new Datetime($date); |
| 205 | 211 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 206 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 212 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 213 | + return array(); |
|
| 214 | + } |
|
| 207 | 215 | $url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign; |
| 208 | 216 | $json = $Common->getData($url); |
| 209 | 217 | $parsed_json = json_decode($json); |
@@ -216,7 +224,9 @@ discard block |
||
| 216 | 224 | $arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'}; |
| 217 | 225 | |
| 218 | 226 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet'); |
| 219 | - } else return array(); |
|
| 227 | + } else { |
|
| 228 | + return array(); |
|
| 229 | + } |
|
| 220 | 230 | } |
| 221 | 231 | |
| 222 | 232 | /** |
@@ -227,7 +237,9 @@ discard block |
||
| 227 | 237 | private function getRyanair($callsign) { |
| 228 | 238 | $Common = new Common(); |
| 229 | 239 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 230 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 240 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 241 | + return array(); |
|
| 242 | + } |
|
| 231 | 243 | $url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/"; |
| 232 | 244 | $post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}'; |
| 233 | 245 | $headers = array('Content-Type: application/json','Content-Length: ' . strlen($post)); |
@@ -241,8 +253,12 @@ discard block |
||
| 241 | 253 | $departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'}; |
| 242 | 254 | $arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'}; |
| 243 | 255 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair'); |
| 244 | - } else return array(); |
|
| 245 | - } else return array(); |
|
| 256 | + } else { |
|
| 257 | + return array(); |
|
| 258 | + } |
|
| 259 | + } else { |
|
| 260 | + return array(); |
|
| 261 | + } |
|
| 246 | 262 | } |
| 247 | 263 | |
| 248 | 264 | /** |
@@ -253,7 +269,9 @@ discard block |
||
| 253 | 269 | private function getSwiss($callsign) { |
| 254 | 270 | $Common = new Common(); |
| 255 | 271 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 256 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 272 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 273 | + return array(); |
|
| 274 | + } |
|
| 257 | 275 | $url = "http://www.world-of-swiss.com/fr/routenetwork.json"; |
| 258 | 276 | $json = $Common->getData($url); |
| 259 | 277 | $parsed_json = json_decode($json); |
@@ -271,8 +289,12 @@ discard block |
||
| 271 | 289 | } |
| 272 | 290 | if (isset($DepartureAirportIata)) { |
| 273 | 291 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss'); |
| 274 | - } else return array(); |
|
| 275 | - } else return array(); |
|
| 292 | + } else { |
|
| 293 | + return array(); |
|
| 294 | + } |
|
| 295 | + } else { |
|
| 296 | + return array(); |
|
| 297 | + } |
|
| 276 | 298 | } |
| 277 | 299 | |
| 278 | 300 | /** |
@@ -286,12 +308,18 @@ discard block |
||
| 286 | 308 | $Common = new Common(); |
| 287 | 309 | $check_date = new Datetime($date); |
| 288 | 310 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
| 289 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 290 | - if ($globalBritishAirwaysKey == '') return array(); |
|
| 311 | + if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) { |
|
| 312 | + return array(); |
|
| 313 | + } |
|
| 314 | + if ($globalBritishAirwaysKey == '') { |
|
| 315 | + return array(); |
|
| 316 | + } |
|
| 291 | 317 | $url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json"; |
| 292 | 318 | $headers = array('Client-Key: '.$globalBritishAirwaysKey); |
| 293 | 319 | $json = $Common->getData($url,'get','',$headers); |
| 294 | - if ($json == '') return array(); |
|
| 320 | + if ($json == '') { |
|
| 321 | + return array(); |
|
| 322 | + } |
|
| 295 | 323 | $parsed_json = json_decode($json); |
| 296 | 324 | $flights = $parsed_json->{'FlightsResponse'}; |
| 297 | 325 | if (count($flights) > 0) { |
@@ -300,7 +328,9 @@ discard block |
||
| 300 | 328 | $departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'})); |
| 301 | 329 | $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'})); |
| 302 | 330 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways'); |
| 303 | - } else return array(); |
|
| 331 | + } else { |
|
| 332 | + return array(); |
|
| 333 | + } |
|
| 304 | 334 | } |
| 305 | 335 | |
| 306 | 336 | /** |
@@ -314,19 +344,27 @@ discard block |
||
| 314 | 344 | $Common = new Common(); |
| 315 | 345 | $check_date = new Datetime($date); |
| 316 | 346 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
| 317 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 318 | - if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array(); |
|
| 347 | + if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) { |
|
| 348 | + return array(); |
|
| 349 | + } |
|
| 350 | + if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') { |
|
| 351 | + return array(); |
|
| 352 | + } |
|
| 319 | 353 | $url = "https://api.lufthansa.com/v1/oauth/token"; |
| 320 | 354 | $post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials'); |
| 321 | 355 | $data = $Common->getData($url,'post',$post); |
| 322 | 356 | $parsed_data = json_decode($data); |
| 323 | - if (!isset($parsed_data->{'access_token'})) return array(); |
|
| 357 | + if (!isset($parsed_data->{'access_token'})) { |
|
| 358 | + return array(); |
|
| 359 | + } |
|
| 324 | 360 | $token = $parsed_data->{'access_token'}; |
| 325 | 361 | |
| 326 | 362 | $url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d'); |
| 327 | 363 | $headers = array('Authorization: Bearer '.$token,'Accept: application/json'); |
| 328 | 364 | $json = $Common->getData($url,'get','',$headers); |
| 329 | - if ($json == '') return array(); |
|
| 365 | + if ($json == '') { |
|
| 366 | + return array(); |
|
| 367 | + } |
|
| 330 | 368 | $parsed_json = json_decode($json); |
| 331 | 369 | if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) { |
| 332 | 370 | $DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'}; |
@@ -334,7 +372,9 @@ discard block |
||
| 334 | 372 | $ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'}; |
| 335 | 373 | $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
| 336 | 374 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
| 337 | - } else return array(); |
|
| 375 | + } else { |
|
| 376 | + return array(); |
|
| 377 | + } |
|
| 338 | 378 | } |
| 339 | 379 | |
| 340 | 380 | /** |
@@ -348,12 +388,18 @@ discard block |
||
| 348 | 388 | $Common = new Common(); |
| 349 | 389 | $check_date = new Datetime($date); |
| 350 | 390 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
| 351 | - if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
|
| 352 | - if ($globalTransaviaKey == '') return array(); |
|
| 391 | + if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) { |
|
| 392 | + return array(); |
|
| 393 | + } |
|
| 394 | + if ($globalTransaviaKey == '') { |
|
| 395 | + return array(); |
|
| 396 | + } |
|
| 353 | 397 | $url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
| 354 | 398 | $headers = array('apikey: '.$globalTransaviaKey); |
| 355 | 399 | $json = $Common->getData($url,'get','',$headers); |
| 356 | - if ($json == '') return array(); |
|
| 400 | + if ($json == '') { |
|
| 401 | + return array(); |
|
| 402 | + } |
|
| 357 | 403 | $parsed_json = json_decode($json); |
| 358 | 404 | |
| 359 | 405 | if (isset($parsed_json->{'data'}[0])) { |
@@ -362,7 +408,9 @@ discard block |
||
| 362 | 408 | $ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'}; |
| 363 | 409 | $arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'})); |
| 364 | 410 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia'); |
| 365 | - } else return array(); |
|
| 411 | + } else { |
|
| 412 | + return array(); |
|
| 413 | + } |
|
| 366 | 414 | } |
| 367 | 415 | |
| 368 | 416 | /** |
@@ -373,7 +421,9 @@ discard block |
||
| 373 | 421 | private function getTunisair($callsign) { |
| 374 | 422 | $Common = new Common(); |
| 375 | 423 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 376 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 424 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 425 | + return array(); |
|
| 426 | + } |
|
| 377 | 427 | $url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp"; |
| 378 | 428 | $data = $Common->getData($url); |
| 379 | 429 | $table = $Common->table2array($data); |
@@ -393,7 +443,9 @@ discard block |
||
| 393 | 443 | private function getVueling($callsign) { |
| 394 | 444 | $Common = new Common(); |
| 395 | 445 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 396 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 446 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 447 | + return array(); |
|
| 448 | + } |
|
| 397 | 449 | $url = "https://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=DailyFlights&OriginSelected=&DestinationSelected=&idioma=en-GB&pageid=30694&ItemsByPage=50&FlightNumberFilter=".$numvol; |
| 398 | 450 | $data = $Common->getData($url); |
| 399 | 451 | if ($data != '') { |
@@ -421,7 +473,9 @@ discard block |
||
| 421 | 473 | $Common = new Common(); |
| 422 | 474 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 423 | 475 | $check_date = new Datetime($date); |
| 424 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 476 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 477 | + return array(); |
|
| 478 | + } |
|
| 425 | 479 | $url = "https://www.iberia.com/web/flightDetail.do"; |
| 426 | 480 | $post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB'); |
| 427 | 481 | $data = $Common->getData($url,'post',$post); |
@@ -438,7 +492,9 @@ discard block |
||
| 438 | 492 | $arrivalTime = trim(str_replace(' lunes','',str_replace(' ','',$flight[5][1]))); |
| 439 | 493 | if ($arrivalTime == 'Hora estimada de llegada') { |
| 440 | 494 | $arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[5][2]))),0,5); |
| 441 | - } else $arrivalTime = substr($arrivalTime,0,5); |
|
| 495 | + } else { |
|
| 496 | + $arrivalTime = substr($arrivalTime,0,5); |
|
| 497 | + } |
|
| 442 | 498 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia'); |
| 443 | 499 | } |
| 444 | 500 | } |
@@ -455,7 +511,9 @@ discard block |
||
| 455 | 511 | $Common = new Common(); |
| 456 | 512 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 457 | 513 | $check_date = new Datetime($date); |
| 458 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 514 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 515 | + return array(); |
|
| 516 | + } |
|
| 459 | 517 | $url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y'); |
| 460 | 518 | $data = $Common->getData($url); |
| 461 | 519 | if ($data != '') { |
@@ -471,7 +529,9 @@ discard block |
||
| 471 | 529 | $departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5); |
| 472 | 530 | $arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5); |
| 473 | 531 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance'); |
| 474 | - } else return array(); |
|
| 532 | + } else { |
|
| 533 | + return array(); |
|
| 534 | + } |
|
| 475 | 535 | } |
| 476 | 536 | |
| 477 | 537 | |
@@ -490,7 +550,9 @@ discard block |
||
| 490 | 550 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 491 | 551 | $check_date = new Datetime($date); |
| 492 | 552 | $url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y'); |
| 493 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 553 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 554 | + return array(); |
|
| 555 | + } |
|
| 494 | 556 | $data = $Common->getData($url); |
| 495 | 557 | if ($data != '') { |
| 496 | 558 | $table = $Common->text2array($data); |
@@ -514,7 +576,9 @@ discard block |
||
| 514 | 576 | $check_date = new Datetime($date); |
| 515 | 577 | $url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302"; |
| 516 | 578 | //http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber"; |
| 517 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 579 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 580 | + return array(); |
|
| 581 | + } |
|
| 518 | 582 | $data = $Common->getData($url); |
| 519 | 583 | if ($data != '') { |
| 520 | 584 | //echo $data; |
@@ -605,7 +669,9 @@ discard block |
||
| 605 | 669 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 606 | 670 | $url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees"; |
| 607 | 671 | $check_date = new Datetime($date); |
| 608 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 672 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 673 | + return array(); |
|
| 674 | + } |
|
| 609 | 675 | $post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1'); |
| 610 | 676 | $data = $Common->getData($url,'post',$post); |
| 611 | 677 | if ($data != '') { |
@@ -640,7 +706,9 @@ discard block |
||
| 640 | 706 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 641 | 707 | $url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol; |
| 642 | 708 | $check_date = new Datetime($date); |
| 643 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 709 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 710 | + return array(); |
|
| 711 | + } |
|
| 644 | 712 | $data = $Common->getData($url); |
| 645 | 713 | if ($data != '') { |
| 646 | 714 | $table = $Common->table2array($data); |
@@ -678,7 +746,9 @@ discard block |
||
| 678 | 746 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 679 | 747 | $url= "http://fr.flightaware.com/live/flight/".$callsign; |
| 680 | 748 | $check_date = new Datetime($date); |
| 681 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 749 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 750 | + return array(); |
|
| 751 | + } |
|
| 682 | 752 | $data = $Common->getData($url); |
| 683 | 753 | if ($data != '') { |
| 684 | 754 | $table = $Common->table2array($data); |
@@ -732,11 +802,15 @@ discard block |
||
| 732 | 802 | $check_date = new Datetime($date); |
| 733 | 803 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 734 | 804 | $url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249"; |
| 735 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 805 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 806 | + return array(); |
|
| 807 | + } |
|
| 736 | 808 | $data = $Common->getData($url); |
| 737 | 809 | $dom = new DomDocument(); |
| 738 | 810 | $dom->loadXML($data); |
| 739 | - if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array(); |
|
| 811 | + if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) { |
|
| 812 | + return array(); |
|
| 813 | + } |
|
| 740 | 814 | $departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0); |
| 741 | 815 | if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) { |
| 742 | 816 | $DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
@@ -745,7 +819,9 @@ discard block |
||
| 745 | 819 | $ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue; |
| 746 | 820 | $arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue)); |
| 747 | 821 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada'); |
| 748 | - } else return array(); |
|
| 822 | + } else { |
|
| 823 | + return array(); |
|
| 824 | + } |
|
| 749 | 825 | } |
| 750 | 826 | |
| 751 | 827 | /** |
@@ -759,7 +835,9 @@ discard block |
||
| 759 | 835 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 760 | 836 | $check_date = new Datetime($date); |
| 761 | 837 | $url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&"; |
| 762 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 838 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 839 | + return array(); |
|
| 840 | + } |
|
| 763 | 841 | $data = $Common->getData($url); |
| 764 | 842 | if ($data != '') { |
| 765 | 843 | $table = $Common->table2array($data); |
@@ -788,7 +866,9 @@ discard block |
||
| 788 | 866 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
| 789 | 867 | $check_date = new Datetime($date); |
| 790 | 868 | $url= "http://www.airberlin.com/en-US/site/aims.php"; |
| 791 | - if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
|
| 869 | + if (!filter_var($numvol,FILTER_VALIDATE_INT)) { |
|
| 870 | + return array(); |
|
| 871 | + } |
|
| 792 | 872 | $post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB'); |
| 793 | 873 | $data = $Common->getData($url,'post',$post); |
| 794 | 874 | //echo $data; |
@@ -798,10 +878,16 @@ discard block |
||
| 798 | 878 | if ($data != '') { |
| 799 | 879 | $table = $Common->table2array($data); |
| 800 | 880 | $flight = $table; |
| 801 | - if (isset($flight[5][4])) $departureTime = $flight[5][4]; |
|
| 802 | - else $departureTime = ''; |
|
| 803 | - if (isset($flight[5][2])) $departureAirport = $flight[5][2]; |
|
| 804 | - else $departureAirport = ''; |
|
| 881 | + if (isset($flight[5][4])) { |
|
| 882 | + $departureTime = $flight[5][4]; |
|
| 883 | + } else { |
|
| 884 | + $departureTime = ''; |
|
| 885 | + } |
|
| 886 | + if (isset($flight[5][2])) { |
|
| 887 | + $departureAirport = $flight[5][2]; |
|
| 888 | + } else { |
|
| 889 | + $departureAirport = ''; |
|
| 890 | + } |
|
| 805 | 891 | } |
| 806 | 892 | $post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB'); |
| 807 | 893 | $data = $Common->getData($url,'post',$post); |
@@ -818,7 +904,9 @@ discard block |
||
| 818 | 904 | } |
| 819 | 905 | $url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner'; |
| 820 | 906 | $json = $Common->getData($url); |
| 821 | - if ($json == '') return array(); |
|
| 907 | + if ($json == '') { |
|
| 908 | + return array(); |
|
| 909 | + } |
|
| 822 | 910 | $parsed_json = json_decode($json); |
| 823 | 911 | $airports = $parsed_json->{'suggestList'}; |
| 824 | 912 | if (count($airports) > 0) { |
@@ -833,7 +921,9 @@ discard block |
||
| 833 | 921 | } |
| 834 | 922 | if (isset($DepartureAirportIata)) { |
| 835 | 923 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin'); |
| 836 | - } else return array(); |
|
| 924 | + } else { |
|
| 925 | + return array(); |
|
| 926 | + } |
|
| 837 | 927 | } |
| 838 | 928 | |
| 839 | 929 | |
@@ -841,7 +931,9 @@ discard block |
||
| 841 | 931 | public function fetchSchedule($ident,$date = 'NOW') { |
| 842 | 932 | global $globalSchedulesSources, $globalSchedulesFetch; |
| 843 | 933 | $Common = new Common(); |
| 844 | - if (!$globalSchedulesFetch) return array(); |
|
| 934 | + if (!$globalSchedulesFetch) { |
|
| 935 | + return array(); |
|
| 936 | + } |
|
| 845 | 937 | $airline_icao = ''; |
| 846 | 938 | if (!is_numeric(substr($ident, 0, 3))) |
| 847 | 939 | { |
@@ -1083,14 +1175,21 @@ discard block |
||
| 1083 | 1175 | default: |
| 1084 | 1176 | // Randomly use a generic function to get hours |
| 1085 | 1177 | if (strlen($airline_icao) == 2) { |
| 1086 | - if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware'); |
|
| 1178 | + if (!isset($globalSchedulesSources)) { |
|
| 1179 | + $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware'); |
|
| 1180 | + } |
|
| 1087 | 1181 | if (count($globalSchedulesSources) > 0) { |
| 1088 | 1182 | $rand = mt_rand(0,count($globalSchedulesSources)-1); |
| 1089 | 1183 | $source = $globalSchedulesSources[$rand]; |
| 1090 | - if ($source == 'flightmapper') return $this->getFlightMapper($ident,$date); |
|
| 1091 | - elseif ($source == 'costtotravel') return $this->getCostToTravel($ident,$date); |
|
| 1184 | + if ($source == 'flightmapper') { |
|
| 1185 | + return $this->getFlightMapper($ident,$date); |
|
| 1186 | + } elseif ($source == 'costtotravel') { |
|
| 1187 | + return $this->getCostToTravel($ident,$date); |
|
| 1188 | + } |
|
| 1092 | 1189 | //elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date); |
| 1093 | - elseif ($source == 'flightaware') return $this->getFlightAware($ident,$date); |
|
| 1190 | + elseif ($source == 'flightaware') { |
|
| 1191 | + return $this->getFlightAware($ident,$date); |
|
| 1192 | + } |
|
| 1094 | 1193 | } |
| 1095 | 1194 | } |
| 1096 | 1195 | } |
@@ -8,29 +8,29 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class Schedule { |
| 10 | 10 | protected $cookies = array(); |
| 11 | - public $db; |
|
| 11 | + public $db; |
|
| 12 | 12 | function __construct($dbc = null) { |
| 13 | 13 | $Connection = new Connection($dbc); |
| 14 | 14 | $this->db = $Connection->db; |
| 15 | - } |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Add schedule data to database |
|
| 19 | - * @param String $ident aircraft ident |
|
| 20 | - * @param String $departure_airport_icao departure airport icao |
|
| 21 | - * @param String $departure_airport_time departure airport time |
|
| 22 | - * @param String $arrival_airport_icao arrival airport icao |
|
| 23 | - * @param String $arrival_airport_time arrival airport time |
|
| 18 | + * Add schedule data to database |
|
| 19 | + * @param String $ident aircraft ident |
|
| 20 | + * @param String $departure_airport_icao departure airport icao |
|
| 21 | + * @param String $departure_airport_time departure airport time |
|
| 22 | + * @param String $arrival_airport_icao arrival airport icao |
|
| 23 | + * @param String $arrival_airport_time arrival airport time |
|
| 24 | 24 | / @param String $source source of data |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') { |
| 28 | 28 | date_default_timezone_set('UTC'); |
| 29 | 29 | $date = date("Y-m-d H:i:s",time()); |
| 30 | - //if ($departure_airport_time == '' && $arrival_airport_time == '') exit; |
|
| 31 | - //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident"; |
|
| 32 | - $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident"; |
|
| 33 | - $query_values = array(':ident' => $ident); |
|
| 30 | + //if ($departure_airport_time == '' && $arrival_airport_time == '') exit; |
|
| 31 | + //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident"; |
|
| 32 | + $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident"; |
|
| 33 | + $query_values = array(':ident' => $ident); |
|
| 34 | 34 | try { |
| 35 | 35 | $sth = $this->db->prepare($query); |
| 36 | 36 | $sth->execute($query_values); |
@@ -39,18 +39,18 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | if ($sth->fetchColumn() > 0) { |
| 41 | 41 | if ($departure_airport_time == '' && $arrival_airport_time == '') { |
| 42 | - $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao"; |
|
| 43 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao); |
|
| 42 | + $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao"; |
|
| 43 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao); |
|
| 44 | 44 | } elseif ($arrival_airport_time == '') { |
| 45 | - $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao"; |
|
| 46 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao); |
|
| 45 | + $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao"; |
|
| 46 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao); |
|
| 47 | 47 | } elseif ($departure_airport_time == '') { |
| 48 | - $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
|
| 49 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
|
| 48 | + $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
|
| 49 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
|
| 50 | 50 | } else { |
| 51 | - //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time"; |
|
| 52 | - $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
|
| 53 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
|
| 51 | + //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time"; |
|
| 52 | + $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
|
| 53 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
|
| 54 | 54 | } |
| 55 | 55 | try { |
| 56 | 56 | $sth = $this->db->prepare($query); |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | if ($sth->fetchColumn() == 0) { |
| 62 | 62 | //$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident'; |
| 63 | 63 | if ($departure_airport_time == '' && $arrival_airport_time == '') { |
| 64 | - $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 65 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 64 | + $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 65 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 66 | 66 | } elseif ($arrival_airport_time == '') { |
| 67 | - $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 68 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 67 | + $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 68 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
|
| 69 | 69 | } elseif ($departure_airport_time == '') { |
| 70 | - $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 71 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 70 | + $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 71 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 72 | 72 | } else { |
| 73 | - $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 74 | - $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 73 | + $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
|
| 74 | + $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
|
| 75 | 75 | } |
| 76 | 76 | try { |
| 77 | 77 | $sth = $this->db->prepare($query); |
@@ -104,15 +104,15 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | public function getSchedule($ident) { |
| 107 | - $Translation = new Translation($this->db); |
|
| 108 | - $operator = $Translation->checkTranslation($ident,false); |
|
| 109 | - if ($ident != $operator) { |
|
| 110 | - $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1"; |
|
| 111 | - $query_values = array(':ident' => $ident,'operator' => $operator); |
|
| 112 | - } else { |
|
| 113 | - $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1"; |
|
| 114 | - $query_values = array(':ident' => $ident); |
|
| 115 | - } |
|
| 107 | + $Translation = new Translation($this->db); |
|
| 108 | + $operator = $Translation->checkTranslation($ident,false); |
|
| 109 | + if ($ident != $operator) { |
|
| 110 | + $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1"; |
|
| 111 | + $query_values = array(':ident' => $ident,'operator' => $operator); |
|
| 112 | + } else { |
|
| 113 | + $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1"; |
|
| 114 | + $query_values = array(':ident' => $ident); |
|
| 115 | + } |
|
| 116 | 116 | try { |
| 117 | 117 | $sth = $this->db->prepare($query); |
| 118 | 118 | $sth->execute($query_values); |
@@ -127,15 +127,15 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | public function checkSchedule($ident) { |
| 129 | 129 | global $globalDBdriver; |
| 130 | - //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1"; |
|
| 131 | - if ($globalDBdriver == 'mysql') { |
|
| 130 | + //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1"; |
|
| 131 | + if ($globalDBdriver == 'mysql') { |
|
| 132 | 132 | $query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1"; |
| 133 | 133 | } else { |
| 134 | 134 | $query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident |
| 135 | 135 | AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '15 DAYS' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL) |
| 136 | 136 | OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '15 DAYS' AND CURRENT_TIMESTAMP) LIMIT 1"; |
| 137 | 137 | } |
| 138 | - $query_values = array(':ident' => $ident); |
|
| 138 | + $query_values = array(':ident' => $ident); |
|
| 139 | 139 | try { |
| 140 | 140 | $sth = $this->db->prepare($query); |
| 141 | 141 | $sth->execute($query_values); |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * Get flight info from Air France |
|
| 151 | - * @param String $callsign The callsign |
|
| 152 | - * @param String $date date we want flight number info |
|
| 153 | - * @param String $carrier IATA code |
|
| 154 | - * @return Flight departure and arrival airports and time |
|
| 155 | - */ |
|
| 150 | + * Get flight info from Air France |
|
| 151 | + * @param String $callsign The callsign |
|
| 152 | + * @param String $date date we want flight number info |
|
| 153 | + * @param String $carrier IATA code |
|
| 154 | + * @return Flight departure and arrival airports and time |
|
| 155 | + */ |
|
| 156 | 156 | private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') { |
| 157 | 157 | $Common = new Common(); |
| 158 | 158 | $check_date = new Datetime($date); |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * Get flight info from EasyJet |
|
| 192 | - * @param String $callsign The callsign |
|
| 193 | - * @param String $date date we want flight number info |
|
| 194 | - * @return Flight departure and arrival airports and time |
|
| 195 | - */ |
|
| 191 | + * Get flight info from EasyJet |
|
| 192 | + * @param String $callsign The callsign |
|
| 193 | + * @param String $date date we want flight number info |
|
| 194 | + * @return Flight departure and arrival airports and time |
|
| 195 | + */ |
|
| 196 | 196 | private function getEasyJet($callsign, $date = 'NOW') { |
| 197 | 197 | global $globalTimezone; |
| 198 | 198 | $Common = new Common(); |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * Get flight info from Ryanair |
|
| 220 | - * @param String $callsign The callsign |
|
| 221 | - * @return Flight departure and arrival airports and time |
|
| 222 | - */ |
|
| 219 | + * Get flight info from Ryanair |
|
| 220 | + * @param String $callsign The callsign |
|
| 221 | + * @return Flight departure and arrival airports and time |
|
| 222 | + */ |
|
| 223 | 223 | private function getRyanair($callsign) { |
| 224 | 224 | $Common = new Common(); |
| 225 | 225 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Get flight info from Swiss |
|
| 246 | - * @param String $callsign The callsign |
|
| 247 | - * @return Flight departure and arrival airports and time |
|
| 248 | - */ |
|
| 245 | + * Get flight info from Swiss |
|
| 246 | + * @param String $callsign The callsign |
|
| 247 | + * @return Flight departure and arrival airports and time |
|
| 248 | + */ |
|
| 249 | 249 | private function getSwiss($callsign) { |
| 250 | 250 | $Common = new Common(); |
| 251 | 251 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -272,11 +272,11 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | - * Get flight info from British Airways API |
|
| 276 | - * @param String $callsign The callsign |
|
| 277 | - * @param String $date date we want flight number info |
|
| 278 | - * @return Flight departure and arrival airports and time |
|
| 279 | - */ |
|
| 275 | + * Get flight info from British Airways API |
|
| 276 | + * @param String $callsign The callsign |
|
| 277 | + * @param String $date date we want flight number info |
|
| 278 | + * @return Flight departure and arrival airports and time |
|
| 279 | + */ |
|
| 280 | 280 | public function getBritishAirways($callsign, $date = 'NOW') { |
| 281 | 281 | global $globalBritishAirwaysKey; |
| 282 | 282 | $Common = new Common(); |
@@ -300,11 +300,11 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
| 303 | - * Get flight info from Lutfhansa API |
|
| 304 | - * @param String $callsign The callsign |
|
| 305 | - * @param String $date date we want flight number info |
|
| 306 | - * @return Flight departure and arrival airports and time |
|
| 307 | - */ |
|
| 303 | + * Get flight info from Lutfhansa API |
|
| 304 | + * @param String $callsign The callsign |
|
| 305 | + * @param String $date date we want flight number info |
|
| 306 | + * @return Flight departure and arrival airports and time |
|
| 307 | + */ |
|
| 308 | 308 | public function getLufthansa($callsign, $date = 'NOW') { |
| 309 | 309 | global $globalLufthansaKey; |
| 310 | 310 | $Common = new Common(); |
@@ -334,11 +334,11 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | - * Get flight info from Transavia API |
|
| 338 | - * @param String $callsign The callsign |
|
| 339 | - * @param String $date date we want flight number info |
|
| 340 | - * @return Flight departure and arrival airports and time |
|
| 341 | - */ |
|
| 337 | + * Get flight info from Transavia API |
|
| 338 | + * @param String $callsign The callsign |
|
| 339 | + * @param String $date date we want flight number info |
|
| 340 | + * @return Flight departure and arrival airports and time |
|
| 341 | + */ |
|
| 342 | 342 | private function getTransavia($callsign, $date = 'NOW') { |
| 343 | 343 | global $globalTransaviaKey; |
| 344 | 344 | $Common = new Common(); |
@@ -362,10 +362,10 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
| 365 | - * Get flight info from Tunisair |
|
| 366 | - * @param String $callsign The callsign |
|
| 367 | - * @return Flight departure and arrival airports and time |
|
| 368 | - */ |
|
| 365 | + * Get flight info from Tunisair |
|
| 366 | + * @param String $callsign The callsign |
|
| 367 | + * @return Flight departure and arrival airports and time |
|
| 368 | + */ |
|
| 369 | 369 | private function getTunisair($callsign) { |
| 370 | 370 | $Common = new Common(); |
| 371 | 371 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -382,10 +382,10 @@ discard block |
||
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
| 385 | - * Get flight info from Vueling |
|
| 386 | - * @param String $callsign The callsign |
|
| 387 | - * @return Flight departure and arrival airports and time |
|
| 388 | - */ |
|
| 385 | + * Get flight info from Vueling |
|
| 386 | + * @param String $callsign The callsign |
|
| 387 | + * @return Flight departure and arrival airports and time |
|
| 388 | + */ |
|
| 389 | 389 | private function getVueling($callsign) { |
| 390 | 390 | $Common = new Common(); |
| 391 | 391 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -408,11 +408,11 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
| 411 | - * Get flight info from Iberia |
|
| 412 | - * @param String $callsign The callsign |
|
| 413 | - * @param String $date date we want flight number info |
|
| 414 | - * @return Flight departure and arrival airports and time |
|
| 415 | - */ |
|
| 411 | + * Get flight info from Iberia |
|
| 412 | + * @param String $callsign The callsign |
|
| 413 | + * @param String $date date we want flight number info |
|
| 414 | + * @return Flight departure and arrival airports and time |
|
| 415 | + */ |
|
| 416 | 416 | private function getIberia($callsign, $date = 'NOW') { |
| 417 | 417 | $Common = new Common(); |
| 418 | 418 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -442,11 +442,11 @@ discard block |
||
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
| 445 | - * Get flight info from Star Alliance |
|
| 446 | - * @param String $callsign The callsign |
|
| 447 | - * @param String $date date we want flight number info |
|
| 448 | - * @return Flight departure and arrival airports and time |
|
| 449 | - */ |
|
| 445 | + * Get flight info from Star Alliance |
|
| 446 | + * @param String $callsign The callsign |
|
| 447 | + * @param String $date date we want flight number info |
|
| 448 | + * @return Flight departure and arrival airports and time |
|
| 449 | + */ |
|
| 450 | 450 | private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') { |
| 451 | 451 | $Common = new Common(); |
| 452 | 452 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
| 479 | - * Get flight info from Alitalia |
|
| 480 | - * @param String $callsign The callsign |
|
| 481 | - * @param String $date date we want flight number info |
|
| 482 | - * @return Flight departure and arrival airports and time |
|
| 483 | - */ |
|
| 479 | + * Get flight info from Alitalia |
|
| 480 | + * @param String $callsign The callsign |
|
| 481 | + * @param String $date date we want flight number info |
|
| 482 | + * @return Flight departure and arrival airports and time |
|
| 483 | + */ |
|
| 484 | 484 | private function getAlitalia($callsign, $date = 'NOW') { |
| 485 | 485 | $Common = new Common(); |
| 486 | 486 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -499,11 +499,11 @@ discard block |
||
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
| 502 | - * Get flight info from Brussels airlines |
|
| 503 | - * @param String $callsign The callsign |
|
| 504 | - * @param String $date date we want flight number info |
|
| 505 | - * @return Flight departure and arrival airports and time |
|
| 506 | - */ |
|
| 502 | + * Get flight info from Brussels airlines |
|
| 503 | + * @param String $callsign The callsign |
|
| 504 | + * @param String $date date we want flight number info |
|
| 505 | + * @return Flight departure and arrival airports and time |
|
| 506 | + */ |
|
| 507 | 507 | private function getBrussels($callsign, $date = 'NOW') { |
| 508 | 508 | $Common = new Common(); |
| 509 | 509 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -513,24 +513,24 @@ discard block |
||
| 513 | 513 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
| 514 | 514 | $data = $Common->getData($url); |
| 515 | 515 | if ($data != '') { |
| 516 | - //echo $data; |
|
| 517 | - $parsed_json = json_decode($data); |
|
| 518 | - if (isset($parsed_json[0]->FromAirportCode)) { |
|
| 516 | + //echo $data; |
|
| 517 | + $parsed_json = json_decode($data); |
|
| 518 | + if (isset($parsed_json[0]->FromAirportCode)) { |
|
| 519 | 519 | $DepartureAirportIata = $parsed_json[0]->FromAirportCode; |
| 520 | 520 | $ArrivalAirportIata = $parsed_json[0]->ToAirportCode; |
| 521 | 521 | $departureTime = date('H:i',strtotime($parsed_json[0]->ScheduledDepatureDate)); |
| 522 | 522 | $arrivalTime = date('H:i',strtotime($parsed_json[0]->ScheduledArrivalDate)); |
| 523 | 523 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels'); |
| 524 | - } |
|
| 524 | + } |
|
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
| 529 | - * Get flight info from FlightRadar24 |
|
| 530 | - * @param String $callsign The callsign |
|
| 531 | - * @param String $date date we want flight number info |
|
| 532 | - * @return Flight departure and arrival airports and time |
|
| 533 | - */ |
|
| 529 | + * Get flight info from FlightRadar24 |
|
| 530 | + * @param String $callsign The callsign |
|
| 531 | + * @param String $date date we want flight number info |
|
| 532 | + * @return Flight departure and arrival airports and time |
|
| 533 | + */ |
|
| 534 | 534 | /* |
| 535 | 535 | public function getFlightRadar24($callsign, $date = 'NOW') { |
| 536 | 536 | $Common = new Common(); |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | } |
| 560 | 560 | */ |
| 561 | 561 | /** |
| 562 | - * Get flight info from Lufthansa |
|
| 563 | - * @param String $callsign The callsign |
|
| 564 | - * @param String $date date we want flight number info |
|
| 565 | - * @return Flight departure and arrival airports and time |
|
| 566 | - */ |
|
| 562 | + * Get flight info from Lufthansa |
|
| 563 | + * @param String $callsign The callsign |
|
| 564 | + * @param String $date date we want flight number info |
|
| 565 | + * @return Flight departure and arrival airports and time |
|
| 566 | + */ |
|
| 567 | 567 | |
| 568 | 568 | /* private function getLufthansa($callsign, $date = 'NOW') { |
| 569 | 569 | $Common = new Common(); |
@@ -591,11 +591,11 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | */ |
| 593 | 593 | /** |
| 594 | - * Get flight info from flytap |
|
| 595 | - * @param String $callsign The callsign |
|
| 596 | - * @param String $date date we want flight number info |
|
| 597 | - * @return Flight departure and arrival airports and time |
|
| 598 | - */ |
|
| 594 | + * Get flight info from flytap |
|
| 595 | + * @param String $callsign The callsign |
|
| 596 | + * @param String $date date we want flight number info |
|
| 597 | + * @return Flight departure and arrival airports and time |
|
| 598 | + */ |
|
| 599 | 599 | private function getFlyTap($callsign, $date = 'NOW') { |
| 600 | 600 | $Common = new Common(); |
| 601 | 601 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -618,11 +618,11 @@ discard block |
||
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Get flight info from flightmapper |
|
| 622 | - * @param String $callsign The callsign |
|
| 623 | - * @param String $date date we want flight number info |
|
| 624 | - * @return Flight departure and arrival airports and time |
|
| 625 | - */ |
|
| 621 | + * Get flight info from flightmapper |
|
| 622 | + * @param String $callsign The callsign |
|
| 623 | + * @param String $date date we want flight number info |
|
| 624 | + * @return Flight departure and arrival airports and time |
|
| 625 | + */ |
|
| 626 | 626 | public function getFlightMapper($callsign, $date = 'NOW') { |
| 627 | 627 | $Common = new Common(); |
| 628 | 628 | if (!is_numeric(substr($callsign, 0, 3))) |
@@ -644,11 +644,11 @@ discard block |
||
| 644 | 644 | $sched = $table[5][0]; |
| 645 | 645 | $n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr); |
| 646 | 646 | if ($n == 7) { |
| 647 | - $departureTime = $dhour; |
|
| 648 | - $arrivalTime = $ahour; |
|
| 649 | - $DepartureAirportIata = str_replace(array('(',')'),'',$darr); |
|
| 650 | - $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr); |
|
| 651 | - return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper'); |
|
| 647 | + $departureTime = $dhour; |
|
| 648 | + $arrivalTime = $ahour; |
|
| 649 | + $DepartureAirportIata = str_replace(array('(',')'),'',$darr); |
|
| 650 | + $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr); |
|
| 651 | + return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper'); |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | } |
@@ -656,11 +656,11 @@ discard block |
||
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
| 659 | - * Get flight info from flightaware |
|
| 660 | - * @param String $callsign The callsign |
|
| 661 | - * @param String $date date we want flight number info |
|
| 662 | - * @return Flight departure and arrival airports and time |
|
| 663 | - */ |
|
| 659 | + * Get flight info from flightaware |
|
| 660 | + * @param String $callsign The callsign |
|
| 661 | + * @param String $date date we want flight number info |
|
| 662 | + * @return Flight departure and arrival airports and time |
|
| 663 | + */ |
|
| 664 | 664 | public function getFlightAware($callsign, $date = 'NOW') { |
| 665 | 665 | $Common = new Common(); |
| 666 | 666 | if (!is_numeric(substr($callsign, 0, 3))) |
@@ -691,11 +691,11 @@ discard block |
||
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | /** |
| 694 | - * Get flight info from CostToTravel |
|
| 695 | - * @param String $callsign The callsign |
|
| 696 | - * @param String $date date we want flight number info |
|
| 697 | - * @return Flight departure and arrival airports and time |
|
| 698 | - */ |
|
| 694 | + * Get flight info from CostToTravel |
|
| 695 | + * @param String $callsign The callsign |
|
| 696 | + * @param String $date date we want flight number info |
|
| 697 | + * @return Flight departure and arrival airports and time |
|
| 698 | + */ |
|
| 699 | 699 | public function getCostToTravel($callsign, $date = 'NOW') { |
| 700 | 700 | $Common = new Common(); |
| 701 | 701 | $url= "http://www.costtotravel.com/flight-number/".$callsign; |
@@ -717,11 +717,11 @@ discard block |
||
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
| 720 | - * Get flight info from Air Canada |
|
| 721 | - * @param String $callsign The callsign |
|
| 722 | - * @param String $date date we want flight number info |
|
| 723 | - * @return Flight departure and arrival airports and time |
|
| 724 | - */ |
|
| 720 | + * Get flight info from Air Canada |
|
| 721 | + * @param String $callsign The callsign |
|
| 722 | + * @param String $date date we want flight number info |
|
| 723 | + * @return Flight departure and arrival airports and time |
|
| 724 | + */ |
|
| 725 | 725 | private function getAirCanada($callsign,$date = 'NOW') { |
| 726 | 726 | $Common = new Common(); |
| 727 | 727 | date_default_timezone_set('UTC'); |
@@ -745,11 +745,11 @@ discard block |
||
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
| 748 | - * Get flight info from Vietnam Airlines |
|
| 749 | - * @param String $callsign The callsign |
|
| 750 | - * @param String $date date we want flight number info |
|
| 751 | - * @return Flight departure and arrival airports and time |
|
| 752 | - */ |
|
| 748 | + * Get flight info from Vietnam Airlines |
|
| 749 | + * @param String $callsign The callsign |
|
| 750 | + * @param String $date date we want flight number info |
|
| 751 | + * @return Flight departure and arrival airports and time |
|
| 752 | + */ |
|
| 753 | 753 | private function getVietnamAirlines($callsign, $date = 'NOW') { |
| 754 | 754 | $Common = new Common(); |
| 755 | 755 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
@@ -771,12 +771,12 @@ discard block |
||
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | /** |
| 774 | - * Get flight info from Air Berlin |
|
| 775 | - * @param String $callsign The callsign |
|
| 776 | - * @param String $date date we want flight number info |
|
| 777 | - * @param String $carrier IATA code |
|
| 778 | - * @return Flight departure and arrival airports and time |
|
| 779 | - */ |
|
| 774 | + * Get flight info from Air Berlin |
|
| 775 | + * @param String $callsign The callsign |
|
| 776 | + * @param String $date date we want flight number info |
|
| 777 | + * @param String $carrier IATA code |
|
| 778 | + * @return Flight departure and arrival airports and time |
|
| 779 | + */ |
|
| 780 | 780 | private function getAirBerlin($callsign, $date = 'NOW', $carrier = 'AB') { |
| 781 | 781 | $Common = new Common(); |
| 782 | 782 | date_default_timezone_set('UTC'); |
@@ -805,11 +805,11 @@ discard block |
||
| 805 | 805 | $table = $Common->table2array($data); |
| 806 | 806 | $flight = $table; |
| 807 | 807 | if (isset($flight[5][4])) { |
| 808 | - $arrivalTime = $flight[5][4]; |
|
| 809 | - $arrivalAirport = $flight[5][3]; |
|
| 808 | + $arrivalTime = $flight[5][4]; |
|
| 809 | + $arrivalAirport = $flight[5][3]; |
|
| 810 | 810 | } else { |
| 811 | - $arrivalTime = ''; |
|
| 812 | - $arrivalAirport = ''; |
|
| 811 | + $arrivalTime = ''; |
|
| 812 | + $arrivalAirport = ''; |
|
| 813 | 813 | } |
| 814 | 814 | } |
| 815 | 815 | $url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner'; |
@@ -1091,7 +1091,7 @@ discard block |
||
| 1091 | 1091 | } |
| 1092 | 1092 | } |
| 1093 | 1093 | } |
| 1094 | - return array(); |
|
| 1094 | + return array(); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | } |
| 1097 | 1097 | |
@@ -7,73 +7,73 @@ |
||
| 7 | 7 | function __construct($dbc = null) { |
| 8 | 8 | $Connection = new Connection($dbc); |
| 9 | 9 | $this->db = $Connection->db; |
| 10 | - } |
|
| 11 | - public function getAllLocationInfo() { |
|
| 12 | - $query = "SELECT * FROM source_location"; |
|
| 13 | - $query_values = array(); |
|
| 14 | - try { |
|
| 15 | - $sth = $this->db->prepare($query); |
|
| 16 | - $sth->execute($query_values); |
|
| 17 | - } catch(PDOException $e) { |
|
| 18 | - return "error : ".$e->getMessage(); |
|
| 19 | - } |
|
| 20 | - $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 21 | - return $all; |
|
| 22 | - } |
|
| 23 | - public function getLocationInfobyName($name) { |
|
| 24 | - $query = "SELECT * FROM source_location WHERE name = :name"; |
|
| 25 | - $query_values = array(':name' => $name); |
|
| 26 | - try { |
|
| 27 | - $sth = $this->db->prepare($query); |
|
| 28 | - $sth->execute($query_values); |
|
| 29 | - } catch(PDOException $e) { |
|
| 30 | - return "error : ".$e->getMessage(); |
|
| 31 | - } |
|
| 32 | - $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 33 | - return $all; |
|
| 34 | - } |
|
| 35 | - public function getLocationInfobySourceName($name) { |
|
| 36 | - $query = "SELECT * FROM source_location WHERE source = :name"; |
|
| 37 | - $query_values = array(':name' => $name); |
|
| 38 | - try { |
|
| 39 | - $sth = $this->db->prepare($query); |
|
| 40 | - $sth->execute($query_values); |
|
| 41 | - } catch(PDOException $e) { |
|
| 42 | - return "error : ".$e->getMessage(); |
|
| 43 | - } |
|
| 44 | - $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 45 | - return $all; |
|
| 46 | - } |
|
| 10 | + } |
|
| 11 | + public function getAllLocationInfo() { |
|
| 12 | + $query = "SELECT * FROM source_location"; |
|
| 13 | + $query_values = array(); |
|
| 14 | + try { |
|
| 15 | + $sth = $this->db->prepare($query); |
|
| 16 | + $sth->execute($query_values); |
|
| 17 | + } catch(PDOException $e) { |
|
| 18 | + return "error : ".$e->getMessage(); |
|
| 19 | + } |
|
| 20 | + $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 21 | + return $all; |
|
| 22 | + } |
|
| 23 | + public function getLocationInfobyName($name) { |
|
| 24 | + $query = "SELECT * FROM source_location WHERE name = :name"; |
|
| 25 | + $query_values = array(':name' => $name); |
|
| 26 | + try { |
|
| 27 | + $sth = $this->db->prepare($query); |
|
| 28 | + $sth->execute($query_values); |
|
| 29 | + } catch(PDOException $e) { |
|
| 30 | + return "error : ".$e->getMessage(); |
|
| 31 | + } |
|
| 32 | + $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 33 | + return $all; |
|
| 34 | + } |
|
| 35 | + public function getLocationInfobySourceName($name) { |
|
| 36 | + $query = "SELECT * FROM source_location WHERE source = :name"; |
|
| 37 | + $query_values = array(':name' => $name); |
|
| 38 | + try { |
|
| 39 | + $sth = $this->db->prepare($query); |
|
| 40 | + $sth->execute($query_values); |
|
| 41 | + } catch(PDOException $e) { |
|
| 42 | + return "error : ".$e->getMessage(); |
|
| 43 | + } |
|
| 44 | + $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
| 45 | + return $all; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function addLocation($name,$latitude,$longitude,$altitude,$city,$country,$source,$logo = 'antenna.png') { |
|
| 49 | - $query = "INSERT INTO source_location (name,latitude,longitude,altitude,country,city,logo,source) VALUES (:name,:latitude,:longitude,:altitude,:country,:city,:logo,:source)"; |
|
| 50 | - $query_values = array(':name' => $name,':latitude' => $latitude, ':longitude' => $longitude,':altitude' => $altitude,':city' => $city,':country' => $country,':logo' => $logo,':source' => $source); |
|
| 51 | - try { |
|
| 52 | - $sth = $this->db->prepare($query); |
|
| 53 | - $sth->execute($query_values); |
|
| 54 | - } catch(PDOException $e) { |
|
| 55 | - return "error : ".$e->getMessage(); |
|
| 56 | - } |
|
| 57 | - } |
|
| 48 | + public function addLocation($name,$latitude,$longitude,$altitude,$city,$country,$source,$logo = 'antenna.png') { |
|
| 49 | + $query = "INSERT INTO source_location (name,latitude,longitude,altitude,country,city,logo,source) VALUES (:name,:latitude,:longitude,:altitude,:country,:city,:logo,:source)"; |
|
| 50 | + $query_values = array(':name' => $name,':latitude' => $latitude, ':longitude' => $longitude,':altitude' => $altitude,':city' => $city,':country' => $country,':logo' => $logo,':source' => $source); |
|
| 51 | + try { |
|
| 52 | + $sth = $this->db->prepare($query); |
|
| 53 | + $sth->execute($query_values); |
|
| 54 | + } catch(PDOException $e) { |
|
| 55 | + return "error : ".$e->getMessage(); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function deleteLocation($id) { |
|
| 60 | - $query = "DELETE FROM source_location WHERE id = :id"; |
|
| 61 | - $query_values = array(':id' => $id); |
|
| 62 | - try { |
|
| 63 | - $sth = $this->db->prepare($query); |
|
| 64 | - $sth->execute($query_values); |
|
| 65 | - } catch(PDOException $e) { |
|
| 66 | - return "error : ".$e->getMessage(); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - public function deleteAllLocation() { |
|
| 70 | - $query = "DELETE FROM source_location"; |
|
| 71 | - try { |
|
| 72 | - $sth = $this->db->prepare($query); |
|
| 73 | - $sth->execute(); |
|
| 74 | - } catch(PDOException $e) { |
|
| 75 | - return "error : ".$e->getMessage(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 59 | + public function deleteLocation($id) { |
|
| 60 | + $query = "DELETE FROM source_location WHERE id = :id"; |
|
| 61 | + $query_values = array(':id' => $id); |
|
| 62 | + try { |
|
| 63 | + $sth = $this->db->prepare($query); |
|
| 64 | + $sth->execute($query_values); |
|
| 65 | + } catch(PDOException $e) { |
|
| 66 | + return "error : ".$e->getMessage(); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + public function deleteAllLocation() { |
|
| 70 | + $query = "DELETE FROM source_location"; |
|
| 71 | + try { |
|
| 72 | + $sth = $this->db->prepare($query); |
|
| 73 | + $sth->execute(); |
|
| 74 | + } catch(PDOException $e) { |
|
| 75 | + return "error : ".$e->getMessage(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | ?> |
| 80 | 80 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | try { |
| 15 | 15 | $sth = $this->db->prepare($query); |
| 16 | 16 | $sth->execute($query_values); |
| 17 | - } catch(PDOException $e) { |
|
| 17 | + } catch (PDOException $e) { |
|
| 18 | 18 | return "error : ".$e->getMessage(); |
| 19 | 19 | } |
| 20 | 20 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | try { |
| 27 | 27 | $sth = $this->db->prepare($query); |
| 28 | 28 | $sth->execute($query_values); |
| 29 | - } catch(PDOException $e) { |
|
| 29 | + } catch (PDOException $e) { |
|
| 30 | 30 | return "error : ".$e->getMessage(); |
| 31 | 31 | } |
| 32 | 32 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -38,20 +38,20 @@ discard block |
||
| 38 | 38 | try { |
| 39 | 39 | $sth = $this->db->prepare($query); |
| 40 | 40 | $sth->execute($query_values); |
| 41 | - } catch(PDOException $e) { |
|
| 41 | + } catch (PDOException $e) { |
|
| 42 | 42 | return "error : ".$e->getMessage(); |
| 43 | 43 | } |
| 44 | 44 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 45 | 45 | return $all; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function addLocation($name,$latitude,$longitude,$altitude,$city,$country,$source,$logo = 'antenna.png') { |
|
| 48 | + public function addLocation($name, $latitude, $longitude, $altitude, $city, $country, $source, $logo = 'antenna.png') { |
|
| 49 | 49 | $query = "INSERT INTO source_location (name,latitude,longitude,altitude,country,city,logo,source) VALUES (:name,:latitude,:longitude,:altitude,:country,:city,:logo,:source)"; |
| 50 | - $query_values = array(':name' => $name,':latitude' => $latitude, ':longitude' => $longitude,':altitude' => $altitude,':city' => $city,':country' => $country,':logo' => $logo,':source' => $source); |
|
| 50 | + $query_values = array(':name' => $name, ':latitude' => $latitude, ':longitude' => $longitude, ':altitude' => $altitude, ':city' => $city, ':country' => $country, ':logo' => $logo, ':source' => $source); |
|
| 51 | 51 | try { |
| 52 | 52 | $sth = $this->db->prepare($query); |
| 53 | 53 | $sth->execute($query_values); |
| 54 | - } catch(PDOException $e) { |
|
| 54 | + } catch (PDOException $e) { |
|
| 55 | 55 | return "error : ".$e->getMessage(); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | try { |
| 63 | 63 | $sth = $this->db->prepare($query); |
| 64 | 64 | $sth->execute($query_values); |
| 65 | - } catch(PDOException $e) { |
|
| 65 | + } catch (PDOException $e) { |
|
| 66 | 66 | return "error : ".$e->getMessage(); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | try { |
| 72 | 72 | $sth = $this->db->prepare($query); |
| 73 | 73 | $sth->execute(); |
| 74 | - } catch(PDOException $e) { |
|
| 74 | + } catch (PDOException $e) { |
|
| 75 | 75 | return "error : ".$e->getMessage(); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -824,11 +824,11 @@ |
||
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
| 827 | - * Returns true if $string is valid UTF-8 and false otherwise. |
|
| 828 | - * |
|
| 829 | - * @param mixed $str String to be tested |
|
| 830 | - * @return boolean |
|
| 831 | - */ |
|
| 827 | + * Returns true if $string is valid UTF-8 and false otherwise. |
|
| 828 | + * |
|
| 829 | + * @param mixed $str String to be tested |
|
| 830 | + * @return boolean |
|
| 831 | + */ |
|
| 832 | 832 | static function is_utf8($str) |
| 833 | 833 | { |
| 834 | 834 | $c=0; $b=0; |
@@ -45,21 +45,21 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | define('HDOM_TYPE_ELEMENT', 1); |
| 47 | 47 | define('HDOM_TYPE_COMMENT', 2); |
| 48 | -define('HDOM_TYPE_TEXT', 3); |
|
| 49 | -define('HDOM_TYPE_ENDTAG', 4); |
|
| 50 | -define('HDOM_TYPE_ROOT', 5); |
|
| 48 | +define('HDOM_TYPE_TEXT', 3); |
|
| 49 | +define('HDOM_TYPE_ENDTAG', 4); |
|
| 50 | +define('HDOM_TYPE_ROOT', 5); |
|
| 51 | 51 | define('HDOM_TYPE_UNKNOWN', 6); |
| 52 | 52 | define('HDOM_QUOTE_DOUBLE', 0); |
| 53 | 53 | define('HDOM_QUOTE_SINGLE', 1); |
| 54 | -define('HDOM_QUOTE_NO', 3); |
|
| 55 | -define('HDOM_INFO_BEGIN', 0); |
|
| 56 | -define('HDOM_INFO_END', 1); |
|
| 57 | -define('HDOM_INFO_QUOTE', 2); |
|
| 58 | -define('HDOM_INFO_SPACE', 3); |
|
| 59 | -define('HDOM_INFO_TEXT', 4); |
|
| 60 | -define('HDOM_INFO_INNER', 5); |
|
| 61 | -define('HDOM_INFO_OUTER', 6); |
|
| 62 | -define('HDOM_INFO_ENDSPACE',7); |
|
| 54 | +define('HDOM_QUOTE_NO', 3); |
|
| 55 | +define('HDOM_INFO_BEGIN', 0); |
|
| 56 | +define('HDOM_INFO_END', 1); |
|
| 57 | +define('HDOM_INFO_QUOTE', 2); |
|
| 58 | +define('HDOM_INFO_SPACE', 3); |
|
| 59 | +define('HDOM_INFO_TEXT', 4); |
|
| 60 | +define('HDOM_INFO_INNER', 5); |
|
| 61 | +define('HDOM_INFO_OUTER', 6); |
|
| 62 | +define('HDOM_INFO_ENDSPACE', 7); |
|
| 63 | 63 | define('DEFAULT_TARGET_CHARSET', 'UTF-8'); |
| 64 | 64 | define('DEFAULT_BR_TEXT', "\r\n"); |
| 65 | 65 | define('DEFAULT_SPAN_TEXT', " "); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | // ----------------------------------------------------------------------------- |
| 69 | 69 | // get html dom from file |
| 70 | 70 | // $maxlen is defined in the code as PHP_STREAM_COPY_ALL which is defined as -1. |
| 71 | -function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) |
|
| 71 | +function file_get_html($url, $use_include_path = false, $context = null, $offset = -1, $maxLen = -1, $lowercase = true, $forceTagsClosed = true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) |
|
| 72 | 72 | { |
| 73 | 73 | // We DO force the tags to be terminated. |
| 74 | 74 | $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // get html dom from string |
| 89 | -function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) |
|
| 89 | +function str_get_html($str, $lowercase = true, $forceTagsClosed = true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) |
|
| 90 | 90 | { |
| 91 | 91 | $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText); |
| 92 | 92 | if (empty($str) || strlen($str) > MAX_FILE_SIZE) |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // dump html dom tree |
| 102 | -function dump_html_tree($node, $show_attr=true, $deep=0) |
|
| 102 | +function dump_html_tree($node, $show_attr = true, $deep = 0) |
|
| 103 | 103 | { |
| 104 | 104 | $node->dump($node); |
| 105 | 105 | } |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // dump node's tree |
| 154 | - function dump($show_attr=true, $deep=0) |
|
| 154 | + function dump($show_attr = true, $deep = 0) |
|
| 155 | 155 | { |
| 156 | 156 | $lead = str_repeat(' ', $deep); |
| 157 | 157 | |
| 158 | 158 | echo $lead.$this->tag; |
| 159 | - if ($show_attr && count($this->attr)>0) |
|
| 159 | + if ($show_attr && count($this->attr) > 0) |
|
| 160 | 160 | { |
| 161 | 161 | echo '('; |
| 162 | 162 | foreach ($this->attr as $k=>$v) |
@@ -169,18 +169,18 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | foreach ($this->nodes as $c) |
| 171 | 171 | { |
| 172 | - $c->dump($show_attr, $deep+1); |
|
| 172 | + $c->dump($show_attr, $deep + 1); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
| 178 | 178 | // Debugging function to dump a single dom node with a bunch of information about it. |
| 179 | - function dump_node($echo=true) |
|
| 179 | + function dump_node($echo = true) |
|
| 180 | 180 | { |
| 181 | 181 | |
| 182 | 182 | $string = $this->tag; |
| 183 | - if (count($this->attr)>0) |
|
| 183 | + if (count($this->attr) > 0) |
|
| 184 | 184 | { |
| 185 | 185 | $string .= '('; |
| 186 | 186 | foreach ($this->attr as $k=>$v) |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | $string .= ')'; |
| 191 | 191 | } |
| 192 | - if (count($this->_)>0) |
|
| 192 | + if (count($this->_) > 0) |
|
| 193 | 193 | { |
| 194 | 194 | $string .= ' $_ ('; |
| 195 | 195 | foreach ($this->_ as $k=>$v) |
@@ -211,22 +211,22 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | if (isset($this->text)) |
| 213 | 213 | { |
| 214 | - $string .= " text: (" . $this->text . ")"; |
|
| 214 | + $string .= " text: (".$this->text.")"; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | $string .= " HDOM_INNER_INFO: '"; |
| 218 | 218 | if (isset($node->_[HDOM_INFO_INNER])) |
| 219 | 219 | { |
| 220 | - $string .= $node->_[HDOM_INFO_INNER] . "'"; |
|
| 220 | + $string .= $node->_[HDOM_INFO_INNER]."'"; |
|
| 221 | 221 | } |
| 222 | 222 | else |
| 223 | 223 | { |
| 224 | 224 | $string .= ' NULL '; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $string .= " children: " . count($this->children); |
|
| 228 | - $string .= " nodes: " . count($this->nodes); |
|
| 229 | - $string .= " tag_start: " . $this->tag_start; |
|
| 227 | + $string .= " children: ".count($this->children); |
|
| 228 | + $string .= " nodes: ".count($this->nodes); |
|
| 229 | + $string .= " tag_start: ".$this->tag_start; |
|
| 230 | 230 | $string .= "\n"; |
| 231 | 231 | |
| 232 | 232 | if ($echo) |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | // returns the parent of node |
| 244 | 244 | // If a node is passed in, it will reset the parent of the current node to that one. |
| 245 | - function parent($parent=null) |
|
| 245 | + function parent($parent = null) |
|
| 246 | 246 | { |
| 247 | 247 | // I am SURE that this doesn't work properly. |
| 248 | 248 | // It fails to unset the current node from it's current parents nodes or children list first. |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | // returns children of node |
| 266 | - function children($idx=-1) |
|
| 266 | + function children($idx = -1) |
|
| 267 | 267 | { |
| 268 | - if ($idx===-1) |
|
| 268 | + if ($idx === -1) |
|
| 269 | 269 | { |
| 270 | 270 | return $this->children; |
| 271 | 271 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | // returns the first child of node |
| 280 | 280 | function first_child() |
| 281 | 281 | { |
| 282 | - if (count($this->children)>0) |
|
| 282 | + if (count($this->children) > 0) |
|
| 283 | 283 | { |
| 284 | 284 | return $this->children[0]; |
| 285 | 285 | } |
@@ -289,9 +289,9 @@ discard block |
||
| 289 | 289 | // returns the last child of node |
| 290 | 290 | function last_child() |
| 291 | 291 | { |
| 292 | - if (($count=count($this->children))>0) |
|
| 292 | + if (($count = count($this->children)) > 0) |
|
| 293 | 293 | { |
| 294 | - return $this->children[$count-1]; |
|
| 294 | + return $this->children[$count - 1]; |
|
| 295 | 295 | } |
| 296 | 296 | return null; |
| 297 | 297 | } |
@@ -299,18 +299,18 @@ discard block |
||
| 299 | 299 | // returns the next sibling of node |
| 300 | 300 | function next_sibling() |
| 301 | 301 | { |
| 302 | - if ($this->parent===null) |
|
| 302 | + if ($this->parent === null) |
|
| 303 | 303 | { |
| 304 | 304 | return null; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | $idx = 0; |
| 308 | 308 | $count = count($this->parent->children); |
| 309 | - while ($idx<$count && $this!==$this->parent->children[$idx]) |
|
| 309 | + while ($idx < $count && $this !== $this->parent->children[$idx]) |
|
| 310 | 310 | { |
| 311 | 311 | ++$idx; |
| 312 | 312 | } |
| 313 | - if (++$idx>=$count) |
|
| 313 | + if (++$idx >= $count) |
|
| 314 | 314 | { |
| 315 | 315 | return null; |
| 316 | 316 | } |
@@ -320,12 +320,12 @@ discard block |
||
| 320 | 320 | // returns the previous sibling of node |
| 321 | 321 | function prev_sibling() |
| 322 | 322 | { |
| 323 | - if ($this->parent===null) return null; |
|
| 323 | + if ($this->parent === null) return null; |
|
| 324 | 324 | $idx = 0; |
| 325 | 325 | $count = count($this->parent->children); |
| 326 | - while ($idx<$count && $this!==$this->parent->children[$idx]) |
|
| 326 | + while ($idx < $count && $this !== $this->parent->children[$idx]) |
|
| 327 | 327 | ++$idx; |
| 328 | - if (--$idx<0) return null; |
|
| 328 | + if (--$idx < 0) return null; |
|
| 329 | 329 | return $this->parent->children[$idx]; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | while (!is_null($returnDom)) |
| 342 | 342 | { |
| 343 | - if (is_object($debug_object)) { $debug_object->debug_log(2, "Current tag is: " . $returnDom->tag); } |
|
| 343 | + if (is_object($debug_object)) { $debug_object->debug_log(2, "Current tag is: ".$returnDom->tag); } |
|
| 344 | 344 | |
| 345 | 345 | if ($returnDom->tag == $tag) |
| 346 | 346 | { |
@@ -374,16 +374,16 @@ discard block |
||
| 374 | 374 | { |
| 375 | 375 | if (!empty($this->text)) |
| 376 | 376 | { |
| 377 | - $text = " with text: " . $this->text; |
|
| 377 | + $text = " with text: ".$this->text; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | - $debug_object->debug_log(1, 'Innertext of tag: ' . $this->tag . $text); |
|
| 380 | + $debug_object->debug_log(1, 'Innertext of tag: '.$this->tag.$text); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if ($this->tag==='root') return $this->innertext(); |
|
| 383 | + if ($this->tag === 'root') return $this->innertext(); |
|
| 384 | 384 | |
| 385 | 385 | // trigger callback |
| 386 | - if ($this->dom && $this->dom->callback!==null) |
|
| 386 | + if ($this->dom && $this->dom->callback !== null) |
|
| 387 | 387 | { |
| 388 | 388 | call_user_func_array($this->dom->callback, array($this)); |
| 389 | 389 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // render end tag |
| 421 | - if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0) |
|
| 421 | + if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END] != 0) |
|
| 422 | 422 | $ret .= '</'.$this->tag.'>'; |
| 423 | 423 | return $ret; |
| 424 | 424 | } |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | case HDOM_TYPE_COMMENT: return ''; |
| 434 | 434 | case HDOM_TYPE_UNKNOWN: return ''; |
| 435 | 435 | } |
| 436 | - if (strcasecmp($this->tag, 'script')===0) return ''; |
|
| 437 | - if (strcasecmp($this->tag, 'style')===0) return ''; |
|
| 436 | + if (strcasecmp($this->tag, 'script') === 0) return ''; |
|
| 437 | + if (strcasecmp($this->tag, 'style') === 0) return ''; |
|
| 438 | 438 | |
| 439 | 439 | $ret = ''; |
| 440 | 440 | // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL. |
@@ -480,12 +480,12 @@ discard block |
||
| 480 | 480 | ++$i; |
| 481 | 481 | |
| 482 | 482 | // skip removed attribute |
| 483 | - if ($val===null || $val===false) |
|
| 483 | + if ($val === null || $val === false) |
|
| 484 | 484 | continue; |
| 485 | 485 | |
| 486 | 486 | $ret .= $this->_[HDOM_INFO_SPACE][$i][0]; |
| 487 | 487 | //no value attr: nowrap, checked selected... |
| 488 | - if ($val===true) |
|
| 488 | + if ($val === true) |
|
| 489 | 489 | $ret .= $key; |
| 490 | 490 | else { |
| 491 | 491 | switch ($this->_[HDOM_INFO_QUOTE][$i]) |
@@ -498,34 +498,34 @@ discard block |
||
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | $ret = $this->dom->restore_noise($ret); |
| 501 | - return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>'; |
|
| 501 | + return $ret.$this->_[HDOM_INFO_ENDSPACE].'>'; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | // find elements by css selector |
| 505 | 505 | //PaperG - added ability for find to lowercase the value of the selector. |
| 506 | - function find($selector, $idx=null, $lowercase=false) |
|
| 506 | + function find($selector, $idx = null, $lowercase = false) |
|
| 507 | 507 | { |
| 508 | 508 | $selectors = $this->parse_selector($selector); |
| 509 | - if (($count=count($selectors))===0) return array(); |
|
| 509 | + if (($count = count($selectors)) === 0) return array(); |
|
| 510 | 510 | $found_keys = array(); |
| 511 | 511 | |
| 512 | 512 | // find each selector |
| 513 | - for ($c=0; $c<$count; ++$c) |
|
| 513 | + for ($c = 0; $c < $count; ++$c) |
|
| 514 | 514 | { |
| 515 | 515 | // The change on the below line was documented on the sourceforge code tracker id 2788009 |
| 516 | 516 | // used to be: if (($levle=count($selectors[0]))===0) return array(); |
| 517 | - if (($levle=count($selectors[$c]))===0) return array(); |
|
| 517 | + if (($levle = count($selectors[$c])) === 0) return array(); |
|
| 518 | 518 | if (!isset($this->_[HDOM_INFO_BEGIN])) return array(); |
| 519 | 519 | |
| 520 | 520 | $head = array($this->_[HDOM_INFO_BEGIN]=>1); |
| 521 | 521 | |
| 522 | 522 | // handle descendant selectors, no recursive! |
| 523 | - for ($l=0; $l<$levle; ++$l) |
|
| 523 | + for ($l = 0; $l < $levle; ++$l) |
|
| 524 | 524 | { |
| 525 | 525 | $ret = array(); |
| 526 | 526 | foreach ($head as $k=>$v) |
| 527 | 527 | { |
| 528 | - $n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k]; |
|
| 528 | + $n = ($k === -1) ? $this->dom->root : $this->dom->nodes[$k]; |
|
| 529 | 529 | //PaperG - Pass this optional parameter on to the seek function. |
| 530 | 530 | $n->seek($selectors[$c][$l], $ret, $lowercase); |
| 531 | 531 | } |
@@ -550,13 +550,13 @@ discard block |
||
| 550 | 550 | |
| 551 | 551 | // return nth-element or array |
| 552 | 552 | if (is_null($idx)) return $found; |
| 553 | - else if ($idx<0) $idx = count($found) + $idx; |
|
| 553 | + else if ($idx < 0) $idx = count($found) + $idx; |
|
| 554 | 554 | return (isset($found[$idx])) ? $found[$idx] : null; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | // seek for given conditions |
| 558 | 558 | // PaperG - added parameter to allow for case insensitive testing of the value of a selector. |
| 559 | - protected function seek($selector, &$ret, $lowercase=false) |
|
| 559 | + protected function seek($selector, &$ret, $lowercase = false) |
|
| 560 | 560 | { |
| 561 | 561 | global $debug_object; |
| 562 | 562 | if (is_object($debug_object)) { $debug_object->debug_log_entry(1); } |
@@ -569,8 +569,8 @@ discard block |
||
| 569 | 569 | $count = 0; |
| 570 | 570 | foreach ($this->children as $c) |
| 571 | 571 | { |
| 572 | - if ($tag==='*' || $tag===$c->tag) { |
|
| 573 | - if (++$count==$key) { |
|
| 572 | + if ($tag === '*' || $tag === $c->tag) { |
|
| 573 | + if (++$count == $key) { |
|
| 574 | 574 | $ret[$c->_[HDOM_INFO_BEGIN]] = 1; |
| 575 | 575 | return; |
| 576 | 576 | } |
@@ -580,38 +580,38 @@ discard block |
||
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0; |
| 583 | - if ($end==0) { |
|
| 583 | + if ($end == 0) { |
|
| 584 | 584 | $parent = $this->parent; |
| 585 | - while (!isset($parent->_[HDOM_INFO_END]) && $parent!==null) { |
|
| 585 | + while (!isset($parent->_[HDOM_INFO_END]) && $parent !== null) { |
|
| 586 | 586 | $end -= 1; |
| 587 | 587 | $parent = $parent->parent; |
| 588 | 588 | } |
| 589 | 589 | $end += $parent->_[HDOM_INFO_END]; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - for ($i=$this->_[HDOM_INFO_BEGIN]+1; $i<$end; ++$i) { |
|
| 592 | + for ($i = $this->_[HDOM_INFO_BEGIN] + 1; $i < $end; ++$i) { |
|
| 593 | 593 | $node = $this->dom->nodes[$i]; |
| 594 | 594 | |
| 595 | 595 | $pass = true; |
| 596 | 596 | |
| 597 | - if ($tag==='*' && !$key) { |
|
| 597 | + if ($tag === '*' && !$key) { |
|
| 598 | 598 | if (in_array($node, $this->children, true)) |
| 599 | 599 | $ret[$i] = 1; |
| 600 | 600 | continue; |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | // compare tag |
| 604 | - if ($tag && $tag!=$node->tag && $tag!=='*') {$pass=false;} |
|
| 604 | + if ($tag && $tag != $node->tag && $tag !== '*') {$pass = false; } |
|
| 605 | 605 | // compare key |
| 606 | 606 | if ($pass && $key) { |
| 607 | 607 | if ($no_key) { |
| 608 | - if (isset($node->attr[$key])) $pass=false; |
|
| 608 | + if (isset($node->attr[$key])) $pass = false; |
|
| 609 | 609 | } else { |
| 610 | - if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false; |
|
| 610 | + if (($key != "plaintext") && !isset($node->attr[$key])) $pass = false; |
|
| 611 | 611 | } |
| 612 | 612 | } |
| 613 | 613 | // compare value |
| 614 | - if ($pass && $key && $val && $val!=='*') { |
|
| 614 | + if ($pass && $key && $val && $val !== '*') { |
|
| 615 | 615 | // If they have told us that this is a "plaintext" search then we want the plaintext of the node - right? |
| 616 | 616 | if ($key == "plaintext") { |
| 617 | 617 | // $node->plaintext actually returns $node->text(); |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | // this is a normal search, we want the value of that attribute of the tag. |
| 621 | 621 | $nodeKeyValue = $node->attr[$key]; |
| 622 | 622 | } |
| 623 | - if (is_object($debug_object)) {$debug_object->debug_log(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue);} |
|
| 623 | + if (is_object($debug_object)) {$debug_object->debug_log(2, "testing node: ".$node->tag." for attribute: ".$key.$exp.$val." where nodes value is: ".$nodeKeyValue); } |
|
| 624 | 624 | |
| 625 | 625 | //PaperG - If lowercase is set, do a case insensitive test of the value of the selector. |
| 626 | 626 | if ($lowercase) { |
@@ -628,11 +628,11 @@ discard block |
||
| 628 | 628 | } else { |
| 629 | 629 | $check = $this->match($exp, $val, $nodeKeyValue); |
| 630 | 630 | } |
| 631 | - if (is_object($debug_object)) {$debug_object->debug_log(2, "after match: " . ($check ? "true" : "false"));} |
|
| 631 | + if (is_object($debug_object)) {$debug_object->debug_log(2, "after match: ".($check ? "true" : "false")); } |
|
| 632 | 632 | |
| 633 | 633 | // handle multiple class |
| 634 | - if (!$check && strcasecmp($key, 'class')===0) { |
|
| 635 | - foreach (explode(' ',$node->attr[$key]) as $k) { |
|
| 634 | + if (!$check && strcasecmp($key, 'class') === 0) { |
|
| 635 | + foreach (explode(' ', $node->attr[$key]) as $k) { |
|
| 636 | 636 | // Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form. |
| 637 | 637 | if (!empty($k)) { |
| 638 | 638 | if ($lowercase) { |
@@ -650,24 +650,24 @@ discard block |
||
| 650 | 650 | unset($node); |
| 651 | 651 | } |
| 652 | 652 | // It's passed by reference so this is actually what this function returns. |
| 653 | - if (is_object($debug_object)) {$debug_object->debug_log(1, "EXIT - ret: ", $ret);} |
|
| 653 | + if (is_object($debug_object)) {$debug_object->debug_log(1, "EXIT - ret: ", $ret); } |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | protected function match($exp, $pattern, $value) { |
| 657 | 657 | global $debug_object; |
| 658 | - if (is_object($debug_object)) {$debug_object->debug_log_entry(1);} |
|
| 658 | + if (is_object($debug_object)) {$debug_object->debug_log_entry(1); } |
|
| 659 | 659 | |
| 660 | 660 | switch ($exp) { |
| 661 | 661 | case '=': |
| 662 | - return ($value===$pattern); |
|
| 662 | + return ($value === $pattern); |
|
| 663 | 663 | case '!=': |
| 664 | - return ($value!==$pattern); |
|
| 664 | + return ($value !== $pattern); |
|
| 665 | 665 | case '^=': |
| 666 | - return preg_match("/^".preg_quote($pattern,'/')."/", $value); |
|
| 666 | + return preg_match("/^".preg_quote($pattern, '/')."/", $value); |
|
| 667 | 667 | case '$=': |
| 668 | - return preg_match("/".preg_quote($pattern,'/')."$/", $value); |
|
| 668 | + return preg_match("/".preg_quote($pattern, '/')."$/", $value); |
|
| 669 | 669 | case '*=': |
| 670 | - if ($pattern[0]=='/') { |
|
| 670 | + if ($pattern[0] == '/') { |
|
| 671 | 671 | return preg_match($pattern, $value); |
| 672 | 672 | } |
| 673 | 673 | return preg_match("/".$pattern."/i", $value); |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | |
| 678 | 678 | protected function parse_selector($selector_string) { |
| 679 | 679 | global $debug_object; |
| 680 | - if (is_object($debug_object)) {$debug_object->debug_log_entry(1);} |
|
| 680 | + if (is_object($debug_object)) {$debug_object->debug_log_entry(1); } |
|
| 681 | 681 | |
| 682 | 682 | // pattern of CSS selectors, modified from mootools |
| 683 | 683 | // Paperg: Add the colon to the attrbute, so that it properly finds <tag attr:ibute="something" > like google does. |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | // $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; |
| 689 | 689 | $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; |
| 690 | 690 | preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER); |
| 691 | - if (is_object($debug_object)) {$debug_object->debug_log(2, "Matches Array: ", $matches);} |
|
| 691 | + if (is_object($debug_object)) {$debug_object->debug_log(2, "Matches Array: ", $matches); } |
|
| 692 | 692 | |
| 693 | 693 | $selectors = array(); |
| 694 | 694 | $result = array(); |
@@ -696,29 +696,29 @@ discard block |
||
| 696 | 696 | |
| 697 | 697 | foreach ($matches as $m) { |
| 698 | 698 | $m[0] = trim($m[0]); |
| 699 | - if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue; |
|
| 699 | + if ($m[0] === '' || $m[0] === '/' || $m[0] === '//') continue; |
|
| 700 | 700 | // for browser generated xpath |
| 701 | - if ($m[1]==='tbody') continue; |
|
| 701 | + if ($m[1] === 'tbody') continue; |
|
| 702 | 702 | |
| 703 | 703 | list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); |
| 704 | - if (!empty($m[2])) {$key='id'; $val=$m[2];} |
|
| 705 | - if (!empty($m[3])) {$key='class'; $val=$m[3];} |
|
| 706 | - if (!empty($m[4])) {$key=$m[4];} |
|
| 707 | - if (!empty($m[5])) {$exp=$m[5];} |
|
| 708 | - if (!empty($m[6])) {$val=$m[6];} |
|
| 704 | + if (!empty($m[2])) {$key = 'id'; $val = $m[2]; } |
|
| 705 | + if (!empty($m[3])) {$key = 'class'; $val = $m[3]; } |
|
| 706 | + if (!empty($m[4])) {$key = $m[4]; } |
|
| 707 | + if (!empty($m[5])) {$exp = $m[5]; } |
|
| 708 | + if (!empty($m[6])) {$val = $m[6]; } |
|
| 709 | 709 | |
| 710 | 710 | // convert to lowercase |
| 711 | - if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);} |
|
| 711 | + if ($this->dom->lowercase) {$tag = strtolower($tag); $key = strtolower($key); } |
|
| 712 | 712 | //elements that do NOT have the specified attribute |
| 713 | - if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;} |
|
| 713 | + if (isset($key[0]) && $key[0] === '!') {$key = substr($key, 1); $no_key = true; } |
|
| 714 | 714 | |
| 715 | 715 | $result[] = array($tag, $key, $val, $exp, $no_key); |
| 716 | - if (trim($m[7])===',') { |
|
| 716 | + if (trim($m[7]) === ',') { |
|
| 717 | 717 | $selectors[] = $result; |
| 718 | 718 | $result = array(); |
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | - if (count($result)>0) |
|
| 721 | + if (count($result) > 0) |
|
| 722 | 722 | $selectors[] = $result; |
| 723 | 723 | return $selectors; |
| 724 | 724 | } |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | function __set($name, $value) |
| 743 | 743 | { |
| 744 | 744 | global $debug_object; |
| 745 | - if (is_object($debug_object)) {$debug_object->debug_log_entry(1);} |
|
| 745 | + if (is_object($debug_object)) {$debug_object->debug_log_entry(1); } |
|
| 746 | 746 | |
| 747 | 747 | switch ($name) |
| 748 | 748 | { |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | function convert_text($text) |
| 781 | 781 | { |
| 782 | 782 | global $debug_object; |
| 783 | - if (is_object($debug_object)) {$debug_object->debug_log_entry(1);} |
|
| 783 | + if (is_object($debug_object)) {$debug_object->debug_log_entry(1); } |
|
| 784 | 784 | |
| 785 | 785 | $converted_text = $text; |
| 786 | 786 | |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | $sourceCharset = strtoupper($this->dom->_charset); |
| 793 | 793 | $targetCharset = strtoupper($this->dom->_target_charset); |
| 794 | 794 | } |
| 795 | - if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);} |
|
| 795 | + if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: ".$sourceCharset." target charaset: ".$targetCharset); } |
|
| 796 | 796 | |
| 797 | 797 | if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0)) |
| 798 | 798 | { |
@@ -831,27 +831,27 @@ discard block |
||
| 831 | 831 | */ |
| 832 | 832 | static function is_utf8($str) |
| 833 | 833 | { |
| 834 | - $c=0; $b=0; |
|
| 835 | - $bits=0; |
|
| 836 | - $len=strlen($str); |
|
| 837 | - for($i=0; $i<$len; $i++) |
|
| 834 | + $c = 0; $b = 0; |
|
| 835 | + $bits = 0; |
|
| 836 | + $len = strlen($str); |
|
| 837 | + for ($i = 0; $i < $len; $i++) |
|
| 838 | 838 | { |
| 839 | - $c=ord($str[$i]); |
|
| 840 | - if($c > 128) |
|
| 839 | + $c = ord($str[$i]); |
|
| 840 | + if ($c > 128) |
|
| 841 | 841 | { |
| 842 | - if(($c >= 254)) return false; |
|
| 843 | - elseif($c >= 252) $bits=6; |
|
| 844 | - elseif($c >= 248) $bits=5; |
|
| 845 | - elseif($c >= 240) $bits=4; |
|
| 846 | - elseif($c >= 224) $bits=3; |
|
| 847 | - elseif($c >= 192) $bits=2; |
|
| 842 | + if (($c >= 254)) return false; |
|
| 843 | + elseif ($c >= 252) $bits = 6; |
|
| 844 | + elseif ($c >= 248) $bits = 5; |
|
| 845 | + elseif ($c >= 240) $bits = 4; |
|
| 846 | + elseif ($c >= 224) $bits = 3; |
|
| 847 | + elseif ($c >= 192) $bits = 2; |
|
| 848 | 848 | else return false; |
| 849 | - if(($i+$bits) > $len) return false; |
|
| 850 | - while($bits > 1) |
|
| 849 | + if (($i + $bits) > $len) return false; |
|
| 850 | + while ($bits > 1) |
|
| 851 | 851 | { |
| 852 | 852 | $i++; |
| 853 | - $b=ord($str[$i]); |
|
| 854 | - if($b < 128 || $b > 191) return false; |
|
| 853 | + $b = ord($str[$i]); |
|
| 854 | + if ($b < 128 || $b > 191) return false; |
|
| 855 | 855 | $bits--; |
| 856 | 856 | } |
| 857 | 857 | } |
@@ -955,24 +955,24 @@ discard block |
||
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | // camel naming conventions |
| 958 | - function getAllAttributes() {return $this->attr;} |
|
| 959 | - function getAttribute($name) {return $this->__get($name);} |
|
| 960 | - function setAttribute($name, $value) {$this->__set($name, $value);} |
|
| 961 | - function hasAttribute($name) {return $this->__isset($name);} |
|
| 962 | - function removeAttribute($name) {$this->__set($name, null);} |
|
| 963 | - function getElementById($id) {return $this->find("#$id", 0);} |
|
| 964 | - function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);} |
|
| 965 | - function getElementByTagName($name) {return $this->find($name, 0);} |
|
| 966 | - function getElementsByTagName($name, $idx=null) {return $this->find($name, $idx);} |
|
| 967 | - function parentNode() {return $this->parent();} |
|
| 968 | - function childNodes($idx=-1) {return $this->children($idx);} |
|
| 969 | - function firstChild() {return $this->first_child();} |
|
| 970 | - function lastChild() {return $this->last_child();} |
|
| 971 | - function nextSibling() {return $this->next_sibling();} |
|
| 972 | - function previousSibling() {return $this->prev_sibling();} |
|
| 973 | - function hasChildNodes() {return $this->has_child();} |
|
| 974 | - function nodeName() {return $this->tag;} |
|
| 975 | - function appendChild($node) {$node->parent($this); return $node;} |
|
| 958 | + function getAllAttributes() {return $this->attr; } |
|
| 959 | + function getAttribute($name) {return $this->__get($name); } |
|
| 960 | + function setAttribute($name, $value) {$this->__set($name, $value); } |
|
| 961 | + function hasAttribute($name) {return $this->__isset($name); } |
|
| 962 | + function removeAttribute($name) {$this->__set($name, null); } |
|
| 963 | + function getElementById($id) {return $this->find("#$id", 0); } |
|
| 964 | + function getElementsById($id, $idx = null) {return $this->find("#$id", $idx); } |
|
| 965 | + function getElementByTagName($name) {return $this->find($name, 0); } |
|
| 966 | + function getElementsByTagName($name, $idx = null) {return $this->find($name, $idx); } |
|
| 967 | + function parentNode() {return $this->parent(); } |
|
| 968 | + function childNodes($idx = -1) {return $this->children($idx); } |
|
| 969 | + function firstChild() {return $this->first_child(); } |
|
| 970 | + function lastChild() {return $this->last_child(); } |
|
| 971 | + function nextSibling() {return $this->next_sibling(); } |
|
| 972 | + function previousSibling() {return $this->prev_sibling(); } |
|
| 973 | + function hasChildNodes() {return $this->has_child(); } |
|
| 974 | + function nodeName() {return $this->tag; } |
|
| 975 | + function appendChild($node) {$node->parent($this); return $node; } |
|
| 976 | 976 | |
| 977 | 977 | } |
| 978 | 978 | |
@@ -1028,11 +1028,11 @@ discard block |
||
| 1028 | 1028 | 'option'=>array('option'=>1), |
| 1029 | 1029 | ); |
| 1030 | 1030 | |
| 1031 | - function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) |
|
| 1031 | + function __construct($str = null, $lowercase = true, $forceTagsClosed = true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) |
|
| 1032 | 1032 | { |
| 1033 | 1033 | if ($str) |
| 1034 | 1034 | { |
| 1035 | - if (preg_match("/^http:\/\//i",$str) || is_file($str)) |
|
| 1035 | + if (preg_match("/^http:\/\//i", $str) || is_file($str)) |
|
| 1036 | 1036 | { |
| 1037 | 1037 | $this->load_file($str); |
| 1038 | 1038 | } |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | } |
| 1044 | 1044 | // Forcing tags to be closed implies that we don't trust the html, but it can lead to parsing errors if we SHOULD trust the html. |
| 1045 | 1045 | if (!$forceTagsClosed) { |
| 1046 | - $this->optional_closing_array=array(); |
|
| 1046 | + $this->optional_closing_array = array(); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | $this->_target_charset = $target_charset; |
| 1049 | 1049 | } |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | 1056 | // load html from string |
| 1057 | - function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) |
|
| 1057 | + function load($str, $lowercase = true, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) |
|
| 1058 | 1058 | { |
| 1059 | 1059 | global $debug_object; |
| 1060 | 1060 | |
@@ -1096,7 +1096,7 @@ discard block |
||
| 1096 | 1096 | $args = func_get_args(); |
| 1097 | 1097 | $this->load(call_user_func_array('file_get_contents', $args), true); |
| 1098 | 1098 | // Throw an error if we can't properly load the dom. |
| 1099 | - if (($error=error_get_last())!==null) { |
|
| 1099 | + if (($error = error_get_last()) !== null) { |
|
| 1100 | 1100 | $this->clear(); |
| 1101 | 1101 | return false; |
| 1102 | 1102 | } |
@@ -1115,16 +1115,16 @@ discard block |
||
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | // save dom as string |
| 1118 | - function save($filepath='') |
|
| 1118 | + function save($filepath = '') |
|
| 1119 | 1119 | { |
| 1120 | 1120 | $ret = $this->root->innertext(); |
| 1121 | - if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX); |
|
| 1121 | + if ($filepath !== '') file_put_contents($filepath, $ret, LOCK_EX); |
|
| 1122 | 1122 | return $ret; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | // find dom node by css selector |
| 1126 | 1126 | // Paperg - allow us to specify that we want case insensitive testing of the value of the selector. |
| 1127 | - function find($selector, $idx=null, $lowercase=false) |
|
| 1127 | + function find($selector, $idx = null, $lowercase = false) |
|
| 1128 | 1128 | { |
| 1129 | 1129 | return $this->root->find($selector, $idx, $lowercase); |
| 1130 | 1130 | } |
@@ -1132,22 +1132,22 @@ discard block |
||
| 1132 | 1132 | // clean up memory due to php5 circular references memory leak... |
| 1133 | 1133 | function clear() |
| 1134 | 1134 | { |
| 1135 | - foreach ($this->nodes as $n) {$n->clear(); $n = null;} |
|
| 1135 | + foreach ($this->nodes as $n) {$n->clear(); $n = null; } |
|
| 1136 | 1136 | // This add next line is documented in the sourceforge repository. 2977248 as a fix for ongoing memory leaks that occur even with the use of clear. |
| 1137 | - if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null;} |
|
| 1138 | - if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);} |
|
| 1139 | - if (isset($this->root)) {$this->root->clear(); unset($this->root);} |
|
| 1137 | + if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null; } |
|
| 1138 | + if (isset($this->parent)) {$this->parent->clear(); unset($this->parent); } |
|
| 1139 | + if (isset($this->root)) {$this->root->clear(); unset($this->root); } |
|
| 1140 | 1140 | unset($this->doc); |
| 1141 | 1141 | unset($this->noise); |
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | - function dump($show_attr=true) |
|
| 1144 | + function dump($show_attr = true) |
|
| 1145 | 1145 | { |
| 1146 | 1146 | $this->root->dump($show_attr); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | // prepare HTML data and init everything |
| 1150 | - protected function prepare($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) |
|
| 1150 | + protected function prepare($str, $lowercase = true, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT) |
|
| 1151 | 1151 | { |
| 1152 | 1152 | $this->clear(); |
| 1153 | 1153 | |
@@ -1178,13 +1178,13 @@ discard block |
||
| 1178 | 1178 | $this->root->_[HDOM_INFO_BEGIN] = -1; |
| 1179 | 1179 | $this->root->nodetype = HDOM_TYPE_ROOT; |
| 1180 | 1180 | $this->parent = $this->root; |
| 1181 | - if ($this->size>0) $this->char = $this->doc[0]; |
|
| 1181 | + if ($this->size > 0) $this->char = $this->doc[0]; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | // parse html content |
| 1185 | 1185 | protected function parse() |
| 1186 | 1186 | { |
| 1187 | - if (($s = $this->copy_until_char('<'))==='') |
|
| 1187 | + if (($s = $this->copy_until_char('<')) === '') |
|
| 1188 | 1188 | { |
| 1189 | 1189 | return $this->read_tag(); |
| 1190 | 1190 | } |
@@ -1213,18 +1213,18 @@ discard block |
||
| 1213 | 1213 | if ($success) |
| 1214 | 1214 | { |
| 1215 | 1215 | $charset = $matches[1]; |
| 1216 | - if (is_object($debug_object)) {$debug_object->debug_log(2, 'header content-type found charset of: ' . $charset);} |
|
| 1216 | + if (is_object($debug_object)) {$debug_object->debug_log(2, 'header content-type found charset of: '.$charset); } |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | if (empty($charset)) |
| 1222 | 1222 | { |
| 1223 | - $el = $this->root->find('meta[http-equiv=Content-Type]',0, true); |
|
| 1223 | + $el = $this->root->find('meta[http-equiv=Content-Type]', 0, true); |
|
| 1224 | 1224 | if (!empty($el)) |
| 1225 | 1225 | { |
| 1226 | 1226 | $fullvalue = $el->content; |
| 1227 | - if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag found' . $fullvalue);} |
|
| 1227 | + if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag found'.$fullvalue); } |
|
| 1228 | 1228 | |
| 1229 | 1229 | if (!empty($fullvalue)) |
| 1230 | 1230 | { |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | else |
| 1237 | 1237 | { |
| 1238 | 1238 | // If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1 |
| 1239 | - if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');} |
|
| 1239 | + if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.'); } |
|
| 1240 | 1240 | $charset = 'ISO-8859-1'; |
| 1241 | 1241 | } |
| 1242 | 1242 | } |
@@ -1251,14 +1251,14 @@ discard block |
||
| 1251 | 1251 | if (function_exists('mb_detect_encoding')) |
| 1252 | 1252 | { |
| 1253 | 1253 | // Have php try to detect the encoding from the text given to us. |
| 1254 | - $charset = mb_detect_encoding($this->root->plaintext . "ascii", $encoding_list = array( "UTF-8", "CP1252" ) ); |
|
| 1255 | - if (is_object($debug_object)) {$debug_object->debug_log(2, 'mb_detect found: ' . $charset);} |
|
| 1254 | + $charset = mb_detect_encoding($this->root->plaintext."ascii", $encoding_list = array("UTF-8", "CP1252")); |
|
| 1255 | + if (is_object($debug_object)) {$debug_object->debug_log(2, 'mb_detect found: '.$charset); } |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | // and if this doesn't work... then we need to just wrongheadedly assume it's UTF-8 so that we can move on - cause this will usually give us most of what we need... |
| 1259 | 1259 | if ($charset === false) |
| 1260 | 1260 | { |
| 1261 | - if (is_object($debug_object)) {$debug_object->debug_log(2, 'since mb_detect failed - using default of utf-8');} |
|
| 1261 | + if (is_object($debug_object)) {$debug_object->debug_log(2, 'since mb_detect failed - using default of utf-8'); } |
|
| 1262 | 1262 | $charset = 'UTF-8'; |
| 1263 | 1263 | } |
| 1264 | 1264 | } |
@@ -1266,11 +1266,11 @@ discard block |
||
| 1266 | 1266 | // Since CP1252 is a superset, if we get one of it's subsets, we want it instead. |
| 1267 | 1267 | if ((strtolower($charset) == strtolower('ISO-8859-1')) || (strtolower($charset) == strtolower('Latin1')) || (strtolower($charset) == strtolower('Latin-1'))) |
| 1268 | 1268 | { |
| 1269 | - if (is_object($debug_object)) {$debug_object->debug_log(2, 'replacing ' . $charset . ' with CP1252 as its a superset');} |
|
| 1269 | + if (is_object($debug_object)) {$debug_object->debug_log(2, 'replacing '.$charset.' with CP1252 as its a superset'); } |
|
| 1270 | 1270 | $charset = 'CP1252'; |
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | - if (is_object($debug_object)) {$debug_object->debug_log(1, 'EXIT - ' . $charset);} |
|
| 1273 | + if (is_object($debug_object)) {$debug_object->debug_log(1, 'EXIT - '.$charset); } |
|
| 1274 | 1274 | |
| 1275 | 1275 | return $this->_charset = $charset; |
| 1276 | 1276 | } |
@@ -1278,41 +1278,41 @@ discard block |
||
| 1278 | 1278 | // read tag info |
| 1279 | 1279 | protected function read_tag() |
| 1280 | 1280 | { |
| 1281 | - if ($this->char!=='<') |
|
| 1281 | + if ($this->char !== '<') |
|
| 1282 | 1282 | { |
| 1283 | 1283 | $this->root->_[HDOM_INFO_END] = $this->cursor; |
| 1284 | 1284 | return false; |
| 1285 | 1285 | } |
| 1286 | 1286 | $begin_tag_pos = $this->pos; |
| 1287 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1287 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1288 | 1288 | |
| 1289 | 1289 | // end tag |
| 1290 | - if ($this->char==='/') |
|
| 1290 | + if ($this->char === '/') |
|
| 1291 | 1291 | { |
| 1292 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1292 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1293 | 1293 | // This represents the change in the simple_html_dom trunk from revision 180 to 181. |
| 1294 | 1294 | // $this->skip($this->token_blank_t); |
| 1295 | 1295 | $this->skip($this->token_blank); |
| 1296 | 1296 | $tag = $this->copy_until_char('>'); |
| 1297 | 1297 | |
| 1298 | 1298 | // skip attributes in end tag |
| 1299 | - if (($pos = strpos($tag, ' '))!==false) |
|
| 1299 | + if (($pos = strpos($tag, ' ')) !== false) |
|
| 1300 | 1300 | $tag = substr($tag, 0, $pos); |
| 1301 | 1301 | |
| 1302 | 1302 | $parent_lower = strtolower($this->parent->tag); |
| 1303 | 1303 | $tag_lower = strtolower($tag); |
| 1304 | 1304 | |
| 1305 | - if ($parent_lower!==$tag_lower) |
|
| 1305 | + if ($parent_lower !== $tag_lower) |
|
| 1306 | 1306 | { |
| 1307 | 1307 | if (isset($this->optional_closing_tags[$parent_lower]) && isset($this->block_tags[$tag_lower])) |
| 1308 | 1308 | { |
| 1309 | 1309 | $this->parent->_[HDOM_INFO_END] = 0; |
| 1310 | 1310 | $org_parent = $this->parent; |
| 1311 | 1311 | |
| 1312 | - while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) |
|
| 1312 | + while (($this->parent->parent) && strtolower($this->parent->tag) !== $tag_lower) |
|
| 1313 | 1313 | $this->parent = $this->parent->parent; |
| 1314 | 1314 | |
| 1315 | - if (strtolower($this->parent->tag)!==$tag_lower) { |
|
| 1315 | + if (strtolower($this->parent->tag) !== $tag_lower) { |
|
| 1316 | 1316 | $this->parent = $org_parent; // restore origonal parent |
| 1317 | 1317 | if ($this->parent->parent) $this->parent = $this->parent->parent; |
| 1318 | 1318 | $this->parent->_[HDOM_INFO_END] = $this->cursor; |
@@ -1324,17 +1324,17 @@ discard block |
||
| 1324 | 1324 | $this->parent->_[HDOM_INFO_END] = 0; |
| 1325 | 1325 | $org_parent = $this->parent; |
| 1326 | 1326 | |
| 1327 | - while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) |
|
| 1327 | + while (($this->parent->parent) && strtolower($this->parent->tag) !== $tag_lower) |
|
| 1328 | 1328 | $this->parent = $this->parent->parent; |
| 1329 | 1329 | |
| 1330 | - if (strtolower($this->parent->tag)!==$tag_lower) |
|
| 1330 | + if (strtolower($this->parent->tag) !== $tag_lower) |
|
| 1331 | 1331 | { |
| 1332 | 1332 | $this->parent = $org_parent; // restore origonal parent |
| 1333 | 1333 | $this->parent->_[HDOM_INFO_END] = $this->cursor; |
| 1334 | 1334 | return $this->as_text_node($tag); |
| 1335 | 1335 | } |
| 1336 | 1336 | } |
| 1337 | - else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower) |
|
| 1337 | + else if (($this->parent->parent) && strtolower($this->parent->parent->tag) === $tag_lower) |
|
| 1338 | 1338 | { |
| 1339 | 1339 | $this->parent->_[HDOM_INFO_END] = 0; |
| 1340 | 1340 | $this->parent = $this->parent->parent; |
@@ -1346,7 +1346,7 @@ discard block |
||
| 1346 | 1346 | $this->parent->_[HDOM_INFO_END] = $this->cursor; |
| 1347 | 1347 | if ($this->parent->parent) $this->parent = $this->parent->parent; |
| 1348 | 1348 | |
| 1349 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1349 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1350 | 1350 | return true; |
| 1351 | 1351 | } |
| 1352 | 1352 | |
@@ -1357,25 +1357,25 @@ discard block |
||
| 1357 | 1357 | $node->tag_start = $begin_tag_pos; |
| 1358 | 1358 | |
| 1359 | 1359 | // doctype, cdata & comments... |
| 1360 | - if (isset($tag[0]) && $tag[0]==='!') { |
|
| 1361 | - $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until_char('>'); |
|
| 1360 | + if (isset($tag[0]) && $tag[0] === '!') { |
|
| 1361 | + $node->_[HDOM_INFO_TEXT] = '<'.$tag.$this->copy_until_char('>'); |
|
| 1362 | 1362 | |
| 1363 | - if (isset($tag[2]) && $tag[1]==='-' && $tag[2]==='-') { |
|
| 1363 | + if (isset($tag[2]) && $tag[1] === '-' && $tag[2] === '-') { |
|
| 1364 | 1364 | $node->nodetype = HDOM_TYPE_COMMENT; |
| 1365 | 1365 | $node->tag = 'comment'; |
| 1366 | 1366 | } else { |
| 1367 | 1367 | $node->nodetype = HDOM_TYPE_UNKNOWN; |
| 1368 | 1368 | $node->tag = 'unknown'; |
| 1369 | 1369 | } |
| 1370 | - if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>'; |
|
| 1370 | + if ($this->char === '>') $node->_[HDOM_INFO_TEXT] .= '>'; |
|
| 1371 | 1371 | $this->link_nodes($node, true); |
| 1372 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1372 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1373 | 1373 | return true; |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | // text |
| 1377 | - if ($pos=strpos($tag, '<')!==false) { |
|
| 1378 | - $tag = '<' . substr($tag, 0, -1); |
|
| 1377 | + if ($pos = strpos($tag, '<') !== false) { |
|
| 1378 | + $tag = '<'.substr($tag, 0, -1); |
|
| 1379 | 1379 | $node->_[HDOM_INFO_TEXT] = $tag; |
| 1380 | 1380 | $this->link_nodes($node, false); |
| 1381 | 1381 | $this->char = $this->doc[--$this->pos]; // prev |
@@ -1383,15 +1383,15 @@ discard block |
||
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | if (!preg_match("/^[\w-:]+$/", $tag)) { |
| 1386 | - $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>'); |
|
| 1387 | - if ($this->char==='<') { |
|
| 1386 | + $node->_[HDOM_INFO_TEXT] = '<'.$tag.$this->copy_until('<>'); |
|
| 1387 | + if ($this->char === '<') { |
|
| 1388 | 1388 | $this->link_nodes($node, false); |
| 1389 | 1389 | return true; |
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | - if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>'; |
|
| 1392 | + if ($this->char === '>') $node->_[HDOM_INFO_TEXT] .= '>'; |
|
| 1393 | 1393 | $this->link_nodes($node, false); |
| 1394 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1394 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1395 | 1395 | return true; |
| 1396 | 1396 | } |
| 1397 | 1397 | |
@@ -1401,7 +1401,7 @@ discard block |
||
| 1401 | 1401 | $node->tag = ($this->lowercase) ? $tag_lower : $tag; |
| 1402 | 1402 | |
| 1403 | 1403 | // handle optional closing tags |
| 1404 | - if (isset($this->optional_closing_tags[$tag_lower]) ) |
|
| 1404 | + if (isset($this->optional_closing_tags[$tag_lower])) |
|
| 1405 | 1405 | { |
| 1406 | 1406 | while (isset($this->optional_closing_tags[$tag_lower][strtolower($this->parent->tag)])) |
| 1407 | 1407 | { |
@@ -1417,67 +1417,67 @@ discard block |
||
| 1417 | 1417 | // attributes |
| 1418 | 1418 | do |
| 1419 | 1419 | { |
| 1420 | - if ($this->char!==null && $space[0]==='') |
|
| 1420 | + if ($this->char !== null && $space[0] === '') |
|
| 1421 | 1421 | { |
| 1422 | 1422 | break; |
| 1423 | 1423 | } |
| 1424 | 1424 | $name = $this->copy_until($this->token_equal); |
| 1425 | - if ($guard===$this->pos) |
|
| 1425 | + if ($guard === $this->pos) |
|
| 1426 | 1426 | { |
| 1427 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1427 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1428 | 1428 | continue; |
| 1429 | 1429 | } |
| 1430 | 1430 | $guard = $this->pos; |
| 1431 | 1431 | |
| 1432 | 1432 | // handle endless '<' |
| 1433 | - if ($this->pos>=$this->size-1 && $this->char!=='>') { |
|
| 1433 | + if ($this->pos >= $this->size - 1 && $this->char !== '>') { |
|
| 1434 | 1434 | $node->nodetype = HDOM_TYPE_TEXT; |
| 1435 | 1435 | $node->_[HDOM_INFO_END] = 0; |
| 1436 | - $node->_[HDOM_INFO_TEXT] = '<'.$tag . $space[0] . $name; |
|
| 1436 | + $node->_[HDOM_INFO_TEXT] = '<'.$tag.$space[0].$name; |
|
| 1437 | 1437 | $node->tag = 'text'; |
| 1438 | 1438 | $this->link_nodes($node, false); |
| 1439 | 1439 | return true; |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | // handle mismatch '<' |
| 1443 | - if ($this->doc[$this->pos-1]=='<') { |
|
| 1443 | + if ($this->doc[$this->pos - 1] == '<') { |
|
| 1444 | 1444 | $node->nodetype = HDOM_TYPE_TEXT; |
| 1445 | 1445 | $node->tag = 'text'; |
| 1446 | 1446 | $node->attr = array(); |
| 1447 | 1447 | $node->_[HDOM_INFO_END] = 0; |
| 1448 | - $node->_[HDOM_INFO_TEXT] = substr($this->doc, $begin_tag_pos, $this->pos-$begin_tag_pos-1); |
|
| 1448 | + $node->_[HDOM_INFO_TEXT] = substr($this->doc, $begin_tag_pos, $this->pos - $begin_tag_pos - 1); |
|
| 1449 | 1449 | $this->pos -= 2; |
| 1450 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1450 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1451 | 1451 | $this->link_nodes($node, false); |
| 1452 | 1452 | return true; |
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | - if ($name!=='/' && $name!=='') { |
|
| 1455 | + if ($name !== '/' && $name !== '') { |
|
| 1456 | 1456 | $space[1] = $this->copy_skip($this->token_blank); |
| 1457 | 1457 | $name = $this->restore_noise($name); |
| 1458 | 1458 | if ($this->lowercase) $name = strtolower($name); |
| 1459 | - if ($this->char==='=') { |
|
| 1460 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1459 | + if ($this->char === '=') { |
|
| 1460 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1461 | 1461 | $this->parse_attr($node, $name, $space); |
| 1462 | 1462 | } |
| 1463 | 1463 | else { |
| 1464 | 1464 | //no value attr: nowrap, checked selected... |
| 1465 | 1465 | $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO; |
| 1466 | 1466 | $node->attr[$name] = true; |
| 1467 | - if ($this->char!='>') $this->char = $this->doc[--$this->pos]; // prev |
|
| 1467 | + if ($this->char != '>') $this->char = $this->doc[--$this->pos]; // prev |
|
| 1468 | 1468 | } |
| 1469 | 1469 | $node->_[HDOM_INFO_SPACE][] = $space; |
| 1470 | 1470 | $space = array($this->copy_skip($this->token_blank), '', ''); |
| 1471 | 1471 | } |
| 1472 | 1472 | else |
| 1473 | 1473 | break; |
| 1474 | - } while ($this->char!=='>' && $this->char!=='/'); |
|
| 1474 | + } while ($this->char !== '>' && $this->char !== '/'); |
|
| 1475 | 1475 | |
| 1476 | 1476 | $this->link_nodes($node, true); |
| 1477 | 1477 | $node->_[HDOM_INFO_ENDSPACE] = $space[0]; |
| 1478 | 1478 | |
| 1479 | 1479 | // check self closing |
| 1480 | - if ($this->copy_until_char_escape('>')==='/') |
|
| 1480 | + if ($this->copy_until_char_escape('>') === '/') |
|
| 1481 | 1481 | { |
| 1482 | 1482 | $node->_[HDOM_INFO_ENDSPACE] .= '/'; |
| 1483 | 1483 | $node->_[HDOM_INFO_END] = 0; |
@@ -1487,7 +1487,7 @@ discard block |
||
| 1487 | 1487 | // reset parent |
| 1488 | 1488 | if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node; |
| 1489 | 1489 | } |
| 1490 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1490 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1491 | 1491 | |
| 1492 | 1492 | // If it's a BR tag, we need to set it's text to the default text. |
| 1493 | 1493 | // This way when we see it in plaintext, we can generate formatting that the user wants. |
@@ -1514,15 +1514,15 @@ discard block |
||
| 1514 | 1514 | switch ($this->char) { |
| 1515 | 1515 | case '"': |
| 1516 | 1516 | $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE; |
| 1517 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1517 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1518 | 1518 | $node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('"')); |
| 1519 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1519 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1520 | 1520 | break; |
| 1521 | 1521 | case '\'': |
| 1522 | 1522 | $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_SINGLE; |
| 1523 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1523 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1524 | 1524 | $node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('\'')); |
| 1525 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1525 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1526 | 1526 | break; |
| 1527 | 1527 | default: |
| 1528 | 1528 | $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO; |
@@ -1553,16 +1553,16 @@ discard block |
||
| 1553 | 1553 | { |
| 1554 | 1554 | $node = new simple_html_dom_node($this); |
| 1555 | 1555 | ++$this->cursor; |
| 1556 | - $node->_[HDOM_INFO_TEXT] = '</' . $tag . '>'; |
|
| 1556 | + $node->_[HDOM_INFO_TEXT] = '</'.$tag.'>'; |
|
| 1557 | 1557 | $this->link_nodes($node, false); |
| 1558 | - $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1558 | + $this->char = (++$this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1559 | 1559 | return true; |
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | protected function skip($chars) |
| 1563 | 1563 | { |
| 1564 | 1564 | $this->pos += strspn($this->doc, $chars, $this->pos); |
| 1565 | - $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1565 | + $this->char = ($this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | protected function copy_skip($chars) |
@@ -1570,8 +1570,8 @@ discard block |
||
| 1570 | 1570 | $pos = $this->pos; |
| 1571 | 1571 | $len = strspn($this->doc, $chars, $pos); |
| 1572 | 1572 | $this->pos += $len; |
| 1573 | - $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1574 | - if ($len===0) return ''; |
|
| 1573 | + $this->char = ($this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1574 | + if ($len === 0) return ''; |
|
| 1575 | 1575 | return substr($this->doc, $pos, $len); |
| 1576 | 1576 | } |
| 1577 | 1577 | |
@@ -1580,70 +1580,70 @@ discard block |
||
| 1580 | 1580 | $pos = $this->pos; |
| 1581 | 1581 | $len = strcspn($this->doc, $chars, $pos); |
| 1582 | 1582 | $this->pos += $len; |
| 1583 | - $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1583 | + $this->char = ($this->pos < $this->size) ? $this->doc[$this->pos] : null; // next |
|
| 1584 | 1584 | return substr($this->doc, $pos, $len); |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | protected function copy_until_char($char) |
| 1588 | 1588 | { |
| 1589 | - if ($this->char===null) return ''; |
|
| 1589 | + if ($this->char === null) return ''; |
|
| 1590 | 1590 | |
| 1591 | - if (($pos = strpos($this->doc, $char, $this->pos))===false) { |
|
| 1592 | - $ret = substr($this->doc, $this->pos, $this->size-$this->pos); |
|
| 1591 | + if (($pos = strpos($this->doc, $char, $this->pos)) === false) { |
|
| 1592 | + $ret = substr($this->doc, $this->pos, $this->size - $this->pos); |
|
| 1593 | 1593 | $this->char = null; |
| 1594 | 1594 | $this->pos = $this->size; |
| 1595 | 1595 | return $ret; |
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | - if ($pos===$this->pos) return ''; |
|
| 1598 | + if ($pos === $this->pos) return ''; |
|
| 1599 | 1599 | $pos_old = $this->pos; |
| 1600 | 1600 | $this->char = $this->doc[$pos]; |
| 1601 | 1601 | $this->pos = $pos; |
| 1602 | - return substr($this->doc, $pos_old, $pos-$pos_old); |
|
| 1602 | + return substr($this->doc, $pos_old, $pos - $pos_old); |
|
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | protected function copy_until_char_escape($char) |
| 1606 | 1606 | { |
| 1607 | - if ($this->char===null) return ''; |
|
| 1607 | + if ($this->char === null) return ''; |
|
| 1608 | 1608 | |
| 1609 | 1609 | $start = $this->pos; |
| 1610 | 1610 | while (1) |
| 1611 | 1611 | { |
| 1612 | - if (($pos = strpos($this->doc, $char, $start))===false) |
|
| 1612 | + if (($pos = strpos($this->doc, $char, $start)) === false) |
|
| 1613 | 1613 | { |
| 1614 | - $ret = substr($this->doc, $this->pos, $this->size-$this->pos); |
|
| 1614 | + $ret = substr($this->doc, $this->pos, $this->size - $this->pos); |
|
| 1615 | 1615 | $this->char = null; |
| 1616 | 1616 | $this->pos = $this->size; |
| 1617 | 1617 | return $ret; |
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | - if ($pos===$this->pos) return ''; |
|
| 1620 | + if ($pos === $this->pos) return ''; |
|
| 1621 | 1621 | |
| 1622 | - if ($this->doc[$pos-1]==='\\') { |
|
| 1623 | - $start = $pos+1; |
|
| 1622 | + if ($this->doc[$pos - 1] === '\\') { |
|
| 1623 | + $start = $pos + 1; |
|
| 1624 | 1624 | continue; |
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | 1627 | $pos_old = $this->pos; |
| 1628 | 1628 | $this->char = $this->doc[$pos]; |
| 1629 | 1629 | $this->pos = $pos; |
| 1630 | - return substr($this->doc, $pos_old, $pos-$pos_old); |
|
| 1630 | + return substr($this->doc, $pos_old, $pos - $pos_old); |
|
| 1631 | 1631 | } |
| 1632 | 1632 | } |
| 1633 | 1633 | |
| 1634 | 1634 | // remove noise from html content |
| 1635 | 1635 | // save the noise in the $this->noise array. |
| 1636 | - protected function remove_noise($pattern, $remove_tag=false) |
|
| 1636 | + protected function remove_noise($pattern, $remove_tag = false) |
|
| 1637 | 1637 | { |
| 1638 | 1638 | global $debug_object; |
| 1639 | 1639 | if (is_object($debug_object)) { $debug_object->debug_log_entry(1); } |
| 1640 | 1640 | |
| 1641 | 1641 | $count = preg_match_all($pattern, $this->doc, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE); |
| 1642 | 1642 | |
| 1643 | - for ($i=$count-1; $i>-1; --$i) |
|
| 1643 | + for ($i = $count - 1; $i > -1; --$i) |
|
| 1644 | 1644 | { |
| 1645 | - $key = '___noise___'.sprintf('% 5d', count($this->noise)+1000); |
|
| 1646 | - if (is_object($debug_object)) { $debug_object->debug_log(2, 'key is: ' . $key); } |
|
| 1645 | + $key = '___noise___'.sprintf('% 5d', count($this->noise) + 1000); |
|
| 1646 | + if (is_object($debug_object)) { $debug_object->debug_log(2, 'key is: '.$key); } |
|
| 1647 | 1647 | $idx = ($remove_tag) ? 0 : 1; |
| 1648 | 1648 | $this->noise[$key] = $matches[$i][$idx][0]; |
| 1649 | 1649 | $this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0])); |
@@ -1651,7 +1651,7 @@ discard block |
||
| 1651 | 1651 | |
| 1652 | 1652 | // reset the length of content |
| 1653 | 1653 | $this->size = strlen($this->doc); |
| 1654 | - if ($this->size>0) |
|
| 1654 | + if ($this->size > 0) |
|
| 1655 | 1655 | { |
| 1656 | 1656 | $this->char = $this->doc[0]; |
| 1657 | 1657 | } |
@@ -1663,28 +1663,28 @@ discard block |
||
| 1663 | 1663 | global $debug_object; |
| 1664 | 1664 | if (is_object($debug_object)) { $debug_object->debug_log_entry(1); } |
| 1665 | 1665 | |
| 1666 | - while (($pos=strpos($text, '___noise___'))!==false) |
|
| 1666 | + while (($pos = strpos($text, '___noise___')) !== false) |
|
| 1667 | 1667 | { |
| 1668 | 1668 | // Sometimes there is a broken piece of markup, and we don't GET the pos+11 etc... token which indicates a problem outside of us... |
| 1669 | - if (strlen($text) > $pos+15) |
|
| 1669 | + if (strlen($text) > $pos + 15) |
|
| 1670 | 1670 | { |
| 1671 | - $key = '___noise___'.$text[$pos+11].$text[$pos+12].$text[$pos+13].$text[$pos+14].$text[$pos+15]; |
|
| 1672 | - if (is_object($debug_object)) { $debug_object->debug_log(2, 'located key of: ' . $key); } |
|
| 1671 | + $key = '___noise___'.$text[$pos + 11].$text[$pos + 12].$text[$pos + 13].$text[$pos + 14].$text[$pos + 15]; |
|
| 1672 | + if (is_object($debug_object)) { $debug_object->debug_log(2, 'located key of: '.$key); } |
|
| 1673 | 1673 | |
| 1674 | 1674 | if (isset($this->noise[$key])) |
| 1675 | 1675 | { |
| 1676 | - $text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+16); |
|
| 1676 | + $text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos + 16); |
|
| 1677 | 1677 | } |
| 1678 | 1678 | else |
| 1679 | 1679 | { |
| 1680 | 1680 | // do this to prevent an infinite loop. |
| 1681 | - $text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key . substr($text, $pos+16); |
|
| 1681 | + $text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key.substr($text, $pos + 16); |
|
| 1682 | 1682 | } |
| 1683 | 1683 | } |
| 1684 | 1684 | else |
| 1685 | 1685 | { |
| 1686 | 1686 | // There is no valid key being given back to us... We must get rid of the ___noise___ or we will have a problem. |
| 1687 | - $text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY' . substr($text, $pos+11); |
|
| 1687 | + $text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY'.substr($text, $pos + 11); |
|
| 1688 | 1688 | } |
| 1689 | 1689 | } |
| 1690 | 1690 | return $text; |
@@ -1696,9 +1696,9 @@ discard block |
||
| 1696 | 1696 | global $debug_object; |
| 1697 | 1697 | if (is_object($debug_object)) { $debug_object->debug_log_entry(1); } |
| 1698 | 1698 | |
| 1699 | - foreach($this->noise as $noiseElement) |
|
| 1699 | + foreach ($this->noise as $noiseElement) |
|
| 1700 | 1700 | { |
| 1701 | - if (strpos($noiseElement, $text)!==false) |
|
| 1701 | + if (strpos($noiseElement, $text) !== false) |
|
| 1702 | 1702 | { |
| 1703 | 1703 | return $noiseElement; |
| 1704 | 1704 | } |
@@ -1727,16 +1727,16 @@ discard block |
||
| 1727 | 1727 | } |
| 1728 | 1728 | |
| 1729 | 1729 | // camel naming conventions |
| 1730 | - function childNodes($idx=-1) {return $this->root->childNodes($idx);} |
|
| 1731 | - function firstChild() {return $this->root->first_child();} |
|
| 1732 | - function lastChild() {return $this->root->last_child();} |
|
| 1733 | - function createElement($name, $value=null) {return @str_get_html("<$name>$value</$name>")->first_child();} |
|
| 1734 | - function createTextNode($value) {return @end(str_get_html($value)->nodes);} |
|
| 1735 | - function getElementById($id) {return $this->find("#$id", 0);} |
|
| 1736 | - function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);} |
|
| 1737 | - function getElementByTagName($name) {return $this->find($name, 0);} |
|
| 1738 | - function getElementsByTagName($name, $idx=-1) {return $this->find($name, $idx);} |
|
| 1739 | - function loadFile() {$args = func_get_args();$this->load_file($args);} |
|
| 1730 | + function childNodes($idx = -1) {return $this->root->childNodes($idx); } |
|
| 1731 | + function firstChild() {return $this->root->first_child(); } |
|
| 1732 | + function lastChild() {return $this->root->last_child(); } |
|
| 1733 | + function createElement($name, $value = null) {return @str_get_html("<$name>$value</$name>")->first_child(); } |
|
| 1734 | + function createTextNode($value) {return @end(str_get_html($value)->nodes); } |
|
| 1735 | + function getElementById($id) {return $this->find("#$id", 0); } |
|
| 1736 | + function getElementsById($id, $idx = null) {return $this->find("#$id", $idx); } |
|
| 1737 | + function getElementByTagName($name) {return $this->find($name, 0); } |
|
| 1738 | + function getElementsByTagName($name, $idx = -1) {return $this->find($name, $idx); } |
|
| 1739 | + function loadFile() {$args = func_get_args(); $this->load_file($args); } |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | ?> |
| 1743 | 1743 | \ No newline at end of file |
@@ -159,8 +159,9 @@ discard block |
||
| 159 | 159 | if ($show_attr && count($this->attr)>0) |
| 160 | 160 | { |
| 161 | 161 | echo '('; |
| 162 | - foreach ($this->attr as $k=>$v) |
|
| 163 | - echo "[$k]=>\"".$this->$k.'", '; |
|
| 162 | + foreach ($this->attr as $k=>$v) { |
|
| 163 | + echo "[$k]=>\"".$this->$k.'", '; |
|
| 164 | + } |
|
| 164 | 165 | echo ')'; |
| 165 | 166 | } |
| 166 | 167 | echo "\n"; |
@@ -218,8 +219,7 @@ discard block |
||
| 218 | 219 | if (isset($node->_[HDOM_INFO_INNER])) |
| 219 | 220 | { |
| 220 | 221 | $string .= $node->_[HDOM_INFO_INNER] . "'"; |
| 221 | - } |
|
| 222 | - else |
|
| 222 | + } else |
|
| 223 | 223 | { |
| 224 | 224 | $string .= ' NULL '; |
| 225 | 225 | } |
@@ -233,8 +233,7 @@ discard block |
||
| 233 | 233 | { |
| 234 | 234 | echo $string; |
| 235 | 235 | return; |
| 236 | - } |
|
| 237 | - else |
|
| 236 | + } else |
|
| 238 | 237 | { |
| 239 | 238 | return $string; |
| 240 | 239 | } |
@@ -320,12 +319,17 @@ discard block |
||
| 320 | 319 | // returns the previous sibling of node |
| 321 | 320 | function prev_sibling() |
| 322 | 321 | { |
| 323 | - if ($this->parent===null) return null; |
|
| 322 | + if ($this->parent===null) { |
|
| 323 | + return null; |
|
| 324 | + } |
|
| 324 | 325 | $idx = 0; |
| 325 | 326 | $count = count($this->parent->children); |
| 326 | - while ($idx<$count && $this!==$this->parent->children[$idx]) |
|
| 327 | - ++$idx; |
|
| 328 | - if (--$idx<0) return null; |
|
| 327 | + while ($idx<$count && $this!==$this->parent->children[$idx]) { |
|
| 328 | + ++$idx; |
|
| 329 | + } |
|
| 330 | + if (--$idx<0) { |
|
| 331 | + return null; |
|
| 332 | + } |
|
| 329 | 333 | return $this->parent->children[$idx]; |
| 330 | 334 | } |
| 331 | 335 | |
@@ -354,12 +358,17 @@ discard block |
||
| 354 | 358 | // get dom node's inner html |
| 355 | 359 | function innertext() |
| 356 | 360 | { |
| 357 | - if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; |
|
| 358 | - if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
|
| 361 | + if (isset($this->_[HDOM_INFO_INNER])) { |
|
| 362 | + return $this->_[HDOM_INFO_INNER]; |
|
| 363 | + } |
|
| 364 | + if (isset($this->_[HDOM_INFO_TEXT])) { |
|
| 365 | + return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
|
| 366 | + } |
|
| 359 | 367 | |
| 360 | 368 | $ret = ''; |
| 361 | - foreach ($this->nodes as $n) |
|
| 362 | - $ret .= $n->outertext(); |
|
| 369 | + foreach ($this->nodes as $n) { |
|
| 370 | + $ret .= $n->outertext(); |
|
| 371 | + } |
|
| 363 | 372 | return $ret; |
| 364 | 373 | } |
| 365 | 374 | |
@@ -380,7 +389,9 @@ discard block |
||
| 380 | 389 | $debug_object->debug_log(1, 'Innertext of tag: ' . $this->tag . $text); |
| 381 | 390 | } |
| 382 | 391 | |
| 383 | - if ($this->tag==='root') return $this->innertext(); |
|
| 392 | + if ($this->tag==='root') { |
|
| 393 | + return $this->innertext(); |
|
| 394 | + } |
|
| 384 | 395 | |
| 385 | 396 | // trigger callback |
| 386 | 397 | if ($this->dom && $this->dom->callback!==null) |
@@ -388,8 +399,12 @@ discard block |
||
| 388 | 399 | call_user_func_array($this->dom->callback, array($this)); |
| 389 | 400 | } |
| 390 | 401 | |
| 391 | - if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER]; |
|
| 392 | - if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
|
| 402 | + if (isset($this->_[HDOM_INFO_OUTER])) { |
|
| 403 | + return $this->_[HDOM_INFO_OUTER]; |
|
| 404 | + } |
|
| 405 | + if (isset($this->_[HDOM_INFO_TEXT])) { |
|
| 406 | + return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
|
| 407 | + } |
|
| 393 | 408 | |
| 394 | 409 | // render begin tag |
| 395 | 410 | if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]) |
@@ -418,23 +433,30 @@ discard block |
||
| 418 | 433 | } |
| 419 | 434 | |
| 420 | 435 | // render end tag |
| 421 | - if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0) |
|
| 422 | - $ret .= '</'.$this->tag.'>'; |
|
| 436 | + if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0) { |
|
| 437 | + $ret .= '</'.$this->tag.'>'; |
|
| 438 | + } |
|
| 423 | 439 | return $ret; |
| 424 | 440 | } |
| 425 | 441 | |
| 426 | 442 | // get dom node's plain text |
| 427 | 443 | function text() |
| 428 | 444 | { |
| 429 | - if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER]; |
|
| 445 | + if (isset($this->_[HDOM_INFO_INNER])) { |
|
| 446 | + return $this->_[HDOM_INFO_INNER]; |
|
| 447 | + } |
|
| 430 | 448 | switch ($this->nodetype) |
| 431 | 449 | { |
| 432 | 450 | case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
| 433 | 451 | case HDOM_TYPE_COMMENT: return ''; |
| 434 | 452 | case HDOM_TYPE_UNKNOWN: return ''; |
| 435 | 453 | } |
| 436 | - if (strcasecmp($this->tag, 'script')===0) return ''; |
|
| 437 | - if (strcasecmp($this->tag, 'style')===0) return ''; |
|
| 454 | + if (strcasecmp($this->tag, 'script')===0) { |
|
| 455 | + return ''; |
|
| 456 | + } |
|
| 457 | + if (strcasecmp($this->tag, 'style')===0) { |
|
| 458 | + return ''; |
|
| 459 | + } |
|
| 438 | 460 | |
| 439 | 461 | $ret = ''; |
| 440 | 462 | // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL. |
@@ -470,7 +492,9 @@ discard block |
||
| 470 | 492 | function makeup() |
| 471 | 493 | { |
| 472 | 494 | // text, comment, unknown |
| 473 | - if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
|
| 495 | + if (isset($this->_[HDOM_INFO_TEXT])) { |
|
| 496 | + return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]); |
|
| 497 | + } |
|
| 474 | 498 | |
| 475 | 499 | $ret = '<'.$this->tag; |
| 476 | 500 | $i = -1; |
@@ -480,14 +504,15 @@ discard block |
||
| 480 | 504 | ++$i; |
| 481 | 505 | |
| 482 | 506 | // skip removed attribute |
| 483 | - if ($val===null || $val===false) |
|
| 484 | - continue; |
|
| 507 | + if ($val===null || $val===false) { |
|
| 508 | + continue; |
|
| 509 | + } |
|
| 485 | 510 | |
| 486 | 511 | $ret .= $this->_[HDOM_INFO_SPACE][$i][0]; |
| 487 | 512 | //no value attr: nowrap, checked selected... |
| 488 | - if ($val===true) |
|
| 489 | - $ret .= $key; |
|
| 490 | - else { |
|
| 513 | + if ($val===true) { |
|
| 514 | + $ret .= $key; |
|
| 515 | + } else { |
|
| 491 | 516 | switch ($this->_[HDOM_INFO_QUOTE][$i]) |
| 492 | 517 | { |
| 493 | 518 | case HDOM_QUOTE_DOUBLE: $quote = '"'; break; |
@@ -506,7 +531,9 @@ discard block |
||
| 506 | 531 | function find($selector, $idx=null, $lowercase=false) |
| 507 | 532 | { |
| 508 | 533 | $selectors = $this->parse_selector($selector); |
| 509 | - if (($count=count($selectors))===0) return array(); |
|
| 534 | + if (($count=count($selectors))===0) { |
|
| 535 | + return array(); |
|
| 536 | + } |
|
| 510 | 537 | $found_keys = array(); |
| 511 | 538 | |
| 512 | 539 | // find each selector |
@@ -514,8 +541,12 @@ discard block |
||
| 514 | 541 | { |
| 515 | 542 | // The change on the below line was documented on the sourceforge code tracker id 2788009 |
| 516 | 543 | // used to be: if (($levle=count($selectors[0]))===0) return array(); |
| 517 | - if (($levle=count($selectors[$c]))===0) return array(); |
|
| 518 | - if (!isset($this->_[HDOM_INFO_BEGIN])) return array(); |
|
| 544 | + if (($levle=count($selectors[$c]))===0) { |
|
| 545 | + return array(); |
|
| 546 | + } |
|
| 547 | + if (!isset($this->_[HDOM_INFO_BEGIN])) { |
|
| 548 | + return array(); |
|
| 549 | + } |
|
| 519 | 550 | |
| 520 | 551 | $head = array($this->_[HDOM_INFO_BEGIN]=>1); |
| 521 | 552 | |
@@ -545,12 +576,16 @@ discard block |
||
| 545 | 576 | ksort($found_keys); |
| 546 | 577 | |
| 547 | 578 | $found = array(); |
| 548 | - foreach ($found_keys as $k=>$v) |
|
| 549 | - $found[] = $this->dom->nodes[$k]; |
|
| 579 | + foreach ($found_keys as $k=>$v) { |
|
| 580 | + $found[] = $this->dom->nodes[$k]; |
|
| 581 | + } |
|
| 550 | 582 | |
| 551 | 583 | // return nth-element or array |
| 552 | - if (is_null($idx)) return $found; |
|
| 553 | - else if ($idx<0) $idx = count($found) + $idx; |
|
| 584 | + if (is_null($idx)) { |
|
| 585 | + return $found; |
|
| 586 | + } else if ($idx<0) { |
|
| 587 | + $idx = count($found) + $idx; |
|
| 588 | + } |
|
| 554 | 589 | return (isset($found[$idx])) ? $found[$idx] : null; |
| 555 | 590 | } |
| 556 | 591 | |
@@ -595,8 +630,9 @@ discard block |
||
| 595 | 630 | $pass = true; |
| 596 | 631 | |
| 597 | 632 | if ($tag==='*' && !$key) { |
| 598 | - if (in_array($node, $this->children, true)) |
|
| 599 | - $ret[$i] = 1; |
|
| 633 | + if (in_array($node, $this->children, true)) { |
|
| 634 | + $ret[$i] = 1; |
|
| 635 | + } |
|
| 600 | 636 | continue; |
| 601 | 637 | } |
| 602 | 638 | |
@@ -605,9 +641,13 @@ discard block |
||
| 605 | 641 | // compare key |
| 606 | 642 | if ($pass && $key) { |
| 607 | 643 | if ($no_key) { |
| 608 | - if (isset($node->attr[$key])) $pass=false; |
|
| 644 | + if (isset($node->attr[$key])) { |
|
| 645 | + $pass=false; |
|
| 646 | + } |
|
| 609 | 647 | } else { |
| 610 | - if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false; |
|
| 648 | + if (($key != "plaintext") && !isset($node->attr[$key])) { |
|
| 649 | + $pass=false; |
|
| 650 | + } |
|
| 611 | 651 | } |
| 612 | 652 | } |
| 613 | 653 | // compare value |
@@ -640,13 +680,19 @@ discard block |
||
| 640 | 680 | } else { |
| 641 | 681 | $check = $this->match($exp, $val, $k); |
| 642 | 682 | } |
| 643 | - if ($check) break; |
|
| 683 | + if ($check) { |
|
| 684 | + break; |
|
| 685 | + } |
|
| 644 | 686 | } |
| 645 | 687 | } |
| 646 | 688 | } |
| 647 | - if (!$check) $pass = false; |
|
| 689 | + if (!$check) { |
|
| 690 | + $pass = false; |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + if ($pass) { |
|
| 694 | + $ret[$i] = 1; |
|
| 648 | 695 | } |
| 649 | - if ($pass) $ret[$i] = 1; |
|
| 650 | 696 | unset($node); |
| 651 | 697 | } |
| 652 | 698 | // It's passed by reference so this is actually what this function returns. |
@@ -696,9 +742,13 @@ discard block |
||
| 696 | 742 | |
| 697 | 743 | foreach ($matches as $m) { |
| 698 | 744 | $m[0] = trim($m[0]); |
| 699 | - if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue; |
|
| 745 | + if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') { |
|
| 746 | + continue; |
|
| 747 | + } |
|
| 700 | 748 | // for browser generated xpath |
| 701 | - if ($m[1]==='tbody') continue; |
|
| 749 | + if ($m[1]==='tbody') { |
|
| 750 | + continue; |
|
| 751 | + } |
|
| 702 | 752 | |
| 703 | 753 | list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false); |
| 704 | 754 | if (!empty($m[2])) {$key='id'; $val=$m[2];} |
@@ -718,8 +768,9 @@ discard block |
||
| 718 | 768 | $result = array(); |
| 719 | 769 | } |
| 720 | 770 | } |
| 721 | - if (count($result)>0) |
|
| 722 | - $selectors[] = $result; |
|
| 771 | + if (count($result)>0) { |
|
| 772 | + $selectors[] = $result; |
|
| 773 | + } |
|
| 723 | 774 | return $selectors; |
| 724 | 775 | } |
| 725 | 776 | |
@@ -748,7 +799,9 @@ discard block |
||
| 748 | 799 | { |
| 749 | 800 | case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value; |
| 750 | 801 | case 'innertext': |
| 751 | - if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value; |
|
| 802 | + if (isset($this->_[HDOM_INFO_TEXT])) { |
|
| 803 | + return $this->_[HDOM_INFO_TEXT] = $value; |
|
| 804 | + } |
|
| 752 | 805 | return $this->_[HDOM_INFO_INNER] = $value; |
| 753 | 806 | } |
| 754 | 807 | if (!isset($this->attr[$name])) |
@@ -772,8 +825,9 @@ discard block |
||
| 772 | 825 | } |
| 773 | 826 | |
| 774 | 827 | function __unset($name) { |
| 775 | - if (isset($this->attr[$name])) |
|
| 776 | - unset($this->attr[$name]); |
|
| 828 | + if (isset($this->attr[$name])) { |
|
| 829 | + unset($this->attr[$name]); |
|
| 830 | + } |
|
| 777 | 831 | } |
| 778 | 832 | |
| 779 | 833 | // PaperG - Function to convert the text from one character set to another if the two sets are not the same. |
@@ -800,8 +854,7 @@ discard block |
||
| 800 | 854 | if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text))) |
| 801 | 855 | { |
| 802 | 856 | $converted_text = $text; |
| 803 | - } |
|
| 804 | - else |
|
| 857 | + } else |
|
| 805 | 858 | { |
| 806 | 859 | $converted_text = iconv($sourceCharset, $targetCharset, $text); |
| 807 | 860 | } |
@@ -839,19 +892,31 @@ discard block |
||
| 839 | 892 | $c=ord($str[$i]); |
| 840 | 893 | if($c > 128) |
| 841 | 894 | { |
| 842 | - if(($c >= 254)) return false; |
|
| 843 | - elseif($c >= 252) $bits=6; |
|
| 844 | - elseif($c >= 248) $bits=5; |
|
| 845 | - elseif($c >= 240) $bits=4; |
|
| 846 | - elseif($c >= 224) $bits=3; |
|
| 847 | - elseif($c >= 192) $bits=2; |
|
| 848 | - else return false; |
|
| 849 | - if(($i+$bits) > $len) return false; |
|
| 895 | + if(($c >= 254)) { |
|
| 896 | + return false; |
|
| 897 | + } elseif($c >= 252) { |
|
| 898 | + $bits=6; |
|
| 899 | + } elseif($c >= 248) { |
|
| 900 | + $bits=5; |
|
| 901 | + } elseif($c >= 240) { |
|
| 902 | + $bits=4; |
|
| 903 | + } elseif($c >= 224) { |
|
| 904 | + $bits=3; |
|
| 905 | + } elseif($c >= 192) { |
|
| 906 | + $bits=2; |
|
| 907 | + } else { |
|
| 908 | + return false; |
|
| 909 | + } |
|
| 910 | + if(($i+$bits) > $len) { |
|
| 911 | + return false; |
|
| 912 | + } |
|
| 850 | 913 | while($bits > 1) |
| 851 | 914 | { |
| 852 | 915 | $i++; |
| 853 | 916 | $b=ord($str[$i]); |
| 854 | - if($b < 128 || $b > 191) return false; |
|
| 917 | + if($b < 128 || $b > 191) { |
|
| 918 | + return false; |
|
| 919 | + } |
|
| 855 | 920 | $bits--; |
| 856 | 921 | } |
| 857 | 922 | } |
@@ -1035,8 +1100,7 @@ discard block |
||
| 1035 | 1100 | if (preg_match("/^http:\/\//i",$str) || is_file($str)) |
| 1036 | 1101 | { |
| 1037 | 1102 | $this->load_file($str); |
| 1038 | - } |
|
| 1039 | - else |
|
| 1103 | + } else |
|
| 1040 | 1104 | { |
| 1041 | 1105 | $this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText); |
| 1042 | 1106 | } |
@@ -1118,7 +1182,9 @@ discard block |
||
| 1118 | 1182 | function save($filepath='') |
| 1119 | 1183 | { |
| 1120 | 1184 | $ret = $this->root->innertext(); |
| 1121 | - if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX); |
|
| 1185 | + if ($filepath!=='') { |
|
| 1186 | + file_put_contents($filepath, $ret, LOCK_EX); |
|
| 1187 | + } |
|
| 1122 | 1188 | return $ret; |
| 1123 | 1189 | } |
| 1124 | 1190 | |
@@ -1134,7 +1200,10 @@ discard block |
||
| 1134 | 1200 | { |
| 1135 | 1201 | foreach ($this->nodes as $n) {$n->clear(); $n = null;} |
| 1136 | 1202 | // This add next line is documented in the sourceforge repository. 2977248 as a fix for ongoing memory leaks that occur even with the use of clear. |
| 1137 | - if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null;} |
|
| 1203 | + if (isset($this->children)) { |
|
| 1204 | + foreach ($this->children as $n) {$n->clear(); |
|
| 1205 | + } |
|
| 1206 | + $n = null;} |
|
| 1138 | 1207 | if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);} |
| 1139 | 1208 | if (isset($this->root)) {$this->root->clear(); unset($this->root);} |
| 1140 | 1209 | unset($this->doc); |
@@ -1178,7 +1247,9 @@ discard block |
||
| 1178 | 1247 | $this->root->_[HDOM_INFO_BEGIN] = -1; |
| 1179 | 1248 | $this->root->nodetype = HDOM_TYPE_ROOT; |
| 1180 | 1249 | $this->parent = $this->root; |
| 1181 | - if ($this->size>0) $this->char = $this->doc[0]; |
|
| 1250 | + if ($this->size>0) { |
|
| 1251 | + $this->char = $this->doc[0]; |
|
| 1252 | + } |
|
| 1182 | 1253 | } |
| 1183 | 1254 | |
| 1184 | 1255 | // parse html content |
@@ -1232,8 +1303,7 @@ discard block |
||
| 1232 | 1303 | if ($success) |
| 1233 | 1304 | { |
| 1234 | 1305 | $charset = $matches[1]; |
| 1235 | - } |
|
| 1236 | - else |
|
| 1306 | + } else |
|
| 1237 | 1307 | { |
| 1238 | 1308 | // If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1 |
| 1239 | 1309 | if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');} |
@@ -1296,8 +1366,9 @@ discard block |
||
| 1296 | 1366 | $tag = $this->copy_until_char('>'); |
| 1297 | 1367 | |
| 1298 | 1368 | // skip attributes in end tag |
| 1299 | - if (($pos = strpos($tag, ' '))!==false) |
|
| 1300 | - $tag = substr($tag, 0, $pos); |
|
| 1369 | + if (($pos = strpos($tag, ' '))!==false) { |
|
| 1370 | + $tag = substr($tag, 0, $pos); |
|
| 1371 | + } |
|
| 1301 | 1372 | |
| 1302 | 1373 | $parent_lower = strtolower($this->parent->tag); |
| 1303 | 1374 | $tag_lower = strtolower($tag); |
@@ -1309,23 +1380,26 @@ discard block |
||
| 1309 | 1380 | $this->parent->_[HDOM_INFO_END] = 0; |
| 1310 | 1381 | $org_parent = $this->parent; |
| 1311 | 1382 | |
| 1312 | - while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) |
|
| 1313 | - $this->parent = $this->parent->parent; |
|
| 1383 | + while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) { |
|
| 1384 | + $this->parent = $this->parent->parent; |
|
| 1385 | + } |
|
| 1314 | 1386 | |
| 1315 | 1387 | if (strtolower($this->parent->tag)!==$tag_lower) { |
| 1316 | 1388 | $this->parent = $org_parent; // restore origonal parent |
| 1317 | - if ($this->parent->parent) $this->parent = $this->parent->parent; |
|
| 1389 | + if ($this->parent->parent) { |
|
| 1390 | + $this->parent = $this->parent->parent; |
|
| 1391 | + } |
|
| 1318 | 1392 | $this->parent->_[HDOM_INFO_END] = $this->cursor; |
| 1319 | 1393 | return $this->as_text_node($tag); |
| 1320 | 1394 | } |
| 1321 | - } |
|
| 1322 | - else if (($this->parent->parent) && isset($this->block_tags[$tag_lower])) |
|
| 1395 | + } else if (($this->parent->parent) && isset($this->block_tags[$tag_lower])) |
|
| 1323 | 1396 | { |
| 1324 | 1397 | $this->parent->_[HDOM_INFO_END] = 0; |
| 1325 | 1398 | $org_parent = $this->parent; |
| 1326 | 1399 | |
| 1327 | - while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) |
|
| 1328 | - $this->parent = $this->parent->parent; |
|
| 1400 | + while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower) { |
|
| 1401 | + $this->parent = $this->parent->parent; |
|
| 1402 | + } |
|
| 1329 | 1403 | |
| 1330 | 1404 | if (strtolower($this->parent->tag)!==$tag_lower) |
| 1331 | 1405 | { |
@@ -1333,18 +1407,19 @@ discard block |
||
| 1333 | 1407 | $this->parent->_[HDOM_INFO_END] = $this->cursor; |
| 1334 | 1408 | return $this->as_text_node($tag); |
| 1335 | 1409 | } |
| 1336 | - } |
|
| 1337 | - else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower) |
|
| 1410 | + } else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower) |
|
| 1338 | 1411 | { |
| 1339 | 1412 | $this->parent->_[HDOM_INFO_END] = 0; |
| 1340 | 1413 | $this->parent = $this->parent->parent; |
| 1414 | + } else { |
|
| 1415 | + return $this->as_text_node($tag); |
|
| 1341 | 1416 | } |
| 1342 | - else |
|
| 1343 | - return $this->as_text_node($tag); |
|
| 1344 | 1417 | } |
| 1345 | 1418 | |
| 1346 | 1419 | $this->parent->_[HDOM_INFO_END] = $this->cursor; |
| 1347 | - if ($this->parent->parent) $this->parent = $this->parent->parent; |
|
| 1420 | + if ($this->parent->parent) { |
|
| 1421 | + $this->parent = $this->parent->parent; |
|
| 1422 | + } |
|
| 1348 | 1423 | |
| 1349 | 1424 | $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1350 | 1425 | return true; |
@@ -1367,7 +1442,9 @@ discard block |
||
| 1367 | 1442 | $node->nodetype = HDOM_TYPE_UNKNOWN; |
| 1368 | 1443 | $node->tag = 'unknown'; |
| 1369 | 1444 | } |
| 1370 | - if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>'; |
|
| 1445 | + if ($this->char==='>') { |
|
| 1446 | + $node->_[HDOM_INFO_TEXT].='>'; |
|
| 1447 | + } |
|
| 1371 | 1448 | $this->link_nodes($node, true); |
| 1372 | 1449 | $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1373 | 1450 | return true; |
@@ -1389,7 +1466,9 @@ discard block |
||
| 1389 | 1466 | return true; |
| 1390 | 1467 | } |
| 1391 | 1468 | |
| 1392 | - if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>'; |
|
| 1469 | + if ($this->char==='>') { |
|
| 1470 | + $node->_[HDOM_INFO_TEXT].='>'; |
|
| 1471 | + } |
|
| 1393 | 1472 | $this->link_nodes($node, false); |
| 1394 | 1473 | $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1395 | 1474 | return true; |
@@ -1455,22 +1534,26 @@ discard block |
||
| 1455 | 1534 | if ($name!=='/' && $name!=='') { |
| 1456 | 1535 | $space[1] = $this->copy_skip($this->token_blank); |
| 1457 | 1536 | $name = $this->restore_noise($name); |
| 1458 | - if ($this->lowercase) $name = strtolower($name); |
|
| 1537 | + if ($this->lowercase) { |
|
| 1538 | + $name = strtolower($name); |
|
| 1539 | + } |
|
| 1459 | 1540 | if ($this->char==='=') { |
| 1460 | 1541 | $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1461 | 1542 | $this->parse_attr($node, $name, $space); |
| 1462 | - } |
|
| 1463 | - else { |
|
| 1543 | + } else { |
|
| 1464 | 1544 | //no value attr: nowrap, checked selected... |
| 1465 | 1545 | $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO; |
| 1466 | 1546 | $node->attr[$name] = true; |
| 1467 | - if ($this->char!='>') $this->char = $this->doc[--$this->pos]; // prev |
|
| 1547 | + if ($this->char!='>') { |
|
| 1548 | + $this->char = $this->doc[--$this->pos]; |
|
| 1549 | + } |
|
| 1550 | + // prev |
|
| 1468 | 1551 | } |
| 1469 | 1552 | $node->_[HDOM_INFO_SPACE][] = $space; |
| 1470 | 1553 | $space = array($this->copy_skip($this->token_blank), '', ''); |
| 1554 | + } else { |
|
| 1555 | + break; |
|
| 1471 | 1556 | } |
| 1472 | - else |
|
| 1473 | - break; |
|
| 1474 | 1557 | } while ($this->char!=='>' && $this->char!=='/'); |
| 1475 | 1558 | |
| 1476 | 1559 | $this->link_nodes($node, true); |
@@ -1481,11 +1564,12 @@ discard block |
||
| 1481 | 1564 | { |
| 1482 | 1565 | $node->_[HDOM_INFO_ENDSPACE] .= '/'; |
| 1483 | 1566 | $node->_[HDOM_INFO_END] = 0; |
| 1484 | - } |
|
| 1485 | - else |
|
| 1567 | + } else |
|
| 1486 | 1568 | { |
| 1487 | 1569 | // reset parent |
| 1488 | - if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node; |
|
| 1570 | + if (!isset($this->self_closing_tags[strtolower($node->tag)])) { |
|
| 1571 | + $this->parent = $node; |
|
| 1572 | + } |
|
| 1489 | 1573 | } |
| 1490 | 1574 | $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1491 | 1575 | |
@@ -1571,7 +1655,9 @@ discard block |
||
| 1571 | 1655 | $len = strspn($this->doc, $chars, $pos); |
| 1572 | 1656 | $this->pos += $len; |
| 1573 | 1657 | $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1574 | - if ($len===0) return ''; |
|
| 1658 | + if ($len===0) { |
|
| 1659 | + return ''; |
|
| 1660 | + } |
|
| 1575 | 1661 | return substr($this->doc, $pos, $len); |
| 1576 | 1662 | } |
| 1577 | 1663 | |
@@ -1586,7 +1672,9 @@ discard block |
||
| 1586 | 1672 | |
| 1587 | 1673 | protected function copy_until_char($char) |
| 1588 | 1674 | { |
| 1589 | - if ($this->char===null) return ''; |
|
| 1675 | + if ($this->char===null) { |
|
| 1676 | + return ''; |
|
| 1677 | + } |
|
| 1590 | 1678 | |
| 1591 | 1679 | if (($pos = strpos($this->doc, $char, $this->pos))===false) { |
| 1592 | 1680 | $ret = substr($this->doc, $this->pos, $this->size-$this->pos); |
@@ -1595,7 +1683,9 @@ discard block |
||
| 1595 | 1683 | return $ret; |
| 1596 | 1684 | } |
| 1597 | 1685 | |
| 1598 | - if ($pos===$this->pos) return ''; |
|
| 1686 | + if ($pos===$this->pos) { |
|
| 1687 | + return ''; |
|
| 1688 | + } |
|
| 1599 | 1689 | $pos_old = $this->pos; |
| 1600 | 1690 | $this->char = $this->doc[$pos]; |
| 1601 | 1691 | $this->pos = $pos; |
@@ -1604,7 +1694,9 @@ discard block |
||
| 1604 | 1694 | |
| 1605 | 1695 | protected function copy_until_char_escape($char) |
| 1606 | 1696 | { |
| 1607 | - if ($this->char===null) return ''; |
|
| 1697 | + if ($this->char===null) { |
|
| 1698 | + return ''; |
|
| 1699 | + } |
|
| 1608 | 1700 | |
| 1609 | 1701 | $start = $this->pos; |
| 1610 | 1702 | while (1) |
@@ -1617,7 +1709,9 @@ discard block |
||
| 1617 | 1709 | return $ret; |
| 1618 | 1710 | } |
| 1619 | 1711 | |
| 1620 | - if ($pos===$this->pos) return ''; |
|
| 1712 | + if ($pos===$this->pos) { |
|
| 1713 | + return ''; |
|
| 1714 | + } |
|
| 1621 | 1715 | |
| 1622 | 1716 | if ($this->doc[$pos-1]==='\\') { |
| 1623 | 1717 | $start = $pos+1; |
@@ -1674,14 +1768,12 @@ discard block |
||
| 1674 | 1768 | if (isset($this->noise[$key])) |
| 1675 | 1769 | { |
| 1676 | 1770 | $text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+16); |
| 1677 | - } |
|
| 1678 | - else |
|
| 1771 | + } else |
|
| 1679 | 1772 | { |
| 1680 | 1773 | // do this to prevent an infinite loop. |
| 1681 | 1774 | $text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key . substr($text, $pos+16); |
| 1682 | 1775 | } |
| 1683 | - } |
|
| 1684 | - else |
|
| 1776 | + } else |
|
| 1685 | 1777 | { |
| 1686 | 1778 | // There is no valid key being given back to us... We must get rid of the ___noise___ or we will have a problem. |
| 1687 | 1779 | $text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY' . substr($text, $pos+11); |
@@ -125,6 +125,9 @@ discard block |
||
| 125 | 125 | public $tag_start = 0; |
| 126 | 126 | private $dom = null; |
| 127 | 127 | |
| 128 | + /** |
|
| 129 | + * @param simple_html_dom $dom |
|
| 130 | + */ |
|
| 128 | 131 | function __construct($dom) |
| 129 | 132 | { |
| 130 | 133 | $this->dom = $dom; |
@@ -1501,6 +1504,11 @@ discard block |
||
| 1501 | 1504 | } |
| 1502 | 1505 | |
| 1503 | 1506 | // parse attributes |
| 1507 | + |
|
| 1508 | + /** |
|
| 1509 | + * @param simple_html_dom_node $node |
|
| 1510 | + * @param string[] $space |
|
| 1511 | + */ |
|
| 1504 | 1512 | protected function parse_attr($node, $name, &$space) |
| 1505 | 1513 | { |
| 1506 | 1514 | // Per sourceforge: http://sourceforge.net/tracker/?func=detail&aid=3061408&group_id=218559&atid=1044037 |
@@ -1538,6 +1546,11 @@ discard block |
||
| 1538 | 1546 | } |
| 1539 | 1547 | |
| 1540 | 1548 | // link node's parent |
| 1549 | + |
|
| 1550 | + /** |
|
| 1551 | + * @param simple_html_dom_node $node |
|
| 1552 | + * @param boolean $is_child |
|
| 1553 | + */ |
|
| 1541 | 1554 | protected function link_nodes(&$node, $is_child) |
| 1542 | 1555 | { |
| 1543 | 1556 | $node->parent = $this->parent; |
@@ -1549,6 +1562,10 @@ discard block |
||
| 1549 | 1562 | } |
| 1550 | 1563 | |
| 1551 | 1564 | // as a text node |
| 1565 | + |
|
| 1566 | + /** |
|
| 1567 | + * @param string $tag |
|
| 1568 | + */ |
|
| 1552 | 1569 | protected function as_text_node($tag) |
| 1553 | 1570 | { |
| 1554 | 1571 | $node = new simple_html_dom_node($this); |
@@ -1559,12 +1576,18 @@ discard block |
||
| 1559 | 1576 | return true; |
| 1560 | 1577 | } |
| 1561 | 1578 | |
| 1579 | + /** |
|
| 1580 | + * @param string $chars |
|
| 1581 | + */ |
|
| 1562 | 1582 | protected function skip($chars) |
| 1563 | 1583 | { |
| 1564 | 1584 | $this->pos += strspn($this->doc, $chars, $this->pos); |
| 1565 | 1585 | $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next |
| 1566 | 1586 | } |
| 1567 | 1587 | |
| 1588 | + /** |
|
| 1589 | + * @param string $chars |
|
| 1590 | + */ |
|
| 1568 | 1591 | protected function copy_skip($chars) |
| 1569 | 1592 | { |
| 1570 | 1593 | $pos = $this->pos; |
@@ -1575,6 +1598,9 @@ discard block |
||
| 1575 | 1598 | return substr($this->doc, $pos, $len); |
| 1576 | 1599 | } |
| 1577 | 1600 | |
| 1601 | + /** |
|
| 1602 | + * @param string $chars |
|
| 1603 | + */ |
|
| 1578 | 1604 | protected function copy_until($chars) |
| 1579 | 1605 | { |
| 1580 | 1606 | $pos = $this->pos; |
@@ -1584,6 +1610,9 @@ discard block |
||
| 1584 | 1610 | return substr($this->doc, $pos, $len); |
| 1585 | 1611 | } |
| 1586 | 1612 | |
| 1613 | + /** |
|
| 1614 | + * @param string $char |
|
| 1615 | + */ |
|
| 1587 | 1616 | protected function copy_until_char($char) |
| 1588 | 1617 | { |
| 1589 | 1618 | if ($this->char===null) return ''; |
@@ -1602,6 +1631,9 @@ discard block |
||
| 1602 | 1631 | return substr($this->doc, $pos_old, $pos-$pos_old); |
| 1603 | 1632 | } |
| 1604 | 1633 | |
| 1634 | + /** |
|
| 1635 | + * @param string $char |
|
| 1636 | + */ |
|
| 1605 | 1637 | protected function copy_until_char_escape($char) |
| 1606 | 1638 | { |
| 1607 | 1639 | if ($this->char===null) return ''; |
@@ -1633,6 +1665,10 @@ discard block |
||
| 1633 | 1665 | |
| 1634 | 1666 | // remove noise from html content |
| 1635 | 1667 | // save the noise in the $this->noise array. |
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * @param string $pattern |
|
| 1671 | + */ |
|
| 1636 | 1672 | protected function remove_noise($pattern, $remove_tag=false) |
| 1637 | 1673 | { |
| 1638 | 1674 | global $debug_object; |
@@ -1658,6 +1694,10 @@ discard block |
||
| 1658 | 1694 | } |
| 1659 | 1695 | |
| 1660 | 1696 | // restore noise to html content |
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * @param string|null $text |
|
| 1700 | + */ |
|
| 1661 | 1701 | function restore_noise($text) |
| 1662 | 1702 | { |
| 1663 | 1703 | global $debug_object; |
@@ -9,281 +9,281 @@ |
||
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function testMethods() { |
| 12 | - $format = 'gpx'; |
|
| 13 | - $value = file_get_contents('./input/20120702.gpx'); |
|
| 14 | - $geometry = geoPHP::load($value, $format); |
|
| 12 | + $format = 'gpx'; |
|
| 13 | + $value = file_get_contents('./input/20120702.gpx'); |
|
| 14 | + $geometry = geoPHP::load($value, $format); |
|
| 15 | 15 | |
| 16 | - $methods = array( |
|
| 17 | - array('name' => 'area'), |
|
| 18 | - array('name' => 'boundary'), |
|
| 19 | - array('name' => 'getBBox'), |
|
| 20 | - array('name' => 'centroid'), |
|
| 21 | - array('name' => 'length'), |
|
| 22 | - array('name' => 'greatCircleLength', 'argument' => 6378137), |
|
| 23 | - array('name' => 'haversineLength'), |
|
| 24 | - array('name' => 'y'), |
|
| 25 | - array('name' => 'x'), |
|
| 26 | - array('name' => 'numGeometries'), |
|
| 27 | - array('name' => 'geometryN', 'argument' => '1'), |
|
| 28 | - array('name' => 'startPoint'), |
|
| 29 | - array('name' => 'endPoint'), |
|
| 30 | - array('name' => 'isRing'), |
|
| 31 | - array('name' => 'isClosed'), |
|
| 32 | - array('name' => 'numPoints'), |
|
| 33 | - array('name' => 'pointN', 'argument' => '1'), |
|
| 34 | - array('name' => 'exteriorRing'), |
|
| 35 | - array('name' => 'numInteriorRings'), |
|
| 36 | - array('name' => 'interiorRingN', 'argument' => '1'), |
|
| 37 | - array('name' => 'dimension'), |
|
| 38 | - array('name' => 'geometryType'), |
|
| 39 | - array('name' => 'SRID'), |
|
| 40 | - array('name' => 'setSRID', 'argument' => '4326'), |
|
| 41 | - ); |
|
| 16 | + $methods = array( |
|
| 17 | + array('name' => 'area'), |
|
| 18 | + array('name' => 'boundary'), |
|
| 19 | + array('name' => 'getBBox'), |
|
| 20 | + array('name' => 'centroid'), |
|
| 21 | + array('name' => 'length'), |
|
| 22 | + array('name' => 'greatCircleLength', 'argument' => 6378137), |
|
| 23 | + array('name' => 'haversineLength'), |
|
| 24 | + array('name' => 'y'), |
|
| 25 | + array('name' => 'x'), |
|
| 26 | + array('name' => 'numGeometries'), |
|
| 27 | + array('name' => 'geometryN', 'argument' => '1'), |
|
| 28 | + array('name' => 'startPoint'), |
|
| 29 | + array('name' => 'endPoint'), |
|
| 30 | + array('name' => 'isRing'), |
|
| 31 | + array('name' => 'isClosed'), |
|
| 32 | + array('name' => 'numPoints'), |
|
| 33 | + array('name' => 'pointN', 'argument' => '1'), |
|
| 34 | + array('name' => 'exteriorRing'), |
|
| 35 | + array('name' => 'numInteriorRings'), |
|
| 36 | + array('name' => 'interiorRingN', 'argument' => '1'), |
|
| 37 | + array('name' => 'dimension'), |
|
| 38 | + array('name' => 'geometryType'), |
|
| 39 | + array('name' => 'SRID'), |
|
| 40 | + array('name' => 'setSRID', 'argument' => '4326'), |
|
| 41 | + ); |
|
| 42 | 42 | |
| 43 | - foreach($methods as $method) { |
|
| 44 | - $argument = NULL; |
|
| 45 | - $method_name = $method['name']; |
|
| 46 | - if (isset($method['argument'])) { |
|
| 47 | - $argument = $method['argument']; |
|
| 48 | - } |
|
| 49 | - $this->_methods_tester($geometry, $method_name, $argument); |
|
| 50 | - } |
|
| 43 | + foreach($methods as $method) { |
|
| 44 | + $argument = NULL; |
|
| 45 | + $method_name = $method['name']; |
|
| 46 | + if (isset($method['argument'])) { |
|
| 47 | + $argument = $method['argument']; |
|
| 48 | + } |
|
| 49 | + $this->_methods_tester($geometry, $method_name, $argument); |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function _methods_tester($geometry, $method_name, $argument) { |
| 54 | 54 | |
| 55 | - if (!method_exists($geometry, $method_name)) { |
|
| 56 | - $this->fail("Method ".$method_name.'() doesn\'t exists.'); |
|
| 57 | - return; |
|
| 58 | - } |
|
| 55 | + if (!method_exists($geometry, $method_name)) { |
|
| 56 | + $this->fail("Method ".$method_name.'() doesn\'t exists.'); |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - switch ($method_name) { |
|
| 61 | - case 'y': |
|
| 62 | - case 'x': |
|
| 63 | - if ($geometry->geometryType() == 'Point') { |
|
| 64 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 65 | - } |
|
| 66 | - if ($geometry->geometryType() == 'LineString') { |
|
| 67 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 68 | - } |
|
| 69 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 70 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 71 | - } |
|
| 72 | - break; |
|
| 73 | - case 'geometryN': |
|
| 74 | - if ($geometry->geometryType() == 'Point') { |
|
| 75 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 76 | - } |
|
| 77 | - if ($geometry->geometryType() == 'LineString') { |
|
| 78 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 79 | - } |
|
| 80 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 81 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 82 | - } |
|
| 83 | - break; |
|
| 84 | - case 'startPoint': |
|
| 85 | - if ($geometry->geometryType() == 'Point') { |
|
| 86 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 87 | - } |
|
| 88 | - if ($geometry->geometryType() == 'LineString') { |
|
| 89 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 90 | - } |
|
| 91 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 92 | - //TODO: Add a method startPoint() to MultiLineString. |
|
| 93 | - //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 94 | - } |
|
| 95 | - break; |
|
| 96 | - case 'endPoint': |
|
| 97 | - if ($geometry->geometryType() == 'Point') { |
|
| 98 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 99 | - } |
|
| 100 | - if ($geometry->geometryType() == 'LineString') { |
|
| 101 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 102 | - } |
|
| 103 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 104 | - //TODO: Add a method endPoint() to MultiLineString. |
|
| 105 | - //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 106 | - } |
|
| 107 | - break; |
|
| 108 | - case 'isRing': |
|
| 109 | - if ($geometry->geometryType() == 'Point') { |
|
| 110 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 111 | - } |
|
| 112 | - if ($geometry->geometryType() == 'LineString') { |
|
| 113 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 114 | - } |
|
| 115 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 116 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 117 | - } |
|
| 118 | - break; |
|
| 119 | - case 'isClosed': |
|
| 120 | - if ($geometry->geometryType() == 'Point') { |
|
| 121 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 122 | - } |
|
| 123 | - if ($geometry->geometryType() == 'LineString') { |
|
| 124 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 125 | - } |
|
| 126 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 127 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 128 | - } |
|
| 129 | - break; |
|
| 130 | - case 'pointN': |
|
| 131 | - if ($geometry->geometryType() == 'Point') { |
|
| 132 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 133 | - } |
|
| 134 | - if ($geometry->geometryType() == 'LineString') { |
|
| 135 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 136 | - } |
|
| 137 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 138 | - //TODO: Add a method pointN() to MultiLineString. |
|
| 139 | - //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 140 | - } |
|
| 141 | - break; |
|
| 142 | - case 'exteriorRing': |
|
| 143 | - if ($geometry->geometryType() == 'Point') { |
|
| 144 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 145 | - } |
|
| 146 | - if ($geometry->geometryType() == 'LineString') { |
|
| 147 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 148 | - } |
|
| 149 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 150 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 151 | - } |
|
| 152 | - break; |
|
| 153 | - case 'numInteriorRings': |
|
| 154 | - if ($geometry->geometryType() == 'Point') { |
|
| 155 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 156 | - } |
|
| 157 | - if ($geometry->geometryType() == 'LineString') { |
|
| 158 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 159 | - } |
|
| 160 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 161 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 162 | - } |
|
| 163 | - break; |
|
| 164 | - case 'interiorRingN': |
|
| 165 | - if ($geometry->geometryType() == 'Point') { |
|
| 166 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 167 | - } |
|
| 168 | - if ($geometry->geometryType() == 'LineString') { |
|
| 169 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 170 | - } |
|
| 171 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 172 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 173 | - } |
|
| 174 | - break; |
|
| 175 | - case 'setSRID': |
|
| 176 | - //TODO: The method setSRID() should return TRUE. |
|
| 177 | - break; |
|
| 178 | - case 'SRID': |
|
| 179 | - if ($geometry->geometryType() == 'Point') { |
|
| 180 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 181 | - } |
|
| 182 | - if ($geometry->geometryType() == 'LineString') { |
|
| 183 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 184 | - } |
|
| 185 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 186 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 187 | - } |
|
| 188 | - break; |
|
| 189 | - case 'getBBox': |
|
| 190 | - if ($geometry->geometryType() == 'Point') { |
|
| 191 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 192 | - } |
|
| 193 | - if ($geometry->geometryType() == 'LineString') { |
|
| 194 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 195 | - } |
|
| 196 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 197 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 198 | - } |
|
| 199 | - break; |
|
| 200 | - case 'centroid': |
|
| 201 | - if ($geometry->geometryType() == 'Point') { |
|
| 202 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 203 | - } |
|
| 204 | - if ($geometry->geometryType() == 'LineString') { |
|
| 205 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 206 | - } |
|
| 207 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 208 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 209 | - } |
|
| 210 | - break; |
|
| 211 | - case 'length': |
|
| 212 | - if ($geometry->geometryType() == 'Point') { |
|
| 213 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 214 | - } |
|
| 215 | - if ($geometry->geometryType() == 'LineString') { |
|
| 216 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 217 | - } |
|
| 218 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 219 | - $this->assertEquals($geometry->$method_name($argument), (float) '0.11624637315233', 'Failed on ' . $method_name); |
|
| 220 | - } |
|
| 221 | - break; |
|
| 222 | - case 'numGeometries': |
|
| 223 | - if ($geometry->geometryType() == 'Point') { |
|
| 224 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 225 | - } |
|
| 226 | - if ($geometry->geometryType() == 'LineString') { |
|
| 227 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 228 | - } |
|
| 229 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 230 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 231 | - } |
|
| 232 | - break; |
|
| 233 | - case 'numPoints': |
|
| 234 | - if ($geometry->geometryType() == 'Point') { |
|
| 235 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 236 | - } |
|
| 237 | - if ($geometry->geometryType() == 'LineString') { |
|
| 238 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 239 | - } |
|
| 240 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 241 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 242 | - } |
|
| 243 | - break; |
|
| 244 | - case 'dimension': |
|
| 245 | - if ($geometry->geometryType() == 'Point') { |
|
| 246 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 247 | - } |
|
| 248 | - if ($geometry->geometryType() == 'LineString') { |
|
| 249 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 250 | - } |
|
| 251 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 252 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 253 | - } |
|
| 254 | - break; |
|
| 255 | - case 'boundary': |
|
| 256 | - if ($geometry->geometryType() == 'Point') { |
|
| 257 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 258 | - } |
|
| 259 | - if ($geometry->geometryType() == 'LineString') { |
|
| 260 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 261 | - } |
|
| 262 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 263 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 264 | - } |
|
| 265 | - break; |
|
| 266 | - case 'greatCircleLength': |
|
| 267 | - if ($geometry->geometryType() == 'Point') { |
|
| 268 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 269 | - } |
|
| 270 | - if ($geometry->geometryType() == 'LineString') { |
|
| 271 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 272 | - } |
|
| 273 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 274 | - $this->assertNotEquals($geometry->$method_name($argument), '9500.9359867418', 'Failed on ' . $method_name); |
|
| 275 | - } |
|
| 276 | - break; |
|
| 277 | - case 'haversineLength': |
|
| 278 | - case 'area': |
|
| 279 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 280 | - break; |
|
| 281 | - case 'geometryType': |
|
| 282 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 283 | - break; |
|
| 284 | - default: |
|
| 285 | - $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 286 | - } |
|
| 60 | + switch ($method_name) { |
|
| 61 | + case 'y': |
|
| 62 | + case 'x': |
|
| 63 | + if ($geometry->geometryType() == 'Point') { |
|
| 64 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 65 | + } |
|
| 66 | + if ($geometry->geometryType() == 'LineString') { |
|
| 67 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 68 | + } |
|
| 69 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 70 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 71 | + } |
|
| 72 | + break; |
|
| 73 | + case 'geometryN': |
|
| 74 | + if ($geometry->geometryType() == 'Point') { |
|
| 75 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 76 | + } |
|
| 77 | + if ($geometry->geometryType() == 'LineString') { |
|
| 78 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 79 | + } |
|
| 80 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 81 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 82 | + } |
|
| 83 | + break; |
|
| 84 | + case 'startPoint': |
|
| 85 | + if ($geometry->geometryType() == 'Point') { |
|
| 86 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 87 | + } |
|
| 88 | + if ($geometry->geometryType() == 'LineString') { |
|
| 89 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 90 | + } |
|
| 91 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 92 | + //TODO: Add a method startPoint() to MultiLineString. |
|
| 93 | + //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 94 | + } |
|
| 95 | + break; |
|
| 96 | + case 'endPoint': |
|
| 97 | + if ($geometry->geometryType() == 'Point') { |
|
| 98 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 99 | + } |
|
| 100 | + if ($geometry->geometryType() == 'LineString') { |
|
| 101 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 102 | + } |
|
| 103 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 104 | + //TODO: Add a method endPoint() to MultiLineString. |
|
| 105 | + //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 106 | + } |
|
| 107 | + break; |
|
| 108 | + case 'isRing': |
|
| 109 | + if ($geometry->geometryType() == 'Point') { |
|
| 110 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 111 | + } |
|
| 112 | + if ($geometry->geometryType() == 'LineString') { |
|
| 113 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 114 | + } |
|
| 115 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 116 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 117 | + } |
|
| 118 | + break; |
|
| 119 | + case 'isClosed': |
|
| 120 | + if ($geometry->geometryType() == 'Point') { |
|
| 121 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 122 | + } |
|
| 123 | + if ($geometry->geometryType() == 'LineString') { |
|
| 124 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 125 | + } |
|
| 126 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 127 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 128 | + } |
|
| 129 | + break; |
|
| 130 | + case 'pointN': |
|
| 131 | + if ($geometry->geometryType() == 'Point') { |
|
| 132 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 133 | + } |
|
| 134 | + if ($geometry->geometryType() == 'LineString') { |
|
| 135 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 136 | + } |
|
| 137 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 138 | + //TODO: Add a method pointN() to MultiLineString. |
|
| 139 | + //$this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 140 | + } |
|
| 141 | + break; |
|
| 142 | + case 'exteriorRing': |
|
| 143 | + if ($geometry->geometryType() == 'Point') { |
|
| 144 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 145 | + } |
|
| 146 | + if ($geometry->geometryType() == 'LineString') { |
|
| 147 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 148 | + } |
|
| 149 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 150 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 151 | + } |
|
| 152 | + break; |
|
| 153 | + case 'numInteriorRings': |
|
| 154 | + if ($geometry->geometryType() == 'Point') { |
|
| 155 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 156 | + } |
|
| 157 | + if ($geometry->geometryType() == 'LineString') { |
|
| 158 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 159 | + } |
|
| 160 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 161 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 162 | + } |
|
| 163 | + break; |
|
| 164 | + case 'interiorRingN': |
|
| 165 | + if ($geometry->geometryType() == 'Point') { |
|
| 166 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 167 | + } |
|
| 168 | + if ($geometry->geometryType() == 'LineString') { |
|
| 169 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 170 | + } |
|
| 171 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 172 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 173 | + } |
|
| 174 | + break; |
|
| 175 | + case 'setSRID': |
|
| 176 | + //TODO: The method setSRID() should return TRUE. |
|
| 177 | + break; |
|
| 178 | + case 'SRID': |
|
| 179 | + if ($geometry->geometryType() == 'Point') { |
|
| 180 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 181 | + } |
|
| 182 | + if ($geometry->geometryType() == 'LineString') { |
|
| 183 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 184 | + } |
|
| 185 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 186 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 187 | + } |
|
| 188 | + break; |
|
| 189 | + case 'getBBox': |
|
| 190 | + if ($geometry->geometryType() == 'Point') { |
|
| 191 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 192 | + } |
|
| 193 | + if ($geometry->geometryType() == 'LineString') { |
|
| 194 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 195 | + } |
|
| 196 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 197 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 198 | + } |
|
| 199 | + break; |
|
| 200 | + case 'centroid': |
|
| 201 | + if ($geometry->geometryType() == 'Point') { |
|
| 202 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 203 | + } |
|
| 204 | + if ($geometry->geometryType() == 'LineString') { |
|
| 205 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 206 | + } |
|
| 207 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 208 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 209 | + } |
|
| 210 | + break; |
|
| 211 | + case 'length': |
|
| 212 | + if ($geometry->geometryType() == 'Point') { |
|
| 213 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 214 | + } |
|
| 215 | + if ($geometry->geometryType() == 'LineString') { |
|
| 216 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 217 | + } |
|
| 218 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 219 | + $this->assertEquals($geometry->$method_name($argument), (float) '0.11624637315233', 'Failed on ' . $method_name); |
|
| 220 | + } |
|
| 221 | + break; |
|
| 222 | + case 'numGeometries': |
|
| 223 | + if ($geometry->geometryType() == 'Point') { |
|
| 224 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 225 | + } |
|
| 226 | + if ($geometry->geometryType() == 'LineString') { |
|
| 227 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 228 | + } |
|
| 229 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 230 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 231 | + } |
|
| 232 | + break; |
|
| 233 | + case 'numPoints': |
|
| 234 | + if ($geometry->geometryType() == 'Point') { |
|
| 235 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 236 | + } |
|
| 237 | + if ($geometry->geometryType() == 'LineString') { |
|
| 238 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 239 | + } |
|
| 240 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 241 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 242 | + } |
|
| 243 | + break; |
|
| 244 | + case 'dimension': |
|
| 245 | + if ($geometry->geometryType() == 'Point') { |
|
| 246 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 247 | + } |
|
| 248 | + if ($geometry->geometryType() == 'LineString') { |
|
| 249 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 250 | + } |
|
| 251 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 252 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 253 | + } |
|
| 254 | + break; |
|
| 255 | + case 'boundary': |
|
| 256 | + if ($geometry->geometryType() == 'Point') { |
|
| 257 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 258 | + } |
|
| 259 | + if ($geometry->geometryType() == 'LineString') { |
|
| 260 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 261 | + } |
|
| 262 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 263 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 264 | + } |
|
| 265 | + break; |
|
| 266 | + case 'greatCircleLength': |
|
| 267 | + if ($geometry->geometryType() == 'Point') { |
|
| 268 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 269 | + } |
|
| 270 | + if ($geometry->geometryType() == 'LineString') { |
|
| 271 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 272 | + } |
|
| 273 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 274 | + $this->assertNotEquals($geometry->$method_name($argument), '9500.9359867418', 'Failed on ' . $method_name); |
|
| 275 | + } |
|
| 276 | + break; |
|
| 277 | + case 'haversineLength': |
|
| 278 | + case 'area': |
|
| 279 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 280 | + break; |
|
| 281 | + case 'geometryType': |
|
| 282 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 283 | + break; |
|
| 284 | + default: |
|
| 285 | + $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 286 | + } |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | array('name' => 'setSRID', 'argument' => '4326'), |
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | - foreach($methods as $method) { |
|
| 43 | + foreach ($methods as $method) { |
|
| 44 | 44 | $argument = NULL; |
| 45 | 45 | $method_name = $method['name']; |
| 46 | 46 | if (isset($method['argument'])) { |
@@ -61,32 +61,32 @@ discard block |
||
| 61 | 61 | case 'y': |
| 62 | 62 | case 'x': |
| 63 | 63 | if ($geometry->geometryType() == 'Point') { |
| 64 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 64 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 65 | 65 | } |
| 66 | 66 | if ($geometry->geometryType() == 'LineString') { |
| 67 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 67 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 68 | 68 | } |
| 69 | 69 | if ($geometry->geometryType() == 'MultiLineString') { |
| 70 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 70 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 71 | 71 | } |
| 72 | 72 | break; |
| 73 | 73 | case 'geometryN': |
| 74 | 74 | if ($geometry->geometryType() == 'Point') { |
| 75 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 75 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 76 | 76 | } |
| 77 | 77 | if ($geometry->geometryType() == 'LineString') { |
| 78 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 78 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 79 | 79 | } |
| 80 | 80 | if ($geometry->geometryType() == 'MultiLineString') { |
| 81 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 81 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 82 | 82 | } |
| 83 | 83 | break; |
| 84 | 84 | case 'startPoint': |
| 85 | 85 | if ($geometry->geometryType() == 'Point') { |
| 86 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 86 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 87 | 87 | } |
| 88 | 88 | if ($geometry->geometryType() == 'LineString') { |
| 89 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 89 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 90 | 90 | } |
| 91 | 91 | if ($geometry->geometryType() == 'MultiLineString') { |
| 92 | 92 | //TODO: Add a method startPoint() to MultiLineString. |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | break; |
| 96 | 96 | case 'endPoint': |
| 97 | 97 | if ($geometry->geometryType() == 'Point') { |
| 98 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 98 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 99 | 99 | } |
| 100 | 100 | if ($geometry->geometryType() == 'LineString') { |
| 101 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 101 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 102 | 102 | } |
| 103 | 103 | if ($geometry->geometryType() == 'MultiLineString') { |
| 104 | 104 | //TODO: Add a method endPoint() to MultiLineString. |
@@ -107,32 +107,32 @@ discard block |
||
| 107 | 107 | break; |
| 108 | 108 | case 'isRing': |
| 109 | 109 | if ($geometry->geometryType() == 'Point') { |
| 110 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 110 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 111 | 111 | } |
| 112 | 112 | if ($geometry->geometryType() == 'LineString') { |
| 113 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 113 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 114 | 114 | } |
| 115 | 115 | if ($geometry->geometryType() == 'MultiLineString') { |
| 116 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 116 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 117 | 117 | } |
| 118 | 118 | break; |
| 119 | 119 | case 'isClosed': |
| 120 | 120 | if ($geometry->geometryType() == 'Point') { |
| 121 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 121 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 122 | 122 | } |
| 123 | 123 | if ($geometry->geometryType() == 'LineString') { |
| 124 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 124 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 125 | 125 | } |
| 126 | 126 | if ($geometry->geometryType() == 'MultiLineString') { |
| 127 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 127 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 128 | 128 | } |
| 129 | 129 | break; |
| 130 | 130 | case 'pointN': |
| 131 | 131 | if ($geometry->geometryType() == 'Point') { |
| 132 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 132 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 133 | 133 | } |
| 134 | 134 | if ($geometry->geometryType() == 'LineString') { |
| 135 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 135 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 136 | 136 | } |
| 137 | 137 | if ($geometry->geometryType() == 'MultiLineString') { |
| 138 | 138 | //TODO: Add a method pointN() to MultiLineString. |
@@ -141,35 +141,35 @@ discard block |
||
| 141 | 141 | break; |
| 142 | 142 | case 'exteriorRing': |
| 143 | 143 | if ($geometry->geometryType() == 'Point') { |
| 144 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 144 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 145 | 145 | } |
| 146 | 146 | if ($geometry->geometryType() == 'LineString') { |
| 147 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 147 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 148 | 148 | } |
| 149 | 149 | if ($geometry->geometryType() == 'MultiLineString') { |
| 150 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 150 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 151 | 151 | } |
| 152 | 152 | break; |
| 153 | 153 | case 'numInteriorRings': |
| 154 | 154 | if ($geometry->geometryType() == 'Point') { |
| 155 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 155 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 156 | 156 | } |
| 157 | 157 | if ($geometry->geometryType() == 'LineString') { |
| 158 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 158 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 159 | 159 | } |
| 160 | 160 | if ($geometry->geometryType() == 'MultiLineString') { |
| 161 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 161 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 162 | 162 | } |
| 163 | 163 | break; |
| 164 | 164 | case 'interiorRingN': |
| 165 | 165 | if ($geometry->geometryType() == 'Point') { |
| 166 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 166 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 167 | 167 | } |
| 168 | 168 | if ($geometry->geometryType() == 'LineString') { |
| 169 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 169 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 170 | 170 | } |
| 171 | 171 | if ($geometry->geometryType() == 'MultiLineString') { |
| 172 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 172 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 173 | 173 | } |
| 174 | 174 | break; |
| 175 | 175 | case 'setSRID': |
@@ -177,112 +177,112 @@ discard block |
||
| 177 | 177 | break; |
| 178 | 178 | case 'SRID': |
| 179 | 179 | if ($geometry->geometryType() == 'Point') { |
| 180 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 180 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 181 | 181 | } |
| 182 | 182 | if ($geometry->geometryType() == 'LineString') { |
| 183 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 183 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 184 | 184 | } |
| 185 | 185 | if ($geometry->geometryType() == 'MultiLineString') { |
| 186 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 186 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 187 | 187 | } |
| 188 | 188 | break; |
| 189 | 189 | case 'getBBox': |
| 190 | 190 | if ($geometry->geometryType() == 'Point') { |
| 191 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 191 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 192 | 192 | } |
| 193 | 193 | if ($geometry->geometryType() == 'LineString') { |
| 194 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 194 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 195 | 195 | } |
| 196 | 196 | if ($geometry->geometryType() == 'MultiLineString') { |
| 197 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 197 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 198 | 198 | } |
| 199 | 199 | break; |
| 200 | 200 | case 'centroid': |
| 201 | 201 | if ($geometry->geometryType() == 'Point') { |
| 202 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 202 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 203 | 203 | } |
| 204 | 204 | if ($geometry->geometryType() == 'LineString') { |
| 205 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 205 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 206 | 206 | } |
| 207 | 207 | if ($geometry->geometryType() == 'MultiLineString') { |
| 208 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 208 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 209 | 209 | } |
| 210 | 210 | break; |
| 211 | 211 | case 'length': |
| 212 | 212 | if ($geometry->geometryType() == 'Point') { |
| 213 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 213 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 214 | 214 | } |
| 215 | 215 | if ($geometry->geometryType() == 'LineString') { |
| 216 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 216 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 217 | 217 | } |
| 218 | 218 | if ($geometry->geometryType() == 'MultiLineString') { |
| 219 | - $this->assertEquals($geometry->$method_name($argument), (float) '0.11624637315233', 'Failed on ' . $method_name); |
|
| 219 | + $this->assertEquals($geometry->$method_name($argument), (float) '0.11624637315233', 'Failed on '.$method_name); |
|
| 220 | 220 | } |
| 221 | 221 | break; |
| 222 | 222 | case 'numGeometries': |
| 223 | 223 | if ($geometry->geometryType() == 'Point') { |
| 224 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 224 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 225 | 225 | } |
| 226 | 226 | if ($geometry->geometryType() == 'LineString') { |
| 227 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 227 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 228 | 228 | } |
| 229 | 229 | if ($geometry->geometryType() == 'MultiLineString') { |
| 230 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 230 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 231 | 231 | } |
| 232 | 232 | break; |
| 233 | 233 | case 'numPoints': |
| 234 | 234 | if ($geometry->geometryType() == 'Point') { |
| 235 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 235 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 236 | 236 | } |
| 237 | 237 | if ($geometry->geometryType() == 'LineString') { |
| 238 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 238 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 239 | 239 | } |
| 240 | 240 | if ($geometry->geometryType() == 'MultiLineString') { |
| 241 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 241 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 242 | 242 | } |
| 243 | 243 | break; |
| 244 | 244 | case 'dimension': |
| 245 | 245 | if ($geometry->geometryType() == 'Point') { |
| 246 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 246 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 247 | 247 | } |
| 248 | 248 | if ($geometry->geometryType() == 'LineString') { |
| 249 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 249 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 250 | 250 | } |
| 251 | 251 | if ($geometry->geometryType() == 'MultiLineString') { |
| 252 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 252 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 253 | 253 | } |
| 254 | 254 | break; |
| 255 | 255 | case 'boundary': |
| 256 | 256 | if ($geometry->geometryType() == 'Point') { |
| 257 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 257 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 258 | 258 | } |
| 259 | 259 | if ($geometry->geometryType() == 'LineString') { |
| 260 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 260 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 261 | 261 | } |
| 262 | 262 | if ($geometry->geometryType() == 'MultiLineString') { |
| 263 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 263 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 264 | 264 | } |
| 265 | 265 | break; |
| 266 | 266 | case 'greatCircleLength': |
| 267 | 267 | if ($geometry->geometryType() == 'Point') { |
| 268 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 268 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 269 | 269 | } |
| 270 | 270 | if ($geometry->geometryType() == 'LineString') { |
| 271 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 271 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 272 | 272 | } |
| 273 | 273 | if ($geometry->geometryType() == 'MultiLineString') { |
| 274 | - $this->assertNotEquals($geometry->$method_name($argument), '9500.9359867418', 'Failed on ' . $method_name); |
|
| 274 | + $this->assertNotEquals($geometry->$method_name($argument), '9500.9359867418', 'Failed on '.$method_name); |
|
| 275 | 275 | } |
| 276 | 276 | break; |
| 277 | 277 | case 'haversineLength': |
| 278 | 278 | case 'area': |
| 279 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 279 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 280 | 280 | break; |
| 281 | 281 | case 'geometryType': |
| 282 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 282 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 283 | 283 | break; |
| 284 | 284 | default: |
| 285 | - $this->assertTrue($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 285 | + $this->assertTrue($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -9,78 +9,78 @@ |
||
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function testGeos() { |
| 12 | - foreach (scandir('./input') as $file) { |
|
| 13 | - $parts = explode('.',$file); |
|
| 14 | - if ($parts[0]) { |
|
| 15 | - $format = $parts[1]; |
|
| 16 | - $value = file_get_contents('./input/'.$file); |
|
| 17 | - $geometry = geoPHP::load($value, $format); |
|
| 12 | + foreach (scandir('./input') as $file) { |
|
| 13 | + $parts = explode('.',$file); |
|
| 14 | + if ($parts[0]) { |
|
| 15 | + $format = $parts[1]; |
|
| 16 | + $value = file_get_contents('./input/'.$file); |
|
| 17 | + $geometry = geoPHP::load($value, $format); |
|
| 18 | 18 | |
| 19 | - $geosMethods = array( |
|
| 20 | - array('name' => 'geos'), |
|
| 21 | - array('name' => 'setGeos', 'argument' => $geometry->geos()), |
|
| 22 | - array('name' => 'PointOnSurface'), |
|
| 23 | - array('name' => 'equals', 'argument' => $geometry), |
|
| 24 | - array('name' => 'equalsExact', 'argument' => $geometry), |
|
| 25 | - array('name' => 'relate', 'argument' => $geometry), |
|
| 26 | - array('name' => 'checkValidity'), |
|
| 27 | - array('name' => 'isSimple'), |
|
| 28 | - array('name' => 'buffer', 'argument' => '10'), |
|
| 29 | - array('name' => 'intersection', 'argument' => $geometry), |
|
| 30 | - array('name' => 'convexHull'), |
|
| 31 | - array('name' => 'difference', 'argument' => $geometry), |
|
| 32 | - array('name' => 'symDifference', 'argument' => $geometry), |
|
| 33 | - array('name' => 'union', 'argument' => $geometry), |
|
| 34 | - array('name' => 'simplify', 'argument' => '0'), |
|
| 35 | - array('name' => 'disjoint', 'argument' => $geometry), |
|
| 36 | - array('name' => 'touches', 'argument' => $geometry), |
|
| 37 | - array('name' => 'intersects', 'argument' => $geometry), |
|
| 38 | - array('name' => 'crosses', 'argument' => $geometry), |
|
| 39 | - array('name' => 'within', 'argument' => $geometry), |
|
| 40 | - array('name' => 'contains', 'argument' => $geometry), |
|
| 41 | - array('name' => 'overlaps', 'argument' => $geometry), |
|
| 42 | - array('name' => 'covers', 'argument' => $geometry), |
|
| 43 | - array('name' => 'coveredBy', 'argument' => $geometry), |
|
| 44 | - array('name' => 'distance', 'argument' => $geometry), |
|
| 45 | - array('name' => 'hausdorffDistance', 'argument' => $geometry), |
|
| 46 | - ); |
|
| 19 | + $geosMethods = array( |
|
| 20 | + array('name' => 'geos'), |
|
| 21 | + array('name' => 'setGeos', 'argument' => $geometry->geos()), |
|
| 22 | + array('name' => 'PointOnSurface'), |
|
| 23 | + array('name' => 'equals', 'argument' => $geometry), |
|
| 24 | + array('name' => 'equalsExact', 'argument' => $geometry), |
|
| 25 | + array('name' => 'relate', 'argument' => $geometry), |
|
| 26 | + array('name' => 'checkValidity'), |
|
| 27 | + array('name' => 'isSimple'), |
|
| 28 | + array('name' => 'buffer', 'argument' => '10'), |
|
| 29 | + array('name' => 'intersection', 'argument' => $geometry), |
|
| 30 | + array('name' => 'convexHull'), |
|
| 31 | + array('name' => 'difference', 'argument' => $geometry), |
|
| 32 | + array('name' => 'symDifference', 'argument' => $geometry), |
|
| 33 | + array('name' => 'union', 'argument' => $geometry), |
|
| 34 | + array('name' => 'simplify', 'argument' => '0'), |
|
| 35 | + array('name' => 'disjoint', 'argument' => $geometry), |
|
| 36 | + array('name' => 'touches', 'argument' => $geometry), |
|
| 37 | + array('name' => 'intersects', 'argument' => $geometry), |
|
| 38 | + array('name' => 'crosses', 'argument' => $geometry), |
|
| 39 | + array('name' => 'within', 'argument' => $geometry), |
|
| 40 | + array('name' => 'contains', 'argument' => $geometry), |
|
| 41 | + array('name' => 'overlaps', 'argument' => $geometry), |
|
| 42 | + array('name' => 'covers', 'argument' => $geometry), |
|
| 43 | + array('name' => 'coveredBy', 'argument' => $geometry), |
|
| 44 | + array('name' => 'distance', 'argument' => $geometry), |
|
| 45 | + array('name' => 'hausdorffDistance', 'argument' => $geometry), |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - foreach($geosMethods as $method) { |
|
| 49 | - $argument = NULL; |
|
| 50 | - $method_name = $method['name']; |
|
| 51 | - if (isset($method['argument'])) { |
|
| 52 | - $argument = $method['argument']; |
|
| 53 | - } |
|
| 48 | + foreach($geosMethods as $method) { |
|
| 49 | + $argument = NULL; |
|
| 50 | + $method_name = $method['name']; |
|
| 51 | + if (isset($method['argument'])) { |
|
| 52 | + $argument = $method['argument']; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - switch ($method_name) { |
|
| 56 | - case 'isSimple': |
|
| 57 | - case 'equals': |
|
| 58 | - case 'geos': |
|
| 59 | - if ($geometry->geometryType() == 'Point') { |
|
| 60 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 61 | - } |
|
| 62 | - if ($geometry->geometryType() == 'LineString') { |
|
| 63 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 64 | - } |
|
| 65 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 66 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 67 | - } |
|
| 68 | - break; |
|
| 69 | - default: |
|
| 70 | - if ($geometry->geometryType() == 'Point') { |
|
| 71 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 72 | - } |
|
| 73 | - if ($geometry->geometryType() == 'LineString') { |
|
| 74 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 75 | - } |
|
| 76 | - if ($geometry->geometryType() == 'MultiLineString') { |
|
| 77 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 55 | + switch ($method_name) { |
|
| 56 | + case 'isSimple': |
|
| 57 | + case 'equals': |
|
| 58 | + case 'geos': |
|
| 59 | + if ($geometry->geometryType() == 'Point') { |
|
| 60 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 61 | + } |
|
| 62 | + if ($geometry->geometryType() == 'LineString') { |
|
| 63 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 64 | + } |
|
| 65 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 66 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 67 | + } |
|
| 68 | + break; |
|
| 69 | + default: |
|
| 70 | + if ($geometry->geometryType() == 'Point') { |
|
| 71 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 72 | + } |
|
| 73 | + if ($geometry->geometryType() == 'LineString') { |
|
| 74 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 75 | + } |
|
| 76 | + if ($geometry->geometryType() == 'MultiLineString') { |
|
| 77 | + $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - } |
|
| 83 | - } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | function testGeos() { |
| 12 | 12 | foreach (scandir('./input') as $file) { |
| 13 | - $parts = explode('.',$file); |
|
| 13 | + $parts = explode('.', $file); |
|
| 14 | 14 | if ($parts[0]) { |
| 15 | 15 | $format = $parts[1]; |
| 16 | 16 | $value = file_get_contents('./input/'.$file); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | array('name' => 'hausdorffDistance', 'argument' => $geometry), |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | - foreach($geosMethods as $method) { |
|
| 48 | + foreach ($geosMethods as $method) { |
|
| 49 | 49 | $argument = NULL; |
| 50 | 50 | $method_name = $method['name']; |
| 51 | 51 | if (isset($method['argument'])) { |
@@ -57,24 +57,24 @@ discard block |
||
| 57 | 57 | case 'equals': |
| 58 | 58 | case 'geos': |
| 59 | 59 | if ($geometry->geometryType() == 'Point') { |
| 60 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 60 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 61 | 61 | } |
| 62 | 62 | if ($geometry->geometryType() == 'LineString') { |
| 63 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 63 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 64 | 64 | } |
| 65 | 65 | if ($geometry->geometryType() == 'MultiLineString') { |
| 66 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 66 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 67 | 67 | } |
| 68 | 68 | break; |
| 69 | 69 | default: |
| 70 | 70 | if ($geometry->geometryType() == 'Point') { |
| 71 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 71 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 72 | 72 | } |
| 73 | 73 | if ($geometry->geometryType() == 'LineString') { |
| 74 | - $this->assertNotNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 74 | + $this->assertNotNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 75 | 75 | } |
| 76 | 76 | if ($geometry->geometryType() == 'MultiLineString') { |
| 77 | - $this->assertNull($geometry->$method_name($argument), 'Failed on ' . $method_name); |
|
| 77 | + $this->assertNull($geometry->$method_name($argument), 'Failed on '.$method_name); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |