Valider 91ee1c83 rédigé par real3t@gmail.com's avatar real3t@gmail.com
Parcourir les fichiers

[Spout] passage en trunk du plugin pour git

parent
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours

.gitattributes

0 → 100644
+147 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
* text=auto !eol
img_pack/logo.png -text
img_pack/spout-128.png -text
img_pack/spout-48.png -text
inc/exporter_csv.php -text
lib/Spout/Autoloader/Psr4Autoloader.php -text
lib/Spout/Autoloader/autoload.php -text
lib/Spout/Common/Creator/HelperFactory.php -text
lib/Spout/Common/Entity/Cell.php -text
lib/Spout/Common/Entity/Row.php -text
lib/Spout/Common/Entity/Style/Border.php -text
lib/Spout/Common/Entity/Style/BorderPart.php -text
lib/Spout/Common/Entity/Style/CellAlignment.php -text
lib/Spout/Common/Entity/Style/Color.php -text
lib/Spout/Common/Entity/Style/Style.php -text
lib/Spout/Common/Exception/EncodingConversionException.php -text
lib/Spout/Common/Exception/IOException.php -text
lib/Spout/Common/Exception/InvalidArgumentException.php -text
lib/Spout/Common/Exception/InvalidColorException.php -text
lib/Spout/Common/Exception/SpoutException.php -text
lib/Spout/Common/Exception/UnsupportedTypeException.php -text
lib/Spout/Common/Helper/CellTypeHelper.php -text
lib/Spout/Common/Helper/EncodingHelper.php -text
lib/Spout/Common/Helper/Escaper/CSV.php -text
lib/Spout/Common/Helper/Escaper/EscaperInterface.php -text
lib/Spout/Common/Helper/Escaper/ODS.php -text
lib/Spout/Common/Helper/Escaper/XLSX.php -text
lib/Spout/Common/Helper/FileSystemHelper.php -text
lib/Spout/Common/Helper/FileSystemHelperInterface.php -text
lib/Spout/Common/Helper/GlobalFunctionsHelper.php -text
lib/Spout/Common/Helper/StringHelper.php -text
lib/Spout/Common/Manager/OptionsManagerAbstract.php -text
lib/Spout/Common/Manager/OptionsManagerInterface.php -text
lib/Spout/Common/Type.php -text
lib/Spout/Reader/CSV/Creator/InternalEntityFactory.php -text
lib/Spout/Reader/CSV/Manager/OptionsManager.php -text
lib/Spout/Reader/CSV/Reader.php -text
lib/Spout/Reader/CSV/RowIterator.php -text
lib/Spout/Reader/CSV/Sheet.php -text
lib/Spout/Reader/CSV/SheetIterator.php -text
lib/Spout/Reader/Common/Creator/InternalEntityFactoryInterface.php -text
lib/Spout/Reader/Common/Creator/ReaderEntityFactory.php -text
lib/Spout/Reader/Common/Creator/ReaderFactory.php -text
lib/Spout/Reader/Common/Entity/Options.php -text
lib/Spout/Reader/Common/Manager/RowManager.php -text
lib/Spout/Reader/Common/XMLProcessor.php -text
lib/Spout/Reader/Exception/InvalidValueException.php -text
lib/Spout/Reader/Exception/IteratorNotRewindableException.php -text
lib/Spout/Reader/Exception/NoSheetsFoundException.php -text
lib/Spout/Reader/Exception/ReaderException.php -text
lib/Spout/Reader/Exception/ReaderNotOpenedException.php -text
lib/Spout/Reader/Exception/SharedStringNotFoundException.php -text
lib/Spout/Reader/Exception/XMLProcessingException.php -text
lib/Spout/Reader/IteratorInterface.php -text
lib/Spout/Reader/ODS/Creator/HelperFactory.php -text
lib/Spout/Reader/ODS/Creator/InternalEntityFactory.php -text
lib/Spout/Reader/ODS/Creator/ManagerFactory.php -text
lib/Spout/Reader/ODS/Helper/CellValueFormatter.php -text
lib/Spout/Reader/ODS/Helper/SettingsHelper.php -text
lib/Spout/Reader/ODS/Manager/OptionsManager.php -text
lib/Spout/Reader/ODS/Reader.php -text
lib/Spout/Reader/ODS/RowIterator.php -text
lib/Spout/Reader/ODS/Sheet.php -text
lib/Spout/Reader/ODS/SheetIterator.php -text
lib/Spout/Reader/ReaderAbstract.php -text
lib/Spout/Reader/ReaderInterface.php -text
lib/Spout/Reader/SheetInterface.php -text
lib/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php -text
lib/Spout/Reader/Wrapper/XMLReader.php -text
lib/Spout/Reader/XLSX/Creator/HelperFactory.php -text
lib/Spout/Reader/XLSX/Creator/InternalEntityFactory.php -text
lib/Spout/Reader/XLSX/Creator/ManagerFactory.php -text
lib/Spout/Reader/XLSX/Helper/CellHelper.php -text
lib/Spout/Reader/XLSX/Helper/CellValueFormatter.php -text
lib/Spout/Reader/XLSX/Helper/DateFormatHelper.php -text
lib/Spout/Reader/XLSX/Manager/OptionsManager.php -text
lib/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php -text
lib/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyInterface.php -text
lib/Spout/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php -text
lib/Spout/Reader/XLSX/Manager/SharedStringsCaching/InMemoryStrategy.php -text
lib/Spout/Reader/XLSX/Manager/SharedStringsManager.php -text
lib/Spout/Reader/XLSX/Manager/SheetManager.php -text
lib/Spout/Reader/XLSX/Manager/StyleManager.php -text
lib/Spout/Reader/XLSX/Manager/WorkbookRelationshipsManager.php -text
lib/Spout/Reader/XLSX/Reader.php -text
lib/Spout/Reader/XLSX/RowIterator.php -text
lib/Spout/Reader/XLSX/Sheet.php -text
lib/Spout/Reader/XLSX/SheetIterator.php -text
lib/Spout/Writer/CSV/Manager/OptionsManager.php -text
lib/Spout/Writer/CSV/Writer.php -text
lib/Spout/Writer/Common/Creator/InternalEntityFactory.php -text
lib/Spout/Writer/Common/Creator/ManagerFactoryInterface.php -text
lib/Spout/Writer/Common/Creator/Style/BorderBuilder.php -text
lib/Spout/Writer/Common/Creator/Style/StyleBuilder.php -text
lib/Spout/Writer/Common/Creator/WriterEntityFactory.php -text
lib/Spout/Writer/Common/Creator/WriterFactory.php -text
lib/Spout/Writer/Common/Entity/Options.php -text
lib/Spout/Writer/Common/Entity/Sheet.php -text
lib/Spout/Writer/Common/Entity/Workbook.php -text
lib/Spout/Writer/Common/Entity/Worksheet.php -text
lib/Spout/Writer/Common/Helper/CellHelper.php -text
lib/Spout/Writer/Common/Helper/FileSystemWithRootFolderHelperInterface.php -text
lib/Spout/Writer/Common/Helper/ZipHelper.php -text
lib/Spout/Writer/Common/Manager/CellManager.php -text
lib/Spout/Writer/Common/Manager/RowManager.php -text
lib/Spout/Writer/Common/Manager/SheetManager.php -text
lib/Spout/Writer/Common/Manager/Style/StyleManager.php -text
lib/Spout/Writer/Common/Manager/Style/StyleManagerInterface.php -text
lib/Spout/Writer/Common/Manager/Style/StyleMerger.php -text
lib/Spout/Writer/Common/Manager/Style/StyleRegistry.php -text
lib/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php -text
lib/Spout/Writer/Common/Manager/WorkbookManagerInterface.php -text
lib/Spout/Writer/Common/Manager/WorksheetManagerInterface.php -text
lib/Spout/Writer/Exception/Border/InvalidNameException.php -text
lib/Spout/Writer/Exception/Border/InvalidStyleException.php -text
lib/Spout/Writer/Exception/Border/InvalidWidthException.php -text
lib/Spout/Writer/Exception/InvalidSheetNameException.php -text
lib/Spout/Writer/Exception/SheetNotFoundException.php -text
lib/Spout/Writer/Exception/WriterAlreadyOpenedException.php -text
lib/Spout/Writer/Exception/WriterException.php -text
lib/Spout/Writer/Exception/WriterNotOpenedException.php -text
lib/Spout/Writer/ODS/Creator/HelperFactory.php -text
lib/Spout/Writer/ODS/Creator/ManagerFactory.php -text
lib/Spout/Writer/ODS/Helper/BorderHelper.php -text
lib/Spout/Writer/ODS/Helper/FileSystemHelper.php -text
lib/Spout/Writer/ODS/Manager/OptionsManager.php -text
lib/Spout/Writer/ODS/Manager/Style/StyleManager.php -text
lib/Spout/Writer/ODS/Manager/Style/StyleRegistry.php -text
lib/Spout/Writer/ODS/Manager/WorkbookManager.php -text
lib/Spout/Writer/ODS/Manager/WorksheetManager.php -text
lib/Spout/Writer/ODS/Writer.php -text
lib/Spout/Writer/WriterAbstract.php -text
lib/Spout/Writer/WriterInterface.php -text
lib/Spout/Writer/WriterMultiSheetsAbstract.php -text
lib/Spout/Writer/XLSX/Creator/HelperFactory.php -text
lib/Spout/Writer/XLSX/Creator/ManagerFactory.php -text
lib/Spout/Writer/XLSX/Helper/BorderHelper.php -text
lib/Spout/Writer/XLSX/Helper/FileSystemHelper.php -text
lib/Spout/Writer/XLSX/Manager/OptionsManager.php -text
lib/Spout/Writer/XLSX/Manager/SharedStringsManager.php -text
lib/Spout/Writer/XLSX/Manager/Style/StyleManager.php -text
lib/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php -text
lib/Spout/Writer/XLSX/Manager/WorkbookManager.php -text
lib/Spout/Writer/XLSX/Manager/WorksheetManager.php -text
lib/Spout/Writer/XLSX/Writer.php -text
lib/Spout/version.txt -text
/paquet.xml -text

