Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / search-rss.php
blob9fd6dbe7f0c14e2f59712d777f91277a5db24b27
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Language.php');
5 $Spotter = new Spotter();
6 if (isset($_GET['start_date'])) {
7 //for the date manipulation into the query
8 if($_GET['start_date'] != "" && $_GET['end_date'] != ""){
9 $start_date = date("Y-m-d",strtotime($_GET['start_date']))." 00:00:00";
10 $end_date = date("Y-m-d",strtotime($_GET['end_date']))." 00:00:00";
11 $sql_date = $start_date.",".$end_date;
12 } else if($_GET['start_date'] != ""){
13 $start_date = date("Y-m-d",strtotime($_GET['start_date']))." 00:00:00";
14 $sql_date = $start_date;
15 } else if($_GET['start_date'] == "" && $_GET['end_date'] != ""){
16 $end_date = date("Y-m-d H:i:s", strtotime("2014-04-12")).",".date("Y-m-d",strtotime($_GET['end_date']))." 00:00:00";
17 $sql_date = $end_date;
18 } else $sql_date = '';
19 } else $sql_date = '';
21 if (isset($_GET['highest_altitude'])) {
22 //for altitude manipulation
23 if($_GET['highest_altitude'] != "" && $_GET['lowest_altitude'] != ""){
24 $end_altitude = filter_input(INPUT_GET,'highest_altitude',FILTER_SANITIZE_NUMBER_INT);
25 $start_altitude = filter_input(INPUT_GET,'lowest_altitude',FILTER_SANITIZE_NUMBER_INT);
26 $sql_altitude = $start_altitude.",".$end_altitude;
27 } else if($_GET['highest_altitude'] != ""){
28 $end_altitude = filter_input(INPUT_GET,'highest_altitude',FILTER_SANITIZE_NUMBER_INT);
29 $sql_altitude = $end_altitude;
30 } else if($_GET['highest_altitude'] == "" && $_GET['lowest_altitude'] != ""){
31 $start_altitude = filter_input(INPUT_GET,'lowest_altitude',FILTER_SANITIZE_NUMBER_INT).",60000";
32 $sql_altitude = $start_altitude;
33 } else $sql_altitude = '';
34 } else $sql_altitude = '';
36 //calculuation for the pagination
37 if(!isset($_GET['limit'])) {
38 if (!isset($_GET['number_results'])) {
39 $limit_start = 0;
40 $limit_end = 25;
41 $absolute_difference = 25;
42 } else {
43 if ($_GET['number_results'] > 1000){
44 $_GET['number_results'] = 1000;
46 $limit_start = 0;
47 $limit_end = filter_input(INPUT_GET,'number_results',FILTER_SANITIZE_NUMBER_INT);
48 $absolute_difference = filter_input(INPUT_GET,'number_results',FILTER_SANITIZE_NUMBER_INT);
50 } else {
51 $limit_explode = explode(",", $_GET['limit']);
52 $limit_start = filter_var($limit_explode[0],FILTER_SANITIZE_NUMBER_INT);
53 $limit_end = filter_var($limit_explode[1],FILTER_SANITIZE_NUMBER_INT);
56 $absolute_difference = abs($limit_start - $limit_end);
57 $limit_next = $limit_end + $absolute_difference;
58 $limit_previous_1 = $limit_start - $absolute_difference;
59 $limit_previous_2 = $limit_end - $absolute_difference;
61 if ($_GET['download'] == "true")
63 header('Content-disposition: attachment; filename="flightairmap.rss"');
66 header('Content-Type: application/rss+xml; charset=utf-8');
68 $date = date("D, d M Y H:i:s T", time());
69 if (isset($_GET['sort'])) $sort = $_GET['sort'];
70 else $sort = '';
71 $q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING);
72 $id = filter_input(INPUT_GET,'id',FILTER_SANITIZE_NUMBER_INT);
73 $registration = filter_input(INPUT_GET,'registratrion',FILTER_SANITIZE_STRING);
74 $aircraft = filter_input(INPUT_GET,'aircraft',FILTER_SANITIZE_STRING);
75 $manufacturer = filter_input(INPUT_GET,'manufacturer',FILTER_SANITIZE_STRING);
76 $highlights = filter_input(INPUT_GET,'highlights',FILTER_SANITIZE_STRING);
77 $airline = filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING);
78 $airline_country = filter_input(INPUT_GET,'airline_country',FILTER_SANITIZE_STRING);
79 $airline_type = filter_input(INPUT_GET,'airline_type',FILTER_SANITIZE_STRING);
80 $airport = filter_input(INPUT_GET,'airport',FILTER_SANITIZE_STRING);
81 $airport_country = filter_input(INPUT_GET,'airport_country',FILTER_SANITIZE_STRING);
82 $callsign = filter_input(INPUT_GET,'callsign',FILTER_SANITIZE_STRING);
83 $owner = filter_input(INPUT_GET,'owner',FILTER_SANITIZE_STRING);
84 $pilot_id = filter_input(INPUT_GET,'pilot_id',FILTER_SANITIZE_STRING);
85 $pilot_name = filter_input(INPUT_GET,'pilot_name',FILTER_SANITIZE_STRING);
86 $departure_airport_route = filter_input(INPUT_GET,'departure_airport_route',FILTER_SANITIZE_STRING);
87 $arrival_airport_route = filter_input(INPUT_GET,'arrival_airport_route',FILTER_SANITIZE_STRING);
88 if ($id != '') {
89 $spotter_array = $Spotter->getSpotterDataByID($id);
90 } else {
91 $spotter_array = $Spotter->searchSpotterData($q,$registration,$aircraft,strtolower(str_replace("-", " ", $manufacturer)),$highlights,$airline,$airline_country,$airline_type,$airport,$airport_country,$callsign,$departure_airport_route,$arrival_airport_route,$owner,$pilot_id,$pilot_name,$sql_altitude,$sql_date,$limit_start.",".$absolute_difference,$sort,'');
93 print '<?xml version="1.0" encoding="UTF-8" ?>';
94 print '<rss xmlns:flightairmap="http://'.$_SERVER['HTTP_HOST'].''.htmlentities($_SERVER['REQUEST_URI']).'" version="2.0">';
96 print '<channel>';
97 print '<title>FlightAirMap RSS Feed</title>';
98 print '<link>http://www.flightairmap.fr/</link>';
99 print '<description>The latest airplanes</description>';
100 print '<language>en-ca</language>';
101 print '<lastBuildDate>'.$date.'</lastBuildDate>';
103 if (!empty($spotter_array)) {
104 foreach($spotter_array as $spotter_item) {
105 print '<item>';
106 print '<title>'.$spotter_item['ident'].' '.$spotter_item['airline_name'].' | '.$spotter_item['registration'].' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].') | '.$spotter_item['departure_airport'].' - '.$spotter_item['arrival_airport'].'</title>';
107 print '<link>http://www.flightairmap.fr/flightid/'.$spotter_item['spotter_id'].'</link>';
108 print '<guid isPermaLink="false">http://www.flightairmap.fr/flightid/'.$spotter_item['spotter_id'].'</guid>';
109 print '<description>Ident: '.$spotter_item['ident'].' | Registration: '.$spotter_item['registration'].' | Aircraft: '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].') | Airline: '.$spotter_item['airline_name'].' | Coming From: '.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_name'].', '.$spotter_item['departure_airport_country'].' ('.$spotter_item['departure_airport'].') | Flying to: '.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_name'].', '.$spotter_item['arrival_airport_country'].' ('.$spotter_item['arrival_airport'].') | Flew nearby on: '.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'</description>';
110 print '<pubDate>'.$date.'</pubDate>';
111 print '</item>';
114 print '</channel>';
115 print '</rss>';