From 65c52735fb594d972d5e0a9907b1abebee0d2795 Mon Sep 17 00:00:00 2001 From: Christopher CHEN Date: Wed, 18 Jul 2018 14:35:45 +0800 Subject: [PATCH] Add plugin pretty-json-column (cherry picked from commit 9b8612a49c43ff170837dbf84f8c08a0e85386a8) --- plugins/pretty-json-column.php | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 plugins/pretty-json-column.php 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)); + } +}