From: Christopher CHEN Date: Wed, 18 Jul 2018 06:35:45 +0000 (+0800) Subject: Add plugin pretty-json-column X-Git-Tag: v4.7.0~26 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=65c52735fb594d972d5e0a9907b1abebee0d2795;p=adminer.git Add plugin pretty-json-column (cherry picked from commit 9b8612a49c43ff170837dbf84f8c08a0e85386a8) --- 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)); + } +}