1
|
|
|
<?php |
2
|
|
|
require_once(dirname(__FILE__).'/class.Spotter.php'); |
3
|
|
|
require_once(dirname(__FILE__).'/class.Common.php'); |
4
|
|
|
require_once(dirname(__FILE__).'/settings.php'); |
5
|
|
|
|
6
|
|
|
class Image { |
7
|
|
|
public $db; |
8
|
|
|
|
9
|
|
|
public function __construct($dbc = null) { |
10
|
|
|
$Connection = new Connection($dbc); |
11
|
|
|
$this->db = $Connection->db(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Gets the images based on the aircraft registration |
16
|
|
|
* |
17
|
|
|
* @return Array the images list |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
public function getSpotterImage($registration,$aircraft_icao = '', $airline_icao = '') |
21
|
|
|
{ |
22
|
|
|
$registration = filter_var($registration,FILTER_SANITIZE_STRING); |
23
|
|
|
$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
24
|
|
|
$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
25
|
|
|
if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
26
|
|
|
$registration = trim($registration); |
27
|
|
|
$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
|
|
|
FROM spotter_image |
29
|
|
|
WHERE spotter_image.registration = :registration"; |
30
|
|
|
$sth = $this->db->prepare($query); |
31
|
|
|
$sth->execute(array(':registration' => $registration)); |
32
|
|
|
/* |
33
|
|
|
$images_array = array(); |
34
|
|
|
$temp_array = array(); |
35
|
|
|
|
36
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
37
|
|
|
{ |
38
|
|
|
//$temp_array['spotter_image_id'] = $row['spotter_image_id']; |
39
|
|
|
$temp_array['registration'] = $row['registration']; |
40
|
|
|
$temp_array['image'] = $row['image']; |
41
|
|
|
$temp_array['image_thumbnail'] = $row['image_thumbnail']; |
42
|
|
|
$temp_array['image_source'] = $row['image_source']; |
43
|
|
|
$temp_array['image_source_website'] = $row['image_source_website']; |
44
|
|
|
$temp_array['image_copyright'] = $row['image_copyright']; |
45
|
|
|
|
46
|
|
|
$images_array[] = $temp_array; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $images_array; |
50
|
|
|
*/ |
51
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Gets the image copyright based on the Exif data |
56
|
|
|
* |
57
|
|
|
* @return String image copyright |
58
|
|
|
* |
59
|
|
|
*/ |
60
|
|
|
public function getExifCopyright($url) { |
61
|
|
|
$exif = exif_read_data($url); |
62
|
|
|
$copyright = ''; |
63
|
|
|
if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright']; |
64
|
|
|
elseif (isset($exif['copyright'])) $copyright = $exif['copyright']; |
65
|
|
|
if ($copyright != '') { |
66
|
|
|
$copyright = str_replace('Copyright ','',$copyright); |
67
|
|
|
$copyright = str_replace('© ','',$copyright); |
68
|
|
|
$copyright = str_replace('(c) ','',$copyright); |
69
|
|
|
} |
70
|
|
|
return $copyright; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Adds the images based on the aircraft registration |
75
|
|
|
* |
76
|
|
|
* @return String either success or error |
77
|
|
|
* |
78
|
|
|
*/ |
79
|
|
|
public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '') |
80
|
|
|
{ |
81
|
|
|
global $globalDebug,$globalAircraftImageFetch; |
82
|
|
|
if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) return ''; |
83
|
|
|
$registration = filter_var($registration,FILTER_SANITIZE_STRING); |
84
|
|
|
$registration = trim($registration); |
85
|
|
|
//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"; |
90
|
|
|
$image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao); |
91
|
|
|
if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
92
|
|
|
if ($image_url['original'] != '') { |
93
|
|
|
if ($globalDebug) echo 'Found !'."\n"; |
94
|
|
|
$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
|
|
|
try { |
96
|
|
|
$sth = $this->db->prepare($query); |
97
|
|
|
$sth->execute(array(':registration' => $registration,':image' => $image_url['original'],':image_thumbnail' => $image_url['thumbnail'], ':copyright' => $image_url['copyright'],':source' => $image_url['source'],':source_website' => $image_url['source_website'])); |
98
|
|
|
} catch(PDOException $e) { |
99
|
|
|
echo $e->getMessage()."\n"; |
100
|
|
|
return "error"; |
101
|
|
|
} |
102
|
|
|
} elseif ($globalDebug) echo "Not found :'(\n"; |
103
|
|
|
return "success"; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Gets the aircraft image |
108
|
|
|
* |
109
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
110
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
111
|
|
|
* |
112
|
|
|
*/ |
113
|
|
|
public function findAircraftImage($aircraft_registration, $aircraft_icao = '', $airline_icao = '') |
114
|
|
|
{ |
115
|
|
|
global $globalAircraftImageSources, $globalIVAO; |
116
|
|
|
$Spotter = new Spotter($this->db); |
117
|
|
|
if (!isset($globalIVAO)) $globalIVAO = FALSE; |
118
|
|
|
$aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING); |
119
|
|
|
if ($aircraft_registration != '') { |
120
|
|
|
if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
121
|
|
|
$aircraft_registration = urlencode(trim($aircraft_registration)); |
122
|
|
|
$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 = ''; |
129
|
|
|
} elseif ($aircraft_icao != '') { |
130
|
|
|
$aircraft_registration = $aircraft_icao; |
131
|
|
|
$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'); |
134
|
|
|
foreach ($globalAircraftImageSources as $source) { |
135
|
|
|
$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; |
147
|
|
|
} |
148
|
|
|
return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Gets the aircraft image from Planespotters |
153
|
|
|
* |
154
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
155
|
|
|
* @param String $aircraft_name type of the aircraft |
156
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
157
|
|
|
* |
158
|
|
|
*/ |
159
|
|
|
public function fromPlanespotters($aircraft_registration, $aircraft_name='') { |
160
|
|
|
$Common = new Common(); |
161
|
|
|
// If aircraft registration is only number, also check with aircraft model |
162
|
|
|
if (preg_match('/^[[:digit]]+$/',$aircraft_registration) && $aircraft_name != '') { |
163
|
|
|
$url= 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$aircraft_registration.'&actype=s_'.urlencode($aircraft_name).'&output=rss'; |
164
|
|
|
} else { |
165
|
|
|
//$url= 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$airline_aircraft_type.'&output=rss'; |
166
|
|
|
$url= 'http://www.planespotters.net/Aviation_Photos/search.php?reg='.$aircraft_registration.'&output=rss'; |
167
|
|
|
} |
168
|
|
|
$data = $Common->getData($url); |
169
|
|
|
if ($xml = simplexml_load_string($data)) { |
170
|
|
|
if (isset($xml->channel->item)) { |
171
|
|
|
$image_url = array(); |
172
|
|
|
$thumbnail_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url); |
173
|
|
|
$image_url['thumbnail'] = $thumbnail_url; |
174
|
|
|
$image_url['original'] = str_replace('thumbnail','original',$thumbnail_url); |
175
|
|
|
$image_url['copyright'] = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright); |
176
|
|
|
$image_url['source_website'] = trim((string)$xml->channel->item->link); |
177
|
|
|
$image_url['source'] = 'planespotters'; |
178
|
|
|
return $image_url; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
return false; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Gets the aircraft image from Deviantart |
186
|
|
|
* |
187
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
188
|
|
|
* @param String $aircraft_name type of the aircraft |
189
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
190
|
|
|
* |
191
|
|
|
*/ |
192
|
|
|
public function fromDeviantart($aircraft_registration, $aircraft_name='') { |
193
|
|
|
$Common = new Common(); |
194
|
|
|
// If aircraft registration is only number, also check with aircraft model |
195
|
|
|
if (preg_match('/^[[:digit]]+$/',$aircraft_registration) && $aircraft_name != '') { |
196
|
|
|
$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q='.$aircraft_registration.'%20'.urlencode($aircraft_name); |
197
|
|
|
} else { |
198
|
|
|
$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q=aircraft%20'.$aircraft_registration; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
$data = $Common->getData($url); |
202
|
|
|
if ($xml = simplexml_load_string($data)) { |
203
|
|
|
if (isset($xml->channel->item->link)) { |
204
|
|
|
$image_url = array(); |
205
|
|
|
$thumbnail_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url); |
206
|
|
|
$image_url['thumbnail'] = $thumbnail_url; |
207
|
|
|
$original_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->content->attributes()->url); |
208
|
|
|
$image_url['original'] = $original_url; |
209
|
|
|
$image_url['copyright'] = str_replace('Copyright ','',trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright)); |
210
|
|
|
$image_url['source_website'] = trim((string)$xml->channel->item->link); |
211
|
|
|
$image_url['source'] = 'deviantart'; |
212
|
|
|
return $image_url; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
return false; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Gets the aircraft image from JetPhotos |
220
|
|
|
* |
221
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
222
|
|
|
* @param String $aircraft_name type of the aircraft |
223
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
224
|
|
|
* |
225
|
|
|
*/ |
226
|
|
|
public function fromJetPhotos($aircraft_registration, $aircraft_name='') { |
|
|
|
|
227
|
|
|
$Common = new Common(); |
228
|
|
|
$url= 'http://jetphotos.net/showphotos.php?displaymode=2®search='.$aircraft_registration; |
229
|
|
|
$data = $Common->getData($url); |
230
|
|
|
$dom = new DOMDocument(); |
231
|
|
|
@$dom->loadHTML($data); |
|
|
|
|
232
|
|
|
$all_pics = array(); |
233
|
|
|
foreach($dom->getElementsByTagName('img') as $image) { |
234
|
|
|
if ($image->getAttribute('itemprop') == "http://schema.org/image") { |
235
|
|
|
$all_pics[] = $image->getAttribute('src'); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
$all_authors = array(); |
239
|
|
|
foreach($dom->getElementsByTagName('meta') as $author) { |
240
|
|
|
if ($author->getAttribute('itemprop') == "http://schema.org/author") { |
241
|
|
|
$all_authors[] = $author->getAttribute('content'); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
$all_ref = array(); |
245
|
|
|
foreach($dom->getElementsByTagName('a') as $link) { |
246
|
|
|
$all_ref[] = $link->getAttribute('href'); |
247
|
|
|
} |
248
|
|
|
if (isset($all_pics[0])) { |
249
|
|
|
$image_url = array(); |
250
|
|
|
$image_url['thumbnail'] = $all_pics[0]; |
251
|
|
|
$image_url['original'] = str_replace('_tb','',$all_pics[0]); |
252
|
|
|
$image_url['copyright'] = $all_authors[0]; |
253
|
|
|
$image_url['source_website'] = 'http://jetphotos.net'.$all_ref[8]; |
254
|
|
|
$image_url['source'] = 'JetPhotos'; |
255
|
|
|
return $image_url; |
256
|
|
|
} |
257
|
|
|
return false; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Gets the aircraft image from PlanePictures |
262
|
|
|
* |
263
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
264
|
|
|
* @param String $aircraft_name type of the aircraft |
265
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
266
|
|
|
* |
267
|
|
|
*/ |
268
|
|
|
public function fromPlanePictures($aircraft_registration, $aircraft_name='') { |
|
|
|
|
269
|
|
|
$Common = new Common(); |
270
|
|
|
$url= 'http://www.planepictures.net/netsearch4.cgi?srch='.$aircraft_registration.'&stype=reg&srng=2'; |
271
|
|
|
$data = $Common->getData($url); |
272
|
|
|
$dom = new DOMDocument(); |
273
|
|
|
@$dom->loadHTML($data); |
|
|
|
|
274
|
|
|
$all_pics = array(); |
275
|
|
|
foreach($dom->getElementsByTagName('img') as $image) { |
276
|
|
|
$all_pics[] = $image->getAttribute('src'); |
277
|
|
|
} |
278
|
|
|
$all_links = array(); |
279
|
|
|
foreach($dom->getElementsByTagName('a') as $link) { |
280
|
|
|
$all_links[] = array('text' => $link->textContent,'href' => $link->getAttribute('href')); |
281
|
|
|
} |
282
|
|
|
if (isset($all_pics[1]) && !preg_match('/bit.ly/',$all_pics[1])) { |
283
|
|
|
$image_url = array(); |
284
|
|
|
$image_url['thumbnail'] = 'http://www.planepictures.net'.$all_pics[1]; |
285
|
|
|
$image_url['original'] = 'http://www.planepictures.net'.str_replace('_TN','',$all_pics[1]); |
286
|
|
|
$image_url['copyright'] = $all_links[6]['text']; |
287
|
|
|
$image_url['source_website'] = 'http://www.planepictures.net/'.$all_links[2]['href']; |
288
|
|
|
$image_url['source'] = 'PlanePictures'; |
289
|
|
|
return $image_url; |
290
|
|
|
} |
291
|
|
|
return false; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Gets the aircraft image from Flickr |
296
|
|
|
* |
297
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
298
|
|
|
* @param String $aircraft_name type of the aircraft |
299
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
300
|
|
|
* |
301
|
|
|
*/ |
302
|
|
|
public function fromFlickr($aircraft_registration,$aircraft_name='') { |
303
|
|
|
$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'; |
306
|
|
|
$data = $Common->getData($url); |
307
|
|
|
if ($xml = simplexml_load_string($data)) { |
308
|
|
|
if (isset($xml->channel->item)) { |
309
|
|
|
$original_url = trim((string)$xml->channel->item->enclosure->attributes()->url); |
310
|
|
|
$image_url = array(); |
311
|
|
|
$image_url['thumbnail'] = $original_url; |
312
|
|
|
$image_url['original'] = $original_url; |
313
|
|
|
$image_url['copyright'] = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->credit); |
314
|
|
|
$image_url['source_website'] = trim((string)$xml->channel->item->link); |
315
|
|
|
$image_url['source'] = 'flickr'; |
316
|
|
|
return $image_url; |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
return false; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
public function fromIvaoMtl($aircraft_icao,$airline_icao) { |
323
|
|
|
$Common = new Common(); |
324
|
|
|
//echo "\n".'SEARCH IMAGE : http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg'; |
325
|
|
|
if ($Common->urlexist('http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg')) { |
326
|
|
|
$image_url = array(); |
327
|
|
|
$image_url['thumbnail'] = 'http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg'; |
328
|
|
|
$image_url['original'] = 'http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg'; |
329
|
|
|
$image_url['copyright'] = 'IVAO'; |
330
|
|
|
$image_url['source_website'] = 'http://mtlcatalog.ivao.aero/'; |
331
|
|
|
$image_url['source'] = 'ivao.aero'; |
332
|
|
|
return $image_url; |
333
|
|
|
} else { |
334
|
|
|
return false; |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Gets the aircraft image from Bing |
340
|
|
|
* |
341
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
342
|
|
|
* @param String $aircraft_name type of the aircraft |
343
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
344
|
|
|
* |
345
|
|
|
*/ |
346
|
|
|
public function fromBing($aircraft_registration,$aircraft_name='') { |
347
|
|
|
global $globalImageBingKey; |
348
|
|
|
$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'; |
352
|
|
|
$headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey)); |
353
|
|
|
$data = $Common->getData($url,'get','',$headers); |
354
|
|
|
$result = json_decode($data); |
355
|
|
|
if (isset($result->d->results[0]->MediaUrl)) { |
356
|
|
|
$image_url = array(); |
357
|
|
|
$image_url['original'] = $result->d->results[0]->MediaUrl; |
358
|
|
|
$image_url['source_website'] = $result->d->results[0]->SourceUrl; |
359
|
|
|
// Thumbnail can't be used this way... |
360
|
|
|
// $image_url['thumbnail'] = $result->d->results[0]->Thumbnail->MediaUrl; |
361
|
|
|
$image_url['thumbnail'] = $result->d->results[0]->MediaUrl; |
362
|
|
|
$url = parse_url($image_url['source_website']); |
363
|
|
|
$image_url['copyright'] = $url['host']; |
364
|
|
|
$image_url['source'] = 'bing'; |
365
|
|
|
return $image_url; |
366
|
|
|
} |
367
|
|
|
return false; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Gets the aircraft image from airport-data |
372
|
|
|
* |
373
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
374
|
|
|
* @param String $aircraft_name type of the aircraft |
375
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
376
|
|
|
* |
377
|
|
|
*/ |
378
|
|
|
public function fromAirportData($aircraft_registration,$aircraft_name='') { |
|
|
|
|
379
|
|
|
$Common = new Common(); |
380
|
|
|
$url = 'http://www.airport-data.com/api/ac_thumb.json?&n=1&r='.$aircraft_registration; |
381
|
|
|
$data = $Common->getData($url); |
382
|
|
|
$result = json_decode($data); |
383
|
|
|
if (isset($result->count) && $result->count > 0) { |
384
|
|
|
$image_url = array(); |
385
|
|
|
$image_url['original'] = str_replace('thumbnails','large',$result->data[0]->image); |
386
|
|
|
$image_url['source_website'] = $result->data[0]->link; |
387
|
|
|
$image_url['thumbnail'] = $result->data[0]->image; |
388
|
|
|
$image_url['copyright'] = $result->data[0]->photographer; |
389
|
|
|
$image_url['source'] = 'AirportData'; |
390
|
|
|
return $image_url; |
391
|
|
|
} |
392
|
|
|
return false; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Gets the aircraft image from WikiMedia |
397
|
|
|
* |
398
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
399
|
|
|
* @param String $aircraft_name type of the aircraft |
400
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
401
|
|
|
* |
402
|
|
|
*/ |
403
|
|
|
public function fromWikimedia($aircraft_registration,$aircraft_name='') { |
404
|
|
|
$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'; |
407
|
|
|
$data = $Common->getData($url); |
408
|
|
|
$result = json_decode($data); |
409
|
|
|
if (isset($result->query->search[0]->title)) { |
410
|
|
|
$fileo = $result->query->search[0]->title; |
411
|
|
|
if (substr($fileo,-3) == 'pdf') return false; |
412
|
|
|
$file = urlencode($fileo); |
413
|
|
|
$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
|
|
|
$data2 = $Common->getData($url2); |
415
|
|
|
$result2 = json_decode($data2); |
416
|
|
|
if (isset($result2->query->pages)) { |
417
|
|
|
foreach ($result2->query->pages as $page) { |
418
|
|
|
if (isset($page->imageinfo[0]->user)) { |
419
|
|
|
$image_url = array(); |
420
|
|
|
$image_url['copyright'] = 'Wikimedia, '.$page->imageinfo[0]->user; |
421
|
|
|
$image_url['original'] = $page->imageinfo[0]->url; |
422
|
|
|
$image_url['thumbnail'] = $page->imageinfo[0]->thumburl; |
423
|
|
|
$image_url['source'] = 'wikimedia'; |
424
|
|
|
$image_url['source_website'] = 'http://commons.wikimedia.org/wiki/'.$fileo; |
425
|
|
|
//return $image_url; |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
if (isset($image_url['original'])) { |
430
|
|
|
$url2 = 'https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=extmetadata&format=json&continue&titles='.$file; |
431
|
|
|
$data2 = $Common->getData($url2); |
432
|
|
|
$result2 = json_decode($data2); |
433
|
|
|
if (isset($result2->query->pages)) { |
434
|
|
|
foreach ($result2->query->pages as $page) { |
435
|
|
|
if (isset($page->imageinfo[0]->extmetadata->Artist)) { |
436
|
|
|
$image_url['copyright'] = preg_replace('/ from(.*)/','',strip_tags($page->imageinfo[0]->extmetadata->Artist->value)); |
437
|
|
|
if (isset($page->imageinfo[0]->extmetadata->License->value)) { |
438
|
|
|
$image_url['copyright'] = $image_url['copyright'].' (under '.$page->imageinfo[0]->extmetadata->License->value.')'; |
439
|
|
|
} |
440
|
|
|
$image_url['copyright'] = trim(str_replace('\n','',$image_url['copyright'])); |
441
|
|
|
return $image_url; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
return $image_url; |
446
|
|
|
} |
447
|
|
|
} |
448
|
|
|
return false; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Gets the aircraft image from custom url |
453
|
|
|
* |
454
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
455
|
|
|
* @param String $aircraft_name type of the aircraft |
456
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
457
|
|
|
* |
458
|
|
|
*/ |
459
|
|
|
public function fromCustomSource($aircraft_registration,$aircraft_name='') { |
|
|
|
|
460
|
|
|
global $globalAircraftImageCustomSources, $globalDebug; |
461
|
|
|
//$globalAircraftImageCustomSource[] = array('thumbnail' => '','original' => '', 'copyright' => '', 'source_website' => '', 'source' => '','exif' => true); |
462
|
|
|
if (!empty($globalAircraftImageCustomSources)) { |
463
|
|
|
$customsources = array(); |
464
|
|
|
if (!isset($globalAircraftImageCustomSources[0])) { |
465
|
|
|
$customsources[] = $globalAircraftImageCustomSources; |
466
|
|
|
} else { |
467
|
|
|
$customsources = $globalAircraftImageCustomSources; |
468
|
|
|
} |
469
|
|
|
foreach ($customsources as $source) { |
470
|
|
|
$Common = new Common(); |
471
|
|
|
if (!isset($source['original']) && $globalDebug) { |
472
|
|
|
echo 'original entry not found for $globalAircraftImageCustomSources.'; |
473
|
|
|
print_r($source); |
474
|
|
|
print_r($customsources); |
475
|
|
|
} |
476
|
|
|
$url = str_replace('{registration}',$aircraft_registration,$source['original']); |
477
|
|
|
$url_thumbnail = str_replace('{registration}',$aircraft_registration,$source['thumbnail']); |
478
|
|
|
if ($Common->urlexist($url)) { |
479
|
|
|
$image_url = array(); |
480
|
|
|
$image_url['thumbnail'] = $url_thumbnail; |
481
|
|
|
$image_url['original'] = $url; |
482
|
|
|
if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
483
|
|
|
else $exifCopyright = ''; |
484
|
|
|
if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
485
|
|
|
elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
486
|
|
|
else $image_url['copyright'] = $source['source_website']; |
487
|
|
|
$image_url['source_website'] = $source['source_website']; |
488
|
|
|
$image_url['source'] = $source['source']; |
489
|
|
|
return $image_url; |
490
|
|
|
} |
491
|
|
|
} |
492
|
|
|
return false; |
493
|
|
|
} else return false; |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
//$Image = new Image(); |
498
|
|
|
//print_r($Image->fromAirportData('F-GZHM')); |
499
|
|
|
|
500
|
|
|
?> |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.