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