3 if (!defined("_ECRIRE_INC_VERSION")) return;
5 function ieconfig_saisies_import() {
6 // Etape de selection du fichier
7 if (!_request('_code_yaml') or _request('annuler') or _request('importer')) {
10 'saisie' => 'fieldset',
12 'nom' => 'ieconfig_import_choix_fichier',
13 'label' => '<:ieconfig:label_ieconfig_import_choix_fichier:>',
14 'icone' => 'img/ieconfig-import.png'
21 'nom' => 'ieconfig_import_fichier',
22 'label' => '<:ieconfig:label_ieconfig_import_fichier:>',
23 'explication' => '<:ieconfig:explication_ieconfig_import_fichier:>'
27 'saisie' => 'selection',
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()
40 // Options d'importations
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
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>';
63 'saisie' => 'explication',
65 'nom' => 'import_details',
66 'texte' => $texte_explication
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');
74 foreach($config['spip_contenu'] as $meta => $valeur)
75 if ($GLOBALS['meta'][$meta] != $valeur) {
76 $texte_explication .= '<br />» '.$meta.' : '.$GLOBALS['meta'][$meta].' -> '.$valeur;
80 $saisies_spip_contenu = array(
82 'saisie' => 'fieldset',
84 'nom' => 'spip_contenu',
85 'label' => '<:spip:onglet_contenu_site:>',
86 'icone' => 'images/racine-site-24.gif'
90 'saisie' => 'explication',
92 'nom' => 'spip_contenu_explication',
93 'texte' => $texte_explication
97 'saisie' => 'oui_non',
99 'nom' => 'spip_contenu_importer',
100 'label' => '<:ieconfig:label_importer:>',
108 $saisies_spip_contenu = array(
110 'saisie' => 'fieldset',
112 'nom' => 'spip_contenu',
113 'label' => '<:spip:onglet_contenu_site:>',
114 'icone' => 'images/racine-site-24.gif'
118 'saisie' => 'explication',
120 'nom' => 'spip_contenu_explication',
121 'texte' => '<:ieconfig:texte_configuration_identique:>'
127 $saisies = array_merge($saisies,$saisies_spip_contenu);
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');
133 foreach($config['spip_interactivite'] as $meta => $valeur)
134 if ($GLOBALS['meta'][$meta] != $valeur) {
135 $texte_explication .= '<br />» '.$meta.' : '.$GLOBALS['meta'][$meta].' -> '.$valeur;
139 $saisies_spip_interactivite = array(
141 'saisie' => 'fieldset',
143 'nom' => 'spip_interactivite',
144 'label' => '<:spip:onglet_interactivite:>',
145 'icone' => 'images/forum-interne-24.gif'
149 'saisie' => 'explication',
151 'nom' => 'spip_interactivite_explication',
152 'texte' => $texte_explication
156 'saisie' => 'oui_non',
158 'nom' => 'spip_interactivite_importer',
159 'label' => '<:ieconfig:label_importer:>',
167 $saisies_spip_interactivite = array(
169 'saisie' => 'fieldset',
171 'nom' => 'spip_interactivite',
172 'label' => '<:spip:onglet_interactivite:>',
173 'icone' => 'images/forum-interne-24.gif'
177 'saisie' => 'explication',
179 'nom' => 'spip_interactivite_explication',
180 'texte' => '<:ieconfig:texte_configuration_identique:>'
186 $saisies = array_merge($saisies,$saisies_spip_interactivite);
189 // On passe via le pipeline ieconfig
190 $saisies = pipeline('ieconfig',array(
192 'action' => 'form_import',
198 // Gestion des plugins utilisant le pipeline ieconfig_metas
199 foreach(pipeline('ieconfig_metas',array()) as $prefixe => $data){
200 if(isset($config[$prefixe]))
202 'saisie' => 'fieldset',
205 'label' => isset($data['titre']) ?
$data['titre'] : $prefixe,
206 'icone' => isset($data['icone']) ?
$data['icone'] : ''
210 'saisie' => 'oui_non',
212 'nom' => 'import_'.$prefixe,
213 'label' => _T('ieconfig:label_importer'),
224 function formulaires_ieconfig_import_charger_dist() {
225 include_spip('inc/saisies');
226 $saisies = ieconfig_saisies_import();
228 '_saisies' => $saisies,
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);
235 function formulaires_ieconfig_import_verifier_dist() {
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');
245 include_spip('inc/saisies');
246 $erreurs = saisies_verifier(ieconfig_saisies_import());
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'];
258 $fichier = _request('ieconfig_import_local');
259 lire_fichier($fichier, $code_yaml);
260 set_request('_code_yaml',$code_yaml);
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'));
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);
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);
279 // On passe via le pipeline ieconfig
280 $message_erreur = pipeline('ieconfig',array(
282 'action' => 'import',
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]));
304 if ($message_erreur!='')
305 return array('message_erreur' => $message_erreur);
307 return array('message_ok' => _T('ieconfig:message_ok_import'));
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;
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
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)))
330 //on vérifie s'il y a un champs nom
332 if (isset($config['nom']))
333 $liste_config[$chemin] = _T_ou_typo($config['nom']);
335 $liste_config[$chemin] = $fichier;
339 return $liste_config;