csv implement insecurity using ob, refactoring now

This commit is contained in:
Jacson Passold 2018-04-11 14:47:26 -03:00
parent 593f8d70c0
commit fe4501c697
1 changed files with 13 additions and 13 deletions

View File

@ -3,6 +3,9 @@
namespace Tainacan\Exposers\Types;
class Csv extends Type {
public $mappers = ['value'];
/**
*
* {@inheritDoc}
@ -13,9 +16,13 @@ class Csv extends Type {
'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ),
'Content-disposition: attachment;filename=tainacan.csv'] // TODO filter/optional
);
$csv = '';
$csv = $this->array_to_csv($response->get_data(), apply_filters('tainacan-exposer-csv', $csv));
$response->set_data($csv);
ob_start();
$csv = fopen('php://output', 'w');
$this->array_to_csv($response->get_data(), apply_filters('tainacan-exposer-csv', $csv));
$ret_csv = ob_get_clean();
ob_end_clean();
fclose($csv);
$response->set_data($ret_csv);
return $response;
}
@ -26,16 +33,9 @@ class Csv extends Type {
* @return string
*/
protected function array_to_csv( $data, $csv ) {
foreach( $data as $key => $value ) {
if( is_numeric($key) ){
//$key = apply_filters('tainacan-exposer-numeric-item-prefix', __('item', 'tainacan').'-', get_class($this)).$key; //dealing with <0/>..<n/> issues
}
if( is_array($value) ) {
//$csv .= $key.": ".$this->array_to_csv($value, '['.$csv.']\n');
} else {
//$csv .= $key.": ".$value .'\n';
}
}
$values = [];
fputcsv($csv, array_keys($data), apply_filters('tainacan-exposer-csv-delimiter', ';') );
fputcsv($csv, array_values($data), apply_filters('tainacan-exposer-csv-delimiter', ';') );
return $csv;
}
}