Merge pull request #1579 from addaleax/json-pretty-print
Add option for exporting pretty-printed JSON
This commit is contained in:
commit
fa763b1828
@ -86,6 +86,7 @@ if (!defined('TESTSUITE')) {
|
||||
'ods_structure_or_data',
|
||||
'ods_columns',
|
||||
'json_structure_or_data',
|
||||
'json_pretty_print',
|
||||
'xml_structure_or_data',
|
||||
'xml_export_events',
|
||||
'xml_export_functions',
|
||||
|
||||
@ -1801,6 +1801,13 @@ $cfg['Export']['phparray_structure_or_data'] = 'data';
|
||||
*/
|
||||
$cfg['Export']['json_structure_or_data'] = 'data';
|
||||
|
||||
/**
|
||||
* Export functions
|
||||
*
|
||||
* @global string $cfg['Export']['json_pretty_print']
|
||||
*/
|
||||
$cfg['Export']['json_pretty_print'] = false;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
||||
@ -41,6 +41,7 @@ class ExportJson extends ExportPlugin
|
||||
include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
|
||||
include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
|
||||
include_once "$props/options/items/HiddenPropertyItem.class.php";
|
||||
include_once "$props/options/items/BoolPropertyItem.class.php";
|
||||
|
||||
$exportPluginProperties = new ExportPluginProperties();
|
||||
$exportPluginProperties->setText('JSON');
|
||||
@ -61,6 +62,15 @@ class ExportJson extends ExportPlugin
|
||||
$leaf = new HiddenPropertyItem();
|
||||
$leaf->setName("structure_or_data");
|
||||
$generalOptions->addProperty($leaf);
|
||||
|
||||
// JSON_PRETTY_PRINT is available since 5.4.0
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$leaf = new BoolPropertyItem();
|
||||
$leaf->setName('pretty_print');
|
||||
$leaf->setText(__('Output pretty-printed JSON (Use human-readable formatting)'));
|
||||
$generalOptions->addProperty($leaf);
|
||||
}
|
||||
|
||||
// add the main group to the root group
|
||||
$exportSpecificOptions->addProperty($generalOptions);
|
||||
|
||||
@ -197,7 +207,13 @@ class ExportJson extends ExportPlugin
|
||||
$data[$columns[$i]] = $record[$i];
|
||||
}
|
||||
|
||||
if (! PMA_exportOutputHandler(json_encode($data))) {
|
||||
if (isset($GLOBALS['json_pretty_print']) && $GLOBALS['json_pretty_print']) {
|
||||
$encoded = json_encode($data, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$encoded = json_encode($data);
|
||||
}
|
||||
|
||||
if (! PMA_exportOutputHandler($encoded)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user