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
|
|
|
$reg = $registration; |
26
|
|
|
if ($reg == '' && $aircraft_icao != '') $reg = $aircraft_icao.$airline_icao; |
27
|
|
|
$reg = trim($reg); |
28
|
|
|
$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 |
29
|
|
|
FROM spotter_image |
30
|
|
|
WHERE spotter_image.registration = :registration LIMIT 1"; |
31
|
|
|
$sth = $this->db->prepare($query); |
32
|
|
|
$sth->execute(array(':registration' => $reg)); |
33
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
34
|
|
|
if (!empty($result)) return $result; |
35
|
|
|
elseif ($registration != '') return $this->getSpotterImage('',$aircraft_icao,$airline_icao); |
36
|
|
|
else return array(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Gets the images based on the ship name |
41
|
|
|
* |
42
|
|
|
* @return Array the images list |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
|
|
public function getMarineImage($mmsi,$imo = '',$name = '') |
46
|
|
|
{ |
47
|
|
|
$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); |
48
|
|
|
$imo = filter_var($imo,FILTER_SANITIZE_STRING); |
49
|
|
|
$name = filter_var($name,FILTER_SANITIZE_STRING); |
50
|
|
|
$name = trim($name); |
51
|
|
|
$query = "SELECT marine_image.image, marine_image.image_thumbnail, marine_image.image_source, marine_image.image_source_website,marine_image.image_copyright, marine_image.mmsi, marine_image.imo, marine_image.name |
52
|
|
|
FROM marine_image |
53
|
|
|
WHERE marine_image.mmsi = :mmsi"; |
54
|
|
|
$query_data = array(':mmsi' => $mmsi); |
55
|
|
|
if ($imo != '') { |
56
|
|
|
$query .= " AND marine_image.imo = :imo"; |
57
|
|
|
$query_data = array_merge($query_data,array(':imo' => $imo)); |
58
|
|
|
} |
59
|
|
|
if ($name != '') { |
60
|
|
|
$query .= " AND marine_image.name = :name"; |
61
|
|
|
$query_data = array_merge($query_data,array(':name' => $name)); |
62
|
|
|
} |
63
|
|
|
$query .= " LIMIT 1"; |
64
|
|
|
$sth = $this->db->prepare($query); |
65
|
|
|
$sth->execute($query_data); |
66
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
67
|
|
|
return $result; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Gets the image copyright based on the Exif data |
72
|
|
|
* |
73
|
|
|
* @return String image copyright |
74
|
|
|
* |
75
|
|
|
*/ |
76
|
|
|
public function getExifCopyright($url) { |
77
|
|
|
$exif = exif_read_data($url); |
78
|
|
|
$copyright = ''; |
79
|
|
|
if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright']; |
80
|
|
|
elseif (isset($exif['copyright'])) $copyright = $exif['copyright']; |
81
|
|
|
if ($copyright != '') { |
82
|
|
|
$copyright = str_replace('Copyright ','',$copyright); |
83
|
|
|
$copyright = str_replace('© ','',$copyright); |
84
|
|
|
$copyright = str_replace('(c) ','',$copyright); |
85
|
|
|
} |
86
|
|
|
return $copyright; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Adds the images based on the aircraft registration |
91
|
|
|
* |
92
|
|
|
* @return String either success or error |
93
|
|
|
* |
94
|
|
|
*/ |
95
|
|
|
public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '') |
96
|
|
|
{ |
97
|
|
|
global $globalDebug,$globalAircraftImageFetch; |
98
|
|
|
if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) return ''; |
99
|
|
|
$registration = filter_var($registration,FILTER_SANITIZE_STRING); |
100
|
|
|
$registration = trim($registration); |
101
|
|
|
//getting the aircraft image |
102
|
|
|
if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...'; |
103
|
|
|
elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...'; |
104
|
|
|
elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...'; |
105
|
|
|
$image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao); |
106
|
|
|
if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao; |
107
|
|
|
if ($image_url['original'] != '') { |
108
|
|
|
if ($globalDebug) echo 'Found !'."\n"; |
109
|
|
|
$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)"; |
110
|
|
|
try { |
111
|
|
|
$sth = $this->db->prepare($query); |
112
|
|
|
$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'])); |
113
|
|
|
} catch(PDOException $e) { |
114
|
|
|
echo $e->getMessage()."\n"; |
115
|
|
|
return "error"; |
116
|
|
|
} |
117
|
|
|
} elseif ($globalDebug) echo "Not found :'(\n"; |
118
|
|
|
return "success"; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Adds the images based on the marine name |
123
|
|
|
* |
124
|
|
|
* @return String either success or error |
125
|
|
|
* |
126
|
|
|
*/ |
127
|
|
|
public function addMarineImage($mmsi,$imo = '',$name = '') |
128
|
|
|
{ |
129
|
|
|
global $globalDebug,$globalMarineImageFetch; |
130
|
|
|
if (isset($globalMarineImageFetch) && !$globalMarineImageFetch) return ''; |
131
|
|
|
$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); |
132
|
|
|
$imo = filter_var($imo,FILTER_SANITIZE_STRING); |
133
|
|
|
$name = filter_var($name,FILTER_SANITIZE_STRING); |
134
|
|
|
$name = trim($name); |
135
|
|
|
$Marine = new Marine($this->db); |
136
|
|
|
if ($imo == '' || $name == '') { |
137
|
|
|
$identity = $Marine->getIdentity($mmsi); |
138
|
|
|
if (isset($identity[0]['mmsi'])) { |
139
|
|
|
$imo = $identity[0]['imo']; |
140
|
|
|
if ($identity[0]['ship_name'] != '') $name = $identity[0]['ship_name']; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
unset($Marine); |
144
|
|
|
|
145
|
|
|
//getting the aircraft image |
146
|
|
|
if ($globalDebug && $name != '') echo 'Try to find an vessel image for '.$name.'...'; |
147
|
|
|
$image_url = $this->findMarineImage($mmsi,$imo,$name); |
148
|
|
|
if ($image_url['original'] != '') { |
149
|
|
|
if ($globalDebug) echo 'Found !'."\n"; |
150
|
|
|
$query = "INSERT INTO marine_image (mmsi,imo,name, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:mmsi,:imo,:name,:image,:image_thumbnail,:copyright,:source,:source_website)"; |
151
|
|
|
try { |
152
|
|
|
$sth = $this->db->prepare($query); |
153
|
|
|
$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':name' => $name,':image' => $image_url['original'],':image_thumbnail' => $image_url['thumbnail'], ':copyright' => $image_url['copyright'],':source' => $image_url['source'],':source_website' => $image_url['source_website'])); |
154
|
|
|
} catch(PDOException $e) { |
155
|
|
|
echo $e->getMessage()."\n"; |
156
|
|
|
return "error"; |
157
|
|
|
} |
158
|
|
|
} elseif ($globalDebug) echo "Not found :'(\n"; |
159
|
|
|
return "success"; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Gets the aircraft image |
164
|
|
|
* |
165
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
166
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
167
|
|
|
* |
168
|
|
|
*/ |
169
|
|
|
public function findAircraftImage($aircraft_registration, $aircraft_icao = '', $airline_icao = '') |
170
|
|
|
{ |
171
|
|
|
global $globalAircraftImageSources, $globalIVAO, $globalAircraftImageCheckICAO, $globalVA; |
172
|
|
|
$Spotter = new Spotter($this->db); |
173
|
|
|
if (!isset($globalIVAO)) $globalIVAO = FALSE; |
174
|
|
|
$aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING); |
175
|
|
|
if ($aircraft_registration != '' && (!isset($globalVA) || $globalVA !== TRUE)) { |
176
|
|
|
if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
177
|
|
|
$aircraft_registration = urlencode(trim($aircraft_registration)); |
178
|
|
|
$aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration); |
179
|
|
|
if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name']; |
180
|
|
|
else $aircraft_name = ''; |
181
|
|
|
if (isset($aircraft_info[0]['aircraft_icao'])) $aircraft_name = $aircraft_info[0]['aircraft_icao']; |
182
|
|
|
else $aircraft_icao = ''; |
183
|
|
|
if (isset($aircraft_info[0]['airline_icao'])) $airline_icao = $aircraft_info[0]['airline_icao']; |
184
|
|
|
else $airline_icao = ''; |
185
|
|
|
} elseif ($aircraft_icao != '') { |
186
|
|
|
$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_icao); |
187
|
|
|
if (isset($aircraft_info[0]['type'])) $aircraft_name = $aircraft_info[0]['type']; |
188
|
|
|
else $aircraft_name = ''; |
189
|
|
|
$aircraft_registration = $aircraft_icao; |
190
|
|
|
} else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
191
|
|
|
unset($Spotter); |
192
|
|
|
if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters'); |
193
|
|
|
foreach ($globalAircraftImageSources as $source) { |
194
|
|
|
$source = strtolower($source); |
195
|
|
|
if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl('aircraft',$aircraft_icao,$airline_icao); |
196
|
|
|
if ($source == 'planespotters' && !$globalIVAO) $images_array = $this->fromPlanespotters('aircraft',$aircraft_registration,$aircraft_name); |
197
|
|
|
if ($source == 'flickr') $images_array = $this->fromFlickr('aircraft',$aircraft_registration,$aircraft_name); |
198
|
|
|
if ($source == 'bing') $images_array = $this->fromBing('aircraft',$aircraft_registration,$aircraft_name); |
199
|
|
|
if ($source == 'deviantart') $images_array = $this->fromDeviantart('aircraft',$aircraft_registration,$aircraft_name); |
200
|
|
|
if ($source == 'wikimedia') $images_array = $this->fromWikimedia('aircraft',$aircraft_registration,$aircraft_name); |
201
|
|
|
if ($source == 'jetphotos' && !$globalIVAO) $images_array = $this->fromJetPhotos('aircraft',$aircraft_registration,$aircraft_name); |
202
|
|
|
if ($source == 'planepictures' && !$globalIVAO) $images_array = $this->fromPlanePictures('aircraft',$aircraft_registration,$aircraft_name); |
203
|
|
|
if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData('aircraft',$aircraft_registration,$aircraft_name); |
204
|
|
|
if ($source == 'customsources') $images_array = $this->fromCustomSource('aircraft',$aircraft_registration,$aircraft_name); |
205
|
|
|
if (isset($images_array) && $images_array['original'] != '') return $images_array; |
206
|
|
|
} |
207
|
|
|
if ((!isset($globalAircraftImageCheckICAO) || $globalAircraftImageCheckICAO === TRUE) && isset($aircraft_icao)) return $this->findAircraftImage($aircraft_icao); |
208
|
|
|
return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Gets the vessel image |
213
|
|
|
* |
214
|
|
|
* @param String $mmsi the vessel mmsi |
215
|
|
|
* @param String $imo the vessel imo |
216
|
|
|
* @param String $name the vessel name |
217
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
218
|
|
|
* |
219
|
|
|
*/ |
220
|
|
|
public function findMarineImage($mmsi,$imo = '',$name = '') |
|
|
|
|
221
|
|
|
{ |
222
|
|
|
global $globalMarineImageSources; |
223
|
|
|
$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); |
224
|
|
|
//$imo = filter_var($imo,FILTER_SANITIZE_STRING); |
225
|
|
|
$name = filter_var($name,FILTER_SANITIZE_STRING); |
226
|
|
|
$name = trim($name); |
227
|
|
|
if (strlen($name) < 4) return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => ''); |
228
|
|
|
/* |
229
|
|
|
$Marine = new Marine($this->db); |
230
|
|
|
if ($imo == '' || $name == '') { |
231
|
|
|
$identity = $Marine->getIdentity($mmsi); |
232
|
|
|
if (isset($identity[0]['mmsi'])) { |
233
|
|
|
$imo = $identity[0]['imo']; |
234
|
|
|
$name = $identity[0]['ship_name']; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
unset($Marine); |
238
|
|
|
*/ |
239
|
|
|
if (!isset($globalMarineImageSources)) $globalMarineImageSources = array('wikimedia','deviantart','flickr','bing'); |
240
|
|
|
foreach ($globalMarineImageSources as $source) { |
241
|
|
|
$source = strtolower($source); |
242
|
|
|
if ($source == 'flickr') $images_array = $this->fromFlickr('marine',$mmsi,$name); |
243
|
|
|
if ($source == 'bing') $images_array = $this->fromBing('marine',$mmsi,$name); |
244
|
|
|
if ($source == 'deviantart') $images_array = $this->fromDeviantart('marine',$mmsi,$name); |
245
|
|
|
if ($source == 'wikimedia') $images_array = $this->fromWikimedia('marine',$mmsi,$name); |
246
|
|
|
if ($source == 'customsources') $images_array = $this->fromCustomSource('marine',$mmsi,$name); |
247
|
|
|
if (isset($images_array) && $images_array['original'] != '') return $images_array; |
248
|
|
|
} |
249
|
|
|
return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => ''); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Gets the aircraft image from Planespotters |
254
|
|
|
* |
255
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
256
|
|
|
* @param String $aircraft_name type of the aircraft |
257
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
258
|
|
|
* |
259
|
|
|
*/ |
260
|
|
|
public function fromPlanespotters($type,$aircraft_registration, $aircraft_name='') { |
|
|
|
|
261
|
|
|
$Common = new Common(); |
262
|
|
|
// If aircraft registration is only number, also check with aircraft model |
263
|
|
|
if (preg_match('/^[[:digit]]+$/',$aircraft_registration) && $aircraft_name != '') { |
264
|
|
|
$url= 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$aircraft_registration.'&actype=s_'.urlencode($aircraft_name).'&output=rss'; |
265
|
|
|
} else { |
266
|
|
|
//$url= 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$airline_aircraft_type.'&output=rss'; |
267
|
|
|
$url= 'http://www.planespotters.net/Aviation_Photos/search.php?reg='.$aircraft_registration.'&output=rss'; |
268
|
|
|
} |
269
|
|
|
$data = $Common->getData($url); |
270
|
|
|
if ($xml = simplexml_load_string($data)) { |
271
|
|
|
if (isset($xml->channel->item)) { |
272
|
|
|
$image_url = array(); |
273
|
|
|
$thumbnail_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url); |
274
|
|
|
$image_url['thumbnail'] = $thumbnail_url; |
275
|
|
|
$image_url['original'] = str_replace('thumbnail','original',$thumbnail_url); |
276
|
|
|
$image_url['copyright'] = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright); |
277
|
|
|
$image_url['source_website'] = trim((string)$xml->channel->item->link); |
278
|
|
|
$image_url['source'] = 'planespotters'; |
279
|
|
|
return $image_url; |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
return false; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Gets the aircraft image from Deviantart |
287
|
|
|
* |
288
|
|
|
* @param String $registration the registration of the aircraft |
289
|
|
|
* @param String $name type of the aircraft |
290
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
291
|
|
|
* |
292
|
|
|
*/ |
293
|
|
|
public function fromDeviantart($type,$registration, $name='') { |
294
|
|
|
$Common = new Common(); |
295
|
|
|
if ($type == 'aircraft') { |
296
|
|
|
// If aircraft registration is only number, also check with aircraft model |
297
|
|
|
if (preg_match('/^[[:digit]]+$/',$registration) && $name != '') { |
298
|
|
|
$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q='.$registration.'%20'.urlencode($name); |
299
|
|
|
} else { |
300
|
|
|
$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q=aircraft%20'.$registration; |
301
|
|
|
} |
302
|
|
|
} elseif ($type == 'marine') { |
303
|
|
|
$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q=ship%20"'.urlencode($name).'"'; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
$data = $Common->getData($url); |
|
|
|
|
307
|
|
|
if ($xml = simplexml_load_string($data)) { |
308
|
|
|
if (isset($xml->channel->item->link)) { |
309
|
|
|
$image_url = array(); |
310
|
|
|
$thumbnail_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url); |
311
|
|
|
$image_url['thumbnail'] = $thumbnail_url; |
312
|
|
|
$original_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->content->attributes()->url); |
313
|
|
|
$image_url['original'] = $original_url; |
314
|
|
|
$image_url['copyright'] = str_replace('Copyright ','',trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright)); |
315
|
|
|
$image_url['source_website'] = trim((string)$xml->channel->item->link); |
316
|
|
|
$image_url['source'] = 'deviantart'; |
317
|
|
|
return $image_url; |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
return false; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Gets the aircraft image from JetPhotos |
325
|
|
|
* |
326
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
327
|
|
|
* @param String $aircraft_name type of the aircraft |
328
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
329
|
|
|
* |
330
|
|
|
*/ |
331
|
|
|
public function fromJetPhotos($type,$aircraft_registration, $aircraft_name='') { |
|
|
|
|
332
|
|
|
$Common = new Common(); |
333
|
|
|
$url= 'http://jetphotos.net/showphotos.php?displaymode=2®search='.$aircraft_registration; |
334
|
|
|
$data = $Common->getData($url); |
335
|
|
|
$dom = new DOMDocument(); |
336
|
|
|
@$dom->loadHTML($data); |
|
|
|
|
337
|
|
|
$all_pics = array(); |
338
|
|
|
foreach($dom->getElementsByTagName('img') as $image) { |
339
|
|
|
if ($image->getAttribute('itemprop') == "http://schema.org/image") { |
340
|
|
|
$all_pics[] = $image->getAttribute('src'); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
$all_authors = array(); |
344
|
|
|
foreach($dom->getElementsByTagName('meta') as $author) { |
345
|
|
|
if ($author->getAttribute('itemprop') == "http://schema.org/author") { |
346
|
|
|
$all_authors[] = $author->getAttribute('content'); |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
$all_ref = array(); |
350
|
|
|
foreach($dom->getElementsByTagName('a') as $link) { |
351
|
|
|
$all_ref[] = $link->getAttribute('href'); |
352
|
|
|
} |
353
|
|
|
if (isset($all_pics[0])) { |
354
|
|
|
$image_url = array(); |
355
|
|
|
$image_url['thumbnail'] = $all_pics[0]; |
356
|
|
|
$image_url['original'] = str_replace('_tb','',$all_pics[0]); |
357
|
|
|
$image_url['copyright'] = $all_authors[0]; |
358
|
|
|
$image_url['source_website'] = 'http://jetphotos.net'.$all_ref[8]; |
359
|
|
|
$image_url['source'] = 'JetPhotos'; |
360
|
|
|
return $image_url; |
361
|
|
|
} |
362
|
|
|
return false; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Gets the aircraft image from PlanePictures |
367
|
|
|
* |
368
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
369
|
|
|
* @param String $aircraft_name type of the aircraft |
370
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
371
|
|
|
* |
372
|
|
|
*/ |
373
|
|
|
public function fromPlanePictures($type,$aircraft_registration, $aircraft_name='') { |
|
|
|
|
374
|
|
|
$Common = new Common(); |
375
|
|
|
$url= 'http://www.planepictures.net/netsearch4.cgi?srch='.$aircraft_registration.'&stype=reg&srng=2'; |
376
|
|
|
$data = $Common->getData($url); |
377
|
|
|
$dom = new DOMDocument(); |
378
|
|
|
@$dom->loadHTML($data); |
|
|
|
|
379
|
|
|
$all_pics = array(); |
380
|
|
|
foreach($dom->getElementsByTagName('img') as $image) { |
381
|
|
|
$all_pics[] = $image->getAttribute('src'); |
382
|
|
|
} |
383
|
|
|
$all_links = array(); |
384
|
|
|
foreach($dom->getElementsByTagName('a') as $link) { |
385
|
|
|
$all_links[] = array('text' => $link->textContent,'href' => $link->getAttribute('href')); |
386
|
|
|
} |
387
|
|
|
if (isset($all_pics[1]) && !preg_match('/bit.ly/',$all_pics[1]) && !preg_match('/flagge/',$all_pics[1])) { |
388
|
|
|
$image_url = array(); |
389
|
|
|
$image_url['thumbnail'] = 'http://www.planepictures.net/'.$all_pics[1]; |
390
|
|
|
$image_url['original'] = 'http://www.planepictures.net/'.str_replace('_TN','',$all_pics[1]); |
391
|
|
|
$image_url['copyright'] = $all_links[6]['text']; |
392
|
|
|
$image_url['source_website'] = 'http://www.planepictures.net/'.$all_links[2]['href']; |
393
|
|
|
$image_url['source'] = 'PlanePictures'; |
394
|
|
|
return $image_url; |
395
|
|
|
} |
396
|
|
|
return false; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Gets the aircraft image from Flickr |
401
|
|
|
* |
402
|
|
|
* @param String $registration the registration of the aircraft |
403
|
|
|
* @param String $name type of the aircraft |
404
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
405
|
|
|
* |
406
|
|
|
*/ |
407
|
|
|
public function fromFlickr($type,$registration,$name='') { |
408
|
|
|
$Common = new Common(); |
409
|
|
|
if ($type == 'aircraft') { |
410
|
|
|
if ($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='.$registration.','.urlencode($name); |
411
|
|
|
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='.$registration.',aircraft'; |
412
|
|
|
} elseif ($type == 'marine') { |
413
|
|
|
if ($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=ship,'.urlencode($name); |
414
|
|
|
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='.$registration.',ship'; |
415
|
|
|
} |
416
|
|
|
$data = $Common->getData($url); |
|
|
|
|
417
|
|
|
if ($xml = simplexml_load_string($data)) { |
418
|
|
|
if (isset($xml->channel->item)) { |
419
|
|
|
$original_url = trim((string)$xml->channel->item->enclosure->attributes()->url); |
420
|
|
|
$image_url = array(); |
421
|
|
|
$image_url['thumbnail'] = $original_url; |
422
|
|
|
$image_url['original'] = $original_url; |
423
|
|
|
$image_url['copyright'] = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->credit); |
424
|
|
|
$image_url['source_website'] = trim((string)$xml->channel->item->link); |
425
|
|
|
$image_url['source'] = 'flickr'; |
426
|
|
|
return $image_url; |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
return false; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
public function fromIvaoMtl($type,$aircraft_icao,$airline_icao) { |
|
|
|
|
433
|
|
|
$Common = new Common(); |
434
|
|
|
//echo "\n".'SEARCH IMAGE : http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg'; |
435
|
|
|
if ($Common->urlexist('http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg')) { |
436
|
|
|
$image_url = array(); |
437
|
|
|
$image_url['thumbnail'] = 'http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg'; |
438
|
|
|
$image_url['original'] = 'http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg'; |
439
|
|
|
$image_url['copyright'] = 'IVAO'; |
440
|
|
|
$image_url['source_website'] = 'http://mtlcatalog.ivao.aero/'; |
441
|
|
|
$image_url['source'] = 'ivao.aero'; |
442
|
|
|
return $image_url; |
443
|
|
|
} else { |
444
|
|
|
return false; |
445
|
|
|
} |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Gets the aircraft image from Bing |
450
|
|
|
* |
451
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
452
|
|
|
* @param String $aircraft_name type of the aircraft |
453
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
454
|
|
|
* |
455
|
|
|
*/ |
456
|
|
|
public function fromBing($type,$aircraft_registration,$aircraft_name='') { |
457
|
|
|
global $globalImageBingKey; |
458
|
|
|
$Common = new Common(); |
459
|
|
|
if (!isset($globalImageBingKey) || $globalImageBingKey == '') return false; |
460
|
|
|
if ($type == 'aircraft') { |
461
|
|
|
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'; |
462
|
|
|
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'; |
463
|
|
|
} elseif ($type == 'marine') { |
464
|
|
|
if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.urlencode($aircraft_name).'%20%2Bship%20-site:flickr.com%27'; |
465
|
|
|
else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Bship%20-site:flickr.com%27'; |
466
|
|
|
} |
467
|
|
|
$headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey)); |
468
|
|
|
$data = $Common->getData($url,'get','',$headers); |
|
|
|
|
469
|
|
|
$result = json_decode($data); |
470
|
|
|
if (isset($result->d->results[0]->MediaUrl)) { |
471
|
|
|
$image_url = array(); |
472
|
|
|
$image_url['original'] = $result->d->results[0]->MediaUrl; |
473
|
|
|
$image_url['source_website'] = $result->d->results[0]->SourceUrl; |
474
|
|
|
// Thumbnail can't be used this way... |
475
|
|
|
// $image_url['thumbnail'] = $result->d->results[0]->Thumbnail->MediaUrl; |
476
|
|
|
$image_url['thumbnail'] = $result->d->results[0]->MediaUrl; |
477
|
|
|
$url = parse_url($image_url['source_website']); |
478
|
|
|
$image_url['copyright'] = $url['host']; |
479
|
|
|
$image_url['source'] = 'bing'; |
480
|
|
|
return $image_url; |
481
|
|
|
} |
482
|
|
|
return false; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Gets the aircraft image from airport-data |
487
|
|
|
* |
488
|
|
|
* @param String $aircraft_registration the registration of the aircraft |
489
|
|
|
* @param String $aircraft_name type of the aircraft |
490
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
491
|
|
|
* |
492
|
|
|
*/ |
493
|
|
|
public function fromAirportData($type,$aircraft_registration,$aircraft_name='') { |
|
|
|
|
494
|
|
|
$Common = new Common(); |
495
|
|
|
$url = 'http://www.airport-data.com/api/ac_thumb.json?&n=1&r='.$aircraft_registration; |
496
|
|
|
$data = $Common->getData($url); |
497
|
|
|
$result = json_decode($data); |
498
|
|
|
if (isset($result->count) && $result->count > 0) { |
499
|
|
|
$image_url = array(); |
500
|
|
|
$image_url['original'] = str_replace('thumbnails','large',$result->data[0]->image); |
501
|
|
|
$image_url['source_website'] = $result->data[0]->link; |
502
|
|
|
$image_url['thumbnail'] = $result->data[0]->image; |
503
|
|
|
$image_url['copyright'] = $result->data[0]->photographer; |
504
|
|
|
$image_url['source'] = 'AirportData'; |
505
|
|
|
return $image_url; |
506
|
|
|
} |
507
|
|
|
return false; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* Gets image from WikiMedia |
512
|
|
|
* |
513
|
|
|
* @param String $registration the registration of the aircraft/mmsi |
514
|
|
|
* @param String $name name |
515
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
516
|
|
|
* |
517
|
|
|
*/ |
518
|
|
|
public function fromWikimedia($type,$registration,$name='') { |
519
|
|
|
$Common = new Common(); |
520
|
|
|
if ($type == 'aircraft') { |
521
|
|
|
if ($name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20'.urlencode($name); |
522
|
|
|
else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$registration.'"%20aircraft'; |
523
|
|
|
} elseif ($type == 'marine') { |
524
|
|
|
if ($name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.urlencode($name).'"'; |
525
|
|
|
else return false; |
526
|
|
|
} |
527
|
|
|
$data = $Common->getData($url); |
|
|
|
|
528
|
|
|
$result = json_decode($data); |
529
|
|
|
if (isset($result->query->search[0]->title)) { |
530
|
|
|
$fileo = $result->query->search[0]->title; |
531
|
|
|
if (substr($fileo,-3) == 'pdf') return false; |
532
|
|
|
$file = urlencode($fileo); |
533
|
|
|
$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; |
534
|
|
|
$data2 = $Common->getData($url2); |
535
|
|
|
$result2 = json_decode($data2); |
536
|
|
|
if (isset($result2->query->pages)) { |
537
|
|
|
foreach ($result2->query->pages as $page) { |
538
|
|
|
if (isset($page->imageinfo[0]->user)) { |
539
|
|
|
$image_url = array(); |
540
|
|
|
$image_url['copyright'] = 'Wikimedia, '.$page->imageinfo[0]->user; |
541
|
|
|
$image_url['original'] = $page->imageinfo[0]->url; |
542
|
|
|
$image_url['thumbnail'] = $page->imageinfo[0]->thumburl; |
543
|
|
|
$image_url['source'] = 'wikimedia'; |
544
|
|
|
$image_url['source_website'] = 'http://commons.wikimedia.org/wiki/'.$fileo; |
545
|
|
|
//return $image_url; |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
} |
549
|
|
|
if (isset($image_url['original'])) { |
550
|
|
|
$url2 = 'https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=extmetadata&format=json&continue&titles='.$file; |
551
|
|
|
$data2 = $Common->getData($url2); |
552
|
|
|
$result2 = json_decode($data2); |
553
|
|
|
if (isset($result2->query->pages)) { |
554
|
|
|
foreach ($result2->query->pages as $page) { |
555
|
|
|
if (isset($page->imageinfo[0]->extmetadata->Artist)) { |
556
|
|
|
$image_url['copyright'] = preg_replace('/ from(.*)/','',strip_tags($page->imageinfo[0]->extmetadata->Artist->value)); |
557
|
|
|
if (isset($page->imageinfo[0]->extmetadata->License->value)) { |
558
|
|
|
$image_url['copyright'] = $image_url['copyright'].' (under '.$page->imageinfo[0]->extmetadata->License->value.')'; |
559
|
|
|
} |
560
|
|
|
$image_url['copyright'] = trim(str_replace('\n','',$image_url['copyright'])); |
561
|
|
|
return $image_url; |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
return $image_url; |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
return false; |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Gets the aircraft image from custom url |
573
|
|
|
* |
574
|
|
|
* @param String $registration the registration of the aircraft |
575
|
|
|
* @param String $name type of the aircraft |
576
|
|
|
* @return Array the aircraft thumbnail, orignal url and copyright |
577
|
|
|
* |
578
|
|
|
*/ |
579
|
|
|
public function fromCustomSource($type,$registration,$name='') { |
|
|
|
|
580
|
|
|
global $globalAircraftImageCustomSources, $globalMarineImageCustomSources, $globalDebug; |
581
|
|
|
//$globalAircraftImageCustomSource[] = array('thumbnail' => '','original' => '', 'copyright' => '', 'source_website' => '', 'source' => '','exif' => true); |
582
|
|
|
if (!empty($globalAircraftImageCustomSources) && $type == 'aircraft') { |
583
|
|
|
$customsources = array(); |
584
|
|
|
if (!isset($globalAircraftImageCustomSources[0])) { |
585
|
|
|
$customsources[] = $globalAircraftImageCustomSources; |
586
|
|
|
} else { |
587
|
|
|
$customsources = $globalAircraftImageCustomSources; |
588
|
|
|
} |
589
|
|
|
foreach ($customsources as $source) { |
590
|
|
|
$Common = new Common(); |
591
|
|
|
if (!isset($source['original']) && $globalDebug) { |
592
|
|
|
echo 'original entry not found for $globalAircraftImageCustomSources.'; |
593
|
|
|
print_r($source); |
594
|
|
|
print_r($customsources); |
595
|
|
|
} |
596
|
|
|
$url = str_replace('{registration}',$registration,$source['original']); |
597
|
|
|
$url_thumbnail = str_replace('{registration}',$registration,$source['thumbnail']); |
598
|
|
|
if ($Common->urlexist($url)) { |
599
|
|
|
$image_url = array(); |
600
|
|
|
$image_url['thumbnail'] = $url_thumbnail; |
601
|
|
|
$image_url['original'] = $url; |
602
|
|
|
if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
603
|
|
|
else $exifCopyright = ''; |
604
|
|
|
if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
605
|
|
|
elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
606
|
|
|
else $image_url['copyright'] = $source['source_website']; |
607
|
|
|
$image_url['source_website'] = $source['source_website']; |
608
|
|
|
$image_url['source'] = $source['source']; |
609
|
|
|
return $image_url; |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
return false; |
|
|
|
|
613
|
|
|
} else return false; |
|
|
|
|
614
|
|
|
if (!empty($globalMarineImageCustomSources) && $type == 'marine') { |
|
|
|
|
615
|
|
|
$customsources = array(); |
616
|
|
|
if (!isset($globalMarineImageCustomSources[0])) { |
617
|
|
|
$customsources[] = $globalMarineImageCustomSources; |
618
|
|
|
} else { |
619
|
|
|
$customsources = $globalMarineImageCustomSources; |
620
|
|
|
} |
621
|
|
|
foreach ($customsources as $source) { |
622
|
|
|
$Common = new Common(); |
623
|
|
|
if (!isset($source['original']) && $globalDebug) { |
624
|
|
|
echo 'original entry not found for $globalMarineImageCustomSources.'; |
625
|
|
|
print_r($source); |
626
|
|
|
print_r($customsources); |
627
|
|
|
} |
628
|
|
|
$url = str_replace('{registration}',$registration,$source['original']); |
629
|
|
|
$url = str_replace('{mmsi}',$registration,$url); |
630
|
|
|
$url = str_replace('{name}',$name,$url); |
631
|
|
|
$url_thumbnail = str_replace('{registration}',$registration,$source['thumbnail']); |
632
|
|
|
$url_thumbnail = str_replace('{mmsi}',$registration,$url_thumbnail); |
633
|
|
|
$url_thumbnail = str_replace('{name}',$name,$url_thumbnail); |
634
|
|
|
if ($Common->urlexist($url)) { |
635
|
|
|
$image_url = array(); |
636
|
|
|
$image_url['thumbnail'] = $url_thumbnail; |
637
|
|
|
$image_url['original'] = $url; |
638
|
|
|
if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url); |
639
|
|
|
else $exifCopyright = ''; |
640
|
|
|
if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright; |
641
|
|
|
elseif (isset($source['copyright'])) $image_url['copyright'] = $source['copyright']; |
642
|
|
|
else $image_url['copyright'] = $source['source_website']; |
643
|
|
|
$image_url['source_website'] = $source['source_website']; |
644
|
|
|
$image_url['source'] = $source['source']; |
645
|
|
|
return $image_url; |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
return false; |
|
|
|
|
649
|
|
|
} else return false; |
650
|
|
|
} |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
//$Image = new Image(); |
654
|
|
|
//print_r($Image->fromAirportData('F-GZHM')); |
655
|
|
|
|
656
|
|
|
?> |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.