Skip to content

Commit

Permalink
Export csv coding style: wrap long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
amarin15 committed May 1, 2012
1 parent a8e990f commit a276a08
Showing 1 changed file with 75 additions and 21 deletions.
96 changes: 75 additions & 21 deletions libraries/export/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,47 @@
'extension' => 'csv',
'mime_type' => 'text/comma-separated-values',
'options' => array(
array('type' => 'begin_group', 'name' => 'general_opts'),
array('type' => 'text', 'name' => 'separator', 'text' => __('Columns separated with:')),
array('type' => 'text', 'name' => 'enclosed', 'text' => __('Columns enclosed with:')),
array('type' => 'text', 'name' => 'escaped', 'text' => __('Columns escaped with:')),
array('type' => 'text', 'name' => 'terminated', 'text' => __('Lines terminated with:')),
array('type' => 'text', 'name' => 'null', 'text' => __('Replace NULL with:')),
array('type' => 'bool', 'name' => 'removeCRLF', 'text' => __('Remove carriage return/line feed characters within columns')),
array('type' => 'bool', 'name' => 'columns', 'text' => __('Put columns names in the first row')),
array('type' => 'hidden', 'name' => 'structure_or_data'),
array('type' => 'end_group'),
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
array('type' => 'text',
'name' => 'separator',
'text' => __('Columns separated with:')
),
array('type' => 'text',
'name' => 'enclosed',
'text' => __('Columns enclosed with:')
),
array('type' => 'text',
'name' => 'escaped',
'text' => __('Columns escaped with:')
),
array('type' => 'text',
'name' => 'terminated',
'text' => __('Lines terminated with:')
),
'options_text' => __('Options'),
);
array('type' => 'text',
'name' => 'null',
'text' => __('Replace NULL with:')
),
array('type' => 'bool',
'name' => 'removeCRLF',
'text' => __(
'Remove carriage return/line feed characters within columns'
)
),
array('type' => 'bool',
'name' => 'columns',
'text' => __('Put columns names in the first row')
),
array('type' => 'hidden',
'name' => 'structure_or_data'
),
array('type' => 'end_group'),
),
'options_text' => __('Options')
);
} else {

/**
Expand Down Expand Up @@ -170,10 +198,14 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
$schema_insert .= stripslashes(PMA_DBI_field_name($result, $i));
} else {
$schema_insert .= $csv_enclosed
. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(PMA_DBI_field_name($result, $i)))
. $csv_enclosed;
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
stripslashes(PMA_DBI_field_name($result, $i))
)
. $csv_enclosed;
}
$schema_insert .= $csv_separator;
$schema_insert .= $csv_separator;
} // end for
$schema_insert = trim(substr($schema_insert, 0, -1));
if (! PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
Expand All @@ -193,22 +225,44 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
$row[$j] = preg_replace("/\015(\012)?/", "\012", $row[$j]);
}
// remove CRLF characters within field
if (isset($GLOBALS[$what . '_removeCRLF']) && $GLOBALS[$what . '_removeCRLF']) {
$row[$j] = str_replace("\n", "", str_replace("\r", "", $row[$j]));
if (isset($GLOBALS[$what . '_removeCRLF'])
&& $GLOBALS[$what . '_removeCRLF']
) {
$row[$j] = str_replace(
"\n",
"",
str_replace(
"\r",
"",
$row[$j]
)
);
}
if ($csv_enclosed == '') {
$schema_insert .= $row[$j];
} else {
// also double the escape string if found in the data
if ($csv_escaped != $csv_enclosed) {
$schema_insert .= $csv_enclosed
. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, str_replace($csv_escaped, $csv_escaped . $csv_escaped, $row[$j]))
. $csv_enclosed;
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
str_replace(
$csv_escaped,
$csv_escaped . $csv_escaped,
$row[$j]
)
)
. $csv_enclosed;
} else {
// avoid a problem when escape string equals enclose
$schema_insert .= $csv_enclosed
. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j])
. $csv_enclosed;
. str_replace(
$csv_enclosed,
$csv_escaped . $csv_enclosed,
$row[$j]
)
. $csv_enclosed;
}
}
} else {
Expand Down

0 comments on commit a276a08

Please sign in to comment.