1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-10 00:28:34 +02:00
Files
php-adminer/plugins/pretty-json-column.php
2025-03-17 00:49:12 +01:00

35 lines
1.0 KiB
PHP

<?php
/** Pretty print JSON values in edit
* @link https://www.adminer.org/plugins/#use
* @author Christopher Chen
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerPrettyJsonColumn {
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 "<textarea$attrs cols='50' rows='20'>" . Adminer\h($jsonText) . "</textarea>";
}
return '';
}
function processInput($field, $value, $function = '') {
if ($function === '') {
$json = $this->testJson($value);
if ($json !== $value) {
$value = json_encode($json);
}
}
}
}