[SPIP] ~maj v2.1.25-->2.1.26
[velocampus/web/www.git] / www / plugins / auto / ieconfig / formulaires / ieconfig_import.php
1 <?php
2
3 if (!defined("_ECRIRE_INC_VERSION")) return;
4
5 function ieconfig_saisies_import() {
6 // Etape de selection du fichier
7 if (!_request('_code_yaml') or _request('annuler') or _request('importer')) {
8 $saisies = array (
9 array(
10 'saisie' => 'fieldset',
11 'options' => array(
12 'nom' => 'ieconfig_import_choix_fichier',
13 'label' => '<:ieconfig:label_ieconfig_import_choix_fichier:>',
14 'icone' => 'img/ieconfig-import.png'
15 ),
16 'saisies' => array(
17 array(
18 'saisie' => 'input',
19 'options' => array(
20 'type' => 'file',
21 'nom' => 'ieconfig_import_fichier',
22 'label' => '<:ieconfig:label_ieconfig_import_fichier:>',
23 'explication' => '<:ieconfig:explication_ieconfig_import_fichier:>'
24 )
25 ),
26 array(
27 'saisie' => 'selection',
28 'options' => array(
29 'type' => 'selection',
30 'nom' => 'ieconfig_import_local',
31 'label' => '<:ieconfig:label_ieconfig_import_local:>',
32 'explication' => '<:ieconfig:explication_ieconfig_import_local:>',
33 'cacher_option_intro' => 'oui',
34 'datas' => ieconfig_config_locales()
35 )
36 )
37 )
38 )
39 );
40 // Options d'importations
41 } else {
42 include_spip('inc/yaml');
43 $config = yaml_decode(_request('_code_yaml'));
44 $texte_explication = '<b>'._T('ieconfig:texte_nom').'</b> '._T_ou_typo($config['nom']);
45 if ($config['description']!= '')
46 $texte_explication .= '<br /><b>'._T('ieconfig:texte_description').'</b> '._T_ou_typo($config['description']);
47 // On identifie les entrées ne correspondant pas à un plugin
48 // Convention : les clés du tableau de config correspondent aux préfixes des plugins
49 $entrees = $config;
50 unset($entrees['nom']);
51 unset($entrees['description']);
52 unset($entrees['necessite']);
53 unset($entrees['spip_contenu']);
54 unset($entrees['spip_interactivite']);
55 $entrees = array_map('strtolower',array_keys($entrees));
56 $plugins = array_map('strtolower',array_keys(unserialize($GLOBALS['meta']['plugin'])));
57 $plugins_manquants = array_diff($entrees,$plugins);
58 if (count($plugins_manquants)>0)
59 $texte_explication .= '<p class="reponse_formulaire reponse_formulaire_erreur">'._T('ieconfig:texte_plugins_manquants',array('plugins' => implode(', ',$plugins_manquants))).'</p>';
60
61 $saisies = array(
62 array(
63 'saisie' => 'explication',
64 'options' => array(
65 'nom' => 'import_details',
66 'texte' => $texte_explication
67 )
68 )
69 );
70 // Le fichier contient-il une configuration des contenus du site
71 if (isset($config['spip_contenu'])) {
72 $texte_explication = _T('ieconfig:texte_spip_contenu_import_explication');
73 $i = 0;
74 foreach($config['spip_contenu'] as $meta => $valeur)
75 if ($GLOBALS['meta'][$meta] != $valeur) {
76 $texte_explication .= '<br />&raquo; '.$meta.' : '.$GLOBALS['meta'][$meta].' -> '.$valeur;
77 $i++;
78 }
79 if ($i>0)
80 $saisies_spip_contenu = array(
81 array(
82 'saisie' => 'fieldset',
83 'options' => array(
84 'nom' => 'spip_contenu',
85 'label' => '<:spip:onglet_contenu_site:>',
86 'icone' => 'images/racine-site-24.gif'
87 ),
88 'saisies' => array(
89 array(
90 'saisie' => 'explication',
91 'options' => array(
92 'nom' => 'spip_contenu_explication',
93 'texte' => $texte_explication
94 )
95 ),
96 array(
97 'saisie' => 'oui_non',
98 'options' => array(
99 'nom' => 'spip_contenu_importer',
100 'label' => '<:ieconfig:label_importer:>',
101 'defaut' => '',
102 )
103 )
104 )
105 )
106 );
107 else
108 $saisies_spip_contenu = array(
109 array(
110 'saisie' => 'fieldset',
111 'options' => array(
112 'nom' => 'spip_contenu',
113 'label' => '<:spip:onglet_contenu_site:>',
114 'icone' => 'images/racine-site-24.gif'
115 ),
116 'saisies' => array(
117 array(
118 'saisie' => 'explication',
119 'options' => array(
120 'nom' => 'spip_contenu_explication',
121 'texte' => '<:ieconfig:texte_configuration_identique:>'
122 )
123 )
124 )
125 )
126 );
127 $saisies = array_merge($saisies,$saisies_spip_contenu);
128 }
129 // Le fichier contient-il une configuration pour l'onglet interactivité
130 if (isset($config['spip_interactivite'])) {
131 $texte_explication = _T('ieconfig:texte_spip_interactivite_import_explication');
132 $i = 0;
133 foreach($config['spip_interactivite'] as $meta => $valeur)
134 if ($GLOBALS['meta'][$meta] != $valeur) {
135 $texte_explication .= '<br />&raquo; '.$meta.' : '.$GLOBALS['meta'][$meta].' -> '.$valeur;
136 $i++;
137 }
138 if ($i>0)
139 $saisies_spip_interactivite = array(
140 array(
141 'saisie' => 'fieldset',
142 'options' => array(
143 'nom' => 'spip_interactivite',
144 'label' => '<:spip:onglet_interactivite:>',
145 'icone' => 'images/forum-interne-24.gif'
146 ),
147 'saisies' => array(
148 array(
149 'saisie' => 'explication',
150 'options' => array(
151 'nom' => 'spip_interactivite_explication',
152 'texte' => $texte_explication
153 )
154 ),
155 array(
156 'saisie' => 'oui_non',
157 'options' => array(
158 'nom' => 'spip_interactivite_importer',
159 'label' => '<:ieconfig:label_importer:>',
160 'defaut' => '',
161 )
162 )
163 )
164 )
165 );
166 else
167 $saisies_spip_interactivite = array(
168 array(
169 'saisie' => 'fieldset',
170 'options' => array(
171 'nom' => 'spip_interactivite',
172 'label' => '<:spip:onglet_interactivite:>',
173 'icone' => 'images/forum-interne-24.gif'
174 ),
175 'saisies' => array(
176 array(
177 'saisie' => 'explication',
178 'options' => array(
179 'nom' => 'spip_interactivite_explication',
180 'texte' => '<:ieconfig:texte_configuration_identique:>'
181 )
182 )
183 )
184 )
185 );
186 $saisies = array_merge($saisies,$saisies_spip_interactivite);
187 }
188
189 // On passe via le pipeline ieconfig
190 $saisies = pipeline('ieconfig',array(
191 'args' => array(
192 'action' => 'form_import',
193 'config' => $config
194 ),
195 'data' => $saisies
196 ));
197
198 // Gestion des plugins utilisant le pipeline ieconfig_metas
199 foreach(pipeline('ieconfig_metas',array()) as $prefixe => $data){
200 if(isset($config[$prefixe]))
201 $saisies[] = array(
202 'saisie' => 'fieldset',
203 'options' => array(
204 'nom' => $prefixe,
205 'label' => isset($data['titre']) ? $data['titre'] : $prefixe,
206 'icone' => isset($data['icone']) ? $data['icone'] : ''
207 ),
208 'saisies' => array(
209 array(
210 'saisie' => 'oui_non',
211 'options' => array(
212 'nom' => 'import_'.$prefixe,
213 'label' => _T('ieconfig:label_importer'),
214 'defaut' => ''
215 )
216 )
217 )
218 );
219 }
220 }
221 return $saisies;
222 }
223
224 function formulaires_ieconfig_import_charger_dist() {
225 include_spip('inc/saisies');
226 $saisies = ieconfig_saisies_import();
227 $contexte = array(
228 '_saisies' => $saisies,
229 );
230 if (_request('_code_yaml') and !_request('annuler') and !_request('importer'))
231 $contexte['_code_yaml'] = _request('_code_yaml');
232 return array_merge(saisies_charger_champs($saisies),$contexte);
233 }
234
235 function formulaires_ieconfig_import_verifier_dist() {
236 $erreurs = array();
237 // Etape de selection du fichier
238 if (!_request('_code_yaml')) {
239 // On a rien transmis et pas de fichier local
240 if (!_request('ieconfig_import_local') AND $_FILES['ieconfig_import_fichier']['name']=='')
241 $erreurs['message_erreur'] = _T('ieconfig:message_erreur_fichier_import_manquant');
242 }
243 // Options d'import
244 else {
245 include_spip('inc/saisies');
246 $erreurs = saisies_verifier(ieconfig_saisies_import());
247 }
248 return $erreurs;
249 }
250
251 function formulaires_ieconfig_import_traiter_dist() {
252 // Si on est à l'étape de sélection d'un fichier de configuration
253 // On place le code YAML dans le contexte
254 if (!_request('_code_yaml')) {
255 if ($_FILES['ieconfig_import_fichier']['name']!='')
256 $fichier = $_FILES['ieconfig_import_fichier']['tmp_name'];
257 else
258 $fichier = _request('ieconfig_import_local');
259 lire_fichier($fichier, $code_yaml);
260 set_request('_code_yaml',$code_yaml);
261 }
262 // Si on valide l'import
263 elseif (_request('importer') && _request('_code_yaml')) {
264 include_spip('inc/yaml');
265 $config = yaml_decode(_request('_code_yaml'));
266
267 // Le fichier contient-il une configuration des contenus du site à importer
268 if (isset($config['spip_contenu']) && _request('spip_contenu_importer')=='on') {
269 foreach($config['spip_contenu'] as $nom => $valeur)
270 ecrire_meta($nom,$valeur);
271 }
272
273 // Le fichier contient-il une configuration pour l'ongler interactivité
274 if (isset($config['spip_interactivite']) && _request('spip_interactivite_importer')=='on') {
275 foreach($config['spip_interactivite'] as $nom => $valeur)
276 ecrire_meta($nom,$valeur);
277 }
278
279 // On passe via le pipeline ieconfig
280 $message_erreur = pipeline('ieconfig',array(
281 'args' => array(
282 'action' => 'import',
283 'config' => $config
284 ),
285 'data' => ''
286 ));
287
288 // Gestion des plugins utilisant le pipeline ieconfig_metas
289 foreach(pipeline('ieconfig_metas',array()) as $prefixe => $data){
290 if(_request('import_'.$prefixe)=='on' && isset($config[$prefixe])) {
291 if(isset($data['metas_brutes']))
292 foreach(explode(',',$data['metas_brutes']) as $meta)
293 if (isset($config[$prefixe][$meta]))
294 ecrire_meta($meta,$config[$prefixe][$meta]);
295 if(isset($data['metas_serialize']))
296 foreach(explode(',',$data['metas_serialize']) as $meta)
297 if (isset($config[$prefixe][$meta]))
298 ecrire_meta($meta,serialize($config[$prefixe][$meta]));
299 }
300 }
301
302 ecrire_metas();
303
304 if ($message_erreur!='')
305 return array('message_erreur' => $message_erreur);
306 else
307 return array('message_ok' => _T('ieconfig:message_ok_import'));
308 }
309 }
310
311 // Renvoie la liste des fichiers de configurations présents dans un sous-répertoires ieconfig/
312 function ieconfig_config_locales() {
313 static $liste_config = null;
314
315 if (is_null($liste_config)){
316 include_spip('inc/yaml');
317 $liste_config = array();
318 $match = ".+[.]yaml$";
319 foreach (array_merge(find_all_in_path('ieconfig/', $match),find_all_in_path('tmp/ieconfig/', $match)) as $fichier => $chemin) {
320 $config = yaml_decode_file($chemin);
321 // On regarde s'il y a un necessite
322 $ok = true;
323 if (isset($config['necessite'])) {
324 if (!is_array($config['necessite']))
325 $config['necessite'] = array($config['necessite']);
326 foreach($config['necessite'] as $plugin)
327 if (!defined('_DIR_PLUGIN_'.strtoupper($plugin)))
328 $ok = false;
329 }
330 //on vérifie s'il y a un champs nom
331 if ($ok) {
332 if (isset($config['nom']))
333 $liste_config[$chemin] = _T_ou_typo($config['nom']);
334 else
335 $liste_config[$chemin] = $fichier;
336 }
337 }
338 }
339 return $liste_config;
340 }
341
342
343 ?>