1 | <?php |
---|
2 | |
---|
3 | function gis_saisies_autonomes($flux){ |
---|
4 | $flux[] = 'carte'; |
---|
5 | return $flux; |
---|
6 | } |
---|
7 | |
---|
8 | function gis_inserer_javascript($flux){ |
---|
9 | |
---|
10 | // initialisation des valeurs de config |
---|
11 | $config = @unserialize($GLOBALS['meta']['gis']); |
---|
12 | if (!is_array($config)) |
---|
13 | $config = array(); |
---|
14 | $config = array_merge(array( |
---|
15 | 'api' => 'openlayers' |
---|
16 | ), $config); |
---|
17 | |
---|
18 | include_spip('gis_fonctions'); |
---|
19 | $config['api'] = gis_api_utilisee(); |
---|
20 | if(defined('_GIS_APIS') && !array_key_exists($config['api'],unserialize(_GIS_APIS))){ |
---|
21 | return $flux; |
---|
22 | } |
---|
23 | |
---|
24 | // insertion du script de l'api a utiliser |
---|
25 | if ($config['api'] == 'cloudmade') |
---|
26 | $flux .="\n".'<script type="text/javascript" src="http://tile.cloudmade.com/wml/latest/web-maps-lite.js"></script>'."\n"; |
---|
27 | if ($config['api'] == 'google') |
---|
28 | $flux .="\n".'<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&sensor=false&key='.$config['api_key_google'].'&hl='.$GLOBALS['spip_lang'].'"></script>'."\n"; |
---|
29 | if ($config['api'] == 'googlev3') |
---|
30 | $flux .="\n".'<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language='.$GLOBALS['spip_lang'].'"></script>'."\n"; |
---|
31 | if ($config['api'] == 'microsoft') |
---|
32 | $flux .="\n".'<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6"></script>'."\n"; |
---|
33 | if ($config['api'] == 'openlayers') |
---|
34 | $flux .="\n".'<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>'."\n"; |
---|
35 | if ($config['api'] == 'ovi') |
---|
36 | $flux .="\n".'<script type="text/javascript" src="http://api.maps.ovi.com/jsl.js"></script>'."\n"; |
---|
37 | if ($config['api'] == 'yandex') |
---|
38 | $flux .="\n".'<script type="text/javascript" src="http://api-maps.yandex.ru/1.1/index.xml?key='.$config['api_key_yandex'].'"></script>'."\n"; |
---|
39 | |
---|
40 | // insertion de la lib mapstraction |
---|
41 | if(in_array($config['api'],array('cartociudad','google','googlev3','yandex'))){ |
---|
42 | $geocoder = ($config['geocoder']) ? ',[geocoder]' : ''; |
---|
43 | }else{ |
---|
44 | $geocoder = ''; |
---|
45 | } |
---|
46 | $flux .="\n".'<script id="mxn_script" type="text/javascript" src="'. url_absolue(find_in_path(_DIR_LIB_GIS.'mxn.js')) .'?('. $config['api'] . $geocoder .')"></script>'."\n"; |
---|
47 | |
---|
48 | // insertion des scripts de gis |
---|
49 | $flux .="\n".'<script type="text/javascript" src="'. url_absolue(find_in_path('javascript/gis.js')) .'"></script>'."\n"; |
---|
50 | |
---|
51 | return $flux; |
---|
52 | } |
---|
53 | |
---|
54 | function gis_afficher_contenu_objet($flux){ |
---|
55 | if ($objet = $flux['args']['type'] |
---|
56 | and include_spip('inc/config') |
---|
57 | and in_array(table_objet_sql($objet), lire_config('gis/gis_objets', array())) |
---|
58 | and ($id = intval($flux['args']['id_objet'])) |
---|
59 | |
---|
60 | ){ |
---|
61 | // TODO : seulement si la conf permet de geolocaliser cet objet |
---|
62 | // -> ajouter un element a la array suivante (qqch comme ca - voir les mots): |
---|
63 | // 'editable'=>autoriser('associergis',$type,$id)?'oui':'non' |
---|
64 | $texte = recuperer_fond( |
---|
65 | 'prive/contenu/gis_objet', |
---|
66 | array( |
---|
67 | 'table_source'=>'gis', |
---|
68 | 'objet'=>$objet, |
---|
69 | 'id_objet'=>$id |
---|
70 | ) |
---|
71 | ); |
---|
72 | $flux['data'] .= $texte; |
---|
73 | } |
---|
74 | |
---|
75 | return $flux; |
---|
76 | } |
---|
77 | |
---|
78 | function gis_post_edition($flux){ |
---|
79 | |
---|
80 | if (($flux['args']['operation'] == 'ajouter_document') |
---|
81 | AND ($document = sql_fetsel("*","spip_documents","id_document=".intval($flux['args']['id_objet']))) |
---|
82 | ) { |
---|
83 | if(in_array($document['extension'],array('jpg','kml','kmz'))){ |
---|
84 | $config = @unserialize($GLOBALS['meta']['gis']); |
---|
85 | if(!is_array($config)) |
---|
86 | $config = array(); |
---|
87 | include_spip('inc/documents'); |
---|
88 | $fichier = get_spip_doc($document['fichier']); |
---|
89 | $id_document = $document['id_document']; |
---|
90 | } |
---|
91 | if ($document['extension'] == 'jpg') { |
---|
92 | // on recupere les coords definies dans les exif du document s'il y en a |
---|
93 | if ($exifs = @exif_read_data($fichier,'GPS')) { |
---|
94 | if(!function_exists('dms_to_dec')) |
---|
95 | include_spip('gis_fonctions'); |
---|
96 | spip_log("GIS EXIFS : Récuperation des coordonnees du fichier $fichier","gis"); |
---|
97 | |
---|
98 | $LatDeg = explode("/",$exifs["GPSLatitude"][0]); |
---|
99 | if(is_numeric($LatDeg[1]) > 0) |
---|
100 | $intLatDeg = $LatDeg[0]/$LatDeg[1]; |
---|
101 | |
---|
102 | $LatMin = explode("/",$exifs["GPSLatitude"][1]); |
---|
103 | if(is_numeric($LatMin[1]) > 0) |
---|
104 | $intLatMin = $LatMin[0]/$LatMin[1]; |
---|
105 | |
---|
106 | $LatSec = explode("/",$exifs["GPSLatitude"][2]); |
---|
107 | if(is_numeric($LatSec[1]) > 0) |
---|
108 | $intLatSec = $LatSec[0]/$LatSec[1]; |
---|
109 | |
---|
110 | $LongDeg = explode("/",$exifs["GPSLongitude"][0]); |
---|
111 | if(is_numeric($LongDeg[1]) > 0) |
---|
112 | $intLongDeg = $LongDeg[0]/$LongDeg[1]; |
---|
113 | |
---|
114 | $LongMin = explode("/",$exifs["GPSLongitude"][1]); |
---|
115 | if(is_numeric($LongMin[1]) > 0) |
---|
116 | $intLongMin = $LongMin[0]/$LongMin[1]; |
---|
117 | |
---|
118 | $LongSec = explode("/",$exifs["GPSLongitude"][2]); |
---|
119 | if(is_numeric($LongSec[1]) > 0) |
---|
120 | $intLongSec = $LongSec[0]/$LongSec[1]; |
---|
121 | |
---|
122 | // round to 5 = approximately 1 meter accuracy |
---|
123 | if(is_numeric($intLatDeg) && is_numeric($intLatMin) && is_numeric($intLatSec)) |
---|
124 | $latitude = round(dms_to_dec($exifs["GPSLatitudeRef"], |
---|
125 | $intLatDeg,$intLatMin,$intLatSec),5); |
---|
126 | |
---|
127 | if(is_numeric($intLongDeg) && is_numeric($intLongMin) && is_numeric($intLongSec)) |
---|
128 | $longitude = round(dms_to_dec($exifs["GPSLongitudeRef"], |
---|
129 | $intLongDeg,$intLongMin,$intLongSec), 5); |
---|
130 | if($config['geocoder'] == 'on'){ |
---|
131 | include_spip('inc/xml'); |
---|
132 | $url_geocoder = 'http://maps.googleapis.com/maps/api/geocode/xml?latlng='.urlencode($latitude).','.urlencode($longitude).'&sensor=true'; |
---|
133 | $geocoder = spip_xml_load($url_geocoder); |
---|
134 | spip_xml_match_nodes(',result,',$geocoder,$matches_adress); |
---|
135 | if(is_array($matches_adress['result'])){ |
---|
136 | foreach($matches_adress['result'] as $component){ |
---|
137 | if(in_array('country',$component['type'])){ |
---|
138 | $pays = $component['address_component'][0]['long_name'][0]; |
---|
139 | $code_pays = $component['address_component'][0]['short_name'][0]; |
---|
140 | } |
---|
141 | if(in_array('administrative_area_level_1',$component['type'])){ |
---|
142 | $region = $component['address_component'][0]['long_name'][0]; |
---|
143 | } |
---|
144 | if(in_array('locality',$component['type'])){ |
---|
145 | $ville = $component['address_component'][0]['long_name'][0]; |
---|
146 | } |
---|
147 | if(in_array('postal_code',$component['type'])){ |
---|
148 | $code_postal = $component['address_component'][0]['long_name'][0]; |
---|
149 | } |
---|
150 | if(in_array('route',$component['type'])){ |
---|
151 | $adresse = $component['address_component'][0]['long_name'][0]; |
---|
152 | } |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | }else if(file_exists($fichier)){ |
---|
157 | include_spip("inc/iptc"); |
---|
158 | |
---|
159 | $er = new class_IPTC($fichier); |
---|
160 | $iptc = $er->fct_lireIPTC(); |
---|
161 | $codesiptc = $er->h_codesIptc; |
---|
162 | $string_recherche = ''; |
---|
163 | |
---|
164 | if($iptc['city']){ |
---|
165 | $string_recherche .= $iptc['city'].', '; |
---|
166 | } |
---|
167 | if($iptc['provinceState']){ |
---|
168 | $string_recherche .= $iptc['provinceState'].', '; |
---|
169 | } |
---|
170 | if($iptc['country']){ |
---|
171 | $string_recherche .= $iptc['country']; |
---|
172 | } |
---|
173 | if(strlen($string_recherche)){ |
---|
174 | include_spip('inc/xml'); |
---|
175 | $url_geocoder = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($string_recherche).'&sensor=true'; |
---|
176 | $geocoder = spip_xml_load($url_geocoder); |
---|
177 | if(is_array($geocoder)){ |
---|
178 | spip_xml_match_nodes(',location,',$geocoder,$matches); |
---|
179 | $latitude = $matches['location']['0']['lat']['0']; |
---|
180 | $longitude = $matches['location']['0']['lng']['0']; |
---|
181 | if($config['adresse'] == 'on'){ |
---|
182 | spip_xml_match_nodes(',address_component,',$geocoder,$matches_adress); |
---|
183 | if(is_array($matches_adress['address_component'])){ |
---|
184 | foreach($matches_adress['address_component'] as $component){ |
---|
185 | if(in_array('country',$component['type'])){ |
---|
186 | $pays = $component['long_name'][0]; |
---|
187 | $code_pays = $component['short_name'][0]; |
---|
188 | } |
---|
189 | if(in_array('administrative_area_level_1',$component['type'])){ |
---|
190 | $region = $component['long_name'][0]; |
---|
191 | } |
---|
192 | if(in_array('locality',$component['type'])){ |
---|
193 | $ville = $component['long_name'][0]; |
---|
194 | } |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | if(is_numeric($latitude) && is_numeric($longitude)){ |
---|
202 | $c = array( |
---|
203 | 'titre' => basename($fichier), |
---|
204 | 'lat'=> $latitude, |
---|
205 | 'lon' => $longitude, |
---|
206 | 'zoom' => $config['zoom'] ? $config['zoom'] :'4', |
---|
207 | 'adresse' => $adresse, |
---|
208 | 'code_postal' => $code_postal, |
---|
209 | 'ville' => $ville, |
---|
210 | 'region' => $region, |
---|
211 | 'pays' => $pays, |
---|
212 | 'code_pays' => $code_pays |
---|
213 | ); |
---|
214 | |
---|
215 | include_spip('action/editer_gis'); |
---|
216 | |
---|
217 | if($id_gis = sql_getfetsel("G.id_gis","spip_gis AS G LEFT JOIN spip_gis_liens AS T ON T.id_gis=G.id_gis ","T.id_objet=" . intval($id_document) . " AND T.objet='document'")){ |
---|
218 | // Des coordonnées sont déjà définies pour ce document => on les update |
---|
219 | revisions_gis($id_gis,$c); |
---|
220 | spip_log("GIS EXIFS : Update des coordonnées depuis EXIFS pour le document $id_document => id_gis = $id_gis","gis"); |
---|
221 | } |
---|
222 | else{ |
---|
223 | // Aucune coordonnée n'est définie pour ce document => on les crées |
---|
224 | $id_gis = insert_gis(); |
---|
225 | revisions_gis($id_gis,$c); |
---|
226 | lier_gis($id_gis, 'document', $id_document); |
---|
227 | spip_log("GIS EXIFS : Création des coordonnées depuis EXIFS pour le document $id_document => id_gis = $id_gis","gis"); |
---|
228 | } |
---|
229 | } |
---|
230 | }elseif(in_array($document['extension'],array('kml','kmz'))){ |
---|
231 | $recuperer_info = charger_fonction('kml_infos','inc'); |
---|
232 | $infos = $recuperer_info($document['id_document']); |
---|
233 | if($infos){ |
---|
234 | if(is_numeric($latitude = $infos['latitude']) && is_numeric($longitude = $infos['longitude'])){ |
---|
235 | $c = array( |
---|
236 | 'titre' => $infos['titre'] ? $infos['titre'] : basename($fichier), |
---|
237 | 'descriptif' => $infos['descriptif'], |
---|
238 | 'lat'=> $latitude, |
---|
239 | 'lon' => $longitude, |
---|
240 | 'zoom' => $config['zoom'] ? $config['zoom'] :'4' |
---|
241 | ); |
---|
242 | |
---|
243 | include_spip('action/editer_gis'); |
---|
244 | |
---|
245 | if($id_gis = sql_getfetsel("G.id_gis","spip_gis AS G LEFT JOIN spip_gis_liens AS T ON T.id_gis=G.id_gis ","T.id_objet=" . intval($id_document) . " AND T.objet='document'")){ |
---|
246 | // Des coordonnées sont déjà définies pour ce document => on les update |
---|
247 | revisions_gis($id_gis,$c); |
---|
248 | spip_log("GIS EXIFS : Update des coordonnées depuis EXIFS pour le document $id_document => id_gis = $id_gis","gis"); |
---|
249 | } |
---|
250 | else{ |
---|
251 | // Aucune coordonnée n'est définie pour ce document => on les crées |
---|
252 | $id_gis = insert_gis(); |
---|
253 | revisions_gis($id_gis,$c); |
---|
254 | lier_gis($id_gis, 'document', $id_document); |
---|
255 | spip_log("GIS EXIFS : Création des coordonnées depuis EXIFS pour le document $id_document => id_gis = $id_gis","gis"); |
---|
256 | } |
---|
257 | } |
---|
258 | unset($infos['longitude']); |
---|
259 | unset($infos['latitude']); |
---|
260 | if(count($infos) > 0){ |
---|
261 | include_spip('inc/modifier'); |
---|
262 | revision_document($id_document, $infos); |
---|
263 | } |
---|
264 | } |
---|
265 | } |
---|
266 | } |
---|
267 | if (($flux['args']['operation'] == 'supprimer_document') |
---|
268 | AND ($id_document = intval($flux['args']['id_objet']) |
---|
269 | AND ($id_gis = sql_getfetsel("G.id_gis","spip_gis AS G LEFT JOIN spip_gis_liens AS T ON T.id_gis=G.id_gis ","T.id_objet=" . intval($id_document) . " AND T.objet='document'"))) |
---|
270 | ) { |
---|
271 | include_spip('action/editer_gis'); |
---|
272 | supprimer_gis($id_gis); |
---|
273 | spip_log("GIS EXIFS : Suppression des coordonnées pour le document $id_document => id_gis = $id_gis","gis"); |
---|
274 | } |
---|
275 | |
---|
276 | return $flux; |
---|
277 | } |
---|
278 | |
---|
279 | function gis_taches_generales_cron($taches_generales){ |
---|
280 | $taches_generales['gis_nettoyer_base'] = 3600*48; |
---|
281 | return $taches_generales; |
---|
282 | } |
---|
283 | |
---|
284 | ?> |
---|