1 | <?php |
---|
2 | |
---|
3 | if (!defined('_ECRIRE_INC_VERSION')) { |
---|
4 | return; |
---|
5 | } |
---|
6 | |
---|
7 | function ieconfig_saisies_export() |
---|
8 | { |
---|
9 | $saisies = array( |
---|
10 | // Options d'export |
---|
11 | array( |
---|
12 | 'saisie' => 'fieldset', |
---|
13 | 'options' => array( |
---|
14 | 'nom' => 'ieconfig_export', |
---|
15 | 'label' => '<:ieconfig:label_ieconfig_export:>', |
---|
16 | 'icone' => 'img/ieconfig-export.png', |
---|
17 | ), |
---|
18 | 'saisies' => array( |
---|
19 | array( |
---|
20 | 'saisie' => 'input', |
---|
21 | 'options' => array( |
---|
22 | 'nom' => 'ieconfig_export_nom', |
---|
23 | 'label' => '<:ieconfig:label_ieconfig_export_nom:>', |
---|
24 | 'obligatoire' => 'oui', |
---|
25 | 'defaut' => $GLOBALS['meta']['nom_site'].' - '.date('Y/m/d'), |
---|
26 | ), |
---|
27 | ), |
---|
28 | array( |
---|
29 | 'saisie' => 'textarea', |
---|
30 | 'options' => array( |
---|
31 | 'nom' => 'ieconfig_export_description', |
---|
32 | 'label' => '<:ieconfig:label_ieconfig_export_description:>', |
---|
33 | 'rows' => 4, |
---|
34 | ), |
---|
35 | ), |
---|
36 | array( |
---|
37 | 'saisie' => 'explication', |
---|
38 | 'options' => array( |
---|
39 | 'nom' => 'ieconfig_export_explication', |
---|
40 | 'texte' => '<:ieconfig:texte_ieconfig_export_explication:>', |
---|
41 | ), |
---|
42 | ), |
---|
43 | array( |
---|
44 | 'saisie' => 'selection', |
---|
45 | 'options' => array( |
---|
46 | 'nom' => 'ieconfig_export_choix', |
---|
47 | 'label' => '<:ieconfig:label_ieconfig_export_choix:>', |
---|
48 | 'cacher_option_intro' => 'oui', |
---|
49 | 'defaut' => 'telecharger', |
---|
50 | 'datas' => array( |
---|
51 | 'sauvegarder' => '<:ieconfig:item_sauvegarder:>', |
---|
52 | 'telecharger' => '<:ieconfig:item_telecharger:>', |
---|
53 | ), |
---|
54 | ), |
---|
55 | ), |
---|
56 | ), |
---|
57 | ), |
---|
58 | ); |
---|
59 | // Gestion des plugins utilisant le pipeline ieconfig_metas |
---|
60 | $ieconfig_metas = array(); |
---|
61 | foreach (pipeline('ieconfig_metas', array()) as $prefixe => $data) { |
---|
62 | if (isset($data['icone'])) { |
---|
63 | $icone = chemin_image($data['icone']); |
---|
64 | if (!$icone) { |
---|
65 | $icone = find_in_path($data['icone']); |
---|
66 | } |
---|
67 | if ($icone) { |
---|
68 | $icone = '<img src="'.$icone.'" alt="" style="margin-left:0px; margin-right:0.5em;" />'; |
---|
69 | } |
---|
70 | } else { |
---|
71 | $icone = ''; |
---|
72 | } |
---|
73 | $ieconfig_metas[$prefixe] = $icone.(isset($data['titre']) ? $data['titre'] : $prefixe); |
---|
74 | } |
---|
75 | ksort($ieconfig_metas); |
---|
76 | if (count($ieconfig_metas) > 0) { |
---|
77 | $saisies[] = array( |
---|
78 | 'saisie' => 'fieldset', |
---|
79 | 'options' => array( |
---|
80 | 'nom' => 'metas_fieldset', |
---|
81 | 'label' => _T('ieconfig:label_configurations_a_exporter'), |
---|
82 | 'icone' => 'config-export-16.png', |
---|
83 | ), |
---|
84 | 'saisies' => array( |
---|
85 | array( |
---|
86 | 'saisie' => 'checkbox', |
---|
87 | 'options' => array( |
---|
88 | 'nom' => 'export_metas', |
---|
89 | 'label' => _T('ieconfig:label_configurations_a_exporter'), |
---|
90 | 'tout_selectionner' => 'oui', |
---|
91 | 'datas' => $ieconfig_metas, |
---|
92 | ), |
---|
93 | ), |
---|
94 | ), |
---|
95 | ); |
---|
96 | } |
---|
97 | |
---|
98 | // On passe via le pipeline ieconfig (pour les cas particuliers) |
---|
99 | $saisies = pipeline('ieconfig', array( |
---|
100 | 'args' => array( |
---|
101 | 'action' => 'form_export', |
---|
102 | ), |
---|
103 | 'data' => $saisies, |
---|
104 | )); |
---|
105 | |
---|
106 | return $saisies; |
---|
107 | } |
---|
108 | |
---|
109 | function formulaires_ieconfig_export_charger_dist() |
---|
110 | { |
---|
111 | $saisies = ieconfig_saisies_export(); |
---|
112 | $contexte = array( |
---|
113 | '_saisies' => $saisies, |
---|
114 | ); |
---|
115 | |
---|
116 | return array_merge(saisies_charger_champs($saisies), $contexte); |
---|
117 | } |
---|
118 | |
---|
119 | function formulaires_ieconfig_export_verifier_dist() |
---|
120 | { |
---|
121 | include_spip('inc/saisies'); |
---|
122 | |
---|
123 | return saisies_verifier(ieconfig_saisies_export()); |
---|
124 | } |
---|
125 | |
---|
126 | function formulaires_ieconfig_export_traiter_dist() |
---|
127 | { |
---|
128 | $export = array(); |
---|
129 | $export['nom'] = _request('ieconfig_export_nom'); |
---|
130 | if (_request('ieconfig_export_description') != '') { |
---|
131 | $export['description'] = _request('ieconfig_export_description'); |
---|
132 | } |
---|
133 | |
---|
134 | // On passe via le pipeline ieconfig |
---|
135 | $export = pipeline('ieconfig', array( |
---|
136 | 'args' => array( |
---|
137 | 'action' => 'export', |
---|
138 | ), |
---|
139 | 'data' => $export, |
---|
140 | )); |
---|
141 | |
---|
142 | // Gestion des plugins utilisant le pipeline ieconfig_metas |
---|
143 | $export_metas = _request('export_metas'); |
---|
144 | if (!is_array($export_metas)) { |
---|
145 | $export_metas = array(); |
---|
146 | } |
---|
147 | |
---|
148 | foreach (pipeline('ieconfig_metas', array()) as $prefixe => $data) { |
---|
149 | if (in_array($prefixe, $export_metas)) { |
---|
150 | $export_plugin = array(); |
---|
151 | if (isset($data['metas_brutes'])) { |
---|
152 | foreach (explode(',', $data['metas_brutes']) as $meta) { |
---|
153 | // On teste le cas ou un prefixe est indique (dernier caractere est *) |
---|
154 | if (substr($meta, -1) == '*') { |
---|
155 | $p = substr($meta, 0, -1); |
---|
156 | foreach ($GLOBALS['meta'] as $m => $v) { |
---|
157 | if (substr($m, 0, strlen($p)) == $p) { |
---|
158 | $export_plugin[$m] = $v; |
---|
159 | } |
---|
160 | } |
---|
161 | } elseif (isset($GLOBALS['meta'][$meta])) { |
---|
162 | $export_plugin[$meta] = $GLOBALS['meta'][$meta]; |
---|
163 | } |
---|
164 | } |
---|
165 | } |
---|
166 | if (isset($data['metas_serialize'])) { |
---|
167 | foreach (explode(',', $data['metas_serialize']) as $meta) { |
---|
168 | // On teste le cas ou un prefixe est indique (dernier caractere est *) |
---|
169 | if (substr($meta, -1) == '*') { |
---|
170 | $p = substr($meta, 0, -1); |
---|
171 | foreach ($GLOBALS['meta'] as $m => $v) { |
---|
172 | if (substr($m, 0, strlen($p)) == $p) { |
---|
173 | $export_plugin[$m] = unserialize($v); |
---|
174 | } |
---|
175 | } |
---|
176 | } elseif (isset($GLOBALS['meta'][$meta])) { |
---|
177 | $export_plugin[$meta] = unserialize($GLOBALS['meta'][$meta]); |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | if (count($export_plugin) > 0) { |
---|
182 | $export[$prefixe] = $export_plugin; |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | // On encode en yaml |
---|
188 | include_spip('inc/yaml'); |
---|
189 | $export = yaml_encode($export, array('inline' => 20)); |
---|
190 | |
---|
191 | // Nom du fichier |
---|
192 | include_spip('inc/texte'); |
---|
193 | $site = isset($GLOBALS['meta']['nom_site']) |
---|
194 | ? preg_replace(array(",\W,is", ',_(?=_),', ',_$,'), array('_', '', ''), couper(translitteration(trim($GLOBALS['meta']['nom_site'])), 30, '')) |
---|
195 | : 'spip'; |
---|
196 | $filename = $site.'_'.date('Y-m-d_H-i').'.yaml'; |
---|
197 | |
---|
198 | // Si telechargement |
---|
199 | if (_request('ieconfig_export_choix') == 'telecharger') { |
---|
200 | refuser_traiter_formulaire_ajax(); |
---|
201 | set_request('action', 'courcircuiter_affichage_usage_memoire'); // Pour empêcher l'extension dev d'ajouter un div avec l'usage mémoire. |
---|
202 | Header('Content-Type: text/x-yaml;'); |
---|
203 | Header("Content-Disposition: attachment; filename=$filename"); |
---|
204 | Header('Content-Length: '.strlen($export)); |
---|
205 | echo $export; |
---|
206 | exit; |
---|
207 | } else { |
---|
208 | sous_repertoire(_DIR_TMP, 'ieconfig'); |
---|
209 | if (ecrire_fichier(_DIR_TMP.'ieconfig/'.$filename, $export)) { |
---|
210 | return array('message_ok' => _T('ieconfig:message_ok_export', array('filename' => $filename))); |
---|
211 | } else { |
---|
212 | return array('message_erreur' => _T('ieconfig:message_erreur_export', array('filename' => $filename))); |
---|
213 | } |
---|
214 | } |
---|
215 | } |
---|