@@ -22,7 +22,9 @@ discard block |
||
22 | 22 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
23 | 23 | $aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
24 | 24 | $airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
25 | - if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
|
25 | + if ($registration == '' && $aircraft_icao != '') { |
|
26 | + $registration = $aircraft_icao.$airline_icao; |
|
27 | + } |
|
26 | 28 | $registration = trim($registration); |
27 | 29 | $query = "SELECT spotter_image.image, spotter_image.image_thumbnail, spotter_image.image_source, spotter_image.image_source_website,spotter_image.image_copyright, spotter_image.registration |
28 | 30 | FROM spotter_image |
@@ -60,8 +62,11 @@ discard block |
||
60 | 62 | public function getExifCopyright($url) { |
61 | 63 | $exif = exif_read_data($url); |
62 | 64 | $copyright = ''; |
63 | - if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright']; |
|
64 | - elseif (isset($exif['copyright'])) $copyright = $exif['copyright']; |
|
65 | + if (isset($exif['COMPUTED']['copyright'])) { |
|
66 | + $copyright = $exif['COMPUTED']['copyright']; |
|
67 | + } elseif (isset($exif['copyright'])) { |
|
68 | + $copyright = $exif['copyright']; |
|
69 | + } |
|
65 | 70 | if ($copyright != '') { |
66 | 71 | $copyright = str_replace('Copyright ','',$copyright); |
67 | 72 | $copyright = str_replace('© ','',$copyright); |
@@ -79,18 +84,29 @@ discard block |
||
79 | 84 | public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '') |
80 | 85 | { |
81 | 86 | global $globalDebug,$globalAircraftImageFetch; |
82 | - if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) return ''; |
|
87 | + if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) { |
|
88 | + return ''; |
|
89 | + } |
|
83 | 90 | $registration = filter_var($registration,FILTER_SANITIZE_STRING); |
84 | 91 | $registration = trim($registration); |
85 | 92 | //getting the aircraft image |
86 | - if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...'; |
|
87 | - elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
|
88 | - elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
|
89 | - else return "success"; |
|
93 | + if ($globalDebug && $registration != '') { |
|
94 | + echo 'Try to find an aircraft image for '.$registration.'...'; |
|
95 | + } elseif ($globalDebug && $aircraft_icao != '') { |
|
96 | + echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
|
97 | + } elseif ($globalDebug && $airline_icao != '') { |
|
98 | + echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
|
99 | + } else { |
|
100 | + return "success"; |
|
101 | + } |
|
90 | 102 | $image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao); |
91 | - if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
|
103 | + if ($registration == '' && $aircraft_icao != '') { |
|
104 | + $registration = $aircraft_icao.$airline_icao; |
|
105 | + } |
|
92 | 106 | if ($image_url['original'] != '') { |
93 | - if ($globalDebug) echo 'Found !'."\n"; |
|
107 | + if ($globalDebug) { |
|
108 | + echo 'Found !'."\n"; |
|
109 | + } |
|
94 | 110 | $query = "INSERT INTO spotter_image (registration, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:registration,:image,:image_thumbnail,:copyright,:source,:source_website)"; |
95 | 111 | try { |
96 | 112 | $sth = $this->db->prepare($query); |
@@ -99,7 +115,9 @@ discard block |
||
99 | 115 | echo $e->getMessage()."\n"; |
100 | 116 | return "error"; |
101 | 117 | } |
102 | - } elseif ($globalDebug) echo "Not found :'(\n"; |
|
118 | + } elseif ($globalDebug) { |
|
119 | + echo "Not found :'(\n"; |
|
120 | + } |
|
103 | 121 | return "success"; |
104 | 122 | } |
105 | 123 | |
@@ -114,36 +132,75 @@ discard block |
||
114 | 132 | { |
115 | 133 | global $globalAircraftImageSources, $globalIVAO; |
116 | 134 | $Spotter = new Spotter($this->db); |
117 | - if (!isset($globalIVAO)) $globalIVAO = FALSE; |
|
135 | + if (!isset($globalIVAO)) { |
|
136 | + $globalIVAO = FALSE; |
|
137 | + } |
|
118 | 138 | $aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING); |
119 | 139 | if ($aircraft_registration != '') { |
120 | - if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
140 | + if (strpos($aircraft_registration,'/') !== false) { |
|
141 | + return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
|
142 | + } |
|
121 | 143 | $aircraft_registration = urlencode(trim($aircraft_registration)); |
122 | 144 | $aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration); |
123 | - if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name']; |
|
124 | - else $aircraft_name = ''; |
|
125 | - if (isset($aircraft_info[0]['aircraft_icao'])) $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
|
126 | - else $aircraft_icao = ''; |
|
127 | - if (isset($aircraft_info[0]['airline_icao'])) $airline_icao = $aircraft_info[0]['airline_icao']; |
|
128 | - else $airline_icao = ''; |
|
145 | + if (isset($aircraft_info[0]['aircraft_name'])) { |
|
146 | + $aircraft_name = $aircraft_info[0]['aircraft_name']; |
|
147 | + } else { |
|
148 | + $aircraft_name = ''; |
|
149 | + } |
|
150 | + if (isset($aircraft_info[0]['aircraft_icao'])) { |
|
151 | + $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
|
152 | + } else { |
|
153 | + $aircraft_icao = ''; |
|
154 | + } |
|
155 | + if (isset($aircraft_info[0]['airline_icao'])) { |
|
156 | + $airline_icao = $aircraft_info[0]['airline_icao']; |
|
157 | + } else { |
|
158 | + $airline_icao = ''; |
|
159 | + } |
|
129 | 160 | } elseif ($aircraft_icao != '') { |
130 | 161 | $aircraft_registration = $aircraft_icao; |
131 | 162 | $aircraft_name = ''; |
132 | - } else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
133 | - if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
|
163 | + } else { |
|
164 | + return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
|
165 | + } |
|
166 | + if (!isset($globalAircraftImageSources)) { |
|
167 | + $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
|
168 | + } |
|
134 | 169 | foreach ($globalAircraftImageSources as $source) { |
135 | 170 | $source = strtolower($source); |
136 | - if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl($aircraft_icao,$airline_icao); |
|
137 | - if ($source == 'planespotters' && !$globalIVAO) $images_array = $this->fromPlanespotters($aircraft_registration,$aircraft_name); |
|
138 | - if ($source == 'flickr') $images_array = $this->fromFlickr($aircraft_registration,$aircraft_name); |
|
139 | - if ($source == 'bing') $images_array = $this->fromBing($aircraft_registration,$aircraft_name); |
|
140 | - if ($source == 'deviantart') $images_array = $this->fromDeviantart($aircraft_registration,$aircraft_name); |
|
141 | - if ($source == 'wikimedia') $images_array = $this->fromWikimedia($aircraft_registration,$aircraft_name); |
|
142 | - if ($source == 'jetphotos' && !$globalIVAO) $images_array = $this->fromJetPhotos($aircraft_registration,$aircraft_name); |
|
143 | - if ($source == 'planepictures' && !$globalIVAO) $images_array = $this->fromPlanePictures($aircraft_registration,$aircraft_name); |
|
144 | - if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData($aircraft_registration,$aircraft_name); |
|
145 | - if ($source == 'customsources') $images_array = $this->fromCustomSource($aircraft_registration,$aircraft_name); |
|
146 | - if (isset($images_array) && $images_array['original'] != '') return $images_array; |
|
171 | + if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') { |
|
172 | + $images_array = $this->fromIvaoMtl($aircraft_icao,$airline_icao); |
|
173 | + } |
|
174 | + if ($source == 'planespotters' && !$globalIVAO) { |
|
175 | + $images_array = $this->fromPlanespotters($aircraft_registration,$aircraft_name); |
|
176 | + } |
|
177 | + if ($source == 'flickr') { |
|
178 | + $images_array = $this->fromFlickr($aircraft_registration,$aircraft_name); |
|
179 | + } |
|
180 | + if ($source == 'bing') { |
|
181 | + $images_array = $this->fromBing($aircraft_registration,$aircraft_name); |
|
182 | + } |
|
183 | + if ($source == 'deviantart') { |
|
184 | + $images_array = $this->fromDeviantart($aircraft_registration,$aircraft_name); |
|
185 | + } |
|
186 | + if ($source == 'wikimedia') { |
|
187 | + $images_array = $this->fromWikimedia($aircraft_registration,$aircraft_name); |
|
188 | + } |
|
189 | + if ($source == 'jetphotos' && !$globalIVAO) { |
|
190 | + $images_array = $this->fromJetPhotos($aircraft_registration,$aircraft_name); |
|
191 | + } |
|
192 | + if ($source == 'planepictures' && !$globalIVAO) { |
|
193 | + $images_array = $this->fromPlanePictures($aircraft_registration,$aircraft_name); |
|
194 | + } |
|
195 | + if ($source == 'airportdata' && !$globalIVAO) { |
|
196 | + $images_array = $this->fromAirportData($aircraft_registration,$aircraft_name); |
|
197 | + } |
|
198 | + if ($source == 'customsources') { |
|
199 | + $images_array = $this->fromCustomSource($aircraft_registration,$aircraft_name); |
|
200 | + } |
|
201 | + if (isset($images_array) && $images_array['original'] != '') { |
|
202 | + return $images_array; |
|
203 | + } |
|
147 | 204 | } |
148 | 205 | return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
149 | 206 | } |
@@ -301,8 +358,11 @@ discard block |
||
301 | 358 | */ |
302 | 359 | public function fromFlickr($aircraft_registration,$aircraft_name='') { |
303 | 360 | $Common = new Common(); |
304 | - if ($aircraft_name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.','.urlencode($aircraft_name); |
|
305 | - else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.',aircraft'; |
|
361 | + if ($aircraft_name != '') { |
|
362 | + $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.','.urlencode($aircraft_name); |
|
363 | + } else { |
|
364 | + $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.',aircraft'; |
|
365 | + } |
|
306 | 366 | $data = $Common->getData($url); |
307 | 367 | if ($xml = simplexml_load_string($data)) { |
308 | 368 | if (isset($xml->channel->item)) { |
@@ -346,9 +406,14 @@ discard block |
||
346 | 406 | public function fromBing($aircraft_registration,$aircraft_name='') { |
347 | 407 | global $globalImageBingKey; |
348 | 408 | $Common = new Common(); |
349 | - if (!isset($globalImageBingKey) || $globalImageBingKey == '') return false; |
|
350 | - if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27'; |
|
351 | - else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27'; |
|
409 | + if (!isset($globalImageBingKey) || $globalImageBingKey == '') { |
|
410 | + return false; |
|
411 | + } |
|
412 | + if ($aircraft_name != '') { |
|
413 | + $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27'; |
|
414 | + } else { |
|
415 | + $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27'; |
|
416 | + } |
|
352 | 417 | $headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey)); |
353 | 418 | $data = $Common->getData($url,'get','',$headers); |
354 | 419 | $result = json_decode($data); |
@@ -402,13 +467,18 @@ discard block |
||
402 | 467 | */ |
403 | 468 | public function fromWikimedia($aircraft_registration,$aircraft_name='') { |
404 | 469 | $Common = new Common(); |
405 | - if ($aircraft_name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20'.urlencode($aircraft_name); |
|
406 | - else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20aircraft'; |
|
470 | + if ($aircraft_name != '') { |
|
471 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20'.urlencode($aircraft_name); |
|
472 | + } else { |
|
473 | + $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20aircraft'; |
|
474 | + } |
|
407 | 475 | $data = $Common->getData($url); |
408 | 476 | $result = json_decode($data); |
409 | 477 | if (isset($result->query->search[0]->title)) { |
410 | 478 | $fileo = $result->query->search[0]->title; |
411 | - if (substr($fileo,-3) == 'pdf') return false; |
|
479 | + if (substr($fileo,-3) == 'pdf') { |
|
480 | + return false; |
|
481 | + } |
|
412 | 482 | $file = urlencode($fileo); |
413 | 483 | $url2 = 'https://commons.wikimedia.org/w/api.php?action=query&format=json&continue&iilimit=500&prop=imageinfo&iiprop=user|url|size|mime|sha1|timestamp&iiurlwidth=200%27&titles='.$file; |
414 | 484 | $data2 = $Common->getData($url2); |
@@ -478,17 +548,25 @@ discard block |
||
478 | 548 | $image_url = array(); |
479 | 549 | $image_url['thumbnail'] = $url_thumbnail; |
480 | 550 | $image_url['original'] = $url; |
481 | - if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
|
482 | - else $exifCopyright = ''; |
|
483 | - if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
|
484 | - else $image_url['copyright'] = $source['copyright']; |
|
551 | + if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) { |
|
552 | + $exifCopyright = $this->getExifCopyright($url); |
|
553 | + } else { |
|
554 | + $exifCopyright = ''; |
|
555 | + } |
|
556 | + if ($exifCopyright != '') { |
|
557 | + $image_url['copyright'] = $exifCopyright; |
|
558 | + } else { |
|
559 | + $image_url['copyright'] = $source['copyright']; |
|
560 | + } |
|
485 | 561 | $image_url['source_website'] = $source['source_website']; |
486 | 562 | $image_url['source'] = $source['source']; |
487 | 563 | return $image_url; |
488 | 564 | } |
489 | 565 | } |
490 | 566 | return false; |
491 | - } else return false; |
|
567 | + } else { |
|
568 | + return false; |
|
569 | + } |
|
492 | 570 | } |
493 | 571 | } |
494 | 572 |