diff --git a/plugins/pretty-json-column.php b/plugins/pretty-json-column.php new file mode 100644 index 00000000..01d63077 --- /dev/null +++ b/plugins/pretty-json-column.php @@ -0,0 +1,40 @@ +adminer = $adminer; + } + + private function _testJson($value) { + if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true))) { + return $json; + } + return $value; + } + + function editInput($table, $field, $attrs, $value) { + $json = $this->_testJson($value); + if ($json !== $value) { + $jsonText = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + return <<$jsonText +HTML; + } + return ''; + } + + function processInput($field, $value, $function = '') { + if ($function === '') { + $json = $this->_testJson($value); + if ($json !== $value) { + $value = json_encode($json); + } + } + return $this->adminer->_callParent('processInput', array($field, $value, $function)); + } +}