Posted by grobot on October 9, 2008 at 1:01am
| Project: | Views Bonus Pack |
| Version: | 5.x-1.2-alpha2 |
| Component: | Views Export |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
CSV exports where the node value contains an '"' (here's hoping that came through OK; it's the HTML quote entity if not) will be invalid because an extra " will get inserted into $value by decode_entities() after the quotes have been handled. This happens in theme_views_bonus_export_csv()
This is most often seen when another module is automatically encoding content, eg with TinyMCE or some other richtext editor.
A quick fix which doesn't require hacking the module is to add this to your template.php - it will override the module function:
/**
* Override views_bonus function to export a view as CSV
*/
function phptemplate_views_bonus_export_csv($view, $nodes) {
if (!user_access('export views')) {
return;
}
$fields = _views_get_fields();
// headings row
$headings = array();
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== false) {
$headings[] = $field['label'] ? $field['label'] : $fields[$field['fullname']]['name'];
}
}
$output .= implode(',', $headings) ."\r\n";
// one row for each node
foreach ($nodes as $node) {
$values = array();
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== false) {
$value = $field;
$value = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
$value = preg_replace('/<.*?>/', '', $value); // strip html tags
$value = str_replace(array("\r", "\n", ','), ' ', $value); // strip line breaks and commas
$value = str_replace(array('"','"'), array('""','""'), $value); // escape " characters
$value = decode_entities($value);
$values[] = '"' . $value . '"';
}
}
$output .= implode(',', $values) . "\r\n";
}
drupal_set_header('Content-Type: text/x-comma-separated-values');
drupal_set_header('Content-Disposition: attachment; filename="view-'. $view->name .'.csv"');
print $output;
module_invoke_all('exit');
exit;
}A patch (makes same modification) will be attached in a moment.
Comments
#1
#2
So, the " in the first line of the above report should read '"'. Yay for input filters :)
#3
I'm pretty sure this is a duplicate of #238465: CSV Export: Field encoding sequence
Feel free to reopen if this isn't fixed in the dev release.