class webform_exporter_delimited in Webform 6.3
Same name and namespace in other branches
- 5.2 webform_export.inc \webform_exporter_delimited
- 6.2 webform_export.inc \webform_exporter_delimited
- 7.4 includes/exporters/webform_exporter_delimited.inc \webform_exporter_delimited
- 7.3 includes/webform.export.inc \webform_exporter_delimited
Hierarchy
- class \webform_exporter
- class \webform_exporter_delimited
Expanded class hierarchy of webform_exporter_delimited
1 string reference to 'webform_exporter_delimited'
- webform_webform_exporters in includes/
webform.export.inc - Implements hook_webform_exporters().
File
- includes/
webform.export.inc, line 96 - Provides several different handlers for exporting webform results.
View source
class webform_exporter_delimited extends webform_exporter {
var $delimiter;
function webform_exporter_delimited($options) {
$this->delimiter = isset($options['delimiter']) ? $options['delimiter'] : ',';
// Convert tabs.
if ($this->delimiter == '\\t') {
$this->delimiter = "\t";
}
}
function bof(&$file_handle) {
$output = '';
// Include at BOM at the beginning of the file for Little Endian.
// This makes tab-separated imports work correctly in MS Excel.
if (function_exists('mb_convert_encoding') && $this->delimiter == "\t") {
$output = chr(255) . chr(254);
}
@fwrite($file_handle, $output);
}
function add_row(&$file_handle, $data) {
foreach ($data as $key => $value) {
// Escape inner quotes and wrap all contents in new quotes.
$data[$key] = '"' . str_replace('"', '""', $data[$key]) . '"';
// Remove <script> tags, which mysteriously cause Excel not to import.
$data[$key] = preg_replace('!<(/?script.*?)>!', '[$1]', $data[$key]);
}
$row = implode($this->delimiter, $data) . "\n";
if (function_exists('mb_convert_encoding')) {
$row = mb_convert_encoding($row, 'UTF-16LE', 'UTF-8');
}
@fwrite($file_handle, $row);
}
function set_headers($filename) {
parent::set_headers($filename);
// Convert tabs.
if ($this->delimiter == "\t") {
$extension = 'tsv';
$content_type = 'text/tab-separated-values';
}
else {
$extension = 'csv';
$content_type = 'text/csv';
}
drupal_set_header("Content-Type: {$content_type}");
drupal_set_header("Content-Disposition: attachment; filename={$filename}.{$extension}");
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
webform_exporter:: |
function | |||
webform_exporter_delimited:: |
property | 1 | ||
webform_exporter_delimited:: |
function |
Overrides webform_exporter:: |
||
webform_exporter_delimited:: |
function |
Overrides webform_exporter:: |
||
webform_exporter_delimited:: |
function |
Overrides webform_exporter:: |
1 | |
webform_exporter_delimited:: |
function |