img_pack/logo.png

0 → 100644
+20,9 ko
Chargement de la diff d'image…

img_pack/spout-128.png

0 → 100644
+3,64 ko
Chargement de la diff d'image…

img_pack/spout-48.png

0 → 100644
+1,83 ko
Chargement de la diff d'image…

inc/exporter_csv.php

0 → 100644
+99 −0
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
<?php


/**
 * Gestion d'export de données au format CSV
 *
 **/

if (!defined('_ECRIRE_INC_VERSION')) {
	return;
}

include_spip('inc/charsets');
include_spip('inc/filtres');
include_spip('inc/texte');

require_once find_in_path('lib/Spout/Autoloader/autoload.php');
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Common\Entity\Style\Color;

/**
 * Exporte une ressource sous forme de fichier CSV
 *
 * La ressource peut etre un tableau ou une resource SQL issue d'une requete
 * L'extension est choisie en fonction du delimiteur :
 * - si on utilise ',' c'est un vrai csv avec extension csv
 * - si on utilise ';' ou tabulation c'est pour E*cel, et on exporte avec une extension .xlsx
 *
 * @uses exporter_csv_ligne()
 *
 * @param string $titre
 *   titre utilise pour nommer le fichier
 * @param array|resource $resource
 * @param string $delim
 *   delimiteur
 * @param array $entetes
 *   tableau d'en-tetes pour nommer les colonnes (genere la premiere ligne)
 * @param bool $envoyer
 *   pour envoyer le fichier exporte (permet le telechargement)
 * @return string
 */
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 = ',';
	}
	
	$charset = $GLOBALS['meta']['charset'];
	$folder = sous_repertoire(_DIR_CACHE, 'export');
	if ($delim == ',') {
		$extension = 'csv';
		$writer = WriterEntityFactory::createWriterFromFile("$folder$filename.$extension");
		$writer->openToFile("$folder$filename.$extension");
	} else {
		$extension = 'xlsx';
		$defaultStyle = (new StyleBuilder())
                ->setFontName('Arial')
                ->setFontSize(11)
                ->build();
		$writer = WriterEntityFactory::createXLSXWriter();
		$writer->setTempFolder(sous_repertoire(_DIR_CACHE, 'export'));
		$writer->setDefaultRowStyle($defaultStyle)
		       ->openToFile("$folder$filename.$extension");
	}
	$filename = "$filename.$extension";

	if ($entetes and is_array($entetes) and count($entetes)) {
		$writer->addRow(WriterEntityFactory::createRowFromArray($entetes));
	}

	// on passe par un fichier temporaire qui permet de ne pas saturer la memoire
	// avec les gros exports
	$fichier = $folder . $filename;

	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
		$writer->addRow(WriterEntityFactory::createRowFromArray($row));
	}
	
	$writer->close();
	
	if ($envoyer) {
		header("Content-Type: text/comma-separated-values; charset=$charset");
		header("Content-Disposition: attachment; filename=$filename");
		//non supporte
		//Header("Content-Type: text/plain; charset=$charset");
		header("Content-Length: $length");
		ob_clean();
		flush();
		readfile($fichier);
	}

	return $fichier;
}