/**
* Plugin Spip-Bonux
* Le plugin qui lave plus SPIP que SPIP
- * (c) 2008 Mathieu Marcillaud, Cedric Morin, Romy Tetue
+ * (c) 2008 Mathieu Marcillaud, Cedric Morin, Tetue
* Licence GPL
*
* Fonctions d'export d'une requete sql ou d'un tableau
*
*/
-if (!defined('_ECRIRE_INC_VERSION')) return;
+if (!defined('_ECRIRE_INC_VERSION')) {
+ return;
+}
include_spip('inc/charsets');
include_spip('inc/filtres');
*/
function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) {
$output = join($delim, array_map('exporter_csv_champ', $ligne))."\r\n";
- if ($importer_charset){
+ if ($importer_charset) {
+ $output = str_replace('’', '\'', $output);
$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
}
return $output;
}
-function inc_exporter_csv_dist($titre, $resource, $delim=',', $entetes = null,$envoyer = true){
+function inc_exporter_csv_dist($titre, $resource, $delim = ',', $entetes = null, $envoyer = true) {
$filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
-
- if ($delim == 'TAB') $delim = "\t";
- if (!in_array($delim,array(',',';',"\t")))
- $delim = ",";
+
+ if ($delim == 'TAB') {
+ $delim = "\t";
+ }
+ if (!in_array($delim, array(',', ';', "\t"))) {
+ $delim = ',';
+ }
$charset = $GLOBALS['meta']['charset'];
$importer_charset = null;
- if ($delim == ',')
+ if ($delim == ',') {
$extension = 'csv';
- else {
+ } else {
$extension = 'xls';
# Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
$importer_charset = $charset = 'iso-8859-1';
}
$filename = "$filename.$extension";
- if ($entetes AND is_array($entetes) AND count($entetes))
- $output = exporter_csv_ligne($entetes,$delim,$importer_charset);
+ if ($entetes and is_array($entetes) and count($entetes)) {
+ $output = exporter_csv_ligne($entetes, $delim, $importer_charset);
+ }
// on passe par un fichier temporaire qui permet de ne pas saturer la memoire
// avec les gros exports
- $fichier = sous_repertoire(_DIR_CACHE,"export") . $filename;
+ $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
$fp = fopen($fichier, 'w');
$length = fwrite($fp, $output);
- while ($row=is_array($resource)?array_shift($resource):sql_fetch($resource)){
- $output = exporter_csv_ligne($row,$delim,$importer_charset);
+ while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
+ $output = exporter_csv_ligne($row, $delim, $importer_charset);
$length += fwrite($fp, $output);
}
fclose($fp);
//Header("Content-Type: text/plain; charset=$charset");
Header("Content-Length: $length");
ob_clean();
- flush();
- readfile($fichier);
+ flush();
+ readfile($fichier);
}
return $fichier;
}
-
-?>
\ No newline at end of file