-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
json-column.php
48 lines (45 loc) · 1.35 KB
/
json-column.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/** Display JSON values as table in edit
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @author Martin Zeman (Zemistr), http:https://www.zemistr.eu/
* @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 AdminerJsonColumn {
private function _testJson($value) {
if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true))) {
return $json;
}
return $value;
}
private function _buildTable($json) {
echo '<table cellspacing="0" style="margin:2px; font-size:100%;">';
foreach ($json as $key => $val) {
echo '<tr>';
echo '<th>' . h($key) . '</th>';
echo '<td>';
if (is_scalar($val) || $val === null) {
if (is_bool($val)) {
$val = $val ? 'true' : 'false';
} elseif ($val === null) {
$val = 'null';
} elseif (!is_numeric($val)) {
$val = '"' . h(addcslashes($val, "\r\n\"")) . '"';
}
echo '<code class="jush-js">' . $val . '</code>';
} else {
$this->_buildTable($val);
}
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
function editInput($table, $field, $attrs, $value) {
$json = $this->_testJson($value);
if ($json !== $value) {
$this->_buildTable($json);
}
}
}