3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/lang');
16 include_spip('inc/actions');
17 include_spip('base/dump');
19 // http://doc.spip.org/@action_export_all_dist
20 function action_export_all_dist()
22 $securiser_action = charger_fonction('securiser_action', 'inc');
23 $arg = $securiser_action();
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);
33 utiliser_langue_visiteur();
35 $corps = _T('avis_erreur_sauvegarde', array('type'=>'.', 'id_objet'=>'. .'));
37 $corps = export_all_report_size($file, $rub, $size, generer_url_ecrire())
38 . export_all_report_tables($tables);
40 include_spip('inc/minipres');
41 echo minipres(_T('info_sauvegarde'), $corps);
44 function export_all_rename($nom, $subdir)
46 $dir = dirname($subdir);
47 $dest = $dir . '/' . $nom;
48 if (file_exists($dest)) {
50 while (@file_exists
($new = "$dir/$n-$nom")) $n++
;
51 spip_log("renomme vieux $dest en $new");
57 // Concatenation des tranches
59 // http://doc.spip.org/@ramasse_parties
60 function ramasse_parties($rub, $archive, $meta)
62 $dir = base_dump_dir($meta);
63 $files = preg_files($dir . $archive . ".part_[0-9]+_[0-9]+[.gz]?");
64 if (!$files) return false;
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) {
72 if (lire_fichier ($f, $contenu)) {
73 if (!ecrire_fichier($but,$contenu,false,false))
74 { $ok = false; break;}
79 ecrire_fichier($but, export_enpied(),false,false);
81 spip_log("concatenation " . join(' ', $files_o));
82 return $ok ?
$but : false;
85 function export_all_end($meta, $archive){
86 $dir = base_dump_dir($meta);
87 $file = $dir . $archive;
90 // http://doc.spip.org/@export_entete
91 function export_entete($version_archive)
94 "<" . "?xml version=\"1.0\" encoding=\"".
95 $GLOBALS['meta']['charset']."\"?".">\n" .
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
. "\"
107 // production de l'en-pied du fichier d'archive
108 // http://doc.spip.org/@export_enpied
109 function export_enpied () { return "</SPIP>\n";}
111 function export_all_report_size($dest, $rub, $size, $retour)
113 global $spip_lang_left,$spip_lang_right;
115 // ne pas effrayer inutilement: il peut y avoir moins de fichiers
116 // qu'annonce' si certains etaient vides
118 $n = _T('taille_octets', array('taille' => number_format($size, 0, ' ', ' ')));
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',
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>"));
130 $titre = _T('info_sauvegarde_reussi_02',
131 array('archive' => ':<br /><b>'.joli_repertoire($dest)."</b> ($n)"));
133 include_spip('inc/filtres');
134 return "<p style='text-align: $spip_lang_left'>".
136 " <a href='" . $retour . "'>".
137 _T('info_sauvegarde_reussi_03')
139 ._T('info_sauvegarde_reussi_04')
141 . "<div style='text-align: $spip_lang_right'>"
142 . bouton_action(_T("retour"), $retour)
146 function export_all_report_tables($tables_sauvegardees)
148 sort($tables_sauvegardees);
149 $n = floor(count($tables_sauvegardees)/2);
151 return "<div style='width:49%;float:left;'><ul><li>"
152 . join('</li><li>', array_slice($tables_sauvegardees,0,$n))
154 . "<div style='width:49%;float:left;'><ul><li>"
155 . join('</li><li>', array_slice($tables_sauvegardees,$n))
157 . "<div class='nettoyeur'></div>";