1 | <?php |
---|
2 | /** |
---|
3 | * Plugin SPIP Geoportail |
---|
4 | * |
---|
5 | * @author: |
---|
6 | * Jean-Marc Viglino (ign.fr) |
---|
7 | * |
---|
8 | * Copyright (c) 2010 |
---|
9 | * Logiciel distribue sous licence GNU/GPL. |
---|
10 | * |
---|
11 | * Ajouter un bouton dans la barre de menu |
---|
12 | * Vous pouvez redefinir geoportail_menu pour placer le menu ailleurs |
---|
13 | * |
---|
14 | * Definition des pipes pour l'affichage du formulaire dans les pages SPIP |
---|
15 | * |
---|
16 | **/ |
---|
17 | include_spip('inc/documents'); |
---|
18 | include_spip('public/assembler'); |
---|
19 | include_spip('inc/compat_192'); |
---|
20 | include_spip('public/geoportail_profils'); |
---|
21 | |
---|
22 | /** |
---|
23 | Fonction pour placer le menu geoportail |
---|
24 | */ |
---|
25 | function geoportail_menu_dist(&$boutons_admin, $menu, $icone, $libelle) |
---|
26 | { // Surcharge de la fonction |
---|
27 | if (function_exists(geoportail_menu)) geoportail_menu($boutons_admin,$menu, $icone, $libelle); |
---|
28 | else |
---|
29 | { switch ($menu) |
---|
30 | { case 'geoservice_tous': |
---|
31 | if ($GLOBALS['meta']['geoportail_service']) |
---|
32 | { if ($boutons_admin['bando_edition']) $ssmenu = 'bando_edition'; |
---|
33 | else $ssmenu = 'naviguer'; |
---|
34 | $boutons_admin[$ssmenu]->sousmenu[$menu] = new Bouton ($icone,$libelle); |
---|
35 | } |
---|
36 | break; |
---|
37 | default: |
---|
38 | if ($boutons_admin['bando_configuration']) $ssmenu ='bando_configuration'; |
---|
39 | else $ssmenu = 'configuration'; |
---|
40 | $boutons_admin[$ssmenu]->sousmenu[$menu] = new Bouton ($icone,$libelle); |
---|
41 | break; |
---|
42 | } |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | // Ajout des boutons dans l'interface privee |
---|
47 | function geoportail_ajouterBoutons($boutons_admin) |
---|
48 | { if (autoriser('configurer','geoportail',0)) |
---|
49 | geoportail_menu_dist ($boutons_admin, 'geoportail_config', _DIR_PLUGIN_GEOPORTAIL."img/geo.png", _T('geoportail:geoportail')); |
---|
50 | if ($GLOBALS['connect_statut'] == "0minirezo") |
---|
51 | geoportail_menu_dist ($boutons_admin, 'geoservice_tous', "site-24.gif", _T('geoportail:geoservices')); |
---|
52 | return $boutons_admin; |
---|
53 | } |
---|
54 | |
---|
55 | // Affichage d'un popup de services (va chercher dans la dscription de la table SPIP) |
---|
56 | function geoportail_services($val, $att) |
---|
57 | { $stat = spip_fetch_array(spip_query("DESCRIBE spip_geoservices $att")); |
---|
58 | $reg = "^enum\('(.*)'\)$"; |
---|
59 | $stat = ereg_replace($reg,'\1',$stat['Type']); |
---|
60 | $stat = preg_split("/[']?,[']?/",$stat); |
---|
61 | $rep = ""; |
---|
62 | foreach ($stat as $s) $rep .= "<option value='$s' ".($val==$s?"SELECTED":"").">$s</option>"; |
---|
63 | return $rep; |
---|
64 | } |
---|
65 | |
---|
66 | // Fonction de gestion des geoservices |
---|
67 | function geoportail_table_geoservices ($id_rubrique=0) |
---|
68 | { global $connect_statut, $connect_toutes_rubriques, $couleur_foncee, $couleur_claire; |
---|
69 | |
---|
70 | $contexte = array( |
---|
71 | 'id_rubrique'=>$id_rubrique, |
---|
72 | 'couleur_foncee'=>$couleur_foncee, |
---|
73 | 'couleur_claire'=>$couleur_claire |
---|
74 | ); |
---|
75 | if (autoriser ("modifier", "geoservice", 0, NULL, array('id_rubrique'=>$id_rubrique))) $contexte['modifier'] = " "; |
---|
76 | |
---|
77 | $fond = recuperer_fond ('fonds/geoservices_table',$contexte); |
---|
78 | if ($fond) |
---|
79 | echo "\n" |
---|
80 | // . bandeau_titre_boite2("<b> "._T("geoportail:geoservices")."</b>", "site-24.gif", $couleur_claire, 'black', false) |
---|
81 | . debut_cadre("trait-couleur", "site-24.gif", "", "<b> "._T("geoportail:geoservices")."</b>", $couleur_claire, 'black', false) |
---|
82 | . $fond |
---|
83 | . fin_cadre(true) |
---|
84 | . "\n"; |
---|
85 | elseif ($id_rubrique==0) echo "<p> </p>"; |
---|
86 | |
---|
87 | if (autoriser ("creer", "geoservice", 0, NULL, array('id_rubrique'=>$id_rubrique))) |
---|
88 | { echo icone_inline(_T('geoportail:icone_ajouter_service'), |
---|
89 | generer_url_ecrire('geoservice_edit',"id_rubrique=$id_rubrique"), |
---|
90 | "site-24.gif", |
---|
91 | "creer.gif", |
---|
92 | "right", |
---|
93 | false); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | Affichage du formulaire pour la saisie de coordonnees |
---|
99 | */ |
---|
100 | function geoportail_affiche_milieu($flux) |
---|
101 | { $exec = $flux['args']['exec']; |
---|
102 | |
---|
103 | // Le contexte |
---|
104 | $contexte = array( |
---|
105 | 'class' => 'carto', |
---|
106 | 'deplier' => _request('zone') ? ' ':'', |
---|
107 | 'lon' => _request('lon'), |
---|
108 | 'lat' => _request('lat'), |
---|
109 | 'zoom' => _request('zoom'), |
---|
110 | 'zone' => _request('zone') |
---|
111 | ); |
---|
112 | // Articles |
---|
113 | if ($exec == 'articles' && $GLOBALS['meta']['geoportail_geoarticle']) |
---|
114 | { $id_article = $contexte['id_objet'] = $flux['args']['id_article']; |
---|
115 | if ($GLOBALS['meta']['geoportail_geodocument']) $contexte['id_article'] = $flux['args']['id_article']; |
---|
116 | $contexte['objet'] = 'article'; |
---|
117 | // position de la rubrique mere |
---|
118 | $r = spip_fetch_array(spip_query("SELECT id_rubrique FROM spip_articles WHERE id_article=$id_article")); |
---|
119 | if ($r) |
---|
120 | { $id_rubrique = $r['id_rubrique']; |
---|
121 | $a = spip_fetch_array(spip_query("SELECT * FROM spip_geopositions WHERE id_objet=$id_rubrique AND objet='rubrique'")); |
---|
122 | if ($a) $contexte['pos_article'] = $a['lon'].",".$a['lat'].",".$a['zoom']; |
---|
123 | } |
---|
124 | } |
---|
125 | // Auteurs |
---|
126 | else if ($exec == 'auteur_infos' && $GLOBALS['meta']['geoportail_geoauteur']) |
---|
127 | { $contexte['id_objet'] = $flux['args']['id_auteur']; |
---|
128 | $contexte['objet'] = 'auteur'; |
---|
129 | } |
---|
130 | // Rubriques |
---|
131 | else if ($exec == 'naviguer' && $GLOBALS['meta']['geoportail_georubrique']) |
---|
132 | { $id_rubrique = $contexte['id_objet'] = $flux['args']['id_rubrique']; |
---|
133 | $contexte['objet'] = 'rubrique'; |
---|
134 | // position de la rubrique mere |
---|
135 | $r = spip_fetch_array(spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique")); |
---|
136 | if ($r) |
---|
137 | { $id_rubrique = $r['id_parent']; |
---|
138 | $a = spip_fetch_array(spip_query("SELECT * FROM spip_geopositions WHERE id_objet=$id_rubrique AND objet='rubrique'")); |
---|
139 | if ($a) $contexte['pos_article'] = $a['lon'].",".$a['lat'].",".$a['zoom']; |
---|
140 | } |
---|
141 | } |
---|
142 | // Documents (utile avec le plugin mediatheque) |
---|
143 | else if ($exec == 'documents_edit' && $GLOBALS['meta']['geoportail_geodocument']) |
---|
144 | { $contexte['id_objet'] = $flux['args']['id_document']; |
---|
145 | $contexte['objet'] = 'document'; |
---|
146 | } |
---|
147 | // Mots |
---|
148 | else if ($exec == 'mots_edit' && $GLOBALS['meta']['geoportail_geomot']) |
---|
149 | { $contexte['id_objet'] = $flux['args']['id_mot']; |
---|
150 | $contexte['objet'] = 'mot'; |
---|
151 | } |
---|
152 | // Breves |
---|
153 | else if ($exec == 'breves_voir' && $GLOBALS['meta']['geoportail_geobreve']) |
---|
154 | { $contexte['id_objet'] = $flux['args']['id_breve']; |
---|
155 | $contexte['objet'] = 'breve'; |
---|
156 | } |
---|
157 | // Sites |
---|
158 | else if ($exec == 'sites' && $GLOBALS['meta']['geoportail_geosyndic']) |
---|
159 | { $contexte['id_objet'] = $flux['args']['id_syndic']; |
---|
160 | $contexte['objet'] = 'syndic'; |
---|
161 | } |
---|
162 | // Si plugin Agenda |
---|
163 | else if ($exec == 'evenements_edit') |
---|
164 | { $contexte['id_objet'] = $flux['args']['id_evenement']; |
---|
165 | $contexte['objet'] = 'evenement'; |
---|
166 | // Position de l'article parent |
---|
167 | $id_article = $flux['args']['id_article']; |
---|
168 | $a = spip_fetch_array(spip_query("SELECT * FROM spip_geopositions WHERE id_objet=$id_article AND objet='article'")); |
---|
169 | if ($a) $contexte['pos_article'] = $a['lon'].",".$a['lat'].",".$a['zoom']; |
---|
170 | } |
---|
171 | // Afficher le formulaire |
---|
172 | if ($contexte['id_objet']) |
---|
173 | { $flux['data'] .= |
---|
174 | debut_cadre_enfonce(_DIR_PLUGIN_GEOPORTAIL."img/punaise.png", true, "", |
---|
175 | "<a id=carto href=\"javascript:geoportail_formulaire_show()\">" |
---|
176 | ."<img class=carto_show src='".find_in_path('images/deplierhaut.gif')."' title='"._T('spip:info_deplier')."' />" |
---|
177 | ."<img class=carto_show style='display:none;' src='".find_in_path('images/deplierbas.gif')."' title='"._T('spip:info_deplier')."' />" |
---|
178 | ."</a>" |
---|
179 | ._T("geoportail:geoposition") |
---|
180 | ." <img class=carto_patience style='display:none; vertical-align:top;' src='".find_in_path('images/searching.gif')."' />" |
---|
181 | ) |
---|
182 | . recuperer_fond ('formulaires/geoportail_formulaire',$contexte) |
---|
183 | . fin_cadre_enfonce(true); |
---|
184 | } |
---|
185 | return $flux; |
---|
186 | } |
---|
187 | |
---|
188 | /** seulement en SPIP v.2 |
---|
189 | idem pour les documents : afficher le lien |
---|
190 | Recherche automatique d'un georef dans le ficher (si cas geoportail_geodocument_auto) |
---|
191 | */ |
---|
192 | function geoportail_afficher_contenu_objet($flux) |
---|
193 | { |
---|
194 | if ($flux['args']['type']=='case_document' && $GLOBALS['meta']['geoportail_geodocument']) |
---|
195 | { // permettre la modification du document (documents_edit) |
---|
196 | $id_article = _request('id_article'); |
---|
197 | if (!$id_article) $id_rubrique = _request('id_rubrique'); |
---|
198 | $id_document = $flux['args']['id']; |
---|
199 | if (autoriser('modifier','document', $id_document)) |
---|
200 | { // Recherche du document |
---|
201 | $document = spip_fetch_array(spip_query("SELECT * FROM spip_documents WHERE id_document = ".$id_document)); |
---|
202 | $titre = $document['titre']; |
---|
203 | $fichier = $document['fichier']; |
---|
204 | $descriptif = $document['descriptif']; |
---|
205 | $extension = $document['extension']; |
---|
206 | $distant = $document['distant']; |
---|
207 | if (!$extension) |
---|
208 | { $result = spip_fetch_array(spip_query("SELECT * FROM spip_types_documents WHERE id_type=".$document['id_type'])); |
---|
209 | $extension = $result['extensions']; |
---|
210 | } |
---|
211 | // Georeferencement de l'objet |
---|
212 | include_spip('public/geoportail_boucles'); |
---|
213 | $info =_T('geoportail:georef'); |
---|
214 | $result = spip_fetch_array(spip_query("SELECT * FROM spip_geopositions WHERE id_objet=$id_document AND objet='document'")); |
---|
215 | if ($result) |
---|
216 | { $lon=$result['lon']; |
---|
217 | $lat=$result['lat']; |
---|
218 | $info = "(".geoportail_longitude($lon,true).", ".geoportail_latitude($lat,true).")"; |
---|
219 | } |
---|
220 | // Rechercher le georeferencement sur le fichier |
---|
221 | else if ($GLOBALS['meta']['geoportail_geodocument_auto']) |
---|
222 | { include_spip('inc/geoupload'); |
---|
223 | if ($distant != 'oui' && geoportail_get_coord(_DIR_IMG.$fichier,$extension,$lon,$lat)) |
---|
224 | $info = "(".geoportail_longitude($lon,true).", ".geoportail_latitude($lat,true).")"; |
---|
225 | $id_position = sql_insert("spip_geopositions", |
---|
226 | "(id_objet, objet, lon, lat, zoom, zone)", |
---|
227 | "($id_document, 'document', $lon, $lat, 10, 'FXX')" |
---|
228 | ); |
---|
229 | } |
---|
230 | |
---|
231 | $flux['data'] .= '<a style="display:block; text-align:center;" href="' |
---|
232 | .generer_url_ecrire("geodocuments_edit","id_article=$id_article&id_rubrique=$id_rubrique&id_document=$id_document",true) |
---|
233 | .'">'.$info.'</a>'; |
---|
234 | } |
---|
235 | } |
---|
236 | return $flux; |
---|
237 | } |
---|
238 | |
---|
239 | /** Ne pas exporter le RGC en SPIP v2 ! */ |
---|
240 | function geoportail_lister_tables_noexport($liste) |
---|
241 | { |
---|
242 | $liste[] = 'spip_georgc'; |
---|
243 | return $liste; |
---|
244 | } |
---|
245 | |
---|
246 | ?> |
---|