Source for file csv.html.php
Documentation is available at csv.html.php
* smarty functions for csv export
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: csv.html.php 144 2007-09-04 11:38:15Z m2mtech $
* @link http://www.ea-geier.at/
* prepares smarty for CSV export
* @param eaSmarty template object
* @param string name of CSV file
* @param boolean send no header info
$conf = & $GLOBALS['conf'];
$smarty->assign('CVSdelimiter', $conf['txtCSVDelimiter']);
$smarty->assign('CVSnewline', $conf['txtCSVNewLine']);
$smarty->register_prefilter('eaPrepareCVSSmartyPre');
$smarty->register_modifier('CVSenquote', 'eaPrepareCVSSmartyModEnquote');
$smarty->register_modifier('neg', 'eaPrepareCVSSmartyModEnquoteNegative');
$smarty->default_modifiers[] = 'CVSenquote';
if ($noHeader) return true;
header('Content-Type: text/x-csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
* enquotes fields containing special charactors
* @param string field content
* @return string quoted field
$conf = & $GLOBALS['conf'];
if (!preg_match('/[\n\r' . preg_quote($conf['txtCSVDelimiter'] . $conf['txtCSVQuote']) . ']/', $string)) return $string;
return $conf['txtCSVQuote'] . preg_replace('/' . preg_quote($conf['txtCSVQuote']) . '/', $conf['txtCSVEscQuote'], $string) . $conf['txtCSVQuote'];
* enquotes fields containing special charactors and add a minus sign
* @param string field content
* @return string quoted field
if (substr($string, 0, 1) != '-') $string = '-' . $string;
* prepare template for CSV export
* places new-line & delimiter variables
* changes variables in foreach fields due to problem with default modifiers
* @param string field content
* @return string quoted field
$return = preg_replace('/\|\|/', '{$CVSnewline|smarty:nodefaults}', $tpl_source);
$return = preg_replace('/\|(?!(smarty|neg))/', '{$CVSdelimiter|smarty:nodefaults}', $return);
$return = preg_replace('/({foreach[^\$]+\$[^\s]+)/', '${1}|smarty:nodefaults', $return);
|