[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / ecrire / action / export_all.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 include_spip('inc/lang');
16 include_spip('inc/actions');
17 include_spip('base/dump');
18
19 // http://doc.spip.org/@action_export_all_dist
20 function action_export_all_dist()
21 {
22 $securiser_action = charger_fonction('securiser_action', 'inc');
23 $arg = $securiser_action();
24
25 @list(, , $archive, $rub) = explode(',', $arg);
26 $meta = base_dump_meta_name($rub);
27 $file = ramasse_parties($rub, $archive, $meta);
28 $size = !$file ? 0 : @(!file_exists($file) ? 0 : filesize($file));
29 $metatable = $meta . '_tables';
30 $tables = isset($GLOBALS['meta'][$metatable])?unserialize($GLOBALS['meta'][$metatable]):array();
31 effacer_meta($metatable);
32 effacer_meta($meta);
33 utiliser_langue_visiteur();
34 if (!$size)
35 $corps = _T('avis_erreur_sauvegarde', array('type'=>'.', 'id_objet'=>'. .'));
36 else {
37 $corps = export_all_report_size($file, $rub, $size, generer_url_ecrire())
38 . export_all_report_tables($tables);
39 }
40 include_spip('inc/minipres');
41 echo minipres(_T('info_sauvegarde'), $corps);
42 }
43
44 function export_all_rename($nom, $subdir)
45 {
46 $dir = dirname($subdir);
47 $dest = $dir . '/' . $nom;
48 if (file_exists($dest)) {
49 $n = 1;
50 while (@file_exists($new = "$dir/$n-$nom")) $n++;
51 spip_log("renomme vieux $dest en $new");
52 @rename($dest, $new);
53 }
54 return $dest;
55 }
56
57 // Concatenation des tranches
58
59 // http://doc.spip.org/@ramasse_parties
60 function ramasse_parties($rub, $archive, $meta)
61 {
62 $dir = base_dump_dir($meta);
63 $files = preg_files($dir . $archive . ".part_[0-9]+_[0-9]+[.gz]?");
64 if (!$files) return false;
65 $ok = true;
66 $files_o = array();
67 $but = export_all_rename($archive, $dir);
68 // creer l'en tete du fichier
69 ecrire_fichier($but, export_entete(_VERSION_ARCHIVE),false);
70 foreach($files as $f) {
71 $contenu = "";
72 if (lire_fichier ($f, $contenu)) {
73 if (!ecrire_fichier($but,$contenu,false,false))
74 { $ok = false; break;}
75 }
76 spip_unlink($f);
77 $files_o[]=$f;
78 }
79 ecrire_fichier($but, export_enpied(),false,false);
80 spip_unlink($dir);
81 spip_log("concatenation " . join(' ', $files_o));
82 return $ok ? $but : false;
83 }
84
85 function export_all_end($meta, $archive){
86 $dir = base_dump_dir($meta);
87 $file = $dir . $archive;
88 }
89
90 // http://doc.spip.org/@export_entete
91 function export_entete($version_archive)
92 {
93 return
94 "<" . "?xml version=\"1.0\" encoding=\"".
95 $GLOBALS['meta']['charset']."\"?".">\n" .
96 "<SPIP
97 version=\"" . $GLOBALS['spip_version_affichee'] . "\"
98 version_base=\"" . $GLOBALS['spip_version_base'] . "\"
99 version_archive=\"" . $version_archive . "\"
100 adresse_site=\"" . $GLOBALS['meta']["adresse_site"] . "\"
101 dir_img=\"" . _DIR_IMG . "\"
102 dir_logos=\"" . _DIR_LOGOS . "\"
103 >\n";
104 }
105
106
107 // production de l'en-pied du fichier d'archive
108 // http://doc.spip.org/@export_enpied
109 function export_enpied () { return "</SPIP>\n";}
110
111 function export_all_report_size($dest, $rub, $size, $retour)
112 {
113 global $spip_lang_left,$spip_lang_right;
114
115 // ne pas effrayer inutilement: il peut y avoir moins de fichiers
116 // qu'annonce' si certains etaient vides
117
118 $n = _T('taille_octets', array('taille' => number_format($size, 0, ' ', ' ')));
119
120 // cette chaine est a refaire car il y a double ambiguite:
121 // - si plusieurs SPIP dans une base SQL (cf table_prefix)
122 // - si on exporte seulement une rubrique
123 # _T('info_sauvegarde_reussi_02',
124
125 if ($rub) {
126 $titre = sql_getfetsel('titre', 'spip_rubriques', "id_rubrique=$rub");
127 $titre = _T('info_sauvegarde_rubrique_reussi',
128 array('archive' => ':<br /><b>'.joli_repertoire($dest)."</b> ($n)", 'titre' => "<b>$titre</b>"));
129 } else
130 $titre = _T('info_sauvegarde_reussi_02',
131 array('archive' => ':<br /><b>'.joli_repertoire($dest)."</b> ($n)"));
132
133 include_spip('inc/filtres');
134 return "<p style='text-align: $spip_lang_left'>".
135 $titre .
136 " <a href='" . $retour . "'>".
137 _T('info_sauvegarde_reussi_03')
138 . "</a> "
139 ._T('info_sauvegarde_reussi_04')
140 . "</p>\n"
141 . "<div style='text-align: $spip_lang_right'>"
142 . bouton_action(_T("retour"), $retour)
143 . "</div>" ;
144 }
145
146 function export_all_report_tables($tables_sauvegardees)
147 {
148 sort($tables_sauvegardees);
149 $n = floor(count($tables_sauvegardees)/2);
150
151 return "<div style='width:49%;float:left;'><ul><li>"
152 . join('</li><li>', array_slice($tables_sauvegardees,0,$n))
153 . "</li></ul></div>"
154 . "<div style='width:49%;float:left;'><ul><li>"
155 . join('</li><li>', array_slice($tables_sauvegardees,$n))
156 . "</li></ul></div>"
157 . "<div class='nettoyeur'></div>";
158 }
159 ?>